A addition compiler (Bison.SIMPLE)

xiaoxiao2021-03-06  34

/ * - * - C - * - Note Some Compilers Choke on Comments on `#Line 'lines. * / # Line 3" bison.simple "

/ * Skeleton Output Parser for Bison, Copyright (C) 1984, 1989, 1990 Free Software Foundation, Inc.

This program is free software; you can redistribute it and / or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2, or (at your option) any later version.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;. Without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE See the GNU General Public License for more details.

You Should Have Received A Copy of The GNU General Public License Along With Program; if Not, Write to The Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. * /

/ * As a special exception, when this file is copied by Bison into a Bison output file, you may use that output file without restriction. This special exception was added by the Free Software Foundation in version 1.24 of Bison. * /

#ifndef alloca # ifdef __GNUC __ # define alloca __builtin_alloca # else / * not GNU C. * / # if (! defined (__STDC__) && defined (sparc)) || defined (__sparc__) || defined (__sparc) || ​​defined ( __sgi) #include #ELSE / * NOT sparc * / # if defined (msdos) &&! deflude #else / * not msdos, or __turboc__ * / # t td (_AIX) #include #pragma alloca # else / * not msdos, __turboc__, or _aix * / # ifdef __hpux # ifdef __cplusextern "c" {void * alloca (unsigned int);}; # else / * Not __cplusplus * / void * alloca (); # ENDIF / * NOT __CPLUSPLUSPLUS * / # endif / * __hpux * / # endif / * not _Aix * / # Endif / * not msdos, or __turboc__ * / # ENDIF / * NOT SPARC * // * this is the parser code That IS Written Into Each Bison Parser when% semantic_parser Declaration is Not Specified in the grammar. IT WAS Written by Richard Stallman by Simplifying The Hairy Parser Used When% Semantic_Parser is Specified. * /

/ * NOTE: THERE MUST BE Only One Dollar Sign in this file. It is replaced by the list of actions, Each action as one case of the switch. * /

#define yyerrok (yyerrstatus = 0) #define yyclearin (yychar = YYEMPTY) #define YYEMPTY -2 # define YYEOF 0 # define YYACCEPT return (0) #define YYABORT return (1) #define YYERROR goto yyerrlab1 / * Like YYERROR except do call yyerror. This remains here temporarily to ease the transition to the new meaning of yYERROR, for GCC. Once GCC version 2 has supplanted version 1, this can go. * / # define YYFAIL goto yyerrlab # define YYRECOVERING () (!! yyerrstatus #define yybackup (token, value) / do / if (YYCHAR == YYEMPTY && YYLEN == 1) / {yychar = (token), yylval = (value); / yychar1 = yytranslate (YYCHAR); / YYPOPSTACK; / Goto yybackup; /} / else / {YYERROR ("Syntax Error: Cannot Back Up"); YYERROR;} / while (0) #define Yyterror 1 # define YyerRcode 256

#ifndef yypure # Define Yylex Yylex () # ENDIF

#ifdef YYPURE # ifdef YYLSP_NEEDED # ifdef YYLEX_PARAM # define YYLEX yylex (& yylval, & yylloc, YYLEX_PARAM) # else # define YYLEX yylex (& yylval, & yylloc) # endif # else / * not YYLSP_NEEDED * / # ifdef YYLEX_PARAM # define YYLEX yylex (& yylval , Yylex_Param) # Else # Define Yylex Yylex (& Yylval) # Endif # Endif / * Not Yylsp_Needed * / # Endif

/ * If NonreenTrant, Generate The Variables Here * /

#ifndef yypure

Int yychar; / * the lookahead symbol * / yystype yylval; / * the semantic value of the * / / * lookahead symbol * /

#ifdef yylsp_needededyyltype yylloc; / * location data for the lookahead * / / * symbol * / # ENDIF

INT YYNERRS; / * NUMBER OF PARSE ERRORS SO FAR * / # ENDIF / * NOT YYPURE * /

! #If YYDEBUG = 0int yydebug;. / * Nonzero means print parse trace * // * Since this is uninitialized, it does not stop multiple parsers from coexisting * / # endif / * YYINITDEPTH indicates the initial size of the parser's stacks * /

#ifndef yyinitDepth # Define YyinitDepth 200 # ENDIF

/ * YYMAXDEPTH IS The Maximum size the stacks can result. * /

#if yymaxdepth == 0 # undef yymaxdepth # Endif

#ifndef yymaxdepth # Define YymaxDepth 10000 # ENDIF

/ * Prevent warning if -Wstrict-prototypes * / # ifdef __GNUC__int yyparse (void);.. # Endif #if __GNUC__> 1 / * GNU C and GNU C define this * / # define __yy_memcpy (FROM, TO, COUNT) __builtin_memcpy (To, from, count) #ELSE / * NOT GNU C or C * / # ifndef __cplusplus

/ * This is the most reliable way to avoid incompatibilities in available built-in functions on various systems * / static void__yy_memcpy (from, to, count) char * from;. Char * to; int count; {register char * f = from Register char * t = TO; Register INT i = count;

While (i-> 0) * t = * f ;}

#ELSE / * __CPLUSPLUS * /

/ * This is the most reliable way to avoid incompatibilities in available built-in functions on various systems * / static void__yy_memcpy (char * from, char * to, int count) {register char * f = from;. Register char * t = TO; Register INT i = Count;

While (i-> 0) * t = * f ;}

# Endif # Endif #Line 192 "Bison.SIMPLE"

/ * The user can define YYPARSE_PARAM as the name of an argument to be passed into yyparse. The argument should have type void *. It should actually point to an object. Grammar actions can access the variable by casting it to the proper pointer type. * / # ifdef yyparse_param # define yyparse_param_decl void * yyparse_param; # ilse # define yyparse_param # define yyparse_param_decl # Endif

intyyparse (YYPARSE_PARAM) YYPARSE_PARAM_DECL {register int yystate; register int yyn; register short * yyssp; register YYSTYPE * yyvsp; int yyerrstatus; / * number of tokens to shift before error messages enabled * / int yychar1 = 0; / * lookahead token as An in (Translated) token Number * /

Short yyssea [yyinitDepth]; / * the state stack * / yystype yyvsa [yyinitdepth]; / * the semantic value stack * /

Short * yyss = yyssa; / * refer to the stacks thru separate pointers * / yystype * yyvs = yyvsa; / * to allow yyoverflow to relatocate theme elsewhere * /

#ifdef Yylsp_Needed YYLTYPE YYLSA [YYINITDEPTH]; / * The location stack * / yectype * yyls = yylsa; yectype * yylsp;

#define yypopstack (YYVSP -, YYSSP -, YYLSP -) # Else # Define Yypopstack (YYVSP -, YYSSP -) # ENDIF

Int Yystacksize = yyinitdepth;

#ifdef YYPURE int yychar; YYSTYPE yylval; int yynerrs; #ifdef YYLSP_NEEDED YYLTYPE yylloc; # endif # endif YYSTYPE yyval; / * the variable used to return * / / * semantic values ​​from the action * / / * routines * /

Int yylen;

#if yydebug! = 0 if (yydebug) fprintf (stderr, "starting parse / n"); # endif yyval = 0; yystate = 0; yyerrstatus = 0; yynerrs = 0; yychar = yyempty; / * cause a token to Be read. * /

. / * Initialize stack pointers Waste one element of value and location stack so that they stay on the same level as the state stack The wasted elements are never initialized * / yyssp = yyss - 1;.. Yyvsp = yyvs; #ifdef YYLSP_NEEDED yylsp = YYLS; #ENDIF

/ * Push a new state, which is found in yystate. * // * in All Cases, WHEN You get here, the value and location stacks Have Just Been Pushed. So pushing a state here evens the stacks. * / YYNewState:

* Yyssp = yystate;

IF (YysSp> = YYSS YYSTACKSIZE - 1) {/ * Give User a chance to relatocate the stack * / / / / * Use copies of these sol at the & 's don't forward the real ones Into memory. * / yystype * yyvs1 = YYVS; Short * Yys1 = yyss; #ifdef yylsp_needed yectype * yyls1 = yyls; #ENDIF

/ * Get the current use size of the three stacks, in elements. * / Int size = yyssp - yyss 1;

#ifdef yyoverflow / * Each stack pointer address is followed by the size of the data in use in that stack, in bytes. * / # ifdef YYLSP_NEEDED / * This used to be a conditional around just the two extra args, but that might be . undefined if yyoverflow is a macro * / yyoverflow ( "parser stack overflow", & yyss1, size * sizeof (* yyssp), & yyvs1, size * sizeof (* yyvsp), & yyls1, size * sizeof (* yylsp), & yystacksize); #ELSE YYOVERFLOW ("Parser Stack Overflow", & Yyss1, Size * SizeOf (* Yyssp), & YYVS1, SIZE * SIZEOF (* YYVSP), & YYSTACKSIZE); # ENDIF

yyss = yyss1; yyvs = yyvs1; #ifdef YYLSP_NEEDED yyls = yyls1; # endif # else / * no yyoverflow * / / * Extend the stack our own way * / if (yystacksize> = YYMAXDEPTH) {yyerror ( "parser stack overflow. "); return 2;} yystacksize * = 2; if (yystacksize> YYMAXDEPTH) yystacksize = YYMAXDEPTH; yyss = (short *) alloca (yystacksize * sizeof (* yyssp)); __yy_memcpy ((char *) yyss1, (char * ) YYSS, SIZE * SIZEOF (* YYSSP)); YYVS = (YYSTYPE *) Alloca (YYSTACKSIZE * SIZEOF (* YYVSP)); __YY_MEMCPY ((char *) YYVS1, (char *) YYVS, SIZE * SIZEOF (* YYVSP) ); # ifdef YYLSP_NEEDED yyls = (YYLTYPE *) alloca (yystacksize * sizeof (* yylsp)); __yy_memcpy ((char *) yyls1, (char *) yyls, size * sizeof (* yylsp)); # endif # endif / * no yyoverflow * / yyssp = yyss size - 1; yYVSP = yyvs size - 1; #ifdef yylsp_needed yylsp = yyls size - 1; #ENDIF

#if yydebug! = 0 if (yydebug) fprintf (stderr, "stack size increased to% d / n", yystacksize); # ENDIF

IF (Yyssp> = YYSS YYSTACKSIZE - 1) YYABORT;

#if yydebug! = 0 if (yydebug) fprintf (stderr, "entering state% d / n", yystate); # ENDIF

Goto yybackup; yybackup:

/ * Do Appropriate Processing Given The Current State. * // * Read a lookahead token if we need one and don't alleady has one. * // * YyResume: * /

/ * First try to decide what to do help inglence to lookahead token. * /

YYN = YYPACT [YYSTATE]; if (yyn == yyflag) goto yydefault;

/ * NOT KNOWN => Get a lookahead token if don't alleady has one. * /

/ * YYCHAR IS Either YYEMPTY or YYEOF OR a Valid token in External Form. * /

IF (YYCHAR == YYEMPTY) {#if yydebug! = 0 if (yydebug) fprintf (stderr, "Reading a token:"); # endif yychar = yylex;} / * convert token to inTernal Form (in yychar1) for indexing Tables with * /

IF (YYCHAR <= 0) / * this means end of infut. * / {yychar1 = 0; yychar = yyeof; / * don't call yylex any more * /

#if yydebug! = 0 if (yydebug) FPRINTF (stderr, "now at end of infut./n" );##dif} else {yychar1 = yytranslate (yychar);

#if yydebug! = 0 if (yydebug) {fprintf (stderr, "next token is% d (% s", yychar, yytname [yychar1]); / * Give the individual Parser a Way to print the precise meaning of a token , for further debugging info. * / # ifdef yyprint yyprint (stderr, yychar, yylval); # Endif fprintf (stderr, ") / n");} #ENDIF}

YYN = yychar1; if (YYN <0 || yyn> yylast || yycheck [yyn]! = yychar1) goto yydefault;

YYN = yytable [yyn];

/ * YYN is what to do for this token type in this state. NEGATIVE => reduuce, -yyn is rule number. posital => shift, yyn is new state. new state is final state => don't Bother to Shift, Just Return Success. 0, or MOST NEGATIVE NUMBER => Error. * /

IF (YYN <0) {if (YYN == YYFLAG) goto yyerrlab; yyn = -yyn; goto yyreduce;} else if (yyn == 0) goto yyerrlab;

IF (YYN == YYFINAL) YYACCEPT;

/ * Shift the lookahead token. * /

#if yydebug! = 0 if (yydebug) fprintf (stderr, "Shifting token% d (% s),", yychar, yytname [yychar1]); # ENDIF

/ * Discard the token being shifted unless it is eof. * / If (yychar! = Yyeof) YYCHAR = yyempty; * yyvsp = yylval; #ifdef yylsp_needed * yylsp = yylloc; #ENDIF

/ * Count tokens Shifted Since Error; After Three, Turn Off Error Status. * / if (Yyerrstatus) YYERRSTATUS -

YYSTATE = YYN; GOTO YYNEWSTATE;

/ * Do The default action for the current state. * / Yydefault:

YYN = yydefact [yystate]; if (yyn == 0) goto yyerrlab;

/ * Do a reduuction. YYN is the number of a rule to reduce with. * / Yyreduce: yylen = yyr2 [yyn]; if (yylen> 0) YYVAL = yyvsp [1-yylen]; / * Implement default value of the Action * /

#if yydebug! = 0 if (yydebug) {INT i;

FPRINTF (stderr, "reducing via rule% d),", yyn, yyrline [yyn]);

/ * Print the symbols being reduced, and their result. * / For (i = yyprhs [yyn]; yyrHs [i]> 0; i ) fprintf (stderr, "% s", yytname [yyrHs [i]]); FPRINTF (stderr, "->% s / n", yytname [yyr1 [yyn]]);} #ENDIF

$ / * The action file gets copied in place of this dollarsign * / # line 487 "bison.simple" yyvsp - = yylen; yyssp - = yylen; #ifdef yylsp_needed yylsp - = yylen; #ENDIF

#if yydebug! = 0 if (yydebug) {Short * SSP1 = yys - 1; fprintf (stderr, "state stack now"); while (ssp1! = yyssp) fprintf (stderr, "% d", * SSP1 ); Fprintf (stderr, "/ n");} #ENDIF

* YYVSP = YYVAL;

#ifdef YYLSP_NEEDED yylsp ; if (yylen == 0) {yylsp-> first_line = yylloc.first_line; yylsp-> first_column = yylloc.first_column; yylsp-> last_line = (yylsp-1) -> last_line; yylsp-> last_column = (YYLSP-1) -> Last_Column; YYLSP-> text = 0;} else {yylsp-> last_line = (YYLSP YYLEN-1) -> last_line; yylsp-> last_column = (YYLSP YYLEN-1) -> Last_Column } # Endif / * Now "Shift" The result of the reduction. Determine what state what goes to and the rule number reduced by. * /

YYN = yyr1 [yyn];

yystate = yypgoto [yyn - YYNTBASE] * yyssp; if (yystate> = 0 && yystate <= YYLAST && yycheck [yystate] == * yyssp) yystate = yytable [yystate]; else yystate = yydefgoto [yyn - YYNTBASE];

Goto yynewstate;

Yherrlab: / * here on detecting error * /

IF (! YYERRSTATUS) / * if not already Recovering from an error, report this error. * / { yynerrs;

#ifdef YYERROR_VERBOSE YYN = YYPACT [YYSTATE];

IF (YYN> YYFLAG && YYN

Count = 0; / * Start x at -yyn if NEC to avoid negative indexes in yycheck. * / for (x = (YYN <0? -yyn: 0); x <(sizeof (yytname) / sizeof (char *) ); x ) IF (YYCHECK [x yyn] == x) size = strlen (YYTNAME [x]) 15, count ; msg = (char *) Malloc (Size 15); if (MSG! = 0 ) {Struct (MSG, "Parse Error");

IF (count <5) {count = 0; for (x = (YYN <0? -yyn: 0); x <(yytname) / sizeof (char *)); x ) IF (YYCHECK [x yyn ] == x) {strcat (msg, count == 0? ", expecting` ":" OR `"); strcat (msg, yytname [x]); strcat (msg, "'"); count ;}} YYERROR (MSG); Free ("Parse Error; Also Virtual Memory Exceeded");} else # endif / * yyerror_verbose * / yyrror ("parse error");} goto yyerrlab1; yYERRLAB1: / * Here on error raised expendly by an action * /

IF (YYERRSTATUS == 3) {/ * if Just Tried and failed to reuse lookahead token after an error, discard it. * /

/ * RETURN FAILURE IF at end of infut * / if (yychar == yyeof) yyabort;

#if yydebug! = 0 if (yydebug) fprintf (stderr, "discarding token% d (% s) ./ n", yychar, yytname [yychar1]); # ENDIF

YYCHAR = YYEMPTY;

/ * Else Will Try to reuse lookahead token after shifting the error token. * /

YYERRSTATUS = 3; / * Each real token shifted Decremers this * /

Goto Yherrhandle;

YYERRDEFAULT: / * CURRENT State Does Not do Anything Special for the Error Token. * /

#if 0 / * this is WRONG; Only States That Explicitly Want Error Token Should Shift Them. * / YYN = YYDEFACT [YYSTATE]; / * if ITS Default is to accept any token, ok. Otherwise pop it. * / if ( YYN) GOTO YYDEFAULT; #ENDIF

Yherrpop: / * Pop The Current State Because it cannot handle the error token * /

IF (Yysp == Yyss) YYABORT; YYVSP - YYSTATE = * - Yysp; #ifdef Yylsp_Needed Yylsp -; # ENDIF

#if yydebug! = 0 if (yydebug) {short * ssp1 = yys - 1; fprintf (stderr, "error: state stack now); while (ssp1! = yyssp) fprintf (stderr,"% d ", * SSP1); FPRINTF (stderr, "/ n");} #ENDIFYYERRHANDLE:

YYN = yypact [yYSTATE]; if (yyn == yyflag) goto yyerrdefault;

YYN = YYTERROR; if (YYN <0 || yyn> YYLAST || YYCHECK [YYN]! = yyterror) goto yyerrdefault;

YYN = yytable [yyn]; if (yyn <0) {if (yyn == yyflag) goto yYERRPOP; YYN = -yyn; goto yyreduce;} else if (yyn == 0) goto yyerrpop;

IF (YYN == YYFINAL) YYACCEPT;

#if yydebug! = 0 if (yydebug) fprintf (stderr, "shifting error token,"); # ENDIF

* YYVSP = yylval; #ifdef yylsp_needed * yylsp = yylloc; #ENDIF

YYSTATE = yyn; goto yynewstate;}

转载请注明原文地址:https://www.9cbs.com/read-67444.html

New Post(0)