📄 add1.y.c
字号:
extern int yylex();extern void yyerror(const char * s);#ifdef __cplusplus# include <stdio.h># include <yacc.h>#endif /* __cplusplus */ # define INTEGER 257#define yyclearin yychar = -1#define yyerrok yyerrflag = 0extern int yychar;#ifndef YYMAXDEPTH#define YYMAXDEPTH 150#endif/* __YYSCLASS defines the scoping/storage class for global objects * that are NOT renamed by the -p option. By default these names * are going to be 'static' so that multi-definition errors * will not occur with multiple parsers. * If you want (unsupported) access to internal names you need * to define this to be null so it implies 'extern' scope. * This should not be used in conjunction with -p. */#ifndef __YYSCLASS# define __YYSCLASS static#endif#ifndef YYSTYPE#define YYSTYPE int#endifYYSTYPE yylval;__YYSCLASS YYSTYPE yyval;typedef int yytabelem;# define YYERRCODE 256void yyerror(const char * s){ fprintf(stderr, "%s\n", s);}int main(void){ yyparse(); return 0;}#include "add1.c"__YYSCLASS yytabelem yyexca[] ={-1, 1, 0, -1, -2, 0, };# define YYNPROD 8# define YYLAST 39__YYSCLASS yytabelem yyact[]={ 10, 9, 3, 6, 5, 4, 2, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 7, 0, 8 };__YYSCLASS yytabelem yypact[]={ -3400, -255, -7, -3400, -256, -257, -3400, -3400, -3400, -3400, -3400 };__YYSCLASS yytabelem yypgo[]={ 0, 7, 6, 5, 4 };__YYSCLASS yytabelem yyr1[]={ 0, 1, 1, 3, 4, 2, 2, 2 };__YYSCLASS yytabelem yyr2[]={ 0, 7, 0, 5, 5, 3, 5, 5 };__YYSCLASS yytabelem yychk[]={ -3400, -1, -2, 257, -3, -4, 10, 43, 45, 257, 257 };__YYSCLASS yytabelem yydef[]={ 2, -2, 0, 5, 0, 0, 1, 3, 4, 6, 7 };typedef struct { char *t_name; int t_val; } yytoktype;#ifndef YYDEBUG# define YYDEBUG 1 /* allow debugging */#endif#if YYDEBUG__YYSCLASS yytoktype yytoks[] ={ "INTEGER", 257, "-unknown-", -1 /* ends search */};__YYSCLASS char * yyreds[] ={ "-no such reduction-", "program : program expr '\n'", "program : /* empty */", "expradd : expr '+'", "exprminus : expr '-'", "expr : INTEGER", "expr : expradd INTEGER", "expr : exprminus INTEGER",};#endif /* YYDEBUG */#define YYFLAG (-3400)/* @(#) $Revision: 70.7 $ */ /*** Skeleton parser driver for yacc output*/#if defined(NLS) && !defined(NL_SETN)#include <msgbuf.h>#endif#ifndef nl_msg#define nl_msg(i,s) (s)#endif/*** yacc user known macros and defines*/#define YYERROR goto yyerrlab#ifndef __RUNTIME_YYMAXDEPTH#define YYACCEPT return(0)#define YYABORT return(1)#else#define YYACCEPT {free_stacks(); return(0);}#define YYABORT {free_stacks(); return(1);}#endif#define YYBACKUP( newtoken, newvalue )\{\ if ( yychar >= 0 || ( yyr2[ yytmp ] >> 1 ) != 1 )\ {\ yyerror( (nl_msg(30001,"syntax error - cannot backup")) );\ goto yyerrlab;\ }\ yychar = newtoken;\ yystate = *yyps;\ yylval = newvalue;\ goto yynewstate;\}#define YYRECOVERING() (!!yyerrflag)#ifndef YYDEBUG# define YYDEBUG 1 /* make debugging available */#endif/*** user known globals*/#ifdef YYREENTRANT__thread int yydebug; /* set to 1 to get debugging */#elseint yydebug; /* set to 1 to get debugging */#endif/*** driver internal defines*//* define for YYFLAG now generated by yacc program. *//*#define YYFLAG (FLAGVAL)*//*** global variables used by the parser*/# ifndef __RUNTIME_YYMAXDEPTH# ifdef YYREENTRANT__thread __YYSCLASS YYSTYPE yyv[ YYMAXDEPTH ]; /* value stack */__thread __YYSCLASS int yys[ YYMAXDEPTH ]; /* state stack */# else__YYSCLASS YYSTYPE yyv[ YYMAXDEPTH ]; /* value stack */__YYSCLASS int yys[ YYMAXDEPTH ]; /* state stack */# endif# else# ifdef YYREENTRANT__thread __YYSCLASS YYSTYPE *yyv; /* pointer to malloc'ed stack stvalue stack */__thread __YYSCLASS int *yys; /* pointer to malloc'ed stack stack */# else__YYSCLASS YYSTYPE *yyv; /* pointer to malloc'ed value stack */__YYSCLASS int *yys; /* pointer to malloc'ed stack stack */# endif#if defined(__STDC__) || defined (__cplusplus)#include <stdlib.h>#else extern char *malloc(); extern char *realloc(); extern void free();#endif /* __STDC__ or __cplusplus */static int allocate_stacks(); static void free_stacks();# ifndef YYINCREMENT# define YYINCREMENT (YYMAXDEPTH/2) + 10# endif# endif /* __RUNTIME_YYMAXDEPTH */long yymaxdepth = YYMAXDEPTH;#ifdef YYREENTRANT__thread __YYSCLASS YYSTYPE *yypv; /* top of value stack */__thread __YYSCLASS int *yyps; /* top of state stack */__thread __YYSCLASS int yystate; /* current state */__thread __YYSCLASS int yytmp; /* extra var (lasts between blocks) */__thread int yynerrs; /* number of errors */__thread __YYSCLASS int yyerrflag; /* error recovery flag */__thread int yychar; /* current input token number */__thread extern int yyinit_key; /* init TLS data once */extern int TLS_INIT; #else__YYSCLASS YYSTYPE *yypv; /* top of value stack */__YYSCLASS int *yyps; /* top of state stack */__YYSCLASS int yystate; /* current state */__YYSCLASS int yytmp; /* extra var (lasts between blocks) */int yynerrs; /* number of errors */__YYSCLASS int yyerrflag; /* error recovery flag */int yychar;#endif/*** yyparse - return 0 if worked, 1 if syntax error not recovered froml*/intyyparse(){ register YYSTYPE *yypvt; /* top of value stack for $vars */ /* ** Initialize externals - yyparse may be called more than once */#ifdef YYREENTRANT if (yyinit_key != TLS_INIT) { yyinit_key = TLS_INIT; yyinit_tls(); }#endif /* ** Initialize externals - yyparse may be called more than once */# ifdef __RUNTIME_YYMAXDEPTH if (allocate_stacks()) YYABORT;# endif yypv = &yyv[-1]; yyps = &yys[-1]; yystate = 0; yytmp = 0; yynerrs = 0; yyerrflag = 0; yychar = -1; goto yystack; { register YYSTYPE *yy_pv; /* top of value stack */ register int *yy_ps; /* top of state stack */ register int yy_state; /* current state */ register int yy_n; /* internal state number info */ /* ** get globals into registers. ** branch to here only if YYBACKUP was called. */ yynewstate: yy_pv = yypv; yy_ps = yyps; yy_state = yystate; goto yy_newstate; /* ** get globals into registers. ** either we just started, or we just finished a reduction */ yystack: yy_pv = yypv; yy_ps = yyps; yy_state = yystate; /* ** top of for (;;) loop while no reductions done */ yy_stack: /* ** put a state and value onto the stacks */#if YYDEBUG /* ** if debugging, look up token value in list of value vs. ** name pairs. 0 and negative (-1) are special values. ** Note: linear search is used since time is not a real ** consideration while debugging. */ if ( yydebug ) { register int yy_i; printf( "State %d, token ", yy_state ); if ( yychar == 0 ) printf( "end-of-file\n" ); else if ( yychar < 0 ) printf( "-none-\n" ); else { for ( yy_i = 0; yytoks[yy_i].t_val >= 0; yy_i++ ) { if ( yytoks[yy_i].t_val == yychar ) break; } printf( "%s\n", yytoks[yy_i].t_name ); }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -