diff options
Diffstat (limited to 'test')
78 files changed, 31446 insertions, 0 deletions
diff --git a/test/README b/test/README new file mode 100644 index 000000000000..c9133c5bc876 --- /dev/null +++ b/test/README @@ -0,0 +1,4 @@ +-- $Id: README,v 1.1 2004/03/28 19:10:48 tom Exp $ + +The files in this directory are input (.y) and output (.output, .tab.c, .tab.h) +examples. diff --git a/test/calc.output b/test/calc.output new file mode 100644 index 000000000000..3aed47511c93 --- /dev/null +++ b/test/calc.output @@ -0,0 +1,461 @@ + 0 $accept : list $end + + 1 list : + 2 | list stat '\n' + 3 | list error '\n' + + 4 stat : expr + 5 | LETTER '=' expr + + 6 expr : '(' expr ')' + 7 | expr '+' expr + 8 | expr '-' expr + 9 | expr '*' expr + 10 | expr '/' expr + 11 | expr '%' expr + 12 | expr '&' expr + 13 | expr '|' expr + 14 | '-' expr + 15 | LETTER + 16 | number + + 17 number : DIGIT + 18 | number DIGIT + +state 0 + $accept : . list $end (0) + list : . (1) + + . reduce 1 + + list goto 1 + + +state 1 + $accept : list . $end (0) + list : list . stat '\n' (2) + list : list . error '\n' (3) + + $end accept + error shift 2 + DIGIT shift 3 + LETTER shift 4 + '-' shift 5 + '(' shift 6 + . error + + stat goto 7 + expr goto 8 + number goto 9 + + +state 2 + list : list error . '\n' (3) + + '\n' shift 10 + . error + + +state 3 + number : DIGIT . (17) + + . reduce 17 + + +state 4 + stat : LETTER . '=' expr (5) + expr : LETTER . (15) + + '=' shift 11 + '|' reduce 15 + '&' reduce 15 + '+' reduce 15 + '-' reduce 15 + '*' reduce 15 + '/' reduce 15 + '%' reduce 15 + '\n' reduce 15 + + +state 5 + expr : '-' . expr (14) + + DIGIT shift 3 + LETTER shift 12 + '-' shift 5 + '(' shift 6 + . error + + expr goto 13 + number goto 9 + + +state 6 + expr : '(' . expr ')' (6) + + DIGIT shift 3 + LETTER shift 12 + '-' shift 5 + '(' shift 6 + . error + + expr goto 14 + number goto 9 + + +state 7 + list : list stat . '\n' (2) + + '\n' shift 15 + . error + + +state 8 + stat : expr . (4) + expr : expr . '+' expr (7) + expr : expr . '-' expr (8) + expr : expr . '*' expr (9) + expr : expr . '/' expr (10) + expr : expr . '%' expr (11) + expr : expr . '&' expr (12) + expr : expr . '|' expr (13) + + '|' shift 16 + '&' shift 17 + '+' shift 18 + '-' shift 19 + '*' shift 20 + '/' shift 21 + '%' shift 22 + '\n' reduce 4 + + +state 9 + expr : number . (16) + number : number . DIGIT (18) + + DIGIT shift 23 + '|' reduce 16 + '&' reduce 16 + '+' reduce 16 + '-' reduce 16 + '*' reduce 16 + '/' reduce 16 + '%' reduce 16 + '\n' reduce 16 + ')' reduce 16 + + +state 10 + list : list error '\n' . (3) + + . reduce 3 + + +state 11 + stat : LETTER '=' . expr (5) + + DIGIT shift 3 + LETTER shift 12 + '-' shift 5 + '(' shift 6 + . error + + expr goto 24 + number goto 9 + + +state 12 + expr : LETTER . (15) + + . reduce 15 + + +state 13 + expr : expr . '+' expr (7) + expr : expr . '-' expr (8) + expr : expr . '*' expr (9) + expr : expr . '/' expr (10) + expr : expr . '%' expr (11) + expr : expr . '&' expr (12) + expr : expr . '|' expr (13) + expr : '-' expr . (14) + + . reduce 14 + + +state 14 + expr : '(' expr . ')' (6) + expr : expr . '+' expr (7) + expr : expr . '-' expr (8) + expr : expr . '*' expr (9) + expr : expr . '/' expr (10) + expr : expr . '%' expr (11) + expr : expr . '&' expr (12) + expr : expr . '|' expr (13) + + '|' shift 16 + '&' shift 17 + '+' shift 18 + '-' shift 19 + '*' shift 20 + '/' shift 21 + '%' shift 22 + ')' shift 25 + . error + + +state 15 + list : list stat '\n' . (2) + + . reduce 2 + + +state 16 + expr : expr '|' . expr (13) + + DIGIT shift 3 + LETTER shift 12 + '-' shift 5 + '(' shift 6 + . error + + expr goto 26 + number goto 9 + + +state 17 + expr : expr '&' . expr (12) + + DIGIT shift 3 + LETTER shift 12 + '-' shift 5 + '(' shift 6 + . error + + expr goto 27 + number goto 9 + + +state 18 + expr : expr '+' . expr (7) + + DIGIT shift 3 + LETTER shift 12 + '-' shift 5 + '(' shift 6 + . error + + expr goto 28 + number goto 9 + + +state 19 + expr : expr '-' . expr (8) + + DIGIT shift 3 + LETTER shift 12 + '-' shift 5 + '(' shift 6 + . error + + expr goto 29 + number goto 9 + + +state 20 + expr : expr '*' . expr (9) + + DIGIT shift 3 + LETTER shift 12 + '-' shift 5 + '(' shift 6 + . error + + expr goto 30 + number goto 9 + + +state 21 + expr : expr '/' . expr (10) + + DIGIT shift 3 + LETTER shift 12 + '-' shift 5 + '(' shift 6 + . error + + expr goto 31 + number goto 9 + + +state 22 + expr : expr '%' . expr (11) + + DIGIT shift 3 + LETTER shift 12 + '-' shift 5 + '(' shift 6 + . error + + expr goto 32 + number goto 9 + + +state 23 + number : number DIGIT . (18) + + . reduce 18 + + +state 24 + stat : LETTER '=' expr . (5) + expr : expr . '+' expr (7) + expr : expr . '-' expr (8) + expr : expr . '*' expr (9) + expr : expr . '/' expr (10) + expr : expr . '%' expr (11) + expr : expr . '&' expr (12) + expr : expr . '|' expr (13) + + '|' shift 16 + '&' shift 17 + '+' shift 18 + '-' shift 19 + '*' shift 20 + '/' shift 21 + '%' shift 22 + '\n' reduce 5 + + +state 25 + expr : '(' expr ')' . (6) + + . reduce 6 + + +state 26 + expr : expr . '+' expr (7) + expr : expr . '-' expr (8) + expr : expr . '*' expr (9) + expr : expr . '/' expr (10) + expr : expr . '%' expr (11) + expr : expr . '&' expr (12) + expr : expr . '|' expr (13) + expr : expr '|' expr . (13) + + '&' shift 17 + '+' shift 18 + '-' shift 19 + '*' shift 20 + '/' shift 21 + '%' shift 22 + '|' reduce 13 + '\n' reduce 13 + ')' reduce 13 + + +state 27 + expr : expr . '+' expr (7) + expr : expr . '-' expr (8) + expr : expr . '*' expr (9) + expr : expr . '/' expr (10) + expr : expr . '%' expr (11) + expr : expr . '&' expr (12) + expr : expr '&' expr . (12) + expr : expr . '|' expr (13) + + '+' shift 18 + '-' shift 19 + '*' shift 20 + '/' shift 21 + '%' shift 22 + '|' reduce 12 + '&' reduce 12 + '\n' reduce 12 + ')' reduce 12 + + +state 28 + expr : expr . '+' expr (7) + expr : expr '+' expr . (7) + expr : expr . '-' expr (8) + expr : expr . '*' expr (9) + expr : expr . '/' expr (10) + expr : expr . '%' expr (11) + expr : expr . '&' expr (12) + expr : expr . '|' expr (13) + + '*' shift 20 + '/' shift 21 + '%' shift 22 + '|' reduce 7 + '&' reduce 7 + '+' reduce 7 + '-' reduce 7 + '\n' reduce 7 + ')' reduce 7 + + +state 29 + expr : expr . '+' expr (7) + expr : expr . '-' expr (8) + expr : expr '-' expr . (8) + expr : expr . '*' expr (9) + expr : expr . '/' expr (10) + expr : expr . '%' expr (11) + expr : expr . '&' expr (12) + expr : expr . '|' expr (13) + + '*' shift 20 + '/' shift 21 + '%' shift 22 + '|' reduce 8 + '&' reduce 8 + '+' reduce 8 + '-' reduce 8 + '\n' reduce 8 + ')' reduce 8 + + +state 30 + expr : expr . '+' expr (7) + expr : expr . '-' expr (8) + expr : expr . '*' expr (9) + expr : expr '*' expr . (9) + expr : expr . '/' expr (10) + expr : expr . '%' expr (11) + expr : expr . '&' expr (12) + expr : expr . '|' expr (13) + + . reduce 9 + + +state 31 + expr : expr . '+' expr (7) + expr : expr . '-' expr (8) + expr : expr . '*' expr (9) + expr : expr . '/' expr (10) + expr : expr '/' expr . (10) + expr : expr . '%' expr (11) + expr : expr . '&' expr (12) + expr : expr . '|' expr (13) + + . reduce 10 + + +state 32 + expr : expr . '+' expr (7) + expr : expr . '-' expr (8) + expr : expr . '*' expr (9) + expr : expr . '/' expr (10) + expr : expr . '%' expr (11) + expr : expr '%' expr . (11) + expr : expr . '&' expr (12) + expr : expr . '|' expr (13) + + . reduce 11 + + +16 terminals, 5 nonterminals +19 grammar rules, 33 states diff --git a/test/calc.tab.c b/test/calc.tab.c new file mode 100644 index 000000000000..de039ec8f263 --- /dev/null +++ b/test/calc.tab.c @@ -0,0 +1,673 @@ +#ifndef lint +static const char yysccsid[] = "@(#)yaccpar 1.9 (Berkeley) 02/21/93"; +#endif + +#define YYBYACC 1 +#define YYMAJOR 1 +#define YYMINOR 9 + +#define YYEMPTY (-1) +#define yyclearin (yychar = YYEMPTY) +#define yyerrok (yyerrflag = 0) +#define YYRECOVERING() (yyerrflag != 0) + + +#ifndef yyparse +#define yyparse calc_parse +#endif /* yyparse */ + +#ifndef yylex +#define yylex calc_lex +#endif /* yylex */ + +#ifndef yyerror +#define yyerror calc_error +#endif /* yyerror */ + +#ifndef yychar +#define yychar calc_char +#endif /* yychar */ + +#ifndef yyval +#define yyval calc_val +#endif /* yyval */ + +#ifndef yylval +#define yylval calc_lval +#endif /* yylval */ + +#ifndef yydebug +#define yydebug calc_debug +#endif /* yydebug */ + +#ifndef yynerrs +#define yynerrs calc_nerrs +#endif /* yynerrs */ + +#ifndef yyerrflag +#define yyerrflag calc_errflag +#endif /* yyerrflag */ + +#ifndef yylhs +#define yylhs calc_lhs +#endif /* yylhs */ + +#ifndef yylen +#define yylen calc_len +#endif /* yylen */ + +#ifndef yydefred +#define yydefred calc_defred +#endif /* yydefred */ + +#ifndef yydgoto +#define yydgoto calc_dgoto +#endif /* yydgoto */ + +#ifndef yysindex +#define yysindex calc_sindex +#endif /* yysindex */ + +#ifndef yyrindex +#define yyrindex calc_rindex +#endif /* yyrindex */ + +#ifndef yygindex +#define yygindex calc_gindex +#endif /* yygindex */ + +#ifndef yytable +#define yytable calc_table +#endif /* yytable */ + +#ifndef yycheck +#define yycheck calc_check +#endif /* yycheck */ + +#ifndef yyname +#define yyname calc_name +#endif /* yyname */ + +#ifndef yyrule +#define yyrule calc_rule +#endif /* yyrule */ +#define YYPREFIX "calc_" + +#define YYPURE 0 + +#line 2 "calc.y" +# include <stdio.h> +# include <ctype.h> + +int regs[26]; +int base; + +extern int yylex(void); +static void yyerror(const char *s); + +#line 109 "calc.tab.c" + +#ifndef YYSTYPE +typedef int YYSTYPE; +#endif + +/* compatibility with bison */ +#ifdef YYPARSE_PARAM +/* compatibility with FreeBSD */ +# ifdef YYPARSE_PARAM_TYPE +# define YYPARSE_DECL() yyparse(YYPARSE_PARAM_TYPE YYPARSE_PARAM) +# else +# define YYPARSE_DECL() yyparse(void *YYPARSE_PARAM) +# endif +#else +# define YYPARSE_DECL() yyparse(void) +#endif + +/* Parameters sent to lex. */ +#ifdef YYLEX_PARAM +# define YYLEX_DECL() yylex(void *YYLEX_PARAM) +# define YYLEX yylex(YYLEX_PARAM) +#else +# define YYLEX_DECL() yylex(void) +# define YYLEX yylex() +#endif + +/* Parameters sent to yyerror. */ +#ifndef YYERROR_DECL +#define YYERROR_DECL() yyerror(const char *s) +#endif +#ifndef YYERROR_CALL +#define YYERROR_CALL(msg) yyerror(msg) +#endif + +extern int YYPARSE_DECL(); + +#define DIGIT 257 +#define LETTER 258 +#define UMINUS 259 +#define YYERRCODE 256 +static const short calc_lhs[] = { -1, + 0, 0, 0, 1, 1, 2, 2, 2, 2, 2, + 2, 2, 2, 2, 2, 2, 3, 3, +}; +static const short calc_len[] = { 2, + 0, 3, 3, 1, 3, 3, 3, 3, 3, 3, + 3, 3, 3, 2, 1, 1, 1, 2, +}; +static const short calc_defred[] = { 1, + 0, 0, 17, 0, 0, 0, 0, 0, 0, 3, + 0, 15, 14, 0, 2, 0, 0, 0, 0, 0, + 0, 0, 18, 0, 6, 0, 0, 0, 0, 9, + 10, 11, +}; +static const short calc_dgoto[] = { 1, + 7, 8, 9, +}; +static const short calc_sindex[] = { 0, + -40, -7, 0, -55, -38, -38, 1, -29, -247, 0, + -38, 0, 0, 22, 0, -38, -38, -38, -38, -38, + -38, -38, 0, -29, 0, 51, 60, -20, -20, 0, + 0, 0, +}; +static const short calc_rindex[] = { 0, + 0, 0, 0, 2, 0, 0, 0, 9, -9, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 10, 0, -6, 14, 5, 13, 0, + 0, 0, +}; +static const short calc_gindex[] = { 0, + 0, 65, 0, +}; +#define YYTABLESIZE 220 +static const short calc_table[] = { 6, + 16, 6, 10, 13, 5, 11, 5, 22, 17, 23, + 15, 15, 20, 18, 7, 19, 22, 21, 4, 5, + 0, 20, 8, 12, 0, 0, 21, 16, 16, 0, + 0, 16, 16, 16, 13, 16, 0, 16, 15, 15, + 0, 0, 7, 15, 15, 7, 15, 7, 15, 7, + 8, 12, 0, 8, 12, 8, 0, 8, 22, 17, + 0, 0, 25, 20, 18, 0, 19, 0, 21, 13, + 14, 0, 0, 0, 0, 24, 0, 0, 0, 0, + 26, 27, 28, 29, 30, 31, 32, 22, 17, 0, + 0, 0, 20, 18, 16, 19, 22, 21, 0, 0, + 0, 20, 18, 0, 19, 0, 21, 0, 0, 0, + 0, 0, 0, 0, 16, 0, 0, 13, 0, 0, + 0, 0, 0, 0, 0, 15, 0, 0, 7, 0, + 0, 0, 0, 0, 0, 0, 8, 12, 0, 0, + 0, 0, 0, 0, 0, 16, 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, 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, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 2, 3, 4, 3, 12, +}; +static const short calc_check[] = { 40, + 10, 40, 10, 10, 45, 61, 45, 37, 38, 257, + 10, 10, 42, 43, 10, 45, 37, 47, 10, 10, + -1, 42, 10, 10, -1, -1, 47, 37, 38, -1, + -1, 41, 42, 43, 41, 45, -1, 47, 37, 38, + -1, -1, 38, 42, 43, 41, 45, 43, 47, 45, + 38, 38, -1, 41, 41, 43, -1, 45, 37, 38, + -1, -1, 41, 42, 43, -1, 45, -1, 47, 5, + 6, -1, -1, -1, -1, 11, -1, -1, -1, -1, + 16, 17, 18, 19, 20, 21, 22, 37, 38, -1, + -1, -1, 42, 43, 124, 45, 37, 47, -1, -1, + -1, 42, 43, -1, 45, -1, 47, -1, -1, -1, + -1, -1, -1, -1, 124, -1, -1, 124, -1, -1, + -1, -1, -1, -1, -1, 124, -1, -1, 124, -1, + -1, -1, -1, -1, -1, -1, 124, 124, -1, -1, + -1, -1, -1, -1, -1, 124, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, 256, 257, 258, 257, 258, +}; +#define YYFINAL 1 +#ifndef YYDEBUG +#define YYDEBUG 0 +#endif +#define YYMAXTOKEN 259 +#if YYDEBUG +static const char *yyname[] = { + +"end-of-file",0,0,0,0,0,0,0,0,0,"'\\n'",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,"'-'",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,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,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,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,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,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,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,0,0,0,0,0,0, +0,0,0,0,0,0,"DIGIT","LETTER","UMINUS", +}; +static const char *yyrule[] = { +"$accept : list", +"list :", +"list : list stat '\\n'", +"list : list error '\\n'", +"stat : expr", +"stat : LETTER '=' expr", +"expr : '(' expr ')'", +"expr : expr '+' expr", +"expr : expr '-' expr", +"expr : expr '*' expr", +"expr : expr '/' expr", +"expr : expr '%' expr", +"expr : expr '&' expr", +"expr : expr '|' expr", +"expr : '-' expr", +"expr : LETTER", +"expr : number", +"number : DIGIT", +"number : number DIGIT", + +}; +#endif + +int yydebug; +int yynerrs; + +int yyerrflag; +int yychar; +YYSTYPE yyval; +YYSTYPE yylval; + +/* define the initial stack-sizes */ +#ifdef YYSTACKSIZE +#undef YYMAXDEPTH +#define YYMAXDEPTH YYSTACKSIZE +#else +#ifdef YYMAXDEPTH +#define YYSTACKSIZE YYMAXDEPTH +#else +#define YYSTACKSIZE 500 +#define YYMAXDEPTH 500 +#endif +#endif + +#define YYINITSTACKSIZE 500 + +typedef struct { + unsigned stacksize; + short *s_base; + short *s_mark; + short *s_last; + YYSTYPE *l_base; + YYSTYPE *l_mark; +} YYSTACKDATA; +/* variables for the parser stack */ +static YYSTACKDATA yystack; +#line 66 "calc.y" + /* start of programs */ + +int +main (void) +{ + while(!feof(stdin)) { + yyparse(); + } + return 0; +} + +static void +yyerror(const char *s) +{ + fprintf(stderr, "%s\n", s); +} + +int +yylex(void) +{ + /* lexical analysis routine */ + /* returns LETTER for a lower case letter, yylval = 0 through 25 */ + /* return DIGIT for a digit, yylval = 0 through 9 */ + /* all other characters are returned immediately */ + + int c; + + while( (c=getchar()) == ' ' ) { /* skip blanks */ } + + /* c is now nonblank */ + + if( islower( c )) { + yylval = c - 'a'; + return ( LETTER ); + } + if( isdigit( c )) { + yylval = c - '0'; + return ( DIGIT ); + } + return( c ); +} +#line 347 "calc.tab.c" + +#if YYDEBUG +#include <stdio.h> /* needed for printf */ +#endif + +#include <stdlib.h> /* needed for malloc, etc */ +#include <string.h> /* needed for memset */ + +/* allocate initial stack or double stack size, up to YYMAXDEPTH */ +static int yygrowstack(YYSTACKDATA *data) +{ + int i; + unsigned newsize; + short *newss; + YYSTYPE *newvs; + + if ((newsize = data->stacksize) == 0) + newsize = YYINITSTACKSIZE; + else if (newsize >= YYMAXDEPTH) + return -1; + else if ((newsize *= 2) > YYMAXDEPTH) + newsize = YYMAXDEPTH; + + i = data->s_mark - data->s_base; + newss = (short *)realloc(data->s_base, newsize * sizeof(*newss)); + if (newss == 0) + return -1; + + data->s_base = newss; + data->s_mark = newss + i; + + newvs = (YYSTYPE *)realloc(data->l_base, newsize * sizeof(*newvs)); + if (newvs == 0) + return -1; + + data->l_base = newvs; + data->l_mark = newvs + i; + + data->stacksize = newsize; + data->s_last = data->s_base + newsize - 1; + return 0; +} + +#if YYPURE || defined(YY_NO_LEAKS) +static void yyfreestack(YYSTACKDATA *data) +{ + free(data->s_base); + free(data->l_base); + memset(data, 0, sizeof(*data)); +} +#else +#define yyfreestack(data) /* nothing */ +#endif + +#define YYABORT goto yyabort +#define YYREJECT goto yyabort +#define YYACCEPT goto yyaccept +#define YYERROR goto yyerrlab + +int +YYPARSE_DECL() +{ + int yym, yyn, yystate; +#if YYDEBUG + const char *yys; + + if ((yys = getenv("YYDEBUG")) != 0) + { + yyn = *yys; + if (yyn >= '0' && yyn <= '9') + yydebug = yyn - '0'; + } +#endif + + yynerrs = 0; + yyerrflag = 0; + yychar = YYEMPTY; + yystate = 0; + +#if YYPURE + memset(&yystack, 0, sizeof(yystack)); +#endif + + if (yystack.s_base == NULL && yygrowstack(&yystack)) goto yyoverflow; + yystack.s_mark = yystack.s_base; + yystack.l_mark = yystack.l_base; + yystate = 0; + *yystack.s_mark = 0; + +yyloop: + if ((yyn = yydefred[yystate]) != 0) goto yyreduce; + if (yychar < 0) + { + if ((yychar = YYLEX) < 0) yychar = 0; +#if YYDEBUG + if (yydebug) + { + yys = 0; + if (yychar <= YYMAXTOKEN) yys = yyname[yychar]; + if (!yys) yys = "illegal-symbol"; + printf("%sdebug: state %d, reading %d (%s)\n", + YYPREFIX, yystate, yychar, yys); + } +#endif + } + if ((yyn = yysindex[yystate]) && (yyn += yychar) >= 0 && + yyn <= YYTABLESIZE && yycheck[yyn] == yychar) + { +#if YYDEBUG + if (yydebug) + printf("%sdebug: state %d, shifting to state %d\n", + YYPREFIX, yystate, yytable[yyn]); +#endif + if (yystack.s_mark >= yystack.s_last && yygrowstack(&yystack)) + { + goto yyoverflow; + } + yystate = yytable[yyn]; + *++yystack.s_mark = yytable[yyn]; + *++yystack.l_mark = yylval; + yychar = YYEMPTY; + if (yyerrflag > 0) --yyerrflag; + goto yyloop; + } + if ((yyn = yyrindex[yystate]) && (yyn += yychar) >= 0 && + yyn <= YYTABLESIZE && yycheck[yyn] == yychar) + { + yyn = yytable[yyn]; + goto yyreduce; + } + if (yyerrflag) goto yyinrecovery; + + yyerror("syntax error"); + + goto yyerrlab; + +yyerrlab: + ++yynerrs; + +yyinrecovery: + if (yyerrflag < 3) + { + yyerrflag = 3; + for (;;) + { + if ((yyn = yysindex[*yystack.s_mark]) && (yyn += YYERRCODE) >= 0 && + yyn <= YYTABLESIZE && yycheck[yyn] == YYERRCODE) + { +#if YYDEBUG + if (yydebug) + printf("%sdebug: state %d, error recovery shifting\ + to state %d\n", YYPREFIX, *yystack.s_mark, yytable[yyn]); +#endif + if (yystack.s_mark >= yystack.s_last && yygrowstack(&yystack)) + { + goto yyoverflow; + } + yystate = yytable[yyn]; + *++yystack.s_mark = yytable[yyn]; + *++yystack.l_mark = yylval; + goto yyloop; + } + else + { +#if YYDEBUG + if (yydebug) + printf("%sdebug: error recovery discarding state %d\n", + YYPREFIX, *yystack.s_mark); +#endif + if (yystack.s_mark <= yystack.s_base) goto yyabort; + --yystack.s_mark; + --yystack.l_mark; + } + } + } + else + { + if (yychar == 0) goto yyabort; +#if YYDEBUG + if (yydebug) + { + yys = 0; + if (yychar <= YYMAXTOKEN) yys = yyname[yychar]; + if (!yys) yys = "illegal-symbol"; + printf("%sdebug: state %d, error recovery discards token %d (%s)\n", + YYPREFIX, yystate, yychar, yys); + } +#endif + yychar = YYEMPTY; + goto yyloop; + } + +yyreduce: +#if YYDEBUG + if (yydebug) + printf("%sdebug: state %d, reducing by rule %d (%s)\n", + YYPREFIX, yystate, yyn, yyrule[yyn]); +#endif + yym = yylen[yyn]; + if (yym) + yyval = yystack.l_mark[1-yym]; + else + memset(&yyval, 0, sizeof yyval); + switch (yyn) + { +case 3: +#line 28 "calc.y" + { yyerrok ; } +break; +case 4: +#line 32 "calc.y" + { printf("%d\n",yystack.l_mark[0]);} +break; +case 5: +#line 34 "calc.y" + { regs[yystack.l_mark[-2]] = yystack.l_mark[0]; } +break; +case 6: +#line 38 "calc.y" + { yyval = yystack.l_mark[-1]; } +break; +case 7: +#line 40 "calc.y" + { yyval = yystack.l_mark[-2] + yystack.l_mark[0]; } +break; +case 8: +#line 42 "calc.y" + { yyval = yystack.l_mark[-2] - yystack.l_mark[0]; } +break; +case 9: +#line 44 "calc.y" + { yyval = yystack.l_mark[-2] * yystack.l_mark[0]; } +break; +case 10: +#line 46 "calc.y" + { yyval = yystack.l_mark[-2] / yystack.l_mark[0]; } +break; +case 11: +#line 48 "calc.y" + { yyval = yystack.l_mark[-2] % yystack.l_mark[0]; } +break; +case 12: +#line 50 "calc.y" + { yyval = yystack.l_mark[-2] & yystack.l_mark[0]; } +break; +case 13: +#line 52 "calc.y" + { yyval = yystack.l_mark[-2] | yystack.l_mark[0]; } +break; +case 14: +#line 54 "calc.y" + { yyval = - yystack.l_mark[0]; } +break; +case 15: +#line 56 "calc.y" + { yyval = regs[yystack.l_mark[0]]; } +break; +case 17: +#line 61 "calc.y" + { yyval = yystack.l_mark[0]; base = (yystack.l_mark[0]==0) ? 8 : 10; } +break; +case 18: +#line 63 "calc.y" + { yyval = base * yystack.l_mark[-1] + yystack.l_mark[0]; } +break; +#line 613 "calc.tab.c" + } + yystack.s_mark -= yym; + yystate = *yystack.s_mark; + yystack.l_mark -= yym; + yym = yylhs[yyn]; + if (yystate == 0 && yym == 0) + { +#if YYDEBUG + if (yydebug) + printf("%sdebug: after reduction, shifting from state 0 to\ + state %d\n", YYPREFIX, YYFINAL); +#endif + yystate = YYFINAL; + *++yystack.s_mark = YYFINAL; + *++yystack.l_mark = yyval; + if (yychar < 0) + { + if ((yychar = YYLEX) < 0) yychar = 0; +#if YYDEBUG + if (yydebug) + { + yys = 0; + if (yychar <= YYMAXTOKEN) yys = yyname[yychar]; + if (!yys) yys = "illegal-symbol"; + printf("%sdebug: state %d, reading %d (%s)\n", + YYPREFIX, YYFINAL, yychar, yys); + } +#endif + } + if (yychar == 0) goto yyaccept; + goto yyloop; + } + if ((yyn = yygindex[yym]) && (yyn += yystate) >= 0 && + yyn <= YYTABLESIZE && yycheck[yyn] == yystate) + yystate = yytable[yyn]; + else + yystate = yydgoto[yym]; +#if YYDEBUG + if (yydebug) + printf("%sdebug: after reduction, shifting from state %d \ +to state %d\n", YYPREFIX, *yystack.s_mark, yystate); +#endif + if (yystack.s_mark >= yystack.s_last && yygrowstack(&yystack)) + { + goto yyoverflow; + } + *++yystack.s_mark = (short) yystate; + *++yystack.l_mark = yyval; + goto yyloop; + +yyoverflow: + yyerror("yacc stack overflow"); + +yyabort: + yyfreestack(&yystack); + return (1); + +yyaccept: + yyfreestack(&yystack); + return (0); +} diff --git a/test/calc.tab.h b/test/calc.tab.h new file mode 100644 index 000000000000..19211182d6b3 --- /dev/null +++ b/test/calc.tab.h @@ -0,0 +1,3 @@ +#define DIGIT 257 +#define LETTER 258 +#define UMINUS 259 diff --git a/test/calc.y b/test/calc.y new file mode 100644 index 000000000000..c2e5a898c93d --- /dev/null +++ b/test/calc.y @@ -0,0 +1,106 @@ +%{ +# include <stdio.h> +# include <ctype.h> + +int regs[26]; +int base; + +extern int yylex(void); +static void yyerror(const char *s); + +%} + +%start list + +%token DIGIT LETTER + +%left '|' +%left '&' +%left '+' '-' +%left '*' '/' '%' +%left UMINUS /* supplies precedence for unary minus */ + +%% /* beginning of rules section */ + +list : /* empty */ + | list stat '\n' + | list error '\n' + { yyerrok ; } + ; + +stat : expr + { printf("%d\n",$1);} + | LETTER '=' expr + { regs[$1] = $3; } + ; + +expr : '(' expr ')' + { $$ = $2; } + | expr '+' expr + { $$ = $1 + $3; } + | expr '-' expr + { $$ = $1 - $3; } + | expr '*' expr + { $$ = $1 * $3; } + | expr '/' expr + { $$ = $1 / $3; } + | expr '%' expr + { $$ = $1 % $3; } + | expr '&' expr + { $$ = $1 & $3; } + | expr '|' expr + { $$ = $1 | $3; } + | '-' expr %prec UMINUS + { $$ = - $2; } + | LETTER + { $$ = regs[$1]; } + | number + ; + +number: DIGIT + { $$ = $1; base = ($1==0) ? 8 : 10; } + | number DIGIT + { $$ = base * $1 + $2; } + ; + +%% /* start of programs */ + +int +main (void) +{ + while(!feof(stdin)) { + yyparse(); + } + return 0; +} + +static void +yyerror(const char *s) +{ + fprintf(stderr, "%s\n", s); +} + +int +yylex(void) +{ + /* lexical analysis routine */ + /* returns LETTER for a lower case letter, yylval = 0 through 25 */ + /* return DIGIT for a digit, yylval = 0 through 9 */ + /* all other characters are returned immediately */ + + int c; + + while( (c=getchar()) == ' ' ) { /* skip blanks */ } + + /* c is now nonblank */ + + if( islower( c )) { + yylval = c - 'a'; + return ( LETTER ); + } + if( isdigit( c )) { + yylval = c - '0'; + return ( DIGIT ); + } + return( c ); +} diff --git a/test/calc1.output b/test/calc1.output new file mode 100644 index 000000000000..2b628d47ddba --- /dev/null +++ b/test/calc1.output @@ -0,0 +1,877 @@ + 0 $accept : line $end + + 1 lines : + 2 | lines line + + 3 line : dexp '\n' + 4 | vexp '\n' + 5 | DREG '=' dexp '\n' + 6 | VREG '=' vexp '\n' + 7 | error '\n' + + 8 dexp : CONST + 9 | DREG + 10 | dexp '+' dexp + 11 | dexp '-' dexp + 12 | dexp '*' dexp + 13 | dexp '/' dexp + 14 | '-' dexp + 15 | '(' dexp ')' + + 16 vexp : dexp + 17 | '(' dexp ',' dexp ')' + 18 | VREG + 19 | vexp '+' vexp + 20 | dexp '+' vexp + 21 | vexp '-' vexp + 22 | dexp '-' vexp + 23 | vexp '*' vexp + 24 | dexp '*' vexp + 25 | vexp '/' vexp + 26 | dexp '/' vexp + 27 | '-' vexp + 28 | '(' vexp ')' + +state 0 + $accept : . line $end (0) + + error shift 1 + DREG shift 2 + VREG shift 3 + CONST shift 4 + '-' shift 5 + '(' shift 6 + . error + + line goto 7 + dexp goto 8 + vexp goto 9 + + +state 1 + line : error . '\n' (7) + + '\n' shift 10 + . error + + +state 2 + line : DREG . '=' dexp '\n' (5) + dexp : DREG . (9) + + '=' shift 11 + '+' reduce 9 + '-' reduce 9 + '*' reduce 9 + '/' reduce 9 + '\n' reduce 9 + + +state 3 + line : VREG . '=' vexp '\n' (6) + vexp : VREG . (18) + + '=' shift 12 + '+' reduce 18 + '-' reduce 18 + '*' reduce 18 + '/' reduce 18 + '\n' reduce 18 + + +state 4 + dexp : CONST . (8) + + . reduce 8 + + +state 5 + dexp : '-' . dexp (14) + vexp : '-' . vexp (27) + + DREG shift 13 + VREG shift 14 + CONST shift 4 + '-' shift 5 + '(' shift 6 + . error + + dexp goto 15 + vexp goto 16 + + +state 6 + dexp : '(' . dexp ')' (15) + vexp : '(' . dexp ',' dexp ')' (17) + vexp : '(' . vexp ')' (28) + + DREG shift 13 + VREG shift 14 + CONST shift 4 + '-' shift 5 + '(' shift 6 + . error + + dexp goto 17 + vexp goto 18 + + +state 7 + $accept : line . $end (0) + + $end accept + + +8: shift/reduce conflict (shift 19, reduce 16) on '+' +8: shift/reduce conflict (shift 20, reduce 16) on '-' +8: shift/reduce conflict (shift 21, reduce 16) on '*' +8: shift/reduce conflict (shift 22, reduce 16) on '/' +8: shift/reduce conflict (shift 23, reduce 16) on '\n' +state 8 + line : dexp . '\n' (3) + dexp : dexp . '+' dexp (10) + dexp : dexp . '-' dexp (11) + dexp : dexp . '*' dexp (12) + dexp : dexp . '/' dexp (13) + vexp : dexp . (16) + vexp : dexp . '+' vexp (20) + vexp : dexp . '-' vexp (22) + vexp : dexp . '*' vexp (24) + vexp : dexp . '/' vexp (26) + + '+' shift 19 + '-' shift 20 + '*' shift 21 + '/' shift 22 + '\n' shift 23 + + +state 9 + line : vexp . '\n' (4) + vexp : vexp . '+' vexp (19) + vexp : vexp . '-' vexp (21) + vexp : vexp . '*' vexp (23) + vexp : vexp . '/' vexp (25) + + '+' shift 24 + '-' shift 25 + '*' shift 26 + '/' shift 27 + '\n' shift 28 + . error + + +state 10 + line : error '\n' . (7) + + . reduce 7 + + +state 11 + line : DREG '=' . dexp '\n' (5) + + DREG shift 13 + CONST shift 4 + '-' shift 29 + '(' shift 30 + . error + + dexp goto 31 + + +state 12 + line : VREG '=' . vexp '\n' (6) + + DREG shift 13 + VREG shift 14 + CONST shift 4 + '-' shift 5 + '(' shift 6 + . error + + dexp goto 32 + vexp goto 33 + + +state 13 + dexp : DREG . (9) + + . reduce 9 + + +state 14 + vexp : VREG . (18) + + . reduce 18 + + +15: reduce/reduce conflict (reduce 14, reduce 16) on '+' +15: reduce/reduce conflict (reduce 14, reduce 16) on '-' +15: reduce/reduce conflict (reduce 14, reduce 16) on '*' +15: reduce/reduce conflict (reduce 14, reduce 16) on '/' +15: reduce/reduce conflict (reduce 14, reduce 16) on '\n' +15: reduce/reduce conflict (reduce 14, reduce 16) on ')' +state 15 + dexp : dexp . '+' dexp (10) + dexp : dexp . '-' dexp (11) + dexp : dexp . '*' dexp (12) + dexp : dexp . '/' dexp (13) + dexp : '-' dexp . (14) + vexp : dexp . (16) + vexp : dexp . '+' vexp (20) + vexp : dexp . '-' vexp (22) + vexp : dexp . '*' vexp (24) + vexp : dexp . '/' vexp (26) + + . reduce 14 + + +state 16 + vexp : vexp . '+' vexp (19) + vexp : vexp . '-' vexp (21) + vexp : vexp . '*' vexp (23) + vexp : vexp . '/' vexp (25) + vexp : '-' vexp . (27) + + . reduce 27 + + +17: shift/reduce conflict (shift 19, reduce 16) on '+' +17: shift/reduce conflict (shift 20, reduce 16) on '-' +17: shift/reduce conflict (shift 21, reduce 16) on '*' +17: shift/reduce conflict (shift 22, reduce 16) on '/' +17: shift/reduce conflict (shift 34, reduce 16) on ')' +state 17 + dexp : dexp . '+' dexp (10) + dexp : dexp . '-' dexp (11) + dexp : dexp . '*' dexp (12) + dexp : dexp . '/' dexp (13) + dexp : '(' dexp . ')' (15) + vexp : dexp . (16) + vexp : '(' dexp . ',' dexp ')' (17) + vexp : dexp . '+' vexp (20) + vexp : dexp . '-' vexp (22) + vexp : dexp . '*' vexp (24) + vexp : dexp . '/' vexp (26) + + '+' shift 19 + '-' shift 20 + '*' shift 21 + '/' shift 22 + ')' shift 34 + ',' shift 35 + + +state 18 + vexp : vexp . '+' vexp (19) + vexp : vexp . '-' vexp (21) + vexp : vexp . '*' vexp (23) + vexp : vexp . '/' vexp (25) + vexp : '(' vexp . ')' (28) + + '+' shift 24 + '-' shift 25 + '*' shift 26 + '/' shift 27 + ')' shift 36 + . error + + +state 19 + dexp : dexp '+' . dexp (10) + vexp : dexp '+' . vexp (20) + + DREG shift 13 + VREG shift 14 + CONST shift 4 + '-' shift 5 + '(' shift 6 + . error + + dexp goto 37 + vexp goto 38 + + +state 20 + dexp : dexp '-' . dexp (11) + vexp : dexp '-' . vexp (22) + + DREG shift 13 + VREG shift 14 + CONST shift 4 + '-' shift 5 + '(' shift 6 + . error + + dexp goto 39 + vexp goto 40 + + +state 21 + dexp : dexp '*' . dexp (12) + vexp : dexp '*' . vexp (24) + + DREG shift 13 + VREG shift 14 + CONST shift 4 + '-' shift 5 + '(' shift 6 + . error + + dexp goto 41 + vexp goto 42 + + +state 22 + dexp : dexp '/' . dexp (13) + vexp : dexp '/' . vexp (26) + + DREG shift 13 + VREG shift 14 + CONST shift 4 + '-' shift 5 + '(' shift 6 + . error + + dexp goto 43 + vexp goto 44 + + +state 23 + line : dexp '\n' . (3) + + . reduce 3 + + +state 24 + vexp : vexp '+' . vexp (19) + + DREG shift 13 + VREG shift 14 + CONST shift 4 + '-' shift 5 + '(' shift 6 + . error + + dexp goto 32 + vexp goto 45 + + +state 25 + vexp : vexp '-' . vexp (21) + + DREG shift 13 + VREG shift 14 + CONST shift 4 + '-' shift 5 + '(' shift 6 + . error + + dexp goto 32 + vexp goto 46 + + +state 26 + vexp : vexp '*' . vexp (23) + + DREG shift 13 + VREG shift 14 + CONST shift 4 + '-' shift 5 + '(' shift 6 + . error + + dexp goto 32 + vexp goto 47 + + +state 27 + vexp : vexp '/' . vexp (25) + + DREG shift 13 + VREG shift 14 + CONST shift 4 + '-' shift 5 + '(' shift 6 + . error + + dexp goto 32 + vexp goto 48 + + +state 28 + line : vexp '\n' . (4) + + . reduce 4 + + +state 29 + dexp : '-' . dexp (14) + + DREG shift 13 + CONST shift 4 + '-' shift 29 + '(' shift 30 + . error + + dexp goto 49 + + +state 30 + dexp : '(' . dexp ')' (15) + + DREG shift 13 + CONST shift 4 + '-' shift 29 + '(' shift 30 + . error + + dexp goto 50 + + +state 31 + line : DREG '=' dexp . '\n' (5) + dexp : dexp . '+' dexp (10) + dexp : dexp . '-' dexp (11) + dexp : dexp . '*' dexp (12) + dexp : dexp . '/' dexp (13) + + '+' shift 51 + '-' shift 52 + '*' shift 53 + '/' shift 54 + '\n' shift 55 + . error + + +32: shift/reduce conflict (shift 19, reduce 16) on '+' +32: shift/reduce conflict (shift 20, reduce 16) on '-' +32: shift/reduce conflict (shift 21, reduce 16) on '*' +32: shift/reduce conflict (shift 22, reduce 16) on '/' +state 32 + dexp : dexp . '+' dexp (10) + dexp : dexp . '-' dexp (11) + dexp : dexp . '*' dexp (12) + dexp : dexp . '/' dexp (13) + vexp : dexp . (16) + vexp : dexp . '+' vexp (20) + vexp : dexp . '-' vexp (22) + vexp : dexp . '*' vexp (24) + vexp : dexp . '/' vexp (26) + + '+' shift 19 + '-' shift 20 + '*' shift 21 + '/' shift 22 + '\n' reduce 16 + ')' reduce 16 + + +state 33 + line : VREG '=' vexp . '\n' (6) + vexp : vexp . '+' vexp (19) + vexp : vexp . '-' vexp (21) + vexp : vexp . '*' vexp (23) + vexp : vexp . '/' vexp (25) + + '+' shift 24 + '-' shift 25 + '*' shift 26 + '/' shift 27 + '\n' shift 56 + . error + + +state 34 + dexp : '(' dexp ')' . (15) + + . reduce 15 + + +state 35 + vexp : '(' dexp ',' . dexp ')' (17) + + DREG shift 13 + CONST shift 4 + '-' shift 29 + '(' shift 30 + . error + + dexp goto 57 + + +state 36 + vexp : '(' vexp ')' . (28) + + . reduce 28 + + +37: reduce/reduce conflict (reduce 10, reduce 16) on '+' +37: reduce/reduce conflict (reduce 10, reduce 16) on '-' +37: shift/reduce conflict (shift 21, reduce 16) on '*' +37: shift/reduce conflict (shift 22, reduce 16) on '/' +37: reduce/reduce conflict (reduce 10, reduce 16) on '\n' +37: reduce/reduce conflict (reduce 10, reduce 16) on ')' +state 37 + dexp : dexp . '+' dexp (10) + dexp : dexp '+' dexp . (10) + dexp : dexp . '-' dexp (11) + dexp : dexp . '*' dexp (12) + dexp : dexp . '/' dexp (13) + vexp : dexp . (16) + vexp : dexp . '+' vexp (20) + vexp : dexp . '-' vexp (22) + vexp : dexp . '*' vexp (24) + vexp : dexp . '/' vexp (26) + + '*' shift 21 + '/' shift 22 + '+' reduce 10 + '-' reduce 10 + '\n' reduce 10 + ')' reduce 10 + ',' reduce 10 + + +state 38 + vexp : vexp . '+' vexp (19) + vexp : dexp '+' vexp . (20) + vexp : vexp . '-' vexp (21) + vexp : vexp . '*' vexp (23) + vexp : vexp . '/' vexp (25) + + '*' shift 26 + '/' shift 27 + '+' reduce 20 + '-' reduce 20 + '\n' reduce 20 + ')' reduce 20 + + +39: reduce/reduce conflict (reduce 11, reduce 16) on '+' +39: reduce/reduce conflict (reduce 11, reduce 16) on '-' +39: shift/reduce conflict (shift 21, reduce 16) on '*' +39: shift/reduce conflict (shift 22, reduce 16) on '/' +39: reduce/reduce conflict (reduce 11, reduce 16) on '\n' +39: reduce/reduce conflict (reduce 11, reduce 16) on ')' +state 39 + dexp : dexp . '+' dexp (10) + dexp : dexp . '-' dexp (11) + dexp : dexp '-' dexp . (11) + dexp : dexp . '*' dexp (12) + dexp : dexp . '/' dexp (13) + vexp : dexp . (16) + vexp : dexp . '+' vexp (20) + vexp : dexp . '-' vexp (22) + vexp : dexp . '*' vexp (24) + vexp : dexp . '/' vexp (26) + + '*' shift 21 + '/' shift 22 + '+' reduce 11 + '-' reduce 11 + '\n' reduce 11 + ')' reduce 11 + ',' reduce 11 + + +state 40 + vexp : vexp . '+' vexp (19) + vexp : vexp . '-' vexp (21) + vexp : dexp '-' vexp . (22) + vexp : vexp . '*' vexp (23) + vexp : vexp . '/' vexp (25) + + '*' shift 26 + '/' shift 27 + '+' reduce 22 + '-' reduce 22 + '\n' reduce 22 + ')' reduce 22 + + +41: reduce/reduce conflict (reduce 12, reduce 16) on '+' +41: reduce/reduce conflict (reduce 12, reduce 16) on '-' +41: reduce/reduce conflict (reduce 12, reduce 16) on '*' +41: reduce/reduce conflict (reduce 12, reduce 16) on '/' +41: reduce/reduce conflict (reduce 12, reduce 16) on '\n' +41: reduce/reduce conflict (reduce 12, reduce 16) on ')' +state 41 + dexp : dexp . '+' dexp (10) + dexp : dexp . '-' dexp (11) + dexp : dexp . '*' dexp (12) + dexp : dexp '*' dexp . (12) + dexp : dexp . '/' dexp (13) + vexp : dexp . (16) + vexp : dexp . '+' vexp (20) + vexp : dexp . '-' vexp (22) + vexp : dexp . '*' vexp (24) + vexp : dexp . '/' vexp (26) + + . reduce 12 + + +state 42 + vexp : vexp . '+' vexp (19) + vexp : vexp . '-' vexp (21) + vexp : vexp . '*' vexp (23) + vexp : dexp '*' vexp . (24) + vexp : vexp . '/' vexp (25) + + . reduce 24 + + +43: reduce/reduce conflict (reduce 13, reduce 16) on '+' +43: reduce/reduce conflict (reduce 13, reduce 16) on '-' +43: reduce/reduce conflict (reduce 13, reduce 16) on '*' +43: reduce/reduce conflict (reduce 13, reduce 16) on '/' +43: reduce/reduce conflict (reduce 13, reduce 16) on '\n' +43: reduce/reduce conflict (reduce 13, reduce 16) on ')' +state 43 + dexp : dexp . '+' dexp (10) + dexp : dexp . '-' dexp (11) + dexp : dexp . '*' dexp (12) + dexp : dexp . '/' dexp (13) + dexp : dexp '/' dexp . (13) + vexp : dexp . (16) + vexp : dexp . '+' vexp (20) + vexp : dexp . '-' vexp (22) + vexp : dexp . '*' vexp (24) + vexp : dexp . '/' vexp (26) + + . reduce 13 + + +state 44 + vexp : vexp . '+' vexp (19) + vexp : vexp . '-' vexp (21) + vexp : vexp . '*' vexp (23) + vexp : vexp . '/' vexp (25) + vexp : dexp '/' vexp . (26) + + . reduce 26 + + +state 45 + vexp : vexp . '+' vexp (19) + vexp : vexp '+' vexp . (19) + vexp : vexp . '-' vexp (21) + vexp : vexp . '*' vexp (23) + vexp : vexp . '/' vexp (25) + + '*' shift 26 + '/' shift 27 + '+' reduce 19 + '-' reduce 19 + '\n' reduce 19 + ')' reduce 19 + + +state 46 + vexp : vexp . '+' vexp (19) + vexp : vexp . '-' vexp (21) + vexp : vexp '-' vexp . (21) + vexp : vexp . '*' vexp (23) + vexp : vexp . '/' vexp (25) + + '*' shift 26 + '/' shift 27 + '+' reduce 21 + '-' reduce 21 + '\n' reduce 21 + ')' reduce 21 + + +state 47 + vexp : vexp . '+' vexp (19) + vexp : vexp . '-' vexp (21) + vexp : vexp . '*' vexp (23) + vexp : vexp '*' vexp . (23) + vexp : vexp . '/' vexp (25) + + . reduce 23 + + +state 48 + vexp : vexp . '+' vexp (19) + vexp : vexp . '-' vexp (21) + vexp : vexp . '*' vexp (23) + vexp : vexp . '/' vexp (25) + vexp : vexp '/' vexp . (25) + + . reduce 25 + + +state 49 + dexp : dexp . '+' dexp (10) + dexp : dexp . '-' dexp (11) + dexp : dexp . '*' dexp (12) + dexp : dexp . '/' dexp (13) + dexp : '-' dexp . (14) + + . reduce 14 + + +state 50 + dexp : dexp . '+' dexp (10) + dexp : dexp . '-' dexp (11) + dexp : dexp . '*' dexp (12) + dexp : dexp . '/' dexp (13) + dexp : '(' dexp . ')' (15) + + '+' shift 51 + '-' shift 52 + '*' shift 53 + '/' shift 54 + ')' shift 34 + . error + + +state 51 + dexp : dexp '+' . dexp (10) + + DREG shift 13 + CONST shift 4 + '-' shift 29 + '(' shift 30 + . error + + dexp goto 58 + + +state 52 + dexp : dexp '-' . dexp (11) + + DREG shift 13 + CONST shift 4 + '-' shift 29 + '(' shift 30 + . error + + dexp goto 59 + + +state 53 + dexp : dexp '*' . dexp (12) + + DREG shift 13 + CONST shift 4 + '-' shift 29 + '(' shift 30 + . error + + dexp goto 60 + + +state 54 + dexp : dexp '/' . dexp (13) + + DREG shift 13 + CONST shift 4 + '-' shift 29 + '(' shift 30 + . error + + dexp goto 61 + + +state 55 + line : DREG '=' dexp '\n' . (5) + + . reduce 5 + + +state 56 + line : VREG '=' vexp '\n' . (6) + + . reduce 6 + + +state 57 + dexp : dexp . '+' dexp (10) + dexp : dexp . '-' dexp (11) + dexp : dexp . '*' dexp (12) + dexp : dexp . '/' dexp (13) + vexp : '(' dexp ',' dexp . ')' (17) + + '+' shift 51 + '-' shift 52 + '*' shift 53 + '/' shift 54 + ')' shift 62 + . error + + +state 58 + dexp : dexp . '+' dexp (10) + dexp : dexp '+' dexp . (10) + dexp : dexp . '-' dexp (11) + dexp : dexp . '*' dexp (12) + dexp : dexp . '/' dexp (13) + + '*' shift 53 + '/' shift 54 + '+' reduce 10 + '-' reduce 10 + '\n' reduce 10 + ')' reduce 10 + + +state 59 + dexp : dexp . '+' dexp (10) + dexp : dexp . '-' dexp (11) + dexp : dexp '-' dexp . (11) + dexp : dexp . '*' dexp (12) + dexp : dexp . '/' dexp (13) + + '*' shift 53 + '/' shift 54 + '+' reduce 11 + '-' reduce 11 + '\n' reduce 11 + ')' reduce 11 + + +state 60 + dexp : dexp . '+' dexp (10) + dexp : dexp . '-' dexp (11) + dexp : dexp . '*' dexp (12) + dexp : dexp '*' dexp . (12) + dexp : dexp . '/' dexp (13) + + . reduce 12 + + +state 61 + dexp : dexp . '+' dexp (10) + dexp : dexp . '-' dexp (11) + dexp : dexp . '*' dexp (12) + dexp : dexp . '/' dexp (13) + dexp : dexp '/' dexp . (13) + + . reduce 13 + + +state 62 + vexp : '(' dexp ',' dexp ')' . (17) + + . reduce 17 + + +Rules never reduced: + lines : (1) + lines : lines line (2) + + +State 8 contains 5 shift/reduce conflicts. +State 15 contains 6 reduce/reduce conflicts. +State 17 contains 5 shift/reduce conflicts. +State 32 contains 4 shift/reduce conflicts. +State 37 contains 2 shift/reduce conflicts, 4 reduce/reduce conflicts. +State 39 contains 2 shift/reduce conflicts, 4 reduce/reduce conflicts. +State 41 contains 6 reduce/reduce conflicts. +State 43 contains 6 reduce/reduce conflicts. + + +15 terminals, 5 nonterminals +29 grammar rules, 63 states diff --git a/test/calc1.tab.c b/test/calc1.tab.c new file mode 100644 index 000000000000..65551e8ecbc7 --- /dev/null +++ b/test/calc1.tab.c @@ -0,0 +1,915 @@ +#ifndef lint +static const char yysccsid[] = "@(#)yaccpar 1.9 (Berkeley) 02/21/93"; +#endif + +#define YYBYACC 1 +#define YYMAJOR 1 +#define YYMINOR 9 + +#define YYEMPTY (-1) +#define yyclearin (yychar = YYEMPTY) +#define yyerrok (yyerrflag = 0) +#define YYRECOVERING() (yyerrflag != 0) + + +#ifndef yyparse +#define yyparse calc1_parse +#endif /* yyparse */ + +#ifndef yylex +#define yylex calc1_lex +#endif /* yylex */ + +#ifndef yyerror +#define yyerror calc1_error +#endif /* yyerror */ + +#ifndef yychar +#define yychar calc1_char +#endif /* yychar */ + +#ifndef yyval +#define yyval calc1_val +#endif /* yyval */ + +#ifndef yylval +#define yylval calc1_lval +#endif /* yylval */ + +#ifndef yydebug +#define yydebug calc1_debug +#endif /* yydebug */ + +#ifndef yynerrs +#define yynerrs calc1_nerrs +#endif /* yynerrs */ + +#ifndef yyerrflag +#define yyerrflag calc1_errflag +#endif /* yyerrflag */ + +#ifndef yylhs +#define yylhs calc1_lhs +#endif /* yylhs */ + +#ifndef yylen +#define yylen calc1_len +#endif /* yylen */ + +#ifndef yydefred +#define yydefred calc1_defred +#endif /* yydefred */ + +#ifndef yydgoto +#define yydgoto calc1_dgoto +#endif /* yydgoto */ + +#ifndef yysindex +#define yysindex calc1_sindex +#endif /* yysindex */ + +#ifndef yyrindex +#define yyrindex calc1_rindex +#endif /* yyrindex */ + +#ifndef yygindex +#define yygindex calc1_gindex +#endif /* yygindex */ + +#ifndef yytable +#define yytable calc1_table +#endif /* yytable */ + +#ifndef yycheck +#define yycheck calc1_check +#endif /* yycheck */ + +#ifndef yyname +#define yyname calc1_name +#endif /* yyname */ + +#ifndef yyrule +#define yyrule calc1_rule +#endif /* yyrule */ +#define YYPREFIX "calc1_" + +#define YYPURE 0 + +#line 2 "calc1.y" + +/* http://dinosaur.compilertools.net/yacc/index.html */ + +#include <stdlib.h> +#include <stdio.h> +#include <ctype.h> +#include <math.h> + +typedef struct interval +{ + double lo, hi; +} +INTERVAL; + +INTERVAL vmul(double, double, INTERVAL); +INTERVAL vdiv(double, double, INTERVAL); + +extern int yylex(void); +static void yyerror(const char *s); + +int dcheck(INTERVAL); + +double dreg[26]; +INTERVAL vreg[26]; + +#line 31 "calc1.y" +#ifdef YYSTYPE +#undef YYSTYPE_IS_DECLARED +#define YYSTYPE_IS_DECLARED 1 +#endif +#ifndef YYSTYPE_IS_DECLARED +#define YYSTYPE_IS_DECLARED 1 +typedef union +{ + int ival; + double dval; + INTERVAL vval; +} YYSTYPE; +#endif /* !YYSTYPE_IS_DECLARED */ +#line 139 "calc1.tab.c" + +/* compatibility with bison */ +#ifdef YYPARSE_PARAM +/* compatibility with FreeBSD */ +# ifdef YYPARSE_PARAM_TYPE +# define YYPARSE_DECL() yyparse(YYPARSE_PARAM_TYPE YYPARSE_PARAM) +# else +# define YYPARSE_DECL() yyparse(void *YYPARSE_PARAM) +# endif +#else +# define YYPARSE_DECL() yyparse(void) +#endif + +/* Parameters sent to lex. */ +#ifdef YYLEX_PARAM +# define YYLEX_DECL() yylex(void *YYLEX_PARAM) +# define YYLEX yylex(YYLEX_PARAM) +#else +# define YYLEX_DECL() yylex(void) +# define YYLEX yylex() +#endif + +/* Parameters sent to yyerror. */ +#ifndef YYERROR_DECL +#define YYERROR_DECL() yyerror(const char *s) +#endif +#ifndef YYERROR_CALL +#define YYERROR_CALL(msg) yyerror(msg) +#endif + +extern int YYPARSE_DECL(); + +#define DREG 257 +#define VREG 258 +#define CONST 259 +#define UMINUS 260 +#define YYERRCODE 256 +static const short calc1_lhs[] = { -1, + 3, 3, 0, 0, 0, 0, 0, 1, 1, 1, + 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, + 2, 2, 2, 2, 2, 2, 2, 2, +}; +static const short calc1_len[] = { 2, + 0, 2, 2, 2, 4, 4, 2, 1, 1, 3, + 3, 3, 3, 2, 3, 1, 5, 1, 3, 3, + 3, 3, 3, 3, 3, 3, 2, 3, +}; +static const short calc1_defred[] = { 0, + 0, 0, 0, 8, 0, 0, 0, 0, 0, 7, + 0, 0, 9, 18, 14, 27, 0, 0, 0, 0, + 0, 0, 3, 0, 0, 0, 0, 4, 0, 0, + 0, 0, 0, 15, 0, 28, 0, 0, 0, 0, + 12, 24, 13, 26, 0, 0, 23, 25, 14, 0, + 0, 0, 0, 0, 5, 6, 0, 0, 0, 12, + 13, 17, +}; +static const short calc1_dgoto[] = { 7, + 32, 9, 0, +}; +static const short calc1_sindex[] = { -40, + -8, -48, -47, 0, -37, -37, 0, 2, 17, 0, + -34, -37, 0, 0, 0, 0, -25, 90, -37, -37, + -37, -37, 0, -37, -37, -37, -37, 0, -34, -34, + 25, 125, 31, 0, -34, 0, -11, 37, -11, 37, + 0, 0, 0, 0, 37, 37, 0, 0, 0, 111, + -34, -34, -34, -34, 0, 0, 118, 69, 69, 0, + 0, 0, +}; +static const short calc1_rindex[] = { 0, + 0, 38, 44, 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, -9, 0, 0, 0, 0, 51, -3, 56, 61, + 0, 0, 0, 0, 67, 72, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 78, 83, 0, + 0, 0, +}; +static const short calc1_gindex[] = { 0, + 4, 124, 0, +}; +#define YYTABLESIZE 225 +static const short calc1_table[] = { 6, + 16, 10, 6, 8, 5, 30, 20, 5, 15, 17, + 29, 23, 11, 12, 31, 34, 21, 19, 35, 20, + 0, 22, 37, 39, 41, 43, 28, 0, 0, 0, + 21, 16, 49, 50, 55, 22, 0, 20, 57, 20, + 56, 20, 0, 21, 19, 0, 20, 9, 22, 0, + 0, 0, 0, 18, 58, 59, 60, 61, 26, 24, + 10, 25, 0, 27, 0, 11, 53, 51, 0, 52, + 22, 54, 26, 24, 0, 25, 19, 27, 26, 9, + 9, 21, 9, 27, 9, 18, 18, 10, 18, 0, + 18, 10, 11, 10, 10, 10, 11, 0, 11, 11, + 11, 22, 0, 22, 0, 22, 0, 19, 0, 19, + 53, 19, 21, 0, 21, 54, 21, 0, 10, 0, + 10, 0, 10, 11, 0, 11, 0, 11, 16, 18, + 36, 26, 24, 0, 25, 33, 27, 0, 0, 0, + 0, 0, 38, 40, 42, 44, 0, 45, 46, 47, + 48, 34, 53, 51, 0, 52, 0, 54, 62, 53, + 51, 0, 52, 0, 54, 0, 21, 19, 0, 20, + 0, 22, 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, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 1, 2, 3, 4, 13, + 14, 4, 13, 0, 4, +}; +static const short calc1_check[] = { 40, + 10, 10, 40, 0, 45, 40, 10, 45, 5, 6, + 45, 10, 61, 61, 11, 41, 42, 43, 44, 45, + -1, 47, 19, 20, 21, 22, 10, -1, -1, -1, + 42, 41, 29, 30, 10, 47, -1, 41, 35, 43, + 10, 45, -1, 42, 43, -1, 45, 10, 47, -1, + -1, -1, -1, 10, 51, 52, 53, 54, 42, 43, + 10, 45, -1, 47, -1, 10, 42, 43, -1, 45, + 10, 47, 42, 43, -1, 45, 10, 47, 42, 42, + 43, 10, 45, 47, 47, 42, 43, 10, 45, -1, + 47, 41, 10, 43, 44, 45, 41, -1, 43, 44, + 45, 41, -1, 43, -1, 45, -1, 41, -1, 43, + 42, 45, 41, -1, 43, 47, 45, -1, 41, -1, + 43, -1, 45, 41, -1, 43, -1, 45, 5, 6, + 41, 42, 43, -1, 45, 12, 47, -1, -1, -1, + -1, -1, 19, 20, 21, 22, -1, 24, 25, 26, + 27, 41, 42, 43, -1, 45, -1, 47, 41, 42, + 43, -1, 45, -1, 47, -1, 42, 43, -1, 45, + -1, 47, -1, -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, 256, 257, 258, 259, 257, + 258, 259, 257, -1, 259, +}; +#define YYFINAL 7 +#ifndef YYDEBUG +#define YYDEBUG 0 +#endif +#define YYMAXTOKEN 260 +#if YYDEBUG +static const char *yyname[] = { + +"end-of-file",0,0,0,0,0,0,0,0,0,"'\\n'",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,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,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,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,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,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,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, +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,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,"DREG","VREG","CONST","UMINUS", +}; +static const char *yyrule[] = { +"$accept : line", +"lines :", +"lines : lines line", +"line : dexp '\\n'", +"line : vexp '\\n'", +"line : DREG '=' dexp '\\n'", +"line : VREG '=' vexp '\\n'", +"line : error '\\n'", +"dexp : CONST", +"dexp : DREG", +"dexp : dexp '+' dexp", +"dexp : dexp '-' dexp", +"dexp : dexp '*' dexp", +"dexp : dexp '/' dexp", +"dexp : '-' dexp", +"dexp : '(' dexp ')'", +"vexp : dexp", +"vexp : '(' dexp ',' dexp ')'", +"vexp : VREG", +"vexp : vexp '+' vexp", +"vexp : dexp '+' vexp", +"vexp : vexp '-' vexp", +"vexp : dexp '-' vexp", +"vexp : vexp '*' vexp", +"vexp : dexp '*' vexp", +"vexp : vexp '/' vexp", +"vexp : dexp '/' vexp", +"vexp : '-' vexp", +"vexp : '(' vexp ')'", + +}; +#endif + +int yydebug; +int yynerrs; + +int yyerrflag; +int yychar; +YYSTYPE yyval; +YYSTYPE yylval; + +/* define the initial stack-sizes */ +#ifdef YYSTACKSIZE +#undef YYMAXDEPTH +#define YYMAXDEPTH YYSTACKSIZE +#else +#ifdef YYMAXDEPTH +#define YYSTACKSIZE YYMAXDEPTH +#else +#define YYSTACKSIZE 500 +#define YYMAXDEPTH 500 +#endif +#endif + +#define YYINITSTACKSIZE 500 + +typedef struct { + unsigned stacksize; + short *s_base; + short *s_mark; + short *s_last; + YYSTYPE *l_base; + YYSTYPE *l_mark; +} YYSTACKDATA; +/* variables for the parser stack */ +static YYSTACKDATA yystack; +#line 176 "calc1.y" + /* beginning of subroutines section */ + +#define BSZ 50 /* buffer size for floating point numbers */ + + /* lexical analysis */ + +static void +yyerror(const char *s) +{ + fprintf(stderr, "%s\n", s); +} + +int +yylex(void) +{ + int c; + + while ((c = getchar()) == ' ') + { /* skip over blanks */ + } + + if (isupper(c)) + { + yylval.ival = c - 'A'; + return (VREG); + } + if (islower(c)) + { + yylval.ival = c - 'a'; + return (DREG); + } + + if (isdigit(c) || c == '.') + { + /* gobble up digits, points, exponents */ + char buf[BSZ + 1], *cp = buf; + int dot = 0, expr = 0; + + for (; (cp - buf) < BSZ; ++cp, c = getchar()) + { + + *cp = c; + if (isdigit(c)) + continue; + if (c == '.') + { + if (dot++ || expr) + return ('.'); /* will cause syntax error */ + continue; + } + + if (c == 'e') + { + if (expr++) + return ('e'); /* will cause syntax error */ + continue; + } + + /* end of number */ + break; + } + *cp = '\0'; + + if ((cp - buf) >= BSZ) + printf("constant too long: truncated\n"); + else + ungetc(c, stdin); /* push back last char read */ + yylval.dval = atof(buf); + return (CONST); + } + return (c); +} + +static INTERVAL +hilo(double a, double b, double c, double d) +{ + /* returns the smallest interval containing a, b, c, and d */ + /* used by *, / routines */ + INTERVAL v; + + if (a > b) + { + v.hi = a; + v.lo = b; + } + else + { + v.hi = b; + v.lo = a; + } + + if (c > d) + { + if (c > v.hi) + v.hi = c; + if (d < v.lo) + v.lo = d; + } + else + { + if (d > v.hi) + v.hi = d; + if (c < v.lo) + v.lo = c; + } + return (v); +} + +INTERVAL +vmul(double a, double b, INTERVAL v) +{ + return (hilo(a * v.hi, a * v.lo, b * v.hi, b * v.lo)); +} + +int +dcheck(INTERVAL v) +{ + if (v.hi >= 0. && v.lo <= 0.) + { + printf("divisor interval contains 0.\n"); + return (1); + } + return (0); +} + +INTERVAL +vdiv(double a, double b, INTERVAL v) +{ + return (hilo(a / v.hi, a / v.lo, b / v.hi, b / v.lo)); +} +#line 486 "calc1.tab.c" + +#if YYDEBUG +#include <stdio.h> /* needed for printf */ +#endif + +#include <stdlib.h> /* needed for malloc, etc */ +#include <string.h> /* needed for memset */ + +/* allocate initial stack or double stack size, up to YYMAXDEPTH */ +static int yygrowstack(YYSTACKDATA *data) +{ + int i; + unsigned newsize; + short *newss; + YYSTYPE *newvs; + + if ((newsize = data->stacksize) == 0) + newsize = YYINITSTACKSIZE; + else if (newsize >= YYMAXDEPTH) + return -1; + else if ((newsize *= 2) > YYMAXDEPTH) + newsize = YYMAXDEPTH; + + i = data->s_mark - data->s_base; + newss = (short *)realloc(data->s_base, newsize * sizeof(*newss)); + if (newss == 0) + return -1; + + data->s_base = newss; + data->s_mark = newss + i; + + newvs = (YYSTYPE *)realloc(data->l_base, newsize * sizeof(*newvs)); + if (newvs == 0) + return -1; + + data->l_base = newvs; + data->l_mark = newvs + i; + + data->stacksize = newsize; + data->s_last = data->s_base + newsize - 1; + return 0; +} + +#if YYPURE || defined(YY_NO_LEAKS) +static void yyfreestack(YYSTACKDATA *data) +{ + free(data->s_base); + free(data->l_base); + memset(data, 0, sizeof(*data)); +} +#else +#define yyfreestack(data) /* nothing */ +#endif + +#define YYABORT goto yyabort +#define YYREJECT goto yyabort +#define YYACCEPT goto yyaccept +#define YYERROR goto yyerrlab + +int +YYPARSE_DECL() +{ + int yym, yyn, yystate; +#if YYDEBUG + const char *yys; + + if ((yys = getenv("YYDEBUG")) != 0) + { + yyn = *yys; + if (yyn >= '0' && yyn <= '9') + yydebug = yyn - '0'; + } +#endif + + yynerrs = 0; + yyerrflag = 0; + yychar = YYEMPTY; + yystate = 0; + +#if YYPURE + memset(&yystack, 0, sizeof(yystack)); +#endif + + if (yystack.s_base == NULL && yygrowstack(&yystack)) goto yyoverflow; + yystack.s_mark = yystack.s_base; + yystack.l_mark = yystack.l_base; + yystate = 0; + *yystack.s_mark = 0; + +yyloop: + if ((yyn = yydefred[yystate]) != 0) goto yyreduce; + if (yychar < 0) + { + if ((yychar = YYLEX) < 0) yychar = 0; +#if YYDEBUG + if (yydebug) + { + yys = 0; + if (yychar <= YYMAXTOKEN) yys = yyname[yychar]; + if (!yys) yys = "illegal-symbol"; + printf("%sdebug: state %d, reading %d (%s)\n", + YYPREFIX, yystate, yychar, yys); + } +#endif + } + if ((yyn = yysindex[yystate]) && (yyn += yychar) >= 0 && + yyn <= YYTABLESIZE && yycheck[yyn] == yychar) + { +#if YYDEBUG + if (yydebug) + printf("%sdebug: state %d, shifting to state %d\n", + YYPREFIX, yystate, yytable[yyn]); +#endif + if (yystack.s_mark >= yystack.s_last && yygrowstack(&yystack)) + { + goto yyoverflow; + } + yystate = yytable[yyn]; + *++yystack.s_mark = yytable[yyn]; + *++yystack.l_mark = yylval; + yychar = YYEMPTY; + if (yyerrflag > 0) --yyerrflag; + goto yyloop; + } + if ((yyn = yyrindex[yystate]) && (yyn += yychar) >= 0 && + yyn <= YYTABLESIZE && yycheck[yyn] == yychar) + { + yyn = yytable[yyn]; + goto yyreduce; + } + if (yyerrflag) goto yyinrecovery; + + yyerror("syntax error"); + + goto yyerrlab; + +yyerrlab: + ++yynerrs; + +yyinrecovery: + if (yyerrflag < 3) + { + yyerrflag = 3; + for (;;) + { + if ((yyn = yysindex[*yystack.s_mark]) && (yyn += YYERRCODE) >= 0 && + yyn <= YYTABLESIZE && yycheck[yyn] == YYERRCODE) + { +#if YYDEBUG + if (yydebug) + printf("%sdebug: state %d, error recovery shifting\ + to state %d\n", YYPREFIX, *yystack.s_mark, yytable[yyn]); +#endif + if (yystack.s_mark >= yystack.s_last && yygrowstack(&yystack)) + { + goto yyoverflow; + } + yystate = yytable[yyn]; + *++yystack.s_mark = yytable[yyn]; + *++yystack.l_mark = yylval; + goto yyloop; + } + else + { +#if YYDEBUG + if (yydebug) + printf("%sdebug: error recovery discarding state %d\n", + YYPREFIX, *yystack.s_mark); +#endif + if (yystack.s_mark <= yystack.s_base) goto yyabort; + --yystack.s_mark; + --yystack.l_mark; + } + } + } + else + { + if (yychar == 0) goto yyabort; +#if YYDEBUG + if (yydebug) + { + yys = 0; + if (yychar <= YYMAXTOKEN) yys = yyname[yychar]; + if (!yys) yys = "illegal-symbol"; + printf("%sdebug: state %d, error recovery discards token %d (%s)\n", + YYPREFIX, yystate, yychar, yys); + } +#endif + yychar = YYEMPTY; + goto yyloop; + } + +yyreduce: +#if YYDEBUG + if (yydebug) + printf("%sdebug: state %d, reducing by rule %d (%s)\n", + YYPREFIX, yystate, yyn, yyrule[yyn]); +#endif + yym = yylen[yyn]; + if (yym) + yyval = yystack.l_mark[1-yym]; + else + memset(&yyval, 0, sizeof yyval); + switch (yyn) + { +case 3: +#line 57 "calc1.y" + { + (void) printf("%15.8f\n", yystack.l_mark[-1].dval); + } +break; +case 4: +#line 61 "calc1.y" + { + (void) printf("(%15.8f, %15.8f)\n", yystack.l_mark[-1].vval.lo, yystack.l_mark[-1].vval.hi); + } +break; +case 5: +#line 65 "calc1.y" + { + dreg[yystack.l_mark[-3].ival] = yystack.l_mark[-1].dval; + } +break; +case 6: +#line 69 "calc1.y" + { + vreg[yystack.l_mark[-3].ival] = yystack.l_mark[-1].vval; + } +break; +case 7: +#line 73 "calc1.y" + { + yyerrok; + } +break; +case 9: +#line 80 "calc1.y" + { + yyval.dval = dreg[yystack.l_mark[0].ival]; + } +break; +case 10: +#line 84 "calc1.y" + { + yyval.dval = yystack.l_mark[-2].dval + yystack.l_mark[0].dval; + } +break; +case 11: +#line 88 "calc1.y" + { + yyval.dval = yystack.l_mark[-2].dval - yystack.l_mark[0].dval; + } +break; +case 12: +#line 92 "calc1.y" + { + yyval.dval = yystack.l_mark[-2].dval * yystack.l_mark[0].dval; + } +break; +case 13: +#line 96 "calc1.y" + { + yyval.dval = yystack.l_mark[-2].dval / yystack.l_mark[0].dval; + } +break; +case 14: +#line 100 "calc1.y" + { + yyval.dval = -yystack.l_mark[0].dval; + } +break; +case 15: +#line 104 "calc1.y" + { + yyval.dval = yystack.l_mark[-1].dval; + } +break; +case 16: +#line 110 "calc1.y" + { + yyval.vval.hi = yyval.vval.lo = yystack.l_mark[0].dval; + } +break; +case 17: +#line 114 "calc1.y" + { + yyval.vval.lo = yystack.l_mark[-3].dval; + yyval.vval.hi = yystack.l_mark[-1].dval; + if ( yyval.vval.lo > yyval.vval.hi ) + { + (void) printf("interval out of order\n"); + YYERROR; + } + } +break; +case 18: +#line 124 "calc1.y" + { + yyval.vval = vreg[yystack.l_mark[0].ival]; + } +break; +case 19: +#line 128 "calc1.y" + { + yyval.vval.hi = yystack.l_mark[-2].vval.hi + yystack.l_mark[0].vval.hi; + yyval.vval.lo = yystack.l_mark[-2].vval.lo + yystack.l_mark[0].vval.lo; + } +break; +case 20: +#line 133 "calc1.y" + { + yyval.vval.hi = yystack.l_mark[-2].dval + yystack.l_mark[0].vval.hi; + yyval.vval.lo = yystack.l_mark[-2].dval + yystack.l_mark[0].vval.lo; + } +break; +case 21: +#line 138 "calc1.y" + { + yyval.vval.hi = yystack.l_mark[-2].vval.hi - yystack.l_mark[0].vval.lo; + yyval.vval.lo = yystack.l_mark[-2].vval.lo - yystack.l_mark[0].vval.hi; + } +break; +case 22: +#line 143 "calc1.y" + { + yyval.vval.hi = yystack.l_mark[-2].dval - yystack.l_mark[0].vval.lo; + yyval.vval.lo = yystack.l_mark[-2].dval - yystack.l_mark[0].vval.hi; + } +break; +case 23: +#line 148 "calc1.y" + { + yyval.vval = vmul( yystack.l_mark[-2].vval.lo, yystack.l_mark[-2].vval.hi, yystack.l_mark[0].vval ); + } +break; +case 24: +#line 152 "calc1.y" + { + yyval.vval = vmul (yystack.l_mark[-2].dval, yystack.l_mark[-2].dval, yystack.l_mark[0].vval ); + } +break; +case 25: +#line 156 "calc1.y" + { + if (dcheck(yystack.l_mark[0].vval)) YYERROR; + yyval.vval = vdiv ( yystack.l_mark[-2].vval.lo, yystack.l_mark[-2].vval.hi, yystack.l_mark[0].vval ); + } +break; +case 26: +#line 161 "calc1.y" + { + if (dcheck ( yystack.l_mark[0].vval )) YYERROR; + yyval.vval = vdiv (yystack.l_mark[-2].dval, yystack.l_mark[-2].dval, yystack.l_mark[0].vval ); + } +break; +case 27: +#line 166 "calc1.y" + { + yyval.vval.hi = -yystack.l_mark[0].vval.lo; + yyval.vval.lo = -yystack.l_mark[0].vval.hi; + } +break; +case 28: +#line 171 "calc1.y" + { + yyval.vval = yystack.l_mark[-1].vval; + } +break; +#line 855 "calc1.tab.c" + } + yystack.s_mark -= yym; + yystate = *yystack.s_mark; + yystack.l_mark -= yym; + yym = yylhs[yyn]; + if (yystate == 0 && yym == 0) + { +#if YYDEBUG + if (yydebug) + printf("%sdebug: after reduction, shifting from state 0 to\ + state %d\n", YYPREFIX, YYFINAL); +#endif + yystate = YYFINAL; + *++yystack.s_mark = YYFINAL; + *++yystack.l_mark = yyval; + if (yychar < 0) + { + if ((yychar = YYLEX) < 0) yychar = 0; +#if YYDEBUG + if (yydebug) + { + yys = 0; + if (yychar <= YYMAXTOKEN) yys = yyname[yychar]; + if (!yys) yys = "illegal-symbol"; + printf("%sdebug: state %d, reading %d (%s)\n", + YYPREFIX, YYFINAL, yychar, yys); + } +#endif + } + if (yychar == 0) goto yyaccept; + goto yyloop; + } + if ((yyn = yygindex[yym]) && (yyn += yystate) >= 0 && + yyn <= YYTABLESIZE && yycheck[yyn] == yystate) + yystate = yytable[yyn]; + else + yystate = yydgoto[yym]; +#if YYDEBUG + if (yydebug) + printf("%sdebug: after reduction, shifting from state %d \ +to state %d\n", YYPREFIX, *yystack.s_mark, yystate); +#endif + if (yystack.s_mark >= yystack.s_last && yygrowstack(&yystack)) + { + goto yyoverflow; + } + *++yystack.s_mark = (short) yystate; + *++yystack.l_mark = yyval; + goto yyloop; + +yyoverflow: + yyerror("yacc stack overflow"); + +yyabort: + yyfreestack(&yystack); + return (1); + +yyaccept: + yyfreestack(&yystack); + return (0); +} diff --git a/test/calc1.tab.h b/test/calc1.tab.h new file mode 100644 index 000000000000..c0633e37dfa8 --- /dev/null +++ b/test/calc1.tab.h @@ -0,0 +1,18 @@ +#define DREG 257 +#define VREG 258 +#define CONST 259 +#define UMINUS 260 +#ifdef YYSTYPE +#undef YYSTYPE_IS_DECLARED +#define YYSTYPE_IS_DECLARED 1 +#endif +#ifndef YYSTYPE_IS_DECLARED +#define YYSTYPE_IS_DECLARED 1 +typedef union +{ + int ival; + double dval; + INTERVAL vval; +} YYSTYPE; +#endif /* !YYSTYPE_IS_DECLARED */ +extern YYSTYPE calc1_lval; diff --git a/test/calc1.y b/test/calc1.y new file mode 100644 index 000000000000..ec89736f47a5 --- /dev/null +++ b/test/calc1.y @@ -0,0 +1,305 @@ +%{ + +/* http://dinosaur.compilertools.net/yacc/index.html */ + +#include <stdlib.h> +#include <stdio.h> +#include <ctype.h> +#include <math.h> + +typedef struct interval +{ + double lo, hi; +} +INTERVAL; + +INTERVAL vmul(double, double, INTERVAL); +INTERVAL vdiv(double, double, INTERVAL); + +extern int yylex(void); +static void yyerror(const char *s); + +int dcheck(INTERVAL); + +double dreg[26]; +INTERVAL vreg[26]; + +%} +%expect 18 + +%start line +%union +{ + int ival; + double dval; + INTERVAL vval; +} + +%token <ival> DREG VREG /* indices into dreg, vreg arrays */ +%token <dval> CONST /* floating point constant */ + +%type <dval> dexp /* expression */ +%type <vval> vexp /* interval expression */ + + /* precedence information about the operators */ + +%left '+' '-' +%left '*' '/' +%left UMINUS /* precedence for unary minus */ + +%% /* beginning of rules section */ + +lines : /* empty */ + | lines line + ; + +line : dexp '\n' + { + (void) printf("%15.8f\n", $1); + } + | vexp '\n' + { + (void) printf("(%15.8f, %15.8f)\n", $1.lo, $1.hi); + } + | DREG '=' dexp '\n' + { + dreg[$1] = $3; + } + | VREG '=' vexp '\n' + { + vreg[$1] = $3; + } + | error '\n' + { + yyerrok; + } + ; + +dexp : CONST + | DREG + { + $$ = dreg[$1]; + } + | dexp '+' dexp + { + $$ = $1 + $3; + } + | dexp '-' dexp + { + $$ = $1 - $3; + } + | dexp '*' dexp + { + $$ = $1 * $3; + } + | dexp '/' dexp + { + $$ = $1 / $3; + } + | '-' dexp %prec UMINUS + { + $$ = -$2; + } + | '(' dexp ')' + { + $$ = $2; + } + ; + +vexp : dexp + { + $$.hi = $$.lo = $1; + } + | '(' dexp ',' dexp ')' + { + $$.lo = $2; + $$.hi = $4; + if ( $$.lo > $$.hi ) + { + (void) printf("interval out of order\n"); + YYERROR; + } + } + | VREG + { + $$ = vreg[$1]; + } + | vexp '+' vexp + { + $$.hi = $1.hi + $3.hi; + $$.lo = $1.lo + $3.lo; + } + | dexp '+' vexp + { + $$.hi = $1 + $3.hi; + $$.lo = $1 + $3.lo; + } + | vexp '-' vexp + { + $$.hi = $1.hi - $3.lo; + $$.lo = $1.lo - $3.hi; + } + | dexp '-' vexp + { + $$.hi = $1 - $3.lo; + $$.lo = $1 - $3.hi; + } + | vexp '*' vexp + { + $$ = vmul( $1.lo, $1.hi, $3 ); + } + | dexp '*' vexp + { + $$ = vmul ($1, $1, $3 ); + } + | vexp '/' vexp + { + if (dcheck($3)) YYERROR; + $$ = vdiv ( $1.lo, $1.hi, $3 ); + } + | dexp '/' vexp + { + if (dcheck ( $3 )) YYERROR; + $$ = vdiv ($1, $1, $3 ); + } + | '-' vexp %prec UMINUS + { + $$.hi = -$2.lo; + $$.lo = -$2.hi; + } + | '(' vexp ')' + { + $$ = $2; + } + ; + +%% /* beginning of subroutines section */ + +#define BSZ 50 /* buffer size for floating point numbers */ + + /* lexical analysis */ + +static void +yyerror(const char *s) +{ + fprintf(stderr, "%s\n", s); +} + +int +yylex(void) +{ + int c; + + while ((c = getchar()) == ' ') + { /* skip over blanks */ + } + + if (isupper(c)) + { + yylval.ival = c - 'A'; + return (VREG); + } + if (islower(c)) + { + yylval.ival = c - 'a'; + return (DREG); + } + + if (isdigit(c) || c == '.') + { + /* gobble up digits, points, exponents */ + char buf[BSZ + 1], *cp = buf; + int dot = 0, expr = 0; + + for (; (cp - buf) < BSZ; ++cp, c = getchar()) + { + + *cp = c; + if (isdigit(c)) + continue; + if (c == '.') + { + if (dot++ || expr) + return ('.'); /* will cause syntax error */ + continue; + } + + if (c == 'e') + { + if (expr++) + return ('e'); /* will cause syntax error */ + continue; + } + + /* end of number */ + break; + } + *cp = '\0'; + + if ((cp - buf) >= BSZ) + printf("constant too long: truncated\n"); + else + ungetc(c, stdin); /* push back last char read */ + yylval.dval = atof(buf); + return (CONST); + } + return (c); +} + +static INTERVAL +hilo(double a, double b, double c, double d) +{ + /* returns the smallest interval containing a, b, c, and d */ + /* used by *, / routines */ + INTERVAL v; + + if (a > b) + { + v.hi = a; + v.lo = b; + } + else + { + v.hi = b; + v.lo = a; + } + + if (c > d) + { + if (c > v.hi) + v.hi = c; + if (d < v.lo) + v.lo = d; + } + else + { + if (d > v.hi) + v.hi = d; + if (c < v.lo) + v.lo = c; + } + return (v); +} + +INTERVAL +vmul(double a, double b, INTERVAL v) +{ + return (hilo(a * v.hi, a * v.lo, b * v.hi, b * v.lo)); +} + +int +dcheck(INTERVAL v) +{ + if (v.hi >= 0. && v.lo <= 0.) + { + printf("divisor interval contains 0.\n"); + return (1); + } + return (0); +} + +INTERVAL +vdiv(double a, double b, INTERVAL v) +{ + return (hilo(a / v.hi, a / v.lo, b / v.hi, b / v.lo)); +} diff --git a/test/calc2.output b/test/calc2.output new file mode 100644 index 000000000000..3aed47511c93 --- /dev/null +++ b/test/calc2.output @@ -0,0 +1,461 @@ + 0 $accept : list $end + + 1 list : + 2 | list stat '\n' + 3 | list error '\n' + + 4 stat : expr + 5 | LETTER '=' expr + + 6 expr : '(' expr ')' + 7 | expr '+' expr + 8 | expr '-' expr + 9 | expr '*' expr + 10 | expr '/' expr + 11 | expr '%' expr + 12 | expr '&' expr + 13 | expr '|' expr + 14 | '-' expr + 15 | LETTER + 16 | number + + 17 number : DIGIT + 18 | number DIGIT + +state 0 + $accept : . list $end (0) + list : . (1) + + . reduce 1 + + list goto 1 + + +state 1 + $accept : list . $end (0) + list : list . stat '\n' (2) + list : list . error '\n' (3) + + $end accept + error shift 2 + DIGIT shift 3 + LETTER shift 4 + '-' shift 5 + '(' shift 6 + . error + + stat goto 7 + expr goto 8 + number goto 9 + + +state 2 + list : list error . '\n' (3) + + '\n' shift 10 + . error + + +state 3 + number : DIGIT . (17) + + . reduce 17 + + +state 4 + stat : LETTER . '=' expr (5) + expr : LETTER . (15) + + '=' shift 11 + '|' reduce 15 + '&' reduce 15 + '+' reduce 15 + '-' reduce 15 + '*' reduce 15 + '/' reduce 15 + '%' reduce 15 + '\n' reduce 15 + + +state 5 + expr : '-' . expr (14) + + DIGIT shift 3 + LETTER shift 12 + '-' shift 5 + '(' shift 6 + . error + + expr goto 13 + number goto 9 + + +state 6 + expr : '(' . expr ')' (6) + + DIGIT shift 3 + LETTER shift 12 + '-' shift 5 + '(' shift 6 + . error + + expr goto 14 + number goto 9 + + +state 7 + list : list stat . '\n' (2) + + '\n' shift 15 + . error + + +state 8 + stat : expr . (4) + expr : expr . '+' expr (7) + expr : expr . '-' expr (8) + expr : expr . '*' expr (9) + expr : expr . '/' expr (10) + expr : expr . '%' expr (11) + expr : expr . '&' expr (12) + expr : expr . '|' expr (13) + + '|' shift 16 + '&' shift 17 + '+' shift 18 + '-' shift 19 + '*' shift 20 + '/' shift 21 + '%' shift 22 + '\n' reduce 4 + + +state 9 + expr : number . (16) + number : number . DIGIT (18) + + DIGIT shift 23 + '|' reduce 16 + '&' reduce 16 + '+' reduce 16 + '-' reduce 16 + '*' reduce 16 + '/' reduce 16 + '%' reduce 16 + '\n' reduce 16 + ')' reduce 16 + + +state 10 + list : list error '\n' . (3) + + . reduce 3 + + +state 11 + stat : LETTER '=' . expr (5) + + DIGIT shift 3 + LETTER shift 12 + '-' shift 5 + '(' shift 6 + . error + + expr goto 24 + number goto 9 + + +state 12 + expr : LETTER . (15) + + . reduce 15 + + +state 13 + expr : expr . '+' expr (7) + expr : expr . '-' expr (8) + expr : expr . '*' expr (9) + expr : expr . '/' expr (10) + expr : expr . '%' expr (11) + expr : expr . '&' expr (12) + expr : expr . '|' expr (13) + expr : '-' expr . (14) + + . reduce 14 + + +state 14 + expr : '(' expr . ')' (6) + expr : expr . '+' expr (7) + expr : expr . '-' expr (8) + expr : expr . '*' expr (9) + expr : expr . '/' expr (10) + expr : expr . '%' expr (11) + expr : expr . '&' expr (12) + expr : expr . '|' expr (13) + + '|' shift 16 + '&' shift 17 + '+' shift 18 + '-' shift 19 + '*' shift 20 + '/' shift 21 + '%' shift 22 + ')' shift 25 + . error + + +state 15 + list : list stat '\n' . (2) + + . reduce 2 + + +state 16 + expr : expr '|' . expr (13) + + DIGIT shift 3 + LETTER shift 12 + '-' shift 5 + '(' shift 6 + . error + + expr goto 26 + number goto 9 + + +state 17 + expr : expr '&' . expr (12) + + DIGIT shift 3 + LETTER shift 12 + '-' shift 5 + '(' shift 6 + . error + + expr goto 27 + number goto 9 + + +state 18 + expr : expr '+' . expr (7) + + DIGIT shift 3 + LETTER shift 12 + '-' shift 5 + '(' shift 6 + . error + + expr goto 28 + number goto 9 + + +state 19 + expr : expr '-' . expr (8) + + DIGIT shift 3 + LETTER shift 12 + '-' shift 5 + '(' shift 6 + . error + + expr goto 29 + number goto 9 + + +state 20 + expr : expr '*' . expr (9) + + DIGIT shift 3 + LETTER shift 12 + '-' shift 5 + '(' shift 6 + . error + + expr goto 30 + number goto 9 + + +state 21 + expr : expr '/' . expr (10) + + DIGIT shift 3 + LETTER shift 12 + '-' shift 5 + '(' shift 6 + . error + + expr goto 31 + number goto 9 + + +state 22 + expr : expr '%' . expr (11) + + DIGIT shift 3 + LETTER shift 12 + '-' shift 5 + '(' shift 6 + . error + + expr goto 32 + number goto 9 + + +state 23 + number : number DIGIT . (18) + + . reduce 18 + + +state 24 + stat : LETTER '=' expr . (5) + expr : expr . '+' expr (7) + expr : expr . '-' expr (8) + expr : expr . '*' expr (9) + expr : expr . '/' expr (10) + expr : expr . '%' expr (11) + expr : expr . '&' expr (12) + expr : expr . '|' expr (13) + + '|' shift 16 + '&' shift 17 + '+' shift 18 + '-' shift 19 + '*' shift 20 + '/' shift 21 + '%' shift 22 + '\n' reduce 5 + + +state 25 + expr : '(' expr ')' . (6) + + . reduce 6 + + +state 26 + expr : expr . '+' expr (7) + expr : expr . '-' expr (8) + expr : expr . '*' expr (9) + expr : expr . '/' expr (10) + expr : expr . '%' expr (11) + expr : expr . '&' expr (12) + expr : expr . '|' expr (13) + expr : expr '|' expr . (13) + + '&' shift 17 + '+' shift 18 + '-' shift 19 + '*' shift 20 + '/' shift 21 + '%' shift 22 + '|' reduce 13 + '\n' reduce 13 + ')' reduce 13 + + +state 27 + expr : expr . '+' expr (7) + expr : expr . '-' expr (8) + expr : expr . '*' expr (9) + expr : expr . '/' expr (10) + expr : expr . '%' expr (11) + expr : expr . '&' expr (12) + expr : expr '&' expr . (12) + expr : expr . '|' expr (13) + + '+' shift 18 + '-' shift 19 + '*' shift 20 + '/' shift 21 + '%' shift 22 + '|' reduce 12 + '&' reduce 12 + '\n' reduce 12 + ')' reduce 12 + + +state 28 + expr : expr . '+' expr (7) + expr : expr '+' expr . (7) + expr : expr . '-' expr (8) + expr : expr . '*' expr (9) + expr : expr . '/' expr (10) + expr : expr . '%' expr (11) + expr : expr . '&' expr (12) + expr : expr . '|' expr (13) + + '*' shift 20 + '/' shift 21 + '%' shift 22 + '|' reduce 7 + '&' reduce 7 + '+' reduce 7 + '-' reduce 7 + '\n' reduce 7 + ')' reduce 7 + + +state 29 + expr : expr . '+' expr (7) + expr : expr . '-' expr (8) + expr : expr '-' expr . (8) + expr : expr . '*' expr (9) + expr : expr . '/' expr (10) + expr : expr . '%' expr (11) + expr : expr . '&' expr (12) + expr : expr . '|' expr (13) + + '*' shift 20 + '/' shift 21 + '%' shift 22 + '|' reduce 8 + '&' reduce 8 + '+' reduce 8 + '-' reduce 8 + '\n' reduce 8 + ')' reduce 8 + + +state 30 + expr : expr . '+' expr (7) + expr : expr . '-' expr (8) + expr : expr . '*' expr (9) + expr : expr '*' expr . (9) + expr : expr . '/' expr (10) + expr : expr . '%' expr (11) + expr : expr . '&' expr (12) + expr : expr . '|' expr (13) + + . reduce 9 + + +state 31 + expr : expr . '+' expr (7) + expr : expr . '-' expr (8) + expr : expr . '*' expr (9) + expr : expr . '/' expr (10) + expr : expr '/' expr . (10) + expr : expr . '%' expr (11) + expr : expr . '&' expr (12) + expr : expr . '|' expr (13) + + . reduce 10 + + +state 32 + expr : expr . '+' expr (7) + expr : expr . '-' expr (8) + expr : expr . '*' expr (9) + expr : expr . '/' expr (10) + expr : expr . '%' expr (11) + expr : expr '%' expr . (11) + expr : expr . '&' expr (12) + expr : expr . '|' expr (13) + + . reduce 11 + + +16 terminals, 5 nonterminals +19 grammar rules, 33 states diff --git a/test/calc2.tab.c b/test/calc2.tab.c new file mode 100644 index 000000000000..1eb9548a6972 --- /dev/null +++ b/test/calc2.tab.c @@ -0,0 +1,682 @@ +#ifndef lint +static const char yysccsid[] = "@(#)yaccpar 1.9 (Berkeley) 02/21/93"; +#endif + +#define YYBYACC 1 +#define YYMAJOR 1 +#define YYMINOR 9 + +#define YYEMPTY (-1) +#define yyclearin (yychar = YYEMPTY) +#define yyerrok (yyerrflag = 0) +#define YYRECOVERING() (yyerrflag != 0) + + +#ifndef yyparse +#define yyparse calc2_parse +#endif /* yyparse */ + +#ifndef yylex +#define yylex calc2_lex +#endif /* yylex */ + +#ifndef yyerror +#define yyerror calc2_error +#endif /* yyerror */ + +#ifndef yychar +#define yychar calc2_char +#endif /* yychar */ + +#ifndef yyval +#define yyval calc2_val +#endif /* yyval */ + +#ifndef yylval +#define yylval calc2_lval +#endif /* yylval */ + +#ifndef yydebug +#define yydebug calc2_debug +#endif /* yydebug */ + +#ifndef yynerrs +#define yynerrs calc2_nerrs +#endif /* yynerrs */ + +#ifndef yyerrflag +#define yyerrflag calc2_errflag +#endif /* yyerrflag */ + +#ifndef yylhs +#define yylhs calc2_lhs +#endif /* yylhs */ + +#ifndef yylen +#define yylen calc2_len +#endif /* yylen */ + +#ifndef yydefred +#define yydefred calc2_defred +#endif /* yydefred */ + +#ifndef yydgoto +#define yydgoto calc2_dgoto +#endif /* yydgoto */ + +#ifndef yysindex +#define yysindex calc2_sindex +#endif /* yysindex */ + +#ifndef yyrindex +#define yyrindex calc2_rindex +#endif /* yyrindex */ + +#ifndef yygindex +#define yygindex calc2_gindex +#endif /* yygindex */ + +#ifndef yytable +#define yytable calc2_table +#endif /* yytable */ + +#ifndef yycheck +#define yycheck calc2_check +#endif /* yycheck */ + +#ifndef yyname +#define yyname calc2_name +#endif /* yyname */ + +#ifndef yyrule +#define yyrule calc2_rule +#endif /* yyrule */ +#define YYPREFIX "calc2_" + +#define YYPURE 0 + +#line 7 "calc2.y" +# include <stdio.h> +# include <ctype.h> + +#ifdef YYBISON +#define YYLEX_PARAM base +#define YYLEX_DECL() yylex(int *YYLEX_PARAM) +#define YYERROR_DECL() yyerror(int regs[26], int *base, const char *s) +int YYLEX_DECL(); +static void YYERROR_DECL(); +#endif + +#line 111 "calc2.tab.c" + +#ifndef YYSTYPE +typedef int YYSTYPE; +#endif + +/* compatibility with bison */ +#ifdef YYPARSE_PARAM +/* compatibility with FreeBSD */ +# ifdef YYPARSE_PARAM_TYPE +# define YYPARSE_DECL() yyparse(YYPARSE_PARAM_TYPE YYPARSE_PARAM) +# else +# define YYPARSE_DECL() yyparse(void *YYPARSE_PARAM) +# endif +#else +# define YYPARSE_DECL() yyparse(int regs[26], int * base) +#endif + +/* Parameters sent to lex. */ +#ifdef YYLEX_PARAM +# define YYLEX_DECL() yylex(void *YYLEX_PARAM) +# define YYLEX yylex(YYLEX_PARAM) +#else +# define YYLEX_DECL() yylex(int * base) +# define YYLEX yylex(base) +#endif + +/* Parameters sent to yyerror. */ +#ifndef YYERROR_DECL +#define YYERROR_DECL() yyerror(int regs[26], int * base, const char *s) +#endif +#ifndef YYERROR_CALL +#define YYERROR_CALL(msg) yyerror(regs, base, msg) +#endif + +extern int YYPARSE_DECL(); + +#define DIGIT 257 +#define LETTER 258 +#define UMINUS 259 +#define YYERRCODE 256 +static const short calc2_lhs[] = { -1, + 0, 0, 0, 1, 1, 2, 2, 2, 2, 2, + 2, 2, 2, 2, 2, 2, 3, 3, +}; +static const short calc2_len[] = { 2, + 0, 3, 3, 1, 3, 3, 3, 3, 3, 3, + 3, 3, 3, 2, 1, 1, 1, 2, +}; +static const short calc2_defred[] = { 1, + 0, 0, 17, 0, 0, 0, 0, 0, 0, 3, + 0, 15, 14, 0, 2, 0, 0, 0, 0, 0, + 0, 0, 18, 0, 6, 0, 0, 0, 0, 9, + 10, 11, +}; +static const short calc2_dgoto[] = { 1, + 7, 8, 9, +}; +static const short calc2_sindex[] = { 0, + -40, -7, 0, -55, -38, -38, 1, -29, -247, 0, + -38, 0, 0, 22, 0, -38, -38, -38, -38, -38, + -38, -38, 0, -29, 0, 51, 60, -20, -20, 0, + 0, 0, +}; +static const short calc2_rindex[] = { 0, + 0, 0, 0, 2, 0, 0, 0, 9, -9, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 10, 0, -6, 14, 5, 13, 0, + 0, 0, +}; +static const short calc2_gindex[] = { 0, + 0, 65, 0, +}; +#define YYTABLESIZE 220 +static const short calc2_table[] = { 6, + 16, 6, 10, 13, 5, 11, 5, 22, 17, 23, + 15, 15, 20, 18, 7, 19, 22, 21, 4, 5, + 0, 20, 8, 12, 0, 0, 21, 16, 16, 0, + 0, 16, 16, 16, 13, 16, 0, 16, 15, 15, + 0, 0, 7, 15, 15, 7, 15, 7, 15, 7, + 8, 12, 0, 8, 12, 8, 0, 8, 22, 17, + 0, 0, 25, 20, 18, 0, 19, 0, 21, 13, + 14, 0, 0, 0, 0, 24, 0, 0, 0, 0, + 26, 27, 28, 29, 30, 31, 32, 22, 17, 0, + 0, 0, 20, 18, 16, 19, 22, 21, 0, 0, + 0, 20, 18, 0, 19, 0, 21, 0, 0, 0, + 0, 0, 0, 0, 16, 0, 0, 13, 0, 0, + 0, 0, 0, 0, 0, 15, 0, 0, 7, 0, + 0, 0, 0, 0, 0, 0, 8, 12, 0, 0, + 0, 0, 0, 0, 0, 16, 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, 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, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 2, 3, 4, 3, 12, +}; +static const short calc2_check[] = { 40, + 10, 40, 10, 10, 45, 61, 45, 37, 38, 257, + 10, 10, 42, 43, 10, 45, 37, 47, 10, 10, + -1, 42, 10, 10, -1, -1, 47, 37, 38, -1, + -1, 41, 42, 43, 41, 45, -1, 47, 37, 38, + -1, -1, 38, 42, 43, 41, 45, 43, 47, 45, + 38, 38, -1, 41, 41, 43, -1, 45, 37, 38, + -1, -1, 41, 42, 43, -1, 45, -1, 47, 5, + 6, -1, -1, -1, -1, 11, -1, -1, -1, -1, + 16, 17, 18, 19, 20, 21, 22, 37, 38, -1, + -1, -1, 42, 43, 124, 45, 37, 47, -1, -1, + -1, 42, 43, -1, 45, -1, 47, -1, -1, -1, + -1, -1, -1, -1, 124, -1, -1, 124, -1, -1, + -1, -1, -1, -1, -1, 124, -1, -1, 124, -1, + -1, -1, -1, -1, -1, -1, 124, 124, -1, -1, + -1, -1, -1, -1, -1, 124, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, 256, 257, 258, 257, 258, +}; +#define YYFINAL 1 +#ifndef YYDEBUG +#define YYDEBUG 0 +#endif +#define YYMAXTOKEN 259 +#if YYDEBUG +static const char *yyname[] = { + +"end-of-file",0,0,0,0,0,0,0,0,0,"'\\n'",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,"'-'",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,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,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,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,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,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,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,0,0,0,0,0,0, +0,0,0,0,0,0,"DIGIT","LETTER","UMINUS", +}; +static const char *yyrule[] = { +"$accept : list", +"list :", +"list : list stat '\\n'", +"list : list error '\\n'", +"stat : expr", +"stat : LETTER '=' expr", +"expr : '(' expr ')'", +"expr : expr '+' expr", +"expr : expr '-' expr", +"expr : expr '*' expr", +"expr : expr '/' expr", +"expr : expr '%' expr", +"expr : expr '&' expr", +"expr : expr '|' expr", +"expr : '-' expr", +"expr : LETTER", +"expr : number", +"number : DIGIT", +"number : number DIGIT", + +}; +#endif + +int yydebug; +int yynerrs; + +int yyerrflag; +int yychar; +YYSTYPE yyval; +YYSTYPE yylval; + +/* define the initial stack-sizes */ +#ifdef YYSTACKSIZE +#undef YYMAXDEPTH +#define YYMAXDEPTH YYSTACKSIZE +#else +#ifdef YYMAXDEPTH +#define YYSTACKSIZE YYMAXDEPTH +#else +#define YYSTACKSIZE 500 +#define YYMAXDEPTH 500 +#endif +#endif + +#define YYINITSTACKSIZE 500 + +typedef struct { + unsigned stacksize; + short *s_base; + short *s_mark; + short *s_last; + YYSTYPE *l_base; + YYSTYPE *l_mark; +} YYSTACKDATA; +/* variables for the parser stack */ +static YYSTACKDATA yystack; +#line 73 "calc2.y" + /* start of programs */ + +#ifdef YYBYACC +extern int YYLEX_DECL(); +#endif + +int +main (void) +{ + int regs[26]; + int base = 10; + + while(!feof(stdin)) { + yyparse(regs, &base); + } + return 0; +} + +static void +YYERROR_DECL() +{ + fprintf(stderr, "%s\n", s); +} + +int +YYLEX_DECL() +{ + /* lexical analysis routine */ + /* returns LETTER for a lower case letter, yylval = 0 through 25 */ + /* return DIGIT for a digit, yylval = 0 through 9 */ + /* all other characters are returned immediately */ + + int c; + + while( (c=getchar()) == ' ' ) { /* skip blanks */ } + + /* c is now nonblank */ + + if( islower( c )) { + yylval = c - 'a'; + return ( LETTER ); + } + if( isdigit( c )) { + yylval = (c - '0') % (*base); + return ( DIGIT ); + } + return( c ); +} +#line 356 "calc2.tab.c" + +#if YYDEBUG +#include <stdio.h> /* needed for printf */ +#endif + +#include <stdlib.h> /* needed for malloc, etc */ +#include <string.h> /* needed for memset */ + +/* allocate initial stack or double stack size, up to YYMAXDEPTH */ +static int yygrowstack(YYSTACKDATA *data) +{ + int i; + unsigned newsize; + short *newss; + YYSTYPE *newvs; + + if ((newsize = data->stacksize) == 0) + newsize = YYINITSTACKSIZE; + else if (newsize >= YYMAXDEPTH) + return -1; + else if ((newsize *= 2) > YYMAXDEPTH) + newsize = YYMAXDEPTH; + + i = data->s_mark - data->s_base; + newss = (short *)realloc(data->s_base, newsize * sizeof(*newss)); + if (newss == 0) + return -1; + + data->s_base = newss; + data->s_mark = newss + i; + + newvs = (YYSTYPE *)realloc(data->l_base, newsize * sizeof(*newvs)); + if (newvs == 0) + return -1; + + data->l_base = newvs; + data->l_mark = newvs + i; + + data->stacksize = newsize; + data->s_last = data->s_base + newsize - 1; + return 0; +} + +#if YYPURE || defined(YY_NO_LEAKS) +static void yyfreestack(YYSTACKDATA *data) +{ + free(data->s_base); + free(data->l_base); + memset(data, 0, sizeof(*data)); +} +#else +#define yyfreestack(data) /* nothing */ +#endif + +#define YYABORT goto yyabort +#define YYREJECT goto yyabort +#define YYACCEPT goto yyaccept +#define YYERROR goto yyerrlab + +int +YYPARSE_DECL() +{ + int yym, yyn, yystate; +#if YYDEBUG + const char *yys; + + if ((yys = getenv("YYDEBUG")) != 0) + { + yyn = *yys; + if (yyn >= '0' && yyn <= '9') + yydebug = yyn - '0'; + } +#endif + + yynerrs = 0; + yyerrflag = 0; + yychar = YYEMPTY; + yystate = 0; + +#if YYPURE + memset(&yystack, 0, sizeof(yystack)); +#endif + + if (yystack.s_base == NULL && yygrowstack(&yystack)) goto yyoverflow; + yystack.s_mark = yystack.s_base; + yystack.l_mark = yystack.l_base; + yystate = 0; + *yystack.s_mark = 0; + +yyloop: + if ((yyn = yydefred[yystate]) != 0) goto yyreduce; + if (yychar < 0) + { + if ((yychar = YYLEX) < 0) yychar = 0; +#if YYDEBUG + if (yydebug) + { + yys = 0; + if (yychar <= YYMAXTOKEN) yys = yyname[yychar]; + if (!yys) yys = "illegal-symbol"; + printf("%sdebug: state %d, reading %d (%s)\n", + YYPREFIX, yystate, yychar, yys); + } +#endif + } + if ((yyn = yysindex[yystate]) && (yyn += yychar) >= 0 && + yyn <= YYTABLESIZE && yycheck[yyn] == yychar) + { +#if YYDEBUG + if (yydebug) + printf("%sdebug: state %d, shifting to state %d\n", + YYPREFIX, yystate, yytable[yyn]); +#endif + if (yystack.s_mark >= yystack.s_last && yygrowstack(&yystack)) + { + goto yyoverflow; + } + yystate = yytable[yyn]; + *++yystack.s_mark = yytable[yyn]; + *++yystack.l_mark = yylval; + yychar = YYEMPTY; + if (yyerrflag > 0) --yyerrflag; + goto yyloop; + } + if ((yyn = yyrindex[yystate]) && (yyn += yychar) >= 0 && + yyn <= YYTABLESIZE && yycheck[yyn] == yychar) + { + yyn = yytable[yyn]; + goto yyreduce; + } + if (yyerrflag) goto yyinrecovery; + + yyerror(regs, base, "syntax error"); + + goto yyerrlab; + +yyerrlab: + ++yynerrs; + +yyinrecovery: + if (yyerrflag < 3) + { + yyerrflag = 3; + for (;;) + { + if ((yyn = yysindex[*yystack.s_mark]) && (yyn += YYERRCODE) >= 0 && + yyn <= YYTABLESIZE && yycheck[yyn] == YYERRCODE) + { +#if YYDEBUG + if (yydebug) + printf("%sdebug: state %d, error recovery shifting\ + to state %d\n", YYPREFIX, *yystack.s_mark, yytable[yyn]); +#endif + if (yystack.s_mark >= yystack.s_last && yygrowstack(&yystack)) + { + goto yyoverflow; + } + yystate = yytable[yyn]; + *++yystack.s_mark = yytable[yyn]; + *++yystack.l_mark = yylval; + goto yyloop; + } + else + { +#if YYDEBUG + if (yydebug) + printf("%sdebug: error recovery discarding state %d\n", + YYPREFIX, *yystack.s_mark); +#endif + if (yystack.s_mark <= yystack.s_base) goto yyabort; + --yystack.s_mark; + --yystack.l_mark; + } + } + } + else + { + if (yychar == 0) goto yyabort; +#if YYDEBUG + if (yydebug) + { + yys = 0; + if (yychar <= YYMAXTOKEN) yys = yyname[yychar]; + if (!yys) yys = "illegal-symbol"; + printf("%sdebug: state %d, error recovery discards token %d (%s)\n", + YYPREFIX, yystate, yychar, yys); + } +#endif + yychar = YYEMPTY; + goto yyloop; + } + +yyreduce: +#if YYDEBUG + if (yydebug) + printf("%sdebug: state %d, reducing by rule %d (%s)\n", + YYPREFIX, yystate, yyn, yyrule[yyn]); +#endif + yym = yylen[yyn]; + if (yym) + yyval = yystack.l_mark[1-yym]; + else + memset(&yyval, 0, sizeof yyval); + switch (yyn) + { +case 3: +#line 35 "calc2.y" + { yyerrok ; } +break; +case 4: +#line 39 "calc2.y" + { printf("%d\n",yystack.l_mark[0]);} +break; +case 5: +#line 41 "calc2.y" + { regs[yystack.l_mark[-2]] = yystack.l_mark[0]; } +break; +case 6: +#line 45 "calc2.y" + { yyval = yystack.l_mark[-1]; } +break; +case 7: +#line 47 "calc2.y" + { yyval = yystack.l_mark[-2] + yystack.l_mark[0]; } +break; +case 8: +#line 49 "calc2.y" + { yyval = yystack.l_mark[-2] - yystack.l_mark[0]; } +break; +case 9: +#line 51 "calc2.y" + { yyval = yystack.l_mark[-2] * yystack.l_mark[0]; } +break; +case 10: +#line 53 "calc2.y" + { yyval = yystack.l_mark[-2] / yystack.l_mark[0]; } +break; +case 11: +#line 55 "calc2.y" + { yyval = yystack.l_mark[-2] % yystack.l_mark[0]; } +break; +case 12: +#line 57 "calc2.y" + { yyval = yystack.l_mark[-2] & yystack.l_mark[0]; } +break; +case 13: +#line 59 "calc2.y" + { yyval = yystack.l_mark[-2] | yystack.l_mark[0]; } +break; +case 14: +#line 61 "calc2.y" + { yyval = - yystack.l_mark[0]; } +break; +case 15: +#line 63 "calc2.y" + { yyval = regs[yystack.l_mark[0]]; } +break; +case 17: +#line 68 "calc2.y" + { yyval = yystack.l_mark[0]; (*base) = (yystack.l_mark[0]==0) ? 8 : 10; } +break; +case 18: +#line 70 "calc2.y" + { yyval = (*base) * yystack.l_mark[-1] + yystack.l_mark[0]; } +break; +#line 622 "calc2.tab.c" + } + yystack.s_mark -= yym; + yystate = *yystack.s_mark; + yystack.l_mark -= yym; + yym = yylhs[yyn]; + if (yystate == 0 && yym == 0) + { +#if YYDEBUG + if (yydebug) + printf("%sdebug: after reduction, shifting from state 0 to\ + state %d\n", YYPREFIX, YYFINAL); +#endif + yystate = YYFINAL; + *++yystack.s_mark = YYFINAL; + *++yystack.l_mark = yyval; + if (yychar < 0) + { + if ((yychar = YYLEX) < 0) yychar = 0; +#if YYDEBUG + if (yydebug) + { + yys = 0; + if (yychar <= YYMAXTOKEN) yys = yyname[yychar]; + if (!yys) yys = "illegal-symbol"; + printf("%sdebug: state %d, reading %d (%s)\n", + YYPREFIX, YYFINAL, yychar, yys); + } +#endif + } + if (yychar == 0) goto yyaccept; + goto yyloop; + } + if ((yyn = yygindex[yym]) && (yyn += yystate) >= 0 && + yyn <= YYTABLESIZE && yycheck[yyn] == yystate) + yystate = yytable[yyn]; + else + yystate = yydgoto[yym]; +#if YYDEBUG + if (yydebug) + printf("%sdebug: after reduction, shifting from state %d \ +to state %d\n", YYPREFIX, *yystack.s_mark, yystate); +#endif + if (yystack.s_mark >= yystack.s_last && yygrowstack(&yystack)) + { + goto yyoverflow; + } + *++yystack.s_mark = (short) yystate; + *++yystack.l_mark = yyval; + goto yyloop; + +yyoverflow: + yyerror(regs, base, "yacc stack overflow"); + +yyabort: + yyfreestack(&yystack); + return (1); + +yyaccept: + yyfreestack(&yystack); + return (0); +} diff --git a/test/calc2.tab.h b/test/calc2.tab.h new file mode 100644 index 000000000000..19211182d6b3 --- /dev/null +++ b/test/calc2.tab.h @@ -0,0 +1,3 @@ +#define DIGIT 257 +#define LETTER 258 +#define UMINUS 259 diff --git a/test/calc2.y b/test/calc2.y new file mode 100644 index 000000000000..e742ff34c215 --- /dev/null +++ b/test/calc2.y @@ -0,0 +1,120 @@ +%parse-param { int regs[26] } +%parse-param { int *base } + +%lex-param { int *base } + +%{ +# include <stdio.h> +# include <ctype.h> + +#ifdef YYBISON +#define YYLEX_PARAM base +#define YYLEX_DECL() yylex(int *YYLEX_PARAM) +#define YYERROR_DECL() yyerror(int regs[26], int *base, const char *s) +int YYLEX_DECL(); +static void YYERROR_DECL(); +#endif + +%} + +%start list + +%token DIGIT LETTER + +%left '|' +%left '&' +%left '+' '-' +%left '*' '/' '%' +%left UMINUS /* supplies precedence for unary minus */ + +%% /* beginning of rules section */ + +list : /* empty */ + | list stat '\n' + | list error '\n' + { yyerrok ; } + ; + +stat : expr + { printf("%d\n",$1);} + | LETTER '=' expr + { regs[$1] = $3; } + ; + +expr : '(' expr ')' + { $$ = $2; } + | expr '+' expr + { $$ = $1 + $3; } + | expr '-' expr + { $$ = $1 - $3; } + | expr '*' expr + { $$ = $1 * $3; } + | expr '/' expr + { $$ = $1 / $3; } + | expr '%' expr + { $$ = $1 % $3; } + | expr '&' expr + { $$ = $1 & $3; } + | expr '|' expr + { $$ = $1 | $3; } + | '-' expr %prec UMINUS + { $$ = - $2; } + | LETTER + { $$ = regs[$1]; } + | number + ; + +number: DIGIT + { $$ = $1; (*base) = ($1==0) ? 8 : 10; } + | number DIGIT + { $$ = (*base) * $1 + $2; } + ; + +%% /* start of programs */ + +#ifdef YYBYACC +extern int YYLEX_DECL(); +#endif + +int +main (void) +{ + int regs[26]; + int base = 10; + + while(!feof(stdin)) { + yyparse(regs, &base); + } + return 0; +} + +static void +YYERROR_DECL() +{ + fprintf(stderr, "%s\n", s); +} + +int +YYLEX_DECL() +{ + /* lexical analysis routine */ + /* returns LETTER for a lower case letter, yylval = 0 through 25 */ + /* return DIGIT for a digit, yylval = 0 through 9 */ + /* all other characters are returned immediately */ + + int c; + + while( (c=getchar()) == ' ' ) { /* skip blanks */ } + + /* c is now nonblank */ + + if( islower( c )) { + yylval = c - 'a'; + return ( LETTER ); + } + if( isdigit( c )) { + yylval = (c - '0') % (*base); + return ( DIGIT ); + } + return( c ); +} diff --git a/test/calc3.output b/test/calc3.output new file mode 100644 index 000000000000..3aed47511c93 --- /dev/null +++ b/test/calc3.output @@ -0,0 +1,461 @@ + 0 $accept : list $end + + 1 list : + 2 | list stat '\n' + 3 | list error '\n' + + 4 stat : expr + 5 | LETTER '=' expr + + 6 expr : '(' expr ')' + 7 | expr '+' expr + 8 | expr '-' expr + 9 | expr '*' expr + 10 | expr '/' expr + 11 | expr '%' expr + 12 | expr '&' expr + 13 | expr '|' expr + 14 | '-' expr + 15 | LETTER + 16 | number + + 17 number : DIGIT + 18 | number DIGIT + +state 0 + $accept : . list $end (0) + list : . (1) + + . reduce 1 + + list goto 1 + + +state 1 + $accept : list . $end (0) + list : list . stat '\n' (2) + list : list . error '\n' (3) + + $end accept + error shift 2 + DIGIT shift 3 + LETTER shift 4 + '-' shift 5 + '(' shift 6 + . error + + stat goto 7 + expr goto 8 + number goto 9 + + +state 2 + list : list error . '\n' (3) + + '\n' shift 10 + . error + + +state 3 + number : DIGIT . (17) + + . reduce 17 + + +state 4 + stat : LETTER . '=' expr (5) + expr : LETTER . (15) + + '=' shift 11 + '|' reduce 15 + '&' reduce 15 + '+' reduce 15 + '-' reduce 15 + '*' reduce 15 + '/' reduce 15 + '%' reduce 15 + '\n' reduce 15 + + +state 5 + expr : '-' . expr (14) + + DIGIT shift 3 + LETTER shift 12 + '-' shift 5 + '(' shift 6 + . error + + expr goto 13 + number goto 9 + + +state 6 + expr : '(' . expr ')' (6) + + DIGIT shift 3 + LETTER shift 12 + '-' shift 5 + '(' shift 6 + . error + + expr goto 14 + number goto 9 + + +state 7 + list : list stat . '\n' (2) + + '\n' shift 15 + . error + + +state 8 + stat : expr . (4) + expr : expr . '+' expr (7) + expr : expr . '-' expr (8) + expr : expr . '*' expr (9) + expr : expr . '/' expr (10) + expr : expr . '%' expr (11) + expr : expr . '&' expr (12) + expr : expr . '|' expr (13) + + '|' shift 16 + '&' shift 17 + '+' shift 18 + '-' shift 19 + '*' shift 20 + '/' shift 21 + '%' shift 22 + '\n' reduce 4 + + +state 9 + expr : number . (16) + number : number . DIGIT (18) + + DIGIT shift 23 + '|' reduce 16 + '&' reduce 16 + '+' reduce 16 + '-' reduce 16 + '*' reduce 16 + '/' reduce 16 + '%' reduce 16 + '\n' reduce 16 + ')' reduce 16 + + +state 10 + list : list error '\n' . (3) + + . reduce 3 + + +state 11 + stat : LETTER '=' . expr (5) + + DIGIT shift 3 + LETTER shift 12 + '-' shift 5 + '(' shift 6 + . error + + expr goto 24 + number goto 9 + + +state 12 + expr : LETTER . (15) + + . reduce 15 + + +state 13 + expr : expr . '+' expr (7) + expr : expr . '-' expr (8) + expr : expr . '*' expr (9) + expr : expr . '/' expr (10) + expr : expr . '%' expr (11) + expr : expr . '&' expr (12) + expr : expr . '|' expr (13) + expr : '-' expr . (14) + + . reduce 14 + + +state 14 + expr : '(' expr . ')' (6) + expr : expr . '+' expr (7) + expr : expr . '-' expr (8) + expr : expr . '*' expr (9) + expr : expr . '/' expr (10) + expr : expr . '%' expr (11) + expr : expr . '&' expr (12) + expr : expr . '|' expr (13) + + '|' shift 16 + '&' shift 17 + '+' shift 18 + '-' shift 19 + '*' shift 20 + '/' shift 21 + '%' shift 22 + ')' shift 25 + . error + + +state 15 + list : list stat '\n' . (2) + + . reduce 2 + + +state 16 + expr : expr '|' . expr (13) + + DIGIT shift 3 + LETTER shift 12 + '-' shift 5 + '(' shift 6 + . error + + expr goto 26 + number goto 9 + + +state 17 + expr : expr '&' . expr (12) + + DIGIT shift 3 + LETTER shift 12 + '-' shift 5 + '(' shift 6 + . error + + expr goto 27 + number goto 9 + + +state 18 + expr : expr '+' . expr (7) + + DIGIT shift 3 + LETTER shift 12 + '-' shift 5 + '(' shift 6 + . error + + expr goto 28 + number goto 9 + + +state 19 + expr : expr '-' . expr (8) + + DIGIT shift 3 + LETTER shift 12 + '-' shift 5 + '(' shift 6 + . error + + expr goto 29 + number goto 9 + + +state 20 + expr : expr '*' . expr (9) + + DIGIT shift 3 + LETTER shift 12 + '-' shift 5 + '(' shift 6 + . error + + expr goto 30 + number goto 9 + + +state 21 + expr : expr '/' . expr (10) + + DIGIT shift 3 + LETTER shift 12 + '-' shift 5 + '(' shift 6 + . error + + expr goto 31 + number goto 9 + + +state 22 + expr : expr '%' . expr (11) + + DIGIT shift 3 + LETTER shift 12 + '-' shift 5 + '(' shift 6 + . error + + expr goto 32 + number goto 9 + + +state 23 + number : number DIGIT . (18) + + . reduce 18 + + +state 24 + stat : LETTER '=' expr . (5) + expr : expr . '+' expr (7) + expr : expr . '-' expr (8) + expr : expr . '*' expr (9) + expr : expr . '/' expr (10) + expr : expr . '%' expr (11) + expr : expr . '&' expr (12) + expr : expr . '|' expr (13) + + '|' shift 16 + '&' shift 17 + '+' shift 18 + '-' shift 19 + '*' shift 20 + '/' shift 21 + '%' shift 22 + '\n' reduce 5 + + +state 25 + expr : '(' expr ')' . (6) + + . reduce 6 + + +state 26 + expr : expr . '+' expr (7) + expr : expr . '-' expr (8) + expr : expr . '*' expr (9) + expr : expr . '/' expr (10) + expr : expr . '%' expr (11) + expr : expr . '&' expr (12) + expr : expr . '|' expr (13) + expr : expr '|' expr . (13) + + '&' shift 17 + '+' shift 18 + '-' shift 19 + '*' shift 20 + '/' shift 21 + '%' shift 22 + '|' reduce 13 + '\n' reduce 13 + ')' reduce 13 + + +state 27 + expr : expr . '+' expr (7) + expr : expr . '-' expr (8) + expr : expr . '*' expr (9) + expr : expr . '/' expr (10) + expr : expr . '%' expr (11) + expr : expr . '&' expr (12) + expr : expr '&' expr . (12) + expr : expr . '|' expr (13) + + '+' shift 18 + '-' shift 19 + '*' shift 20 + '/' shift 21 + '%' shift 22 + '|' reduce 12 + '&' reduce 12 + '\n' reduce 12 + ')' reduce 12 + + +state 28 + expr : expr . '+' expr (7) + expr : expr '+' expr . (7) + expr : expr . '-' expr (8) + expr : expr . '*' expr (9) + expr : expr . '/' expr (10) + expr : expr . '%' expr (11) + expr : expr . '&' expr (12) + expr : expr . '|' expr (13) + + '*' shift 20 + '/' shift 21 + '%' shift 22 + '|' reduce 7 + '&' reduce 7 + '+' reduce 7 + '-' reduce 7 + '\n' reduce 7 + ')' reduce 7 + + +state 29 + expr : expr . '+' expr (7) + expr : expr . '-' expr (8) + expr : expr '-' expr . (8) + expr : expr . '*' expr (9) + expr : expr . '/' expr (10) + expr : expr . '%' expr (11) + expr : expr . '&' expr (12) + expr : expr . '|' expr (13) + + '*' shift 20 + '/' shift 21 + '%' shift 22 + '|' reduce 8 + '&' reduce 8 + '+' reduce 8 + '-' reduce 8 + '\n' reduce 8 + ')' reduce 8 + + +state 30 + expr : expr . '+' expr (7) + expr : expr . '-' expr (8) + expr : expr . '*' expr (9) + expr : expr '*' expr . (9) + expr : expr . '/' expr (10) + expr : expr . '%' expr (11) + expr : expr . '&' expr (12) + expr : expr . '|' expr (13) + + . reduce 9 + + +state 31 + expr : expr . '+' expr (7) + expr : expr . '-' expr (8) + expr : expr . '*' expr (9) + expr : expr . '/' expr (10) + expr : expr '/' expr . (10) + expr : expr . '%' expr (11) + expr : expr . '&' expr (12) + expr : expr . '|' expr (13) + + . reduce 10 + + +state 32 + expr : expr . '+' expr (7) + expr : expr . '-' expr (8) + expr : expr . '*' expr (9) + expr : expr . '/' expr (10) + expr : expr . '%' expr (11) + expr : expr '%' expr . (11) + expr : expr . '&' expr (12) + expr : expr . '|' expr (13) + + . reduce 11 + + +16 terminals, 5 nonterminals +19 grammar rules, 33 states diff --git a/test/calc3.tab.c b/test/calc3.tab.c new file mode 100644 index 000000000000..9c38899beba7 --- /dev/null +++ b/test/calc3.tab.c @@ -0,0 +1,687 @@ +#ifndef lint +static const char yysccsid[] = "@(#)yaccpar 1.9 (Berkeley) 02/21/93"; +#endif + +#define YYBYACC 1 +#define YYMAJOR 1 +#define YYMINOR 9 + +#define YYEMPTY (-1) +#define yyclearin (yychar = YYEMPTY) +#define yyerrok (yyerrflag = 0) +#define YYRECOVERING() (yyerrflag != 0) + + +#ifndef yyparse +#define yyparse calc3_parse +#endif /* yyparse */ + +#ifndef yylex +#define yylex calc3_lex +#endif /* yylex */ + +#ifndef yyerror +#define yyerror calc3_error +#endif /* yyerror */ + +#ifndef yychar +#define yychar calc3_char +#endif /* yychar */ + +#ifndef yyval +#define yyval calc3_val +#endif /* yyval */ + +#ifndef yylval +#define yylval calc3_lval +#endif /* yylval */ + +#ifndef yydebug +#define yydebug calc3_debug +#endif /* yydebug */ + +#ifndef yynerrs +#define yynerrs calc3_nerrs +#endif /* yynerrs */ + +#ifndef yyerrflag +#define yyerrflag calc3_errflag +#endif /* yyerrflag */ + +#ifndef yylhs +#define yylhs calc3_lhs +#endif /* yylhs */ + +#ifndef yylen +#define yylen calc3_len +#endif /* yylen */ + +#ifndef yydefred +#define yydefred calc3_defred +#endif /* yydefred */ + +#ifndef yydgoto +#define yydgoto calc3_dgoto +#endif /* yydgoto */ + +#ifndef yysindex +#define yysindex calc3_sindex +#endif /* yysindex */ + +#ifndef yyrindex +#define yyrindex calc3_rindex +#endif /* yyrindex */ + +#ifndef yygindex +#define yygindex calc3_gindex +#endif /* yygindex */ + +#ifndef yytable +#define yytable calc3_table +#endif /* yytable */ + +#ifndef yycheck +#define yycheck calc3_check +#endif /* yycheck */ + +#ifndef yyname +#define yyname calc3_name +#endif /* yyname */ + +#ifndef yyrule +#define yyrule calc3_rule +#endif /* yyrule */ +#define YYPREFIX "calc3_" + +#define YYPURE 1 + +#line 9 "calc3.y" +# include <stdio.h> +# include <ctype.h> + +#ifdef YYBISON +#define YYSTYPE int +#define YYLEX_PARAM base +#define YYLEX_DECL() yylex(YYSTYPE *yylval, int *YYLEX_PARAM) +#define YYERROR_DECL() yyerror(int regs[26], int *base, const char *s) +int YYLEX_DECL(); +static void YYERROR_DECL(); +#endif + +#line 112 "calc3.tab.c" + +#ifndef YYSTYPE +typedef int YYSTYPE; +#endif + +/* compatibility with bison */ +#ifdef YYPARSE_PARAM +/* compatibility with FreeBSD */ +# ifdef YYPARSE_PARAM_TYPE +# define YYPARSE_DECL() yyparse(YYPARSE_PARAM_TYPE YYPARSE_PARAM) +# else +# define YYPARSE_DECL() yyparse(void *YYPARSE_PARAM) +# endif +#else +# define YYPARSE_DECL() yyparse(int regs[26], int * base) +#endif + +/* Parameters sent to lex. */ +#ifdef YYLEX_PARAM +# ifdef YYLEX_PARAM_TYPE +# define YYLEX_DECL() yylex(YYSTYPE *yylval, YYLEX_PARAM_TYPE YYLEX_PARAM) +# else +# define YYLEX_DECL() yylex(YYSTYPE *yylval, void * YYLEX_PARAM) +# endif +# define YYLEX yylex(&yylval, YYLEX_PARAM) +#else +# define YYLEX_DECL() yylex(YYSTYPE *yylval, int * base) +# define YYLEX yylex(&yylval, base) +#endif + +/* Parameters sent to yyerror. */ +#ifndef YYERROR_DECL +#define YYERROR_DECL() yyerror(int regs[26], int * base, const char *s) +#endif +#ifndef YYERROR_CALL +#define YYERROR_CALL(msg) yyerror(regs, base, msg) +#endif + +extern int YYPARSE_DECL(); + +#define DIGIT 257 +#define LETTER 258 +#define UMINUS 259 +#define YYERRCODE 256 +static const short calc3_lhs[] = { -1, + 0, 0, 0, 1, 1, 2, 2, 2, 2, 2, + 2, 2, 2, 2, 2, 2, 3, 3, +}; +static const short calc3_len[] = { 2, + 0, 3, 3, 1, 3, 3, 3, 3, 3, 3, + 3, 3, 3, 2, 1, 1, 1, 2, +}; +static const short calc3_defred[] = { 1, + 0, 0, 17, 0, 0, 0, 0, 0, 0, 3, + 0, 15, 14, 0, 2, 0, 0, 0, 0, 0, + 0, 0, 18, 0, 6, 0, 0, 0, 0, 9, + 10, 11, +}; +static const short calc3_dgoto[] = { 1, + 7, 8, 9, +}; +static const short calc3_sindex[] = { 0, + -40, -7, 0, -55, -38, -38, 1, -29, -247, 0, + -38, 0, 0, 22, 0, -38, -38, -38, -38, -38, + -38, -38, 0, -29, 0, 51, 60, -20, -20, 0, + 0, 0, +}; +static const short calc3_rindex[] = { 0, + 0, 0, 0, 2, 0, 0, 0, 9, -9, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 10, 0, -6, 14, 5, 13, 0, + 0, 0, +}; +static const short calc3_gindex[] = { 0, + 0, 65, 0, +}; +#define YYTABLESIZE 220 +static const short calc3_table[] = { 6, + 16, 6, 10, 13, 5, 11, 5, 22, 17, 23, + 15, 15, 20, 18, 7, 19, 22, 21, 4, 5, + 0, 20, 8, 12, 0, 0, 21, 16, 16, 0, + 0, 16, 16, 16, 13, 16, 0, 16, 15, 15, + 0, 0, 7, 15, 15, 7, 15, 7, 15, 7, + 8, 12, 0, 8, 12, 8, 0, 8, 22, 17, + 0, 0, 25, 20, 18, 0, 19, 0, 21, 13, + 14, 0, 0, 0, 0, 24, 0, 0, 0, 0, + 26, 27, 28, 29, 30, 31, 32, 22, 17, 0, + 0, 0, 20, 18, 16, 19, 22, 21, 0, 0, + 0, 20, 18, 0, 19, 0, 21, 0, 0, 0, + 0, 0, 0, 0, 16, 0, 0, 13, 0, 0, + 0, 0, 0, 0, 0, 15, 0, 0, 7, 0, + 0, 0, 0, 0, 0, 0, 8, 12, 0, 0, + 0, 0, 0, 0, 0, 16, 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, 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, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 2, 3, 4, 3, 12, +}; +static const short calc3_check[] = { 40, + 10, 40, 10, 10, 45, 61, 45, 37, 38, 257, + 10, 10, 42, 43, 10, 45, 37, 47, 10, 10, + -1, 42, 10, 10, -1, -1, 47, 37, 38, -1, + -1, 41, 42, 43, 41, 45, -1, 47, 37, 38, + -1, -1, 38, 42, 43, 41, 45, 43, 47, 45, + 38, 38, -1, 41, 41, 43, -1, 45, 37, 38, + -1, -1, 41, 42, 43, -1, 45, -1, 47, 5, + 6, -1, -1, -1, -1, 11, -1, -1, -1, -1, + 16, 17, 18, 19, 20, 21, 22, 37, 38, -1, + -1, -1, 42, 43, 124, 45, 37, 47, -1, -1, + -1, 42, 43, -1, 45, -1, 47, -1, -1, -1, + -1, -1, -1, -1, 124, -1, -1, 124, -1, -1, + -1, -1, -1, -1, -1, 124, -1, -1, 124, -1, + -1, -1, -1, -1, -1, -1, 124, 124, -1, -1, + -1, -1, -1, -1, -1, 124, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, 256, 257, 258, 257, 258, +}; +#define YYFINAL 1 +#ifndef YYDEBUG +#define YYDEBUG 0 +#endif +#define YYMAXTOKEN 259 +#if YYDEBUG +static const char *yyname[] = { + +"end-of-file",0,0,0,0,0,0,0,0,0,"'\\n'",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,"'-'",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,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,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,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,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,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,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,0,0,0,0,0,0, +0,0,0,0,0,0,"DIGIT","LETTER","UMINUS", +}; +static const char *yyrule[] = { +"$accept : list", +"list :", +"list : list stat '\\n'", +"list : list error '\\n'", +"stat : expr", +"stat : LETTER '=' expr", +"expr : '(' expr ')'", +"expr : expr '+' expr", +"expr : expr '-' expr", +"expr : expr '*' expr", +"expr : expr '/' expr", +"expr : expr '%' expr", +"expr : expr '&' expr", +"expr : expr '|' expr", +"expr : '-' expr", +"expr : LETTER", +"expr : number", +"number : DIGIT", +"number : number DIGIT", + +}; +#endif + +int yydebug; +int yynerrs; + +/* define the initial stack-sizes */ +#ifdef YYSTACKSIZE +#undef YYMAXDEPTH +#define YYMAXDEPTH YYSTACKSIZE +#else +#ifdef YYMAXDEPTH +#define YYSTACKSIZE YYMAXDEPTH +#else +#define YYSTACKSIZE 500 +#define YYMAXDEPTH 500 +#endif +#endif + +#define YYINITSTACKSIZE 500 + +typedef struct { + unsigned stacksize; + short *s_base; + short *s_mark; + short *s_last; + YYSTYPE *l_base; + YYSTYPE *l_mark; +} YYSTACKDATA; +#line 76 "calc3.y" + /* start of programs */ + +#ifdef YYBYACC +extern int YYLEX_DECL(); +#endif + +int +main (void) +{ + int regs[26]; + int base = 10; + + while(!feof(stdin)) { + yyparse(regs, &base); + } + return 0; +} + +static void +YYERROR_DECL() +{ + fprintf(stderr, "%s\n", s); +} + +int +YYLEX_DECL() +{ + /* lexical analysis routine */ + /* returns LETTER for a lower case letter, yylval = 0 through 25 */ + /* return DIGIT for a digit, yylval = 0 through 9 */ + /* all other characters are returned immediately */ + + int c; + + while( (c=getchar()) == ' ' ) { /* skip blanks */ } + + /* c is now nonblank */ + + if( islower( c )) { + *yylval = (c - 'a'); + return ( LETTER ); + } + if( isdigit( c )) { + *yylval = (c - '0') % (*base); + return ( DIGIT ); + } + return( c ); +} +#line 354 "calc3.tab.c" + +#if YYDEBUG +#include <stdio.h> /* needed for printf */ +#endif + +#include <stdlib.h> /* needed for malloc, etc */ +#include <string.h> /* needed for memset */ + +/* allocate initial stack or double stack size, up to YYMAXDEPTH */ +static int yygrowstack(YYSTACKDATA *data) +{ + int i; + unsigned newsize; + short *newss; + YYSTYPE *newvs; + + if ((newsize = data->stacksize) == 0) + newsize = YYINITSTACKSIZE; + else if (newsize >= YYMAXDEPTH) + return -1; + else if ((newsize *= 2) > YYMAXDEPTH) + newsize = YYMAXDEPTH; + + i = data->s_mark - data->s_base; + newss = (short *)realloc(data->s_base, newsize * sizeof(*newss)); + if (newss == 0) + return -1; + + data->s_base = newss; + data->s_mark = newss + i; + + newvs = (YYSTYPE *)realloc(data->l_base, newsize * sizeof(*newvs)); + if (newvs == 0) + return -1; + + data->l_base = newvs; + data->l_mark = newvs + i; + + data->stacksize = newsize; + data->s_last = data->s_base + newsize - 1; + return 0; +} + +#if YYPURE || defined(YY_NO_LEAKS) +static void yyfreestack(YYSTACKDATA *data) +{ + free(data->s_base); + free(data->l_base); + memset(data, 0, sizeof(*data)); +} +#else +#define yyfreestack(data) /* nothing */ +#endif + +#define YYABORT goto yyabort +#define YYREJECT goto yyabort +#define YYACCEPT goto yyaccept +#define YYERROR goto yyerrlab + +int +YYPARSE_DECL() +{ + int yyerrflag; + int yychar; + YYSTYPE yyval; + YYSTYPE yylval; + + /* variables for the parser stack */ + YYSTACKDATA yystack; + int yym, yyn, yystate; +#if YYDEBUG + const char *yys; + + if ((yys = getenv("YYDEBUG")) != 0) + { + yyn = *yys; + if (yyn >= '0' && yyn <= '9') + yydebug = yyn - '0'; + } +#endif + + yynerrs = 0; + yyerrflag = 0; + yychar = YYEMPTY; + yystate = 0; + +#if YYPURE + memset(&yystack, 0, sizeof(yystack)); +#endif + + if (yystack.s_base == NULL && yygrowstack(&yystack)) goto yyoverflow; + yystack.s_mark = yystack.s_base; + yystack.l_mark = yystack.l_base; + yystate = 0; + *yystack.s_mark = 0; + +yyloop: + if ((yyn = yydefred[yystate]) != 0) goto yyreduce; + if (yychar < 0) + { + if ((yychar = YYLEX) < 0) yychar = 0; +#if YYDEBUG + if (yydebug) + { + yys = 0; + if (yychar <= YYMAXTOKEN) yys = yyname[yychar]; + if (!yys) yys = "illegal-symbol"; + printf("%sdebug: state %d, reading %d (%s)\n", + YYPREFIX, yystate, yychar, yys); + } +#endif + } + if ((yyn = yysindex[yystate]) && (yyn += yychar) >= 0 && + yyn <= YYTABLESIZE && yycheck[yyn] == yychar) + { +#if YYDEBUG + if (yydebug) + printf("%sdebug: state %d, shifting to state %d\n", + YYPREFIX, yystate, yytable[yyn]); +#endif + if (yystack.s_mark >= yystack.s_last && yygrowstack(&yystack)) + { + goto yyoverflow; + } + yystate = yytable[yyn]; + *++yystack.s_mark = yytable[yyn]; + *++yystack.l_mark = yylval; + yychar = YYEMPTY; + if (yyerrflag > 0) --yyerrflag; + goto yyloop; + } + if ((yyn = yyrindex[yystate]) && (yyn += yychar) >= 0 && + yyn <= YYTABLESIZE && yycheck[yyn] == yychar) + { + yyn = yytable[yyn]; + goto yyreduce; + } + if (yyerrflag) goto yyinrecovery; + + yyerror(regs, base, "syntax error"); + + goto yyerrlab; + +yyerrlab: + ++yynerrs; + +yyinrecovery: + if (yyerrflag < 3) + { + yyerrflag = 3; + for (;;) + { + if ((yyn = yysindex[*yystack.s_mark]) && (yyn += YYERRCODE) >= 0 && + yyn <= YYTABLESIZE && yycheck[yyn] == YYERRCODE) + { +#if YYDEBUG + if (yydebug) + printf("%sdebug: state %d, error recovery shifting\ + to state %d\n", YYPREFIX, *yystack.s_mark, yytable[yyn]); +#endif + if (yystack.s_mark >= yystack.s_last && yygrowstack(&yystack)) + { + goto yyoverflow; + } + yystate = yytable[yyn]; + *++yystack.s_mark = yytable[yyn]; + *++yystack.l_mark = yylval; + goto yyloop; + } + else + { +#if YYDEBUG + if (yydebug) + printf("%sdebug: error recovery discarding state %d\n", + YYPREFIX, *yystack.s_mark); +#endif + if (yystack.s_mark <= yystack.s_base) goto yyabort; + --yystack.s_mark; + --yystack.l_mark; + } + } + } + else + { + if (yychar == 0) goto yyabort; +#if YYDEBUG + if (yydebug) + { + yys = 0; + if (yychar <= YYMAXTOKEN) yys = yyname[yychar]; + if (!yys) yys = "illegal-symbol"; + printf("%sdebug: state %d, error recovery discards token %d (%s)\n", + YYPREFIX, yystate, yychar, yys); + } +#endif + yychar = YYEMPTY; + goto yyloop; + } + +yyreduce: +#if YYDEBUG + if (yydebug) + printf("%sdebug: state %d, reducing by rule %d (%s)\n", + YYPREFIX, yystate, yyn, yyrule[yyn]); +#endif + yym = yylen[yyn]; + if (yym) + yyval = yystack.l_mark[1-yym]; + else + memset(&yyval, 0, sizeof yyval); + switch (yyn) + { +case 3: +#line 38 "calc3.y" + { yyerrok ; } +break; +case 4: +#line 42 "calc3.y" + { printf("%d\n",yystack.l_mark[0]);} +break; +case 5: +#line 44 "calc3.y" + { regs[yystack.l_mark[-2]] = yystack.l_mark[0]; } +break; +case 6: +#line 48 "calc3.y" + { yyval = yystack.l_mark[-1]; } +break; +case 7: +#line 50 "calc3.y" + { yyval = yystack.l_mark[-2] + yystack.l_mark[0]; } +break; +case 8: +#line 52 "calc3.y" + { yyval = yystack.l_mark[-2] - yystack.l_mark[0]; } +break; +case 9: +#line 54 "calc3.y" + { yyval = yystack.l_mark[-2] * yystack.l_mark[0]; } +break; +case 10: +#line 56 "calc3.y" + { yyval = yystack.l_mark[-2] / yystack.l_mark[0]; } +break; +case 11: +#line 58 "calc3.y" + { yyval = yystack.l_mark[-2] % yystack.l_mark[0]; } +break; +case 12: +#line 60 "calc3.y" + { yyval = yystack.l_mark[-2] & yystack.l_mark[0]; } +break; +case 13: +#line 62 "calc3.y" + { yyval = yystack.l_mark[-2] | yystack.l_mark[0]; } +break; +case 14: +#line 64 "calc3.y" + { yyval = - yystack.l_mark[0]; } +break; +case 15: +#line 66 "calc3.y" + { yyval = regs[yystack.l_mark[0]]; } +break; +case 17: +#line 71 "calc3.y" + { yyval = yystack.l_mark[0]; (*base) = (yystack.l_mark[0]==0) ? 8 : 10; } +break; +case 18: +#line 73 "calc3.y" + { yyval = (*base) * yystack.l_mark[-1] + yystack.l_mark[0]; } +break; +#line 627 "calc3.tab.c" + } + yystack.s_mark -= yym; + yystate = *yystack.s_mark; + yystack.l_mark -= yym; + yym = yylhs[yyn]; + if (yystate == 0 && yym == 0) + { +#if YYDEBUG + if (yydebug) + printf("%sdebug: after reduction, shifting from state 0 to\ + state %d\n", YYPREFIX, YYFINAL); +#endif + yystate = YYFINAL; + *++yystack.s_mark = YYFINAL; + *++yystack.l_mark = yyval; + if (yychar < 0) + { + if ((yychar = YYLEX) < 0) yychar = 0; +#if YYDEBUG + if (yydebug) + { + yys = 0; + if (yychar <= YYMAXTOKEN) yys = yyname[yychar]; + if (!yys) yys = "illegal-symbol"; + printf("%sdebug: state %d, reading %d (%s)\n", + YYPREFIX, YYFINAL, yychar, yys); + } +#endif + } + if (yychar == 0) goto yyaccept; + goto yyloop; + } + if ((yyn = yygindex[yym]) && (yyn += yystate) >= 0 && + yyn <= YYTABLESIZE && yycheck[yyn] == yystate) + yystate = yytable[yyn]; + else + yystate = yydgoto[yym]; +#if YYDEBUG + if (yydebug) + printf("%sdebug: after reduction, shifting from state %d \ +to state %d\n", YYPREFIX, *yystack.s_mark, yystate); +#endif + if (yystack.s_mark >= yystack.s_last && yygrowstack(&yystack)) + { + goto yyoverflow; + } + *++yystack.s_mark = (short) yystate; + *++yystack.l_mark = yyval; + goto yyloop; + +yyoverflow: + yyerror(regs, base, "yacc stack overflow"); + +yyabort: + yyfreestack(&yystack); + return (1); + +yyaccept: + yyfreestack(&yystack); + return (0); +} diff --git a/test/calc3.tab.h b/test/calc3.tab.h new file mode 100644 index 000000000000..19211182d6b3 --- /dev/null +++ b/test/calc3.tab.h @@ -0,0 +1,3 @@ +#define DIGIT 257 +#define LETTER 258 +#define UMINUS 259 diff --git a/test/calc3.y b/test/calc3.y new file mode 100644 index 000000000000..252faa961f4b --- /dev/null +++ b/test/calc3.y @@ -0,0 +1,123 @@ +%pure-parser + +%parse-param { int regs[26] } +%parse-param { int *base } + +%lex-param { int *base } + +%{ +# include <stdio.h> +# include <ctype.h> + +#ifdef YYBISON +#define YYSTYPE int +#define YYLEX_PARAM base +#define YYLEX_DECL() yylex(YYSTYPE *yylval, int *YYLEX_PARAM) +#define YYERROR_DECL() yyerror(int regs[26], int *base, const char *s) +int YYLEX_DECL(); +static void YYERROR_DECL(); +#endif + +%} + +%start list + +%token DIGIT LETTER + +%left '|' +%left '&' +%left '+' '-' +%left '*' '/' '%' +%left UMINUS /* supplies precedence for unary minus */ + +%% /* beginning of rules section */ + +list : /* empty */ + | list stat '\n' + | list error '\n' + { yyerrok ; } + ; + +stat : expr + { printf("%d\n",$1);} + | LETTER '=' expr + { regs[$1] = $3; } + ; + +expr : '(' expr ')' + { $$ = $2; } + | expr '+' expr + { $$ = $1 + $3; } + | expr '-' expr + { $$ = $1 - $3; } + | expr '*' expr + { $$ = $1 * $3; } + | expr '/' expr + { $$ = $1 / $3; } + | expr '%' expr + { $$ = $1 % $3; } + | expr '&' expr + { $$ = $1 & $3; } + | expr '|' expr + { $$ = $1 | $3; } + | '-' expr %prec UMINUS + { $$ = - $2; } + | LETTER + { $$ = regs[$1]; } + | number + ; + +number: DIGIT + { $$ = $1; (*base) = ($1==0) ? 8 : 10; } + | number DIGIT + { $$ = (*base) * $1 + $2; } + ; + +%% /* start of programs */ + +#ifdef YYBYACC +extern int YYLEX_DECL(); +#endif + +int +main (void) +{ + int regs[26]; + int base = 10; + + while(!feof(stdin)) { + yyparse(regs, &base); + } + return 0; +} + +static void +YYERROR_DECL() +{ + fprintf(stderr, "%s\n", s); +} + +int +YYLEX_DECL() +{ + /* lexical analysis routine */ + /* returns LETTER for a lower case letter, yylval = 0 through 25 */ + /* return DIGIT for a digit, yylval = 0 through 9 */ + /* all other characters are returned immediately */ + + int c; + + while( (c=getchar()) == ' ' ) { /* skip blanks */ } + + /* c is now nonblank */ + + if( islower( c )) { + *yylval = (c - 'a'); + return ( LETTER ); + } + if( isdigit( c )) { + *yylval = (c - '0') % (*base); + return ( DIGIT ); + } + return( c ); +} diff --git a/test/code_calc.code.c b/test/code_calc.code.c new file mode 100644 index 000000000000..a3cf368a07a4 --- /dev/null +++ b/test/code_calc.code.c @@ -0,0 +1,580 @@ +#ifndef lint +static const char yysccsid[] = "@(#)yaccpar 1.9 (Berkeley) 02/21/93"; +#endif + +#define YYBYACC 1 +#define YYMAJOR 1 +#define YYMINOR 9 + +#define YYEMPTY (-1) +#define yyclearin (yychar = YYEMPTY) +#define yyerrok (yyerrflag = 0) +#define YYRECOVERING() (yyerrflag != 0) + + +#define YYPURE 0 + +#line 2 "code_calc.y" +# include <stdio.h> +# include <ctype.h> + +int regs[26]; +int base; + +#ifdef YYBISON +int yylex(void); +static void yyerror(const char *s); +#endif + +#line 30 "code_calc.code.c" + +#ifndef YYSTYPE +typedef int YYSTYPE; +#endif + +/* compatibility with bison */ +#ifdef YYPARSE_PARAM +/* compatibility with FreeBSD */ +# ifdef YYPARSE_PARAM_TYPE +# define YYPARSE_DECL() yyparse(YYPARSE_PARAM_TYPE YYPARSE_PARAM) +# else +# define YYPARSE_DECL() yyparse(void *YYPARSE_PARAM) +# endif +#else +# define YYPARSE_DECL() yyparse(void) +#endif + +/* Parameters sent to lex. */ +#ifdef YYLEX_PARAM +# define YYLEX_DECL() yylex(void *YYLEX_PARAM) +# define YYLEX yylex(YYLEX_PARAM) +#else +# define YYLEX_DECL() yylex(void) +# define YYLEX yylex() +#endif + +/* Parameters sent to yyerror. */ +#ifndef YYERROR_DECL +#define YYERROR_DECL() yyerror(const char *s) +#endif +#ifndef YYERROR_CALL +#define YYERROR_CALL(msg) yyerror(msg) +#endif + +extern int YYPARSE_DECL(); + +#define DIGIT 257 +#define LETTER 258 +#define UMINUS 259 +#define YYERRCODE 256 +#define YYTABLESIZE 220 +#define YYFINAL 1 +#ifndef YYDEBUG +#define YYDEBUG 0 +#endif +#define YYMAXTOKEN 259 + +#ifndef yyparse +#define yyparse calc_parse +#endif /* yyparse */ + +#ifndef yylex +#define yylex calc_lex +#endif /* yylex */ + +#ifndef yyerror +#define yyerror calc_error +#endif /* yyerror */ + +#ifndef yychar +#define yychar calc_char +#endif /* yychar */ + +#ifndef yyval +#define yyval calc_val +#endif /* yyval */ + +#ifndef yylval +#define yylval calc_lval +#endif /* yylval */ + +#ifndef yydebug +#define yydebug calc_debug +#endif /* yydebug */ + +#ifndef yynerrs +#define yynerrs calc_nerrs +#endif /* yynerrs */ + +#ifndef yyerrflag +#define yyerrflag calc_errflag +#endif /* yyerrflag */ + +#ifndef yylhs +#define yylhs calc_lhs +#endif /* yylhs */ + +#ifndef yylen +#define yylen calc_len +#endif /* yylen */ + +#ifndef yydefred +#define yydefred calc_defred +#endif /* yydefred */ + +#ifndef yydgoto +#define yydgoto calc_dgoto +#endif /* yydgoto */ + +#ifndef yysindex +#define yysindex calc_sindex +#endif /* yysindex */ + +#ifndef yyrindex +#define yyrindex calc_rindex +#endif /* yyrindex */ + +#ifndef yygindex +#define yygindex calc_gindex +#endif /* yygindex */ + +#ifndef yytable +#define yytable calc_table +#endif /* yytable */ + +#ifndef yycheck +#define yycheck calc_check +#endif /* yycheck */ + +#ifndef yyname +#define yyname calc_name +#endif /* yyname */ + +#ifndef yyrule +#define yyrule calc_rule +#endif /* yyrule */ +#define YYPREFIX "calc_" + +extern int YYPARSE_DECL(); +extern short yylhs[]; +extern short yylen[]; +extern short yydefred[]; +extern short yydgoto[]; +extern short yysindex[]; +extern short yyrindex[]; +extern short yygindex[]; +extern short yytable[]; +extern short yycheck[]; + +#if YYDEBUG +extern char *yyname[]; +extern char *yyrule[]; +#endif + +int yydebug; +int yynerrs; + +int yyerrflag; +int yychar; +YYSTYPE yyval; +YYSTYPE yylval; + +/* define the initial stack-sizes */ +#ifdef YYSTACKSIZE +#undef YYMAXDEPTH +#define YYMAXDEPTH YYSTACKSIZE +#else +#ifdef YYMAXDEPTH +#define YYSTACKSIZE YYMAXDEPTH +#else +#define YYSTACKSIZE 500 +#define YYMAXDEPTH 500 +#endif +#endif + +#define YYINITSTACKSIZE 500 + +typedef struct { + unsigned stacksize; + short *s_base; + short *s_mark; + short *s_last; + YYSTYPE *l_base; + YYSTYPE *l_mark; +} YYSTACKDATA; +/* variables for the parser stack */ +static YYSTACKDATA yystack; +#line 68 "code_calc.y" + /* start of programs */ + +#ifdef YYBYACC +extern int YYLEX_DECL(); +#endif + +int +main (void) +{ + while(!feof(stdin)) { + yyparse(); + } + return 0; +} + +static void +yyerror(const char *s) +{ + fprintf(stderr, "%s\n", s); +} + +int +yylex(void) +{ + /* lexical analysis routine */ + /* returns LETTER for a lower case letter, yylval = 0 through 25 */ + /* return DIGIT for a digit, yylval = 0 through 9 */ + /* all other characters are returned immediately */ + + int c; + + while( (c=getchar()) == ' ' ) { /* skip blanks */ } + + /* c is now nonblank */ + + if( islower( c )) { + yylval = c - 'a'; + return ( LETTER ); + } + if( isdigit( c )) { + yylval = c - '0'; + return ( DIGIT ); + } + return( c ); +} +#line 254 "code_calc.code.c" + +#if YYDEBUG +#include <stdio.h> /* needed for printf */ +#endif + +#include <stdlib.h> /* needed for malloc, etc */ +#include <string.h> /* needed for memset */ + +/* allocate initial stack or double stack size, up to YYMAXDEPTH */ +static int yygrowstack(YYSTACKDATA *data) +{ + int i; + unsigned newsize; + short *newss; + YYSTYPE *newvs; + + if ((newsize = data->stacksize) == 0) + newsize = YYINITSTACKSIZE; + else if (newsize >= YYMAXDEPTH) + return -1; + else if ((newsize *= 2) > YYMAXDEPTH) + newsize = YYMAXDEPTH; + + i = data->s_mark - data->s_base; + newss = (short *)realloc(data->s_base, newsize * sizeof(*newss)); + if (newss == 0) + return -1; + + data->s_base = newss; + data->s_mark = newss + i; + + newvs = (YYSTYPE *)realloc(data->l_base, newsize * sizeof(*newvs)); + if (newvs == 0) + return -1; + + data->l_base = newvs; + data->l_mark = newvs + i; + + data->stacksize = newsize; + data->s_last = data->s_base + newsize - 1; + return 0; +} + +#if YYPURE || defined(YY_NO_LEAKS) +static void yyfreestack(YYSTACKDATA *data) +{ + free(data->s_base); + free(data->l_base); + memset(data, 0, sizeof(*data)); +} +#else +#define yyfreestack(data) /* nothing */ +#endif + +#define YYABORT goto yyabort +#define YYREJECT goto yyabort +#define YYACCEPT goto yyaccept +#define YYERROR goto yyerrlab + +int +YYPARSE_DECL() +{ + int yym, yyn, yystate; +#if YYDEBUG + const char *yys; + + if ((yys = getenv("YYDEBUG")) != 0) + { + yyn = *yys; + if (yyn >= '0' && yyn <= '9') + yydebug = yyn - '0'; + } +#endif + + yynerrs = 0; + yyerrflag = 0; + yychar = YYEMPTY; + yystate = 0; + +#if YYPURE + memset(&yystack, 0, sizeof(yystack)); +#endif + + if (yystack.s_base == NULL && yygrowstack(&yystack)) goto yyoverflow; + yystack.s_mark = yystack.s_base; + yystack.l_mark = yystack.l_base; + yystate = 0; + *yystack.s_mark = 0; + +yyloop: + if ((yyn = yydefred[yystate]) != 0) goto yyreduce; + if (yychar < 0) + { + if ((yychar = YYLEX) < 0) yychar = 0; +#if YYDEBUG + if (yydebug) + { + yys = 0; + if (yychar <= YYMAXTOKEN) yys = yyname[yychar]; + if (!yys) yys = "illegal-symbol"; + printf("%sdebug: state %d, reading %d (%s)\n", + YYPREFIX, yystate, yychar, yys); + } +#endif + } + if ((yyn = yysindex[yystate]) && (yyn += yychar) >= 0 && + yyn <= YYTABLESIZE && yycheck[yyn] == yychar) + { +#if YYDEBUG + if (yydebug) + printf("%sdebug: state %d, shifting to state %d\n", + YYPREFIX, yystate, yytable[yyn]); +#endif + if (yystack.s_mark >= yystack.s_last && yygrowstack(&yystack)) + { + goto yyoverflow; + } + yystate = yytable[yyn]; + *++yystack.s_mark = yytable[yyn]; + *++yystack.l_mark = yylval; + yychar = YYEMPTY; + if (yyerrflag > 0) --yyerrflag; + goto yyloop; + } + if ((yyn = yyrindex[yystate]) && (yyn += yychar) >= 0 && + yyn <= YYTABLESIZE && yycheck[yyn] == yychar) + { + yyn = yytable[yyn]; + goto yyreduce; + } + if (yyerrflag) goto yyinrecovery; + + yyerror("syntax error"); + + goto yyerrlab; + +yyerrlab: + ++yynerrs; + +yyinrecovery: + if (yyerrflag < 3) + { + yyerrflag = 3; + for (;;) + { + if ((yyn = yysindex[*yystack.s_mark]) && (yyn += YYERRCODE) >= 0 && + yyn <= YYTABLESIZE && yycheck[yyn] == YYERRCODE) + { +#if YYDEBUG + if (yydebug) + printf("%sdebug: state %d, error recovery shifting\ + to state %d\n", YYPREFIX, *yystack.s_mark, yytable[yyn]); +#endif + if (yystack.s_mark >= yystack.s_last && yygrowstack(&yystack)) + { + goto yyoverflow; + } + yystate = yytable[yyn]; + *++yystack.s_mark = yytable[yyn]; + *++yystack.l_mark = yylval; + goto yyloop; + } + else + { +#if YYDEBUG + if (yydebug) + printf("%sdebug: error recovery discarding state %d\n", + YYPREFIX, *yystack.s_mark); +#endif + if (yystack.s_mark <= yystack.s_base) goto yyabort; + --yystack.s_mark; + --yystack.l_mark; + } + } + } + else + { + if (yychar == 0) goto yyabort; +#if YYDEBUG + if (yydebug) + { + yys = 0; + if (yychar <= YYMAXTOKEN) yys = yyname[yychar]; + if (!yys) yys = "illegal-symbol"; + printf("%sdebug: state %d, error recovery discards token %d (%s)\n", + YYPREFIX, yystate, yychar, yys); + } +#endif + yychar = YYEMPTY; + goto yyloop; + } + +yyreduce: +#if YYDEBUG + if (yydebug) + printf("%sdebug: state %d, reducing by rule %d (%s)\n", + YYPREFIX, yystate, yyn, yyrule[yyn]); +#endif + yym = yylen[yyn]; + if (yym) + yyval = yystack.l_mark[1-yym]; + else + memset(&yyval, 0, sizeof yyval); + switch (yyn) + { +case 3: +#line 30 "code_calc.y" + { yyerrok ; } +break; +case 4: +#line 34 "code_calc.y" + { printf("%d\n",yystack.l_mark[0]);} +break; +case 5: +#line 36 "code_calc.y" + { regs[yystack.l_mark[-2]] = yystack.l_mark[0]; } +break; +case 6: +#line 40 "code_calc.y" + { yyval = yystack.l_mark[-1]; } +break; +case 7: +#line 42 "code_calc.y" + { yyval = yystack.l_mark[-2] + yystack.l_mark[0]; } +break; +case 8: +#line 44 "code_calc.y" + { yyval = yystack.l_mark[-2] - yystack.l_mark[0]; } +break; +case 9: +#line 46 "code_calc.y" + { yyval = yystack.l_mark[-2] * yystack.l_mark[0]; } +break; +case 10: +#line 48 "code_calc.y" + { yyval = yystack.l_mark[-2] / yystack.l_mark[0]; } +break; +case 11: +#line 50 "code_calc.y" + { yyval = yystack.l_mark[-2] % yystack.l_mark[0]; } +break; +case 12: +#line 52 "code_calc.y" + { yyval = yystack.l_mark[-2] & yystack.l_mark[0]; } +break; +case 13: +#line 54 "code_calc.y" + { yyval = yystack.l_mark[-2] | yystack.l_mark[0]; } +break; +case 14: +#line 56 "code_calc.y" + { yyval = - yystack.l_mark[0]; } +break; +case 15: +#line 58 "code_calc.y" + { yyval = regs[yystack.l_mark[0]]; } +break; +case 17: +#line 63 "code_calc.y" + { yyval = yystack.l_mark[0]; base = (yystack.l_mark[0]==0) ? 8 : 10; } +break; +case 18: +#line 65 "code_calc.y" + { yyval = base * yystack.l_mark[-1] + yystack.l_mark[0]; } +break; +#line 520 "code_calc.code.c" + } + yystack.s_mark -= yym; + yystate = *yystack.s_mark; + yystack.l_mark -= yym; + yym = yylhs[yyn]; + if (yystate == 0 && yym == 0) + { +#if YYDEBUG + if (yydebug) + printf("%sdebug: after reduction, shifting from state 0 to\ + state %d\n", YYPREFIX, YYFINAL); +#endif + yystate = YYFINAL; + *++yystack.s_mark = YYFINAL; + *++yystack.l_mark = yyval; + if (yychar < 0) + { + if ((yychar = YYLEX) < 0) yychar = 0; +#if YYDEBUG + if (yydebug) + { + yys = 0; + if (yychar <= YYMAXTOKEN) yys = yyname[yychar]; + if (!yys) yys = "illegal-symbol"; + printf("%sdebug: state %d, reading %d (%s)\n", + YYPREFIX, YYFINAL, yychar, yys); + } +#endif + } + if (yychar == 0) goto yyaccept; + goto yyloop; + } + if ((yyn = yygindex[yym]) && (yyn += yystate) >= 0 && + yyn <= YYTABLESIZE && yycheck[yyn] == yystate) + yystate = yytable[yyn]; + else + yystate = yydgoto[yym]; +#if YYDEBUG + if (yydebug) + printf("%sdebug: after reduction, shifting from state %d \ +to state %d\n", YYPREFIX, *yystack.s_mark, yystate); +#endif + if (yystack.s_mark >= yystack.s_last && yygrowstack(&yystack)) + { + goto yyoverflow; + } + *++yystack.s_mark = (short) yystate; + *++yystack.l_mark = yyval; + goto yyloop; + +yyoverflow: + yyerror("yacc stack overflow"); + +yyabort: + yyfreestack(&yystack); + return (1); + +yyaccept: + yyfreestack(&yystack); + return (0); +} diff --git a/test/code_calc.output b/test/code_calc.output new file mode 100644 index 000000000000..3aed47511c93 --- /dev/null +++ b/test/code_calc.output @@ -0,0 +1,461 @@ + 0 $accept : list $end + + 1 list : + 2 | list stat '\n' + 3 | list error '\n' + + 4 stat : expr + 5 | LETTER '=' expr + + 6 expr : '(' expr ')' + 7 | expr '+' expr + 8 | expr '-' expr + 9 | expr '*' expr + 10 | expr '/' expr + 11 | expr '%' expr + 12 | expr '&' expr + 13 | expr '|' expr + 14 | '-' expr + 15 | LETTER + 16 | number + + 17 number : DIGIT + 18 | number DIGIT + +state 0 + $accept : . list $end (0) + list : . (1) + + . reduce 1 + + list goto 1 + + +state 1 + $accept : list . $end (0) + list : list . stat '\n' (2) + list : list . error '\n' (3) + + $end accept + error shift 2 + DIGIT shift 3 + LETTER shift 4 + '-' shift 5 + '(' shift 6 + . error + + stat goto 7 + expr goto 8 + number goto 9 + + +state 2 + list : list error . '\n' (3) + + '\n' shift 10 + . error + + +state 3 + number : DIGIT . (17) + + . reduce 17 + + +state 4 + stat : LETTER . '=' expr (5) + expr : LETTER . (15) + + '=' shift 11 + '|' reduce 15 + '&' reduce 15 + '+' reduce 15 + '-' reduce 15 + '*' reduce 15 + '/' reduce 15 + '%' reduce 15 + '\n' reduce 15 + + +state 5 + expr : '-' . expr (14) + + DIGIT shift 3 + LETTER shift 12 + '-' shift 5 + '(' shift 6 + . error + + expr goto 13 + number goto 9 + + +state 6 + expr : '(' . expr ')' (6) + + DIGIT shift 3 + LETTER shift 12 + '-' shift 5 + '(' shift 6 + . error + + expr goto 14 + number goto 9 + + +state 7 + list : list stat . '\n' (2) + + '\n' shift 15 + . error + + +state 8 + stat : expr . (4) + expr : expr . '+' expr (7) + expr : expr . '-' expr (8) + expr : expr . '*' expr (9) + expr : expr . '/' expr (10) + expr : expr . '%' expr (11) + expr : expr . '&' expr (12) + expr : expr . '|' expr (13) + + '|' shift 16 + '&' shift 17 + '+' shift 18 + '-' shift 19 + '*' shift 20 + '/' shift 21 + '%' shift 22 + '\n' reduce 4 + + +state 9 + expr : number . (16) + number : number . DIGIT (18) + + DIGIT shift 23 + '|' reduce 16 + '&' reduce 16 + '+' reduce 16 + '-' reduce 16 + '*' reduce 16 + '/' reduce 16 + '%' reduce 16 + '\n' reduce 16 + ')' reduce 16 + + +state 10 + list : list error '\n' . (3) + + . reduce 3 + + +state 11 + stat : LETTER '=' . expr (5) + + DIGIT shift 3 + LETTER shift 12 + '-' shift 5 + '(' shift 6 + . error + + expr goto 24 + number goto 9 + + +state 12 + expr : LETTER . (15) + + . reduce 15 + + +state 13 + expr : expr . '+' expr (7) + expr : expr . '-' expr (8) + expr : expr . '*' expr (9) + expr : expr . '/' expr (10) + expr : expr . '%' expr (11) + expr : expr . '&' expr (12) + expr : expr . '|' expr (13) + expr : '-' expr . (14) + + . reduce 14 + + +state 14 + expr : '(' expr . ')' (6) + expr : expr . '+' expr (7) + expr : expr . '-' expr (8) + expr : expr . '*' expr (9) + expr : expr . '/' expr (10) + expr : expr . '%' expr (11) + expr : expr . '&' expr (12) + expr : expr . '|' expr (13) + + '|' shift 16 + '&' shift 17 + '+' shift 18 + '-' shift 19 + '*' shift 20 + '/' shift 21 + '%' shift 22 + ')' shift 25 + . error + + +state 15 + list : list stat '\n' . (2) + + . reduce 2 + + +state 16 + expr : expr '|' . expr (13) + + DIGIT shift 3 + LETTER shift 12 + '-' shift 5 + '(' shift 6 + . error + + expr goto 26 + number goto 9 + + +state 17 + expr : expr '&' . expr (12) + + DIGIT shift 3 + LETTER shift 12 + '-' shift 5 + '(' shift 6 + . error + + expr goto 27 + number goto 9 + + +state 18 + expr : expr '+' . expr (7) + + DIGIT shift 3 + LETTER shift 12 + '-' shift 5 + '(' shift 6 + . error + + expr goto 28 + number goto 9 + + +state 19 + expr : expr '-' . expr (8) + + DIGIT shift 3 + LETTER shift 12 + '-' shift 5 + '(' shift 6 + . error + + expr goto 29 + number goto 9 + + +state 20 + expr : expr '*' . expr (9) + + DIGIT shift 3 + LETTER shift 12 + '-' shift 5 + '(' shift 6 + . error + + expr goto 30 + number goto 9 + + +state 21 + expr : expr '/' . expr (10) + + DIGIT shift 3 + LETTER shift 12 + '-' shift 5 + '(' shift 6 + . error + + expr goto 31 + number goto 9 + + +state 22 + expr : expr '%' . expr (11) + + DIGIT shift 3 + LETTER shift 12 + '-' shift 5 + '(' shift 6 + . error + + expr goto 32 + number goto 9 + + +state 23 + number : number DIGIT . (18) + + . reduce 18 + + +state 24 + stat : LETTER '=' expr . (5) + expr : expr . '+' expr (7) + expr : expr . '-' expr (8) + expr : expr . '*' expr (9) + expr : expr . '/' expr (10) + expr : expr . '%' expr (11) + expr : expr . '&' expr (12) + expr : expr . '|' expr (13) + + '|' shift 16 + '&' shift 17 + '+' shift 18 + '-' shift 19 + '*' shift 20 + '/' shift 21 + '%' shift 22 + '\n' reduce 5 + + +state 25 + expr : '(' expr ')' . (6) + + . reduce 6 + + +state 26 + expr : expr . '+' expr (7) + expr : expr . '-' expr (8) + expr : expr . '*' expr (9) + expr : expr . '/' expr (10) + expr : expr . '%' expr (11) + expr : expr . '&' expr (12) + expr : expr . '|' expr (13) + expr : expr '|' expr . (13) + + '&' shift 17 + '+' shift 18 + '-' shift 19 + '*' shift 20 + '/' shift 21 + '%' shift 22 + '|' reduce 13 + '\n' reduce 13 + ')' reduce 13 + + +state 27 + expr : expr . '+' expr (7) + expr : expr . '-' expr (8) + expr : expr . '*' expr (9) + expr : expr . '/' expr (10) + expr : expr . '%' expr (11) + expr : expr . '&' expr (12) + expr : expr '&' expr . (12) + expr : expr . '|' expr (13) + + '+' shift 18 + '-' shift 19 + '*' shift 20 + '/' shift 21 + '%' shift 22 + '|' reduce 12 + '&' reduce 12 + '\n' reduce 12 + ')' reduce 12 + + +state 28 + expr : expr . '+' expr (7) + expr : expr '+' expr . (7) + expr : expr . '-' expr (8) + expr : expr . '*' expr (9) + expr : expr . '/' expr (10) + expr : expr . '%' expr (11) + expr : expr . '&' expr (12) + expr : expr . '|' expr (13) + + '*' shift 20 + '/' shift 21 + '%' shift 22 + '|' reduce 7 + '&' reduce 7 + '+' reduce 7 + '-' reduce 7 + '\n' reduce 7 + ')' reduce 7 + + +state 29 + expr : expr . '+' expr (7) + expr : expr . '-' expr (8) + expr : expr '-' expr . (8) + expr : expr . '*' expr (9) + expr : expr . '/' expr (10) + expr : expr . '%' expr (11) + expr : expr . '&' expr (12) + expr : expr . '|' expr (13) + + '*' shift 20 + '/' shift 21 + '%' shift 22 + '|' reduce 8 + '&' reduce 8 + '+' reduce 8 + '-' reduce 8 + '\n' reduce 8 + ')' reduce 8 + + +state 30 + expr : expr . '+' expr (7) + expr : expr . '-' expr (8) + expr : expr . '*' expr (9) + expr : expr '*' expr . (9) + expr : expr . '/' expr (10) + expr : expr . '%' expr (11) + expr : expr . '&' expr (12) + expr : expr . '|' expr (13) + + . reduce 9 + + +state 31 + expr : expr . '+' expr (7) + expr : expr . '-' expr (8) + expr : expr . '*' expr (9) + expr : expr . '/' expr (10) + expr : expr '/' expr . (10) + expr : expr . '%' expr (11) + expr : expr . '&' expr (12) + expr : expr . '|' expr (13) + + . reduce 10 + + +state 32 + expr : expr . '+' expr (7) + expr : expr . '-' expr (8) + expr : expr . '*' expr (9) + expr : expr . '/' expr (10) + expr : expr . '%' expr (11) + expr : expr '%' expr . (11) + expr : expr . '&' expr (12) + expr : expr . '|' expr (13) + + . reduce 11 + + +16 terminals, 5 nonterminals +19 grammar rules, 33 states diff --git a/test/code_calc.tab.c b/test/code_calc.tab.c new file mode 100644 index 000000000000..37a17ef4f814 --- /dev/null +++ b/test/code_calc.tab.c @@ -0,0 +1,199 @@ + +#ifndef yyparse +#define yyparse calc_parse +#endif /* yyparse */ + +#ifndef yylex +#define yylex calc_lex +#endif /* yylex */ + +#ifndef yyerror +#define yyerror calc_error +#endif /* yyerror */ + +#ifndef yychar +#define yychar calc_char +#endif /* yychar */ + +#ifndef yyval +#define yyval calc_val +#endif /* yyval */ + +#ifndef yylval +#define yylval calc_lval +#endif /* yylval */ + +#ifndef yydebug +#define yydebug calc_debug +#endif /* yydebug */ + +#ifndef yynerrs +#define yynerrs calc_nerrs +#endif /* yynerrs */ + +#ifndef yyerrflag +#define yyerrflag calc_errflag +#endif /* yyerrflag */ + +#ifndef yylhs +#define yylhs calc_lhs +#endif /* yylhs */ + +#ifndef yylen +#define yylen calc_len +#endif /* yylen */ + +#ifndef yydefred +#define yydefred calc_defred +#endif /* yydefred */ + +#ifndef yydgoto +#define yydgoto calc_dgoto +#endif /* yydgoto */ + +#ifndef yysindex +#define yysindex calc_sindex +#endif /* yysindex */ + +#ifndef yyrindex +#define yyrindex calc_rindex +#endif /* yyrindex */ + +#ifndef yygindex +#define yygindex calc_gindex +#endif /* yygindex */ + +#ifndef yytable +#define yytable calc_table +#endif /* yytable */ + +#ifndef yycheck +#define yycheck calc_check +#endif /* yycheck */ + +#ifndef yyname +#define yyname calc_name +#endif /* yyname */ + +#ifndef yyrule +#define yyrule calc_rule +#endif /* yyrule */ +#define YYPREFIX "calc_" +const short calc_lhs[] = { -1, + 0, 0, 0, 1, 1, 2, 2, 2, 2, 2, + 2, 2, 2, 2, 2, 2, 3, 3, +}; +const short calc_len[] = { 2, + 0, 3, 3, 1, 3, 3, 3, 3, 3, 3, + 3, 3, 3, 2, 1, 1, 1, 2, +}; +const short calc_defred[] = { 1, + 0, 0, 17, 0, 0, 0, 0, 0, 0, 3, + 0, 15, 14, 0, 2, 0, 0, 0, 0, 0, + 0, 0, 18, 0, 6, 0, 0, 0, 0, 9, + 10, 11, +}; +const short calc_dgoto[] = { 1, + 7, 8, 9, +}; +const short calc_sindex[] = { 0, + -40, -7, 0, -55, -38, -38, 1, -29, -247, 0, + -38, 0, 0, 22, 0, -38, -38, -38, -38, -38, + -38, -38, 0, -29, 0, 51, 60, -20, -20, 0, + 0, 0, +}; +const short calc_rindex[] = { 0, + 0, 0, 0, 2, 0, 0, 0, 9, -9, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 10, 0, -6, 14, 5, 13, 0, + 0, 0, +}; +const short calc_gindex[] = { 0, + 0, 65, 0, +}; +const short calc_table[] = { 6, + 16, 6, 10, 13, 5, 11, 5, 22, 17, 23, + 15, 15, 20, 18, 7, 19, 22, 21, 4, 5, + 0, 20, 8, 12, 0, 0, 21, 16, 16, 0, + 0, 16, 16, 16, 13, 16, 0, 16, 15, 15, + 0, 0, 7, 15, 15, 7, 15, 7, 15, 7, + 8, 12, 0, 8, 12, 8, 0, 8, 22, 17, + 0, 0, 25, 20, 18, 0, 19, 0, 21, 13, + 14, 0, 0, 0, 0, 24, 0, 0, 0, 0, + 26, 27, 28, 29, 30, 31, 32, 22, 17, 0, + 0, 0, 20, 18, 16, 19, 22, 21, 0, 0, + 0, 20, 18, 0, 19, 0, 21, 0, 0, 0, + 0, 0, 0, 0, 16, 0, 0, 13, 0, 0, + 0, 0, 0, 0, 0, 15, 0, 0, 7, 0, + 0, 0, 0, 0, 0, 0, 8, 12, 0, 0, + 0, 0, 0, 0, 0, 16, 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, 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, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 2, 3, 4, 3, 12, +}; +const short calc_check[] = { 40, + 10, 40, 10, 10, 45, 61, 45, 37, 38, 257, + 10, 10, 42, 43, 10, 45, 37, 47, 10, 10, + -1, 42, 10, 10, -1, -1, 47, 37, 38, -1, + -1, 41, 42, 43, 41, 45, -1, 47, 37, 38, + -1, -1, 38, 42, 43, 41, 45, 43, 47, 45, + 38, 38, -1, 41, 41, 43, -1, 45, 37, 38, + -1, -1, 41, 42, 43, -1, 45, -1, 47, 5, + 6, -1, -1, -1, -1, 11, -1, -1, -1, -1, + 16, 17, 18, 19, 20, 21, 22, 37, 38, -1, + -1, -1, 42, 43, 124, 45, 37, 47, -1, -1, + -1, 42, 43, -1, 45, -1, 47, -1, -1, -1, + -1, -1, -1, -1, 124, -1, -1, 124, -1, -1, + -1, -1, -1, -1, -1, 124, -1, -1, 124, -1, + -1, -1, -1, -1, -1, -1, 124, 124, -1, -1, + -1, -1, -1, -1, -1, 124, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, 256, 257, 258, 257, 258, +}; +#ifndef YYDEBUG +#define YYDEBUG 0 +#endif +#if YYDEBUG +const char *yyname[] = { + +"end-of-file",0,0,0,0,0,0,0,0,0,"'\\n'",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,"'-'",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,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,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,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,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,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,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,0,0,0,0,0,0, +0,0,0,0,0,0,"DIGIT","LETTER","UMINUS", +}; +const char *yyrule[] = { +"$accept : list", +"list :", +"list : list stat '\\n'", +"list : list error '\\n'", +"stat : expr", +"stat : LETTER '=' expr", +"expr : '(' expr ')'", +"expr : expr '+' expr", +"expr : expr '-' expr", +"expr : expr '*' expr", +"expr : expr '/' expr", +"expr : expr '%' expr", +"expr : expr '&' expr", +"expr : expr '|' expr", +"expr : '-' expr", +"expr : LETTER", +"expr : number", +"number : DIGIT", +"number : number DIGIT", + +}; +#endif diff --git a/test/code_calc.tab.h b/test/code_calc.tab.h new file mode 100644 index 000000000000..19211182d6b3 --- /dev/null +++ b/test/code_calc.tab.h @@ -0,0 +1,3 @@ +#define DIGIT 257 +#define LETTER 258 +#define UMINUS 259 diff --git a/test/code_calc.y b/test/code_calc.y new file mode 100644 index 000000000000..0a99456e7f89 --- /dev/null +++ b/test/code_calc.y @@ -0,0 +1,112 @@ +%{ +# include <stdio.h> +# include <ctype.h> + +int regs[26]; +int base; + +#ifdef YYBISON +int yylex(void); +static void yyerror(const char *s); +#endif + +%} + +%start list + +%token DIGIT LETTER + +%left '|' +%left '&' +%left '+' '-' +%left '*' '/' '%' +%left UMINUS /* supplies precedence for unary minus */ + +%% /* beginning of rules section */ + +list : /* empty */ + | list stat '\n' + | list error '\n' + { yyerrok ; } + ; + +stat : expr + { printf("%d\n",$1);} + | LETTER '=' expr + { regs[$1] = $3; } + ; + +expr : '(' expr ')' + { $$ = $2; } + | expr '+' expr + { $$ = $1 + $3; } + | expr '-' expr + { $$ = $1 - $3; } + | expr '*' expr + { $$ = $1 * $3; } + | expr '/' expr + { $$ = $1 / $3; } + | expr '%' expr + { $$ = $1 % $3; } + | expr '&' expr + { $$ = $1 & $3; } + | expr '|' expr + { $$ = $1 | $3; } + | '-' expr %prec UMINUS + { $$ = - $2; } + | LETTER + { $$ = regs[$1]; } + | number + ; + +number: DIGIT + { $$ = $1; base = ($1==0) ? 8 : 10; } + | number DIGIT + { $$ = base * $1 + $2; } + ; + +%% /* start of programs */ + +#ifdef YYBYACC +extern int YYLEX_DECL(); +#endif + +int +main (void) +{ + while(!feof(stdin)) { + yyparse(); + } + return 0; +} + +static void +yyerror(const char *s) +{ + fprintf(stderr, "%s\n", s); +} + +int +yylex(void) +{ + /* lexical analysis routine */ + /* returns LETTER for a lower case letter, yylval = 0 through 25 */ + /* return DIGIT for a digit, yylval = 0 through 9 */ + /* all other characters are returned immediately */ + + int c; + + while( (c=getchar()) == ' ' ) { /* skip blanks */ } + + /* c is now nonblank */ + + if( islower( c )) { + yylval = c - 'a'; + return ( LETTER ); + } + if( isdigit( c )) { + yylval = c - '0'; + return ( DIGIT ); + } + return( c ); +} diff --git a/test/code_error.code.c b/test/code_error.code.c new file mode 100644 index 000000000000..db50bbcf60d0 --- /dev/null +++ b/test/code_error.code.c @@ -0,0 +1,491 @@ +#ifndef lint +static const char yysccsid[] = "@(#)yaccpar 1.9 (Berkeley) 02/21/93"; +#endif + +#define YYBYACC 1 +#define YYMAJOR 1 +#define YYMINOR 9 + +#define YYEMPTY (-1) +#define yyclearin (yychar = YYEMPTY) +#define yyerrok (yyerrflag = 0) +#define YYRECOVERING() (yyerrflag != 0) + + +#define YYPURE 0 + +#line 2 "code_error.y" + +#ifdef YYBISON +int yylex(void); +static void yyerror(const char *); +#endif + +#line 25 "code_error.code.c" + +#ifndef YYSTYPE +typedef int YYSTYPE; +#endif + +/* compatibility with bison */ +#ifdef YYPARSE_PARAM +/* compatibility with FreeBSD */ +# ifdef YYPARSE_PARAM_TYPE +# define YYPARSE_DECL() yyparse(YYPARSE_PARAM_TYPE YYPARSE_PARAM) +# else +# define YYPARSE_DECL() yyparse(void *YYPARSE_PARAM) +# endif +#else +# define YYPARSE_DECL() yyparse(void) +#endif + +/* Parameters sent to lex. */ +#ifdef YYLEX_PARAM +# define YYLEX_DECL() yylex(void *YYLEX_PARAM) +# define YYLEX yylex(YYLEX_PARAM) +#else +# define YYLEX_DECL() yylex(void) +# define YYLEX yylex() +#endif + +/* Parameters sent to yyerror. */ +#ifndef YYERROR_DECL +#define YYERROR_DECL() yyerror(const char *s) +#endif +#ifndef YYERROR_CALL +#define YYERROR_CALL(msg) yyerror(msg) +#endif + +extern int YYPARSE_DECL(); + +#define YYERRCODE 256 +#define YYTABLESIZE 0 +#define YYFINAL 2 +#ifndef YYDEBUG +#define YYDEBUG 0 +#endif +#define YYMAXTOKEN 0 + +#ifndef yyparse +#define yyparse error_parse +#endif /* yyparse */ + +#ifndef yylex +#define yylex error_lex +#endif /* yylex */ + +#ifndef yyerror +#define yyerror error_error +#endif /* yyerror */ + +#ifndef yychar +#define yychar error_char +#endif /* yychar */ + +#ifndef yyval +#define yyval error_val +#endif /* yyval */ + +#ifndef yylval +#define yylval error_lval +#endif /* yylval */ + +#ifndef yydebug +#define yydebug error_debug +#endif /* yydebug */ + +#ifndef yynerrs +#define yynerrs error_nerrs +#endif /* yynerrs */ + +#ifndef yyerrflag +#define yyerrflag error_errflag +#endif /* yyerrflag */ + +#ifndef yylhs +#define yylhs error_lhs +#endif /* yylhs */ + +#ifndef yylen +#define yylen error_len +#endif /* yylen */ + +#ifndef yydefred +#define yydefred error_defred +#endif /* yydefred */ + +#ifndef yydgoto +#define yydgoto error_dgoto +#endif /* yydgoto */ + +#ifndef yysindex +#define yysindex error_sindex +#endif /* yysindex */ + +#ifndef yyrindex +#define yyrindex error_rindex +#endif /* yyrindex */ + +#ifndef yygindex +#define yygindex error_gindex +#endif /* yygindex */ + +#ifndef yytable +#define yytable error_table +#endif /* yytable */ + +#ifndef yycheck +#define yycheck error_check +#endif /* yycheck */ + +#ifndef yyname +#define yyname error_name +#endif /* yyname */ + +#ifndef yyrule +#define yyrule error_rule +#endif /* yyrule */ +#define YYPREFIX "error_" + +extern int YYPARSE_DECL(); +extern short yylhs[]; +extern short yylen[]; +extern short yydefred[]; +extern short yydgoto[]; +extern short yysindex[]; +extern short yyrindex[]; +extern short yygindex[]; +extern short yytable[]; +extern short yycheck[]; + +#if YYDEBUG +extern char *yyname[]; +extern char *yyrule[]; +#endif + +int yydebug; +int yynerrs; + +int yyerrflag; +int yychar; +YYSTYPE yyval; +YYSTYPE yylval; + +/* define the initial stack-sizes */ +#ifdef YYSTACKSIZE +#undef YYMAXDEPTH +#define YYMAXDEPTH YYSTACKSIZE +#else +#ifdef YYMAXDEPTH +#define YYSTACKSIZE YYMAXDEPTH +#else +#define YYSTACKSIZE 500 +#define YYMAXDEPTH 500 +#endif +#endif + +#define YYINITSTACKSIZE 500 + +typedef struct { + unsigned stacksize; + short *s_base; + short *s_mark; + short *s_last; + YYSTYPE *l_base; + YYSTYPE *l_mark; +} YYSTACKDATA; +/* variables for the parser stack */ +static YYSTACKDATA yystack; +#line 12 "code_error.y" + +#include <stdio.h> + +#ifdef YYBYACC +extern int YYLEX_DECL(); +#endif + +int +main(void) +{ + printf("yyparse() = %d\n", yyparse()); + return 0; +} + +int +yylex(void) +{ + return -1; +} + +static void +yyerror(const char* s) +{ + printf("%s\n", s); +} +#line 226 "code_error.code.c" + +#if YYDEBUG +#include <stdio.h> /* needed for printf */ +#endif + +#include <stdlib.h> /* needed for malloc, etc */ +#include <string.h> /* needed for memset */ + +/* allocate initial stack or double stack size, up to YYMAXDEPTH */ +static int yygrowstack(YYSTACKDATA *data) +{ + int i; + unsigned newsize; + short *newss; + YYSTYPE *newvs; + + if ((newsize = data->stacksize) == 0) + newsize = YYINITSTACKSIZE; + else if (newsize >= YYMAXDEPTH) + return -1; + else if ((newsize *= 2) > YYMAXDEPTH) + newsize = YYMAXDEPTH; + + i = data->s_mark - data->s_base; + newss = (short *)realloc(data->s_base, newsize * sizeof(*newss)); + if (newss == 0) + return -1; + + data->s_base = newss; + data->s_mark = newss + i; + + newvs = (YYSTYPE *)realloc(data->l_base, newsize * sizeof(*newvs)); + if (newvs == 0) + return -1; + + data->l_base = newvs; + data->l_mark = newvs + i; + + data->stacksize = newsize; + data->s_last = data->s_base + newsize - 1; + return 0; +} + +#if YYPURE || defined(YY_NO_LEAKS) +static void yyfreestack(YYSTACKDATA *data) +{ + free(data->s_base); + free(data->l_base); + memset(data, 0, sizeof(*data)); +} +#else +#define yyfreestack(data) /* nothing */ +#endif + +#define YYABORT goto yyabort +#define YYREJECT goto yyabort +#define YYACCEPT goto yyaccept +#define YYERROR goto yyerrlab + +int +YYPARSE_DECL() +{ + int yym, yyn, yystate; +#if YYDEBUG + const char *yys; + + if ((yys = getenv("YYDEBUG")) != 0) + { + yyn = *yys; + if (yyn >= '0' && yyn <= '9') + yydebug = yyn - '0'; + } +#endif + + yynerrs = 0; + yyerrflag = 0; + yychar = YYEMPTY; + yystate = 0; + +#if YYPURE + memset(&yystack, 0, sizeof(yystack)); +#endif + + if (yystack.s_base == NULL && yygrowstack(&yystack)) goto yyoverflow; + yystack.s_mark = yystack.s_base; + yystack.l_mark = yystack.l_base; + yystate = 0; + *yystack.s_mark = 0; + +yyloop: + if ((yyn = yydefred[yystate]) != 0) goto yyreduce; + if (yychar < 0) + { + if ((yychar = YYLEX) < 0) yychar = 0; +#if YYDEBUG + if (yydebug) + { + yys = 0; + if (yychar <= YYMAXTOKEN) yys = yyname[yychar]; + if (!yys) yys = "illegal-symbol"; + printf("%sdebug: state %d, reading %d (%s)\n", + YYPREFIX, yystate, yychar, yys); + } +#endif + } + if ((yyn = yysindex[yystate]) && (yyn += yychar) >= 0 && + yyn <= YYTABLESIZE && yycheck[yyn] == yychar) + { +#if YYDEBUG + if (yydebug) + printf("%sdebug: state %d, shifting to state %d\n", + YYPREFIX, yystate, yytable[yyn]); +#endif + if (yystack.s_mark >= yystack.s_last && yygrowstack(&yystack)) + { + goto yyoverflow; + } + yystate = yytable[yyn]; + *++yystack.s_mark = yytable[yyn]; + *++yystack.l_mark = yylval; + yychar = YYEMPTY; + if (yyerrflag > 0) --yyerrflag; + goto yyloop; + } + if ((yyn = yyrindex[yystate]) && (yyn += yychar) >= 0 && + yyn <= YYTABLESIZE && yycheck[yyn] == yychar) + { + yyn = yytable[yyn]; + goto yyreduce; + } + if (yyerrflag) goto yyinrecovery; + + yyerror("syntax error"); + + goto yyerrlab; + +yyerrlab: + ++yynerrs; + +yyinrecovery: + if (yyerrflag < 3) + { + yyerrflag = 3; + for (;;) + { + if ((yyn = yysindex[*yystack.s_mark]) && (yyn += YYERRCODE) >= 0 && + yyn <= YYTABLESIZE && yycheck[yyn] == YYERRCODE) + { +#if YYDEBUG + if (yydebug) + printf("%sdebug: state %d, error recovery shifting\ + to state %d\n", YYPREFIX, *yystack.s_mark, yytable[yyn]); +#endif + if (yystack.s_mark >= yystack.s_last && yygrowstack(&yystack)) + { + goto yyoverflow; + } + yystate = yytable[yyn]; + *++yystack.s_mark = yytable[yyn]; + *++yystack.l_mark = yylval; + goto yyloop; + } + else + { +#if YYDEBUG + if (yydebug) + printf("%sdebug: error recovery discarding state %d\n", + YYPREFIX, *yystack.s_mark); +#endif + if (yystack.s_mark <= yystack.s_base) goto yyabort; + --yystack.s_mark; + --yystack.l_mark; + } + } + } + else + { + if (yychar == 0) goto yyabort; +#if YYDEBUG + if (yydebug) + { + yys = 0; + if (yychar <= YYMAXTOKEN) yys = yyname[yychar]; + if (!yys) yys = "illegal-symbol"; + printf("%sdebug: state %d, error recovery discards token %d (%s)\n", + YYPREFIX, yystate, yychar, yys); + } +#endif + yychar = YYEMPTY; + goto yyloop; + } + +yyreduce: +#if YYDEBUG + if (yydebug) + printf("%sdebug: state %d, reducing by rule %d (%s)\n", + YYPREFIX, yystate, yyn, yyrule[yyn]); +#endif + yym = yylen[yyn]; + if (yym) + yyval = yystack.l_mark[1-yym]; + else + memset(&yyval, 0, sizeof yyval); + switch (yyn) + { + } + yystack.s_mark -= yym; + yystate = *yystack.s_mark; + yystack.l_mark -= yym; + yym = yylhs[yyn]; + if (yystate == 0 && yym == 0) + { +#if YYDEBUG + if (yydebug) + printf("%sdebug: after reduction, shifting from state 0 to\ + state %d\n", YYPREFIX, YYFINAL); +#endif + yystate = YYFINAL; + *++yystack.s_mark = YYFINAL; + *++yystack.l_mark = yyval; + if (yychar < 0) + { + if ((yychar = YYLEX) < 0) yychar = 0; +#if YYDEBUG + if (yydebug) + { + yys = 0; + if (yychar <= YYMAXTOKEN) yys = yyname[yychar]; + if (!yys) yys = "illegal-symbol"; + printf("%sdebug: state %d, reading %d (%s)\n", + YYPREFIX, YYFINAL, yychar, yys); + } +#endif + } + if (yychar == 0) goto yyaccept; + goto yyloop; + } + if ((yyn = yygindex[yym]) && (yyn += yystate) >= 0 && + yyn <= YYTABLESIZE && yycheck[yyn] == yystate) + yystate = yytable[yyn]; + else + yystate = yydgoto[yym]; +#if YYDEBUG + if (yydebug) + printf("%sdebug: after reduction, shifting from state %d \ +to state %d\n", YYPREFIX, *yystack.s_mark, yystate); +#endif + if (yystack.s_mark >= yystack.s_last && yygrowstack(&yystack)) + { + goto yyoverflow; + } + *++yystack.s_mark = (short) yystate; + *++yystack.l_mark = yyval; + goto yyloop; + +yyoverflow: + yyerror("yacc stack overflow"); + +yyabort: + yyfreestack(&yystack); + return (1); + +yyaccept: + yyfreestack(&yystack); + return (0); +} diff --git a/test/code_error.output b/test/code_error.output new file mode 100644 index 000000000000..0c4db6225e24 --- /dev/null +++ b/test/code_error.output @@ -0,0 +1,27 @@ + 0 $accept : S $end + + 1 S : error + +state 0 + $accept : . S $end (0) + + error shift 1 + . error + + S goto 2 + + +state 1 + S : error . (1) + + . reduce 1 + + +state 2 + $accept : S . $end (0) + + $end accept + + +2 terminals, 2 nonterminals +2 grammar rules, 3 states diff --git a/test/code_error.tab.c b/test/code_error.tab.c new file mode 100644 index 000000000000..eb4db127835f --- /dev/null +++ b/test/code_error.tab.c @@ -0,0 +1,118 @@ + +#ifndef yyparse +#define yyparse error_parse +#endif /* yyparse */ + +#ifndef yylex +#define yylex error_lex +#endif /* yylex */ + +#ifndef yyerror +#define yyerror error_error +#endif /* yyerror */ + +#ifndef yychar +#define yychar error_char +#endif /* yychar */ + +#ifndef yyval +#define yyval error_val +#endif /* yyval */ + +#ifndef yylval +#define yylval error_lval +#endif /* yylval */ + +#ifndef yydebug +#define yydebug error_debug +#endif /* yydebug */ + +#ifndef yynerrs +#define yynerrs error_nerrs +#endif /* yynerrs */ + +#ifndef yyerrflag +#define yyerrflag error_errflag +#endif /* yyerrflag */ + +#ifndef yylhs +#define yylhs error_lhs +#endif /* yylhs */ + +#ifndef yylen +#define yylen error_len +#endif /* yylen */ + +#ifndef yydefred +#define yydefred error_defred +#endif /* yydefred */ + +#ifndef yydgoto +#define yydgoto error_dgoto +#endif /* yydgoto */ + +#ifndef yysindex +#define yysindex error_sindex +#endif /* yysindex */ + +#ifndef yyrindex +#define yyrindex error_rindex +#endif /* yyrindex */ + +#ifndef yygindex +#define yygindex error_gindex +#endif /* yygindex */ + +#ifndef yytable +#define yytable error_table +#endif /* yytable */ + +#ifndef yycheck +#define yycheck error_check +#endif /* yycheck */ + +#ifndef yyname +#define yyname error_name +#endif /* yyname */ + +#ifndef yyrule +#define yyrule error_rule +#endif /* yyrule */ +#define YYPREFIX "error_" +const short error_lhs[] = { -1, + 0, +}; +const short error_len[] = { 2, + 1, +}; +const short error_defred[] = { 0, + 1, 0, +}; +const short error_dgoto[] = { 2, +}; +const short error_sindex[] = { -256, + 0, 0, +}; +const short error_rindex[] = { 0, + 0, 0, +}; +const short error_gindex[] = { 0, +}; +const short error_table[] = { 1, +}; +const short error_check[] = { 256, +}; +#ifndef YYDEBUG +#define YYDEBUG 0 +#endif +#if YYDEBUG +const char *yyname[] = { + +"end-of-file", +}; +const char *yyrule[] = { +"$accept : S", +"S : error", + +}; +#endif diff --git a/test/code_error.tab.h b/test/code_error.tab.h new file mode 100644 index 000000000000..e69de29bb2d1 --- /dev/null +++ b/test/code_error.tab.h diff --git a/test/code_error.y b/test/code_error.y new file mode 100644 index 000000000000..bb771567606a --- /dev/null +++ b/test/code_error.y @@ -0,0 +1,36 @@ +%{ + +#ifdef YYBISON +int yylex(void); +static void yyerror(const char *); +#endif + +%} +%% +S: error +%% + +#include <stdio.h> + +#ifdef YYBYACC +extern int YYLEX_DECL(); +#endif + +int +main(void) +{ + printf("yyparse() = %d\n", yyparse()); + return 0; +} + +int +yylex(void) +{ + return -1; +} + +static void +yyerror(const char* s) +{ + printf("%s\n", s); +} diff --git a/test/error.output b/test/error.output new file mode 100644 index 000000000000..0c4db6225e24 --- /dev/null +++ b/test/error.output @@ -0,0 +1,27 @@ + 0 $accept : S $end + + 1 S : error + +state 0 + $accept : . S $end (0) + + error shift 1 + . error + + S goto 2 + + +state 1 + S : error . (1) + + . reduce 1 + + +state 2 + $accept : S . $end (0) + + $end accept + + +2 terminals, 2 nonterminals +2 grammar rules, 3 states diff --git a/test/error.tab.c b/test/error.tab.c new file mode 100644 index 000000000000..91136291aea6 --- /dev/null +++ b/test/error.tab.c @@ -0,0 +1,501 @@ +#ifndef lint +static const char yysccsid[] = "@(#)yaccpar 1.9 (Berkeley) 02/21/93"; +#endif + +#define YYBYACC 1 +#define YYMAJOR 1 +#define YYMINOR 9 + +#define YYEMPTY (-1) +#define yyclearin (yychar = YYEMPTY) +#define yyerrok (yyerrflag = 0) +#define YYRECOVERING() (yyerrflag != 0) + + +#ifndef yyparse +#define yyparse error_parse +#endif /* yyparse */ + +#ifndef yylex +#define yylex error_lex +#endif /* yylex */ + +#ifndef yyerror +#define yyerror error_error +#endif /* yyerror */ + +#ifndef yychar +#define yychar error_char +#endif /* yychar */ + +#ifndef yyval +#define yyval error_val +#endif /* yyval */ + +#ifndef yylval +#define yylval error_lval +#endif /* yylval */ + +#ifndef yydebug +#define yydebug error_debug +#endif /* yydebug */ + +#ifndef yynerrs +#define yynerrs error_nerrs +#endif /* yynerrs */ + +#ifndef yyerrflag +#define yyerrflag error_errflag +#endif /* yyerrflag */ + +#ifndef yylhs +#define yylhs error_lhs +#endif /* yylhs */ + +#ifndef yylen +#define yylen error_len +#endif /* yylen */ + +#ifndef yydefred +#define yydefred error_defred +#endif /* yydefred */ + +#ifndef yydgoto +#define yydgoto error_dgoto +#endif /* yydgoto */ + +#ifndef yysindex +#define yysindex error_sindex +#endif /* yysindex */ + +#ifndef yyrindex +#define yyrindex error_rindex +#endif /* yyrindex */ + +#ifndef yygindex +#define yygindex error_gindex +#endif /* yygindex */ + +#ifndef yytable +#define yytable error_table +#endif /* yytable */ + +#ifndef yycheck +#define yycheck error_check +#endif /* yycheck */ + +#ifndef yyname +#define yyname error_name +#endif /* yyname */ + +#ifndef yyrule +#define yyrule error_rule +#endif /* yyrule */ +#define YYPREFIX "error_" + +#define YYPURE 0 + +#line 2 "error.y" +int yylex(void); +static void yyerror(const char *); +#line 102 "error.tab.c" + +#ifndef YYSTYPE +typedef int YYSTYPE; +#endif + +/* compatibility with bison */ +#ifdef YYPARSE_PARAM +/* compatibility with FreeBSD */ +# ifdef YYPARSE_PARAM_TYPE +# define YYPARSE_DECL() yyparse(YYPARSE_PARAM_TYPE YYPARSE_PARAM) +# else +# define YYPARSE_DECL() yyparse(void *YYPARSE_PARAM) +# endif +#else +# define YYPARSE_DECL() yyparse(void) +#endif + +/* Parameters sent to lex. */ +#ifdef YYLEX_PARAM +# define YYLEX_DECL() yylex(void *YYLEX_PARAM) +# define YYLEX yylex(YYLEX_PARAM) +#else +# define YYLEX_DECL() yylex(void) +# define YYLEX yylex() +#endif + +/* Parameters sent to yyerror. */ +#ifndef YYERROR_DECL +#define YYERROR_DECL() yyerror(const char *s) +#endif +#ifndef YYERROR_CALL +#define YYERROR_CALL(msg) yyerror(msg) +#endif + +extern int YYPARSE_DECL(); + +#define YYERRCODE 256 +static const short error_lhs[] = { -1, + 0, +}; +static const short error_len[] = { 2, + 1, +}; +static const short error_defred[] = { 0, + 1, 0, +}; +static const short error_dgoto[] = { 2, +}; +static const short error_sindex[] = { -256, + 0, 0, +}; +static const short error_rindex[] = { 0, + 0, 0, +}; +static const short error_gindex[] = { 0, +}; +#define YYTABLESIZE 0 +static const short error_table[] = { 1, +}; +static const short error_check[] = { 256, +}; +#define YYFINAL 2 +#ifndef YYDEBUG +#define YYDEBUG 0 +#endif +#define YYMAXTOKEN 0 +#if YYDEBUG +static const char *yyname[] = { + +"end-of-file", +}; +static const char *yyrule[] = { +"$accept : S", +"S : error", + +}; +#endif + +int yydebug; +int yynerrs; + +int yyerrflag; +int yychar; +YYSTYPE yyval; +YYSTYPE yylval; + +/* define the initial stack-sizes */ +#ifdef YYSTACKSIZE +#undef YYMAXDEPTH +#define YYMAXDEPTH YYSTACKSIZE +#else +#ifdef YYMAXDEPTH +#define YYSTACKSIZE YYMAXDEPTH +#else +#define YYSTACKSIZE 500 +#define YYMAXDEPTH 500 +#endif +#endif + +#define YYINITSTACKSIZE 500 + +typedef struct { + unsigned stacksize; + short *s_base; + short *s_mark; + short *s_last; + YYSTYPE *l_base; + YYSTYPE *l_mark; +} YYSTACKDATA; +/* variables for the parser stack */ +static YYSTACKDATA yystack; +#line 8 "error.y" + +#include <stdio.h> + +int +main(void) +{ + printf("yyparse() = %d\n", yyparse()); + return 0; +} + +int +yylex(void) +{ + return -1; +} + +static void +yyerror(const char* s) +{ + printf("%s\n", s); +} +#line 236 "error.tab.c" + +#if YYDEBUG +#include <stdio.h> /* needed for printf */ +#endif + +#include <stdlib.h> /* needed for malloc, etc */ +#include <string.h> /* needed for memset */ + +/* allocate initial stack or double stack size, up to YYMAXDEPTH */ +static int yygrowstack(YYSTACKDATA *data) +{ + int i; + unsigned newsize; + short *newss; + YYSTYPE *newvs; + + if ((newsize = data->stacksize) == 0) + newsize = YYINITSTACKSIZE; + else if (newsize >= YYMAXDEPTH) + return -1; + else if ((newsize *= 2) > YYMAXDEPTH) + newsize = YYMAXDEPTH; + + i = data->s_mark - data->s_base; + newss = (short *)realloc(data->s_base, newsize * sizeof(*newss)); + if (newss == 0) + return -1; + + data->s_base = newss; + data->s_mark = newss + i; + + newvs = (YYSTYPE *)realloc(data->l_base, newsize * sizeof(*newvs)); + if (newvs == 0) + return -1; + + data->l_base = newvs; + data->l_mark = newvs + i; + + data->stacksize = newsize; + data->s_last = data->s_base + newsize - 1; + return 0; +} + +#if YYPURE || defined(YY_NO_LEAKS) +static void yyfreestack(YYSTACKDATA *data) +{ + free(data->s_base); + free(data->l_base); + memset(data, 0, sizeof(*data)); +} +#else +#define yyfreestack(data) /* nothing */ +#endif + +#define YYABORT goto yyabort +#define YYREJECT goto yyabort +#define YYACCEPT goto yyaccept +#define YYERROR goto yyerrlab + +int +YYPARSE_DECL() +{ + int yym, yyn, yystate; +#if YYDEBUG + const char *yys; + + if ((yys = getenv("YYDEBUG")) != 0) + { + yyn = *yys; + if (yyn >= '0' && yyn <= '9') + yydebug = yyn - '0'; + } +#endif + + yynerrs = 0; + yyerrflag = 0; + yychar = YYEMPTY; + yystate = 0; + +#if YYPURE + memset(&yystack, 0, sizeof(yystack)); +#endif + + if (yystack.s_base == NULL && yygrowstack(&yystack)) goto yyoverflow; + yystack.s_mark = yystack.s_base; + yystack.l_mark = yystack.l_base; + yystate = 0; + *yystack.s_mark = 0; + +yyloop: + if ((yyn = yydefred[yystate]) != 0) goto yyreduce; + if (yychar < 0) + { + if ((yychar = YYLEX) < 0) yychar = 0; +#if YYDEBUG + if (yydebug) + { + yys = 0; + if (yychar <= YYMAXTOKEN) yys = yyname[yychar]; + if (!yys) yys = "illegal-symbol"; + printf("%sdebug: state %d, reading %d (%s)\n", + YYPREFIX, yystate, yychar, yys); + } +#endif + } + if ((yyn = yysindex[yystate]) && (yyn += yychar) >= 0 && + yyn <= YYTABLESIZE && yycheck[yyn] == yychar) + { +#if YYDEBUG + if (yydebug) + printf("%sdebug: state %d, shifting to state %d\n", + YYPREFIX, yystate, yytable[yyn]); +#endif + if (yystack.s_mark >= yystack.s_last && yygrowstack(&yystack)) + { + goto yyoverflow; + } + yystate = yytable[yyn]; + *++yystack.s_mark = yytable[yyn]; + *++yystack.l_mark = yylval; + yychar = YYEMPTY; + if (yyerrflag > 0) --yyerrflag; + goto yyloop; + } + if ((yyn = yyrindex[yystate]) && (yyn += yychar) >= 0 && + yyn <= YYTABLESIZE && yycheck[yyn] == yychar) + { + yyn = yytable[yyn]; + goto yyreduce; + } + if (yyerrflag) goto yyinrecovery; + + yyerror("syntax error"); + + goto yyerrlab; + +yyerrlab: + ++yynerrs; + +yyinrecovery: + if (yyerrflag < 3) + { + yyerrflag = 3; + for (;;) + { + if ((yyn = yysindex[*yystack.s_mark]) && (yyn += YYERRCODE) >= 0 && + yyn <= YYTABLESIZE && yycheck[yyn] == YYERRCODE) + { +#if YYDEBUG + if (yydebug) + printf("%sdebug: state %d, error recovery shifting\ + to state %d\n", YYPREFIX, *yystack.s_mark, yytable[yyn]); +#endif + if (yystack.s_mark >= yystack.s_last && yygrowstack(&yystack)) + { + goto yyoverflow; + } + yystate = yytable[yyn]; + *++yystack.s_mark = yytable[yyn]; + *++yystack.l_mark = yylval; + goto yyloop; + } + else + { +#if YYDEBUG + if (yydebug) + printf("%sdebug: error recovery discarding state %d\n", + YYPREFIX, *yystack.s_mark); +#endif + if (yystack.s_mark <= yystack.s_base) goto yyabort; + --yystack.s_mark; + --yystack.l_mark; + } + } + } + else + { + if (yychar == 0) goto yyabort; +#if YYDEBUG + if (yydebug) + { + yys = 0; + if (yychar <= YYMAXTOKEN) yys = yyname[yychar]; + if (!yys) yys = "illegal-symbol"; + printf("%sdebug: state %d, error recovery discards token %d (%s)\n", + YYPREFIX, yystate, yychar, yys); + } +#endif + yychar = YYEMPTY; + goto yyloop; + } + +yyreduce: +#if YYDEBUG + if (yydebug) + printf("%sdebug: state %d, reducing by rule %d (%s)\n", + YYPREFIX, yystate, yyn, yyrule[yyn]); +#endif + yym = yylen[yyn]; + if (yym) + yyval = yystack.l_mark[1-yym]; + else + memset(&yyval, 0, sizeof yyval); + switch (yyn) + { + } + yystack.s_mark -= yym; + yystate = *yystack.s_mark; + yystack.l_mark -= yym; + yym = yylhs[yyn]; + if (yystate == 0 && yym == 0) + { +#if YYDEBUG + if (yydebug) + printf("%sdebug: after reduction, shifting from state 0 to\ + state %d\n", YYPREFIX, YYFINAL); +#endif + yystate = YYFINAL; + *++yystack.s_mark = YYFINAL; + *++yystack.l_mark = yyval; + if (yychar < 0) + { + if ((yychar = YYLEX) < 0) yychar = 0; +#if YYDEBUG + if (yydebug) + { + yys = 0; + if (yychar <= YYMAXTOKEN) yys = yyname[yychar]; + if (!yys) yys = "illegal-symbol"; + printf("%sdebug: state %d, reading %d (%s)\n", + YYPREFIX, YYFINAL, yychar, yys); + } +#endif + } + if (yychar == 0) goto yyaccept; + goto yyloop; + } + if ((yyn = yygindex[yym]) && (yyn += yystate) >= 0 && + yyn <= YYTABLESIZE && yycheck[yyn] == yystate) + yystate = yytable[yyn]; + else + yystate = yydgoto[yym]; +#if YYDEBUG + if (yydebug) + printf("%sdebug: after reduction, shifting from state %d \ +to state %d\n", YYPREFIX, *yystack.s_mark, yystate); +#endif + if (yystack.s_mark >= yystack.s_last && yygrowstack(&yystack)) + { + goto yyoverflow; + } + *++yystack.s_mark = (short) yystate; + *++yystack.l_mark = yyval; + goto yyloop; + +yyoverflow: + yyerror("yacc stack overflow"); + +yyabort: + yyfreestack(&yystack); + return (1); + +yyaccept: + yyfreestack(&yystack); + return (0); +} diff --git a/test/error.tab.h b/test/error.tab.h new file mode 100644 index 000000000000..e69de29bb2d1 --- /dev/null +++ b/test/error.tab.h diff --git a/test/error.y b/test/error.y new file mode 100644 index 000000000000..673c68d68e92 --- /dev/null +++ b/test/error.y @@ -0,0 +1,28 @@ +%{ +int yylex(void); +static void yyerror(const char *); +%} +%% +S: error +%% + +#include <stdio.h> + +int +main(void) +{ + printf("yyparse() = %d\n", yyparse()); + return 0; +} + +int +yylex(void) +{ + return -1; +} + +static void +yyerror(const char* s) +{ + printf("%s\n", s); +} diff --git a/test/ftp.output b/test/ftp.output new file mode 100644 index 000000000000..f1ab4b298829 --- /dev/null +++ b/test/ftp.output @@ -0,0 +1,1625 @@ + 0 $accept : cmd_list $end + + 1 cmd_list : + 2 | cmd_list cmd + 3 | cmd_list rcmd + + 4 cmd : USER SP username CRLF + 5 | PASS SP password CRLF + 6 | PORT SP host_port CRLF + 7 | PASV CRLF + 8 | TYPE SP type_code CRLF + 9 | STRU SP struct_code CRLF + 10 | MODE SP mode_code CRLF + 11 | ALLO SP NUMBER CRLF + 12 | ALLO SP NUMBER SP R SP NUMBER CRLF + 13 | RETR check_login SP pathname CRLF + 14 | STOR check_login SP pathname CRLF + 15 | APPE check_login SP pathname CRLF + 16 | NLST check_login CRLF + 17 | NLST check_login SP STRING CRLF + 18 | LIST check_login CRLF + 19 | LIST check_login SP pathname CRLF + 20 | STAT check_login SP pathname CRLF + 21 | STAT CRLF + 22 | DELE check_login SP pathname CRLF + 23 | RNTO SP pathname CRLF + 24 | ABOR CRLF + 25 | CWD check_login CRLF + 26 | CWD check_login SP pathname CRLF + 27 | HELP CRLF + 28 | HELP SP STRING CRLF + 29 | NOOP CRLF + 30 | MKD check_login SP pathname CRLF + 31 | RMD check_login SP pathname CRLF + 32 | PWD check_login CRLF + 33 | CDUP check_login CRLF + 34 | SITE SP HELP CRLF + 35 | SITE SP HELP SP STRING CRLF + 36 | SITE SP UMASK check_login CRLF + 37 | SITE SP UMASK check_login SP octal_number CRLF + 38 | SITE SP CHMOD check_login SP octal_number SP pathname CRLF + 39 | SITE SP IDLE CRLF + 40 | SITE SP IDLE SP NUMBER CRLF + 41 | STOU check_login SP pathname CRLF + 42 | SYST CRLF + 43 | SIZE check_login SP pathname CRLF + 44 | MDTM check_login SP pathname CRLF + 45 | QUIT CRLF + 46 | error CRLF + + 47 rcmd : RNFR check_login SP pathname CRLF + + 48 username : STRING + + 49 password : + 50 | STRING + + 51 byte_size : NUMBER + + 52 host_port : NUMBER COMMA NUMBER COMMA NUMBER COMMA NUMBER COMMA NUMBER COMMA NUMBER + + 53 form_code : N + 54 | T + 55 | C + + 56 type_code : A + 57 | A SP form_code + 58 | E + 59 | E SP form_code + 60 | I + 61 | L + 62 | L SP byte_size + 63 | L byte_size + + 64 struct_code : F + 65 | R + 66 | P + + 67 mode_code : S + 68 | B + 69 | C + + 70 pathname : pathstring + + 71 pathstring : STRING + + 72 octal_number : NUMBER + + 73 check_login : + +state 0 + $accept : . cmd_list $end (0) + cmd_list : . (1) + + . reduce 1 + + cmd_list goto 1 + + +state 1 + $accept : cmd_list . $end (0) + cmd_list : cmd_list . cmd (2) + cmd_list : cmd_list . rcmd (3) + + $end accept + error shift 2 + USER shift 3 + PASS shift 4 + QUIT shift 5 + PORT shift 6 + PASV shift 7 + TYPE shift 8 + STRU shift 9 + MODE shift 10 + RETR shift 11 + STOR shift 12 + APPE shift 13 + ALLO shift 14 + RNFR shift 15 + RNTO shift 16 + ABOR shift 17 + DELE shift 18 + CWD shift 19 + LIST shift 20 + NLST shift 21 + SITE shift 22 + STAT shift 23 + HELP shift 24 + NOOP shift 25 + MKD shift 26 + RMD shift 27 + PWD shift 28 + CDUP shift 29 + STOU shift 30 + SYST shift 31 + SIZE shift 32 + MDTM shift 33 + . error + + cmd goto 34 + rcmd goto 35 + + +state 2 + cmd : error . CRLF (46) + + CRLF shift 36 + . error + + +state 3 + cmd : USER . SP username CRLF (4) + + SP shift 37 + . error + + +state 4 + cmd : PASS . SP password CRLF (5) + + SP shift 38 + . error + + +state 5 + cmd : QUIT . CRLF (45) + + CRLF shift 39 + . error + + +state 6 + cmd : PORT . SP host_port CRLF (6) + + SP shift 40 + . error + + +state 7 + cmd : PASV . CRLF (7) + + CRLF shift 41 + . error + + +state 8 + cmd : TYPE . SP type_code CRLF (8) + + SP shift 42 + . error + + +state 9 + cmd : STRU . SP struct_code CRLF (9) + + SP shift 43 + . error + + +state 10 + cmd : MODE . SP mode_code CRLF (10) + + SP shift 44 + . error + + +state 11 + cmd : RETR . check_login SP pathname CRLF (13) + check_login : . (73) + + . reduce 73 + + check_login goto 45 + + +state 12 + cmd : STOR . check_login SP pathname CRLF (14) + check_login : . (73) + + . reduce 73 + + check_login goto 46 + + +state 13 + cmd : APPE . check_login SP pathname CRLF (15) + check_login : . (73) + + . reduce 73 + + check_login goto 47 + + +state 14 + cmd : ALLO . SP NUMBER CRLF (11) + cmd : ALLO . SP NUMBER SP R SP NUMBER CRLF (12) + + SP shift 48 + . error + + +state 15 + rcmd : RNFR . check_login SP pathname CRLF (47) + check_login : . (73) + + . reduce 73 + + check_login goto 49 + + +state 16 + cmd : RNTO . SP pathname CRLF (23) + + SP shift 50 + . error + + +state 17 + cmd : ABOR . CRLF (24) + + CRLF shift 51 + . error + + +state 18 + cmd : DELE . check_login SP pathname CRLF (22) + check_login : . (73) + + . reduce 73 + + check_login goto 52 + + +state 19 + cmd : CWD . check_login CRLF (25) + cmd : CWD . check_login SP pathname CRLF (26) + check_login : . (73) + + . reduce 73 + + check_login goto 53 + + +state 20 + cmd : LIST . check_login CRLF (18) + cmd : LIST . check_login SP pathname CRLF (19) + check_login : . (73) + + . reduce 73 + + check_login goto 54 + + +state 21 + cmd : NLST . check_login CRLF (16) + cmd : NLST . check_login SP STRING CRLF (17) + check_login : . (73) + + . reduce 73 + + check_login goto 55 + + +state 22 + cmd : SITE . SP HELP CRLF (34) + cmd : SITE . SP HELP SP STRING CRLF (35) + cmd : SITE . SP UMASK check_login CRLF (36) + cmd : SITE . SP UMASK check_login SP octal_number CRLF (37) + cmd : SITE . SP CHMOD check_login SP octal_number SP pathname CRLF (38) + cmd : SITE . SP IDLE CRLF (39) + cmd : SITE . SP IDLE SP NUMBER CRLF (40) + + SP shift 56 + . error + + +state 23 + cmd : STAT . check_login SP pathname CRLF (20) + cmd : STAT . CRLF (21) + check_login : . (73) + + CRLF shift 57 + SP reduce 73 + + check_login goto 58 + + +state 24 + cmd : HELP . CRLF (27) + cmd : HELP . SP STRING CRLF (28) + + SP shift 59 + CRLF shift 60 + . error + + +state 25 + cmd : NOOP . CRLF (29) + + CRLF shift 61 + . error + + +state 26 + cmd : MKD . check_login SP pathname CRLF (30) + check_login : . (73) + + . reduce 73 + + check_login goto 62 + + +state 27 + cmd : RMD . check_login SP pathname CRLF (31) + check_login : . (73) + + . reduce 73 + + check_login goto 63 + + +state 28 + cmd : PWD . check_login CRLF (32) + check_login : . (73) + + . reduce 73 + + check_login goto 64 + + +state 29 + cmd : CDUP . check_login CRLF (33) + check_login : . (73) + + . reduce 73 + + check_login goto 65 + + +state 30 + cmd : STOU . check_login SP pathname CRLF (41) + check_login : . (73) + + . reduce 73 + + check_login goto 66 + + +state 31 + cmd : SYST . CRLF (42) + + CRLF shift 67 + . error + + +state 32 + cmd : SIZE . check_login SP pathname CRLF (43) + check_login : . (73) + + . reduce 73 + + check_login goto 68 + + +state 33 + cmd : MDTM . check_login SP pathname CRLF (44) + check_login : . (73) + + . reduce 73 + + check_login goto 69 + + +state 34 + cmd_list : cmd_list cmd . (2) + + . reduce 2 + + +state 35 + cmd_list : cmd_list rcmd . (3) + + . reduce 3 + + +state 36 + cmd : error CRLF . (46) + + . reduce 46 + + +state 37 + cmd : USER SP . username CRLF (4) + + STRING shift 70 + . error + + username goto 71 + + +state 38 + cmd : PASS SP . password CRLF (5) + password : . (49) + + STRING shift 72 + CRLF reduce 49 + + password goto 73 + + +state 39 + cmd : QUIT CRLF . (45) + + . reduce 45 + + +state 40 + cmd : PORT SP . host_port CRLF (6) + + NUMBER shift 74 + . error + + host_port goto 75 + + +state 41 + cmd : PASV CRLF . (7) + + . reduce 7 + + +state 42 + cmd : TYPE SP . type_code CRLF (8) + + A shift 76 + E shift 77 + I shift 78 + L shift 79 + . error + + type_code goto 80 + + +state 43 + cmd : STRU SP . struct_code CRLF (9) + + F shift 81 + P shift 82 + R shift 83 + . error + + struct_code goto 84 + + +state 44 + cmd : MODE SP . mode_code CRLF (10) + + B shift 85 + C shift 86 + S shift 87 + . error + + mode_code goto 88 + + +state 45 + cmd : RETR check_login . SP pathname CRLF (13) + + SP shift 89 + . error + + +state 46 + cmd : STOR check_login . SP pathname CRLF (14) + + SP shift 90 + . error + + +state 47 + cmd : APPE check_login . SP pathname CRLF (15) + + SP shift 91 + . error + + +state 48 + cmd : ALLO SP . NUMBER CRLF (11) + cmd : ALLO SP . NUMBER SP R SP NUMBER CRLF (12) + + NUMBER shift 92 + . error + + +state 49 + rcmd : RNFR check_login . SP pathname CRLF (47) + + SP shift 93 + . error + + +state 50 + cmd : RNTO SP . pathname CRLF (23) + + STRING shift 94 + . error + + pathname goto 95 + pathstring goto 96 + + +state 51 + cmd : ABOR CRLF . (24) + + . reduce 24 + + +state 52 + cmd : DELE check_login . SP pathname CRLF (22) + + SP shift 97 + . error + + +state 53 + cmd : CWD check_login . CRLF (25) + cmd : CWD check_login . SP pathname CRLF (26) + + SP shift 98 + CRLF shift 99 + . error + + +state 54 + cmd : LIST check_login . CRLF (18) + cmd : LIST check_login . SP pathname CRLF (19) + + SP shift 100 + CRLF shift 101 + . error + + +state 55 + cmd : NLST check_login . CRLF (16) + cmd : NLST check_login . SP STRING CRLF (17) + + SP shift 102 + CRLF shift 103 + . error + + +state 56 + cmd : SITE SP . HELP CRLF (34) + cmd : SITE SP . HELP SP STRING CRLF (35) + cmd : SITE SP . UMASK check_login CRLF (36) + cmd : SITE SP . UMASK check_login SP octal_number CRLF (37) + cmd : SITE SP . CHMOD check_login SP octal_number SP pathname CRLF (38) + cmd : SITE SP . IDLE CRLF (39) + cmd : SITE SP . IDLE SP NUMBER CRLF (40) + + HELP shift 104 + UMASK shift 105 + IDLE shift 106 + CHMOD shift 107 + . error + + +state 57 + cmd : STAT CRLF . (21) + + . reduce 21 + + +state 58 + cmd : STAT check_login . SP pathname CRLF (20) + + SP shift 108 + . error + + +state 59 + cmd : HELP SP . STRING CRLF (28) + + STRING shift 109 + . error + + +state 60 + cmd : HELP CRLF . (27) + + . reduce 27 + + +state 61 + cmd : NOOP CRLF . (29) + + . reduce 29 + + +state 62 + cmd : MKD check_login . SP pathname CRLF (30) + + SP shift 110 + . error + + +state 63 + cmd : RMD check_login . SP pathname CRLF (31) + + SP shift 111 + . error + + +state 64 + cmd : PWD check_login . CRLF (32) + + CRLF shift 112 + . error + + +state 65 + cmd : CDUP check_login . CRLF (33) + + CRLF shift 113 + . error + + +state 66 + cmd : STOU check_login . SP pathname CRLF (41) + + SP shift 114 + . error + + +state 67 + cmd : SYST CRLF . (42) + + . reduce 42 + + +state 68 + cmd : SIZE check_login . SP pathname CRLF (43) + + SP shift 115 + . error + + +state 69 + cmd : MDTM check_login . SP pathname CRLF (44) + + SP shift 116 + . error + + +state 70 + username : STRING . (48) + + . reduce 48 + + +state 71 + cmd : USER SP username . CRLF (4) + + CRLF shift 117 + . error + + +state 72 + password : STRING . (50) + + . reduce 50 + + +state 73 + cmd : PASS SP password . CRLF (5) + + CRLF shift 118 + . error + + +state 74 + host_port : NUMBER . COMMA NUMBER COMMA NUMBER COMMA NUMBER COMMA NUMBER COMMA NUMBER (52) + + COMMA shift 119 + . error + + +state 75 + cmd : PORT SP host_port . CRLF (6) + + CRLF shift 120 + . error + + +state 76 + type_code : A . (56) + type_code : A . SP form_code (57) + + SP shift 121 + CRLF reduce 56 + + +state 77 + type_code : E . (58) + type_code : E . SP form_code (59) + + SP shift 122 + CRLF reduce 58 + + +state 78 + type_code : I . (60) + + . reduce 60 + + +state 79 + type_code : L . (61) + type_code : L . SP byte_size (62) + type_code : L . byte_size (63) + + SP shift 123 + NUMBER shift 124 + CRLF reduce 61 + + byte_size goto 125 + + +state 80 + cmd : TYPE SP type_code . CRLF (8) + + CRLF shift 126 + . error + + +state 81 + struct_code : F . (64) + + . reduce 64 + + +state 82 + struct_code : P . (66) + + . reduce 66 + + +state 83 + struct_code : R . (65) + + . reduce 65 + + +state 84 + cmd : STRU SP struct_code . CRLF (9) + + CRLF shift 127 + . error + + +state 85 + mode_code : B . (68) + + . reduce 68 + + +state 86 + mode_code : C . (69) + + . reduce 69 + + +state 87 + mode_code : S . (67) + + . reduce 67 + + +state 88 + cmd : MODE SP mode_code . CRLF (10) + + CRLF shift 128 + . error + + +state 89 + cmd : RETR check_login SP . pathname CRLF (13) + + STRING shift 94 + . error + + pathname goto 129 + pathstring goto 96 + + +state 90 + cmd : STOR check_login SP . pathname CRLF (14) + + STRING shift 94 + . error + + pathname goto 130 + pathstring goto 96 + + +state 91 + cmd : APPE check_login SP . pathname CRLF (15) + + STRING shift 94 + . error + + pathname goto 131 + pathstring goto 96 + + +state 92 + cmd : ALLO SP NUMBER . CRLF (11) + cmd : ALLO SP NUMBER . SP R SP NUMBER CRLF (12) + + SP shift 132 + CRLF shift 133 + . error + + +state 93 + rcmd : RNFR check_login SP . pathname CRLF (47) + + STRING shift 94 + . error + + pathname goto 134 + pathstring goto 96 + + +state 94 + pathstring : STRING . (71) + + . reduce 71 + + +state 95 + cmd : RNTO SP pathname . CRLF (23) + + CRLF shift 135 + . error + + +state 96 + pathname : pathstring . (70) + + . reduce 70 + + +state 97 + cmd : DELE check_login SP . pathname CRLF (22) + + STRING shift 94 + . error + + pathname goto 136 + pathstring goto 96 + + +state 98 + cmd : CWD check_login SP . pathname CRLF (26) + + STRING shift 94 + . error + + pathname goto 137 + pathstring goto 96 + + +state 99 + cmd : CWD check_login CRLF . (25) + + . reduce 25 + + +state 100 + cmd : LIST check_login SP . pathname CRLF (19) + + STRING shift 94 + . error + + pathname goto 138 + pathstring goto 96 + + +state 101 + cmd : LIST check_login CRLF . (18) + + . reduce 18 + + +state 102 + cmd : NLST check_login SP . STRING CRLF (17) + + STRING shift 139 + . error + + +state 103 + cmd : NLST check_login CRLF . (16) + + . reduce 16 + + +state 104 + cmd : SITE SP HELP . CRLF (34) + cmd : SITE SP HELP . SP STRING CRLF (35) + + SP shift 140 + CRLF shift 141 + . error + + +state 105 + cmd : SITE SP UMASK . check_login CRLF (36) + cmd : SITE SP UMASK . check_login SP octal_number CRLF (37) + check_login : . (73) + + . reduce 73 + + check_login goto 142 + + +state 106 + cmd : SITE SP IDLE . CRLF (39) + cmd : SITE SP IDLE . SP NUMBER CRLF (40) + + SP shift 143 + CRLF shift 144 + . error + + +state 107 + cmd : SITE SP CHMOD . check_login SP octal_number SP pathname CRLF (38) + check_login : . (73) + + . reduce 73 + + check_login goto 145 + + +state 108 + cmd : STAT check_login SP . pathname CRLF (20) + + STRING shift 94 + . error + + pathname goto 146 + pathstring goto 96 + + +state 109 + cmd : HELP SP STRING . CRLF (28) + + CRLF shift 147 + . error + + +state 110 + cmd : MKD check_login SP . pathname CRLF (30) + + STRING shift 94 + . error + + pathname goto 148 + pathstring goto 96 + + +state 111 + cmd : RMD check_login SP . pathname CRLF (31) + + STRING shift 94 + . error + + pathname goto 149 + pathstring goto 96 + + +state 112 + cmd : PWD check_login CRLF . (32) + + . reduce 32 + + +state 113 + cmd : CDUP check_login CRLF . (33) + + . reduce 33 + + +state 114 + cmd : STOU check_login SP . pathname CRLF (41) + + STRING shift 94 + . error + + pathname goto 150 + pathstring goto 96 + + +state 115 + cmd : SIZE check_login SP . pathname CRLF (43) + + STRING shift 94 + . error + + pathname goto 151 + pathstring goto 96 + + +state 116 + cmd : MDTM check_login SP . pathname CRLF (44) + + STRING shift 94 + . error + + pathname goto 152 + pathstring goto 96 + + +state 117 + cmd : USER SP username CRLF . (4) + + . reduce 4 + + +state 118 + cmd : PASS SP password CRLF . (5) + + . reduce 5 + + +state 119 + host_port : NUMBER COMMA . NUMBER COMMA NUMBER COMMA NUMBER COMMA NUMBER COMMA NUMBER (52) + + NUMBER shift 153 + . error + + +state 120 + cmd : PORT SP host_port CRLF . (6) + + . reduce 6 + + +state 121 + type_code : A SP . form_code (57) + + C shift 154 + N shift 155 + T shift 156 + . error + + form_code goto 157 + + +state 122 + type_code : E SP . form_code (59) + + C shift 154 + N shift 155 + T shift 156 + . error + + form_code goto 158 + + +state 123 + type_code : L SP . byte_size (62) + + NUMBER shift 124 + . error + + byte_size goto 159 + + +state 124 + byte_size : NUMBER . (51) + + . reduce 51 + + +state 125 + type_code : L byte_size . (63) + + . reduce 63 + + +state 126 + cmd : TYPE SP type_code CRLF . (8) + + . reduce 8 + + +state 127 + cmd : STRU SP struct_code CRLF . (9) + + . reduce 9 + + +state 128 + cmd : MODE SP mode_code CRLF . (10) + + . reduce 10 + + +state 129 + cmd : RETR check_login SP pathname . CRLF (13) + + CRLF shift 160 + . error + + +state 130 + cmd : STOR check_login SP pathname . CRLF (14) + + CRLF shift 161 + . error + + +state 131 + cmd : APPE check_login SP pathname . CRLF (15) + + CRLF shift 162 + . error + + +state 132 + cmd : ALLO SP NUMBER SP . R SP NUMBER CRLF (12) + + R shift 163 + . error + + +state 133 + cmd : ALLO SP NUMBER CRLF . (11) + + . reduce 11 + + +state 134 + rcmd : RNFR check_login SP pathname . CRLF (47) + + CRLF shift 164 + . error + + +state 135 + cmd : RNTO SP pathname CRLF . (23) + + . reduce 23 + + +state 136 + cmd : DELE check_login SP pathname . CRLF (22) + + CRLF shift 165 + . error + + +state 137 + cmd : CWD check_login SP pathname . CRLF (26) + + CRLF shift 166 + . error + + +state 138 + cmd : LIST check_login SP pathname . CRLF (19) + + CRLF shift 167 + . error + + +state 139 + cmd : NLST check_login SP STRING . CRLF (17) + + CRLF shift 168 + . error + + +state 140 + cmd : SITE SP HELP SP . STRING CRLF (35) + + STRING shift 169 + . error + + +state 141 + cmd : SITE SP HELP CRLF . (34) + + . reduce 34 + + +state 142 + cmd : SITE SP UMASK check_login . CRLF (36) + cmd : SITE SP UMASK check_login . SP octal_number CRLF (37) + + SP shift 170 + CRLF shift 171 + . error + + +state 143 + cmd : SITE SP IDLE SP . NUMBER CRLF (40) + + NUMBER shift 172 + . error + + +state 144 + cmd : SITE SP IDLE CRLF . (39) + + . reduce 39 + + +state 145 + cmd : SITE SP CHMOD check_login . SP octal_number SP pathname CRLF (38) + + SP shift 173 + . error + + +state 146 + cmd : STAT check_login SP pathname . CRLF (20) + + CRLF shift 174 + . error + + +state 147 + cmd : HELP SP STRING CRLF . (28) + + . reduce 28 + + +state 148 + cmd : MKD check_login SP pathname . CRLF (30) + + CRLF shift 175 + . error + + +state 149 + cmd : RMD check_login SP pathname . CRLF (31) + + CRLF shift 176 + . error + + +state 150 + cmd : STOU check_login SP pathname . CRLF (41) + + CRLF shift 177 + . error + + +state 151 + cmd : SIZE check_login SP pathname . CRLF (43) + + CRLF shift 178 + . error + + +state 152 + cmd : MDTM check_login SP pathname . CRLF (44) + + CRLF shift 179 + . error + + +state 153 + host_port : NUMBER COMMA NUMBER . COMMA NUMBER COMMA NUMBER COMMA NUMBER COMMA NUMBER (52) + + COMMA shift 180 + . error + + +state 154 + form_code : C . (55) + + . reduce 55 + + +state 155 + form_code : N . (53) + + . reduce 53 + + +state 156 + form_code : T . (54) + + . reduce 54 + + +state 157 + type_code : A SP form_code . (57) + + . reduce 57 + + +state 158 + type_code : E SP form_code . (59) + + . reduce 59 + + +state 159 + type_code : L SP byte_size . (62) + + . reduce 62 + + +state 160 + cmd : RETR check_login SP pathname CRLF . (13) + + . reduce 13 + + +state 161 + cmd : STOR check_login SP pathname CRLF . (14) + + . reduce 14 + + +state 162 + cmd : APPE check_login SP pathname CRLF . (15) + + . reduce 15 + + +state 163 + cmd : ALLO SP NUMBER SP R . SP NUMBER CRLF (12) + + SP shift 181 + . error + + +state 164 + rcmd : RNFR check_login SP pathname CRLF . (47) + + . reduce 47 + + +state 165 + cmd : DELE check_login SP pathname CRLF . (22) + + . reduce 22 + + +state 166 + cmd : CWD check_login SP pathname CRLF . (26) + + . reduce 26 + + +state 167 + cmd : LIST check_login SP pathname CRLF . (19) + + . reduce 19 + + +state 168 + cmd : NLST check_login SP STRING CRLF . (17) + + . reduce 17 + + +state 169 + cmd : SITE SP HELP SP STRING . CRLF (35) + + CRLF shift 182 + . error + + +state 170 + cmd : SITE SP UMASK check_login SP . octal_number CRLF (37) + + NUMBER shift 183 + . error + + octal_number goto 184 + + +state 171 + cmd : SITE SP UMASK check_login CRLF . (36) + + . reduce 36 + + +state 172 + cmd : SITE SP IDLE SP NUMBER . CRLF (40) + + CRLF shift 185 + . error + + +state 173 + cmd : SITE SP CHMOD check_login SP . octal_number SP pathname CRLF (38) + + NUMBER shift 183 + . error + + octal_number goto 186 + + +state 174 + cmd : STAT check_login SP pathname CRLF . (20) + + . reduce 20 + + +state 175 + cmd : MKD check_login SP pathname CRLF . (30) + + . reduce 30 + + +state 176 + cmd : RMD check_login SP pathname CRLF . (31) + + . reduce 31 + + +state 177 + cmd : STOU check_login SP pathname CRLF . (41) + + . reduce 41 + + +state 178 + cmd : SIZE check_login SP pathname CRLF . (43) + + . reduce 43 + + +state 179 + cmd : MDTM check_login SP pathname CRLF . (44) + + . reduce 44 + + +state 180 + host_port : NUMBER COMMA NUMBER COMMA . NUMBER COMMA NUMBER COMMA NUMBER COMMA NUMBER (52) + + NUMBER shift 187 + . error + + +state 181 + cmd : ALLO SP NUMBER SP R SP . NUMBER CRLF (12) + + NUMBER shift 188 + . error + + +state 182 + cmd : SITE SP HELP SP STRING CRLF . (35) + + . reduce 35 + + +state 183 + octal_number : NUMBER . (72) + + . reduce 72 + + +state 184 + cmd : SITE SP UMASK check_login SP octal_number . CRLF (37) + + CRLF shift 189 + . error + + +state 185 + cmd : SITE SP IDLE SP NUMBER CRLF . (40) + + . reduce 40 + + +state 186 + cmd : SITE SP CHMOD check_login SP octal_number . SP pathname CRLF (38) + + SP shift 190 + . error + + +state 187 + host_port : NUMBER COMMA NUMBER COMMA NUMBER . COMMA NUMBER COMMA NUMBER COMMA NUMBER (52) + + COMMA shift 191 + . error + + +state 188 + cmd : ALLO SP NUMBER SP R SP NUMBER . CRLF (12) + + CRLF shift 192 + . error + + +state 189 + cmd : SITE SP UMASK check_login SP octal_number CRLF . (37) + + . reduce 37 + + +state 190 + cmd : SITE SP CHMOD check_login SP octal_number SP . pathname CRLF (38) + + STRING shift 94 + . error + + pathname goto 193 + pathstring goto 96 + + +state 191 + host_port : NUMBER COMMA NUMBER COMMA NUMBER COMMA . NUMBER COMMA NUMBER COMMA NUMBER (52) + + NUMBER shift 194 + . error + + +state 192 + cmd : ALLO SP NUMBER SP R SP NUMBER CRLF . (12) + + . reduce 12 + + +state 193 + cmd : SITE SP CHMOD check_login SP octal_number SP pathname . CRLF (38) + + CRLF shift 195 + . error + + +state 194 + host_port : NUMBER COMMA NUMBER COMMA NUMBER COMMA NUMBER . COMMA NUMBER COMMA NUMBER (52) + + COMMA shift 196 + . error + + +state 195 + cmd : SITE SP CHMOD check_login SP octal_number SP pathname CRLF . (38) + + . reduce 38 + + +state 196 + host_port : NUMBER COMMA NUMBER COMMA NUMBER COMMA NUMBER COMMA . NUMBER COMMA NUMBER (52) + + NUMBER shift 197 + . error + + +state 197 + host_port : NUMBER COMMA NUMBER COMMA NUMBER COMMA NUMBER COMMA NUMBER . COMMA NUMBER (52) + + COMMA shift 198 + . error + + +state 198 + host_port : NUMBER COMMA NUMBER COMMA NUMBER COMMA NUMBER COMMA NUMBER COMMA . NUMBER (52) + + NUMBER shift 199 + . error + + +state 199 + host_port : NUMBER COMMA NUMBER COMMA NUMBER COMMA NUMBER COMMA NUMBER COMMA NUMBER . (52) + + . reduce 52 + + +65 terminals, 16 nonterminals +74 grammar rules, 200 states diff --git a/test/ftp.tab.c b/test/ftp.tab.c new file mode 100644 index 000000000000..c450766e74bf --- /dev/null +++ b/test/ftp.tab.c @@ -0,0 +1,1995 @@ +#ifndef lint +static const char yysccsid[] = "@(#)yaccpar 1.9 (Berkeley) 02/21/93"; +#endif + +#define YYBYACC 1 +#define YYMAJOR 1 +#define YYMINOR 9 + +#define YYEMPTY (-1) +#define yyclearin (yychar = YYEMPTY) +#define yyerrok (yyerrflag = 0) +#define YYRECOVERING() (yyerrflag != 0) + + +#ifndef yyparse +#define yyparse ftp_parse +#endif /* yyparse */ + +#ifndef yylex +#define yylex ftp_lex +#endif /* yylex */ + +#ifndef yyerror +#define yyerror ftp_error +#endif /* yyerror */ + +#ifndef yychar +#define yychar ftp_char +#endif /* yychar */ + +#ifndef yyval +#define yyval ftp_val +#endif /* yyval */ + +#ifndef yylval +#define yylval ftp_lval +#endif /* yylval */ + +#ifndef yydebug +#define yydebug ftp_debug +#endif /* yydebug */ + +#ifndef yynerrs +#define yynerrs ftp_nerrs +#endif /* yynerrs */ + +#ifndef yyerrflag +#define yyerrflag ftp_errflag +#endif /* yyerrflag */ + +#ifndef yylhs +#define yylhs ftp_lhs +#endif /* yylhs */ + +#ifndef yylen +#define yylen ftp_len +#endif /* yylen */ + +#ifndef yydefred +#define yydefred ftp_defred +#endif /* yydefred */ + +#ifndef yydgoto +#define yydgoto ftp_dgoto +#endif /* yydgoto */ + +#ifndef yysindex +#define yysindex ftp_sindex +#endif /* yysindex */ + +#ifndef yyrindex +#define yyrindex ftp_rindex +#endif /* yyrindex */ + +#ifndef yygindex +#define yygindex ftp_gindex +#endif /* yygindex */ + +#ifndef yytable +#define yytable ftp_table +#endif /* yytable */ + +#ifndef yycheck +#define yycheck ftp_check +#endif /* yycheck */ + +#ifndef yyname +#define yyname ftp_name +#endif /* yyname */ + +#ifndef yyrule +#define yyrule ftp_rule +#endif /* yyrule */ +#define YYPREFIX "ftp_" + +#define YYPURE 0 + +#line 26 "ftp.y" + +/* sccsid[] = "@(#)ftpcmd.y 5.20.1.1 (Berkeley) 3/2/89"; */ + +#include <sys/param.h> +#include <sys/socket.h> + +#include <netinet/in.h> + +#include <arpa/ftp.h> + +#include <stdlib.h> +#include <unistd.h> +#include <stdio.h> +#include <signal.h> +#include <ctype.h> +#include <pwd.h> +#include <setjmp.h> +#include <syslog.h> +#include <sys/stat.h> +#include <string.h> +#include <time.h> +#include <assert.h> + +#ifdef YYBISON +int yylex(void); +static void yyerror(const char *); +#endif + +extern struct sockaddr_in data_dest; +extern int logged_in; +extern struct passwd *pw; +extern int guest; +extern int logging; +extern int type; +extern int form; +extern int debug; +extern int timeout; +extern int maxtimeout; +extern int pdata; +extern char hostname[], remotehost[]; +extern char proctitle[]; +extern char *globerr; +extern int usedefault; +extern int transflag; +extern char tmpline[]; + +extern char **glob(char *); +extern char *renamefrom(char *); +extern void cwd(const char *); + +extern void dologout(int); +extern void fatal(const char *); +extern void makedir(const char *); +extern void nack(const char *); +extern void pass(const char *); +extern void passive(void); +extern void pwd(void); +extern void removedir(char *); +extern void renamecmd(char *, char *); +extern void retrieve(const char *, const char *); +extern void send_file_list(const char *); +extern void statcmd(void); +extern void statfilecmd(const char *); +extern void store(char *, const char *, int); +extern void user(const char *); + +extern void perror_reply(int, const char *, ...); +extern void reply(int, const char *, ...); +extern void lreply(int, const char *, ...); + +static int cmd_type; +static int cmd_form; +static int cmd_bytesz; +char cbuf[512]; +char *fromname; + +struct tab { + const char *name; + short token; + short state; + short implemented; /* 1 if command is implemented */ + const char *help; +}; + +static char * copy(const char *); + +#ifdef YYBISON +static void sizecmd(char *filename); +static void help(struct tab *ctab, char *s); +struct tab cmdtab[]; +struct tab sitetab[]; +#endif + +static void +yyerror(const char *msg) +{ + perror(msg); +} +#line 198 "ftp.tab.c" + +#ifndef YYSTYPE +typedef int YYSTYPE; +#endif + +/* compatibility with bison */ +#ifdef YYPARSE_PARAM +/* compatibility with FreeBSD */ +# ifdef YYPARSE_PARAM_TYPE +# define YYPARSE_DECL() yyparse(YYPARSE_PARAM_TYPE YYPARSE_PARAM) +# else +# define YYPARSE_DECL() yyparse(void *YYPARSE_PARAM) +# endif +#else +# define YYPARSE_DECL() yyparse(void) +#endif + +/* Parameters sent to lex. */ +#ifdef YYLEX_PARAM +# define YYLEX_DECL() yylex(void *YYLEX_PARAM) +# define YYLEX yylex(YYLEX_PARAM) +#else +# define YYLEX_DECL() yylex(void) +# define YYLEX yylex() +#endif + +/* Parameters sent to yyerror. */ +#ifndef YYERROR_DECL +#define YYERROR_DECL() yyerror(const char *s) +#endif +#ifndef YYERROR_CALL +#define YYERROR_CALL(msg) yyerror(msg) +#endif + +extern int YYPARSE_DECL(); + +#define A 257 +#define B 258 +#define C 259 +#define E 260 +#define F 261 +#define I 262 +#define L 263 +#define N 264 +#define P 265 +#define R 266 +#define S 267 +#define T 268 +#define SP 269 +#define CRLF 270 +#define COMMA 271 +#define STRING 272 +#define NUMBER 273 +#define USER 274 +#define PASS 275 +#define ACCT 276 +#define REIN 277 +#define QUIT 278 +#define PORT 279 +#define PASV 280 +#define TYPE 281 +#define STRU 282 +#define MODE 283 +#define RETR 284 +#define STOR 285 +#define APPE 286 +#define MLFL 287 +#define MAIL 288 +#define MSND 289 +#define MSOM 290 +#define MSAM 291 +#define MRSQ 292 +#define MRCP 293 +#define ALLO 294 +#define REST 295 +#define RNFR 296 +#define RNTO 297 +#define ABOR 298 +#define DELE 299 +#define CWD 300 +#define LIST 301 +#define NLST 302 +#define SITE 303 +#define STAT 304 +#define HELP 305 +#define NOOP 306 +#define MKD 307 +#define RMD 308 +#define PWD 309 +#define CDUP 310 +#define STOU 311 +#define SMNT 312 +#define SYST 313 +#define SIZE 314 +#define MDTM 315 +#define UMASK 316 +#define IDLE 317 +#define CHMOD 318 +#define LEXERR 319 +#define YYERRCODE 256 +static const short ftp_lhs[] = { -1, + 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 2, 3, 4, 4, + 12, 5, 13, 13, 13, 6, 6, 6, 6, 6, + 6, 6, 6, 7, 7, 7, 8, 8, 8, 10, + 14, 11, 9, +}; +static const short ftp_len[] = { 2, + 0, 2, 2, 4, 4, 4, 2, 4, 4, 4, + 4, 8, 5, 5, 5, 3, 5, 3, 5, 5, + 2, 5, 4, 2, 3, 5, 2, 4, 2, 5, + 5, 3, 3, 4, 6, 5, 7, 9, 4, 6, + 5, 2, 5, 5, 2, 2, 5, 1, 0, 1, + 1, 11, 1, 1, 1, 1, 3, 1, 3, 1, + 1, 3, 2, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 0, +}; +static const short ftp_defred[] = { 1, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 73, 73, 73, 0, 73, 0, 0, 73, 73, 73, + 73, 0, 0, 0, 0, 73, 73, 73, 73, 73, + 0, 73, 73, 2, 3, 46, 0, 0, 45, 0, + 7, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 24, 0, 0, 0, 0, 0, 21, 0, 0, 27, + 29, 0, 0, 0, 0, 0, 42, 0, 0, 48, + 0, 50, 0, 0, 0, 0, 0, 60, 0, 0, + 64, 66, 65, 0, 68, 69, 67, 0, 0, 0, + 0, 0, 0, 71, 0, 70, 0, 0, 25, 0, + 18, 0, 16, 0, 73, 0, 73, 0, 0, 0, + 0, 32, 33, 0, 0, 0, 4, 5, 0, 6, + 0, 0, 0, 51, 63, 8, 9, 10, 0, 0, + 0, 0, 11, 0, 23, 0, 0, 0, 0, 0, + 34, 0, 0, 39, 0, 0, 28, 0, 0, 0, + 0, 0, 0, 55, 53, 54, 57, 59, 62, 13, + 14, 15, 0, 47, 22, 26, 19, 17, 0, 0, + 36, 0, 0, 20, 30, 31, 41, 43, 44, 0, + 0, 35, 72, 0, 40, 0, 0, 0, 37, 0, + 0, 12, 0, 0, 38, 0, 0, 0, 52, +}; +static const short ftp_dgoto[] = { 1, + 34, 35, 71, 73, 75, 80, 84, 88, 45, 95, + 184, 125, 157, 96, +}; +static const short ftp_sindex[] = { 0, + -224, -247, -239, -236, -232, -222, -204, -200, -181, -177, + 0, 0, 0, -166, 0, -161, -199, 0, 0, 0, + 0, -160, -159, -264, -158, 0, 0, 0, 0, 0, + -157, 0, 0, 0, 0, 0, -167, -162, 0, -156, + 0, -250, -198, -165, -155, -154, -153, -151, -150, -152, + 0, -145, -252, -229, -217, -302, 0, -144, -146, 0, + 0, -142, -141, -140, -139, -137, 0, -136, -135, 0, + -134, 0, -133, -132, -130, -131, -128, 0, -249, -127, + 0, 0, 0, -126, 0, 0, 0, -125, -152, -152, + -152, -205, -152, 0, -124, 0, -152, -152, 0, -152, + 0, -143, 0, -173, 0, -171, 0, -152, -123, -152, + -152, 0, 0, -152, -152, -152, 0, 0, -138, 0, + -164, -164, -122, 0, 0, 0, 0, 0, -121, -120, + -118, -148, 0, -117, 0, -116, -115, -114, -113, -112, + 0, -163, -111, 0, -110, -109, 0, -107, -106, -105, + -104, -103, -129, 0, 0, 0, 0, 0, 0, 0, + 0, 0, -101, 0, 0, 0, 0, 0, -100, -102, + 0, -98, -102, 0, 0, 0, 0, 0, 0, -99, + -97, 0, 0, -95, 0, -96, -94, -92, 0, -152, + -93, 0, -91, -90, 0, -88, -87, -86, 0, +}; +static const short ftp_rindex[] = { 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, -83, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, -82, 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, 0, 0, 0, 0, + 0, 0, 0, 0, 0, -81, -80, 0, -158, 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, 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, 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, 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, 0, 0, 0, 0, 0, 0, 0, 0, +}; +static const short ftp_gindex[] = { 0, + 0, 0, 0, 0, 0, 0, 0, 0, 16, -89, + -25, 35, 47, 0, +}; +#define YYTABLESIZE 190 +static const short ftp_table[] = { 129, + 130, 131, 104, 134, 59, 60, 76, 136, 137, 77, + 138, 78, 79, 105, 106, 107, 98, 99, 146, 123, + 148, 149, 36, 124, 150, 151, 152, 46, 47, 37, + 49, 2, 38, 52, 53, 54, 55, 39, 58, 100, + 101, 62, 63, 64, 65, 66, 40, 68, 69, 3, + 4, 102, 103, 5, 6, 7, 8, 9, 10, 11, + 12, 13, 81, 132, 133, 41, 82, 83, 42, 14, + 51, 15, 16, 17, 18, 19, 20, 21, 22, 23, + 24, 25, 26, 27, 28, 29, 30, 43, 31, 32, + 33, 44, 85, 86, 154, 140, 141, 143, 144, 155, + 193, 87, 48, 156, 70, 170, 171, 50, 56, 72, + 57, 61, 67, 89, 90, 91, 74, 163, 93, 94, + 142, 92, 145, 97, 108, 109, 110, 111, 139, 112, + 113, 114, 115, 116, 153, 117, 118, 121, 119, 120, + 122, 180, 126, 127, 128, 135, 147, 186, 160, 161, + 124, 162, 164, 165, 166, 167, 168, 159, 173, 169, + 174, 172, 175, 176, 177, 178, 179, 181, 158, 182, + 183, 185, 190, 187, 189, 188, 191, 192, 195, 194, + 196, 0, 0, 198, 197, 73, 199, 49, 56, 58, +}; +static const short ftp_check[] = { 89, + 90, 91, 305, 93, 269, 270, 257, 97, 98, 260, + 100, 262, 263, 316, 317, 318, 269, 270, 108, 269, + 110, 111, 270, 273, 114, 115, 116, 12, 13, 269, + 15, 256, 269, 18, 19, 20, 21, 270, 23, 269, + 270, 26, 27, 28, 29, 30, 269, 32, 33, 274, + 275, 269, 270, 278, 279, 280, 281, 282, 283, 284, + 285, 286, 261, 269, 270, 270, 265, 266, 269, 294, + 270, 296, 297, 298, 299, 300, 301, 302, 303, 304, + 305, 306, 307, 308, 309, 310, 311, 269, 313, 314, + 315, 269, 258, 259, 259, 269, 270, 269, 270, 264, + 190, 267, 269, 268, 272, 269, 270, 269, 269, 272, + 270, 270, 270, 269, 269, 269, 273, 266, 269, 272, + 105, 273, 107, 269, 269, 272, 269, 269, 272, 270, + 270, 269, 269, 269, 273, 270, 270, 269, 271, 270, + 269, 271, 270, 270, 270, 270, 270, 173, 270, 270, + 273, 270, 270, 270, 270, 270, 270, 123, 269, 272, + 270, 273, 270, 270, 270, 270, 270, 269, 122, 270, + 273, 270, 269, 273, 270, 273, 271, 270, 270, 273, + 271, -1, -1, 271, 273, 269, 273, 270, 270, 270, +}; +#define YYFINAL 1 +#ifndef YYDEBUG +#define YYDEBUG 0 +#endif +#define YYMAXTOKEN 319 +#if YYDEBUG +static const char *yyname[] = { + +"end-of-file",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,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,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,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,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,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,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,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,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,0,0,0,0,"A","B","C","E","F","I","L","N", +"P","R","S","T","SP","CRLF","COMMA","STRING","NUMBER","USER","PASS","ACCT", +"REIN","QUIT","PORT","PASV","TYPE","STRU","MODE","RETR","STOR","APPE","MLFL", +"MAIL","MSND","MSOM","MSAM","MRSQ","MRCP","ALLO","REST","RNFR","RNTO","ABOR", +"DELE","CWD","LIST","NLST","SITE","STAT","HELP","NOOP","MKD","RMD","PWD","CDUP", +"STOU","SMNT","SYST","SIZE","MDTM","UMASK","IDLE","CHMOD","LEXERR", +}; +static const char *yyrule[] = { +"$accept : cmd_list", +"cmd_list :", +"cmd_list : cmd_list cmd", +"cmd_list : cmd_list rcmd", +"cmd : USER SP username CRLF", +"cmd : PASS SP password CRLF", +"cmd : PORT SP host_port CRLF", +"cmd : PASV CRLF", +"cmd : TYPE SP type_code CRLF", +"cmd : STRU SP struct_code CRLF", +"cmd : MODE SP mode_code CRLF", +"cmd : ALLO SP NUMBER CRLF", +"cmd : ALLO SP NUMBER SP R SP NUMBER CRLF", +"cmd : RETR check_login SP pathname CRLF", +"cmd : STOR check_login SP pathname CRLF", +"cmd : APPE check_login SP pathname CRLF", +"cmd : NLST check_login CRLF", +"cmd : NLST check_login SP STRING CRLF", +"cmd : LIST check_login CRLF", +"cmd : LIST check_login SP pathname CRLF", +"cmd : STAT check_login SP pathname CRLF", +"cmd : STAT CRLF", +"cmd : DELE check_login SP pathname CRLF", +"cmd : RNTO SP pathname CRLF", +"cmd : ABOR CRLF", +"cmd : CWD check_login CRLF", +"cmd : CWD check_login SP pathname CRLF", +"cmd : HELP CRLF", +"cmd : HELP SP STRING CRLF", +"cmd : NOOP CRLF", +"cmd : MKD check_login SP pathname CRLF", +"cmd : RMD check_login SP pathname CRLF", +"cmd : PWD check_login CRLF", +"cmd : CDUP check_login CRLF", +"cmd : SITE SP HELP CRLF", +"cmd : SITE SP HELP SP STRING CRLF", +"cmd : SITE SP UMASK check_login CRLF", +"cmd : SITE SP UMASK check_login SP octal_number CRLF", +"cmd : SITE SP CHMOD check_login SP octal_number SP pathname CRLF", +"cmd : SITE SP IDLE CRLF", +"cmd : SITE SP IDLE SP NUMBER CRLF", +"cmd : STOU check_login SP pathname CRLF", +"cmd : SYST CRLF", +"cmd : SIZE check_login SP pathname CRLF", +"cmd : MDTM check_login SP pathname CRLF", +"cmd : QUIT CRLF", +"cmd : error CRLF", +"rcmd : RNFR check_login SP pathname CRLF", +"username : STRING", +"password :", +"password : STRING", +"byte_size : NUMBER", +"host_port : NUMBER COMMA NUMBER COMMA NUMBER COMMA NUMBER COMMA NUMBER COMMA NUMBER", +"form_code : N", +"form_code : T", +"form_code : C", +"type_code : A", +"type_code : A SP form_code", +"type_code : E", +"type_code : E SP form_code", +"type_code : I", +"type_code : L", +"type_code : L SP byte_size", +"type_code : L byte_size", +"struct_code : F", +"struct_code : R", +"struct_code : P", +"mode_code : S", +"mode_code : B", +"mode_code : C", +"pathname : pathstring", +"pathstring : STRING", +"octal_number : NUMBER", +"check_login :", + +}; +#endif + +int yydebug; +int yynerrs; + +int yyerrflag; +int yychar; +YYSTYPE yyval; +YYSTYPE yylval; + +/* define the initial stack-sizes */ +#ifdef YYSTACKSIZE +#undef YYMAXDEPTH +#define YYMAXDEPTH YYSTACKSIZE +#else +#ifdef YYMAXDEPTH +#define YYSTACKSIZE YYMAXDEPTH +#else +#define YYSTACKSIZE 500 +#define YYMAXDEPTH 500 +#endif +#endif + +#define YYINITSTACKSIZE 500 + +typedef struct { + unsigned stacksize; + short *s_base; + short *s_mark; + short *s_last; + YYSTYPE *l_base; + YYSTYPE *l_mark; +} YYSTACKDATA; +/* variables for the parser stack */ +static YYSTACKDATA yystack; +#line 707 "ftp.y" + +#ifdef YYBYACC +extern int YYLEX_DECL(); +#endif + +extern jmp_buf errcatch; + +static void upper(char *); + +#define CMD 0 /* beginning of command */ +#define ARGS 1 /* expect miscellaneous arguments */ +#define STR1 2 /* expect SP followed by STRING */ +#define STR2 3 /* expect STRING */ +#define OSTR 4 /* optional SP then STRING */ +#define ZSTR1 5 /* SP then optional STRING */ +#define ZSTR2 6 /* optional STRING after SP */ +#define SITECMD 7 /* SITE command */ +#define NSTR 8 /* Number followed by a string */ + +struct tab cmdtab[] = { /* In order defined in RFC 765 */ + { "USER", USER, STR1, 1, "<sp> username" }, + { "PASS", PASS, ZSTR1, 1, "<sp> password" }, + { "ACCT", ACCT, STR1, 0, "(specify account)" }, + { "SMNT", SMNT, ARGS, 0, "(structure mount)" }, + { "REIN", REIN, ARGS, 0, "(reinitialize server state)" }, + { "QUIT", QUIT, ARGS, 1, "(terminate service)", }, + { "PORT", PORT, ARGS, 1, "<sp> b0, b1, b2, b3, b4" }, + { "PASV", PASV, ARGS, 1, "(set server in passive mode)" }, + { "TYPE", TYPE, ARGS, 1, "<sp> [ A | E | I | L ]" }, + { "STRU", STRU, ARGS, 1, "(specify file structure)" }, + { "MODE", MODE, ARGS, 1, "(specify transfer mode)" }, + { "RETR", RETR, STR1, 1, "<sp> file-name" }, + { "STOR", STOR, STR1, 1, "<sp> file-name" }, + { "APPE", APPE, STR1, 1, "<sp> file-name" }, + { "MLFL", MLFL, OSTR, 0, "(mail file)" }, + { "MAIL", MAIL, OSTR, 0, "(mail to user)" }, + { "MSND", MSND, OSTR, 0, "(mail send to terminal)" }, + { "MSOM", MSOM, OSTR, 0, "(mail send to terminal or mailbox)" }, + { "MSAM", MSAM, OSTR, 0, "(mail send to terminal and mailbox)" }, + { "MRSQ", MRSQ, OSTR, 0, "(mail recipient scheme question)" }, + { "MRCP", MRCP, STR1, 0, "(mail recipient)" }, + { "ALLO", ALLO, ARGS, 1, "allocate storage (vacuously)" }, + { "REST", REST, ARGS, 0, "(restart command)" }, + { "RNFR", RNFR, STR1, 1, "<sp> file-name" }, + { "RNTO", RNTO, STR1, 1, "<sp> file-name" }, + { "ABOR", ABOR, ARGS, 1, "(abort operation)" }, + { "DELE", DELE, STR1, 1, "<sp> file-name" }, + { "CWD", CWD, OSTR, 1, "[ <sp> directory-name ]" }, + { "XCWD", CWD, OSTR, 1, "[ <sp> directory-name ]" }, + { "LIST", LIST, OSTR, 1, "[ <sp> path-name ]" }, + { "NLST", NLST, OSTR, 1, "[ <sp> path-name ]" }, + { "SITE", SITE, SITECMD, 1, "site-cmd [ <sp> arguments ]" }, + { "SYST", SYST, ARGS, 1, "(get type of operating system)" }, + { "STAT", STAT, OSTR, 1, "[ <sp> path-name ]" }, + { "HELP", HELP, OSTR, 1, "[ <sp> <string> ]" }, + { "NOOP", NOOP, ARGS, 1, "" }, + { "MKD", MKD, STR1, 1, "<sp> path-name" }, + { "XMKD", MKD, STR1, 1, "<sp> path-name" }, + { "RMD", RMD, STR1, 1, "<sp> path-name" }, + { "XRMD", RMD, STR1, 1, "<sp> path-name" }, + { "PWD", PWD, ARGS, 1, "(return current directory)" }, + { "XPWD", PWD, ARGS, 1, "(return current directory)" }, + { "CDUP", CDUP, ARGS, 1, "(change to parent directory)" }, + { "XCUP", CDUP, ARGS, 1, "(change to parent directory)" }, + { "STOU", STOU, STR1, 1, "<sp> file-name" }, + { "SIZE", SIZE, OSTR, 1, "<sp> path-name" }, + { "MDTM", MDTM, OSTR, 1, "<sp> path-name" }, + { 0, 0, 0, 0, 0 } +}; + +struct tab sitetab[] = { + { "UMASK", UMASK, ARGS, 1, "[ <sp> umask ]" }, + { "IDLE", IDLE, ARGS, 1, "[ <sp> maximum-idle-time ]" }, + { "CHMOD", CHMOD, NSTR, 1, "<sp> mode <sp> file-name" }, + { "HELP", HELP, OSTR, 1, "[ <sp> <string> ]" }, + { 0, 0, 0, 0, 0 } +}; + +static struct tab * +lookup(struct tab *p, char *cmd) +{ + + for (; p->name != 0; p++) + if (strcmp(cmd, p->name) == 0) + return (p); + return (0); +} + +#include <arpa/telnet.h> + +/* + * get_line - a hacked up version of fgets to ignore TELNET escape codes. + */ +static char * +get_line(char *s, int n, FILE *iop) +{ + register int c; + register char *cs; + + cs = s; +/* tmpline may contain saved command from urgent mode interruption */ + for (c = 0; tmpline[c] != '\0' && --n > 0; ++c) { + *cs++ = tmpline[c]; + if (tmpline[c] == '\n') { + *cs = '\0'; + if (debug) + syslog(LOG_DEBUG, "command: %s", s); + tmpline[0] = '\0'; + return(s); + } + if (c == 0) + tmpline[0] = '\0'; + } + while ((c = getc(iop)) != EOF) { + c &= 0377; + if (c == IAC) { + if ((c = getc(iop)) != EOF) { + c &= 0377; + switch (c) { + case WILL: + case WONT: + c = getc(iop); + printf("%c%c%c", IAC, DONT, 0377&c); + (void) fflush(stdout); + continue; + case DO: + case DONT: + c = getc(iop); + printf("%c%c%c", IAC, WONT, 0377&c); + (void) fflush(stdout); + continue; + case IAC: + break; + default: + continue; /* ignore command */ + } + } + } + *cs++ = c; + if (--n <= 0 || c == '\n') + break; + } + if (c == EOF && cs == s) + return (0); + *cs = '\0'; + if (debug) + syslog(LOG_DEBUG, "command: %s", s); + return (s); +} + +static void +toolong(int sig) +{ + time_t now; + + (void) sig; + reply(421, + "Timeout (%d seconds): closing control connection.", timeout); + (void) time(&now); + if (logging) { + syslog(LOG_INFO, + "User %s timed out after %d seconds at %s", + (pw ? pw -> pw_name : "unknown"), timeout, ctime(&now)); + } + dologout(1); +} + +int +yylex(void) +{ + static int cpos, state; + register char *cp, *cp2; + register struct tab *p; + int n; + char c; + + for (;;) { + switch (state) { + + case CMD: + (void) signal(SIGALRM, toolong); + (void) alarm((unsigned) timeout); + if (get_line(cbuf, sizeof(cbuf)-1, stdin) == 0) { + reply(221, "You could at least say goodbye."); + dologout(0); + } + (void) alarm(0); +#ifdef SETPROCTITLE + if (strncasecmp(cbuf, "PASS", 4) != 0) + setproctitle("%s: %s", proctitle, cbuf); +#endif /* SETPROCTITLE */ + if ((cp = strchr(cbuf, '\r'))) { + *cp++ = '\n'; + *cp = '\0'; + } + if ((cp = strpbrk(cbuf, " \n"))) + cpos = cp - cbuf; + if (cpos == 0) + cpos = 4; + c = cbuf[cpos]; + cbuf[cpos] = '\0'; + upper(cbuf); + p = lookup(cmdtab, cbuf); + cbuf[cpos] = c; + if (p != 0) { + if (p->implemented == 0) { + nack(p->name); + longjmp(errcatch,0); + /* NOTREACHED */ + } + state = p->state; + *(const char **)(&yylval) = p->name; + return (p->token); + } + break; + + case SITECMD: + if (cbuf[cpos] == ' ') { + cpos++; + return (SP); + } + cp = &cbuf[cpos]; + if ((cp2 = strpbrk(cp, " \n"))) + cpos = cp2 - cbuf; + c = cbuf[cpos]; + cbuf[cpos] = '\0'; + upper(cp); + p = lookup(sitetab, cp); + cbuf[cpos] = c; + if (p != 0) { + if (p->implemented == 0) { + state = CMD; + nack(p->name); + longjmp(errcatch,0); + /* NOTREACHED */ + } + state = p->state; + *(const char **)(&yylval) = p->name; + return (p->token); + } + state = CMD; + break; + + case OSTR: + if (cbuf[cpos] == '\n') { + state = CMD; + return (CRLF); + } + /* FALLTHROUGH */ + + case STR1: + case ZSTR1: + dostr1: + if (cbuf[cpos] == ' ') { + cpos++; + if (state == OSTR) + state = STR2; + else + ++state; + return (SP); + } + break; + + case ZSTR2: + if (cbuf[cpos] == '\n') { + state = CMD; + return (CRLF); + } + /* FALLTHROUGH */ + + case STR2: + cp = &cbuf[cpos]; + n = strlen(cp); + cpos += n - 1; + /* + * Make sure the string is nonempty and \n terminated. + */ + if (n > 1 && cbuf[cpos] == '\n') { + cbuf[cpos] = '\0'; + *(char **)&yylval = copy(cp); + cbuf[cpos] = '\n'; + state = ARGS; + return (STRING); + } + break; + + case NSTR: + if (cbuf[cpos] == ' ') { + cpos++; + return (SP); + } + if (isdigit(cbuf[cpos])) { + cp = &cbuf[cpos]; + while (isdigit(cbuf[++cpos])) + ; + c = cbuf[cpos]; + cbuf[cpos] = '\0'; + yylval = atoi(cp); + cbuf[cpos] = c; + state = STR1; + return (NUMBER); + } + state = STR1; + goto dostr1; + + case ARGS: + if (isdigit(cbuf[cpos])) { + cp = &cbuf[cpos]; + while (isdigit(cbuf[++cpos])) + ; + c = cbuf[cpos]; + cbuf[cpos] = '\0'; + yylval = atoi(cp); + cbuf[cpos] = c; + return (NUMBER); + } + switch (cbuf[cpos++]) { + + case '\n': + state = CMD; + return (CRLF); + + case ' ': + return (SP); + + case ',': + return (COMMA); + + case 'A': + case 'a': + return (A); + + case 'B': + case 'b': + return (B); + + case 'C': + case 'c': + return (C); + + case 'E': + case 'e': + return (E); + + case 'F': + case 'f': + return (F); + + case 'I': + case 'i': + return (I); + + case 'L': + case 'l': + return (L); + + case 'N': + case 'n': + return (N); + + case 'P': + case 'p': + return (P); + + case 'R': + case 'r': + return (R); + + case 'S': + case 's': + return (S); + + case 'T': + case 't': + return (T); + + } + break; + + default: + fatal("Unknown state in scanner."); + } + yyerror((char *) 0); + state = CMD; + longjmp(errcatch,0); + } +} + +static void +upper(char *s) +{ + while (*s != '\0') { + if (islower(*s)) + *s = toupper(*s); + s++; + } +} + +static char * +copy(const char *s) +{ + char *p; + + p = (char * )malloc(strlen(s) + 1); + if (p == 0) + fatal("Ran out of memory."); + else + (void) strcpy(p, s); + return (p); +} + +static void +help(struct tab *ctab, char *s) +{ + register struct tab *c; + register int width, NCMDS; + const char *help_type; + + if (ctab == sitetab) + help_type = "SITE "; + else + help_type = ""; + width = 0, NCMDS = 0; + for (c = ctab; c->name != 0; c++) { + int len = strlen(c->name); + + if (len > width) + width = len; + NCMDS++; + } + width = (width + 8) &~ 7; + if (s == 0) { + register int i, j, w; + int columns, lines; + + lreply(214, "The following %scommands are recognized %s.", + help_type, "(* =>'s unimplemented)"); + columns = 76 / width; + if (columns == 0) + columns = 1; + lines = (NCMDS + columns - 1) / columns; + for (i = 0; i < lines; i++) { + printf(" "); + for (j = 0; j < columns; j++) { + c = ctab + j * lines + i; + assert(c->name != 0); + printf("%s%c", c->name, + c->implemented ? ' ' : '*'); + if (c + lines >= &ctab[NCMDS]) + break; + w = strlen(c->name) + 1; + while (w < width) { + putchar(' '); + w++; + } + } + printf("\r\n"); + } + (void) fflush(stdout); + reply(214, "Direct comments to ftp-bugs@%s.", hostname); + return; + } + upper(s); + c = lookup(ctab, s); + if (c == (struct tab *)0) { + reply(502, "Unknown command %s.", s); + return; + } + if (c->implemented) + reply(214, "Syntax: %s%s %s", help_type, c->name, c->help); + else + reply(214, "%s%-*s\t%s; unimplemented.", help_type, width, + c->name, c->help); +} + +static void +sizecmd(char *filename) +{ + switch (type) { + case TYPE_L: + case TYPE_I: { + struct stat stbuf; + if (stat(filename, &stbuf) < 0 || + (stbuf.st_mode&S_IFMT) != S_IFREG) + reply(550, "%s: not a plain file.", filename); + else +#ifdef HAVE_LONG_LONG + reply(213, "%llu", (long long) stbuf.st_size); +#else + reply(213, "%lu", stbuf.st_size); +#endif + break;} + case TYPE_A: { + FILE *fin; + register int c, count; + struct stat stbuf; + fin = fopen(filename, "r"); + if (fin == 0) { + perror_reply(550, filename); + return; + } + if (fstat(fileno(fin), &stbuf) < 0 || + (stbuf.st_mode&S_IFMT) != S_IFREG) { + reply(550, "%s: not a plain file.", filename); + (void) fclose(fin); + return; + } + + count = 0; + while((c=getc(fin)) != EOF) { + if (c == '\n') /* will get expanded to \r\n */ + count++; + count++; + } + (void) fclose(fin); + + reply(213, "%ld", count); + break;} + default: + reply(504, "SIZE not implemented for Type %c.", "?AEIL"[type]); + } +} +#line 1092 "ftp.tab.c" + +#if YYDEBUG +#include <stdio.h> /* needed for printf */ +#endif + +#include <stdlib.h> /* needed for malloc, etc */ +#include <string.h> /* needed for memset */ + +/* allocate initial stack or double stack size, up to YYMAXDEPTH */ +static int yygrowstack(YYSTACKDATA *data) +{ + int i; + unsigned newsize; + short *newss; + YYSTYPE *newvs; + + if ((newsize = data->stacksize) == 0) + newsize = YYINITSTACKSIZE; + else if (newsize >= YYMAXDEPTH) + return -1; + else if ((newsize *= 2) > YYMAXDEPTH) + newsize = YYMAXDEPTH; + + i = data->s_mark - data->s_base; + newss = (short *)realloc(data->s_base, newsize * sizeof(*newss)); + if (newss == 0) + return -1; + + data->s_base = newss; + data->s_mark = newss + i; + + newvs = (YYSTYPE *)realloc(data->l_base, newsize * sizeof(*newvs)); + if (newvs == 0) + return -1; + + data->l_base = newvs; + data->l_mark = newvs + i; + + data->stacksize = newsize; + data->s_last = data->s_base + newsize - 1; + return 0; +} + +#if YYPURE || defined(YY_NO_LEAKS) +static void yyfreestack(YYSTACKDATA *data) +{ + free(data->s_base); + free(data->l_base); + memset(data, 0, sizeof(*data)); +} +#else +#define yyfreestack(data) /* nothing */ +#endif + +#define YYABORT goto yyabort +#define YYREJECT goto yyabort +#define YYACCEPT goto yyaccept +#define YYERROR goto yyerrlab + +int +YYPARSE_DECL() +{ + int yym, yyn, yystate; +#if YYDEBUG + const char *yys; + + if ((yys = getenv("YYDEBUG")) != 0) + { + yyn = *yys; + if (yyn >= '0' && yyn <= '9') + yydebug = yyn - '0'; + } +#endif + + yynerrs = 0; + yyerrflag = 0; + yychar = YYEMPTY; + yystate = 0; + +#if YYPURE + memset(&yystack, 0, sizeof(yystack)); +#endif + + if (yystack.s_base == NULL && yygrowstack(&yystack)) goto yyoverflow; + yystack.s_mark = yystack.s_base; + yystack.l_mark = yystack.l_base; + yystate = 0; + *yystack.s_mark = 0; + +yyloop: + if ((yyn = yydefred[yystate]) != 0) goto yyreduce; + if (yychar < 0) + { + if ((yychar = YYLEX) < 0) yychar = 0; +#if YYDEBUG + if (yydebug) + { + yys = 0; + if (yychar <= YYMAXTOKEN) yys = yyname[yychar]; + if (!yys) yys = "illegal-symbol"; + printf("%sdebug: state %d, reading %d (%s)\n", + YYPREFIX, yystate, yychar, yys); + } +#endif + } + if ((yyn = yysindex[yystate]) && (yyn += yychar) >= 0 && + yyn <= YYTABLESIZE && yycheck[yyn] == yychar) + { +#if YYDEBUG + if (yydebug) + printf("%sdebug: state %d, shifting to state %d\n", + YYPREFIX, yystate, yytable[yyn]); +#endif + if (yystack.s_mark >= yystack.s_last && yygrowstack(&yystack)) + { + goto yyoverflow; + } + yystate = yytable[yyn]; + *++yystack.s_mark = yytable[yyn]; + *++yystack.l_mark = yylval; + yychar = YYEMPTY; + if (yyerrflag > 0) --yyerrflag; + goto yyloop; + } + if ((yyn = yyrindex[yystate]) && (yyn += yychar) >= 0 && + yyn <= YYTABLESIZE && yycheck[yyn] == yychar) + { + yyn = yytable[yyn]; + goto yyreduce; + } + if (yyerrflag) goto yyinrecovery; + + yyerror("syntax error"); + + goto yyerrlab; + +yyerrlab: + ++yynerrs; + +yyinrecovery: + if (yyerrflag < 3) + { + yyerrflag = 3; + for (;;) + { + if ((yyn = yysindex[*yystack.s_mark]) && (yyn += YYERRCODE) >= 0 && + yyn <= YYTABLESIZE && yycheck[yyn] == YYERRCODE) + { +#if YYDEBUG + if (yydebug) + printf("%sdebug: state %d, error recovery shifting\ + to state %d\n", YYPREFIX, *yystack.s_mark, yytable[yyn]); +#endif + if (yystack.s_mark >= yystack.s_last && yygrowstack(&yystack)) + { + goto yyoverflow; + } + yystate = yytable[yyn]; + *++yystack.s_mark = yytable[yyn]; + *++yystack.l_mark = yylval; + goto yyloop; + } + else + { +#if YYDEBUG + if (yydebug) + printf("%sdebug: error recovery discarding state %d\n", + YYPREFIX, *yystack.s_mark); +#endif + if (yystack.s_mark <= yystack.s_base) goto yyabort; + --yystack.s_mark; + --yystack.l_mark; + } + } + } + else + { + if (yychar == 0) goto yyabort; +#if YYDEBUG + if (yydebug) + { + yys = 0; + if (yychar <= YYMAXTOKEN) yys = yyname[yychar]; + if (!yys) yys = "illegal-symbol"; + printf("%sdebug: state %d, error recovery discards token %d (%s)\n", + YYPREFIX, yystate, yychar, yys); + } +#endif + yychar = YYEMPTY; + goto yyloop; + } + +yyreduce: +#if YYDEBUG + if (yydebug) + printf("%sdebug: state %d, reducing by rule %d (%s)\n", + YYPREFIX, yystate, yyn, yyrule[yyn]); +#endif + yym = yylen[yyn]; + if (yym) + yyval = yystack.l_mark[1-yym]; + else + memset(&yyval, 0, sizeof yyval); + switch (yyn) + { +case 2: +#line 150 "ftp.y" + { + fromname = (char *) 0; + } +break; +case 4: +#line 157 "ftp.y" + { + user((char *) yystack.l_mark[-1]); + free((char *) yystack.l_mark[-1]); + } +break; +case 5: +#line 162 "ftp.y" + { + pass((char *) yystack.l_mark[-1]); + free((char *) yystack.l_mark[-1]); + } +break; +case 6: +#line 167 "ftp.y" + { + usedefault = 0; + if (pdata >= 0) { + (void) close(pdata); + pdata = -1; + } + reply(200, "PORT command successful."); + } +break; +case 7: +#line 176 "ftp.y" + { + passive(); + } +break; +case 8: +#line 180 "ftp.y" + { + switch (cmd_type) { + + case TYPE_A: + if (cmd_form == FORM_N) { + reply(200, "Type set to A."); + type = cmd_type; + form = cmd_form; + } else + reply(504, "Form must be N."); + break; + + case TYPE_E: + reply(504, "Type E not implemented."); + break; + + case TYPE_I: + reply(200, "Type set to I."); + type = cmd_type; + break; + + case TYPE_L: +#if NBBY == 8 + if (cmd_bytesz == 8) { + reply(200, + "Type set to L (byte size 8)."); + type = cmd_type; + } else + reply(504, "Byte size must be 8."); +#else /* NBBY == 8 */ + UNIMPLEMENTED for NBBY != 8 +#endif /* NBBY == 8 */ + } + } +break; +case 9: +#line 215 "ftp.y" + { + switch (yystack.l_mark[-1]) { + + case STRU_F: + reply(200, "STRU F ok."); + break; + + default: + reply(504, "Unimplemented STRU type."); + } + } +break; +case 10: +#line 227 "ftp.y" + { + switch (yystack.l_mark[-1]) { + + case MODE_S: + reply(200, "MODE S ok."); + break; + + default: + reply(502, "Unimplemented MODE type."); + } + } +break; +case 11: +#line 239 "ftp.y" + { + reply(202, "ALLO command ignored."); + } +break; +case 12: +#line 243 "ftp.y" + { + reply(202, "ALLO command ignored."); + } +break; +case 13: +#line 247 "ftp.y" + { + if (yystack.l_mark[-3] && yystack.l_mark[-1] != 0) + retrieve((char *) 0, (char *) yystack.l_mark[-1]); + if (yystack.l_mark[-1] != 0) + free((char *) yystack.l_mark[-1]); + } +break; +case 14: +#line 254 "ftp.y" + { + if (yystack.l_mark[-3] && yystack.l_mark[-1] != 0) + store((char *) yystack.l_mark[-1], "w", 0); + if (yystack.l_mark[-1] != 0) + free((char *) yystack.l_mark[-1]); + } +break; +case 15: +#line 261 "ftp.y" + { + if (yystack.l_mark[-3] && yystack.l_mark[-1] != 0) + store((char *) yystack.l_mark[-1], "a", 0); + if (yystack.l_mark[-1] != 0) + free((char *) yystack.l_mark[-1]); + } +break; +case 16: +#line 268 "ftp.y" + { + if (yystack.l_mark[-1]) + send_file_list("."); + } +break; +case 17: +#line 273 "ftp.y" + { + if (yystack.l_mark[-3] && yystack.l_mark[-1] != 0) + send_file_list((char *) yystack.l_mark[-1]); + if (yystack.l_mark[-1] != 0) + free((char *) yystack.l_mark[-1]); + } +break; +case 18: +#line 280 "ftp.y" + { + if (yystack.l_mark[-1]) + retrieve("/bin/ls -lgA", ""); + } +break; +case 19: +#line 285 "ftp.y" + { + if (yystack.l_mark[-3] && yystack.l_mark[-1] != 0) + retrieve("/bin/ls -lgA %s", (char *) yystack.l_mark[-1]); + if (yystack.l_mark[-1] != 0) + free((char *) yystack.l_mark[-1]); + } +break; +case 20: +#line 292 "ftp.y" + { + if (yystack.l_mark[-3] && yystack.l_mark[-1] != 0) + statfilecmd((char *) yystack.l_mark[-1]); + if (yystack.l_mark[-1] != 0) + free((char *) yystack.l_mark[-1]); + } +break; +case 21: +#line 299 "ftp.y" + { + statcmd(); + } +break; +case 22: +#line 303 "ftp.y" + { + if (yystack.l_mark[-3] && yystack.l_mark[-1] != 0) + remove((char *) yystack.l_mark[-1]); + if (yystack.l_mark[-1] != 0) + free((char *) yystack.l_mark[-1]); + } +break; +case 23: +#line 310 "ftp.y" + { + if (fromname) { + renamecmd(fromname, (char *) yystack.l_mark[-1]); + free(fromname); + fromname = (char *) 0; + } else { + reply(503, "Bad sequence of commands."); + } + free((char *) yystack.l_mark[-1]); + } +break; +case 24: +#line 321 "ftp.y" + { + reply(225, "ABOR command successful."); + } +break; +case 25: +#line 325 "ftp.y" + { + if (yystack.l_mark[-1]) + cwd(pw->pw_dir); + } +break; +case 26: +#line 330 "ftp.y" + { + if (yystack.l_mark[-3] && yystack.l_mark[-1] != 0) + cwd((char *) yystack.l_mark[-1]); + if (yystack.l_mark[-1] != 0) + free((char *) yystack.l_mark[-1]); + } +break; +case 27: +#line 337 "ftp.y" + { + help(cmdtab, (char *) 0); + } +break; +case 28: +#line 341 "ftp.y" + { + register char *cp = (char *)yystack.l_mark[-1]; + + if (strncasecmp(cp, "SITE", 4) == 0) { + cp = (char *)yystack.l_mark[-1] + 4; + if (*cp == ' ') + cp++; + if (*cp) + help(sitetab, cp); + else + help(sitetab, (char *) 0); + } else + help(cmdtab, (char *) yystack.l_mark[-1]); + } +break; +case 29: +#line 356 "ftp.y" + { + reply(200, "NOOP command successful."); + } +break; +case 30: +#line 360 "ftp.y" + { + if (yystack.l_mark[-3] && yystack.l_mark[-1] != 0) + makedir((char *) yystack.l_mark[-1]); + if (yystack.l_mark[-1] != 0) + free((char *) yystack.l_mark[-1]); + } +break; +case 31: +#line 367 "ftp.y" + { + if (yystack.l_mark[-3] && yystack.l_mark[-1] != 0) + removedir((char *) yystack.l_mark[-1]); + if (yystack.l_mark[-1] != 0) + free((char *) yystack.l_mark[-1]); + } +break; +case 32: +#line 374 "ftp.y" + { + if (yystack.l_mark[-1]) + pwd(); + } +break; +case 33: +#line 379 "ftp.y" + { + if (yystack.l_mark[-1]) + cwd(".."); + } +break; +case 34: +#line 384 "ftp.y" + { + help(sitetab, (char *) 0); + } +break; +case 35: +#line 388 "ftp.y" + { + help(sitetab, (char *) yystack.l_mark[-1]); + } +break; +case 36: +#line 392 "ftp.y" + { + int oldmask; + + if (yystack.l_mark[-1]) { + oldmask = umask(0); + (void) umask(oldmask); + reply(200, "Current UMASK is %03o", oldmask); + } + } +break; +case 37: +#line 402 "ftp.y" + { + int oldmask; + + if (yystack.l_mark[-3]) { + if ((yystack.l_mark[-1] == -1) || (yystack.l_mark[-1] > 0777)) { + reply(501, "Bad UMASK value"); + } else { + oldmask = umask(yystack.l_mark[-1]); + reply(200, + "UMASK set to %03o (was %03o)", + yystack.l_mark[-1], oldmask); + } + } + } +break; +case 38: +#line 417 "ftp.y" + { + if (yystack.l_mark[-5] && (yystack.l_mark[-1] != 0)) { + if (yystack.l_mark[-3] > 0777) + reply(501, + "CHMOD: Mode value must be between 0 and 0777"); + else if (chmod((char *) yystack.l_mark[-1], yystack.l_mark[-3]) < 0) + perror_reply(550, (char *) yystack.l_mark[-1]); + else + reply(200, "CHMOD command successful."); + } + if (yystack.l_mark[-1] != 0) + free((char *) yystack.l_mark[-1]); + } +break; +case 39: +#line 431 "ftp.y" + { + reply(200, + "Current IDLE time limit is %d seconds; max %d", + timeout, maxtimeout); + } +break; +case 40: +#line 437 "ftp.y" + { + if (yystack.l_mark[-1] < 30 || yystack.l_mark[-1] > maxtimeout) { + reply(501, + "Maximum IDLE time must be between 30 and %d seconds", + maxtimeout); + } else { + timeout = yystack.l_mark[-1]; + (void) alarm((unsigned) timeout); + reply(200, + "Maximum IDLE time set to %d seconds", + timeout); + } + } +break; +case 41: +#line 451 "ftp.y" + { + if (yystack.l_mark[-3] && yystack.l_mark[-1] != 0) + store((char *) yystack.l_mark[-1], "w", 1); + if (yystack.l_mark[-1] != 0) + free((char *) yystack.l_mark[-1]); + } +break; +case 42: +#line 458 "ftp.y" + { +#ifdef unix +#ifdef BSD + reply(215, "UNIX Type: L%d Version: BSD-%d", + NBBY, BSD); +#else /* BSD */ + reply(215, "UNIX Type: L%d", NBBY); +#endif /* BSD */ +#else /* unix */ + reply(215, "UNKNOWN Type: L%d", NBBY); +#endif /* unix */ + } +break; +case 43: +#line 479 "ftp.y" + { + if (yystack.l_mark[-3] && yystack.l_mark[-1] != 0) + sizecmd((char *) yystack.l_mark[-1]); + if (yystack.l_mark[-1] != 0) + free((char *) yystack.l_mark[-1]); + } +break; +case 44: +#line 496 "ftp.y" + { + if (yystack.l_mark[-3] && yystack.l_mark[-1] != 0) { + struct stat stbuf; + if (stat((char *) yystack.l_mark[-1], &stbuf) < 0) + perror_reply(550, "%s", (char *) yystack.l_mark[-1]); + else if ((stbuf.st_mode&S_IFMT) != S_IFREG) { + reply(550, "%s: not a plain file.", + (char *) yystack.l_mark[-1]); + } else { + register struct tm *t; + t = gmtime(&stbuf.st_mtime); + reply(213, + "%04d%02d%02d%02d%02d%02d", + 1900 + t->tm_year, + t->tm_mon+1, t->tm_mday, + t->tm_hour, t->tm_min, t->tm_sec); + } + } + if (yystack.l_mark[-1] != 0) + free((char *) yystack.l_mark[-1]); + } +break; +case 45: +#line 518 "ftp.y" + { + reply(221, "Goodbye."); + dologout(0); + } +break; +case 46: +#line 523 "ftp.y" + { + yyerrok; + } +break; +case 47: +#line 528 "ftp.y" + { + if (yystack.l_mark[-3] && yystack.l_mark[-1]) { + fromname = renamefrom((char *) yystack.l_mark[-1]); + if (fromname == (char *) 0 && yystack.l_mark[-1]) { + free((char *) yystack.l_mark[-1]); + } + } + } +break; +case 49: +#line 542 "ftp.y" + { + *(const char **)(&(yyval)) = ""; + } +break; +case 52: +#line 553 "ftp.y" + { + register char *a, *p; + + a = (char *)&data_dest.sin_addr; + a[0] = yystack.l_mark[-10]; a[1] = yystack.l_mark[-8]; a[2] = yystack.l_mark[-6]; a[3] = yystack.l_mark[-4]; + p = (char *)&data_dest.sin_port; + p[0] = yystack.l_mark[-2]; p[1] = yystack.l_mark[0]; + data_dest.sin_family = AF_INET; + } +break; +case 53: +#line 565 "ftp.y" + { + yyval = FORM_N; + } +break; +case 54: +#line 569 "ftp.y" + { + yyval = FORM_T; + } +break; +case 55: +#line 573 "ftp.y" + { + yyval = FORM_C; + } +break; +case 56: +#line 579 "ftp.y" + { + cmd_type = TYPE_A; + cmd_form = FORM_N; + } +break; +case 57: +#line 584 "ftp.y" + { + cmd_type = TYPE_A; + cmd_form = yystack.l_mark[0]; + } +break; +case 58: +#line 589 "ftp.y" + { + cmd_type = TYPE_E; + cmd_form = FORM_N; + } +break; +case 59: +#line 594 "ftp.y" + { + cmd_type = TYPE_E; + cmd_form = yystack.l_mark[0]; + } +break; +case 60: +#line 599 "ftp.y" + { + cmd_type = TYPE_I; + } +break; +case 61: +#line 603 "ftp.y" + { + cmd_type = TYPE_L; + cmd_bytesz = NBBY; + } +break; +case 62: +#line 608 "ftp.y" + { + cmd_type = TYPE_L; + cmd_bytesz = yystack.l_mark[0]; + } +break; +case 63: +#line 614 "ftp.y" + { + cmd_type = TYPE_L; + cmd_bytesz = yystack.l_mark[0]; + } +break; +case 64: +#line 621 "ftp.y" + { + yyval = STRU_F; + } +break; +case 65: +#line 625 "ftp.y" + { + yyval = STRU_R; + } +break; +case 66: +#line 629 "ftp.y" + { + yyval = STRU_P; + } +break; +case 67: +#line 635 "ftp.y" + { + yyval = MODE_S; + } +break; +case 68: +#line 639 "ftp.y" + { + yyval = MODE_B; + } +break; +case 69: +#line 643 "ftp.y" + { + yyval = MODE_C; + } +break; +case 70: +#line 649 "ftp.y" + { + /* + * Problem: this production is used for all pathname + * processing, but only gives a 550 error reply. + * This is a valid reply in some cases but not in others. + */ + if (logged_in && yystack.l_mark[0] && strncmp((char *) yystack.l_mark[0], "~", 1) == 0) { + *(char **)&(yyval) = *glob((char *) yystack.l_mark[0]); + if (globerr != 0) { + reply(550, globerr); + yyval = 0; + } + free((char *) yystack.l_mark[0]); + } else + yyval = yystack.l_mark[0]; + } +break; +case 72: +#line 671 "ftp.y" + { + register int ret, dec, multby, digit; + + /* + * Convert a number that was read as decimal number + * to what it would be if it had been read as octal. + */ + dec = yystack.l_mark[0]; + multby = 1; + ret = 0; + while (dec) { + digit = dec%10; + if (digit > 7) { + ret = -1; + break; + } + ret += digit * multby; + multby *= 8; + dec /= 10; + } + yyval = ret; + } +break; +case 73: +#line 696 "ftp.y" + { + if (logged_in) + yyval = 1; + else { + reply(530, "Please login with USER and PASS."); + yyval = 0; + } + } +break; +#line 1935 "ftp.tab.c" + } + yystack.s_mark -= yym; + yystate = *yystack.s_mark; + yystack.l_mark -= yym; + yym = yylhs[yyn]; + if (yystate == 0 && yym == 0) + { +#if YYDEBUG + if (yydebug) + printf("%sdebug: after reduction, shifting from state 0 to\ + state %d\n", YYPREFIX, YYFINAL); +#endif + yystate = YYFINAL; + *++yystack.s_mark = YYFINAL; + *++yystack.l_mark = yyval; + if (yychar < 0) + { + if ((yychar = YYLEX) < 0) yychar = 0; +#if YYDEBUG + if (yydebug) + { + yys = 0; + if (yychar <= YYMAXTOKEN) yys = yyname[yychar]; + if (!yys) yys = "illegal-symbol"; + printf("%sdebug: state %d, reading %d (%s)\n", + YYPREFIX, YYFINAL, yychar, yys); + } +#endif + } + if (yychar == 0) goto yyaccept; + goto yyloop; + } + if ((yyn = yygindex[yym]) && (yyn += yystate) >= 0 && + yyn <= YYTABLESIZE && yycheck[yyn] == yystate) + yystate = yytable[yyn]; + else + yystate = yydgoto[yym]; +#if YYDEBUG + if (yydebug) + printf("%sdebug: after reduction, shifting from state %d \ +to state %d\n", YYPREFIX, *yystack.s_mark, yystate); +#endif + if (yystack.s_mark >= yystack.s_last && yygrowstack(&yystack)) + { + goto yyoverflow; + } + *++yystack.s_mark = (short) yystate; + *++yystack.l_mark = yyval; + goto yyloop; + +yyoverflow: + yyerror("yacc stack overflow"); + +yyabort: + yyfreestack(&yystack); + return (1); + +yyaccept: + yyfreestack(&yystack); + return (0); +} diff --git a/test/ftp.tab.h b/test/ftp.tab.h new file mode 100644 index 000000000000..24f0791390a9 --- /dev/null +++ b/test/ftp.tab.h @@ -0,0 +1,63 @@ +#define A 257 +#define B 258 +#define C 259 +#define E 260 +#define F 261 +#define I 262 +#define L 263 +#define N 264 +#define P 265 +#define R 266 +#define S 267 +#define T 268 +#define SP 269 +#define CRLF 270 +#define COMMA 271 +#define STRING 272 +#define NUMBER 273 +#define USER 274 +#define PASS 275 +#define ACCT 276 +#define REIN 277 +#define QUIT 278 +#define PORT 279 +#define PASV 280 +#define TYPE 281 +#define STRU 282 +#define MODE 283 +#define RETR 284 +#define STOR 285 +#define APPE 286 +#define MLFL 287 +#define MAIL 288 +#define MSND 289 +#define MSOM 290 +#define MSAM 291 +#define MRSQ 292 +#define MRCP 293 +#define ALLO 294 +#define REST 295 +#define RNFR 296 +#define RNTO 297 +#define ABOR 298 +#define DELE 299 +#define CWD 300 +#define LIST 301 +#define NLST 302 +#define SITE 303 +#define STAT 304 +#define HELP 305 +#define NOOP 306 +#define MKD 307 +#define RMD 308 +#define PWD 309 +#define CDUP 310 +#define STOU 311 +#define SMNT 312 +#define SYST 313 +#define SIZE 314 +#define MDTM 315 +#define UMASK 316 +#define IDLE 317 +#define CHMOD 318 +#define LEXERR 319 diff --git a/test/ftp.y b/test/ftp.y new file mode 100644 index 000000000000..42c210bf4ef6 --- /dev/null +++ b/test/ftp.y @@ -0,0 +1,1228 @@ +/* + * Copyright (c) 1985, 1988 Regents of the University of California. + * All rights reserved. + * + * Redistribution and use in source and binary forms are permitted + * provided that the above copyright notice and this paragraph are + * duplicated in all such forms and that any documentation, + * advertising materials, and other materials related to such + * distribution and use acknowledge that the software was developed + * by the University of California, Berkeley. The name of the + * University may not be used to endorse or promote products derived + * from this software without specific prior written permission. + * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. + * + * @(#)ftpcmd.y 5.20.1.1 (Berkeley) 3/2/89 + */ + +/* + * Grammar for FTP commands. + * See RFC 959. + */ + +%{ + +/* sccsid[] = "@(#)ftpcmd.y 5.20.1.1 (Berkeley) 3/2/89"; */ + +#include <sys/param.h> +#include <sys/socket.h> + +#include <netinet/in.h> + +#include <arpa/ftp.h> + +#include <stdlib.h> +#include <unistd.h> +#include <stdio.h> +#include <signal.h> +#include <ctype.h> +#include <pwd.h> +#include <setjmp.h> +#include <syslog.h> +#include <sys/stat.h> +#include <string.h> +#include <time.h> +#include <assert.h> + +#ifdef YYBISON +int yylex(void); +static void yyerror(const char *); +#endif + +extern struct sockaddr_in data_dest; +extern int logged_in; +extern struct passwd *pw; +extern int guest; +extern int logging; +extern int type; +extern int form; +extern int debug; +extern int timeout; +extern int maxtimeout; +extern int pdata; +extern char hostname[], remotehost[]; +extern char proctitle[]; +extern char *globerr; +extern int usedefault; +extern int transflag; +extern char tmpline[]; + +extern char **glob(char *); +extern char *renamefrom(char *); +extern void cwd(const char *); + +extern void dologout(int); +extern void fatal(const char *); +extern void makedir(const char *); +extern void nack(const char *); +extern void pass(const char *); +extern void passive(void); +extern void pwd(void); +extern void removedir(char *); +extern void renamecmd(char *, char *); +extern void retrieve(const char *, const char *); +extern void send_file_list(const char *); +extern void statcmd(void); +extern void statfilecmd(const char *); +extern void store(char *, const char *, int); +extern void user(const char *); + +extern void perror_reply(int, const char *, ...); +extern void reply(int, const char *, ...); +extern void lreply(int, const char *, ...); + +static int cmd_type; +static int cmd_form; +static int cmd_bytesz; +char cbuf[512]; +char *fromname; + +struct tab { + const char *name; + short token; + short state; + short implemented; /* 1 if command is implemented */ + const char *help; +}; + +static char * copy(const char *); + +#ifdef YYBISON +static void sizecmd(char *filename); +static void help(struct tab *ctab, char *s); +struct tab cmdtab[]; +struct tab sitetab[]; +#endif + +static void +yyerror(const char *msg) +{ + perror(msg); +} +%} + +%token + A B C E F I + L N P R S T + + SP CRLF COMMA STRING NUMBER + + USER PASS ACCT REIN QUIT PORT + PASV TYPE STRU MODE RETR STOR + APPE MLFL MAIL MSND MSOM MSAM + MRSQ MRCP ALLO REST RNFR RNTO + ABOR DELE CWD LIST NLST SITE + STAT HELP NOOP MKD RMD PWD + CDUP STOU SMNT SYST SIZE MDTM + + UMASK IDLE CHMOD + + LEXERR + +%start cmd_list + +%% + +cmd_list: /* empty */ + | cmd_list cmd + { + fromname = (char *) 0; + } + | cmd_list rcmd + ; + +cmd: USER SP username CRLF + { + user((char *) $3); + free((char *) $3); + } + | PASS SP password CRLF + { + pass((char *) $3); + free((char *) $3); + } + | PORT SP host_port CRLF + { + usedefault = 0; + if (pdata >= 0) { + (void) close(pdata); + pdata = -1; + } + reply(200, "PORT command successful."); + } + | PASV CRLF + { + passive(); + } + | TYPE SP type_code CRLF + { + switch (cmd_type) { + + case TYPE_A: + if (cmd_form == FORM_N) { + reply(200, "Type set to A."); + type = cmd_type; + form = cmd_form; + } else + reply(504, "Form must be N."); + break; + + case TYPE_E: + reply(504, "Type E not implemented."); + break; + + case TYPE_I: + reply(200, "Type set to I."); + type = cmd_type; + break; + + case TYPE_L: +#if NBBY == 8 + if (cmd_bytesz == 8) { + reply(200, + "Type set to L (byte size 8)."); + type = cmd_type; + } else + reply(504, "Byte size must be 8."); +#else /* NBBY == 8 */ + UNIMPLEMENTED for NBBY != 8 +#endif /* NBBY == 8 */ + } + } + | STRU SP struct_code CRLF + { + switch ($3) { + + case STRU_F: + reply(200, "STRU F ok."); + break; + + default: + reply(504, "Unimplemented STRU type."); + } + } + | MODE SP mode_code CRLF + { + switch ($3) { + + case MODE_S: + reply(200, "MODE S ok."); + break; + + default: + reply(502, "Unimplemented MODE type."); + } + } + | ALLO SP NUMBER CRLF + { + reply(202, "ALLO command ignored."); + } + | ALLO SP NUMBER SP R SP NUMBER CRLF + { + reply(202, "ALLO command ignored."); + } + | RETR check_login SP pathname CRLF + { + if ($2 && $4 != 0) + retrieve((char *) 0, (char *) $4); + if ($4 != 0) + free((char *) $4); + } + | STOR check_login SP pathname CRLF + { + if ($2 && $4 != 0) + store((char *) $4, "w", 0); + if ($4 != 0) + free((char *) $4); + } + | APPE check_login SP pathname CRLF + { + if ($2 && $4 != 0) + store((char *) $4, "a", 0); + if ($4 != 0) + free((char *) $4); + } + | NLST check_login CRLF + { + if ($2) + send_file_list("."); + } + | NLST check_login SP STRING CRLF + { + if ($2 && $4 != 0) + send_file_list((char *) $4); + if ($4 != 0) + free((char *) $4); + } + | LIST check_login CRLF + { + if ($2) + retrieve("/bin/ls -lgA", ""); + } + | LIST check_login SP pathname CRLF + { + if ($2 && $4 != 0) + retrieve("/bin/ls -lgA %s", (char *) $4); + if ($4 != 0) + free((char *) $4); + } + | STAT check_login SP pathname CRLF + { + if ($2 && $4 != 0) + statfilecmd((char *) $4); + if ($4 != 0) + free((char *) $4); + } + | STAT CRLF + { + statcmd(); + } + | DELE check_login SP pathname CRLF + { + if ($2 && $4 != 0) + remove((char *) $4); + if ($4 != 0) + free((char *) $4); + } + | RNTO SP pathname CRLF + { + if (fromname) { + renamecmd(fromname, (char *) $3); + free(fromname); + fromname = (char *) 0; + } else { + reply(503, "Bad sequence of commands."); + } + free((char *) $3); + } + | ABOR CRLF + { + reply(225, "ABOR command successful."); + } + | CWD check_login CRLF + { + if ($2) + cwd(pw->pw_dir); + } + | CWD check_login SP pathname CRLF + { + if ($2 && $4 != 0) + cwd((char *) $4); + if ($4 != 0) + free((char *) $4); + } + | HELP CRLF + { + help(cmdtab, (char *) 0); + } + | HELP SP STRING CRLF + { + register char *cp = (char *)$3; + + if (strncasecmp(cp, "SITE", 4) == 0) { + cp = (char *)$3 + 4; + if (*cp == ' ') + cp++; + if (*cp) + help(sitetab, cp); + else + help(sitetab, (char *) 0); + } else + help(cmdtab, (char *) $3); + } + | NOOP CRLF + { + reply(200, "NOOP command successful."); + } + | MKD check_login SP pathname CRLF + { + if ($2 && $4 != 0) + makedir((char *) $4); + if ($4 != 0) + free((char *) $4); + } + | RMD check_login SP pathname CRLF + { + if ($2 && $4 != 0) + removedir((char *) $4); + if ($4 != 0) + free((char *) $4); + } + | PWD check_login CRLF + { + if ($2) + pwd(); + } + | CDUP check_login CRLF + { + if ($2) + cwd(".."); + } + | SITE SP HELP CRLF + { + help(sitetab, (char *) 0); + } + | SITE SP HELP SP STRING CRLF + { + help(sitetab, (char *) $5); + } + | SITE SP UMASK check_login CRLF + { + int oldmask; + + if ($4) { + oldmask = umask(0); + (void) umask(oldmask); + reply(200, "Current UMASK is %03o", oldmask); + } + } + | SITE SP UMASK check_login SP octal_number CRLF + { + int oldmask; + + if ($4) { + if (($6 == -1) || ($6 > 0777)) { + reply(501, "Bad UMASK value"); + } else { + oldmask = umask($6); + reply(200, + "UMASK set to %03o (was %03o)", + $6, oldmask); + } + } + } + | SITE SP CHMOD check_login SP octal_number SP pathname CRLF + { + if ($4 && ($8 != 0)) { + if ($6 > 0777) + reply(501, + "CHMOD: Mode value must be between 0 and 0777"); + else if (chmod((char *) $8, $6) < 0) + perror_reply(550, (char *) $8); + else + reply(200, "CHMOD command successful."); + } + if ($8 != 0) + free((char *) $8); + } + | SITE SP IDLE CRLF + { + reply(200, + "Current IDLE time limit is %d seconds; max %d", + timeout, maxtimeout); + } + | SITE SP IDLE SP NUMBER CRLF + { + if ($5 < 30 || $5 > maxtimeout) { + reply(501, + "Maximum IDLE time must be between 30 and %d seconds", + maxtimeout); + } else { + timeout = $5; + (void) alarm((unsigned) timeout); + reply(200, + "Maximum IDLE time set to %d seconds", + timeout); + } + } + | STOU check_login SP pathname CRLF + { + if ($2 && $4 != 0) + store((char *) $4, "w", 1); + if ($4 != 0) + free((char *) $4); + } + | SYST CRLF + { +#ifdef unix +#ifdef BSD + reply(215, "UNIX Type: L%d Version: BSD-%d", + NBBY, BSD); +#else /* BSD */ + reply(215, "UNIX Type: L%d", NBBY); +#endif /* BSD */ +#else /* unix */ + reply(215, "UNKNOWN Type: L%d", NBBY); +#endif /* unix */ + } + + /* + * SIZE is not in RFC959, but Postel has blessed it and + * it will be in the updated RFC. + * + * Return size of file in a format suitable for + * using with RESTART (we just count bytes). + */ + | SIZE check_login SP pathname CRLF + { + if ($2 && $4 != 0) + sizecmd((char *) $4); + if ($4 != 0) + free((char *) $4); + } + + /* + * MDTM is not in RFC959, but Postel has blessed it and + * it will be in the updated RFC. + * + * Return modification time of file as an ISO 3307 + * style time. E.g. YYYYMMDDHHMMSS or YYYYMMDDHHMMSS.xxx + * where xxx is the fractional second (of any precision, + * not necessarily 3 digits) + */ + | MDTM check_login SP pathname CRLF + { + if ($2 && $4 != 0) { + struct stat stbuf; + if (stat((char *) $4, &stbuf) < 0) + perror_reply(550, "%s", (char *) $4); + else if ((stbuf.st_mode&S_IFMT) != S_IFREG) { + reply(550, "%s: not a plain file.", + (char *) $4); + } else { + register struct tm *t; + t = gmtime(&stbuf.st_mtime); + reply(213, + "%04d%02d%02d%02d%02d%02d", + 1900 + t->tm_year, + t->tm_mon+1, t->tm_mday, + t->tm_hour, t->tm_min, t->tm_sec); + } + } + if ($4 != 0) + free((char *) $4); + } + | QUIT CRLF + { + reply(221, "Goodbye."); + dologout(0); + } + | error CRLF + { + yyerrok; + } + ; +rcmd: RNFR check_login SP pathname CRLF + { + if ($2 && $4) { + fromname = renamefrom((char *) $4); + if (fromname == (char *) 0 && $4) { + free((char *) $4); + } + } + } + ; + +username: STRING + ; + +password: /* empty */ + { + *(const char **)(&($$)) = ""; + } + | STRING + ; + +byte_size: NUMBER + ; + +host_port: NUMBER COMMA NUMBER COMMA NUMBER COMMA NUMBER COMMA + NUMBER COMMA NUMBER + { + register char *a, *p; + + a = (char *)&data_dest.sin_addr; + a[0] = $1; a[1] = $3; a[2] = $5; a[3] = $7; + p = (char *)&data_dest.sin_port; + p[0] = $9; p[1] = $11; + data_dest.sin_family = AF_INET; + } + ; + +form_code: N + { + $$ = FORM_N; + } + | T + { + $$ = FORM_T; + } + | C + { + $$ = FORM_C; + } + ; + +type_code: A + { + cmd_type = TYPE_A; + cmd_form = FORM_N; + } + | A SP form_code + { + cmd_type = TYPE_A; + cmd_form = $3; + } + | E + { + cmd_type = TYPE_E; + cmd_form = FORM_N; + } + | E SP form_code + { + cmd_type = TYPE_E; + cmd_form = $3; + } + | I + { + cmd_type = TYPE_I; + } + | L + { + cmd_type = TYPE_L; + cmd_bytesz = NBBY; + } + | L SP byte_size + { + cmd_type = TYPE_L; + cmd_bytesz = $3; + } + /* this is for a bug in the BBN ftp */ + | L byte_size + { + cmd_type = TYPE_L; + cmd_bytesz = $2; + } + ; + +struct_code: F + { + $$ = STRU_F; + } + | R + { + $$ = STRU_R; + } + | P + { + $$ = STRU_P; + } + ; + +mode_code: S + { + $$ = MODE_S; + } + | B + { + $$ = MODE_B; + } + | C + { + $$ = MODE_C; + } + ; + +pathname: pathstring + { + /* + * Problem: this production is used for all pathname + * processing, but only gives a 550 error reply. + * This is a valid reply in some cases but not in others. + */ + if (logged_in && $1 && strncmp((char *) $1, "~", 1) == 0) { + *(char **)&($$) = *glob((char *) $1); + if (globerr != 0) { + reply(550, globerr); + $$ = 0; + } + free((char *) $1); + } else + $$ = $1; + } + ; + +pathstring: STRING + ; + +octal_number: NUMBER + { + register int ret, dec, multby, digit; + + /* + * Convert a number that was read as decimal number + * to what it would be if it had been read as octal. + */ + dec = $1; + multby = 1; + ret = 0; + while (dec) { + digit = dec%10; + if (digit > 7) { + ret = -1; + break; + } + ret += digit * multby; + multby *= 8; + dec /= 10; + } + $$ = ret; + } + ; + +check_login: /* empty */ + { + if (logged_in) + $$ = 1; + else { + reply(530, "Please login with USER and PASS."); + $$ = 0; + } + } + ; + +%% + +#ifdef YYBYACC +extern int YYLEX_DECL(); +#endif + +extern jmp_buf errcatch; + +static void upper(char *); + +#define CMD 0 /* beginning of command */ +#define ARGS 1 /* expect miscellaneous arguments */ +#define STR1 2 /* expect SP followed by STRING */ +#define STR2 3 /* expect STRING */ +#define OSTR 4 /* optional SP then STRING */ +#define ZSTR1 5 /* SP then optional STRING */ +#define ZSTR2 6 /* optional STRING after SP */ +#define SITECMD 7 /* SITE command */ +#define NSTR 8 /* Number followed by a string */ + +struct tab cmdtab[] = { /* In order defined in RFC 765 */ + { "USER", USER, STR1, 1, "<sp> username" }, + { "PASS", PASS, ZSTR1, 1, "<sp> password" }, + { "ACCT", ACCT, STR1, 0, "(specify account)" }, + { "SMNT", SMNT, ARGS, 0, "(structure mount)" }, + { "REIN", REIN, ARGS, 0, "(reinitialize server state)" }, + { "QUIT", QUIT, ARGS, 1, "(terminate service)", }, + { "PORT", PORT, ARGS, 1, "<sp> b0, b1, b2, b3, b4" }, + { "PASV", PASV, ARGS, 1, "(set server in passive mode)" }, + { "TYPE", TYPE, ARGS, 1, "<sp> [ A | E | I | L ]" }, + { "STRU", STRU, ARGS, 1, "(specify file structure)" }, + { "MODE", MODE, ARGS, 1, "(specify transfer mode)" }, + { "RETR", RETR, STR1, 1, "<sp> file-name" }, + { "STOR", STOR, STR1, 1, "<sp> file-name" }, + { "APPE", APPE, STR1, 1, "<sp> file-name" }, + { "MLFL", MLFL, OSTR, 0, "(mail file)" }, + { "MAIL", MAIL, OSTR, 0, "(mail to user)" }, + { "MSND", MSND, OSTR, 0, "(mail send to terminal)" }, + { "MSOM", MSOM, OSTR, 0, "(mail send to terminal or mailbox)" }, + { "MSAM", MSAM, OSTR, 0, "(mail send to terminal and mailbox)" }, + { "MRSQ", MRSQ, OSTR, 0, "(mail recipient scheme question)" }, + { "MRCP", MRCP, STR1, 0, "(mail recipient)" }, + { "ALLO", ALLO, ARGS, 1, "allocate storage (vacuously)" }, + { "REST", REST, ARGS, 0, "(restart command)" }, + { "RNFR", RNFR, STR1, 1, "<sp> file-name" }, + { "RNTO", RNTO, STR1, 1, "<sp> file-name" }, + { "ABOR", ABOR, ARGS, 1, "(abort operation)" }, + { "DELE", DELE, STR1, 1, "<sp> file-name" }, + { "CWD", CWD, OSTR, 1, "[ <sp> directory-name ]" }, + { "XCWD", CWD, OSTR, 1, "[ <sp> directory-name ]" }, + { "LIST", LIST, OSTR, 1, "[ <sp> path-name ]" }, + { "NLST", NLST, OSTR, 1, "[ <sp> path-name ]" }, + { "SITE", SITE, SITECMD, 1, "site-cmd [ <sp> arguments ]" }, + { "SYST", SYST, ARGS, 1, "(get type of operating system)" }, + { "STAT", STAT, OSTR, 1, "[ <sp> path-name ]" }, + { "HELP", HELP, OSTR, 1, "[ <sp> <string> ]" }, + { "NOOP", NOOP, ARGS, 1, "" }, + { "MKD", MKD, STR1, 1, "<sp> path-name" }, + { "XMKD", MKD, STR1, 1, "<sp> path-name" }, + { "RMD", RMD, STR1, 1, "<sp> path-name" }, + { "XRMD", RMD, STR1, 1, "<sp> path-name" }, + { "PWD", PWD, ARGS, 1, "(return current directory)" }, + { "XPWD", PWD, ARGS, 1, "(return current directory)" }, + { "CDUP", CDUP, ARGS, 1, "(change to parent directory)" }, + { "XCUP", CDUP, ARGS, 1, "(change to parent directory)" }, + { "STOU", STOU, STR1, 1, "<sp> file-name" }, + { "SIZE", SIZE, OSTR, 1, "<sp> path-name" }, + { "MDTM", MDTM, OSTR, 1, "<sp> path-name" }, + { 0, 0, 0, 0, 0 } +}; + +struct tab sitetab[] = { + { "UMASK", UMASK, ARGS, 1, "[ <sp> umask ]" }, + { "IDLE", IDLE, ARGS, 1, "[ <sp> maximum-idle-time ]" }, + { "CHMOD", CHMOD, NSTR, 1, "<sp> mode <sp> file-name" }, + { "HELP", HELP, OSTR, 1, "[ <sp> <string> ]" }, + { 0, 0, 0, 0, 0 } +}; + +static struct tab * +lookup(struct tab *p, char *cmd) +{ + + for (; p->name != 0; p++) + if (strcmp(cmd, p->name) == 0) + return (p); + return (0); +} + +#include <arpa/telnet.h> + +/* + * get_line - a hacked up version of fgets to ignore TELNET escape codes. + */ +static char * +get_line(char *s, int n, FILE *iop) +{ + register int c; + register char *cs; + + cs = s; +/* tmpline may contain saved command from urgent mode interruption */ + for (c = 0; tmpline[c] != '\0' && --n > 0; ++c) { + *cs++ = tmpline[c]; + if (tmpline[c] == '\n') { + *cs = '\0'; + if (debug) + syslog(LOG_DEBUG, "command: %s", s); + tmpline[0] = '\0'; + return(s); + } + if (c == 0) + tmpline[0] = '\0'; + } + while ((c = getc(iop)) != EOF) { + c &= 0377; + if (c == IAC) { + if ((c = getc(iop)) != EOF) { + c &= 0377; + switch (c) { + case WILL: + case WONT: + c = getc(iop); + printf("%c%c%c", IAC, DONT, 0377&c); + (void) fflush(stdout); + continue; + case DO: + case DONT: + c = getc(iop); + printf("%c%c%c", IAC, WONT, 0377&c); + (void) fflush(stdout); + continue; + case IAC: + break; + default: + continue; /* ignore command */ + } + } + } + *cs++ = c; + if (--n <= 0 || c == '\n') + break; + } + if (c == EOF && cs == s) + return (0); + *cs = '\0'; + if (debug) + syslog(LOG_DEBUG, "command: %s", s); + return (s); +} + +static void +toolong(int sig) +{ + time_t now; + + (void) sig; + reply(421, + "Timeout (%d seconds): closing control connection.", timeout); + (void) time(&now); + if (logging) { + syslog(LOG_INFO, + "User %s timed out after %d seconds at %s", + (pw ? pw -> pw_name : "unknown"), timeout, ctime(&now)); + } + dologout(1); +} + +int +yylex(void) +{ + static int cpos, state; + register char *cp, *cp2; + register struct tab *p; + int n; + char c; + + for (;;) { + switch (state) { + + case CMD: + (void) signal(SIGALRM, toolong); + (void) alarm((unsigned) timeout); + if (get_line(cbuf, sizeof(cbuf)-1, stdin) == 0) { + reply(221, "You could at least say goodbye."); + dologout(0); + } + (void) alarm(0); +#ifdef SETPROCTITLE + if (strncasecmp(cbuf, "PASS", 4) != 0) + setproctitle("%s: %s", proctitle, cbuf); +#endif /* SETPROCTITLE */ + if ((cp = strchr(cbuf, '\r'))) { + *cp++ = '\n'; + *cp = '\0'; + } + if ((cp = strpbrk(cbuf, " \n"))) + cpos = cp - cbuf; + if (cpos == 0) + cpos = 4; + c = cbuf[cpos]; + cbuf[cpos] = '\0'; + upper(cbuf); + p = lookup(cmdtab, cbuf); + cbuf[cpos] = c; + if (p != 0) { + if (p->implemented == 0) { + nack(p->name); + longjmp(errcatch,0); + /* NOTREACHED */ + } + state = p->state; + *(const char **)(&yylval) = p->name; + return (p->token); + } + break; + + case SITECMD: + if (cbuf[cpos] == ' ') { + cpos++; + return (SP); + } + cp = &cbuf[cpos]; + if ((cp2 = strpbrk(cp, " \n"))) + cpos = cp2 - cbuf; + c = cbuf[cpos]; + cbuf[cpos] = '\0'; + upper(cp); + p = lookup(sitetab, cp); + cbuf[cpos] = c; + if (p != 0) { + if (p->implemented == 0) { + state = CMD; + nack(p->name); + longjmp(errcatch,0); + /* NOTREACHED */ + } + state = p->state; + *(const char **)(&yylval) = p->name; + return (p->token); + } + state = CMD; + break; + + case OSTR: + if (cbuf[cpos] == '\n') { + state = CMD; + return (CRLF); + } + /* FALLTHROUGH */ + + case STR1: + case ZSTR1: + dostr1: + if (cbuf[cpos] == ' ') { + cpos++; + if (state == OSTR) + state = STR2; + else + ++state; + return (SP); + } + break; + + case ZSTR2: + if (cbuf[cpos] == '\n') { + state = CMD; + return (CRLF); + } + /* FALLTHROUGH */ + + case STR2: + cp = &cbuf[cpos]; + n = strlen(cp); + cpos += n - 1; + /* + * Make sure the string is nonempty and \n terminated. + */ + if (n > 1 && cbuf[cpos] == '\n') { + cbuf[cpos] = '\0'; + *(char **)&yylval = copy(cp); + cbuf[cpos] = '\n'; + state = ARGS; + return (STRING); + } + break; + + case NSTR: + if (cbuf[cpos] == ' ') { + cpos++; + return (SP); + } + if (isdigit(cbuf[cpos])) { + cp = &cbuf[cpos]; + while (isdigit(cbuf[++cpos])) + ; + c = cbuf[cpos]; + cbuf[cpos] = '\0'; + yylval = atoi(cp); + cbuf[cpos] = c; + state = STR1; + return (NUMBER); + } + state = STR1; + goto dostr1; + + case ARGS: + if (isdigit(cbuf[cpos])) { + cp = &cbuf[cpos]; + while (isdigit(cbuf[++cpos])) + ; + c = cbuf[cpos]; + cbuf[cpos] = '\0'; + yylval = atoi(cp); + cbuf[cpos] = c; + return (NUMBER); + } + switch (cbuf[cpos++]) { + + case '\n': + state = CMD; + return (CRLF); + + case ' ': + return (SP); + + case ',': + return (COMMA); + + case 'A': + case 'a': + return (A); + + case 'B': + case 'b': + return (B); + + case 'C': + case 'c': + return (C); + + case 'E': + case 'e': + return (E); + + case 'F': + case 'f': + return (F); + + case 'I': + case 'i': + return (I); + + case 'L': + case 'l': + return (L); + + case 'N': + case 'n': + return (N); + + case 'P': + case 'p': + return (P); + + case 'R': + case 'r': + return (R); + + case 'S': + case 's': + return (S); + + case 'T': + case 't': + return (T); + + } + break; + + default: + fatal("Unknown state in scanner."); + } + yyerror((char *) 0); + state = CMD; + longjmp(errcatch,0); + } +} + +static void +upper(char *s) +{ + while (*s != '\0') { + if (islower(*s)) + *s = toupper(*s); + s++; + } +} + +static char * +copy(const char *s) +{ + char *p; + + p = (char * )malloc(strlen(s) + 1); + if (p == 0) + fatal("Ran out of memory."); + else + (void) strcpy(p, s); + return (p); +} + +static void +help(struct tab *ctab, char *s) +{ + register struct tab *c; + register int width, NCMDS; + const char *help_type; + + if (ctab == sitetab) + help_type = "SITE "; + else + help_type = ""; + width = 0, NCMDS = 0; + for (c = ctab; c->name != 0; c++) { + int len = strlen(c->name); + + if (len > width) + width = len; + NCMDS++; + } + width = (width + 8) &~ 7; + if (s == 0) { + register int i, j, w; + int columns, lines; + + lreply(214, "The following %scommands are recognized %s.", + help_type, "(* =>'s unimplemented)"); + columns = 76 / width; + if (columns == 0) + columns = 1; + lines = (NCMDS + columns - 1) / columns; + for (i = 0; i < lines; i++) { + printf(" "); + for (j = 0; j < columns; j++) { + c = ctab + j * lines + i; + assert(c->name != 0); + printf("%s%c", c->name, + c->implemented ? ' ' : '*'); + if (c + lines >= &ctab[NCMDS]) + break; + w = strlen(c->name) + 1; + while (w < width) { + putchar(' '); + w++; + } + } + printf("\r\n"); + } + (void) fflush(stdout); + reply(214, "Direct comments to ftp-bugs@%s.", hostname); + return; + } + upper(s); + c = lookup(ctab, s); + if (c == (struct tab *)0) { + reply(502, "Unknown command %s.", s); + return; + } + if (c->implemented) + reply(214, "Syntax: %s%s %s", help_type, c->name, c->help); + else + reply(214, "%s%-*s\t%s; unimplemented.", help_type, width, + c->name, c->help); +} + +static void +sizecmd(char *filename) +{ + switch (type) { + case TYPE_L: + case TYPE_I: { + struct stat stbuf; + if (stat(filename, &stbuf) < 0 || + (stbuf.st_mode&S_IFMT) != S_IFREG) + reply(550, "%s: not a plain file.", filename); + else +#ifdef HAVE_LONG_LONG + reply(213, "%llu", (long long) stbuf.st_size); +#else + reply(213, "%lu", stbuf.st_size); +#endif + break;} + case TYPE_A: { + FILE *fin; + register int c, count; + struct stat stbuf; + fin = fopen(filename, "r"); + if (fin == 0) { + perror_reply(550, filename); + return; + } + if (fstat(fileno(fin), &stbuf) < 0 || + (stbuf.st_mode&S_IFMT) != S_IFREG) { + reply(550, "%s: not a plain file.", filename); + (void) fclose(fin); + return; + } + + count = 0; + while((c=getc(fin)) != EOF) { + if (c == '\n') /* will get expanded to \r\n */ + count++; + count++; + } + (void) fclose(fin); + + reply(213, "%ld", count); + break;} + default: + reply(504, "SIZE not implemented for Type %c.", "?AEIL"[type]); + } +} diff --git a/test/grammar.output b/test/grammar.output new file mode 100644 index 000000000000..6351322345b5 --- /dev/null +++ b/test/grammar.output @@ -0,0 +1,2214 @@ + 0 $accept : program $end + + 1 program : + 2 | translation_unit + + 3 translation_unit : external_declaration + 4 | translation_unit external_declaration + + 5 external_declaration : declaration + 6 | function_definition + 7 | ';' + 8 | linkage_specification + 9 | T_ASM T_ASMARG ';' + 10 | error T_MATCHRBRACE + 11 | error ';' + + 12 braces : T_LBRACE T_MATCHRBRACE + + 13 linkage_specification : T_EXTERN T_STRING_LITERAL braces + 14 | T_EXTERN T_STRING_LITERAL declaration + + 15 declaration : decl_specifiers ';' + 16 | decl_specifiers init_declarator_list ';' + + 17 $$1 : + + 18 declaration : any_typedef decl_specifiers $$1 opt_declarator_list ';' + + 19 any_typedef : T_EXTENSION T_TYPEDEF + 20 | T_TYPEDEF + + 21 opt_declarator_list : + 22 | declarator_list + + 23 declarator_list : declarator + 24 | declarator_list ',' declarator + + 25 $$2 : + + 26 $$3 : + + 27 function_definition : decl_specifiers declarator $$2 opt_declaration_list T_LBRACE $$3 T_MATCHRBRACE + + 28 $$4 : + + 29 function_definition : declarator $$4 opt_declaration_list T_LBRACE T_MATCHRBRACE + + 30 opt_declaration_list : + 31 | T_VA_DCL + 32 | declaration_list + + 33 declaration_list : declaration + 34 | declaration_list declaration + + 35 decl_specifiers : decl_specifier + 36 | decl_specifiers decl_specifier + + 37 decl_specifier : storage_class + 38 | type_specifier + 39 | type_qualifier + + 40 storage_class : T_AUTO + 41 | T_EXTERN + 42 | T_REGISTER + 43 | T_STATIC + 44 | T_INLINE + 45 | T_EXTENSION + + 46 type_specifier : T_CHAR + 47 | T_DOUBLE + 48 | T_FLOAT + 49 | T_INT + 50 | T_LONG + 51 | T_SHORT + 52 | T_SIGNED + 53 | T_UNSIGNED + 54 | T_VOID + 55 | T_Bool + 56 | T_Complex + 57 | T_Imaginary + 58 | T_TYPEDEF_NAME + 59 | struct_or_union_specifier + 60 | enum_specifier + + 61 type_qualifier : T_TYPE_QUALIFIER + 62 | T_DEFINE_NAME + + 63 struct_or_union_specifier : struct_or_union any_id braces + 64 | struct_or_union braces + 65 | struct_or_union any_id + + 66 struct_or_union : T_STRUCT + 67 | T_UNION + + 68 init_declarator_list : init_declarator + 69 | init_declarator_list ',' init_declarator + + 70 init_declarator : declarator + + 71 $$5 : + + 72 init_declarator : declarator '=' $$5 T_INITIALIZER + + 73 enum_specifier : enumeration any_id braces + 74 | enumeration braces + 75 | enumeration any_id + + 76 enumeration : T_ENUM + + 77 any_id : T_IDENTIFIER + 78 | T_TYPEDEF_NAME + + 79 declarator : pointer direct_declarator + 80 | direct_declarator + + 81 direct_declarator : identifier_or_ref + 82 | '(' declarator ')' + 83 | direct_declarator T_BRACKETS + 84 | direct_declarator '(' parameter_type_list ')' + 85 | direct_declarator '(' opt_identifier_list ')' + + 86 pointer : '*' opt_type_qualifiers + 87 | '*' opt_type_qualifiers pointer + + 88 opt_type_qualifiers : + 89 | type_qualifier_list + + 90 type_qualifier_list : type_qualifier + 91 | type_qualifier_list type_qualifier + + 92 parameter_type_list : parameter_list + 93 | parameter_list ',' T_ELLIPSIS + + 94 parameter_list : parameter_declaration + 95 | parameter_list ',' parameter_declaration + + 96 parameter_declaration : decl_specifiers declarator + 97 | decl_specifiers abs_declarator + 98 | decl_specifiers + + 99 opt_identifier_list : + 100 | identifier_list + + 101 identifier_list : any_id + 102 | identifier_list ',' any_id + + 103 identifier_or_ref : any_id + 104 | '&' any_id + + 105 abs_declarator : pointer + 106 | pointer direct_abs_declarator + 107 | direct_abs_declarator + + 108 direct_abs_declarator : '(' abs_declarator ')' + 109 | direct_abs_declarator T_BRACKETS + 110 | T_BRACKETS + 111 | direct_abs_declarator '(' parameter_type_list ')' + 112 | direct_abs_declarator '(' ')' + 113 | '(' parameter_type_list ')' + 114 | '(' ')' + +state 0 + $accept : . program $end (0) + program : . (1) + + error shift 1 + '(' shift 2 + '*' shift 3 + '&' shift 4 + T_IDENTIFIER shift 5 + T_TYPEDEF_NAME shift 6 + T_DEFINE_NAME shift 7 + T_AUTO shift 8 + T_EXTERN shift 9 + T_REGISTER shift 10 + T_STATIC shift 11 + T_TYPEDEF shift 12 + T_INLINE shift 13 + T_EXTENSION shift 14 + T_CHAR shift 15 + T_DOUBLE shift 16 + T_FLOAT shift 17 + T_INT shift 18 + T_VOID shift 19 + T_LONG shift 20 + T_SHORT shift 21 + T_SIGNED shift 22 + T_UNSIGNED shift 23 + T_ENUM shift 24 + T_STRUCT shift 25 + T_UNION shift 26 + T_Bool shift 27 + T_Complex shift 28 + T_Imaginary shift 29 + T_TYPE_QUALIFIER shift 30 + T_ASM shift 31 + ';' shift 32 + $end reduce 1 + + program goto 33 + decl_specifiers goto 34 + decl_specifier goto 35 + storage_class goto 36 + type_specifier goto 37 + type_qualifier goto 38 + struct_or_union_specifier goto 39 + enum_specifier goto 40 + declarator goto 41 + direct_declarator goto 42 + struct_or_union goto 43 + pointer goto 44 + any_id goto 45 + identifier_or_ref goto 46 + enumeration goto 47 + translation_unit goto 48 + external_declaration goto 49 + declaration goto 50 + function_definition goto 51 + linkage_specification goto 52 + any_typedef goto 53 + + +state 1 + external_declaration : error . T_MATCHRBRACE (10) + external_declaration : error . ';' (11) + + T_MATCHRBRACE shift 54 + ';' shift 55 + . error + + +state 2 + direct_declarator : '(' . declarator ')' (82) + + '(' shift 2 + '*' shift 3 + '&' shift 4 + T_IDENTIFIER shift 5 + T_TYPEDEF_NAME shift 56 + . error + + declarator goto 57 + direct_declarator goto 42 + pointer goto 44 + any_id goto 45 + identifier_or_ref goto 46 + + +state 3 + pointer : '*' . opt_type_qualifiers (86) + pointer : '*' . opt_type_qualifiers pointer (87) + opt_type_qualifiers : . (88) + + T_DEFINE_NAME shift 7 + T_TYPE_QUALIFIER shift 30 + '(' reduce 88 + '*' reduce 88 + '&' reduce 88 + T_IDENTIFIER reduce 88 + T_TYPEDEF_NAME reduce 88 + T_BRACKETS reduce 88 + ',' reduce 88 + ')' reduce 88 + + type_qualifier goto 58 + opt_type_qualifiers goto 59 + type_qualifier_list goto 60 + + +state 4 + identifier_or_ref : '&' . any_id (104) + + T_IDENTIFIER shift 5 + T_TYPEDEF_NAME shift 56 + . error + + any_id goto 61 + + +state 5 + any_id : T_IDENTIFIER . (77) + + . reduce 77 + + +6: reduce/reduce conflict (reduce 58, reduce 78) on '(' +6: reduce/reduce conflict (reduce 58, reduce 78) on T_TYPEDEF_NAME +6: reduce/reduce conflict (reduce 58, reduce 78) on T_DEFINE_NAME +6: reduce/reduce conflict (reduce 58, reduce 78) on T_AUTO +6: reduce/reduce conflict (reduce 58, reduce 78) on T_EXTERN +6: reduce/reduce conflict (reduce 58, reduce 78) on T_REGISTER +6: reduce/reduce conflict (reduce 58, reduce 78) on T_STATIC +6: reduce/reduce conflict (reduce 58, reduce 78) on T_INLINE +6: reduce/reduce conflict (reduce 58, reduce 78) on T_EXTENSION +6: reduce/reduce conflict (reduce 58, reduce 78) on T_CHAR +6: reduce/reduce conflict (reduce 58, reduce 78) on T_DOUBLE +6: reduce/reduce conflict (reduce 58, reduce 78) on T_FLOAT +6: reduce/reduce conflict (reduce 58, reduce 78) on T_INT +6: reduce/reduce conflict (reduce 58, reduce 78) on T_VOID +6: reduce/reduce conflict (reduce 58, reduce 78) on T_LONG +6: reduce/reduce conflict (reduce 58, reduce 78) on T_SHORT +6: reduce/reduce conflict (reduce 58, reduce 78) on T_SIGNED +6: reduce/reduce conflict (reduce 58, reduce 78) on T_UNSIGNED +6: reduce/reduce conflict (reduce 58, reduce 78) on T_ENUM +6: reduce/reduce conflict (reduce 58, reduce 78) on T_STRUCT +6: reduce/reduce conflict (reduce 58, reduce 78) on T_UNION +6: reduce/reduce conflict (reduce 58, reduce 78) on T_Bool +6: reduce/reduce conflict (reduce 58, reduce 78) on T_Complex +6: reduce/reduce conflict (reduce 58, reduce 78) on T_Imaginary +6: reduce/reduce conflict (reduce 58, reduce 78) on T_TYPE_QUALIFIER +6: reduce/reduce conflict (reduce 58, reduce 78) on T_BRACKETS +6: reduce/reduce conflict (reduce 58, reduce 78) on ';' +6: reduce/reduce conflict (reduce 58, reduce 78) on ',' +6: reduce/reduce conflict (reduce 58, reduce 78) on ')' +state 6 + type_specifier : T_TYPEDEF_NAME . (58) + any_id : T_TYPEDEF_NAME . (78) + + '(' reduce 58 + '*' reduce 58 + '&' reduce 58 + T_IDENTIFIER reduce 58 + T_TYPEDEF_NAME reduce 58 + T_DEFINE_NAME reduce 58 + T_AUTO reduce 58 + T_EXTERN reduce 58 + T_REGISTER reduce 58 + T_STATIC reduce 58 + T_TYPEDEF reduce 78 + T_INLINE reduce 58 + T_EXTENSION reduce 58 + T_CHAR reduce 58 + T_DOUBLE reduce 58 + T_FLOAT reduce 58 + T_INT reduce 58 + T_VOID reduce 58 + T_LONG reduce 58 + T_SHORT reduce 58 + T_SIGNED reduce 58 + T_UNSIGNED reduce 58 + T_ENUM reduce 58 + T_STRUCT reduce 58 + T_UNION reduce 58 + T_Bool reduce 58 + T_Complex reduce 58 + T_Imaginary reduce 58 + T_TYPE_QUALIFIER reduce 58 + T_BRACKETS reduce 58 + T_LBRACE reduce 78 + T_VA_DCL reduce 78 + ';' reduce 58 + ',' reduce 58 + '=' reduce 78 + ')' reduce 58 + + +state 7 + type_qualifier : T_DEFINE_NAME . (62) + + . reduce 62 + + +state 8 + storage_class : T_AUTO . (40) + + . reduce 40 + + +state 9 + linkage_specification : T_EXTERN . T_STRING_LITERAL braces (13) + linkage_specification : T_EXTERN . T_STRING_LITERAL declaration (14) + storage_class : T_EXTERN . (41) + + T_STRING_LITERAL shift 62 + '(' reduce 41 + '*' reduce 41 + '&' reduce 41 + T_IDENTIFIER reduce 41 + T_TYPEDEF_NAME reduce 41 + T_DEFINE_NAME reduce 41 + T_AUTO reduce 41 + T_EXTERN reduce 41 + T_REGISTER reduce 41 + T_STATIC reduce 41 + T_INLINE reduce 41 + T_EXTENSION reduce 41 + T_CHAR reduce 41 + T_DOUBLE reduce 41 + T_FLOAT reduce 41 + T_INT reduce 41 + T_VOID reduce 41 + T_LONG reduce 41 + T_SHORT reduce 41 + T_SIGNED reduce 41 + T_UNSIGNED reduce 41 + T_ENUM reduce 41 + T_STRUCT reduce 41 + T_UNION reduce 41 + T_Bool reduce 41 + T_Complex reduce 41 + T_Imaginary reduce 41 + T_TYPE_QUALIFIER reduce 41 + ';' reduce 41 + + +state 10 + storage_class : T_REGISTER . (42) + + . reduce 42 + + +state 11 + storage_class : T_STATIC . (43) + + . reduce 43 + + +state 12 + any_typedef : T_TYPEDEF . (20) + + . reduce 20 + + +state 13 + storage_class : T_INLINE . (44) + + . reduce 44 + + +state 14 + any_typedef : T_EXTENSION . T_TYPEDEF (19) + storage_class : T_EXTENSION . (45) + + T_TYPEDEF shift 63 + '(' reduce 45 + '*' reduce 45 + '&' reduce 45 + T_IDENTIFIER reduce 45 + T_TYPEDEF_NAME reduce 45 + T_DEFINE_NAME reduce 45 + T_AUTO reduce 45 + T_EXTERN reduce 45 + T_REGISTER reduce 45 + T_STATIC reduce 45 + T_INLINE reduce 45 + T_EXTENSION reduce 45 + T_CHAR reduce 45 + T_DOUBLE reduce 45 + T_FLOAT reduce 45 + T_INT reduce 45 + T_VOID reduce 45 + T_LONG reduce 45 + T_SHORT reduce 45 + T_SIGNED reduce 45 + T_UNSIGNED reduce 45 + T_ENUM reduce 45 + T_STRUCT reduce 45 + T_UNION reduce 45 + T_Bool reduce 45 + T_Complex reduce 45 + T_Imaginary reduce 45 + T_TYPE_QUALIFIER reduce 45 + ';' reduce 45 + + +state 15 + type_specifier : T_CHAR . (46) + + . reduce 46 + + +state 16 + type_specifier : T_DOUBLE . (47) + + . reduce 47 + + +state 17 + type_specifier : T_FLOAT . (48) + + . reduce 48 + + +state 18 + type_specifier : T_INT . (49) + + . reduce 49 + + +state 19 + type_specifier : T_VOID . (54) + + . reduce 54 + + +state 20 + type_specifier : T_LONG . (50) + + . reduce 50 + + +state 21 + type_specifier : T_SHORT . (51) + + . reduce 51 + + +state 22 + type_specifier : T_SIGNED . (52) + + . reduce 52 + + +state 23 + type_specifier : T_UNSIGNED . (53) + + . reduce 53 + + +state 24 + enumeration : T_ENUM . (76) + + . reduce 76 + + +state 25 + struct_or_union : T_STRUCT . (66) + + . reduce 66 + + +state 26 + struct_or_union : T_UNION . (67) + + . reduce 67 + + +state 27 + type_specifier : T_Bool . (55) + + . reduce 55 + + +state 28 + type_specifier : T_Complex . (56) + + . reduce 56 + + +state 29 + type_specifier : T_Imaginary . (57) + + . reduce 57 + + +state 30 + type_qualifier : T_TYPE_QUALIFIER . (61) + + . reduce 61 + + +state 31 + external_declaration : T_ASM . T_ASMARG ';' (9) + + T_ASMARG shift 64 + . error + + +state 32 + external_declaration : ';' . (7) + + . reduce 7 + + +state 33 + $accept : program . $end (0) + + $end accept + + +state 34 + declaration : decl_specifiers . ';' (15) + declaration : decl_specifiers . init_declarator_list ';' (16) + function_definition : decl_specifiers . declarator $$2 opt_declaration_list T_LBRACE $$3 T_MATCHRBRACE (27) + decl_specifiers : decl_specifiers . decl_specifier (36) + + '(' shift 2 + '*' shift 3 + '&' shift 4 + T_IDENTIFIER shift 5 + T_TYPEDEF_NAME shift 6 + T_DEFINE_NAME shift 7 + T_AUTO shift 8 + T_EXTERN shift 65 + T_REGISTER shift 10 + T_STATIC shift 11 + T_INLINE shift 13 + T_EXTENSION shift 66 + T_CHAR shift 15 + T_DOUBLE shift 16 + T_FLOAT shift 17 + T_INT shift 18 + T_VOID shift 19 + T_LONG shift 20 + T_SHORT shift 21 + T_SIGNED shift 22 + T_UNSIGNED shift 23 + T_ENUM shift 24 + T_STRUCT shift 25 + T_UNION shift 26 + T_Bool shift 27 + T_Complex shift 28 + T_Imaginary shift 29 + T_TYPE_QUALIFIER shift 30 + ';' shift 67 + . error + + decl_specifier goto 68 + storage_class goto 36 + type_specifier goto 37 + type_qualifier goto 38 + struct_or_union_specifier goto 39 + enum_specifier goto 40 + init_declarator_list goto 69 + init_declarator goto 70 + declarator goto 71 + direct_declarator goto 42 + struct_or_union goto 43 + pointer goto 44 + any_id goto 45 + identifier_or_ref goto 46 + enumeration goto 47 + + +state 35 + decl_specifiers : decl_specifier . (35) + + . reduce 35 + + +state 36 + decl_specifier : storage_class . (37) + + . reduce 37 + + +state 37 + decl_specifier : type_specifier . (38) + + . reduce 38 + + +state 38 + decl_specifier : type_qualifier . (39) + + . reduce 39 + + +state 39 + type_specifier : struct_or_union_specifier . (59) + + . reduce 59 + + +state 40 + type_specifier : enum_specifier . (60) + + . reduce 60 + + +state 41 + function_definition : declarator . $$4 opt_declaration_list T_LBRACE T_MATCHRBRACE (29) + $$4 : . (28) + + . reduce 28 + + $$4 goto 72 + + +state 42 + declarator : direct_declarator . (80) + direct_declarator : direct_declarator . T_BRACKETS (83) + direct_declarator : direct_declarator . '(' parameter_type_list ')' (84) + direct_declarator : direct_declarator . '(' opt_identifier_list ')' (85) + + '(' shift 73 + T_BRACKETS shift 74 + T_TYPEDEF_NAME reduce 80 + T_DEFINE_NAME reduce 80 + T_AUTO reduce 80 + T_EXTERN reduce 80 + T_REGISTER reduce 80 + T_STATIC reduce 80 + T_TYPEDEF reduce 80 + T_INLINE reduce 80 + T_EXTENSION reduce 80 + T_CHAR reduce 80 + T_DOUBLE reduce 80 + T_FLOAT reduce 80 + T_INT reduce 80 + T_VOID reduce 80 + T_LONG reduce 80 + T_SHORT reduce 80 + T_SIGNED reduce 80 + T_UNSIGNED reduce 80 + T_ENUM reduce 80 + T_STRUCT reduce 80 + T_UNION reduce 80 + T_Bool reduce 80 + T_Complex reduce 80 + T_Imaginary reduce 80 + T_TYPE_QUALIFIER reduce 80 + T_LBRACE reduce 80 + T_VA_DCL reduce 80 + ';' reduce 80 + ',' reduce 80 + '=' reduce 80 + ')' reduce 80 + + +state 43 + struct_or_union_specifier : struct_or_union . any_id braces (63) + struct_or_union_specifier : struct_or_union . braces (64) + struct_or_union_specifier : struct_or_union . any_id (65) + + T_IDENTIFIER shift 5 + T_TYPEDEF_NAME shift 56 + T_LBRACE shift 75 + . error + + any_id goto 76 + braces goto 77 + + +state 44 + declarator : pointer . direct_declarator (79) + + '(' shift 2 + '&' shift 4 + T_IDENTIFIER shift 5 + T_TYPEDEF_NAME shift 56 + . error + + direct_declarator goto 78 + any_id goto 45 + identifier_or_ref goto 46 + + +state 45 + identifier_or_ref : any_id . (103) + + . reduce 103 + + +state 46 + direct_declarator : identifier_or_ref . (81) + + . reduce 81 + + +state 47 + enum_specifier : enumeration . any_id braces (73) + enum_specifier : enumeration . braces (74) + enum_specifier : enumeration . any_id (75) + + T_IDENTIFIER shift 5 + T_TYPEDEF_NAME shift 56 + T_LBRACE shift 75 + . error + + any_id goto 79 + braces goto 80 + + +state 48 + program : translation_unit . (2) + translation_unit : translation_unit . external_declaration (4) + + error shift 1 + '(' shift 2 + '*' shift 3 + '&' shift 4 + T_IDENTIFIER shift 5 + T_TYPEDEF_NAME shift 6 + T_DEFINE_NAME shift 7 + T_AUTO shift 8 + T_EXTERN shift 9 + T_REGISTER shift 10 + T_STATIC shift 11 + T_TYPEDEF shift 12 + T_INLINE shift 13 + T_EXTENSION shift 14 + T_CHAR shift 15 + T_DOUBLE shift 16 + T_FLOAT shift 17 + T_INT shift 18 + T_VOID shift 19 + T_LONG shift 20 + T_SHORT shift 21 + T_SIGNED shift 22 + T_UNSIGNED shift 23 + T_ENUM shift 24 + T_STRUCT shift 25 + T_UNION shift 26 + T_Bool shift 27 + T_Complex shift 28 + T_Imaginary shift 29 + T_TYPE_QUALIFIER shift 30 + T_ASM shift 31 + ';' shift 32 + $end reduce 2 + + decl_specifiers goto 34 + decl_specifier goto 35 + storage_class goto 36 + type_specifier goto 37 + type_qualifier goto 38 + struct_or_union_specifier goto 39 + enum_specifier goto 40 + declarator goto 41 + direct_declarator goto 42 + struct_or_union goto 43 + pointer goto 44 + any_id goto 45 + identifier_or_ref goto 46 + enumeration goto 47 + external_declaration goto 81 + declaration goto 50 + function_definition goto 51 + linkage_specification goto 52 + any_typedef goto 53 + + +state 49 + translation_unit : external_declaration . (3) + + . reduce 3 + + +state 50 + external_declaration : declaration . (5) + + . reduce 5 + + +state 51 + external_declaration : function_definition . (6) + + . reduce 6 + + +state 52 + external_declaration : linkage_specification . (8) + + . reduce 8 + + +state 53 + declaration : any_typedef . decl_specifiers $$1 opt_declarator_list ';' (18) + + T_TYPEDEF_NAME shift 82 + T_DEFINE_NAME shift 7 + T_AUTO shift 8 + T_EXTERN shift 65 + T_REGISTER shift 10 + T_STATIC shift 11 + T_INLINE shift 13 + T_EXTENSION shift 66 + T_CHAR shift 15 + T_DOUBLE shift 16 + T_FLOAT shift 17 + T_INT shift 18 + T_VOID shift 19 + T_LONG shift 20 + T_SHORT shift 21 + T_SIGNED shift 22 + T_UNSIGNED shift 23 + T_ENUM shift 24 + T_STRUCT shift 25 + T_UNION shift 26 + T_Bool shift 27 + T_Complex shift 28 + T_Imaginary shift 29 + T_TYPE_QUALIFIER shift 30 + . error + + decl_specifiers goto 83 + decl_specifier goto 35 + storage_class goto 36 + type_specifier goto 37 + type_qualifier goto 38 + struct_or_union_specifier goto 39 + enum_specifier goto 40 + struct_or_union goto 43 + enumeration goto 47 + + +state 54 + external_declaration : error T_MATCHRBRACE . (10) + + . reduce 10 + + +state 55 + external_declaration : error ';' . (11) + + . reduce 11 + + +state 56 + any_id : T_TYPEDEF_NAME . (78) + + . reduce 78 + + +state 57 + direct_declarator : '(' declarator . ')' (82) + + ')' shift 84 + . error + + +state 58 + type_qualifier_list : type_qualifier . (90) + + . reduce 90 + + +state 59 + pointer : '*' opt_type_qualifiers . (86) + pointer : '*' opt_type_qualifiers . pointer (87) + + '*' shift 3 + '(' reduce 86 + '&' reduce 86 + T_IDENTIFIER reduce 86 + T_TYPEDEF_NAME reduce 86 + T_BRACKETS reduce 86 + ',' reduce 86 + ')' reduce 86 + + pointer goto 85 + + +state 60 + opt_type_qualifiers : type_qualifier_list . (89) + type_qualifier_list : type_qualifier_list . type_qualifier (91) + + T_DEFINE_NAME shift 7 + T_TYPE_QUALIFIER shift 30 + '(' reduce 89 + '*' reduce 89 + '&' reduce 89 + T_IDENTIFIER reduce 89 + T_TYPEDEF_NAME reduce 89 + T_BRACKETS reduce 89 + ',' reduce 89 + ')' reduce 89 + + type_qualifier goto 86 + + +state 61 + identifier_or_ref : '&' any_id . (104) + + . reduce 104 + + +state 62 + linkage_specification : T_EXTERN T_STRING_LITERAL . braces (13) + linkage_specification : T_EXTERN T_STRING_LITERAL . declaration (14) + + T_TYPEDEF_NAME shift 82 + T_DEFINE_NAME shift 7 + T_AUTO shift 8 + T_EXTERN shift 65 + T_REGISTER shift 10 + T_STATIC shift 11 + T_TYPEDEF shift 12 + T_INLINE shift 13 + T_EXTENSION shift 14 + T_CHAR shift 15 + T_DOUBLE shift 16 + T_FLOAT shift 17 + T_INT shift 18 + T_VOID shift 19 + T_LONG shift 20 + T_SHORT shift 21 + T_SIGNED shift 22 + T_UNSIGNED shift 23 + T_ENUM shift 24 + T_STRUCT shift 25 + T_UNION shift 26 + T_Bool shift 27 + T_Complex shift 28 + T_Imaginary shift 29 + T_TYPE_QUALIFIER shift 30 + T_LBRACE shift 75 + . error + + decl_specifiers goto 87 + decl_specifier goto 35 + storage_class goto 36 + type_specifier goto 37 + type_qualifier goto 38 + struct_or_union_specifier goto 39 + enum_specifier goto 40 + struct_or_union goto 43 + enumeration goto 47 + declaration goto 88 + braces goto 89 + any_typedef goto 53 + + +state 63 + any_typedef : T_EXTENSION T_TYPEDEF . (19) + + . reduce 19 + + +state 64 + external_declaration : T_ASM T_ASMARG . ';' (9) + + ';' shift 90 + . error + + +state 65 + storage_class : T_EXTERN . (41) + + . reduce 41 + + +state 66 + storage_class : T_EXTENSION . (45) + + . reduce 45 + + +state 67 + declaration : decl_specifiers ';' . (15) + + . reduce 15 + + +state 68 + decl_specifiers : decl_specifiers decl_specifier . (36) + + . reduce 36 + + +state 69 + declaration : decl_specifiers init_declarator_list . ';' (16) + init_declarator_list : init_declarator_list . ',' init_declarator (69) + + ';' shift 91 + ',' shift 92 + . error + + +state 70 + init_declarator_list : init_declarator . (68) + + . reduce 68 + + +state 71 + function_definition : decl_specifiers declarator . $$2 opt_declaration_list T_LBRACE $$3 T_MATCHRBRACE (27) + init_declarator : declarator . (70) + init_declarator : declarator . '=' $$5 T_INITIALIZER (72) + $$2 : . (25) + + '=' shift 93 + T_TYPEDEF_NAME reduce 25 + T_DEFINE_NAME reduce 25 + T_AUTO reduce 25 + T_EXTERN reduce 25 + T_REGISTER reduce 25 + T_STATIC reduce 25 + T_TYPEDEF reduce 25 + T_INLINE reduce 25 + T_EXTENSION reduce 25 + T_CHAR reduce 25 + T_DOUBLE reduce 25 + T_FLOAT reduce 25 + T_INT reduce 25 + T_VOID reduce 25 + T_LONG reduce 25 + T_SHORT reduce 25 + T_SIGNED reduce 25 + T_UNSIGNED reduce 25 + T_ENUM reduce 25 + T_STRUCT reduce 25 + T_UNION reduce 25 + T_Bool reduce 25 + T_Complex reduce 25 + T_Imaginary reduce 25 + T_TYPE_QUALIFIER reduce 25 + T_LBRACE reduce 25 + T_VA_DCL reduce 25 + ';' reduce 70 + ',' reduce 70 + + $$2 goto 94 + + +state 72 + function_definition : declarator $$4 . opt_declaration_list T_LBRACE T_MATCHRBRACE (29) + opt_declaration_list : . (30) + + T_TYPEDEF_NAME shift 82 + T_DEFINE_NAME shift 7 + T_AUTO shift 8 + T_EXTERN shift 65 + T_REGISTER shift 10 + T_STATIC shift 11 + T_TYPEDEF shift 12 + T_INLINE shift 13 + T_EXTENSION shift 14 + T_CHAR shift 15 + T_DOUBLE shift 16 + T_FLOAT shift 17 + T_INT shift 18 + T_VOID shift 19 + T_LONG shift 20 + T_SHORT shift 21 + T_SIGNED shift 22 + T_UNSIGNED shift 23 + T_ENUM shift 24 + T_STRUCT shift 25 + T_UNION shift 26 + T_Bool shift 27 + T_Complex shift 28 + T_Imaginary shift 29 + T_TYPE_QUALIFIER shift 30 + T_VA_DCL shift 95 + T_LBRACE reduce 30 + + decl_specifiers goto 87 + decl_specifier goto 35 + storage_class goto 36 + type_specifier goto 37 + type_qualifier goto 38 + struct_or_union_specifier goto 39 + enum_specifier goto 40 + struct_or_union goto 43 + enumeration goto 47 + declaration goto 96 + any_typedef goto 53 + opt_declaration_list goto 97 + declaration_list goto 98 + + +state 73 + direct_declarator : direct_declarator '(' . parameter_type_list ')' (84) + direct_declarator : direct_declarator '(' . opt_identifier_list ')' (85) + opt_identifier_list : . (99) + + T_IDENTIFIER shift 5 + T_TYPEDEF_NAME shift 6 + T_DEFINE_NAME shift 7 + T_AUTO shift 8 + T_EXTERN shift 65 + T_REGISTER shift 10 + T_STATIC shift 11 + T_INLINE shift 13 + T_EXTENSION shift 66 + T_CHAR shift 15 + T_DOUBLE shift 16 + T_FLOAT shift 17 + T_INT shift 18 + T_VOID shift 19 + T_LONG shift 20 + T_SHORT shift 21 + T_SIGNED shift 22 + T_UNSIGNED shift 23 + T_ENUM shift 24 + T_STRUCT shift 25 + T_UNION shift 26 + T_Bool shift 27 + T_Complex shift 28 + T_Imaginary shift 29 + T_TYPE_QUALIFIER shift 30 + ')' reduce 99 + + decl_specifiers goto 99 + decl_specifier goto 35 + storage_class goto 36 + type_specifier goto 37 + type_qualifier goto 38 + struct_or_union_specifier goto 39 + enum_specifier goto 40 + parameter_type_list goto 100 + parameter_list goto 101 + parameter_declaration goto 102 + opt_identifier_list goto 103 + identifier_list goto 104 + struct_or_union goto 43 + any_id goto 105 + enumeration goto 47 + + +state 74 + direct_declarator : direct_declarator T_BRACKETS . (83) + + . reduce 83 + + +state 75 + braces : T_LBRACE . T_MATCHRBRACE (12) + + T_MATCHRBRACE shift 106 + . error + + +state 76 + struct_or_union_specifier : struct_or_union any_id . braces (63) + struct_or_union_specifier : struct_or_union any_id . (65) + + T_LBRACE shift 75 + '(' reduce 65 + '*' reduce 65 + '&' reduce 65 + T_IDENTIFIER reduce 65 + T_TYPEDEF_NAME reduce 65 + T_DEFINE_NAME reduce 65 + T_AUTO reduce 65 + T_EXTERN reduce 65 + T_REGISTER reduce 65 + T_STATIC reduce 65 + T_INLINE reduce 65 + T_EXTENSION reduce 65 + T_CHAR reduce 65 + T_DOUBLE reduce 65 + T_FLOAT reduce 65 + T_INT reduce 65 + T_VOID reduce 65 + T_LONG reduce 65 + T_SHORT reduce 65 + T_SIGNED reduce 65 + T_UNSIGNED reduce 65 + T_ENUM reduce 65 + T_STRUCT reduce 65 + T_UNION reduce 65 + T_Bool reduce 65 + T_Complex reduce 65 + T_Imaginary reduce 65 + T_TYPE_QUALIFIER reduce 65 + T_BRACKETS reduce 65 + ';' reduce 65 + ',' reduce 65 + ')' reduce 65 + + braces goto 107 + + +state 77 + struct_or_union_specifier : struct_or_union braces . (64) + + . reduce 64 + + +state 78 + declarator : pointer direct_declarator . (79) + direct_declarator : direct_declarator . T_BRACKETS (83) + direct_declarator : direct_declarator . '(' parameter_type_list ')' (84) + direct_declarator : direct_declarator . '(' opt_identifier_list ')' (85) + + '(' shift 73 + T_BRACKETS shift 74 + T_TYPEDEF_NAME reduce 79 + T_DEFINE_NAME reduce 79 + T_AUTO reduce 79 + T_EXTERN reduce 79 + T_REGISTER reduce 79 + T_STATIC reduce 79 + T_TYPEDEF reduce 79 + T_INLINE reduce 79 + T_EXTENSION reduce 79 + T_CHAR reduce 79 + T_DOUBLE reduce 79 + T_FLOAT reduce 79 + T_INT reduce 79 + T_VOID reduce 79 + T_LONG reduce 79 + T_SHORT reduce 79 + T_SIGNED reduce 79 + T_UNSIGNED reduce 79 + T_ENUM reduce 79 + T_STRUCT reduce 79 + T_UNION reduce 79 + T_Bool reduce 79 + T_Complex reduce 79 + T_Imaginary reduce 79 + T_TYPE_QUALIFIER reduce 79 + T_LBRACE reduce 79 + T_VA_DCL reduce 79 + ';' reduce 79 + ',' reduce 79 + '=' reduce 79 + ')' reduce 79 + + +state 79 + enum_specifier : enumeration any_id . braces (73) + enum_specifier : enumeration any_id . (75) + + T_LBRACE shift 75 + '(' reduce 75 + '*' reduce 75 + '&' reduce 75 + T_IDENTIFIER reduce 75 + T_TYPEDEF_NAME reduce 75 + T_DEFINE_NAME reduce 75 + T_AUTO reduce 75 + T_EXTERN reduce 75 + T_REGISTER reduce 75 + T_STATIC reduce 75 + T_INLINE reduce 75 + T_EXTENSION reduce 75 + T_CHAR reduce 75 + T_DOUBLE reduce 75 + T_FLOAT reduce 75 + T_INT reduce 75 + T_VOID reduce 75 + T_LONG reduce 75 + T_SHORT reduce 75 + T_SIGNED reduce 75 + T_UNSIGNED reduce 75 + T_ENUM reduce 75 + T_STRUCT reduce 75 + T_UNION reduce 75 + T_Bool reduce 75 + T_Complex reduce 75 + T_Imaginary reduce 75 + T_TYPE_QUALIFIER reduce 75 + T_BRACKETS reduce 75 + ';' reduce 75 + ',' reduce 75 + ')' reduce 75 + + braces goto 108 + + +state 80 + enum_specifier : enumeration braces . (74) + + . reduce 74 + + +state 81 + translation_unit : translation_unit external_declaration . (4) + + . reduce 4 + + +state 82 + type_specifier : T_TYPEDEF_NAME . (58) + + . reduce 58 + + +83: shift/reduce conflict (shift 82, reduce 17) on T_TYPEDEF_NAME +state 83 + declaration : any_typedef decl_specifiers . $$1 opt_declarator_list ';' (18) + decl_specifiers : decl_specifiers . decl_specifier (36) + $$1 : . (17) + + T_TYPEDEF_NAME shift 82 + T_DEFINE_NAME shift 7 + T_AUTO shift 8 + T_EXTERN shift 65 + T_REGISTER shift 10 + T_STATIC shift 11 + T_INLINE shift 13 + T_EXTENSION shift 66 + T_CHAR shift 15 + T_DOUBLE shift 16 + T_FLOAT shift 17 + T_INT shift 18 + T_VOID shift 19 + T_LONG shift 20 + T_SHORT shift 21 + T_SIGNED shift 22 + T_UNSIGNED shift 23 + T_ENUM shift 24 + T_STRUCT shift 25 + T_UNION shift 26 + T_Bool shift 27 + T_Complex shift 28 + T_Imaginary shift 29 + T_TYPE_QUALIFIER shift 30 + '(' reduce 17 + '*' reduce 17 + '&' reduce 17 + T_IDENTIFIER reduce 17 + ';' reduce 17 + + decl_specifier goto 68 + storage_class goto 36 + type_specifier goto 37 + type_qualifier goto 38 + struct_or_union_specifier goto 39 + enum_specifier goto 40 + struct_or_union goto 43 + enumeration goto 47 + $$1 goto 109 + + +state 84 + direct_declarator : '(' declarator ')' . (82) + + . reduce 82 + + +state 85 + pointer : '*' opt_type_qualifiers pointer . (87) + + . reduce 87 + + +state 86 + type_qualifier_list : type_qualifier_list type_qualifier . (91) + + . reduce 91 + + +state 87 + declaration : decl_specifiers . ';' (15) + declaration : decl_specifiers . init_declarator_list ';' (16) + decl_specifiers : decl_specifiers . decl_specifier (36) + + '(' shift 2 + '*' shift 3 + '&' shift 4 + T_IDENTIFIER shift 5 + T_TYPEDEF_NAME shift 6 + T_DEFINE_NAME shift 7 + T_AUTO shift 8 + T_EXTERN shift 65 + T_REGISTER shift 10 + T_STATIC shift 11 + T_INLINE shift 13 + T_EXTENSION shift 66 + T_CHAR shift 15 + T_DOUBLE shift 16 + T_FLOAT shift 17 + T_INT shift 18 + T_VOID shift 19 + T_LONG shift 20 + T_SHORT shift 21 + T_SIGNED shift 22 + T_UNSIGNED shift 23 + T_ENUM shift 24 + T_STRUCT shift 25 + T_UNION shift 26 + T_Bool shift 27 + T_Complex shift 28 + T_Imaginary shift 29 + T_TYPE_QUALIFIER shift 30 + ';' shift 67 + . error + + decl_specifier goto 68 + storage_class goto 36 + type_specifier goto 37 + type_qualifier goto 38 + struct_or_union_specifier goto 39 + enum_specifier goto 40 + init_declarator_list goto 69 + init_declarator goto 70 + declarator goto 110 + direct_declarator goto 42 + struct_or_union goto 43 + pointer goto 44 + any_id goto 45 + identifier_or_ref goto 46 + enumeration goto 47 + + +state 88 + linkage_specification : T_EXTERN T_STRING_LITERAL declaration . (14) + + . reduce 14 + + +state 89 + linkage_specification : T_EXTERN T_STRING_LITERAL braces . (13) + + . reduce 13 + + +state 90 + external_declaration : T_ASM T_ASMARG ';' . (9) + + . reduce 9 + + +state 91 + declaration : decl_specifiers init_declarator_list ';' . (16) + + . reduce 16 + + +state 92 + init_declarator_list : init_declarator_list ',' . init_declarator (69) + + '(' shift 2 + '*' shift 3 + '&' shift 4 + T_IDENTIFIER shift 5 + T_TYPEDEF_NAME shift 56 + . error + + init_declarator goto 111 + declarator goto 110 + direct_declarator goto 42 + pointer goto 44 + any_id goto 45 + identifier_or_ref goto 46 + + +state 93 + init_declarator : declarator '=' . $$5 T_INITIALIZER (72) + $$5 : . (71) + + . reduce 71 + + $$5 goto 112 + + +state 94 + function_definition : decl_specifiers declarator $$2 . opt_declaration_list T_LBRACE $$3 T_MATCHRBRACE (27) + opt_declaration_list : . (30) + + T_TYPEDEF_NAME shift 82 + T_DEFINE_NAME shift 7 + T_AUTO shift 8 + T_EXTERN shift 65 + T_REGISTER shift 10 + T_STATIC shift 11 + T_TYPEDEF shift 12 + T_INLINE shift 13 + T_EXTENSION shift 14 + T_CHAR shift 15 + T_DOUBLE shift 16 + T_FLOAT shift 17 + T_INT shift 18 + T_VOID shift 19 + T_LONG shift 20 + T_SHORT shift 21 + T_SIGNED shift 22 + T_UNSIGNED shift 23 + T_ENUM shift 24 + T_STRUCT shift 25 + T_UNION shift 26 + T_Bool shift 27 + T_Complex shift 28 + T_Imaginary shift 29 + T_TYPE_QUALIFIER shift 30 + T_VA_DCL shift 95 + T_LBRACE reduce 30 + + decl_specifiers goto 87 + decl_specifier goto 35 + storage_class goto 36 + type_specifier goto 37 + type_qualifier goto 38 + struct_or_union_specifier goto 39 + enum_specifier goto 40 + struct_or_union goto 43 + enumeration goto 47 + declaration goto 96 + any_typedef goto 53 + opt_declaration_list goto 113 + declaration_list goto 98 + + +state 95 + opt_declaration_list : T_VA_DCL . (31) + + . reduce 31 + + +state 96 + declaration_list : declaration . (33) + + . reduce 33 + + +state 97 + function_definition : declarator $$4 opt_declaration_list . T_LBRACE T_MATCHRBRACE (29) + + T_LBRACE shift 114 + . error + + +state 98 + opt_declaration_list : declaration_list . (32) + declaration_list : declaration_list . declaration (34) + + T_TYPEDEF_NAME shift 82 + T_DEFINE_NAME shift 7 + T_AUTO shift 8 + T_EXTERN shift 65 + T_REGISTER shift 10 + T_STATIC shift 11 + T_TYPEDEF shift 12 + T_INLINE shift 13 + T_EXTENSION shift 14 + T_CHAR shift 15 + T_DOUBLE shift 16 + T_FLOAT shift 17 + T_INT shift 18 + T_VOID shift 19 + T_LONG shift 20 + T_SHORT shift 21 + T_SIGNED shift 22 + T_UNSIGNED shift 23 + T_ENUM shift 24 + T_STRUCT shift 25 + T_UNION shift 26 + T_Bool shift 27 + T_Complex shift 28 + T_Imaginary shift 29 + T_TYPE_QUALIFIER shift 30 + T_LBRACE reduce 32 + + decl_specifiers goto 87 + decl_specifier goto 35 + storage_class goto 36 + type_specifier goto 37 + type_qualifier goto 38 + struct_or_union_specifier goto 39 + enum_specifier goto 40 + struct_or_union goto 43 + enumeration goto 47 + declaration goto 115 + any_typedef goto 53 + + +state 99 + decl_specifiers : decl_specifiers . decl_specifier (36) + parameter_declaration : decl_specifiers . declarator (96) + parameter_declaration : decl_specifiers . abs_declarator (97) + parameter_declaration : decl_specifiers . (98) + + '(' shift 116 + '*' shift 3 + '&' shift 4 + T_IDENTIFIER shift 5 + T_TYPEDEF_NAME shift 6 + T_DEFINE_NAME shift 7 + T_AUTO shift 8 + T_EXTERN shift 65 + T_REGISTER shift 10 + T_STATIC shift 11 + T_INLINE shift 13 + T_EXTENSION shift 66 + T_CHAR shift 15 + T_DOUBLE shift 16 + T_FLOAT shift 17 + T_INT shift 18 + T_VOID shift 19 + T_LONG shift 20 + T_SHORT shift 21 + T_SIGNED shift 22 + T_UNSIGNED shift 23 + T_ENUM shift 24 + T_STRUCT shift 25 + T_UNION shift 26 + T_Bool shift 27 + T_Complex shift 28 + T_Imaginary shift 29 + T_TYPE_QUALIFIER shift 30 + T_BRACKETS shift 117 + ',' reduce 98 + ')' reduce 98 + + decl_specifier goto 68 + storage_class goto 36 + type_specifier goto 37 + type_qualifier goto 38 + struct_or_union_specifier goto 39 + enum_specifier goto 40 + declarator goto 118 + direct_declarator goto 42 + abs_declarator goto 119 + direct_abs_declarator goto 120 + struct_or_union goto 43 + pointer goto 121 + any_id goto 45 + identifier_or_ref goto 46 + enumeration goto 47 + + +state 100 + direct_declarator : direct_declarator '(' parameter_type_list . ')' (84) + + ')' shift 122 + . error + + +state 101 + parameter_type_list : parameter_list . (92) + parameter_type_list : parameter_list . ',' T_ELLIPSIS (93) + parameter_list : parameter_list . ',' parameter_declaration (95) + + ',' shift 123 + ')' reduce 92 + + +state 102 + parameter_list : parameter_declaration . (94) + + . reduce 94 + + +state 103 + direct_declarator : direct_declarator '(' opt_identifier_list . ')' (85) + + ')' shift 124 + . error + + +state 104 + opt_identifier_list : identifier_list . (100) + identifier_list : identifier_list . ',' any_id (102) + + ',' shift 125 + ')' reduce 100 + + +state 105 + identifier_list : any_id . (101) + + . reduce 101 + + +state 106 + braces : T_LBRACE T_MATCHRBRACE . (12) + + . reduce 12 + + +state 107 + struct_or_union_specifier : struct_or_union any_id braces . (63) + + . reduce 63 + + +state 108 + enum_specifier : enumeration any_id braces . (73) + + . reduce 73 + + +state 109 + declaration : any_typedef decl_specifiers $$1 . opt_declarator_list ';' (18) + opt_declarator_list : . (21) + + '(' shift 2 + '*' shift 3 + '&' shift 4 + T_IDENTIFIER shift 5 + T_TYPEDEF_NAME shift 56 + ';' reduce 21 + + declarator goto 126 + direct_declarator goto 42 + pointer goto 44 + any_id goto 45 + identifier_or_ref goto 46 + opt_declarator_list goto 127 + declarator_list goto 128 + + +state 110 + init_declarator : declarator . (70) + init_declarator : declarator . '=' $$5 T_INITIALIZER (72) + + '=' shift 93 + ';' reduce 70 + ',' reduce 70 + + +state 111 + init_declarator_list : init_declarator_list ',' init_declarator . (69) + + . reduce 69 + + +state 112 + init_declarator : declarator '=' $$5 . T_INITIALIZER (72) + + T_INITIALIZER shift 129 + . error + + +state 113 + function_definition : decl_specifiers declarator $$2 opt_declaration_list . T_LBRACE $$3 T_MATCHRBRACE (27) + + T_LBRACE shift 130 + . error + + +state 114 + function_definition : declarator $$4 opt_declaration_list T_LBRACE . T_MATCHRBRACE (29) + + T_MATCHRBRACE shift 131 + . error + + +state 115 + declaration_list : declaration_list declaration . (34) + + . reduce 34 + + +state 116 + direct_declarator : '(' . declarator ')' (82) + direct_abs_declarator : '(' . abs_declarator ')' (108) + direct_abs_declarator : '(' . parameter_type_list ')' (113) + direct_abs_declarator : '(' . ')' (114) + + '(' shift 116 + '*' shift 3 + '&' shift 4 + T_IDENTIFIER shift 5 + T_TYPEDEF_NAME shift 6 + T_DEFINE_NAME shift 7 + T_AUTO shift 8 + T_EXTERN shift 65 + T_REGISTER shift 10 + T_STATIC shift 11 + T_INLINE shift 13 + T_EXTENSION shift 66 + T_CHAR shift 15 + T_DOUBLE shift 16 + T_FLOAT shift 17 + T_INT shift 18 + T_VOID shift 19 + T_LONG shift 20 + T_SHORT shift 21 + T_SIGNED shift 22 + T_UNSIGNED shift 23 + T_ENUM shift 24 + T_STRUCT shift 25 + T_UNION shift 26 + T_Bool shift 27 + T_Complex shift 28 + T_Imaginary shift 29 + T_TYPE_QUALIFIER shift 30 + T_BRACKETS shift 117 + ')' shift 132 + . error + + decl_specifiers goto 99 + decl_specifier goto 35 + storage_class goto 36 + type_specifier goto 37 + type_qualifier goto 38 + struct_or_union_specifier goto 39 + enum_specifier goto 40 + declarator goto 57 + direct_declarator goto 42 + abs_declarator goto 133 + direct_abs_declarator goto 120 + parameter_type_list goto 134 + parameter_list goto 101 + parameter_declaration goto 102 + struct_or_union goto 43 + pointer goto 121 + any_id goto 45 + identifier_or_ref goto 46 + enumeration goto 47 + + +state 117 + direct_abs_declarator : T_BRACKETS . (110) + + . reduce 110 + + +state 118 + parameter_declaration : decl_specifiers declarator . (96) + + . reduce 96 + + +state 119 + parameter_declaration : decl_specifiers abs_declarator . (97) + + . reduce 97 + + +state 120 + abs_declarator : direct_abs_declarator . (107) + direct_abs_declarator : direct_abs_declarator . T_BRACKETS (109) + direct_abs_declarator : direct_abs_declarator . '(' parameter_type_list ')' (111) + direct_abs_declarator : direct_abs_declarator . '(' ')' (112) + + '(' shift 135 + T_BRACKETS shift 136 + ',' reduce 107 + ')' reduce 107 + + +state 121 + declarator : pointer . direct_declarator (79) + abs_declarator : pointer . (105) + abs_declarator : pointer . direct_abs_declarator (106) + + '(' shift 116 + '&' shift 4 + T_IDENTIFIER shift 5 + T_TYPEDEF_NAME shift 56 + T_BRACKETS shift 117 + ',' reduce 105 + ')' reduce 105 + + direct_declarator goto 78 + direct_abs_declarator goto 137 + any_id goto 45 + identifier_or_ref goto 46 + + +state 122 + direct_declarator : direct_declarator '(' parameter_type_list ')' . (84) + + . reduce 84 + + +state 123 + parameter_type_list : parameter_list ',' . T_ELLIPSIS (93) + parameter_list : parameter_list ',' . parameter_declaration (95) + + T_TYPEDEF_NAME shift 82 + T_DEFINE_NAME shift 7 + T_AUTO shift 8 + T_EXTERN shift 65 + T_REGISTER shift 10 + T_STATIC shift 11 + T_INLINE shift 13 + T_EXTENSION shift 66 + T_CHAR shift 15 + T_DOUBLE shift 16 + T_FLOAT shift 17 + T_INT shift 18 + T_VOID shift 19 + T_LONG shift 20 + T_SHORT shift 21 + T_SIGNED shift 22 + T_UNSIGNED shift 23 + T_ENUM shift 24 + T_STRUCT shift 25 + T_UNION shift 26 + T_Bool shift 27 + T_Complex shift 28 + T_Imaginary shift 29 + T_TYPE_QUALIFIER shift 30 + T_ELLIPSIS shift 138 + . error + + decl_specifiers goto 99 + decl_specifier goto 35 + storage_class goto 36 + type_specifier goto 37 + type_qualifier goto 38 + struct_or_union_specifier goto 39 + enum_specifier goto 40 + parameter_declaration goto 139 + struct_or_union goto 43 + enumeration goto 47 + + +state 124 + direct_declarator : direct_declarator '(' opt_identifier_list ')' . (85) + + . reduce 85 + + +state 125 + identifier_list : identifier_list ',' . any_id (102) + + T_IDENTIFIER shift 5 + T_TYPEDEF_NAME shift 56 + . error + + any_id goto 140 + + +state 126 + declarator_list : declarator . (23) + + . reduce 23 + + +state 127 + declaration : any_typedef decl_specifiers $$1 opt_declarator_list . ';' (18) + + ';' shift 141 + . error + + +state 128 + opt_declarator_list : declarator_list . (22) + declarator_list : declarator_list . ',' declarator (24) + + ',' shift 142 + ';' reduce 22 + + +state 129 + init_declarator : declarator '=' $$5 T_INITIALIZER . (72) + + . reduce 72 + + +state 130 + function_definition : decl_specifiers declarator $$2 opt_declaration_list T_LBRACE . $$3 T_MATCHRBRACE (27) + $$3 : . (26) + + . reduce 26 + + $$3 goto 143 + + +state 131 + function_definition : declarator $$4 opt_declaration_list T_LBRACE T_MATCHRBRACE . (29) + + . reduce 29 + + +state 132 + direct_abs_declarator : '(' ')' . (114) + + . reduce 114 + + +state 133 + direct_abs_declarator : '(' abs_declarator . ')' (108) + + ')' shift 144 + . error + + +state 134 + direct_abs_declarator : '(' parameter_type_list . ')' (113) + + ')' shift 145 + . error + + +state 135 + direct_abs_declarator : direct_abs_declarator '(' . parameter_type_list ')' (111) + direct_abs_declarator : direct_abs_declarator '(' . ')' (112) + + T_TYPEDEF_NAME shift 82 + T_DEFINE_NAME shift 7 + T_AUTO shift 8 + T_EXTERN shift 65 + T_REGISTER shift 10 + T_STATIC shift 11 + T_INLINE shift 13 + T_EXTENSION shift 66 + T_CHAR shift 15 + T_DOUBLE shift 16 + T_FLOAT shift 17 + T_INT shift 18 + T_VOID shift 19 + T_LONG shift 20 + T_SHORT shift 21 + T_SIGNED shift 22 + T_UNSIGNED shift 23 + T_ENUM shift 24 + T_STRUCT shift 25 + T_UNION shift 26 + T_Bool shift 27 + T_Complex shift 28 + T_Imaginary shift 29 + T_TYPE_QUALIFIER shift 30 + ')' shift 146 + . error + + decl_specifiers goto 99 + decl_specifier goto 35 + storage_class goto 36 + type_specifier goto 37 + type_qualifier goto 38 + struct_or_union_specifier goto 39 + enum_specifier goto 40 + parameter_type_list goto 147 + parameter_list goto 101 + parameter_declaration goto 102 + struct_or_union goto 43 + enumeration goto 47 + + +state 136 + direct_abs_declarator : direct_abs_declarator T_BRACKETS . (109) + + . reduce 109 + + +state 137 + abs_declarator : pointer direct_abs_declarator . (106) + direct_abs_declarator : direct_abs_declarator . T_BRACKETS (109) + direct_abs_declarator : direct_abs_declarator . '(' parameter_type_list ')' (111) + direct_abs_declarator : direct_abs_declarator . '(' ')' (112) + + '(' shift 135 + T_BRACKETS shift 136 + ',' reduce 106 + ')' reduce 106 + + +state 138 + parameter_type_list : parameter_list ',' T_ELLIPSIS . (93) + + . reduce 93 + + +state 139 + parameter_list : parameter_list ',' parameter_declaration . (95) + + . reduce 95 + + +state 140 + identifier_list : identifier_list ',' any_id . (102) + + . reduce 102 + + +state 141 + declaration : any_typedef decl_specifiers $$1 opt_declarator_list ';' . (18) + + . reduce 18 + + +state 142 + declarator_list : declarator_list ',' . declarator (24) + + '(' shift 2 + '*' shift 3 + '&' shift 4 + T_IDENTIFIER shift 5 + T_TYPEDEF_NAME shift 56 + . error + + declarator goto 148 + direct_declarator goto 42 + pointer goto 44 + any_id goto 45 + identifier_or_ref goto 46 + + +state 143 + function_definition : decl_specifiers declarator $$2 opt_declaration_list T_LBRACE $$3 . T_MATCHRBRACE (27) + + T_MATCHRBRACE shift 149 + . error + + +state 144 + direct_abs_declarator : '(' abs_declarator ')' . (108) + + . reduce 108 + + +state 145 + direct_abs_declarator : '(' parameter_type_list ')' . (113) + + . reduce 113 + + +state 146 + direct_abs_declarator : direct_abs_declarator '(' ')' . (112) + + . reduce 112 + + +state 147 + direct_abs_declarator : direct_abs_declarator '(' parameter_type_list . ')' (111) + + ')' shift 150 + . error + + +state 148 + declarator_list : declarator_list ',' declarator . (24) + + . reduce 24 + + +state 149 + function_definition : decl_specifiers declarator $$2 opt_declaration_list T_LBRACE $$3 T_MATCHRBRACE . (27) + + . reduce 27 + + +state 150 + direct_abs_declarator : direct_abs_declarator '(' parameter_type_list ')' . (111) + + . reduce 111 + + +State 6 contains 29 reduce/reduce conflicts. +State 83 contains 1 shift/reduce conflict. + + +44 terminals, 43 nonterminals +115 grammar rules, 151 states diff --git a/test/grammar.tab.c b/test/grammar.tab.c new file mode 100644 index 000000000000..64ffe1eae5a7 --- /dev/null +++ b/test/grammar.tab.c @@ -0,0 +1,2025 @@ +#ifndef lint +static const char yysccsid[] = "@(#)yaccpar 1.9 (Berkeley) 02/21/93"; +#endif + +#define YYBYACC 1 +#define YYMAJOR 1 +#define YYMINOR 9 + +#define YYEMPTY (-1) +#define yyclearin (yychar = YYEMPTY) +#define yyerrok (yyerrflag = 0) +#define YYRECOVERING() (yyerrflag != 0) + + +#ifndef yyparse +#define yyparse grammar_parse +#endif /* yyparse */ + +#ifndef yylex +#define yylex grammar_lex +#endif /* yylex */ + +#ifndef yyerror +#define yyerror grammar_error +#endif /* yyerror */ + +#ifndef yychar +#define yychar grammar_char +#endif /* yychar */ + +#ifndef yyval +#define yyval grammar_val +#endif /* yyval */ + +#ifndef yylval +#define yylval grammar_lval +#endif /* yylval */ + +#ifndef yydebug +#define yydebug grammar_debug +#endif /* yydebug */ + +#ifndef yynerrs +#define yynerrs grammar_nerrs +#endif /* yynerrs */ + +#ifndef yyerrflag +#define yyerrflag grammar_errflag +#endif /* yyerrflag */ + +#ifndef yylhs +#define yylhs grammar_lhs +#endif /* yylhs */ + +#ifndef yylen +#define yylen grammar_len +#endif /* yylen */ + +#ifndef yydefred +#define yydefred grammar_defred +#endif /* yydefred */ + +#ifndef yydgoto +#define yydgoto grammar_dgoto +#endif /* yydgoto */ + +#ifndef yysindex +#define yysindex grammar_sindex +#endif /* yysindex */ + +#ifndef yyrindex +#define yyrindex grammar_rindex +#endif /* yyrindex */ + +#ifndef yygindex +#define yygindex grammar_gindex +#endif /* yygindex */ + +#ifndef yytable +#define yytable grammar_table +#endif /* yytable */ + +#ifndef yycheck +#define yycheck grammar_check +#endif /* yycheck */ + +#ifndef yyname +#define yyname grammar_name +#endif /* yyname */ + +#ifndef yyrule +#define yyrule grammar_rule +#endif /* yyrule */ +#define YYPREFIX "grammar_" + +#define YYPURE 0 + +#line 9 "grammar.y" +#ifdef YYBISON +#include <stdlib.h> +#define YYSTYPE_IS_DECLARED +#define yyerror yaccError +#endif + +#if defined(YYBISON) || !defined(YYBYACC) +static void yyerror(const char *s); +#endif +#line 81 "grammar.y" +#include <stdio.h> +#include <ctype.h> +#include <string.h> + +#define OPT_LINTLIBRARY 1 + +#ifndef TRUE +#define TRUE (1) +#endif + +#ifndef FALSE +#define FALSE (0) +#endif + +/* #include "cproto.h" */ +#define MAX_TEXT_SIZE 1024 + +/* Prototype styles */ +#if OPT_LINTLIBRARY +#define PROTO_ANSI_LLIB -2 /* form ANSI lint-library source */ +#define PROTO_LINTLIBRARY -1 /* form lint-library source */ +#endif +#define PROTO_NONE 0 /* do not output any prototypes */ +#define PROTO_TRADITIONAL 1 /* comment out parameters */ +#define PROTO_ABSTRACT 2 /* comment out parameter names */ +#define PROTO_ANSI 3 /* ANSI C prototype */ + +typedef int PrototypeStyle; + +typedef char boolean; + +extern boolean types_out; +extern PrototypeStyle proto_style; + +#define ansiLintLibrary() (proto_style == PROTO_ANSI_LLIB) +#define knrLintLibrary() (proto_style == PROTO_LINTLIBRARY) +#define lintLibrary() (knrLintLibrary() || ansiLintLibrary()) + +#if OPT_LINTLIBRARY +#define FUNC_UNKNOWN -1 /* unspecified */ +#else +#define FUNC_UNKNOWN 0 /* unspecified (same as FUNC_NONE) */ +#endif +#define FUNC_NONE 0 /* not a function definition */ +#define FUNC_TRADITIONAL 1 /* traditional style */ +#define FUNC_ANSI 2 /* ANSI style */ +#define FUNC_BOTH 3 /* both styles */ + +typedef int FuncDefStyle; + +/* Source file text */ +typedef struct text { + char text[MAX_TEXT_SIZE]; /* source text */ + long begin; /* offset in temporary file */ +} Text; + +/* Declaration specifier flags */ +#define DS_NONE 0 /* default */ +#define DS_EXTERN 1 /* contains "extern" specifier */ +#define DS_STATIC 2 /* contains "static" specifier */ +#define DS_CHAR 4 /* contains "char" type specifier */ +#define DS_SHORT 8 /* contains "short" type specifier */ +#define DS_FLOAT 16 /* contains "float" type specifier */ +#define DS_INLINE 32 /* contains "inline" specifier */ +#define DS_JUNK 64 /* we're not interested in this declaration */ + +/* This structure stores information about a declaration specifier. */ +typedef struct decl_spec { + unsigned short flags; /* flags defined above */ + char *text; /* source text */ + long begin; /* offset in temporary file */ +} DeclSpec; + +/* This is a list of function parameters. */ +typedef struct _ParameterList { + struct parameter *first; /* pointer to first parameter in list */ + struct parameter *last; /* pointer to last parameter in list */ + long begin_comment; /* begin offset of comment */ + long end_comment; /* end offset of comment */ + char *comment; /* comment at start of parameter list */ +} ParameterList; + +/* This structure stores information about a declarator. */ +typedef struct _Declarator { + char *name; /* name of variable or function */ + char *text; /* source text */ + long begin; /* offset in temporary file */ + long begin_comment; /* begin offset of comment */ + long end_comment; /* end offset of comment */ + FuncDefStyle func_def; /* style of function definition */ + ParameterList params; /* function parameters */ + boolean pointer; /* TRUE if it declares a pointer */ + struct _Declarator *head; /* head function declarator */ + struct _Declarator *func_stack; /* stack of function declarators */ + struct _Declarator *next; /* next declarator in list */ +} Declarator; + +/* This structure stores information about a function parameter. */ +typedef struct parameter { + struct parameter *next; /* next parameter in list */ + DeclSpec decl_spec; + Declarator *declarator; + char *comment; /* comment following the parameter */ +} Parameter; + +/* This is a list of declarators. */ +typedef struct declarator_list { + Declarator *first; /* pointer to first declarator in list */ + Declarator *last; /* pointer to last declarator in list */ +} DeclaratorList; + +/* #include "symbol.h" */ +typedef struct symbol { + struct symbol *next; /* next symbol in list */ + char *name; /* name of symbol */ + char *value; /* value of symbol (for defines) */ + short flags; /* symbol attributes */ +} Symbol; + +/* parser stack entry type */ +typedef union { + Text text; + DeclSpec decl_spec; + Parameter *parameter; + ParameterList param_list; + Declarator *declarator; + DeclaratorList decl_list; +} YYSTYPE; + +/* The hash table length should be a prime number. */ +#define SYM_MAX_HASH 251 + +typedef struct symbol_table { + Symbol *bucket[SYM_MAX_HASH]; /* hash buckets */ +} SymbolTable; + +extern SymbolTable *new_symbol_table /* Create symbol table */ + (void); +extern void free_symbol_table /* Destroy symbol table */ + (SymbolTable *s); +extern Symbol *find_symbol /* Lookup symbol name */ + (SymbolTable *s, const char *n); +extern Symbol *new_symbol /* Define new symbol */ + (SymbolTable *s, const char *n, const char *v, int f); + +/* #include "semantic.h" */ +extern void new_decl_spec (DeclSpec *, const char *, long, int); +extern void free_decl_spec (DeclSpec *); +extern void join_decl_specs (DeclSpec *, DeclSpec *, DeclSpec *); +extern void check_untagged (DeclSpec *); +extern Declarator *new_declarator (const char *, const char *, long); +extern void free_declarator (Declarator *); +extern void new_decl_list (DeclaratorList *, Declarator *); +extern void free_decl_list (DeclaratorList *); +extern void add_decl_list (DeclaratorList *, DeclaratorList *, Declarator *); +extern Parameter *new_parameter (DeclSpec *, Declarator *); +extern void free_parameter (Parameter *); +extern void new_param_list (ParameterList *, Parameter *); +extern void free_param_list (ParameterList *); +extern void add_param_list (ParameterList *, ParameterList *, Parameter *); +extern void new_ident_list (ParameterList *); +extern void add_ident_list (ParameterList *, ParameterList *, const char *); +extern void set_param_types (ParameterList *, DeclSpec *, DeclaratorList *); +extern void gen_declarations (DeclSpec *, DeclaratorList *); +extern void gen_prototype (DeclSpec *, Declarator *); +extern void gen_func_declarator (Declarator *); +extern void gen_func_definition (DeclSpec *, Declarator *); + +extern void init_parser (void); +extern void process_file (FILE *infile, char *name); +extern char *cur_text (void); +extern char *cur_file_name (void); +extern char *implied_typedef (void); +extern void include_file (char *name, int convert); +extern char *supply_parm (int count); +extern char *xstrdup (const char *); +extern int already_declared (char *name); +extern int is_actual_func (Declarator *d); +extern int lint_ellipsis (Parameter *p); +extern int want_typedef (void); +extern void begin_tracking (void); +extern void begin_typedef (void); +extern void copy_typedef (char *s); +extern void ellipsis_varargs (Declarator *d); +extern void end_typedef (void); +extern void flush_varargs (void); +extern void fmt_library (int code); +extern void imply_typedef (const char *s); +extern void indent (FILE *outf); +extern void put_blankline (FILE *outf); +extern void put_body (FILE *outf, DeclSpec *decl_spec, Declarator *declarator); +extern void put_char (FILE *outf, int c); +extern void put_error (void); +extern void put_newline (FILE *outf); +extern void put_padded (FILE *outf, const char *s); +extern void put_string (FILE *outf, const char *s); +extern void track_in (void); + +extern boolean file_comments; +extern FuncDefStyle func_style; +extern char base_file[]; + +extern int yylex (void); + +/* declaration specifier attributes for the typedef statement currently being + * scanned + */ +static int cur_decl_spec_flags; + +/* pointer to parameter list for the current function definition */ +static ParameterList *func_params; + +/* A parser semantic action sets this pointer to the current declarator in + * a function parameter declaration in order to catch any comments following + * the parameter declaration on the same line. If the lexer scans a comment + * and <cur_declarator> is not NULL, then the comment is attached to the + * declarator. To ignore subsequent comments, the lexer sets this to NULL + * after scanning a comment or end of line. + */ +static Declarator *cur_declarator; + +/* temporary string buffer */ +static char buf[MAX_TEXT_SIZE]; + +/* table of typedef names */ +static SymbolTable *typedef_names; + +/* table of define names */ +static SymbolTable *define_names; + +/* table of type qualifiers */ +static SymbolTable *type_qualifiers; + +/* information about the current input file */ +typedef struct { + char *base_name; /* base input file name */ + char *file_name; /* current file name */ + FILE *file; /* input file */ + unsigned line_num; /* current line number in input file */ + FILE *tmp_file; /* temporary file */ + long begin_comment; /* tmp file offset after last written ) or ; */ + long end_comment; /* tmp file offset after last comment */ + boolean convert; /* if TRUE, convert function definitions */ + boolean changed; /* TRUE if conversion done in this file */ +} IncludeStack; + +static IncludeStack *cur_file; /* current input file */ + +/* #include "yyerror.c" */ + +static int haveAnsiParam (void); + + +/* Flags to enable us to find if a procedure returns a value. + */ +static int return_val; /* nonzero on BRACES iff return-expression found */ + +static const char * +dft_decl_spec (void) +{ + return (lintLibrary() && !return_val) ? "void" : "int"; +} + +static int +haveAnsiParam (void) +{ + Parameter *p; + if (func_params != 0) { + for (p = func_params->first; p != 0; p = p->next) { + if (p->declarator->func_def == FUNC_ANSI) { + return TRUE; + } + } + } + return FALSE; +} +#line 386 "grammar.tab.c" + +/* compatibility with bison */ +#ifdef YYPARSE_PARAM +/* compatibility with FreeBSD */ +# ifdef YYPARSE_PARAM_TYPE +# define YYPARSE_DECL() yyparse(YYPARSE_PARAM_TYPE YYPARSE_PARAM) +# else +# define YYPARSE_DECL() yyparse(void *YYPARSE_PARAM) +# endif +#else +# define YYPARSE_DECL() yyparse(void) +#endif + +/* Parameters sent to lex. */ +#ifdef YYLEX_PARAM +# define YYLEX_DECL() yylex(void *YYLEX_PARAM) +# define YYLEX yylex(YYLEX_PARAM) +#else +# define YYLEX_DECL() yylex(void) +# define YYLEX yylex() +#endif + +/* Parameters sent to yyerror. */ +#ifndef YYERROR_DECL +#define YYERROR_DECL() yyerror(const char *s) +#endif +#ifndef YYERROR_CALL +#define YYERROR_CALL(msg) yyerror(msg) +#endif + +extern int YYPARSE_DECL(); + +#define T_IDENTIFIER 257 +#define T_TYPEDEF_NAME 258 +#define T_DEFINE_NAME 259 +#define T_AUTO 260 +#define T_EXTERN 261 +#define T_REGISTER 262 +#define T_STATIC 263 +#define T_TYPEDEF 264 +#define T_INLINE 265 +#define T_EXTENSION 266 +#define T_CHAR 267 +#define T_DOUBLE 268 +#define T_FLOAT 269 +#define T_INT 270 +#define T_VOID 271 +#define T_LONG 272 +#define T_SHORT 273 +#define T_SIGNED 274 +#define T_UNSIGNED 275 +#define T_ENUM 276 +#define T_STRUCT 277 +#define T_UNION 278 +#define T_Bool 279 +#define T_Complex 280 +#define T_Imaginary 281 +#define T_TYPE_QUALIFIER 282 +#define T_BRACKETS 283 +#define T_LBRACE 284 +#define T_MATCHRBRACE 285 +#define T_ELLIPSIS 286 +#define T_INITIALIZER 287 +#define T_STRING_LITERAL 288 +#define T_ASM 289 +#define T_ASMARG 290 +#define T_VA_DCL 291 +#define YYERRCODE 256 +static const short grammar_lhs[] = { -1, + 0, 0, 26, 26, 27, 27, 27, 27, 27, 27, + 27, 31, 30, 30, 28, 28, 34, 28, 32, 32, + 33, 33, 35, 35, 37, 38, 29, 39, 29, 36, + 36, 36, 40, 40, 1, 1, 2, 2, 2, 3, + 3, 3, 3, 3, 3, 4, 4, 4, 4, 4, + 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, + 5, 5, 6, 6, 6, 19, 19, 8, 8, 9, + 41, 9, 7, 7, 7, 25, 23, 23, 10, 10, + 11, 11, 11, 11, 11, 20, 20, 21, 21, 22, + 22, 14, 14, 15, 15, 16, 16, 16, 17, 17, + 18, 18, 24, 24, 12, 12, 12, 13, 13, 13, + 13, 13, 13, 13, +}; +static const short grammar_len[] = { 2, + 0, 1, 1, 2, 1, 1, 1, 1, 3, 2, + 2, 2, 3, 3, 2, 3, 0, 5, 2, 1, + 0, 1, 1, 3, 0, 0, 7, 0, 5, 0, + 1, 1, 1, 2, 1, 2, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 3, 2, 2, 1, 1, 1, 3, 1, + 0, 4, 3, 2, 2, 1, 1, 1, 2, 1, + 1, 3, 2, 4, 4, 2, 3, 0, 1, 1, + 2, 1, 3, 1, 3, 2, 2, 1, 0, 1, + 1, 3, 1, 2, 1, 2, 1, 3, 2, 1, + 4, 3, 3, 2, +}; +static const short grammar_defred[] = { 0, + 0, 0, 0, 0, 77, 0, 62, 40, 0, 42, + 43, 20, 44, 0, 46, 47, 48, 49, 54, 50, + 51, 52, 53, 76, 66, 67, 55, 56, 57, 61, + 0, 7, 0, 0, 35, 37, 38, 39, 59, 60, + 28, 0, 0, 0, 103, 81, 0, 0, 3, 5, + 6, 8, 0, 10, 11, 78, 0, 90, 0, 0, + 104, 0, 19, 0, 41, 45, 15, 36, 0, 68, + 0, 0, 0, 83, 0, 0, 64, 0, 0, 74, + 4, 58, 0, 82, 87, 91, 0, 14, 13, 9, + 16, 0, 71, 0, 31, 33, 0, 0, 0, 0, + 0, 94, 0, 0, 101, 12, 63, 73, 0, 0, + 69, 0, 0, 0, 34, 0, 110, 96, 97, 0, + 0, 84, 0, 85, 0, 23, 0, 0, 72, 26, + 29, 114, 0, 0, 0, 109, 0, 93, 95, 102, + 18, 0, 0, 108, 113, 112, 0, 24, 27, 111, +}; +static const short grammar_dgoto[] = { 33, + 87, 35, 36, 37, 38, 39, 40, 69, 70, 41, + 42, 119, 120, 100, 101, 102, 103, 104, 43, 44, + 59, 60, 45, 46, 47, 48, 49, 50, 51, 52, + 77, 53, 127, 109, 128, 97, 94, 143, 72, 98, + 112, +}; +static const short grammar_sindex[] = { -2, + -3, 27, -239, -177, 0, 0, 0, 0, -274, 0, + 0, 0, 0, -246, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + -266, 0, 0, 455, 0, 0, 0, 0, 0, 0, + 0, -35, -245, 128, 0, 0, -245, -2, 0, 0, + 0, 0, 642, 0, 0, 0, -15, 0, -12, -239, + 0, 590, 0, -27, 0, 0, 0, 0, -10, 0, + -11, 534, -72, 0, -237, -232, 0, -35, -232, 0, + 0, 0, 642, 0, 0, 0, 455, 0, 0, 0, + 0, 27, 0, 534, 0, 0, -222, 617, 209, 34, + 39, 0, 44, 42, 0, 0, 0, 0, 27, -11, + 0, -200, -196, -195, 0, 174, 0, 0, 0, -33, + 243, 0, 561, 0, -177, 0, 33, 49, 0, 0, + 0, 0, 53, 55, 417, 0, -33, 0, 0, 0, + 0, 27, -188, 0, 0, 0, 57, 0, 0, 0, +}; +static const short grammar_rindex[] = { 99, + 0, 0, 275, 0, 0, -38, 0, 0, 481, 0, + 0, 0, 0, 509, 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, 30, 0, 0, 0, 0, 0, 101, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 343, 309, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 98, -182, 62, 0, 0, 133, 0, 64, 379, 0, + 0, 0, -5, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, -182, 0, 0, 0, -180, -19, 0, + 65, 0, 0, 68, 0, 0, 0, 0, 51, 9, + 0, 0, 0, 0, 0, 0, 0, 0, 0, -13, + 19, 0, 0, 0, 0, 0, 0, 52, 0, 0, + 0, 0, 0, 0, 0, 0, 35, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, +}; +static const short grammar_gindex[] = { 0, + 11, -17, 0, 0, 13, 0, 0, 0, 20, 8, + -43, -1, -8, -89, 0, -9, 0, 0, 0, -44, + 0, 0, 4, 0, 0, 0, 70, -53, 0, 0, + -18, 0, 0, 0, 0, 22, 0, 0, 0, 0, + 0, +}; +#define YYTABLESIZE 924 +static const short grammar_table[] = { 58, + 78, 58, 58, 58, 73, 58, 135, 61, 88, 57, + 34, 5, 56, 62, 85, 58, 68, 63, 96, 7, + 58, 98, 78, 64, 98, 84, 134, 107, 80, 3, + 107, 90, 17, 92, 17, 4, 17, 2, 75, 3, + 96, 71, 30, 89, 115, 147, 76, 106, 91, 93, + 79, 75, 70, 17, 121, 55, 32, 107, 34, 105, + 108, 114, 105, 83, 4, 68, 2, 70, 3, 68, + 80, 121, 86, 80, 122, 106, 105, 78, 106, 5, + 56, 68, 123, 99, 124, 125, 129, 130, 80, 131, + 80, 141, 142, 144, 110, 145, 149, 150, 1, 110, + 2, 30, 99, 32, 79, 92, 118, 79, 100, 21, + 22, 111, 137, 139, 133, 113, 126, 81, 0, 0, + 0, 0, 79, 57, 79, 0, 99, 0, 140, 0, + 0, 0, 0, 99, 0, 0, 0, 0, 0, 0, + 0, 70, 0, 0, 0, 99, 0, 0, 0, 148, + 0, 0, 0, 0, 0, 0, 70, 0, 0, 0, + 0, 0, 0, 0, 0, 4, 0, 2, 0, 0, + 65, 0, 65, 65, 65, 0, 65, 0, 0, 0, + 0, 0, 0, 0, 5, 6, 7, 8, 65, 10, + 11, 65, 13, 66, 15, 16, 17, 18, 19, 20, + 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, + 0, 4, 0, 116, 132, 3, 0, 0, 58, 58, + 58, 58, 58, 58, 58, 78, 58, 58, 58, 58, + 58, 58, 58, 58, 58, 58, 58, 58, 58, 58, + 58, 58, 58, 58, 58, 78, 4, 74, 116, 136, + 3, 17, 78, 1, 5, 6, 7, 8, 9, 10, + 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, + 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, + 4, 54, 116, 5, 56, 0, 31, 80, 80, 80, + 80, 80, 80, 80, 80, 80, 80, 80, 80, 80, + 80, 80, 80, 80, 80, 80, 80, 80, 80, 80, + 80, 80, 88, 80, 88, 88, 88, 0, 88, 0, + 80, 79, 79, 79, 79, 79, 79, 79, 79, 79, + 79, 79, 79, 79, 79, 79, 79, 79, 79, 79, + 79, 79, 79, 79, 79, 79, 89, 79, 89, 89, + 89, 0, 89, 0, 79, 25, 25, 25, 25, 25, + 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, + 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, + 86, 25, 86, 86, 5, 56, 86, 0, 25, 65, + 65, 65, 65, 65, 65, 65, 0, 65, 65, 65, + 65, 65, 65, 65, 65, 65, 65, 65, 65, 65, + 65, 65, 65, 65, 65, 65, 75, 0, 75, 75, + 75, 0, 75, 0, 0, 0, 0, 0, 0, 0, + 5, 6, 7, 8, 65, 10, 11, 75, 13, 66, + 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, + 25, 26, 27, 28, 29, 30, 117, 146, 0, 0, + 0, 0, 0, 0, 0, 5, 6, 7, 8, 65, + 10, 11, 0, 13, 66, 15, 16, 17, 18, 19, + 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, + 30, 117, 4, 0, 2, 0, 3, 0, 0, 5, + 56, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 67, 0, 0, 0, 0, 41, 0, + 41, 0, 41, 0, 0, 117, 0, 0, 0, 0, + 0, 88, 88, 0, 0, 0, 0, 0, 0, 41, + 0, 0, 0, 0, 0, 0, 45, 0, 45, 0, + 45, 0, 0, 0, 0, 0, 0, 88, 0, 0, + 0, 0, 0, 0, 0, 89, 89, 45, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 89, 0, 0, 0, 0, 0, 0, 0, 86, + 86, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 86, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 75, 75, 75, 75, 75, + 75, 75, 0, 75, 75, 75, 75, 75, 75, 75, + 75, 75, 75, 75, 75, 75, 75, 75, 75, 75, + 75, 75, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 82, 7, 8, 65, 10, 11, + 0, 13, 66, 15, 16, 17, 18, 19, 20, 21, + 22, 23, 24, 25, 26, 27, 28, 29, 30, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 5, 6, 7, 8, 65, 10, 11, 0, 13, + 66, 15, 16, 17, 18, 19, 20, 21, 22, 23, + 24, 25, 26, 27, 28, 29, 30, 41, 41, 41, + 41, 41, 41, 41, 0, 41, 41, 41, 41, 41, + 41, 41, 41, 41, 41, 41, 41, 41, 41, 41, + 41, 41, 41, 0, 0, 45, 45, 45, 45, 45, + 45, 45, 0, 45, 45, 45, 45, 45, 45, 45, + 45, 45, 45, 45, 45, 45, 45, 45, 45, 45, + 45, 82, 7, 8, 65, 10, 11, 12, 13, 14, + 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, + 25, 26, 27, 28, 29, 30, 0, 0, 82, 7, + 8, 65, 10, 11, 95, 13, 66, 15, 16, 17, + 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, + 28, 29, 30, 0, 0, 0, 138, 82, 7, 8, + 65, 10, 11, 12, 13, 14, 15, 16, 17, 18, + 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, + 29, 30, 0, 75, 82, 7, 8, 65, 10, 11, + 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, + 22, 23, 24, 25, 26, 27, 28, 29, 30, 82, + 7, 8, 65, 10, 11, 0, 13, 66, 15, 16, + 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, + 27, 28, 29, 30, +}; +static const short grammar_check[] = { 38, + 44, 40, 41, 42, 40, 44, 40, 4, 62, 2, + 0, 257, 258, 288, 59, 3, 34, 264, 72, 259, + 59, 41, 61, 290, 44, 41, 116, 41, 47, 42, + 44, 59, 38, 44, 40, 38, 42, 40, 284, 42, + 94, 34, 282, 62, 98, 135, 43, 285, 59, 61, + 47, 284, 44, 59, 99, 59, 59, 76, 48, 41, + 79, 284, 44, 53, 38, 83, 40, 59, 42, 87, + 41, 116, 60, 44, 41, 41, 73, 121, 44, 257, + 258, 99, 44, 73, 41, 44, 287, 284, 59, 285, + 61, 59, 44, 41, 87, 41, 285, 41, 0, 92, + 0, 284, 41, 284, 41, 41, 99, 44, 41, 59, + 59, 92, 121, 123, 116, 94, 109, 48, -1, -1, + -1, -1, 59, 116, 61, -1, 116, -1, 125, -1, + -1, -1, -1, 123, -1, -1, -1, -1, -1, -1, + -1, 44, -1, -1, -1, 135, -1, -1, -1, 142, + -1, -1, -1, -1, -1, -1, 59, -1, -1, -1, + -1, -1, -1, -1, -1, 38, -1, 40, -1, -1, + 38, -1, 40, 41, 42, -1, 44, -1, -1, -1, + -1, -1, -1, -1, 257, 258, 259, 260, 261, 262, + 263, 59, 265, 266, 267, 268, 269, 270, 271, 272, + 273, 274, 275, 276, 277, 278, 279, 280, 281, 282, + -1, 38, -1, 40, 41, 42, -1, -1, 257, 258, + 259, 260, 261, 262, 263, 264, 265, 266, 267, 268, + 269, 270, 271, 272, 273, 274, 275, 276, 277, 278, + 279, 280, 281, 282, 283, 284, 38, 283, 40, 283, + 42, 257, 291, 256, 257, 258, 259, 260, 261, 262, + 263, 264, 265, 266, 267, 268, 269, 270, 271, 272, + 273, 274, 275, 276, 277, 278, 279, 280, 281, 282, + 38, 285, 40, 257, 258, -1, 289, 258, 259, 260, + 261, 262, 263, 264, 265, 266, 267, 268, 269, 270, + 271, 272, 273, 274, 275, 276, 277, 278, 279, 280, + 281, 282, 38, 284, 40, 41, 42, -1, 44, -1, + 291, 258, 259, 260, 261, 262, 263, 264, 265, 266, + 267, 268, 269, 270, 271, 272, 273, 274, 275, 276, + 277, 278, 279, 280, 281, 282, 38, 284, 40, 41, + 42, -1, 44, -1, 291, 258, 259, 260, 261, 262, + 263, 264, 265, 266, 267, 268, 269, 270, 271, 272, + 273, 274, 275, 276, 277, 278, 279, 280, 281, 282, + 38, 284, 40, 41, 257, 258, 44, -1, 291, 257, + 258, 259, 260, 261, 262, 263, -1, 265, 266, 267, + 268, 269, 270, 271, 272, 273, 274, 275, 276, 277, + 278, 279, 280, 281, 282, 283, 38, -1, 40, 41, + 42, -1, 44, -1, -1, -1, -1, -1, -1, -1, + 257, 258, 259, 260, 261, 262, 263, 59, 265, 266, + 267, 268, 269, 270, 271, 272, 273, 274, 275, 276, + 277, 278, 279, 280, 281, 282, 283, 41, -1, -1, + -1, -1, -1, -1, -1, 257, 258, 259, 260, 261, + 262, 263, -1, 265, 266, 267, 268, 269, 270, 271, + 272, 273, 274, 275, 276, 277, 278, 279, 280, 281, + 282, 283, 38, -1, 40, -1, 42, -1, -1, 257, + 258, -1, -1, -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, 59, -1, -1, -1, -1, 38, -1, + 40, -1, 42, -1, -1, 283, -1, -1, -1, -1, + -1, 257, 258, -1, -1, -1, -1, -1, -1, 59, + -1, -1, -1, -1, -1, -1, 38, -1, 40, -1, + 42, -1, -1, -1, -1, -1, -1, 283, -1, -1, + -1, -1, -1, -1, -1, 257, 258, 59, -1, -1, + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, + -1, 283, -1, -1, -1, -1, -1, -1, -1, 257, + 258, -1, -1, -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, 283, -1, -1, -1, -1, + -1, -1, -1, -1, -1, 257, 258, 259, 260, 261, + 262, 263, -1, 265, 266, 267, 268, 269, 270, 271, + 272, 273, 274, 275, 276, 277, 278, 279, 280, 281, + 282, 283, -1, -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, 258, 259, 260, 261, 262, 263, + -1, 265, 266, 267, 268, 269, 270, 271, 272, 273, + 274, 275, 276, 277, 278, 279, 280, 281, 282, -1, + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, + -1, 257, 258, 259, 260, 261, 262, 263, -1, 265, + 266, 267, 268, 269, 270, 271, 272, 273, 274, 275, + 276, 277, 278, 279, 280, 281, 282, 257, 258, 259, + 260, 261, 262, 263, -1, 265, 266, 267, 268, 269, + 270, 271, 272, 273, 274, 275, 276, 277, 278, 279, + 280, 281, 282, -1, -1, 257, 258, 259, 260, 261, + 262, 263, -1, 265, 266, 267, 268, 269, 270, 271, + 272, 273, 274, 275, 276, 277, 278, 279, 280, 281, + 282, 258, 259, 260, 261, 262, 263, 264, 265, 266, + 267, 268, 269, 270, 271, 272, 273, 274, 275, 276, + 277, 278, 279, 280, 281, 282, -1, -1, 258, 259, + 260, 261, 262, 263, 291, 265, 266, 267, 268, 269, + 270, 271, 272, 273, 274, 275, 276, 277, 278, 279, + 280, 281, 282, -1, -1, -1, 286, 258, 259, 260, + 261, 262, 263, 264, 265, 266, 267, 268, 269, 270, + 271, 272, 273, 274, 275, 276, 277, 278, 279, 280, + 281, 282, -1, 284, 258, 259, 260, 261, 262, 263, + 264, 265, 266, 267, 268, 269, 270, 271, 272, 273, + 274, 275, 276, 277, 278, 279, 280, 281, 282, 258, + 259, 260, 261, 262, 263, -1, 265, 266, 267, 268, + 269, 270, 271, 272, 273, 274, 275, 276, 277, 278, + 279, 280, 281, 282, +}; +#define YYFINAL 33 +#ifndef YYDEBUG +#define YYDEBUG 0 +#endif +#define YYMAXTOKEN 291 +#if YYDEBUG +static const char *yyname[] = { + +"end-of-file",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,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,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,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,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,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,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,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,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, +"T_IDENTIFIER","T_TYPEDEF_NAME","T_DEFINE_NAME","T_AUTO","T_EXTERN", +"T_REGISTER","T_STATIC","T_TYPEDEF","T_INLINE","T_EXTENSION","T_CHAR", +"T_DOUBLE","T_FLOAT","T_INT","T_VOID","T_LONG","T_SHORT","T_SIGNED", +"T_UNSIGNED","T_ENUM","T_STRUCT","T_UNION","T_Bool","T_Complex","T_Imaginary", +"T_TYPE_QUALIFIER","T_BRACKETS","T_LBRACE","T_MATCHRBRACE","T_ELLIPSIS", +"T_INITIALIZER","T_STRING_LITERAL","T_ASM","T_ASMARG","T_VA_DCL", +}; +static const char *yyrule[] = { +"$accept : program", +"program :", +"program : translation_unit", +"translation_unit : external_declaration", +"translation_unit : translation_unit external_declaration", +"external_declaration : declaration", +"external_declaration : function_definition", +"external_declaration : ';'", +"external_declaration : linkage_specification", +"external_declaration : T_ASM T_ASMARG ';'", +"external_declaration : error T_MATCHRBRACE", +"external_declaration : error ';'", +"braces : T_LBRACE T_MATCHRBRACE", +"linkage_specification : T_EXTERN T_STRING_LITERAL braces", +"linkage_specification : T_EXTERN T_STRING_LITERAL declaration", +"declaration : decl_specifiers ';'", +"declaration : decl_specifiers init_declarator_list ';'", +"$$1 :", +"declaration : any_typedef decl_specifiers $$1 opt_declarator_list ';'", +"any_typedef : T_EXTENSION T_TYPEDEF", +"any_typedef : T_TYPEDEF", +"opt_declarator_list :", +"opt_declarator_list : declarator_list", +"declarator_list : declarator", +"declarator_list : declarator_list ',' declarator", +"$$2 :", +"$$3 :", +"function_definition : decl_specifiers declarator $$2 opt_declaration_list T_LBRACE $$3 T_MATCHRBRACE", +"$$4 :", +"function_definition : declarator $$4 opt_declaration_list T_LBRACE T_MATCHRBRACE", +"opt_declaration_list :", +"opt_declaration_list : T_VA_DCL", +"opt_declaration_list : declaration_list", +"declaration_list : declaration", +"declaration_list : declaration_list declaration", +"decl_specifiers : decl_specifier", +"decl_specifiers : decl_specifiers decl_specifier", +"decl_specifier : storage_class", +"decl_specifier : type_specifier", +"decl_specifier : type_qualifier", +"storage_class : T_AUTO", +"storage_class : T_EXTERN", +"storage_class : T_REGISTER", +"storage_class : T_STATIC", +"storage_class : T_INLINE", +"storage_class : T_EXTENSION", +"type_specifier : T_CHAR", +"type_specifier : T_DOUBLE", +"type_specifier : T_FLOAT", +"type_specifier : T_INT", +"type_specifier : T_LONG", +"type_specifier : T_SHORT", +"type_specifier : T_SIGNED", +"type_specifier : T_UNSIGNED", +"type_specifier : T_VOID", +"type_specifier : T_Bool", +"type_specifier : T_Complex", +"type_specifier : T_Imaginary", +"type_specifier : T_TYPEDEF_NAME", +"type_specifier : struct_or_union_specifier", +"type_specifier : enum_specifier", +"type_qualifier : T_TYPE_QUALIFIER", +"type_qualifier : T_DEFINE_NAME", +"struct_or_union_specifier : struct_or_union any_id braces", +"struct_or_union_specifier : struct_or_union braces", +"struct_or_union_specifier : struct_or_union any_id", +"struct_or_union : T_STRUCT", +"struct_or_union : T_UNION", +"init_declarator_list : init_declarator", +"init_declarator_list : init_declarator_list ',' init_declarator", +"init_declarator : declarator", +"$$5 :", +"init_declarator : declarator '=' $$5 T_INITIALIZER", +"enum_specifier : enumeration any_id braces", +"enum_specifier : enumeration braces", +"enum_specifier : enumeration any_id", +"enumeration : T_ENUM", +"any_id : T_IDENTIFIER", +"any_id : T_TYPEDEF_NAME", +"declarator : pointer direct_declarator", +"declarator : direct_declarator", +"direct_declarator : identifier_or_ref", +"direct_declarator : '(' declarator ')'", +"direct_declarator : direct_declarator T_BRACKETS", +"direct_declarator : direct_declarator '(' parameter_type_list ')'", +"direct_declarator : direct_declarator '(' opt_identifier_list ')'", +"pointer : '*' opt_type_qualifiers", +"pointer : '*' opt_type_qualifiers pointer", +"opt_type_qualifiers :", +"opt_type_qualifiers : type_qualifier_list", +"type_qualifier_list : type_qualifier", +"type_qualifier_list : type_qualifier_list type_qualifier", +"parameter_type_list : parameter_list", +"parameter_type_list : parameter_list ',' T_ELLIPSIS", +"parameter_list : parameter_declaration", +"parameter_list : parameter_list ',' parameter_declaration", +"parameter_declaration : decl_specifiers declarator", +"parameter_declaration : decl_specifiers abs_declarator", +"parameter_declaration : decl_specifiers", +"opt_identifier_list :", +"opt_identifier_list : identifier_list", +"identifier_list : any_id", +"identifier_list : identifier_list ',' any_id", +"identifier_or_ref : any_id", +"identifier_or_ref : '&' any_id", +"abs_declarator : pointer", +"abs_declarator : pointer direct_abs_declarator", +"abs_declarator : direct_abs_declarator", +"direct_abs_declarator : '(' abs_declarator ')'", +"direct_abs_declarator : direct_abs_declarator T_BRACKETS", +"direct_abs_declarator : T_BRACKETS", +"direct_abs_declarator : direct_abs_declarator '(' parameter_type_list ')'", +"direct_abs_declarator : direct_abs_declarator '(' ')'", +"direct_abs_declarator : '(' parameter_type_list ')'", +"direct_abs_declarator : '(' ')'", + +}; +#endif + +int yydebug; +int yynerrs; + +int yyerrflag; +int yychar; +YYSTYPE yyval; +YYSTYPE yylval; + +/* define the initial stack-sizes */ +#ifdef YYSTACKSIZE +#undef YYMAXDEPTH +#define YYMAXDEPTH YYSTACKSIZE +#else +#ifdef YYMAXDEPTH +#define YYSTACKSIZE YYMAXDEPTH +#else +#define YYSTACKSIZE 500 +#define YYMAXDEPTH 500 +#endif +#endif + +#define YYINITSTACKSIZE 500 + +typedef struct { + unsigned stacksize; + short *s_base; + short *s_mark; + short *s_last; + YYSTYPE *l_base; + YYSTYPE *l_mark; +} YYSTACKDATA; +/* variables for the parser stack */ +static YYSTACKDATA yystack; +#line 1014 "grammar.y" + +/* lex.yy.c */ +#define BEGIN yy_start = 1 + 2 * + +#define CPP1 1 +#define INIT1 2 +#define INIT2 3 +#define CURLY 4 +#define LEXYACC 5 +#define ASM 6 +#define CPP_INLINE 7 + +extern char *yytext; +extern FILE *yyin, *yyout; + +static int curly; /* number of curly brace nesting levels */ +static int ly_count; /* number of occurances of %% */ +static int inc_depth; /* include nesting level */ +static SymbolTable *included_files; /* files already included */ +static int yy_start = 0; /* start state number */ + +#define grammar_error(s) yaccError(s) + +static void +yaccError (const char *msg) +{ + func_params = NULL; + put_error(); /* tell what line we're on, and what file */ + fprintf(stderr, "%s at token '%s'\n", msg, yytext); +} + +/* Initialize the table of type qualifier keywords recognized by the lexical + * analyzer. + */ +void +init_parser (void) +{ + static const char *keywords[] = { + "const", + "restrict", + "volatile", + "interrupt", +#ifdef vms + "noshare", + "readonly", +#endif +#if defined(MSDOS) || defined(OS2) + "__cdecl", + "__export", + "__far", + "__fastcall", + "__fortran", + "__huge", + "__inline", + "__interrupt", + "__loadds", + "__near", + "__pascal", + "__saveregs", + "__segment", + "__stdcall", + "__syscall", + "_cdecl", + "_cs", + "_ds", + "_es", + "_export", + "_far", + "_fastcall", + "_fortran", + "_huge", + "_interrupt", + "_loadds", + "_near", + "_pascal", + "_saveregs", + "_seg", + "_segment", + "_ss", + "cdecl", + "far", + "huge", + "near", + "pascal", +#ifdef OS2 + "__far16", +#endif +#endif +#ifdef __GNUC__ + /* gcc aliases */ + "__builtin_va_arg", + "__builtin_va_list", + "__const", + "__const__", + "__inline", + "__inline__", + "__restrict", + "__restrict__", + "__volatile", + "__volatile__", +#endif + }; + unsigned i; + + /* Initialize type qualifier table. */ + type_qualifiers = new_symbol_table(); + for (i = 0; i < sizeof(keywords)/sizeof(keywords[0]); ++i) { + new_symbol(type_qualifiers, keywords[i], NULL, DS_NONE); + } +} + +/* Process the C source file. Write function prototypes to the standard + * output. Convert function definitions and write the converted source + * code to a temporary file. + */ +void +process_file (FILE *infile, char *name) +{ + char *s; + + if (strlen(name) > 2) { + s = name + strlen(name) - 2; + if (*s == '.') { + ++s; + if (*s == 'l' || *s == 'y') + BEGIN LEXYACC; +#if defined(MSDOS) || defined(OS2) + if (*s == 'L' || *s == 'Y') + BEGIN LEXYACC; +#endif + } + } + + included_files = new_symbol_table(); + typedef_names = new_symbol_table(); + define_names = new_symbol_table(); + inc_depth = -1; + curly = 0; + ly_count = 0; + func_params = NULL; + yyin = infile; + include_file(strcpy(base_file, name), func_style != FUNC_NONE); + if (file_comments) { +#if OPT_LINTLIBRARY + if (lintLibrary()) { + put_blankline(stdout); + begin_tracking(); + } +#endif + put_string(stdout, "/* "); + put_string(stdout, cur_file_name()); + put_string(stdout, " */\n"); + } + yyparse(); + free_symbol_table(define_names); + free_symbol_table(typedef_names); + free_symbol_table(included_files); +} + +#ifdef NO_LEAKS +void +free_parser(void) +{ + free_symbol_table (type_qualifiers); +#ifdef FLEX_SCANNER + if (yy_current_buffer != 0) + yy_delete_buffer(yy_current_buffer); +#endif +} +#endif +#line 1085 "grammar.tab.c" + +#if YYDEBUG +#include <stdio.h> /* needed for printf */ +#endif + +#include <stdlib.h> /* needed for malloc, etc */ +#include <string.h> /* needed for memset */ + +/* allocate initial stack or double stack size, up to YYMAXDEPTH */ +static int yygrowstack(YYSTACKDATA *data) +{ + int i; + unsigned newsize; + short *newss; + YYSTYPE *newvs; + + if ((newsize = data->stacksize) == 0) + newsize = YYINITSTACKSIZE; + else if (newsize >= YYMAXDEPTH) + return -1; + else if ((newsize *= 2) > YYMAXDEPTH) + newsize = YYMAXDEPTH; + + i = data->s_mark - data->s_base; + newss = (short *)realloc(data->s_base, newsize * sizeof(*newss)); + if (newss == 0) + return -1; + + data->s_base = newss; + data->s_mark = newss + i; + + newvs = (YYSTYPE *)realloc(data->l_base, newsize * sizeof(*newvs)); + if (newvs == 0) + return -1; + + data->l_base = newvs; + data->l_mark = newvs + i; + + data->stacksize = newsize; + data->s_last = data->s_base + newsize - 1; + return 0; +} + +#if YYPURE || defined(YY_NO_LEAKS) +static void yyfreestack(YYSTACKDATA *data) +{ + free(data->s_base); + free(data->l_base); + memset(data, 0, sizeof(*data)); +} +#else +#define yyfreestack(data) /* nothing */ +#endif + +#define YYABORT goto yyabort +#define YYREJECT goto yyabort +#define YYACCEPT goto yyaccept +#define YYERROR goto yyerrlab + +int +YYPARSE_DECL() +{ + int yym, yyn, yystate; +#if YYDEBUG + const char *yys; + + if ((yys = getenv("YYDEBUG")) != 0) + { + yyn = *yys; + if (yyn >= '0' && yyn <= '9') + yydebug = yyn - '0'; + } +#endif + + yynerrs = 0; + yyerrflag = 0; + yychar = YYEMPTY; + yystate = 0; + +#if YYPURE + memset(&yystack, 0, sizeof(yystack)); +#endif + + if (yystack.s_base == NULL && yygrowstack(&yystack)) goto yyoverflow; + yystack.s_mark = yystack.s_base; + yystack.l_mark = yystack.l_base; + yystate = 0; + *yystack.s_mark = 0; + +yyloop: + if ((yyn = yydefred[yystate]) != 0) goto yyreduce; + if (yychar < 0) + { + if ((yychar = YYLEX) < 0) yychar = 0; +#if YYDEBUG + if (yydebug) + { + yys = 0; + if (yychar <= YYMAXTOKEN) yys = yyname[yychar]; + if (!yys) yys = "illegal-symbol"; + printf("%sdebug: state %d, reading %d (%s)\n", + YYPREFIX, yystate, yychar, yys); + } +#endif + } + if ((yyn = yysindex[yystate]) && (yyn += yychar) >= 0 && + yyn <= YYTABLESIZE && yycheck[yyn] == yychar) + { +#if YYDEBUG + if (yydebug) + printf("%sdebug: state %d, shifting to state %d\n", + YYPREFIX, yystate, yytable[yyn]); +#endif + if (yystack.s_mark >= yystack.s_last && yygrowstack(&yystack)) + { + goto yyoverflow; + } + yystate = yytable[yyn]; + *++yystack.s_mark = yytable[yyn]; + *++yystack.l_mark = yylval; + yychar = YYEMPTY; + if (yyerrflag > 0) --yyerrflag; + goto yyloop; + } + if ((yyn = yyrindex[yystate]) && (yyn += yychar) >= 0 && + yyn <= YYTABLESIZE && yycheck[yyn] == yychar) + { + yyn = yytable[yyn]; + goto yyreduce; + } + if (yyerrflag) goto yyinrecovery; + + yyerror("syntax error"); + + goto yyerrlab; + +yyerrlab: + ++yynerrs; + +yyinrecovery: + if (yyerrflag < 3) + { + yyerrflag = 3; + for (;;) + { + if ((yyn = yysindex[*yystack.s_mark]) && (yyn += YYERRCODE) >= 0 && + yyn <= YYTABLESIZE && yycheck[yyn] == YYERRCODE) + { +#if YYDEBUG + if (yydebug) + printf("%sdebug: state %d, error recovery shifting\ + to state %d\n", YYPREFIX, *yystack.s_mark, yytable[yyn]); +#endif + if (yystack.s_mark >= yystack.s_last && yygrowstack(&yystack)) + { + goto yyoverflow; + } + yystate = yytable[yyn]; + *++yystack.s_mark = yytable[yyn]; + *++yystack.l_mark = yylval; + goto yyloop; + } + else + { +#if YYDEBUG + if (yydebug) + printf("%sdebug: error recovery discarding state %d\n", + YYPREFIX, *yystack.s_mark); +#endif + if (yystack.s_mark <= yystack.s_base) goto yyabort; + --yystack.s_mark; + --yystack.l_mark; + } + } + } + else + { + if (yychar == 0) goto yyabort; +#if YYDEBUG + if (yydebug) + { + yys = 0; + if (yychar <= YYMAXTOKEN) yys = yyname[yychar]; + if (!yys) yys = "illegal-symbol"; + printf("%sdebug: state %d, error recovery discards token %d (%s)\n", + YYPREFIX, yystate, yychar, yys); + } +#endif + yychar = YYEMPTY; + goto yyloop; + } + +yyreduce: +#if YYDEBUG + if (yydebug) + printf("%sdebug: state %d, reducing by rule %d (%s)\n", + YYPREFIX, yystate, yyn, yyrule[yyn]); +#endif + yym = yylen[yyn]; + if (yym) + yyval = yystack.l_mark[1-yym]; + else + memset(&yyval, 0, sizeof yyval); + switch (yyn) + { +case 10: +#line 377 "grammar.y" + { + yyerrok; + } +break; +case 11: +#line 381 "grammar.y" + { + yyerrok; + } +break; +case 13: +#line 392 "grammar.y" + { + /* Provide an empty action here so bison will not complain about + * incompatible types in the default action it normally would + * have generated. + */ + } +break; +case 14: +#line 399 "grammar.y" + { + /* empty */ + } +break; +case 15: +#line 406 "grammar.y" + { +#if OPT_LINTLIBRARY + if (types_out && want_typedef()) { + gen_declarations(&yystack.l_mark[-1].decl_spec, (DeclaratorList *)0); + flush_varargs(); + } +#endif + free_decl_spec(&yystack.l_mark[-1].decl_spec); + end_typedef(); + } +break; +case 16: +#line 417 "grammar.y" + { + if (func_params != NULL) { + set_param_types(func_params, &yystack.l_mark[-2].decl_spec, &yystack.l_mark[-1].decl_list); + } else { + gen_declarations(&yystack.l_mark[-2].decl_spec, &yystack.l_mark[-1].decl_list); +#if OPT_LINTLIBRARY + flush_varargs(); +#endif + free_decl_list(&yystack.l_mark[-1].decl_list); + } + free_decl_spec(&yystack.l_mark[-2].decl_spec); + end_typedef(); + } +break; +case 17: +#line 431 "grammar.y" + { + cur_decl_spec_flags = yystack.l_mark[0].decl_spec.flags; + free_decl_spec(&yystack.l_mark[0].decl_spec); + } +break; +case 18: +#line 436 "grammar.y" + { + end_typedef(); + } +break; +case 19: +#line 443 "grammar.y" + { + begin_typedef(); + } +break; +case 20: +#line 447 "grammar.y" + { + begin_typedef(); + } +break; +case 23: +#line 459 "grammar.y" + { + int flags = cur_decl_spec_flags; + + /* If the typedef is a pointer type, then reset the short type + * flags so it does not get promoted. + */ + if (strcmp(yystack.l_mark[0].declarator->text, yystack.l_mark[0].declarator->name) != 0) + flags &= ~(DS_CHAR | DS_SHORT | DS_FLOAT); + new_symbol(typedef_names, yystack.l_mark[0].declarator->name, NULL, flags); + free_declarator(yystack.l_mark[0].declarator); + } +break; +case 24: +#line 471 "grammar.y" + { + int flags = cur_decl_spec_flags; + + if (strcmp(yystack.l_mark[0].declarator->text, yystack.l_mark[0].declarator->name) != 0) + flags &= ~(DS_CHAR | DS_SHORT | DS_FLOAT); + new_symbol(typedef_names, yystack.l_mark[0].declarator->name, NULL, flags); + free_declarator(yystack.l_mark[0].declarator); + } +break; +case 25: +#line 483 "grammar.y" + { + check_untagged(&yystack.l_mark[-1].decl_spec); + if (yystack.l_mark[0].declarator->func_def == FUNC_NONE) { + yyerror("syntax error"); + YYERROR; + } + func_params = &(yystack.l_mark[0].declarator->head->params); + func_params->begin_comment = cur_file->begin_comment; + func_params->end_comment = cur_file->end_comment; + } +break; +case 26: +#line 494 "grammar.y" + { + /* If we're converting to K&R and we've got a nominally K&R + * function which has a parameter which is ANSI (i.e., a prototyped + * function pointer), then we must override the deciphered value of + * 'func_def' so that the parameter will be converted. + */ + if (func_style == FUNC_TRADITIONAL + && haveAnsiParam() + && yystack.l_mark[-3].declarator->head->func_def == func_style) { + yystack.l_mark[-3].declarator->head->func_def = FUNC_BOTH; + } + + func_params = NULL; + + if (cur_file->convert) + gen_func_definition(&yystack.l_mark[-4].decl_spec, yystack.l_mark[-3].declarator); + gen_prototype(&yystack.l_mark[-4].decl_spec, yystack.l_mark[-3].declarator); +#if OPT_LINTLIBRARY + flush_varargs(); +#endif + free_decl_spec(&yystack.l_mark[-4].decl_spec); + free_declarator(yystack.l_mark[-3].declarator); + } +break; +case 28: +#line 519 "grammar.y" + { + if (yystack.l_mark[0].declarator->func_def == FUNC_NONE) { + yyerror("syntax error"); + YYERROR; + } + func_params = &(yystack.l_mark[0].declarator->head->params); + func_params->begin_comment = cur_file->begin_comment; + func_params->end_comment = cur_file->end_comment; + } +break; +case 29: +#line 529 "grammar.y" + { + DeclSpec decl_spec; + + func_params = NULL; + + new_decl_spec(&decl_spec, dft_decl_spec(), yystack.l_mark[-4].declarator->begin, DS_NONE); + if (cur_file->convert) + gen_func_definition(&decl_spec, yystack.l_mark[-4].declarator); + gen_prototype(&decl_spec, yystack.l_mark[-4].declarator); +#if OPT_LINTLIBRARY + flush_varargs(); +#endif + free_decl_spec(&decl_spec); + free_declarator(yystack.l_mark[-4].declarator); + } +break; +case 36: +#line 560 "grammar.y" + { + join_decl_specs(&yyval.decl_spec, &yystack.l_mark[-1].decl_spec, &yystack.l_mark[0].decl_spec); + free(yystack.l_mark[-1].decl_spec.text); + free(yystack.l_mark[0].decl_spec.text); + } +break; +case 40: +#line 575 "grammar.y" + { + new_decl_spec(&yyval.decl_spec, yystack.l_mark[0].text.text, yystack.l_mark[0].text.begin, DS_NONE); + } +break; +case 41: +#line 579 "grammar.y" + { + new_decl_spec(&yyval.decl_spec, yystack.l_mark[0].text.text, yystack.l_mark[0].text.begin, DS_EXTERN); + } +break; +case 42: +#line 583 "grammar.y" + { + new_decl_spec(&yyval.decl_spec, yystack.l_mark[0].text.text, yystack.l_mark[0].text.begin, DS_NONE); + } +break; +case 43: +#line 587 "grammar.y" + { + new_decl_spec(&yyval.decl_spec, yystack.l_mark[0].text.text, yystack.l_mark[0].text.begin, DS_STATIC); + } +break; +case 44: +#line 591 "grammar.y" + { + new_decl_spec(&yyval.decl_spec, yystack.l_mark[0].text.text, yystack.l_mark[0].text.begin, DS_INLINE); + } +break; +case 45: +#line 595 "grammar.y" + { + new_decl_spec(&yyval.decl_spec, yystack.l_mark[0].text.text, yystack.l_mark[0].text.begin, DS_JUNK); + } +break; +case 46: +#line 602 "grammar.y" + { + new_decl_spec(&yyval.decl_spec, yystack.l_mark[0].text.text, yystack.l_mark[0].text.begin, DS_CHAR); + } +break; +case 47: +#line 606 "grammar.y" + { + new_decl_spec(&yyval.decl_spec, yystack.l_mark[0].text.text, yystack.l_mark[0].text.begin, DS_NONE); + } +break; +case 48: +#line 610 "grammar.y" + { + new_decl_spec(&yyval.decl_spec, yystack.l_mark[0].text.text, yystack.l_mark[0].text.begin, DS_FLOAT); + } +break; +case 49: +#line 614 "grammar.y" + { + new_decl_spec(&yyval.decl_spec, yystack.l_mark[0].text.text, yystack.l_mark[0].text.begin, DS_NONE); + } +break; +case 50: +#line 618 "grammar.y" + { + new_decl_spec(&yyval.decl_spec, yystack.l_mark[0].text.text, yystack.l_mark[0].text.begin, DS_NONE); + } +break; +case 51: +#line 622 "grammar.y" + { + new_decl_spec(&yyval.decl_spec, yystack.l_mark[0].text.text, yystack.l_mark[0].text.begin, DS_SHORT); + } +break; +case 52: +#line 626 "grammar.y" + { + new_decl_spec(&yyval.decl_spec, yystack.l_mark[0].text.text, yystack.l_mark[0].text.begin, DS_NONE); + } +break; +case 53: +#line 630 "grammar.y" + { + new_decl_spec(&yyval.decl_spec, yystack.l_mark[0].text.text, yystack.l_mark[0].text.begin, DS_NONE); + } +break; +case 54: +#line 634 "grammar.y" + { + new_decl_spec(&yyval.decl_spec, yystack.l_mark[0].text.text, yystack.l_mark[0].text.begin, DS_NONE); + } +break; +case 55: +#line 638 "grammar.y" + { + new_decl_spec(&yyval.decl_spec, yystack.l_mark[0].text.text, yystack.l_mark[0].text.begin, DS_CHAR); + } +break; +case 56: +#line 642 "grammar.y" + { + new_decl_spec(&yyval.decl_spec, yystack.l_mark[0].text.text, yystack.l_mark[0].text.begin, DS_NONE); + } +break; +case 57: +#line 646 "grammar.y" + { + new_decl_spec(&yyval.decl_spec, yystack.l_mark[0].text.text, yystack.l_mark[0].text.begin, DS_NONE); + } +break; +case 58: +#line 650 "grammar.y" + { + Symbol *s; + s = find_symbol(typedef_names, yystack.l_mark[0].text.text); + if (s != NULL) + new_decl_spec(&yyval.decl_spec, yystack.l_mark[0].text.text, yystack.l_mark[0].text.begin, s->flags); + } +break; +case 61: +#line 662 "grammar.y" + { + new_decl_spec(&yyval.decl_spec, yystack.l_mark[0].text.text, yystack.l_mark[0].text.begin, DS_NONE); + } +break; +case 62: +#line 666 "grammar.y" + { + /* This rule allows the <pointer> nonterminal to scan #define + * names as if they were type modifiers. + */ + Symbol *s; + s = find_symbol(define_names, yystack.l_mark[0].text.text); + if (s != NULL) + new_decl_spec(&yyval.decl_spec, yystack.l_mark[0].text.text, yystack.l_mark[0].text.begin, s->flags); + } +break; +case 63: +#line 679 "grammar.y" + { + char *s; + if ((s = implied_typedef()) == 0) + (void)sprintf(s = buf, "%s %s", yystack.l_mark[-2].text.text, yystack.l_mark[-1].text.text); + new_decl_spec(&yyval.decl_spec, s, yystack.l_mark[-2].text.begin, DS_NONE); + } +break; +case 64: +#line 686 "grammar.y" + { + char *s; + if ((s = implied_typedef()) == 0) + (void)sprintf(s = buf, "%s {}", yystack.l_mark[-1].text.text); + new_decl_spec(&yyval.decl_spec, s, yystack.l_mark[-1].text.begin, DS_NONE); + } +break; +case 65: +#line 693 "grammar.y" + { + (void)sprintf(buf, "%s %s", yystack.l_mark[-1].text.text, yystack.l_mark[0].text.text); + new_decl_spec(&yyval.decl_spec, buf, yystack.l_mark[-1].text.begin, DS_NONE); + } +break; +case 66: +#line 701 "grammar.y" + { + imply_typedef(yyval.text.text); + } +break; +case 67: +#line 705 "grammar.y" + { + imply_typedef(yyval.text.text); + } +break; +case 68: +#line 712 "grammar.y" + { + new_decl_list(&yyval.decl_list, yystack.l_mark[0].declarator); + } +break; +case 69: +#line 716 "grammar.y" + { + add_decl_list(&yyval.decl_list, &yystack.l_mark[-2].decl_list, yystack.l_mark[0].declarator); + } +break; +case 70: +#line 723 "grammar.y" + { + if (yystack.l_mark[0].declarator->func_def != FUNC_NONE && func_params == NULL && + func_style == FUNC_TRADITIONAL && cur_file->convert) { + gen_func_declarator(yystack.l_mark[0].declarator); + fputs(cur_text(), cur_file->tmp_file); + } + cur_declarator = yyval.declarator; + } +break; +case 71: +#line 732 "grammar.y" + { + if (yystack.l_mark[-1].declarator->func_def != FUNC_NONE && func_params == NULL && + func_style == FUNC_TRADITIONAL && cur_file->convert) { + gen_func_declarator(yystack.l_mark[-1].declarator); + fputs(" =", cur_file->tmp_file); + } + } +break; +case 73: +#line 744 "grammar.y" + { + char *s; + if ((s = implied_typedef()) == 0) + (void)sprintf(s = buf, "enum %s", yystack.l_mark[-1].text.text); + new_decl_spec(&yyval.decl_spec, s, yystack.l_mark[-2].text.begin, DS_NONE); + } +break; +case 74: +#line 751 "grammar.y" + { + char *s; + if ((s = implied_typedef()) == 0) + (void)sprintf(s = buf, "%s {}", yystack.l_mark[-1].text.text); + new_decl_spec(&yyval.decl_spec, s, yystack.l_mark[-1].text.begin, DS_NONE); + } +break; +case 75: +#line 758 "grammar.y" + { + (void)sprintf(buf, "enum %s", yystack.l_mark[0].text.text); + new_decl_spec(&yyval.decl_spec, buf, yystack.l_mark[-1].text.begin, DS_NONE); + } +break; +case 76: +#line 766 "grammar.y" + { + imply_typedef("enum"); + yyval.text = yystack.l_mark[0].text; + } +break; +case 79: +#line 779 "grammar.y" + { + yyval.declarator = yystack.l_mark[0].declarator; + (void)sprintf(buf, "%s%s", yystack.l_mark[-1].text.text, yyval.declarator->text); + free(yyval.declarator->text); + yyval.declarator->text = xstrdup(buf); + yyval.declarator->begin = yystack.l_mark[-1].text.begin; + yyval.declarator->pointer = TRUE; + } +break; +case 81: +#line 792 "grammar.y" + { + yyval.declarator = new_declarator(yystack.l_mark[0].text.text, yystack.l_mark[0].text.text, yystack.l_mark[0].text.begin); + } +break; +case 82: +#line 796 "grammar.y" + { + yyval.declarator = yystack.l_mark[-1].declarator; + (void)sprintf(buf, "(%s)", yyval.declarator->text); + free(yyval.declarator->text); + yyval.declarator->text = xstrdup(buf); + yyval.declarator->begin = yystack.l_mark[-2].text.begin; + } +break; +case 83: +#line 804 "grammar.y" + { + yyval.declarator = yystack.l_mark[-1].declarator; + (void)sprintf(buf, "%s%s", yyval.declarator->text, yystack.l_mark[0].text.text); + free(yyval.declarator->text); + yyval.declarator->text = xstrdup(buf); + } +break; +case 84: +#line 811 "grammar.y" + { + yyval.declarator = new_declarator("%s()", yystack.l_mark[-3].declarator->name, yystack.l_mark[-3].declarator->begin); + yyval.declarator->params = yystack.l_mark[-1].param_list; + yyval.declarator->func_stack = yystack.l_mark[-3].declarator; + yyval.declarator->head = (yystack.l_mark[-3].declarator->func_stack == NULL) ? yyval.declarator : yystack.l_mark[-3].declarator->head; + yyval.declarator->func_def = FUNC_ANSI; + } +break; +case 85: +#line 819 "grammar.y" + { + yyval.declarator = new_declarator("%s()", yystack.l_mark[-3].declarator->name, yystack.l_mark[-3].declarator->begin); + yyval.declarator->params = yystack.l_mark[-1].param_list; + yyval.declarator->func_stack = yystack.l_mark[-3].declarator; + yyval.declarator->head = (yystack.l_mark[-3].declarator->func_stack == NULL) ? yyval.declarator : yystack.l_mark[-3].declarator->head; + yyval.declarator->func_def = FUNC_TRADITIONAL; + } +break; +case 86: +#line 830 "grammar.y" + { + (void)sprintf(yyval.text.text, "*%s", yystack.l_mark[0].text.text); + yyval.text.begin = yystack.l_mark[-1].text.begin; + } +break; +case 87: +#line 835 "grammar.y" + { + (void)sprintf(yyval.text.text, "*%s%s", yystack.l_mark[-1].text.text, yystack.l_mark[0].text.text); + yyval.text.begin = yystack.l_mark[-2].text.begin; + } +break; +case 88: +#line 843 "grammar.y" + { + strcpy(yyval.text.text, ""); + yyval.text.begin = 0L; + } +break; +case 90: +#line 852 "grammar.y" + { + (void)sprintf(yyval.text.text, "%s ", yystack.l_mark[0].decl_spec.text); + yyval.text.begin = yystack.l_mark[0].decl_spec.begin; + free(yystack.l_mark[0].decl_spec.text); + } +break; +case 91: +#line 858 "grammar.y" + { + (void)sprintf(yyval.text.text, "%s%s ", yystack.l_mark[-1].text.text, yystack.l_mark[0].decl_spec.text); + yyval.text.begin = yystack.l_mark[-1].text.begin; + free(yystack.l_mark[0].decl_spec.text); + } +break; +case 93: +#line 868 "grammar.y" + { + add_ident_list(&yyval.param_list, &yystack.l_mark[-2].param_list, "..."); + } +break; +case 94: +#line 875 "grammar.y" + { + new_param_list(&yyval.param_list, yystack.l_mark[0].parameter); + } +break; +case 95: +#line 879 "grammar.y" + { + add_param_list(&yyval.param_list, &yystack.l_mark[-2].param_list, yystack.l_mark[0].parameter); + } +break; +case 96: +#line 886 "grammar.y" + { + check_untagged(&yystack.l_mark[-1].decl_spec); + yyval.parameter = new_parameter(&yystack.l_mark[-1].decl_spec, yystack.l_mark[0].declarator); + } +break; +case 97: +#line 891 "grammar.y" + { + check_untagged(&yystack.l_mark[-1].decl_spec); + yyval.parameter = new_parameter(&yystack.l_mark[-1].decl_spec, yystack.l_mark[0].declarator); + } +break; +case 98: +#line 896 "grammar.y" + { + check_untagged(&yystack.l_mark[0].decl_spec); + yyval.parameter = new_parameter(&yystack.l_mark[0].decl_spec, (Declarator *)0); + } +break; +case 99: +#line 904 "grammar.y" + { + new_ident_list(&yyval.param_list); + } +break; +case 101: +#line 912 "grammar.y" + { + new_ident_list(&yyval.param_list); + add_ident_list(&yyval.param_list, &yyval.param_list, yystack.l_mark[0].text.text); + } +break; +case 102: +#line 917 "grammar.y" + { + add_ident_list(&yyval.param_list, &yystack.l_mark[-2].param_list, yystack.l_mark[0].text.text); + } +break; +case 103: +#line 924 "grammar.y" + { + yyval.text = yystack.l_mark[0].text; + } +break; +case 104: +#line 928 "grammar.y" + { +#if OPT_LINTLIBRARY + if (lintLibrary()) { /* Lint doesn't grok C++ ref variables */ + yyval.text = yystack.l_mark[0].text; + } else +#endif + (void)sprintf(yyval.text.text, "&%s", yystack.l_mark[0].text.text); + yyval.text.begin = yystack.l_mark[-1].text.begin; + } +break; +case 105: +#line 941 "grammar.y" + { + yyval.declarator = new_declarator(yystack.l_mark[0].text.text, "", yystack.l_mark[0].text.begin); + } +break; +case 106: +#line 945 "grammar.y" + { + yyval.declarator = yystack.l_mark[0].declarator; + (void)sprintf(buf, "%s%s", yystack.l_mark[-1].text.text, yyval.declarator->text); + free(yyval.declarator->text); + yyval.declarator->text = xstrdup(buf); + yyval.declarator->begin = yystack.l_mark[-1].text.begin; + } +break; +case 108: +#line 957 "grammar.y" + { + yyval.declarator = yystack.l_mark[-1].declarator; + (void)sprintf(buf, "(%s)", yyval.declarator->text); + free(yyval.declarator->text); + yyval.declarator->text = xstrdup(buf); + yyval.declarator->begin = yystack.l_mark[-2].text.begin; + } +break; +case 109: +#line 965 "grammar.y" + { + yyval.declarator = yystack.l_mark[-1].declarator; + (void)sprintf(buf, "%s%s", yyval.declarator->text, yystack.l_mark[0].text.text); + free(yyval.declarator->text); + yyval.declarator->text = xstrdup(buf); + } +break; +case 110: +#line 972 "grammar.y" + { + yyval.declarator = new_declarator(yystack.l_mark[0].text.text, "", yystack.l_mark[0].text.begin); + } +break; +case 111: +#line 976 "grammar.y" + { + yyval.declarator = new_declarator("%s()", "", yystack.l_mark[-3].declarator->begin); + yyval.declarator->params = yystack.l_mark[-1].param_list; + yyval.declarator->func_stack = yystack.l_mark[-3].declarator; + yyval.declarator->head = (yystack.l_mark[-3].declarator->func_stack == NULL) ? yyval.declarator : yystack.l_mark[-3].declarator->head; + yyval.declarator->func_def = FUNC_ANSI; + } +break; +case 112: +#line 984 "grammar.y" + { + yyval.declarator = new_declarator("%s()", "", yystack.l_mark[-2].declarator->begin); + yyval.declarator->func_stack = yystack.l_mark[-2].declarator; + yyval.declarator->head = (yystack.l_mark[-2].declarator->func_stack == NULL) ? yyval.declarator : yystack.l_mark[-2].declarator->head; + yyval.declarator->func_def = FUNC_ANSI; + } +break; +case 113: +#line 991 "grammar.y" + { + Declarator *d; + + d = new_declarator("", "", yystack.l_mark[-2].text.begin); + yyval.declarator = new_declarator("%s()", "", yystack.l_mark[-2].text.begin); + yyval.declarator->params = yystack.l_mark[-1].param_list; + yyval.declarator->func_stack = d; + yyval.declarator->head = yyval.declarator; + yyval.declarator->func_def = FUNC_ANSI; + } +break; +case 114: +#line 1002 "grammar.y" + { + Declarator *d; + + d = new_declarator("", "", yystack.l_mark[-1].text.begin); + yyval.declarator = new_declarator("%s()", "", yystack.l_mark[-1].text.begin); + yyval.declarator->func_stack = d; + yyval.declarator->head = yyval.declarator; + yyval.declarator->func_def = FUNC_ANSI; + } +break; +#line 1965 "grammar.tab.c" + } + yystack.s_mark -= yym; + yystate = *yystack.s_mark; + yystack.l_mark -= yym; + yym = yylhs[yyn]; + if (yystate == 0 && yym == 0) + { +#if YYDEBUG + if (yydebug) + printf("%sdebug: after reduction, shifting from state 0 to\ + state %d\n", YYPREFIX, YYFINAL); +#endif + yystate = YYFINAL; + *++yystack.s_mark = YYFINAL; + *++yystack.l_mark = yyval; + if (yychar < 0) + { + if ((yychar = YYLEX) < 0) yychar = 0; +#if YYDEBUG + if (yydebug) + { + yys = 0; + if (yychar <= YYMAXTOKEN) yys = yyname[yychar]; + if (!yys) yys = "illegal-symbol"; + printf("%sdebug: state %d, reading %d (%s)\n", + YYPREFIX, YYFINAL, yychar, yys); + } +#endif + } + if (yychar == 0) goto yyaccept; + goto yyloop; + } + if ((yyn = yygindex[yym]) && (yyn += yystate) >= 0 && + yyn <= YYTABLESIZE && yycheck[yyn] == yystate) + yystate = yytable[yyn]; + else + yystate = yydgoto[yym]; +#if YYDEBUG + if (yydebug) + printf("%sdebug: after reduction, shifting from state %d \ +to state %d\n", YYPREFIX, *yystack.s_mark, yystate); +#endif + if (yystack.s_mark >= yystack.s_last && yygrowstack(&yystack)) + { + goto yyoverflow; + } + *++yystack.s_mark = (short) yystate; + *++yystack.l_mark = yyval; + goto yyloop; + +yyoverflow: + yyerror("yacc stack overflow"); + +yyabort: + yyfreestack(&yystack); + return (1); + +yyaccept: + yyfreestack(&yystack); + return (0); +} diff --git a/test/grammar.tab.h b/test/grammar.tab.h new file mode 100644 index 000000000000..531dd2e849b2 --- /dev/null +++ b/test/grammar.tab.h @@ -0,0 +1,35 @@ +#define T_IDENTIFIER 257 +#define T_TYPEDEF_NAME 258 +#define T_DEFINE_NAME 259 +#define T_AUTO 260 +#define T_EXTERN 261 +#define T_REGISTER 262 +#define T_STATIC 263 +#define T_TYPEDEF 264 +#define T_INLINE 265 +#define T_EXTENSION 266 +#define T_CHAR 267 +#define T_DOUBLE 268 +#define T_FLOAT 269 +#define T_INT 270 +#define T_VOID 271 +#define T_LONG 272 +#define T_SHORT 273 +#define T_SIGNED 274 +#define T_UNSIGNED 275 +#define T_ENUM 276 +#define T_STRUCT 277 +#define T_UNION 278 +#define T_Bool 279 +#define T_Complex 280 +#define T_Imaginary 281 +#define T_TYPE_QUALIFIER 282 +#define T_BRACKETS 283 +#define T_LBRACE 284 +#define T_MATCHRBRACE 285 +#define T_ELLIPSIS 286 +#define T_INITIALIZER 287 +#define T_STRING_LITERAL 288 +#define T_ASM 289 +#define T_ASMARG 290 +#define T_VA_DCL 291 diff --git a/test/grammar.y b/test/grammar.y new file mode 100644 index 000000000000..675552268370 --- /dev/null +++ b/test/grammar.y @@ -0,0 +1,1183 @@ +/* $Id: grammar.y,v 1.5 2012/01/15 20:00:59 tom Exp $ + * + * yacc grammar for C function prototype generator + * This was derived from the grammar in Appendix A of + * "The C Programming Language" by Kernighan and Ritchie. + */ +%expect 1 +%{ +#ifdef YYBISON +#include <stdlib.h> +#define YYSTYPE_IS_DECLARED +#define yyerror yaccError +#endif + +#if defined(YYBISON) || !defined(YYBYACC) +static void yyerror(const char *s); +#endif +%} + +%token <text> '(' '*' '&' + /* identifiers that are not reserved words */ + T_IDENTIFIER T_TYPEDEF_NAME T_DEFINE_NAME + + /* storage class */ + T_AUTO T_EXTERN T_REGISTER T_STATIC T_TYPEDEF + /* This keyword included for compatibility with C++. */ + T_INLINE + /* This keyword included for compatibility with GCC */ + T_EXTENSION + + /* type specifiers */ + T_CHAR T_DOUBLE T_FLOAT T_INT T_VOID + T_LONG T_SHORT T_SIGNED T_UNSIGNED + T_ENUM T_STRUCT T_UNION + /* C9X new types */ + T_Bool T_Complex T_Imaginary + + /* type qualifiers */ + T_TYPE_QUALIFIER + + /* paired square brackets and everything between them: [ ... ] */ + T_BRACKETS + +%token + /* left brace */ + T_LBRACE + /* all input to the matching right brace */ + T_MATCHRBRACE + + /* three periods */ + T_ELLIPSIS + + /* constant expression or paired braces following an equal sign */ + T_INITIALIZER + + /* string literal */ + T_STRING_LITERAL + + /* asm */ + T_ASM + /* ( "string literal" ) following asm keyword */ + T_ASMARG + + /* va_dcl from <varargs.h> */ + T_VA_DCL + +%type <decl_spec> decl_specifiers decl_specifier +%type <decl_spec> storage_class type_specifier type_qualifier +%type <decl_spec> struct_or_union_specifier enum_specifier +%type <decl_list> init_declarator_list +%type <declarator> init_declarator declarator direct_declarator +%type <declarator> abs_declarator direct_abs_declarator +%type <param_list> parameter_type_list parameter_list +%type <parameter> parameter_declaration +%type <param_list> opt_identifier_list identifier_list +%type <text> struct_or_union pointer opt_type_qualifiers type_qualifier_list + any_id identifier_or_ref +%type <text> enumeration + +%{ +#include <stdio.h> +#include <ctype.h> +#include <string.h> + +#define OPT_LINTLIBRARY 1 + +#ifndef TRUE +#define TRUE (1) +#endif + +#ifndef FALSE +#define FALSE (0) +#endif + +/* #include "cproto.h" */ +#define MAX_TEXT_SIZE 1024 + +/* Prototype styles */ +#if OPT_LINTLIBRARY +#define PROTO_ANSI_LLIB -2 /* form ANSI lint-library source */ +#define PROTO_LINTLIBRARY -1 /* form lint-library source */ +#endif +#define PROTO_NONE 0 /* do not output any prototypes */ +#define PROTO_TRADITIONAL 1 /* comment out parameters */ +#define PROTO_ABSTRACT 2 /* comment out parameter names */ +#define PROTO_ANSI 3 /* ANSI C prototype */ + +typedef int PrototypeStyle; + +typedef char boolean; + +extern boolean types_out; +extern PrototypeStyle proto_style; + +#define ansiLintLibrary() (proto_style == PROTO_ANSI_LLIB) +#define knrLintLibrary() (proto_style == PROTO_LINTLIBRARY) +#define lintLibrary() (knrLintLibrary() || ansiLintLibrary()) + +#if OPT_LINTLIBRARY +#define FUNC_UNKNOWN -1 /* unspecified */ +#else +#define FUNC_UNKNOWN 0 /* unspecified (same as FUNC_NONE) */ +#endif +#define FUNC_NONE 0 /* not a function definition */ +#define FUNC_TRADITIONAL 1 /* traditional style */ +#define FUNC_ANSI 2 /* ANSI style */ +#define FUNC_BOTH 3 /* both styles */ + +typedef int FuncDefStyle; + +/* Source file text */ +typedef struct text { + char text[MAX_TEXT_SIZE]; /* source text */ + long begin; /* offset in temporary file */ +} Text; + +/* Declaration specifier flags */ +#define DS_NONE 0 /* default */ +#define DS_EXTERN 1 /* contains "extern" specifier */ +#define DS_STATIC 2 /* contains "static" specifier */ +#define DS_CHAR 4 /* contains "char" type specifier */ +#define DS_SHORT 8 /* contains "short" type specifier */ +#define DS_FLOAT 16 /* contains "float" type specifier */ +#define DS_INLINE 32 /* contains "inline" specifier */ +#define DS_JUNK 64 /* we're not interested in this declaration */ + +/* This structure stores information about a declaration specifier. */ +typedef struct decl_spec { + unsigned short flags; /* flags defined above */ + char *text; /* source text */ + long begin; /* offset in temporary file */ +} DeclSpec; + +/* This is a list of function parameters. */ +typedef struct _ParameterList { + struct parameter *first; /* pointer to first parameter in list */ + struct parameter *last; /* pointer to last parameter in list */ + long begin_comment; /* begin offset of comment */ + long end_comment; /* end offset of comment */ + char *comment; /* comment at start of parameter list */ +} ParameterList; + +/* This structure stores information about a declarator. */ +typedef struct _Declarator { + char *name; /* name of variable or function */ + char *text; /* source text */ + long begin; /* offset in temporary file */ + long begin_comment; /* begin offset of comment */ + long end_comment; /* end offset of comment */ + FuncDefStyle func_def; /* style of function definition */ + ParameterList params; /* function parameters */ + boolean pointer; /* TRUE if it declares a pointer */ + struct _Declarator *head; /* head function declarator */ + struct _Declarator *func_stack; /* stack of function declarators */ + struct _Declarator *next; /* next declarator in list */ +} Declarator; + +/* This structure stores information about a function parameter. */ +typedef struct parameter { + struct parameter *next; /* next parameter in list */ + DeclSpec decl_spec; + Declarator *declarator; + char *comment; /* comment following the parameter */ +} Parameter; + +/* This is a list of declarators. */ +typedef struct declarator_list { + Declarator *first; /* pointer to first declarator in list */ + Declarator *last; /* pointer to last declarator in list */ +} DeclaratorList; + +/* #include "symbol.h" */ +typedef struct symbol { + struct symbol *next; /* next symbol in list */ + char *name; /* name of symbol */ + char *value; /* value of symbol (for defines) */ + short flags; /* symbol attributes */ +} Symbol; + +/* parser stack entry type */ +typedef union { + Text text; + DeclSpec decl_spec; + Parameter *parameter; + ParameterList param_list; + Declarator *declarator; + DeclaratorList decl_list; +} YYSTYPE; + +/* The hash table length should be a prime number. */ +#define SYM_MAX_HASH 251 + +typedef struct symbol_table { + Symbol *bucket[SYM_MAX_HASH]; /* hash buckets */ +} SymbolTable; + +extern SymbolTable *new_symbol_table /* Create symbol table */ + (void); +extern void free_symbol_table /* Destroy symbol table */ + (SymbolTable *s); +extern Symbol *find_symbol /* Lookup symbol name */ + (SymbolTable *s, const char *n); +extern Symbol *new_symbol /* Define new symbol */ + (SymbolTable *s, const char *n, const char *v, int f); + +/* #include "semantic.h" */ +extern void new_decl_spec (DeclSpec *, const char *, long, int); +extern void free_decl_spec (DeclSpec *); +extern void join_decl_specs (DeclSpec *, DeclSpec *, DeclSpec *); +extern void check_untagged (DeclSpec *); +extern Declarator *new_declarator (const char *, const char *, long); +extern void free_declarator (Declarator *); +extern void new_decl_list (DeclaratorList *, Declarator *); +extern void free_decl_list (DeclaratorList *); +extern void add_decl_list (DeclaratorList *, DeclaratorList *, Declarator *); +extern Parameter *new_parameter (DeclSpec *, Declarator *); +extern void free_parameter (Parameter *); +extern void new_param_list (ParameterList *, Parameter *); +extern void free_param_list (ParameterList *); +extern void add_param_list (ParameterList *, ParameterList *, Parameter *); +extern void new_ident_list (ParameterList *); +extern void add_ident_list (ParameterList *, ParameterList *, const char *); +extern void set_param_types (ParameterList *, DeclSpec *, DeclaratorList *); +extern void gen_declarations (DeclSpec *, DeclaratorList *); +extern void gen_prototype (DeclSpec *, Declarator *); +extern void gen_func_declarator (Declarator *); +extern void gen_func_definition (DeclSpec *, Declarator *); + +extern void init_parser (void); +extern void process_file (FILE *infile, char *name); +extern char *cur_text (void); +extern char *cur_file_name (void); +extern char *implied_typedef (void); +extern void include_file (char *name, int convert); +extern char *supply_parm (int count); +extern char *xstrdup (const char *); +extern int already_declared (char *name); +extern int is_actual_func (Declarator *d); +extern int lint_ellipsis (Parameter *p); +extern int want_typedef (void); +extern void begin_tracking (void); +extern void begin_typedef (void); +extern void copy_typedef (char *s); +extern void ellipsis_varargs (Declarator *d); +extern void end_typedef (void); +extern void flush_varargs (void); +extern void fmt_library (int code); +extern void imply_typedef (const char *s); +extern void indent (FILE *outf); +extern void put_blankline (FILE *outf); +extern void put_body (FILE *outf, DeclSpec *decl_spec, Declarator *declarator); +extern void put_char (FILE *outf, int c); +extern void put_error (void); +extern void put_newline (FILE *outf); +extern void put_padded (FILE *outf, const char *s); +extern void put_string (FILE *outf, const char *s); +extern void track_in (void); + +extern boolean file_comments; +extern FuncDefStyle func_style; +extern char base_file[]; + +extern int yylex (void); + +/* declaration specifier attributes for the typedef statement currently being + * scanned + */ +static int cur_decl_spec_flags; + +/* pointer to parameter list for the current function definition */ +static ParameterList *func_params; + +/* A parser semantic action sets this pointer to the current declarator in + * a function parameter declaration in order to catch any comments following + * the parameter declaration on the same line. If the lexer scans a comment + * and <cur_declarator> is not NULL, then the comment is attached to the + * declarator. To ignore subsequent comments, the lexer sets this to NULL + * after scanning a comment or end of line. + */ +static Declarator *cur_declarator; + +/* temporary string buffer */ +static char buf[MAX_TEXT_SIZE]; + +/* table of typedef names */ +static SymbolTable *typedef_names; + +/* table of define names */ +static SymbolTable *define_names; + +/* table of type qualifiers */ +static SymbolTable *type_qualifiers; + +/* information about the current input file */ +typedef struct { + char *base_name; /* base input file name */ + char *file_name; /* current file name */ + FILE *file; /* input file */ + unsigned line_num; /* current line number in input file */ + FILE *tmp_file; /* temporary file */ + long begin_comment; /* tmp file offset after last written ) or ; */ + long end_comment; /* tmp file offset after last comment */ + boolean convert; /* if TRUE, convert function definitions */ + boolean changed; /* TRUE if conversion done in this file */ +} IncludeStack; + +static IncludeStack *cur_file; /* current input file */ + +/* #include "yyerror.c" */ + +static int haveAnsiParam (void); + + +/* Flags to enable us to find if a procedure returns a value. + */ +static int return_val; /* nonzero on BRACES iff return-expression found */ + +static const char * +dft_decl_spec (void) +{ + return (lintLibrary() && !return_val) ? "void" : "int"; +} + +static int +haveAnsiParam (void) +{ + Parameter *p; + if (func_params != 0) { + for (p = func_params->first; p != 0; p = p->next) { + if (p->declarator->func_def == FUNC_ANSI) { + return TRUE; + } + } + } + return FALSE; +} +%} +%% + +program + : /* empty */ + | translation_unit + ; + +translation_unit + : external_declaration + | translation_unit external_declaration + ; + +external_declaration + : declaration + | function_definition + | ';' + | linkage_specification + | T_ASM T_ASMARG ';' + | error T_MATCHRBRACE + { + yyerrok; + } + | error ';' + { + yyerrok; + } + ; + +braces + : T_LBRACE T_MATCHRBRACE + ; + +linkage_specification + : T_EXTERN T_STRING_LITERAL braces + { + /* Provide an empty action here so bison will not complain about + * incompatible types in the default action it normally would + * have generated. + */ + } + | T_EXTERN T_STRING_LITERAL declaration + { + /* empty */ + } + ; + +declaration + : decl_specifiers ';' + { +#if OPT_LINTLIBRARY + if (types_out && want_typedef()) { + gen_declarations(&$1, (DeclaratorList *)0); + flush_varargs(); + } +#endif + free_decl_spec(&$1); + end_typedef(); + } + | decl_specifiers init_declarator_list ';' + { + if (func_params != NULL) { + set_param_types(func_params, &$1, &$2); + } else { + gen_declarations(&$1, &$2); +#if OPT_LINTLIBRARY + flush_varargs(); +#endif + free_decl_list(&$2); + } + free_decl_spec(&$1); + end_typedef(); + } + | any_typedef decl_specifiers + { + cur_decl_spec_flags = $2.flags; + free_decl_spec(&$2); + } + opt_declarator_list ';' + { + end_typedef(); + } + ; + +any_typedef + : T_EXTENSION T_TYPEDEF + { + begin_typedef(); + } + | T_TYPEDEF + { + begin_typedef(); + } + ; + +opt_declarator_list + : /* empty */ + | declarator_list + ; + +declarator_list + : declarator + { + int flags = cur_decl_spec_flags; + + /* If the typedef is a pointer type, then reset the short type + * flags so it does not get promoted. + */ + if (strcmp($1->text, $1->name) != 0) + flags &= ~(DS_CHAR | DS_SHORT | DS_FLOAT); + new_symbol(typedef_names, $1->name, NULL, flags); + free_declarator($1); + } + | declarator_list ',' declarator + { + int flags = cur_decl_spec_flags; + + if (strcmp($3->text, $3->name) != 0) + flags &= ~(DS_CHAR | DS_SHORT | DS_FLOAT); + new_symbol(typedef_names, $3->name, NULL, flags); + free_declarator($3); + } + ; + +function_definition + : decl_specifiers declarator + { + check_untagged(&$1); + if ($2->func_def == FUNC_NONE) { + yyerror("syntax error"); + YYERROR; + } + func_params = &($2->head->params); + func_params->begin_comment = cur_file->begin_comment; + func_params->end_comment = cur_file->end_comment; + } + opt_declaration_list T_LBRACE + { + /* If we're converting to K&R and we've got a nominally K&R + * function which has a parameter which is ANSI (i.e., a prototyped + * function pointer), then we must override the deciphered value of + * 'func_def' so that the parameter will be converted. + */ + if (func_style == FUNC_TRADITIONAL + && haveAnsiParam() + && $2->head->func_def == func_style) { + $2->head->func_def = FUNC_BOTH; + } + + func_params = NULL; + + if (cur_file->convert) + gen_func_definition(&$1, $2); + gen_prototype(&$1, $2); +#if OPT_LINTLIBRARY + flush_varargs(); +#endif + free_decl_spec(&$1); + free_declarator($2); + } + T_MATCHRBRACE + | declarator + { + if ($1->func_def == FUNC_NONE) { + yyerror("syntax error"); + YYERROR; + } + func_params = &($1->head->params); + func_params->begin_comment = cur_file->begin_comment; + func_params->end_comment = cur_file->end_comment; + } + opt_declaration_list T_LBRACE T_MATCHRBRACE + { + DeclSpec decl_spec; + + func_params = NULL; + + new_decl_spec(&decl_spec, dft_decl_spec(), $1->begin, DS_NONE); + if (cur_file->convert) + gen_func_definition(&decl_spec, $1); + gen_prototype(&decl_spec, $1); +#if OPT_LINTLIBRARY + flush_varargs(); +#endif + free_decl_spec(&decl_spec); + free_declarator($1); + } + ; + +opt_declaration_list + : /* empty */ + | T_VA_DCL + | declaration_list + ; + +declaration_list + : declaration + | declaration_list declaration + ; + +decl_specifiers + : decl_specifier + | decl_specifiers decl_specifier + { + join_decl_specs(&$$, &$1, &$2); + free($1.text); + free($2.text); + } + ; + +decl_specifier + : storage_class + | type_specifier + | type_qualifier + ; + +storage_class + : T_AUTO + { + new_decl_spec(&$$, $1.text, $1.begin, DS_NONE); + } + | T_EXTERN + { + new_decl_spec(&$$, $1.text, $1.begin, DS_EXTERN); + } + | T_REGISTER + { + new_decl_spec(&$$, $1.text, $1.begin, DS_NONE); + } + | T_STATIC + { + new_decl_spec(&$$, $1.text, $1.begin, DS_STATIC); + } + | T_INLINE + { + new_decl_spec(&$$, $1.text, $1.begin, DS_INLINE); + } + | T_EXTENSION + { + new_decl_spec(&$$, $1.text, $1.begin, DS_JUNK); + } + ; + +type_specifier + : T_CHAR + { + new_decl_spec(&$$, $1.text, $1.begin, DS_CHAR); + } + | T_DOUBLE + { + new_decl_spec(&$$, $1.text, $1.begin, DS_NONE); + } + | T_FLOAT + { + new_decl_spec(&$$, $1.text, $1.begin, DS_FLOAT); + } + | T_INT + { + new_decl_spec(&$$, $1.text, $1.begin, DS_NONE); + } + | T_LONG + { + new_decl_spec(&$$, $1.text, $1.begin, DS_NONE); + } + | T_SHORT + { + new_decl_spec(&$$, $1.text, $1.begin, DS_SHORT); + } + | T_SIGNED + { + new_decl_spec(&$$, $1.text, $1.begin, DS_NONE); + } + | T_UNSIGNED + { + new_decl_spec(&$$, $1.text, $1.begin, DS_NONE); + } + | T_VOID + { + new_decl_spec(&$$, $1.text, $1.begin, DS_NONE); + } + | T_Bool + { + new_decl_spec(&$$, $1.text, $1.begin, DS_CHAR); + } + | T_Complex + { + new_decl_spec(&$$, $1.text, $1.begin, DS_NONE); + } + | T_Imaginary + { + new_decl_spec(&$$, $1.text, $1.begin, DS_NONE); + } + | T_TYPEDEF_NAME + { + Symbol *s; + s = find_symbol(typedef_names, $1.text); + if (s != NULL) + new_decl_spec(&$$, $1.text, $1.begin, s->flags); + } + | struct_or_union_specifier + | enum_specifier + ; + +type_qualifier + : T_TYPE_QUALIFIER + { + new_decl_spec(&$$, $1.text, $1.begin, DS_NONE); + } + | T_DEFINE_NAME + { + /* This rule allows the <pointer> nonterminal to scan #define + * names as if they were type modifiers. + */ + Symbol *s; + s = find_symbol(define_names, $1.text); + if (s != NULL) + new_decl_spec(&$$, $1.text, $1.begin, s->flags); + } + ; + +struct_or_union_specifier + : struct_or_union any_id braces + { + char *s; + if ((s = implied_typedef()) == 0) + (void)sprintf(s = buf, "%s %s", $1.text, $2.text); + new_decl_spec(&$$, s, $1.begin, DS_NONE); + } + | struct_or_union braces + { + char *s; + if ((s = implied_typedef()) == 0) + (void)sprintf(s = buf, "%s {}", $1.text); + new_decl_spec(&$$, s, $1.begin, DS_NONE); + } + | struct_or_union any_id + { + (void)sprintf(buf, "%s %s", $1.text, $2.text); + new_decl_spec(&$$, buf, $1.begin, DS_NONE); + } + ; + +struct_or_union + : T_STRUCT + { + imply_typedef($$.text); + } + | T_UNION + { + imply_typedef($$.text); + } + ; + +init_declarator_list + : init_declarator + { + new_decl_list(&$$, $1); + } + | init_declarator_list ',' init_declarator + { + add_decl_list(&$$, &$1, $3); + } + ; + +init_declarator + : declarator + { + if ($1->func_def != FUNC_NONE && func_params == NULL && + func_style == FUNC_TRADITIONAL && cur_file->convert) { + gen_func_declarator($1); + fputs(cur_text(), cur_file->tmp_file); + } + cur_declarator = $$; + } + | declarator '=' + { + if ($1->func_def != FUNC_NONE && func_params == NULL && + func_style == FUNC_TRADITIONAL && cur_file->convert) { + gen_func_declarator($1); + fputs(" =", cur_file->tmp_file); + } + } + T_INITIALIZER + ; + +enum_specifier + : enumeration any_id braces + { + char *s; + if ((s = implied_typedef()) == 0) + (void)sprintf(s = buf, "enum %s", $2.text); + new_decl_spec(&$$, s, $1.begin, DS_NONE); + } + | enumeration braces + { + char *s; + if ((s = implied_typedef()) == 0) + (void)sprintf(s = buf, "%s {}", $1.text); + new_decl_spec(&$$, s, $1.begin, DS_NONE); + } + | enumeration any_id + { + (void)sprintf(buf, "enum %s", $2.text); + new_decl_spec(&$$, buf, $1.begin, DS_NONE); + } + ; + +enumeration + : T_ENUM + { + imply_typedef("enum"); + $$ = $1; + } + ; + +any_id + : T_IDENTIFIER + | T_TYPEDEF_NAME + ; + +declarator + : pointer direct_declarator + { + $$ = $2; + (void)sprintf(buf, "%s%s", $1.text, $$->text); + free($$->text); + $$->text = xstrdup(buf); + $$->begin = $1.begin; + $$->pointer = TRUE; + } + | direct_declarator + ; + +direct_declarator + : identifier_or_ref + { + $$ = new_declarator($1.text, $1.text, $1.begin); + } + | '(' declarator ')' + { + $$ = $2; + (void)sprintf(buf, "(%s)", $$->text); + free($$->text); + $$->text = xstrdup(buf); + $$->begin = $1.begin; + } + | direct_declarator T_BRACKETS + { + $$ = $1; + (void)sprintf(buf, "%s%s", $$->text, $2.text); + free($$->text); + $$->text = xstrdup(buf); + } + | direct_declarator '(' parameter_type_list ')' + { + $$ = new_declarator("%s()", $1->name, $1->begin); + $$->params = $3; + $$->func_stack = $1; + $$->head = ($1->func_stack == NULL) ? $$ : $1->head; + $$->func_def = FUNC_ANSI; + } + | direct_declarator '(' opt_identifier_list ')' + { + $$ = new_declarator("%s()", $1->name, $1->begin); + $$->params = $3; + $$->func_stack = $1; + $$->head = ($1->func_stack == NULL) ? $$ : $1->head; + $$->func_def = FUNC_TRADITIONAL; + } + ; + +pointer + : '*' opt_type_qualifiers + { + (void)sprintf($$.text, "*%s", $2.text); + $$.begin = $1.begin; + } + | '*' opt_type_qualifiers pointer + { + (void)sprintf($$.text, "*%s%s", $2.text, $3.text); + $$.begin = $1.begin; + } + ; + +opt_type_qualifiers + : /* empty */ + { + strcpy($$.text, ""); + $$.begin = 0L; + } + | type_qualifier_list + ; + +type_qualifier_list + : type_qualifier + { + (void)sprintf($$.text, "%s ", $1.text); + $$.begin = $1.begin; + free($1.text); + } + | type_qualifier_list type_qualifier + { + (void)sprintf($$.text, "%s%s ", $1.text, $2.text); + $$.begin = $1.begin; + free($2.text); + } + ; + +parameter_type_list + : parameter_list + | parameter_list ',' T_ELLIPSIS + { + add_ident_list(&$$, &$1, "..."); + } + ; + +parameter_list + : parameter_declaration + { + new_param_list(&$$, $1); + } + | parameter_list ',' parameter_declaration + { + add_param_list(&$$, &$1, $3); + } + ; + +parameter_declaration + : decl_specifiers declarator + { + check_untagged(&$1); + $$ = new_parameter(&$1, $2); + } + | decl_specifiers abs_declarator + { + check_untagged(&$1); + $$ = new_parameter(&$1, $2); + } + | decl_specifiers + { + check_untagged(&$1); + $$ = new_parameter(&$1, (Declarator *)0); + } + ; + +opt_identifier_list + : /* empty */ + { + new_ident_list(&$$); + } + | identifier_list + ; + +identifier_list + : any_id + { + new_ident_list(&$$); + add_ident_list(&$$, &$$, $1.text); + } + | identifier_list ',' any_id + { + add_ident_list(&$$, &$1, $3.text); + } + ; + +identifier_or_ref + : any_id + { + $$ = $1; + } + | '&' any_id + { +#if OPT_LINTLIBRARY + if (lintLibrary()) { /* Lint doesn't grok C++ ref variables */ + $$ = $2; + } else +#endif + (void)sprintf($$.text, "&%s", $2.text); + $$.begin = $1.begin; + } + ; + +abs_declarator + : pointer + { + $$ = new_declarator($1.text, "", $1.begin); + } + | pointer direct_abs_declarator + { + $$ = $2; + (void)sprintf(buf, "%s%s", $1.text, $$->text); + free($$->text); + $$->text = xstrdup(buf); + $$->begin = $1.begin; + } + | direct_abs_declarator + ; + +direct_abs_declarator + : '(' abs_declarator ')' + { + $$ = $2; + (void)sprintf(buf, "(%s)", $$->text); + free($$->text); + $$->text = xstrdup(buf); + $$->begin = $1.begin; + } + | direct_abs_declarator T_BRACKETS + { + $$ = $1; + (void)sprintf(buf, "%s%s", $$->text, $2.text); + free($$->text); + $$->text = xstrdup(buf); + } + | T_BRACKETS + { + $$ = new_declarator($1.text, "", $1.begin); + } + | direct_abs_declarator '(' parameter_type_list ')' + { + $$ = new_declarator("%s()", "", $1->begin); + $$->params = $3; + $$->func_stack = $1; + $$->head = ($1->func_stack == NULL) ? $$ : $1->head; + $$->func_def = FUNC_ANSI; + } + | direct_abs_declarator '(' ')' + { + $$ = new_declarator("%s()", "", $1->begin); + $$->func_stack = $1; + $$->head = ($1->func_stack == NULL) ? $$ : $1->head; + $$->func_def = FUNC_ANSI; + } + | '(' parameter_type_list ')' + { + Declarator *d; + + d = new_declarator("", "", $1.begin); + $$ = new_declarator("%s()", "", $1.begin); + $$->params = $2; + $$->func_stack = d; + $$->head = $$; + $$->func_def = FUNC_ANSI; + } + | '(' ')' + { + Declarator *d; + + d = new_declarator("", "", $1.begin); + $$ = new_declarator("%s()", "", $1.begin); + $$->func_stack = d; + $$->head = $$; + $$->func_def = FUNC_ANSI; + } + ; + +%% + +/* lex.yy.c */ +#define BEGIN yy_start = 1 + 2 * + +#define CPP1 1 +#define INIT1 2 +#define INIT2 3 +#define CURLY 4 +#define LEXYACC 5 +#define ASM 6 +#define CPP_INLINE 7 + +extern char *yytext; +extern FILE *yyin, *yyout; + +static int curly; /* number of curly brace nesting levels */ +static int ly_count; /* number of occurances of %% */ +static int inc_depth; /* include nesting level */ +static SymbolTable *included_files; /* files already included */ +static int yy_start = 0; /* start state number */ + +#define grammar_error(s) yaccError(s) + +static void +yaccError (const char *msg) +{ + func_params = NULL; + put_error(); /* tell what line we're on, and what file */ + fprintf(stderr, "%s at token '%s'\n", msg, yytext); +} + +/* Initialize the table of type qualifier keywords recognized by the lexical + * analyzer. + */ +void +init_parser (void) +{ + static const char *keywords[] = { + "const", + "restrict", + "volatile", + "interrupt", +#ifdef vms + "noshare", + "readonly", +#endif +#if defined(MSDOS) || defined(OS2) + "__cdecl", + "__export", + "__far", + "__fastcall", + "__fortran", + "__huge", + "__inline", + "__interrupt", + "__loadds", + "__near", + "__pascal", + "__saveregs", + "__segment", + "__stdcall", + "__syscall", + "_cdecl", + "_cs", + "_ds", + "_es", + "_export", + "_far", + "_fastcall", + "_fortran", + "_huge", + "_interrupt", + "_loadds", + "_near", + "_pascal", + "_saveregs", + "_seg", + "_segment", + "_ss", + "cdecl", + "far", + "huge", + "near", + "pascal", +#ifdef OS2 + "__far16", +#endif +#endif +#ifdef __GNUC__ + /* gcc aliases */ + "__builtin_va_arg", + "__builtin_va_list", + "__const", + "__const__", + "__inline", + "__inline__", + "__restrict", + "__restrict__", + "__volatile", + "__volatile__", +#endif + }; + unsigned i; + + /* Initialize type qualifier table. */ + type_qualifiers = new_symbol_table(); + for (i = 0; i < sizeof(keywords)/sizeof(keywords[0]); ++i) { + new_symbol(type_qualifiers, keywords[i], NULL, DS_NONE); + } +} + +/* Process the C source file. Write function prototypes to the standard + * output. Convert function definitions and write the converted source + * code to a temporary file. + */ +void +process_file (FILE *infile, char *name) +{ + char *s; + + if (strlen(name) > 2) { + s = name + strlen(name) - 2; + if (*s == '.') { + ++s; + if (*s == 'l' || *s == 'y') + BEGIN LEXYACC; +#if defined(MSDOS) || defined(OS2) + if (*s == 'L' || *s == 'Y') + BEGIN LEXYACC; +#endif + } + } + + included_files = new_symbol_table(); + typedef_names = new_symbol_table(); + define_names = new_symbol_table(); + inc_depth = -1; + curly = 0; + ly_count = 0; + func_params = NULL; + yyin = infile; + include_file(strcpy(base_file, name), func_style != FUNC_NONE); + if (file_comments) { +#if OPT_LINTLIBRARY + if (lintLibrary()) { + put_blankline(stdout); + begin_tracking(); + } +#endif + put_string(stdout, "/* "); + put_string(stdout, cur_file_name()); + put_string(stdout, " */\n"); + } + yyparse(); + free_symbol_table(define_names); + free_symbol_table(typedef_names); + free_symbol_table(included_files); +} + +#ifdef NO_LEAKS +void +free_parser(void) +{ + free_symbol_table (type_qualifiers); +#ifdef FLEX_SCANNER + if (yy_current_buffer != 0) + yy_delete_buffer(yy_current_buffer); +#endif +} +#endif diff --git a/test/pure_calc.output b/test/pure_calc.output new file mode 100644 index 000000000000..3aed47511c93 --- /dev/null +++ b/test/pure_calc.output @@ -0,0 +1,461 @@ + 0 $accept : list $end + + 1 list : + 2 | list stat '\n' + 3 | list error '\n' + + 4 stat : expr + 5 | LETTER '=' expr + + 6 expr : '(' expr ')' + 7 | expr '+' expr + 8 | expr '-' expr + 9 | expr '*' expr + 10 | expr '/' expr + 11 | expr '%' expr + 12 | expr '&' expr + 13 | expr '|' expr + 14 | '-' expr + 15 | LETTER + 16 | number + + 17 number : DIGIT + 18 | number DIGIT + +state 0 + $accept : . list $end (0) + list : . (1) + + . reduce 1 + + list goto 1 + + +state 1 + $accept : list . $end (0) + list : list . stat '\n' (2) + list : list . error '\n' (3) + + $end accept + error shift 2 + DIGIT shift 3 + LETTER shift 4 + '-' shift 5 + '(' shift 6 + . error + + stat goto 7 + expr goto 8 + number goto 9 + + +state 2 + list : list error . '\n' (3) + + '\n' shift 10 + . error + + +state 3 + number : DIGIT . (17) + + . reduce 17 + + +state 4 + stat : LETTER . '=' expr (5) + expr : LETTER . (15) + + '=' shift 11 + '|' reduce 15 + '&' reduce 15 + '+' reduce 15 + '-' reduce 15 + '*' reduce 15 + '/' reduce 15 + '%' reduce 15 + '\n' reduce 15 + + +state 5 + expr : '-' . expr (14) + + DIGIT shift 3 + LETTER shift 12 + '-' shift 5 + '(' shift 6 + . error + + expr goto 13 + number goto 9 + + +state 6 + expr : '(' . expr ')' (6) + + DIGIT shift 3 + LETTER shift 12 + '-' shift 5 + '(' shift 6 + . error + + expr goto 14 + number goto 9 + + +state 7 + list : list stat . '\n' (2) + + '\n' shift 15 + . error + + +state 8 + stat : expr . (4) + expr : expr . '+' expr (7) + expr : expr . '-' expr (8) + expr : expr . '*' expr (9) + expr : expr . '/' expr (10) + expr : expr . '%' expr (11) + expr : expr . '&' expr (12) + expr : expr . '|' expr (13) + + '|' shift 16 + '&' shift 17 + '+' shift 18 + '-' shift 19 + '*' shift 20 + '/' shift 21 + '%' shift 22 + '\n' reduce 4 + + +state 9 + expr : number . (16) + number : number . DIGIT (18) + + DIGIT shift 23 + '|' reduce 16 + '&' reduce 16 + '+' reduce 16 + '-' reduce 16 + '*' reduce 16 + '/' reduce 16 + '%' reduce 16 + '\n' reduce 16 + ')' reduce 16 + + +state 10 + list : list error '\n' . (3) + + . reduce 3 + + +state 11 + stat : LETTER '=' . expr (5) + + DIGIT shift 3 + LETTER shift 12 + '-' shift 5 + '(' shift 6 + . error + + expr goto 24 + number goto 9 + + +state 12 + expr : LETTER . (15) + + . reduce 15 + + +state 13 + expr : expr . '+' expr (7) + expr : expr . '-' expr (8) + expr : expr . '*' expr (9) + expr : expr . '/' expr (10) + expr : expr . '%' expr (11) + expr : expr . '&' expr (12) + expr : expr . '|' expr (13) + expr : '-' expr . (14) + + . reduce 14 + + +state 14 + expr : '(' expr . ')' (6) + expr : expr . '+' expr (7) + expr : expr . '-' expr (8) + expr : expr . '*' expr (9) + expr : expr . '/' expr (10) + expr : expr . '%' expr (11) + expr : expr . '&' expr (12) + expr : expr . '|' expr (13) + + '|' shift 16 + '&' shift 17 + '+' shift 18 + '-' shift 19 + '*' shift 20 + '/' shift 21 + '%' shift 22 + ')' shift 25 + . error + + +state 15 + list : list stat '\n' . (2) + + . reduce 2 + + +state 16 + expr : expr '|' . expr (13) + + DIGIT shift 3 + LETTER shift 12 + '-' shift 5 + '(' shift 6 + . error + + expr goto 26 + number goto 9 + + +state 17 + expr : expr '&' . expr (12) + + DIGIT shift 3 + LETTER shift 12 + '-' shift 5 + '(' shift 6 + . error + + expr goto 27 + number goto 9 + + +state 18 + expr : expr '+' . expr (7) + + DIGIT shift 3 + LETTER shift 12 + '-' shift 5 + '(' shift 6 + . error + + expr goto 28 + number goto 9 + + +state 19 + expr : expr '-' . expr (8) + + DIGIT shift 3 + LETTER shift 12 + '-' shift 5 + '(' shift 6 + . error + + expr goto 29 + number goto 9 + + +state 20 + expr : expr '*' . expr (9) + + DIGIT shift 3 + LETTER shift 12 + '-' shift 5 + '(' shift 6 + . error + + expr goto 30 + number goto 9 + + +state 21 + expr : expr '/' . expr (10) + + DIGIT shift 3 + LETTER shift 12 + '-' shift 5 + '(' shift 6 + . error + + expr goto 31 + number goto 9 + + +state 22 + expr : expr '%' . expr (11) + + DIGIT shift 3 + LETTER shift 12 + '-' shift 5 + '(' shift 6 + . error + + expr goto 32 + number goto 9 + + +state 23 + number : number DIGIT . (18) + + . reduce 18 + + +state 24 + stat : LETTER '=' expr . (5) + expr : expr . '+' expr (7) + expr : expr . '-' expr (8) + expr : expr . '*' expr (9) + expr : expr . '/' expr (10) + expr : expr . '%' expr (11) + expr : expr . '&' expr (12) + expr : expr . '|' expr (13) + + '|' shift 16 + '&' shift 17 + '+' shift 18 + '-' shift 19 + '*' shift 20 + '/' shift 21 + '%' shift 22 + '\n' reduce 5 + + +state 25 + expr : '(' expr ')' . (6) + + . reduce 6 + + +state 26 + expr : expr . '+' expr (7) + expr : expr . '-' expr (8) + expr : expr . '*' expr (9) + expr : expr . '/' expr (10) + expr : expr . '%' expr (11) + expr : expr . '&' expr (12) + expr : expr . '|' expr (13) + expr : expr '|' expr . (13) + + '&' shift 17 + '+' shift 18 + '-' shift 19 + '*' shift 20 + '/' shift 21 + '%' shift 22 + '|' reduce 13 + '\n' reduce 13 + ')' reduce 13 + + +state 27 + expr : expr . '+' expr (7) + expr : expr . '-' expr (8) + expr : expr . '*' expr (9) + expr : expr . '/' expr (10) + expr : expr . '%' expr (11) + expr : expr . '&' expr (12) + expr : expr '&' expr . (12) + expr : expr . '|' expr (13) + + '+' shift 18 + '-' shift 19 + '*' shift 20 + '/' shift 21 + '%' shift 22 + '|' reduce 12 + '&' reduce 12 + '\n' reduce 12 + ')' reduce 12 + + +state 28 + expr : expr . '+' expr (7) + expr : expr '+' expr . (7) + expr : expr . '-' expr (8) + expr : expr . '*' expr (9) + expr : expr . '/' expr (10) + expr : expr . '%' expr (11) + expr : expr . '&' expr (12) + expr : expr . '|' expr (13) + + '*' shift 20 + '/' shift 21 + '%' shift 22 + '|' reduce 7 + '&' reduce 7 + '+' reduce 7 + '-' reduce 7 + '\n' reduce 7 + ')' reduce 7 + + +state 29 + expr : expr . '+' expr (7) + expr : expr . '-' expr (8) + expr : expr '-' expr . (8) + expr : expr . '*' expr (9) + expr : expr . '/' expr (10) + expr : expr . '%' expr (11) + expr : expr . '&' expr (12) + expr : expr . '|' expr (13) + + '*' shift 20 + '/' shift 21 + '%' shift 22 + '|' reduce 8 + '&' reduce 8 + '+' reduce 8 + '-' reduce 8 + '\n' reduce 8 + ')' reduce 8 + + +state 30 + expr : expr . '+' expr (7) + expr : expr . '-' expr (8) + expr : expr . '*' expr (9) + expr : expr '*' expr . (9) + expr : expr . '/' expr (10) + expr : expr . '%' expr (11) + expr : expr . '&' expr (12) + expr : expr . '|' expr (13) + + . reduce 9 + + +state 31 + expr : expr . '+' expr (7) + expr : expr . '-' expr (8) + expr : expr . '*' expr (9) + expr : expr . '/' expr (10) + expr : expr '/' expr . (10) + expr : expr . '%' expr (11) + expr : expr . '&' expr (12) + expr : expr . '|' expr (13) + + . reduce 10 + + +state 32 + expr : expr . '+' expr (7) + expr : expr . '-' expr (8) + expr : expr . '*' expr (9) + expr : expr . '/' expr (10) + expr : expr . '%' expr (11) + expr : expr '%' expr . (11) + expr : expr . '&' expr (12) + expr : expr . '|' expr (13) + + . reduce 11 + + +16 terminals, 5 nonterminals +19 grammar rules, 33 states diff --git a/test/pure_calc.tab.c b/test/pure_calc.tab.c new file mode 100644 index 000000000000..eb8c189b5086 --- /dev/null +++ b/test/pure_calc.tab.c @@ -0,0 +1,687 @@ +#ifndef lint +static const char yysccsid[] = "@(#)yaccpar 1.9 (Berkeley) 02/21/93"; +#endif + +#define YYBYACC 1 +#define YYMAJOR 1 +#define YYMINOR 9 + +#define YYEMPTY (-1) +#define yyclearin (yychar = YYEMPTY) +#define yyerrok (yyerrflag = 0) +#define YYRECOVERING() (yyerrflag != 0) + + +#ifndef yyparse +#define yyparse calc_parse +#endif /* yyparse */ + +#ifndef yylex +#define yylex calc_lex +#endif /* yylex */ + +#ifndef yyerror +#define yyerror calc_error +#endif /* yyerror */ + +#ifndef yychar +#define yychar calc_char +#endif /* yychar */ + +#ifndef yyval +#define yyval calc_val +#endif /* yyval */ + +#ifndef yylval +#define yylval calc_lval +#endif /* yylval */ + +#ifndef yydebug +#define yydebug calc_debug +#endif /* yydebug */ + +#ifndef yynerrs +#define yynerrs calc_nerrs +#endif /* yynerrs */ + +#ifndef yyerrflag +#define yyerrflag calc_errflag +#endif /* yyerrflag */ + +#ifndef yylhs +#define yylhs calc_lhs +#endif /* yylhs */ + +#ifndef yylen +#define yylen calc_len +#endif /* yylen */ + +#ifndef yydefred +#define yydefred calc_defred +#endif /* yydefred */ + +#ifndef yydgoto +#define yydgoto calc_dgoto +#endif /* yydgoto */ + +#ifndef yysindex +#define yysindex calc_sindex +#endif /* yysindex */ + +#ifndef yyrindex +#define yyrindex calc_rindex +#endif /* yyrindex */ + +#ifndef yygindex +#define yygindex calc_gindex +#endif /* yygindex */ + +#ifndef yytable +#define yytable calc_table +#endif /* yytable */ + +#ifndef yycheck +#define yycheck calc_check +#endif /* yycheck */ + +#ifndef yyname +#define yyname calc_name +#endif /* yyname */ + +#ifndef yyrule +#define yyrule calc_rule +#endif /* yyrule */ +#define YYPREFIX "calc_" + +#define YYPURE 1 + +#line 2 "pure_calc.y" +# include <stdio.h> +# include <ctype.h> + +int regs[26]; +int base; + +#ifdef YYBISON +#define YYSTYPE int +#define YYLEX_PARAM &yylval +#define YYLEX_DECL() yylex(YYSTYPE *yylval) +#define YYERROR_DECL() yyerror(const char *s) +int YYLEX_DECL(); +static void YYERROR_DECL(); +#endif + +#line 115 "pure_calc.tab.c" + +#ifndef YYSTYPE +typedef int YYSTYPE; +#endif + +/* compatibility with bison */ +#ifdef YYPARSE_PARAM +/* compatibility with FreeBSD */ +# ifdef YYPARSE_PARAM_TYPE +# define YYPARSE_DECL() yyparse(YYPARSE_PARAM_TYPE YYPARSE_PARAM) +# else +# define YYPARSE_DECL() yyparse(void *YYPARSE_PARAM) +# endif +#else +# define YYPARSE_DECL() yyparse(void) +#endif + +/* Parameters sent to lex. */ +#ifdef YYLEX_PARAM +# ifdef YYLEX_PARAM_TYPE +# define YYLEX_DECL() yylex(YYSTYPE *yylval, YYLEX_PARAM_TYPE YYLEX_PARAM) +# else +# define YYLEX_DECL() yylex(YYSTYPE *yylval, void * YYLEX_PARAM) +# endif +# define YYLEX yylex(&yylval, YYLEX_PARAM) +#else +# define YYLEX_DECL() yylex(YYSTYPE *yylval) +# define YYLEX yylex(&yylval) +#endif + +/* Parameters sent to yyerror. */ +#ifndef YYERROR_DECL +#define YYERROR_DECL() yyerror(const char *s) +#endif +#ifndef YYERROR_CALL +#define YYERROR_CALL(msg) yyerror(msg) +#endif + +extern int YYPARSE_DECL(); + +#define DIGIT 257 +#define LETTER 258 +#define UMINUS 259 +#define YYERRCODE 256 +static const short calc_lhs[] = { -1, + 0, 0, 0, 1, 1, 2, 2, 2, 2, 2, + 2, 2, 2, 2, 2, 2, 3, 3, +}; +static const short calc_len[] = { 2, + 0, 3, 3, 1, 3, 3, 3, 3, 3, 3, + 3, 3, 3, 2, 1, 1, 1, 2, +}; +static const short calc_defred[] = { 1, + 0, 0, 17, 0, 0, 0, 0, 0, 0, 3, + 0, 15, 14, 0, 2, 0, 0, 0, 0, 0, + 0, 0, 18, 0, 6, 0, 0, 0, 0, 9, + 10, 11, +}; +static const short calc_dgoto[] = { 1, + 7, 8, 9, +}; +static const short calc_sindex[] = { 0, + -40, -7, 0, -55, -38, -38, 1, -29, -247, 0, + -38, 0, 0, 22, 0, -38, -38, -38, -38, -38, + -38, -38, 0, -29, 0, 51, 60, -20, -20, 0, + 0, 0, +}; +static const short calc_rindex[] = { 0, + 0, 0, 0, 2, 0, 0, 0, 9, -9, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 10, 0, -6, 14, 5, 13, 0, + 0, 0, +}; +static const short calc_gindex[] = { 0, + 0, 65, 0, +}; +#define YYTABLESIZE 220 +static const short calc_table[] = { 6, + 16, 6, 10, 13, 5, 11, 5, 22, 17, 23, + 15, 15, 20, 18, 7, 19, 22, 21, 4, 5, + 0, 20, 8, 12, 0, 0, 21, 16, 16, 0, + 0, 16, 16, 16, 13, 16, 0, 16, 15, 15, + 0, 0, 7, 15, 15, 7, 15, 7, 15, 7, + 8, 12, 0, 8, 12, 8, 0, 8, 22, 17, + 0, 0, 25, 20, 18, 0, 19, 0, 21, 13, + 14, 0, 0, 0, 0, 24, 0, 0, 0, 0, + 26, 27, 28, 29, 30, 31, 32, 22, 17, 0, + 0, 0, 20, 18, 16, 19, 22, 21, 0, 0, + 0, 20, 18, 0, 19, 0, 21, 0, 0, 0, + 0, 0, 0, 0, 16, 0, 0, 13, 0, 0, + 0, 0, 0, 0, 0, 15, 0, 0, 7, 0, + 0, 0, 0, 0, 0, 0, 8, 12, 0, 0, + 0, 0, 0, 0, 0, 16, 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, 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, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 2, 3, 4, 3, 12, +}; +static const short calc_check[] = { 40, + 10, 40, 10, 10, 45, 61, 45, 37, 38, 257, + 10, 10, 42, 43, 10, 45, 37, 47, 10, 10, + -1, 42, 10, 10, -1, -1, 47, 37, 38, -1, + -1, 41, 42, 43, 41, 45, -1, 47, 37, 38, + -1, -1, 38, 42, 43, 41, 45, 43, 47, 45, + 38, 38, -1, 41, 41, 43, -1, 45, 37, 38, + -1, -1, 41, 42, 43, -1, 45, -1, 47, 5, + 6, -1, -1, -1, -1, 11, -1, -1, -1, -1, + 16, 17, 18, 19, 20, 21, 22, 37, 38, -1, + -1, -1, 42, 43, 124, 45, 37, 47, -1, -1, + -1, 42, 43, -1, 45, -1, 47, -1, -1, -1, + -1, -1, -1, -1, 124, -1, -1, 124, -1, -1, + -1, -1, -1, -1, -1, 124, -1, -1, 124, -1, + -1, -1, -1, -1, -1, -1, 124, 124, -1, -1, + -1, -1, -1, -1, -1, 124, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, 256, 257, 258, 257, 258, +}; +#define YYFINAL 1 +#ifndef YYDEBUG +#define YYDEBUG 0 +#endif +#define YYMAXTOKEN 259 +#if YYDEBUG +static const char *yyname[] = { + +"end-of-file",0,0,0,0,0,0,0,0,0,"'\\n'",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,"'-'",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,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,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,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,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,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,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,0,0,0,0,0,0, +0,0,0,0,0,0,"DIGIT","LETTER","UMINUS", +}; +static const char *yyrule[] = { +"$accept : list", +"list :", +"list : list stat '\\n'", +"list : list error '\\n'", +"stat : expr", +"stat : LETTER '=' expr", +"expr : '(' expr ')'", +"expr : expr '+' expr", +"expr : expr '-' expr", +"expr : expr '*' expr", +"expr : expr '/' expr", +"expr : expr '%' expr", +"expr : expr '&' expr", +"expr : expr '|' expr", +"expr : '-' expr", +"expr : LETTER", +"expr : number", +"number : DIGIT", +"number : number DIGIT", + +}; +#endif + +int yydebug; +int yynerrs; + +/* define the initial stack-sizes */ +#ifdef YYSTACKSIZE +#undef YYMAXDEPTH +#define YYMAXDEPTH YYSTACKSIZE +#else +#ifdef YYMAXDEPTH +#define YYSTACKSIZE YYMAXDEPTH +#else +#define YYSTACKSIZE 500 +#define YYMAXDEPTH 500 +#endif +#endif + +#define YYINITSTACKSIZE 500 + +typedef struct { + unsigned stacksize; + short *s_base; + short *s_mark; + short *s_last; + YYSTYPE *l_base; + YYSTYPE *l_mark; +} YYSTACKDATA; +#line 72 "pure_calc.y" + /* start of programs */ + +#ifdef YYBYACC +static int YYLEX_DECL(); +#endif + +int +main (void) +{ + while(!feof(stdin)) { + yyparse(); + } + return 0; +} + +static void +YYERROR_DECL() +{ + fprintf(stderr, "%s\n", s); +} + +int +YYLEX_DECL() +{ + /* lexical analysis routine */ + /* returns LETTER for a lower case letter, yylval = 0 through 25 */ + /* return DIGIT for a digit, yylval = 0 through 9 */ + /* all other characters are returned immediately */ + + int c; + + while( (c=getchar()) == ' ' ) { /* skip blanks */ } + + /* c is now nonblank */ + + if( islower( c )) { + *yylval = c - 'a'; + return ( LETTER ); + } + if( isdigit( c )) { + *yylval = c - '0'; + return ( DIGIT ); + } + return( c ); +} +#line 354 "pure_calc.tab.c" + +#if YYDEBUG +#include <stdio.h> /* needed for printf */ +#endif + +#include <stdlib.h> /* needed for malloc, etc */ +#include <string.h> /* needed for memset */ + +/* allocate initial stack or double stack size, up to YYMAXDEPTH */ +static int yygrowstack(YYSTACKDATA *data) +{ + int i; + unsigned newsize; + short *newss; + YYSTYPE *newvs; + + if ((newsize = data->stacksize) == 0) + newsize = YYINITSTACKSIZE; + else if (newsize >= YYMAXDEPTH) + return -1; + else if ((newsize *= 2) > YYMAXDEPTH) + newsize = YYMAXDEPTH; + + i = data->s_mark - data->s_base; + newss = (short *)realloc(data->s_base, newsize * sizeof(*newss)); + if (newss == 0) + return -1; + + data->s_base = newss; + data->s_mark = newss + i; + + newvs = (YYSTYPE *)realloc(data->l_base, newsize * sizeof(*newvs)); + if (newvs == 0) + return -1; + + data->l_base = newvs; + data->l_mark = newvs + i; + + data->stacksize = newsize; + data->s_last = data->s_base + newsize - 1; + return 0; +} + +#if YYPURE || defined(YY_NO_LEAKS) +static void yyfreestack(YYSTACKDATA *data) +{ + free(data->s_base); + free(data->l_base); + memset(data, 0, sizeof(*data)); +} +#else +#define yyfreestack(data) /* nothing */ +#endif + +#define YYABORT goto yyabort +#define YYREJECT goto yyabort +#define YYACCEPT goto yyaccept +#define YYERROR goto yyerrlab + +int +YYPARSE_DECL() +{ + int yyerrflag; + int yychar; + YYSTYPE yyval; + YYSTYPE yylval; + + /* variables for the parser stack */ + YYSTACKDATA yystack; + int yym, yyn, yystate; +#if YYDEBUG + const char *yys; + + if ((yys = getenv("YYDEBUG")) != 0) + { + yyn = *yys; + if (yyn >= '0' && yyn <= '9') + yydebug = yyn - '0'; + } +#endif + + yynerrs = 0; + yyerrflag = 0; + yychar = YYEMPTY; + yystate = 0; + +#if YYPURE + memset(&yystack, 0, sizeof(yystack)); +#endif + + if (yystack.s_base == NULL && yygrowstack(&yystack)) goto yyoverflow; + yystack.s_mark = yystack.s_base; + yystack.l_mark = yystack.l_base; + yystate = 0; + *yystack.s_mark = 0; + +yyloop: + if ((yyn = yydefred[yystate]) != 0) goto yyreduce; + if (yychar < 0) + { + if ((yychar = YYLEX) < 0) yychar = 0; +#if YYDEBUG + if (yydebug) + { + yys = 0; + if (yychar <= YYMAXTOKEN) yys = yyname[yychar]; + if (!yys) yys = "illegal-symbol"; + printf("%sdebug: state %d, reading %d (%s)\n", + YYPREFIX, yystate, yychar, yys); + } +#endif + } + if ((yyn = yysindex[yystate]) && (yyn += yychar) >= 0 && + yyn <= YYTABLESIZE && yycheck[yyn] == yychar) + { +#if YYDEBUG + if (yydebug) + printf("%sdebug: state %d, shifting to state %d\n", + YYPREFIX, yystate, yytable[yyn]); +#endif + if (yystack.s_mark >= yystack.s_last && yygrowstack(&yystack)) + { + goto yyoverflow; + } + yystate = yytable[yyn]; + *++yystack.s_mark = yytable[yyn]; + *++yystack.l_mark = yylval; + yychar = YYEMPTY; + if (yyerrflag > 0) --yyerrflag; + goto yyloop; + } + if ((yyn = yyrindex[yystate]) && (yyn += yychar) >= 0 && + yyn <= YYTABLESIZE && yycheck[yyn] == yychar) + { + yyn = yytable[yyn]; + goto yyreduce; + } + if (yyerrflag) goto yyinrecovery; + + yyerror("syntax error"); + + goto yyerrlab; + +yyerrlab: + ++yynerrs; + +yyinrecovery: + if (yyerrflag < 3) + { + yyerrflag = 3; + for (;;) + { + if ((yyn = yysindex[*yystack.s_mark]) && (yyn += YYERRCODE) >= 0 && + yyn <= YYTABLESIZE && yycheck[yyn] == YYERRCODE) + { +#if YYDEBUG + if (yydebug) + printf("%sdebug: state %d, error recovery shifting\ + to state %d\n", YYPREFIX, *yystack.s_mark, yytable[yyn]); +#endif + if (yystack.s_mark >= yystack.s_last && yygrowstack(&yystack)) + { + goto yyoverflow; + } + yystate = yytable[yyn]; + *++yystack.s_mark = yytable[yyn]; + *++yystack.l_mark = yylval; + goto yyloop; + } + else + { +#if YYDEBUG + if (yydebug) + printf("%sdebug: error recovery discarding state %d\n", + YYPREFIX, *yystack.s_mark); +#endif + if (yystack.s_mark <= yystack.s_base) goto yyabort; + --yystack.s_mark; + --yystack.l_mark; + } + } + } + else + { + if (yychar == 0) goto yyabort; +#if YYDEBUG + if (yydebug) + { + yys = 0; + if (yychar <= YYMAXTOKEN) yys = yyname[yychar]; + if (!yys) yys = "illegal-symbol"; + printf("%sdebug: state %d, error recovery discards token %d (%s)\n", + YYPREFIX, yystate, yychar, yys); + } +#endif + yychar = YYEMPTY; + goto yyloop; + } + +yyreduce: +#if YYDEBUG + if (yydebug) + printf("%sdebug: state %d, reducing by rule %d (%s)\n", + YYPREFIX, yystate, yyn, yyrule[yyn]); +#endif + yym = yylen[yyn]; + if (yym) + yyval = yystack.l_mark[1-yym]; + else + memset(&yyval, 0, sizeof yyval); + switch (yyn) + { +case 3: +#line 34 "pure_calc.y" + { yyerrok ; } +break; +case 4: +#line 38 "pure_calc.y" + { printf("%d\n",yystack.l_mark[0]);} +break; +case 5: +#line 40 "pure_calc.y" + { regs[yystack.l_mark[-2]] = yystack.l_mark[0]; } +break; +case 6: +#line 44 "pure_calc.y" + { yyval = yystack.l_mark[-1]; } +break; +case 7: +#line 46 "pure_calc.y" + { yyval = yystack.l_mark[-2] + yystack.l_mark[0]; } +break; +case 8: +#line 48 "pure_calc.y" + { yyval = yystack.l_mark[-2] - yystack.l_mark[0]; } +break; +case 9: +#line 50 "pure_calc.y" + { yyval = yystack.l_mark[-2] * yystack.l_mark[0]; } +break; +case 10: +#line 52 "pure_calc.y" + { yyval = yystack.l_mark[-2] / yystack.l_mark[0]; } +break; +case 11: +#line 54 "pure_calc.y" + { yyval = yystack.l_mark[-2] % yystack.l_mark[0]; } +break; +case 12: +#line 56 "pure_calc.y" + { yyval = yystack.l_mark[-2] & yystack.l_mark[0]; } +break; +case 13: +#line 58 "pure_calc.y" + { yyval = yystack.l_mark[-2] | yystack.l_mark[0]; } +break; +case 14: +#line 60 "pure_calc.y" + { yyval = - yystack.l_mark[0]; } +break; +case 15: +#line 62 "pure_calc.y" + { yyval = regs[yystack.l_mark[0]]; } +break; +case 17: +#line 67 "pure_calc.y" + { yyval = yystack.l_mark[0]; base = (yystack.l_mark[0]==0) ? 8 : 10; } +break; +case 18: +#line 69 "pure_calc.y" + { yyval = base * yystack.l_mark[-1] + yystack.l_mark[0]; } +break; +#line 627 "pure_calc.tab.c" + } + yystack.s_mark -= yym; + yystate = *yystack.s_mark; + yystack.l_mark -= yym; + yym = yylhs[yyn]; + if (yystate == 0 && yym == 0) + { +#if YYDEBUG + if (yydebug) + printf("%sdebug: after reduction, shifting from state 0 to\ + state %d\n", YYPREFIX, YYFINAL); +#endif + yystate = YYFINAL; + *++yystack.s_mark = YYFINAL; + *++yystack.l_mark = yyval; + if (yychar < 0) + { + if ((yychar = YYLEX) < 0) yychar = 0; +#if YYDEBUG + if (yydebug) + { + yys = 0; + if (yychar <= YYMAXTOKEN) yys = yyname[yychar]; + if (!yys) yys = "illegal-symbol"; + printf("%sdebug: state %d, reading %d (%s)\n", + YYPREFIX, YYFINAL, yychar, yys); + } +#endif + } + if (yychar == 0) goto yyaccept; + goto yyloop; + } + if ((yyn = yygindex[yym]) && (yyn += yystate) >= 0 && + yyn <= YYTABLESIZE && yycheck[yyn] == yystate) + yystate = yytable[yyn]; + else + yystate = yydgoto[yym]; +#if YYDEBUG + if (yydebug) + printf("%sdebug: after reduction, shifting from state %d \ +to state %d\n", YYPREFIX, *yystack.s_mark, yystate); +#endif + if (yystack.s_mark >= yystack.s_last && yygrowstack(&yystack)) + { + goto yyoverflow; + } + *++yystack.s_mark = (short) yystate; + *++yystack.l_mark = yyval; + goto yyloop; + +yyoverflow: + yyerror("yacc stack overflow"); + +yyabort: + yyfreestack(&yystack); + return (1); + +yyaccept: + yyfreestack(&yystack); + return (0); +} diff --git a/test/pure_calc.tab.h b/test/pure_calc.tab.h new file mode 100644 index 000000000000..19211182d6b3 --- /dev/null +++ b/test/pure_calc.tab.h @@ -0,0 +1,3 @@ +#define DIGIT 257 +#define LETTER 258 +#define UMINUS 259 diff --git a/test/pure_calc.y b/test/pure_calc.y new file mode 100644 index 000000000000..3cd04332dcdd --- /dev/null +++ b/test/pure_calc.y @@ -0,0 +1,116 @@ +%{ +# include <stdio.h> +# include <ctype.h> + +int regs[26]; +int base; + +#ifdef YYBISON +#define YYSTYPE int +#define YYLEX_PARAM &yylval +#define YYLEX_DECL() yylex(YYSTYPE *yylval) +#define YYERROR_DECL() yyerror(const char *s) +int YYLEX_DECL(); +static void YYERROR_DECL(); +#endif + +%} + +%start list + +%token DIGIT LETTER + +%left '|' +%left '&' +%left '+' '-' +%left '*' '/' '%' +%left UMINUS /* supplies precedence for unary minus */ + +%% /* beginning of rules section */ + +list : /* empty */ + | list stat '\n' + | list error '\n' + { yyerrok ; } + ; + +stat : expr + { printf("%d\n",$1);} + | LETTER '=' expr + { regs[$1] = $3; } + ; + +expr : '(' expr ')' + { $$ = $2; } + | expr '+' expr + { $$ = $1 + $3; } + | expr '-' expr + { $$ = $1 - $3; } + | expr '*' expr + { $$ = $1 * $3; } + | expr '/' expr + { $$ = $1 / $3; } + | expr '%' expr + { $$ = $1 % $3; } + | expr '&' expr + { $$ = $1 & $3; } + | expr '|' expr + { $$ = $1 | $3; } + | '-' expr %prec UMINUS + { $$ = - $2; } + | LETTER + { $$ = regs[$1]; } + | number + ; + +number: DIGIT + { $$ = $1; base = ($1==0) ? 8 : 10; } + | number DIGIT + { $$ = base * $1 + $2; } + ; + +%% /* start of programs */ + +#ifdef YYBYACC +static int YYLEX_DECL(); +#endif + +int +main (void) +{ + while(!feof(stdin)) { + yyparse(); + } + return 0; +} + +static void +YYERROR_DECL() +{ + fprintf(stderr, "%s\n", s); +} + +int +YYLEX_DECL() +{ + /* lexical analysis routine */ + /* returns LETTER for a lower case letter, yylval = 0 through 25 */ + /* return DIGIT for a digit, yylval = 0 through 9 */ + /* all other characters are returned immediately */ + + int c; + + while( (c=getchar()) == ' ' ) { /* skip blanks */ } + + /* c is now nonblank */ + + if( islower( c )) { + *yylval = c - 'a'; + return ( LETTER ); + } + if( isdigit( c )) { + *yylval = c - '0'; + return ( DIGIT ); + } + return( c ); +} diff --git a/test/pure_error.output b/test/pure_error.output new file mode 100644 index 000000000000..0c4db6225e24 --- /dev/null +++ b/test/pure_error.output @@ -0,0 +1,27 @@ + 0 $accept : S $end + + 1 S : error + +state 0 + $accept : . S $end (0) + + error shift 1 + . error + + S goto 2 + + +state 1 + S : error . (1) + + . reduce 1 + + +state 2 + $accept : S . $end (0) + + $end accept + + +2 terminals, 2 nonterminals +2 grammar rules, 3 states diff --git a/test/pure_error.tab.c b/test/pure_error.tab.c new file mode 100644 index 000000000000..98de3d8299b7 --- /dev/null +++ b/test/pure_error.tab.c @@ -0,0 +1,517 @@ +#ifndef lint +static const char yysccsid[] = "@(#)yaccpar 1.9 (Berkeley) 02/21/93"; +#endif + +#define YYBYACC 1 +#define YYMAJOR 1 +#define YYMINOR 9 + +#define YYEMPTY (-1) +#define yyclearin (yychar = YYEMPTY) +#define yyerrok (yyerrflag = 0) +#define YYRECOVERING() (yyerrflag != 0) + + +#ifndef yyparse +#define yyparse error_parse +#endif /* yyparse */ + +#ifndef yylex +#define yylex error_lex +#endif /* yylex */ + +#ifndef yyerror +#define yyerror error_error +#endif /* yyerror */ + +#ifndef yychar +#define yychar error_char +#endif /* yychar */ + +#ifndef yyval +#define yyval error_val +#endif /* yyval */ + +#ifndef yylval +#define yylval error_lval +#endif /* yylval */ + +#ifndef yydebug +#define yydebug error_debug +#endif /* yydebug */ + +#ifndef yynerrs +#define yynerrs error_nerrs +#endif /* yynerrs */ + +#ifndef yyerrflag +#define yyerrflag error_errflag +#endif /* yyerrflag */ + +#ifndef yylhs +#define yylhs error_lhs +#endif /* yylhs */ + +#ifndef yylen +#define yylen error_len +#endif /* yylen */ + +#ifndef yydefred +#define yydefred error_defred +#endif /* yydefred */ + +#ifndef yydgoto +#define yydgoto error_dgoto +#endif /* yydgoto */ + +#ifndef yysindex +#define yysindex error_sindex +#endif /* yysindex */ + +#ifndef yyrindex +#define yyrindex error_rindex +#endif /* yyrindex */ + +#ifndef yygindex +#define yygindex error_gindex +#endif /* yygindex */ + +#ifndef yytable +#define yytable error_table +#endif /* yytable */ + +#ifndef yycheck +#define yycheck error_check +#endif /* yycheck */ + +#ifndef yyname +#define yyname error_name +#endif /* yyname */ + +#ifndef yyrule +#define yyrule error_rule +#endif /* yyrule */ +#define YYPREFIX "error_" + +#define YYPURE 1 + +#line 2 "pure_error.y" + +#ifdef YYBISON +#define YYSTYPE int +#define YYLEX_PARAM &yylval +#define YYLEX_DECL() yylex(YYSTYPE *yylval) +#define YYERROR_DECL() yyerror(const char *s) +int YYLEX_DECL(); +static void YYERROR_DECL(); +#endif + +#line 110 "pure_error.tab.c" + +#ifndef YYSTYPE +typedef int YYSTYPE; +#endif + +/* compatibility with bison */ +#ifdef YYPARSE_PARAM +/* compatibility with FreeBSD */ +# ifdef YYPARSE_PARAM_TYPE +# define YYPARSE_DECL() yyparse(YYPARSE_PARAM_TYPE YYPARSE_PARAM) +# else +# define YYPARSE_DECL() yyparse(void *YYPARSE_PARAM) +# endif +#else +# define YYPARSE_DECL() yyparse(void) +#endif + +/* Parameters sent to lex. */ +#ifdef YYLEX_PARAM +# ifdef YYLEX_PARAM_TYPE +# define YYLEX_DECL() yylex(YYSTYPE *yylval, YYLEX_PARAM_TYPE YYLEX_PARAM) +# else +# define YYLEX_DECL() yylex(YYSTYPE *yylval, void * YYLEX_PARAM) +# endif +# define YYLEX yylex(&yylval, YYLEX_PARAM) +#else +# define YYLEX_DECL() yylex(YYSTYPE *yylval) +# define YYLEX yylex(&yylval) +#endif + +/* Parameters sent to yyerror. */ +#ifndef YYERROR_DECL +#define YYERROR_DECL() yyerror(const char *s) +#endif +#ifndef YYERROR_CALL +#define YYERROR_CALL(msg) yyerror(msg) +#endif + +extern int YYPARSE_DECL(); + +#define YYERRCODE 256 +static const short error_lhs[] = { -1, + 0, +}; +static const short error_len[] = { 2, + 1, +}; +static const short error_defred[] = { 0, + 1, 0, +}; +static const short error_dgoto[] = { 2, +}; +static const short error_sindex[] = { -256, + 0, 0, +}; +static const short error_rindex[] = { 0, + 0, 0, +}; +static const short error_gindex[] = { 0, +}; +#define YYTABLESIZE 0 +static const short error_table[] = { 1, +}; +static const short error_check[] = { 256, +}; +#define YYFINAL 2 +#ifndef YYDEBUG +#define YYDEBUG 0 +#endif +#define YYMAXTOKEN 0 +#if YYDEBUG +static const char *yyname[] = { + +"end-of-file", +}; +static const char *yyrule[] = { +"$accept : S", +"S : error", + +}; +#endif + +int yydebug; +int yynerrs; + +/* define the initial stack-sizes */ +#ifdef YYSTACKSIZE +#undef YYMAXDEPTH +#define YYMAXDEPTH YYSTACKSIZE +#else +#ifdef YYMAXDEPTH +#define YYSTACKSIZE YYMAXDEPTH +#else +#define YYSTACKSIZE 500 +#define YYMAXDEPTH 500 +#endif +#endif + +#define YYINITSTACKSIZE 500 + +typedef struct { + unsigned stacksize; + short *s_base; + short *s_mark; + short *s_last; + YYSTYPE *l_base; + YYSTYPE *l_mark; +} YYSTACKDATA; +#line 17 "pure_error.y" + +#include <stdio.h> + +#ifdef YYBYACC +extern int YYLEX_DECL(); +#endif + +int +main(void) +{ + printf("yyparse() = %d\n", yyparse()); + return 0; +} + +int +yylex(YYSTYPE *value) +{ + return value ? 0 : -1; +} + +static void +yyerror(const char* s) +{ + printf("%s\n", s); +} +#line 245 "pure_error.tab.c" + +#if YYDEBUG +#include <stdio.h> /* needed for printf */ +#endif + +#include <stdlib.h> /* needed for malloc, etc */ +#include <string.h> /* needed for memset */ + +/* allocate initial stack or double stack size, up to YYMAXDEPTH */ +static int yygrowstack(YYSTACKDATA *data) +{ + int i; + unsigned newsize; + short *newss; + YYSTYPE *newvs; + + if ((newsize = data->stacksize) == 0) + newsize = YYINITSTACKSIZE; + else if (newsize >= YYMAXDEPTH) + return -1; + else if ((newsize *= 2) > YYMAXDEPTH) + newsize = YYMAXDEPTH; + + i = data->s_mark - data->s_base; + newss = (short *)realloc(data->s_base, newsize * sizeof(*newss)); + if (newss == 0) + return -1; + + data->s_base = newss; + data->s_mark = newss + i; + + newvs = (YYSTYPE *)realloc(data->l_base, newsize * sizeof(*newvs)); + if (newvs == 0) + return -1; + + data->l_base = newvs; + data->l_mark = newvs + i; + + data->stacksize = newsize; + data->s_last = data->s_base + newsize - 1; + return 0; +} + +#if YYPURE || defined(YY_NO_LEAKS) +static void yyfreestack(YYSTACKDATA *data) +{ + free(data->s_base); + free(data->l_base); + memset(data, 0, sizeof(*data)); +} +#else +#define yyfreestack(data) /* nothing */ +#endif + +#define YYABORT goto yyabort +#define YYREJECT goto yyabort +#define YYACCEPT goto yyaccept +#define YYERROR goto yyerrlab + +int +YYPARSE_DECL() +{ + int yyerrflag; + int yychar; + YYSTYPE yyval; + YYSTYPE yylval; + + /* variables for the parser stack */ + YYSTACKDATA yystack; + int yym, yyn, yystate; +#if YYDEBUG + const char *yys; + + if ((yys = getenv("YYDEBUG")) != 0) + { + yyn = *yys; + if (yyn >= '0' && yyn <= '9') + yydebug = yyn - '0'; + } +#endif + + yynerrs = 0; + yyerrflag = 0; + yychar = YYEMPTY; + yystate = 0; + +#if YYPURE + memset(&yystack, 0, sizeof(yystack)); +#endif + + if (yystack.s_base == NULL && yygrowstack(&yystack)) goto yyoverflow; + yystack.s_mark = yystack.s_base; + yystack.l_mark = yystack.l_base; + yystate = 0; + *yystack.s_mark = 0; + +yyloop: + if ((yyn = yydefred[yystate]) != 0) goto yyreduce; + if (yychar < 0) + { + if ((yychar = YYLEX) < 0) yychar = 0; +#if YYDEBUG + if (yydebug) + { + yys = 0; + if (yychar <= YYMAXTOKEN) yys = yyname[yychar]; + if (!yys) yys = "illegal-symbol"; + printf("%sdebug: state %d, reading %d (%s)\n", + YYPREFIX, yystate, yychar, yys); + } +#endif + } + if ((yyn = yysindex[yystate]) && (yyn += yychar) >= 0 && + yyn <= YYTABLESIZE && yycheck[yyn] == yychar) + { +#if YYDEBUG + if (yydebug) + printf("%sdebug: state %d, shifting to state %d\n", + YYPREFIX, yystate, yytable[yyn]); +#endif + if (yystack.s_mark >= yystack.s_last && yygrowstack(&yystack)) + { + goto yyoverflow; + } + yystate = yytable[yyn]; + *++yystack.s_mark = yytable[yyn]; + *++yystack.l_mark = yylval; + yychar = YYEMPTY; + if (yyerrflag > 0) --yyerrflag; + goto yyloop; + } + if ((yyn = yyrindex[yystate]) && (yyn += yychar) >= 0 && + yyn <= YYTABLESIZE && yycheck[yyn] == yychar) + { + yyn = yytable[yyn]; + goto yyreduce; + } + if (yyerrflag) goto yyinrecovery; + + yyerror("syntax error"); + + goto yyerrlab; + +yyerrlab: + ++yynerrs; + +yyinrecovery: + if (yyerrflag < 3) + { + yyerrflag = 3; + for (;;) + { + if ((yyn = yysindex[*yystack.s_mark]) && (yyn += YYERRCODE) >= 0 && + yyn <= YYTABLESIZE && yycheck[yyn] == YYERRCODE) + { +#if YYDEBUG + if (yydebug) + printf("%sdebug: state %d, error recovery shifting\ + to state %d\n", YYPREFIX, *yystack.s_mark, yytable[yyn]); +#endif + if (yystack.s_mark >= yystack.s_last && yygrowstack(&yystack)) + { + goto yyoverflow; + } + yystate = yytable[yyn]; + *++yystack.s_mark = yytable[yyn]; + *++yystack.l_mark = yylval; + goto yyloop; + } + else + { +#if YYDEBUG + if (yydebug) + printf("%sdebug: error recovery discarding state %d\n", + YYPREFIX, *yystack.s_mark); +#endif + if (yystack.s_mark <= yystack.s_base) goto yyabort; + --yystack.s_mark; + --yystack.l_mark; + } + } + } + else + { + if (yychar == 0) goto yyabort; +#if YYDEBUG + if (yydebug) + { + yys = 0; + if (yychar <= YYMAXTOKEN) yys = yyname[yychar]; + if (!yys) yys = "illegal-symbol"; + printf("%sdebug: state %d, error recovery discards token %d (%s)\n", + YYPREFIX, yystate, yychar, yys); + } +#endif + yychar = YYEMPTY; + goto yyloop; + } + +yyreduce: +#if YYDEBUG + if (yydebug) + printf("%sdebug: state %d, reducing by rule %d (%s)\n", + YYPREFIX, yystate, yyn, yyrule[yyn]); +#endif + yym = yylen[yyn]; + if (yym) + yyval = yystack.l_mark[1-yym]; + else + memset(&yyval, 0, sizeof yyval); + switch (yyn) + { + } + yystack.s_mark -= yym; + yystate = *yystack.s_mark; + yystack.l_mark -= yym; + yym = yylhs[yyn]; + if (yystate == 0 && yym == 0) + { +#if YYDEBUG + if (yydebug) + printf("%sdebug: after reduction, shifting from state 0 to\ + state %d\n", YYPREFIX, YYFINAL); +#endif + yystate = YYFINAL; + *++yystack.s_mark = YYFINAL; + *++yystack.l_mark = yyval; + if (yychar < 0) + { + if ((yychar = YYLEX) < 0) yychar = 0; +#if YYDEBUG + if (yydebug) + { + yys = 0; + if (yychar <= YYMAXTOKEN) yys = yyname[yychar]; + if (!yys) yys = "illegal-symbol"; + printf("%sdebug: state %d, reading %d (%s)\n", + YYPREFIX, YYFINAL, yychar, yys); + } +#endif + } + if (yychar == 0) goto yyaccept; + goto yyloop; + } + if ((yyn = yygindex[yym]) && (yyn += yystate) >= 0 && + yyn <= YYTABLESIZE && yycheck[yyn] == yystate) + yystate = yytable[yyn]; + else + yystate = yydgoto[yym]; +#if YYDEBUG + if (yydebug) + printf("%sdebug: after reduction, shifting from state %d \ +to state %d\n", YYPREFIX, *yystack.s_mark, yystate); +#endif + if (yystack.s_mark >= yystack.s_last && yygrowstack(&yystack)) + { + goto yyoverflow; + } + *++yystack.s_mark = (short) yystate; + *++yystack.l_mark = yyval; + goto yyloop; + +yyoverflow: + yyerror("yacc stack overflow"); + +yyabort: + yyfreestack(&yystack); + return (1); + +yyaccept: + yyfreestack(&yystack); + return (0); +} diff --git a/test/pure_error.tab.h b/test/pure_error.tab.h new file mode 100644 index 000000000000..e69de29bb2d1 --- /dev/null +++ b/test/pure_error.tab.h diff --git a/test/pure_error.y b/test/pure_error.y new file mode 100644 index 000000000000..fe7a3c3094f2 --- /dev/null +++ b/test/pure_error.y @@ -0,0 +1,41 @@ +%{ + +#ifdef YYBISON +#define YYSTYPE int +#define YYLEX_PARAM &yylval +#define YYLEX_DECL() yylex(YYSTYPE *yylval) +#define YYERROR_DECL() yyerror(const char *s) +int YYLEX_DECL(); +static void YYERROR_DECL(); +#endif + +%} + +%% +S: error +%% + +#include <stdio.h> + +#ifdef YYBYACC +extern int YYLEX_DECL(); +#endif + +int +main(void) +{ + printf("yyparse() = %d\n", yyparse()); + return 0; +} + +int +yylex(YYSTYPE *value) +{ + return value ? 0 : -1; +} + +static void +yyerror(const char* s) +{ + printf("%s\n", s); +} diff --git a/test/quote_calc-s.output b/test/quote_calc-s.output new file mode 100644 index 000000000000..0306652bfaa1 --- /dev/null +++ b/test/quote_calc-s.output @@ -0,0 +1,557 @@ + 0 $accept : list $end + + 1 list : + 2 | list stat '\n' + 3 | list error '\n' + + 4 stat : expr + 5 | LETTER '=' expr + + 6 expr : '(' expr ')' + 7 | expr OP_ADD expr + 8 | expr OP_SUB expr + 9 | expr OP_MUL expr + 10 | expr OP_DIV expr + 11 | expr OP_MOD expr + 12 | expr OP_AND expr + 13 | expr '|' expr + 14 | OP_SUB expr + 15 | LETTER + 16 | number + + 17 number : DIGIT + 18 | number DIGIT + +state 0 + $accept : . list $end (0) + list : . (1) + + . reduce 1 + + list goto 1 + + +state 1 + $accept : list . $end (0) + list : list . stat '\n' (2) + list : list . error '\n' (3) + + $end accept + error shift 2 + OP_SUB shift 3 + DIGIT shift 4 + LETTER shift 5 + '(' shift 6 + . error + + stat goto 7 + expr goto 8 + number goto 9 + + +state 2 + list : list error . '\n' (3) + + '\n' shift 10 + . error + + +state 3 + expr : OP_SUB . expr (14) + + OP_SUB shift 3 + DIGIT shift 4 + LETTER shift 11 + '(' shift 6 + . error + + expr goto 12 + number goto 9 + + +state 4 + number : DIGIT . (17) + + . reduce 17 + + +state 5 + stat : LETTER . '=' expr (5) + expr : LETTER . (15) + + '=' shift 13 + OP_ADD reduce 15 + OP_SUB reduce 15 + OP_MUL reduce 15 + OP_DIV reduce 15 + OP_MOD reduce 15 + OP_AND reduce 15 + '|' reduce 15 + '\n' reduce 15 + + +state 6 + expr : '(' . expr ')' (6) + + OP_SUB shift 3 + DIGIT shift 4 + LETTER shift 11 + '(' shift 6 + . error + + expr goto 14 + number goto 9 + + +state 7 + list : list stat . '\n' (2) + + '\n' shift 15 + . error + + +state 8 + stat : expr . (4) + expr : expr . OP_ADD expr (7) + expr : expr . OP_SUB expr (8) + expr : expr . OP_MUL expr (9) + expr : expr . OP_DIV expr (10) + expr : expr . OP_MOD expr (11) + expr : expr . OP_AND expr (12) + expr : expr . '|' expr (13) + + OP_ADD shift 16 + OP_SUB shift 17 + OP_MUL shift 18 + OP_DIV shift 19 + OP_MOD shift 20 + OP_AND shift 21 + '|' shift 22 + '\n' reduce 4 + + +state 9 + expr : number . (16) + number : number . DIGIT (18) + + DIGIT shift 23 + OP_ADD reduce 16 + OP_SUB reduce 16 + OP_MUL reduce 16 + OP_DIV reduce 16 + OP_MOD reduce 16 + OP_AND reduce 16 + '|' reduce 16 + '\n' reduce 16 + ')' reduce 16 + + +state 10 + list : list error '\n' . (3) + + . reduce 3 + + +state 11 + expr : LETTER . (15) + + . reduce 15 + + +12: shift/reduce conflict (shift 16, reduce 14) on OP_ADD +12: shift/reduce conflict (shift 17, reduce 14) on OP_SUB +12: shift/reduce conflict (shift 18, reduce 14) on OP_MUL +12: shift/reduce conflict (shift 19, reduce 14) on OP_DIV +12: shift/reduce conflict (shift 20, reduce 14) on OP_MOD +12: shift/reduce conflict (shift 21, reduce 14) on OP_AND +state 12 + expr : expr . OP_ADD expr (7) + expr : expr . OP_SUB expr (8) + expr : expr . OP_MUL expr (9) + expr : expr . OP_DIV expr (10) + expr : expr . OP_MOD expr (11) + expr : expr . OP_AND expr (12) + expr : expr . '|' expr (13) + expr : OP_SUB expr . (14) + + OP_ADD shift 16 + OP_SUB shift 17 + OP_MUL shift 18 + OP_DIV shift 19 + OP_MOD shift 20 + OP_AND shift 21 + '|' reduce 14 + '\n' reduce 14 + ')' reduce 14 + + +state 13 + stat : LETTER '=' . expr (5) + + OP_SUB shift 3 + DIGIT shift 4 + LETTER shift 11 + '(' shift 6 + . error + + expr goto 24 + number goto 9 + + +state 14 + expr : '(' expr . ')' (6) + expr : expr . OP_ADD expr (7) + expr : expr . OP_SUB expr (8) + expr : expr . OP_MUL expr (9) + expr : expr . OP_DIV expr (10) + expr : expr . OP_MOD expr (11) + expr : expr . OP_AND expr (12) + expr : expr . '|' expr (13) + + OP_ADD shift 16 + OP_SUB shift 17 + OP_MUL shift 18 + OP_DIV shift 19 + OP_MOD shift 20 + OP_AND shift 21 + '|' shift 22 + ')' shift 25 + . error + + +state 15 + list : list stat '\n' . (2) + + . reduce 2 + + +state 16 + expr : expr OP_ADD . expr (7) + + OP_SUB shift 3 + DIGIT shift 4 + LETTER shift 11 + '(' shift 6 + . error + + expr goto 26 + number goto 9 + + +state 17 + expr : expr OP_SUB . expr (8) + + OP_SUB shift 3 + DIGIT shift 4 + LETTER shift 11 + '(' shift 6 + . error + + expr goto 27 + number goto 9 + + +state 18 + expr : expr OP_MUL . expr (9) + + OP_SUB shift 3 + DIGIT shift 4 + LETTER shift 11 + '(' shift 6 + . error + + expr goto 28 + number goto 9 + + +state 19 + expr : expr OP_DIV . expr (10) + + OP_SUB shift 3 + DIGIT shift 4 + LETTER shift 11 + '(' shift 6 + . error + + expr goto 29 + number goto 9 + + +state 20 + expr : expr OP_MOD . expr (11) + + OP_SUB shift 3 + DIGIT shift 4 + LETTER shift 11 + '(' shift 6 + . error + + expr goto 30 + number goto 9 + + +state 21 + expr : expr OP_AND . expr (12) + + OP_SUB shift 3 + DIGIT shift 4 + LETTER shift 11 + '(' shift 6 + . error + + expr goto 31 + number goto 9 + + +state 22 + expr : expr '|' . expr (13) + + OP_SUB shift 3 + DIGIT shift 4 + LETTER shift 11 + '(' shift 6 + . error + + expr goto 32 + number goto 9 + + +state 23 + number : number DIGIT . (18) + + . reduce 18 + + +state 24 + stat : LETTER '=' expr . (5) + expr : expr . OP_ADD expr (7) + expr : expr . OP_SUB expr (8) + expr : expr . OP_MUL expr (9) + expr : expr . OP_DIV expr (10) + expr : expr . OP_MOD expr (11) + expr : expr . OP_AND expr (12) + expr : expr . '|' expr (13) + + OP_ADD shift 16 + OP_SUB shift 17 + OP_MUL shift 18 + OP_DIV shift 19 + OP_MOD shift 20 + OP_AND shift 21 + '|' shift 22 + '\n' reduce 5 + + +state 25 + expr : '(' expr ')' . (6) + + . reduce 6 + + +26: shift/reduce conflict (shift 16, reduce 7) on OP_ADD +26: shift/reduce conflict (shift 17, reduce 7) on OP_SUB +26: shift/reduce conflict (shift 18, reduce 7) on OP_MUL +26: shift/reduce conflict (shift 19, reduce 7) on OP_DIV +26: shift/reduce conflict (shift 20, reduce 7) on OP_MOD +26: shift/reduce conflict (shift 21, reduce 7) on OP_AND +26: shift/reduce conflict (shift 22, reduce 7) on '|' +state 26 + expr : expr . OP_ADD expr (7) + expr : expr OP_ADD expr . (7) + expr : expr . OP_SUB expr (8) + expr : expr . OP_MUL expr (9) + expr : expr . OP_DIV expr (10) + expr : expr . OP_MOD expr (11) + expr : expr . OP_AND expr (12) + expr : expr . '|' expr (13) + + OP_ADD shift 16 + OP_SUB shift 17 + OP_MUL shift 18 + OP_DIV shift 19 + OP_MOD shift 20 + OP_AND shift 21 + '|' shift 22 + '\n' reduce 7 + ')' reduce 7 + + +27: shift/reduce conflict (shift 16, reduce 8) on OP_ADD +27: shift/reduce conflict (shift 17, reduce 8) on OP_SUB +27: shift/reduce conflict (shift 18, reduce 8) on OP_MUL +27: shift/reduce conflict (shift 19, reduce 8) on OP_DIV +27: shift/reduce conflict (shift 20, reduce 8) on OP_MOD +27: shift/reduce conflict (shift 21, reduce 8) on OP_AND +27: shift/reduce conflict (shift 22, reduce 8) on '|' +state 27 + expr : expr . OP_ADD expr (7) + expr : expr . OP_SUB expr (8) + expr : expr OP_SUB expr . (8) + expr : expr . OP_MUL expr (9) + expr : expr . OP_DIV expr (10) + expr : expr . OP_MOD expr (11) + expr : expr . OP_AND expr (12) + expr : expr . '|' expr (13) + + OP_ADD shift 16 + OP_SUB shift 17 + OP_MUL shift 18 + OP_DIV shift 19 + OP_MOD shift 20 + OP_AND shift 21 + '|' shift 22 + '\n' reduce 8 + ')' reduce 8 + + +28: shift/reduce conflict (shift 16, reduce 9) on OP_ADD +28: shift/reduce conflict (shift 17, reduce 9) on OP_SUB +28: shift/reduce conflict (shift 18, reduce 9) on OP_MUL +28: shift/reduce conflict (shift 19, reduce 9) on OP_DIV +28: shift/reduce conflict (shift 20, reduce 9) on OP_MOD +28: shift/reduce conflict (shift 21, reduce 9) on OP_AND +28: shift/reduce conflict (shift 22, reduce 9) on '|' +state 28 + expr : expr . OP_ADD expr (7) + expr : expr . OP_SUB expr (8) + expr : expr . OP_MUL expr (9) + expr : expr OP_MUL expr . (9) + expr : expr . OP_DIV expr (10) + expr : expr . OP_MOD expr (11) + expr : expr . OP_AND expr (12) + expr : expr . '|' expr (13) + + OP_ADD shift 16 + OP_SUB shift 17 + OP_MUL shift 18 + OP_DIV shift 19 + OP_MOD shift 20 + OP_AND shift 21 + '|' shift 22 + '\n' reduce 9 + ')' reduce 9 + + +29: shift/reduce conflict (shift 16, reduce 10) on OP_ADD +29: shift/reduce conflict (shift 17, reduce 10) on OP_SUB +29: shift/reduce conflict (shift 18, reduce 10) on OP_MUL +29: shift/reduce conflict (shift 19, reduce 10) on OP_DIV +29: shift/reduce conflict (shift 20, reduce 10) on OP_MOD +29: shift/reduce conflict (shift 21, reduce 10) on OP_AND +29: shift/reduce conflict (shift 22, reduce 10) on '|' +state 29 + expr : expr . OP_ADD expr (7) + expr : expr . OP_SUB expr (8) + expr : expr . OP_MUL expr (9) + expr : expr . OP_DIV expr (10) + expr : expr OP_DIV expr . (10) + expr : expr . OP_MOD expr (11) + expr : expr . OP_AND expr (12) + expr : expr . '|' expr (13) + + OP_ADD shift 16 + OP_SUB shift 17 + OP_MUL shift 18 + OP_DIV shift 19 + OP_MOD shift 20 + OP_AND shift 21 + '|' shift 22 + '\n' reduce 10 + ')' reduce 10 + + +30: shift/reduce conflict (shift 16, reduce 11) on OP_ADD +30: shift/reduce conflict (shift 17, reduce 11) on OP_SUB +30: shift/reduce conflict (shift 18, reduce 11) on OP_MUL +30: shift/reduce conflict (shift 19, reduce 11) on OP_DIV +30: shift/reduce conflict (shift 20, reduce 11) on OP_MOD +30: shift/reduce conflict (shift 21, reduce 11) on OP_AND +30: shift/reduce conflict (shift 22, reduce 11) on '|' +state 30 + expr : expr . OP_ADD expr (7) + expr : expr . OP_SUB expr (8) + expr : expr . OP_MUL expr (9) + expr : expr . OP_DIV expr (10) + expr : expr . OP_MOD expr (11) + expr : expr OP_MOD expr . (11) + expr : expr . OP_AND expr (12) + expr : expr . '|' expr (13) + + OP_ADD shift 16 + OP_SUB shift 17 + OP_MUL shift 18 + OP_DIV shift 19 + OP_MOD shift 20 + OP_AND shift 21 + '|' shift 22 + '\n' reduce 11 + ')' reduce 11 + + +31: shift/reduce conflict (shift 16, reduce 12) on OP_ADD +31: shift/reduce conflict (shift 17, reduce 12) on OP_SUB +31: shift/reduce conflict (shift 18, reduce 12) on OP_MUL +31: shift/reduce conflict (shift 19, reduce 12) on OP_DIV +31: shift/reduce conflict (shift 20, reduce 12) on OP_MOD +31: shift/reduce conflict (shift 21, reduce 12) on OP_AND +31: shift/reduce conflict (shift 22, reduce 12) on '|' +state 31 + expr : expr . OP_ADD expr (7) + expr : expr . OP_SUB expr (8) + expr : expr . OP_MUL expr (9) + expr : expr . OP_DIV expr (10) + expr : expr . OP_MOD expr (11) + expr : expr . OP_AND expr (12) + expr : expr OP_AND expr . (12) + expr : expr . '|' expr (13) + + OP_ADD shift 16 + OP_SUB shift 17 + OP_MUL shift 18 + OP_DIV shift 19 + OP_MOD shift 20 + OP_AND shift 21 + '|' shift 22 + '\n' reduce 12 + ')' reduce 12 + + +32: shift/reduce conflict (shift 16, reduce 13) on OP_ADD +32: shift/reduce conflict (shift 17, reduce 13) on OP_SUB +32: shift/reduce conflict (shift 18, reduce 13) on OP_MUL +32: shift/reduce conflict (shift 19, reduce 13) on OP_DIV +32: shift/reduce conflict (shift 20, reduce 13) on OP_MOD +32: shift/reduce conflict (shift 21, reduce 13) on OP_AND +state 32 + expr : expr . OP_ADD expr (7) + expr : expr . OP_SUB expr (8) + expr : expr . OP_MUL expr (9) + expr : expr . OP_DIV expr (10) + expr : expr . OP_MOD expr (11) + expr : expr . OP_AND expr (12) + expr : expr . '|' expr (13) + expr : expr '|' expr . (13) + + OP_ADD shift 16 + OP_SUB shift 17 + OP_MUL shift 18 + OP_DIV shift 19 + OP_MOD shift 20 + OP_AND shift 21 + '|' reduce 13 + '\n' reduce 13 + ')' reduce 13 + + +State 12 contains 6 shift/reduce conflicts. +State 26 contains 7 shift/reduce conflicts. +State 27 contains 7 shift/reduce conflicts. +State 28 contains 7 shift/reduce conflicts. +State 29 contains 7 shift/reduce conflicts. +State 30 contains 7 shift/reduce conflicts. +State 31 contains 7 shift/reduce conflicts. +State 32 contains 6 shift/reduce conflicts. + + +28 terminals, 5 nonterminals +19 grammar rules, 33 states diff --git a/test/quote_calc-s.tab.c b/test/quote_calc-s.tab.c new file mode 100644 index 000000000000..15346fdcfafa --- /dev/null +++ b/test/quote_calc-s.tab.c @@ -0,0 +1,687 @@ +#ifndef lint +static const char yysccsid[] = "@(#)yaccpar 1.9 (Berkeley) 02/21/93"; +#endif + +#define YYBYACC 1 +#define YYMAJOR 1 +#define YYMINOR 9 + +#define YYEMPTY (-1) +#define yyclearin (yychar = YYEMPTY) +#define yyerrok (yyerrflag = 0) +#define YYRECOVERING() (yyerrflag != 0) + + +#ifndef yyparse +#define yyparse quote_calc_parse +#endif /* yyparse */ + +#ifndef yylex +#define yylex quote_calc_lex +#endif /* yylex */ + +#ifndef yyerror +#define yyerror quote_calc_error +#endif /* yyerror */ + +#ifndef yychar +#define yychar quote_calc_char +#endif /* yychar */ + +#ifndef yyval +#define yyval quote_calc_val +#endif /* yyval */ + +#ifndef yylval +#define yylval quote_calc_lval +#endif /* yylval */ + +#ifndef yydebug +#define yydebug quote_calc_debug +#endif /* yydebug */ + +#ifndef yynerrs +#define yynerrs quote_calc_nerrs +#endif /* yynerrs */ + +#ifndef yyerrflag +#define yyerrflag quote_calc_errflag +#endif /* yyerrflag */ + +#ifndef yylhs +#define yylhs quote_calc_lhs +#endif /* yylhs */ + +#ifndef yylen +#define yylen quote_calc_len +#endif /* yylen */ + +#ifndef yydefred +#define yydefred quote_calc_defred +#endif /* yydefred */ + +#ifndef yydgoto +#define yydgoto quote_calc_dgoto +#endif /* yydgoto */ + +#ifndef yysindex +#define yysindex quote_calc_sindex +#endif /* yysindex */ + +#ifndef yyrindex +#define yyrindex quote_calc_rindex +#endif /* yyrindex */ + +#ifndef yygindex +#define yygindex quote_calc_gindex +#endif /* yygindex */ + +#ifndef yytable +#define yytable quote_calc_table +#endif /* yytable */ + +#ifndef yycheck +#define yycheck quote_calc_check +#endif /* yycheck */ + +#ifndef yyname +#define yyname quote_calc_name +#endif /* yyname */ + +#ifndef yyrule +#define yyrule quote_calc_rule +#endif /* yyrule */ +#define YYPREFIX "quote_calc_" + +#define YYPURE 0 + +#line 2 "quote_calc.y" +# include <stdio.h> +# include <ctype.h> + +int regs[26]; +int base; + +int yylex(void); +static void yyerror(const char *s); + +#line 109 "quote_calc-s.tab.c" + +#ifndef YYSTYPE +typedef int YYSTYPE; +#endif + +/* compatibility with bison */ +#ifdef YYPARSE_PARAM +/* compatibility with FreeBSD */ +# ifdef YYPARSE_PARAM_TYPE +# define YYPARSE_DECL() yyparse(YYPARSE_PARAM_TYPE YYPARSE_PARAM) +# else +# define YYPARSE_DECL() yyparse(void *YYPARSE_PARAM) +# endif +#else +# define YYPARSE_DECL() yyparse(void) +#endif + +/* Parameters sent to lex. */ +#ifdef YYLEX_PARAM +# define YYLEX_DECL() yylex(void *YYLEX_PARAM) +# define YYLEX yylex(YYLEX_PARAM) +#else +# define YYLEX_DECL() yylex(void) +# define YYLEX yylex() +#endif + +/* Parameters sent to yyerror. */ +#ifndef YYERROR_DECL +#define YYERROR_DECL() yyerror(const char *s) +#endif +#ifndef YYERROR_CALL +#define YYERROR_CALL(msg) yyerror(msg) +#endif + +extern int YYPARSE_DECL(); + +#define OP_ADD 257 +#define OP_SUB 259 +#define OP_MUL 261 +#define OP_DIV 263 +#define OP_MOD 265 +#define OP_AND 267 +#define DIGIT 269 +#define LETTER 270 +#define UMINUS 271 +#define YYERRCODE 256 +static const short quote_calc_lhs[] = { -1, + 0, 0, 0, 1, 1, 2, 2, 2, 2, 2, + 2, 2, 2, 2, 2, 2, 3, 3, +}; +static const short quote_calc_len[] = { 2, + 0, 3, 3, 1, 3, 3, 3, 3, 3, 3, + 3, 3, 3, 2, 1, 1, 1, 2, +}; +static const short quote_calc_defred[] = { 1, + 0, 0, 0, 17, 0, 0, 0, 0, 0, 3, + 15, 0, 0, 0, 2, 0, 0, 0, 0, 0, + 0, 0, 18, 0, 6, 0, 0, 0, 0, 0, + 0, 0, +}; +static const short quote_calc_dgoto[] = { 1, + 7, 8, 9, +}; +static const short quote_calc_sindex[] = { 0, + -38, 5, -36, 0, -51, -36, 7, -121, -248, 0, + 0, -243, -36, -22, 0, -36, -36, -36, -36, -36, + -36, -36, 0, -121, 0, -121, -121, -121, -121, -121, + -121, -243, +}; +static const short quote_calc_rindex[] = { 0, + 0, 0, 0, 0, -9, 0, 0, 13, -10, 0, + 0, -5, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 15, 0, -3, -2, -1, 1, 2, + 3, -4, +}; +static const short quote_calc_gindex[] = { 0, + 0, 42, 0, +}; +#define YYTABLESIZE 258 +static const short quote_calc_table[] = { 16, + 15, 6, 22, 6, 14, 13, 7, 8, 9, 13, + 10, 11, 12, 16, 10, 17, 15, 18, 25, 19, + 23, 20, 4, 21, 5, 0, 0, 0, 0, 0, + 16, 0, 0, 0, 0, 14, 13, 7, 8, 9, + 0, 10, 11, 12, 12, 0, 0, 14, 0, 0, + 0, 0, 0, 0, 24, 0, 0, 26, 27, 28, + 29, 30, 31, 32, 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, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 22, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 16, 15, 0, 0, 0, 14, 13, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 16, 0, 17, 0, 18, + 0, 19, 0, 20, 0, 21, 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, 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, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 2, 0, 0, + 3, 0, 3, 0, 0, 0, 0, 0, 0, 0, + 4, 5, 4, 11, 16, 0, 17, 0, 18, 0, + 19, 0, 20, 0, 21, 0, 16, 15, 16, 15, + 16, 15, 16, 15, 16, 15, 16, 15, +}; +static const short quote_calc_check[] = { 10, + 10, 40, 124, 40, 10, 10, 10, 10, 10, 61, + 10, 10, 10, 257, 10, 259, 10, 261, 41, 263, + 269, 265, 10, 267, 10, -1, -1, -1, -1, -1, + 41, -1, -1, -1, -1, 41, 41, 41, 41, 41, + -1, 41, 41, 41, 3, -1, -1, 6, -1, -1, + -1, -1, -1, -1, 13, -1, -1, 16, 17, 18, + 19, 20, 21, 22, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, + -1, 124, -1, -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, 124, 124, -1, -1, -1, 124, 124, + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, 257, -1, 259, -1, 261, + -1, 263, -1, 265, -1, 267, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, 256, -1, -1, + 259, -1, 259, -1, -1, -1, -1, -1, -1, -1, + 269, 270, 269, 270, 257, -1, 259, -1, 261, -1, + 263, -1, 265, -1, 267, -1, 257, 257, 259, 259, + 261, 261, 263, 263, 265, 265, 267, 267, +}; +#define YYFINAL 1 +#ifndef YYDEBUG +#define YYDEBUG 0 +#endif +#define YYMAXTOKEN 271 +#if YYDEBUG +static const char *yyname[] = { + +"end-of-file",0,0,0,0,0,0,0,0,0,"'\\n'",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,"'-'",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,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,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,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,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,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,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,0,0,0,0,0,0, +0,0,0,0,0,0,"OP_ADD","\"ADD\"","OP_SUB","\"SUB\"","OP_MUL","\"MUL\"","OP_DIV", +"\"DIV\"","OP_MOD","\"MOD\"","OP_AND","\"AND\"","DIGIT","LETTER","UMINUS", +}; +static const char *yyrule[] = { +"$accept : list", +"list :", +"list : list stat '\\n'", +"list : list error '\\n'", +"stat : expr", +"stat : LETTER '=' expr", +"expr : '(' expr ')'", +"expr : expr OP_ADD expr", +"expr : expr OP_SUB expr", +"expr : expr OP_MUL expr", +"expr : expr OP_DIV expr", +"expr : expr OP_MOD expr", +"expr : expr OP_AND expr", +"expr : expr '|' expr", +"expr : OP_SUB expr", +"expr : LETTER", +"expr : number", +"number : DIGIT", +"number : number DIGIT", + +}; +#endif + +int yydebug; +int yynerrs; + +int yyerrflag; +int yychar; +YYSTYPE yyval; +YYSTYPE yylval; + +/* define the initial stack-sizes */ +#ifdef YYSTACKSIZE +#undef YYMAXDEPTH +#define YYMAXDEPTH YYSTACKSIZE +#else +#ifdef YYMAXDEPTH +#define YYSTACKSIZE YYMAXDEPTH +#else +#define YYSTACKSIZE 500 +#define YYMAXDEPTH 500 +#endif +#endif + +#define YYINITSTACKSIZE 500 + +typedef struct { + unsigned stacksize; + short *s_base; + short *s_mark; + short *s_last; + YYSTYPE *l_base; + YYSTYPE *l_mark; +} YYSTACKDATA; +/* variables for the parser stack */ +static YYSTACKDATA yystack; +#line 73 "quote_calc.y" + /* start of programs */ + +int +main (void) +{ + while(!feof(stdin)) { + yyparse(); + } + return 0; +} + +static void +yyerror(const char *s) +{ + fprintf(stderr, "%s\n", s); +} + +int +yylex(void) { + /* lexical analysis routine */ + /* returns LETTER for a lower case letter, yylval = 0 through 25 */ + /* return DIGIT for a digit, yylval = 0 through 9 */ + /* all other characters are returned immediately */ + + int c; + + while( (c=getchar()) == ' ' ) { /* skip blanks */ } + + /* c is now nonblank */ + + if( islower( c )) { + yylval = c - 'a'; + return ( LETTER ); + } + if( isdigit( c )) { + yylval = c - '0'; + return ( DIGIT ); + } + return( c ); +} +#line 361 "quote_calc-s.tab.c" + +#if YYDEBUG +#include <stdio.h> /* needed for printf */ +#endif + +#include <stdlib.h> /* needed for malloc, etc */ +#include <string.h> /* needed for memset */ + +/* allocate initial stack or double stack size, up to YYMAXDEPTH */ +static int yygrowstack(YYSTACKDATA *data) +{ + int i; + unsigned newsize; + short *newss; + YYSTYPE *newvs; + + if ((newsize = data->stacksize) == 0) + newsize = YYINITSTACKSIZE; + else if (newsize >= YYMAXDEPTH) + return -1; + else if ((newsize *= 2) > YYMAXDEPTH) + newsize = YYMAXDEPTH; + + i = data->s_mark - data->s_base; + newss = (short *)realloc(data->s_base, newsize * sizeof(*newss)); + if (newss == 0) + return -1; + + data->s_base = newss; + data->s_mark = newss + i; + + newvs = (YYSTYPE *)realloc(data->l_base, newsize * sizeof(*newvs)); + if (newvs == 0) + return -1; + + data->l_base = newvs; + data->l_mark = newvs + i; + + data->stacksize = newsize; + data->s_last = data->s_base + newsize - 1; + return 0; +} + +#if YYPURE || defined(YY_NO_LEAKS) +static void yyfreestack(YYSTACKDATA *data) +{ + free(data->s_base); + free(data->l_base); + memset(data, 0, sizeof(*data)); +} +#else +#define yyfreestack(data) /* nothing */ +#endif + +#define YYABORT goto yyabort +#define YYREJECT goto yyabort +#define YYACCEPT goto yyaccept +#define YYERROR goto yyerrlab + +int +YYPARSE_DECL() +{ + int yym, yyn, yystate; +#if YYDEBUG + const char *yys; + + if ((yys = getenv("YYDEBUG")) != 0) + { + yyn = *yys; + if (yyn >= '0' && yyn <= '9') + yydebug = yyn - '0'; + } +#endif + + yynerrs = 0; + yyerrflag = 0; + yychar = YYEMPTY; + yystate = 0; + +#if YYPURE + memset(&yystack, 0, sizeof(yystack)); +#endif + + if (yystack.s_base == NULL && yygrowstack(&yystack)) goto yyoverflow; + yystack.s_mark = yystack.s_base; + yystack.l_mark = yystack.l_base; + yystate = 0; + *yystack.s_mark = 0; + +yyloop: + if ((yyn = yydefred[yystate]) != 0) goto yyreduce; + if (yychar < 0) + { + if ((yychar = YYLEX) < 0) yychar = 0; +#if YYDEBUG + if (yydebug) + { + yys = 0; + if (yychar <= YYMAXTOKEN) yys = yyname[yychar]; + if (!yys) yys = "illegal-symbol"; + printf("%sdebug: state %d, reading %d (%s)\n", + YYPREFIX, yystate, yychar, yys); + } +#endif + } + if ((yyn = yysindex[yystate]) && (yyn += yychar) >= 0 && + yyn <= YYTABLESIZE && yycheck[yyn] == yychar) + { +#if YYDEBUG + if (yydebug) + printf("%sdebug: state %d, shifting to state %d\n", + YYPREFIX, yystate, yytable[yyn]); +#endif + if (yystack.s_mark >= yystack.s_last && yygrowstack(&yystack)) + { + goto yyoverflow; + } + yystate = yytable[yyn]; + *++yystack.s_mark = yytable[yyn]; + *++yystack.l_mark = yylval; + yychar = YYEMPTY; + if (yyerrflag > 0) --yyerrflag; + goto yyloop; + } + if ((yyn = yyrindex[yystate]) && (yyn += yychar) >= 0 && + yyn <= YYTABLESIZE && yycheck[yyn] == yychar) + { + yyn = yytable[yyn]; + goto yyreduce; + } + if (yyerrflag) goto yyinrecovery; + + yyerror("syntax error"); + + goto yyerrlab; + +yyerrlab: + ++yynerrs; + +yyinrecovery: + if (yyerrflag < 3) + { + yyerrflag = 3; + for (;;) + { + if ((yyn = yysindex[*yystack.s_mark]) && (yyn += YYERRCODE) >= 0 && + yyn <= YYTABLESIZE && yycheck[yyn] == YYERRCODE) + { +#if YYDEBUG + if (yydebug) + printf("%sdebug: state %d, error recovery shifting\ + to state %d\n", YYPREFIX, *yystack.s_mark, yytable[yyn]); +#endif + if (yystack.s_mark >= yystack.s_last && yygrowstack(&yystack)) + { + goto yyoverflow; + } + yystate = yytable[yyn]; + *++yystack.s_mark = yytable[yyn]; + *++yystack.l_mark = yylval; + goto yyloop; + } + else + { +#if YYDEBUG + if (yydebug) + printf("%sdebug: error recovery discarding state %d\n", + YYPREFIX, *yystack.s_mark); +#endif + if (yystack.s_mark <= yystack.s_base) goto yyabort; + --yystack.s_mark; + --yystack.l_mark; + } + } + } + else + { + if (yychar == 0) goto yyabort; +#if YYDEBUG + if (yydebug) + { + yys = 0; + if (yychar <= YYMAXTOKEN) yys = yyname[yychar]; + if (!yys) yys = "illegal-symbol"; + printf("%sdebug: state %d, error recovery discards token %d (%s)\n", + YYPREFIX, yystate, yychar, yys); + } +#endif + yychar = YYEMPTY; + goto yyloop; + } + +yyreduce: +#if YYDEBUG + if (yydebug) + printf("%sdebug: state %d, reducing by rule %d (%s)\n", + YYPREFIX, yystate, yyn, yyrule[yyn]); +#endif + yym = yylen[yyn]; + if (yym) + yyval = yystack.l_mark[1-yym]; + else + memset(&yyval, 0, sizeof yyval); + switch (yyn) + { +case 3: +#line 35 "quote_calc.y" + { yyerrok ; } +break; +case 4: +#line 39 "quote_calc.y" + { printf("%d\n",yystack.l_mark[0]);} +break; +case 5: +#line 41 "quote_calc.y" + { regs[yystack.l_mark[-2]] = yystack.l_mark[0]; } +break; +case 6: +#line 45 "quote_calc.y" + { yyval = yystack.l_mark[-1]; } +break; +case 7: +#line 47 "quote_calc.y" + { yyval = yystack.l_mark[-2] + yystack.l_mark[0]; } +break; +case 8: +#line 49 "quote_calc.y" + { yyval = yystack.l_mark[-2] - yystack.l_mark[0]; } +break; +case 9: +#line 51 "quote_calc.y" + { yyval = yystack.l_mark[-2] * yystack.l_mark[0]; } +break; +case 10: +#line 53 "quote_calc.y" + { yyval = yystack.l_mark[-2] / yystack.l_mark[0]; } +break; +case 11: +#line 55 "quote_calc.y" + { yyval = yystack.l_mark[-2] % yystack.l_mark[0]; } +break; +case 12: +#line 57 "quote_calc.y" + { yyval = yystack.l_mark[-2] & yystack.l_mark[0]; } +break; +case 13: +#line 59 "quote_calc.y" + { yyval = yystack.l_mark[-2] | yystack.l_mark[0]; } +break; +case 14: +#line 61 "quote_calc.y" + { yyval = - yystack.l_mark[0]; } +break; +case 15: +#line 63 "quote_calc.y" + { yyval = regs[yystack.l_mark[0]]; } +break; +case 17: +#line 68 "quote_calc.y" + { yyval = yystack.l_mark[0]; base = (yystack.l_mark[0]==0) ? 8 : 10; } +break; +case 18: +#line 70 "quote_calc.y" + { yyval = base * yystack.l_mark[-1] + yystack.l_mark[0]; } +break; +#line 627 "quote_calc-s.tab.c" + } + yystack.s_mark -= yym; + yystate = *yystack.s_mark; + yystack.l_mark -= yym; + yym = yylhs[yyn]; + if (yystate == 0 && yym == 0) + { +#if YYDEBUG + if (yydebug) + printf("%sdebug: after reduction, shifting from state 0 to\ + state %d\n", YYPREFIX, YYFINAL); +#endif + yystate = YYFINAL; + *++yystack.s_mark = YYFINAL; + *++yystack.l_mark = yyval; + if (yychar < 0) + { + if ((yychar = YYLEX) < 0) yychar = 0; +#if YYDEBUG + if (yydebug) + { + yys = 0; + if (yychar <= YYMAXTOKEN) yys = yyname[yychar]; + if (!yys) yys = "illegal-symbol"; + printf("%sdebug: state %d, reading %d (%s)\n", + YYPREFIX, YYFINAL, yychar, yys); + } +#endif + } + if (yychar == 0) goto yyaccept; + goto yyloop; + } + if ((yyn = yygindex[yym]) && (yyn += yystate) >= 0 && + yyn <= YYTABLESIZE && yycheck[yyn] == yystate) + yystate = yytable[yyn]; + else + yystate = yydgoto[yym]; +#if YYDEBUG + if (yydebug) + printf("%sdebug: after reduction, shifting from state %d \ +to state %d\n", YYPREFIX, *yystack.s_mark, yystate); +#endif + if (yystack.s_mark >= yystack.s_last && yygrowstack(&yystack)) + { + goto yyoverflow; + } + *++yystack.s_mark = (short) yystate; + *++yystack.l_mark = yyval; + goto yyloop; + +yyoverflow: + yyerror("yacc stack overflow"); + +yyabort: + yyfreestack(&yystack); + return (1); + +yyaccept: + yyfreestack(&yystack); + return (0); +} diff --git a/test/quote_calc-s.tab.h b/test/quote_calc-s.tab.h new file mode 100644 index 000000000000..1a4657903411 --- /dev/null +++ b/test/quote_calc-s.tab.h @@ -0,0 +1,9 @@ +#define OP_ADD 257 +#define OP_SUB 259 +#define OP_MUL 261 +#define OP_DIV 263 +#define OP_MOD 265 +#define OP_AND 267 +#define DIGIT 269 +#define LETTER 270 +#define UMINUS 271 diff --git a/test/quote_calc.output b/test/quote_calc.output new file mode 100644 index 000000000000..0306652bfaa1 --- /dev/null +++ b/test/quote_calc.output @@ -0,0 +1,557 @@ + 0 $accept : list $end + + 1 list : + 2 | list stat '\n' + 3 | list error '\n' + + 4 stat : expr + 5 | LETTER '=' expr + + 6 expr : '(' expr ')' + 7 | expr OP_ADD expr + 8 | expr OP_SUB expr + 9 | expr OP_MUL expr + 10 | expr OP_DIV expr + 11 | expr OP_MOD expr + 12 | expr OP_AND expr + 13 | expr '|' expr + 14 | OP_SUB expr + 15 | LETTER + 16 | number + + 17 number : DIGIT + 18 | number DIGIT + +state 0 + $accept : . list $end (0) + list : . (1) + + . reduce 1 + + list goto 1 + + +state 1 + $accept : list . $end (0) + list : list . stat '\n' (2) + list : list . error '\n' (3) + + $end accept + error shift 2 + OP_SUB shift 3 + DIGIT shift 4 + LETTER shift 5 + '(' shift 6 + . error + + stat goto 7 + expr goto 8 + number goto 9 + + +state 2 + list : list error . '\n' (3) + + '\n' shift 10 + . error + + +state 3 + expr : OP_SUB . expr (14) + + OP_SUB shift 3 + DIGIT shift 4 + LETTER shift 11 + '(' shift 6 + . error + + expr goto 12 + number goto 9 + + +state 4 + number : DIGIT . (17) + + . reduce 17 + + +state 5 + stat : LETTER . '=' expr (5) + expr : LETTER . (15) + + '=' shift 13 + OP_ADD reduce 15 + OP_SUB reduce 15 + OP_MUL reduce 15 + OP_DIV reduce 15 + OP_MOD reduce 15 + OP_AND reduce 15 + '|' reduce 15 + '\n' reduce 15 + + +state 6 + expr : '(' . expr ')' (6) + + OP_SUB shift 3 + DIGIT shift 4 + LETTER shift 11 + '(' shift 6 + . error + + expr goto 14 + number goto 9 + + +state 7 + list : list stat . '\n' (2) + + '\n' shift 15 + . error + + +state 8 + stat : expr . (4) + expr : expr . OP_ADD expr (7) + expr : expr . OP_SUB expr (8) + expr : expr . OP_MUL expr (9) + expr : expr . OP_DIV expr (10) + expr : expr . OP_MOD expr (11) + expr : expr . OP_AND expr (12) + expr : expr . '|' expr (13) + + OP_ADD shift 16 + OP_SUB shift 17 + OP_MUL shift 18 + OP_DIV shift 19 + OP_MOD shift 20 + OP_AND shift 21 + '|' shift 22 + '\n' reduce 4 + + +state 9 + expr : number . (16) + number : number . DIGIT (18) + + DIGIT shift 23 + OP_ADD reduce 16 + OP_SUB reduce 16 + OP_MUL reduce 16 + OP_DIV reduce 16 + OP_MOD reduce 16 + OP_AND reduce 16 + '|' reduce 16 + '\n' reduce 16 + ')' reduce 16 + + +state 10 + list : list error '\n' . (3) + + . reduce 3 + + +state 11 + expr : LETTER . (15) + + . reduce 15 + + +12: shift/reduce conflict (shift 16, reduce 14) on OP_ADD +12: shift/reduce conflict (shift 17, reduce 14) on OP_SUB +12: shift/reduce conflict (shift 18, reduce 14) on OP_MUL +12: shift/reduce conflict (shift 19, reduce 14) on OP_DIV +12: shift/reduce conflict (shift 20, reduce 14) on OP_MOD +12: shift/reduce conflict (shift 21, reduce 14) on OP_AND +state 12 + expr : expr . OP_ADD expr (7) + expr : expr . OP_SUB expr (8) + expr : expr . OP_MUL expr (9) + expr : expr . OP_DIV expr (10) + expr : expr . OP_MOD expr (11) + expr : expr . OP_AND expr (12) + expr : expr . '|' expr (13) + expr : OP_SUB expr . (14) + + OP_ADD shift 16 + OP_SUB shift 17 + OP_MUL shift 18 + OP_DIV shift 19 + OP_MOD shift 20 + OP_AND shift 21 + '|' reduce 14 + '\n' reduce 14 + ')' reduce 14 + + +state 13 + stat : LETTER '=' . expr (5) + + OP_SUB shift 3 + DIGIT shift 4 + LETTER shift 11 + '(' shift 6 + . error + + expr goto 24 + number goto 9 + + +state 14 + expr : '(' expr . ')' (6) + expr : expr . OP_ADD expr (7) + expr : expr . OP_SUB expr (8) + expr : expr . OP_MUL expr (9) + expr : expr . OP_DIV expr (10) + expr : expr . OP_MOD expr (11) + expr : expr . OP_AND expr (12) + expr : expr . '|' expr (13) + + OP_ADD shift 16 + OP_SUB shift 17 + OP_MUL shift 18 + OP_DIV shift 19 + OP_MOD shift 20 + OP_AND shift 21 + '|' shift 22 + ')' shift 25 + . error + + +state 15 + list : list stat '\n' . (2) + + . reduce 2 + + +state 16 + expr : expr OP_ADD . expr (7) + + OP_SUB shift 3 + DIGIT shift 4 + LETTER shift 11 + '(' shift 6 + . error + + expr goto 26 + number goto 9 + + +state 17 + expr : expr OP_SUB . expr (8) + + OP_SUB shift 3 + DIGIT shift 4 + LETTER shift 11 + '(' shift 6 + . error + + expr goto 27 + number goto 9 + + +state 18 + expr : expr OP_MUL . expr (9) + + OP_SUB shift 3 + DIGIT shift 4 + LETTER shift 11 + '(' shift 6 + . error + + expr goto 28 + number goto 9 + + +state 19 + expr : expr OP_DIV . expr (10) + + OP_SUB shift 3 + DIGIT shift 4 + LETTER shift 11 + '(' shift 6 + . error + + expr goto 29 + number goto 9 + + +state 20 + expr : expr OP_MOD . expr (11) + + OP_SUB shift 3 + DIGIT shift 4 + LETTER shift 11 + '(' shift 6 + . error + + expr goto 30 + number goto 9 + + +state 21 + expr : expr OP_AND . expr (12) + + OP_SUB shift 3 + DIGIT shift 4 + LETTER shift 11 + '(' shift 6 + . error + + expr goto 31 + number goto 9 + + +state 22 + expr : expr '|' . expr (13) + + OP_SUB shift 3 + DIGIT shift 4 + LETTER shift 11 + '(' shift 6 + . error + + expr goto 32 + number goto 9 + + +state 23 + number : number DIGIT . (18) + + . reduce 18 + + +state 24 + stat : LETTER '=' expr . (5) + expr : expr . OP_ADD expr (7) + expr : expr . OP_SUB expr (8) + expr : expr . OP_MUL expr (9) + expr : expr . OP_DIV expr (10) + expr : expr . OP_MOD expr (11) + expr : expr . OP_AND expr (12) + expr : expr . '|' expr (13) + + OP_ADD shift 16 + OP_SUB shift 17 + OP_MUL shift 18 + OP_DIV shift 19 + OP_MOD shift 20 + OP_AND shift 21 + '|' shift 22 + '\n' reduce 5 + + +state 25 + expr : '(' expr ')' . (6) + + . reduce 6 + + +26: shift/reduce conflict (shift 16, reduce 7) on OP_ADD +26: shift/reduce conflict (shift 17, reduce 7) on OP_SUB +26: shift/reduce conflict (shift 18, reduce 7) on OP_MUL +26: shift/reduce conflict (shift 19, reduce 7) on OP_DIV +26: shift/reduce conflict (shift 20, reduce 7) on OP_MOD +26: shift/reduce conflict (shift 21, reduce 7) on OP_AND +26: shift/reduce conflict (shift 22, reduce 7) on '|' +state 26 + expr : expr . OP_ADD expr (7) + expr : expr OP_ADD expr . (7) + expr : expr . OP_SUB expr (8) + expr : expr . OP_MUL expr (9) + expr : expr . OP_DIV expr (10) + expr : expr . OP_MOD expr (11) + expr : expr . OP_AND expr (12) + expr : expr . '|' expr (13) + + OP_ADD shift 16 + OP_SUB shift 17 + OP_MUL shift 18 + OP_DIV shift 19 + OP_MOD shift 20 + OP_AND shift 21 + '|' shift 22 + '\n' reduce 7 + ')' reduce 7 + + +27: shift/reduce conflict (shift 16, reduce 8) on OP_ADD +27: shift/reduce conflict (shift 17, reduce 8) on OP_SUB +27: shift/reduce conflict (shift 18, reduce 8) on OP_MUL +27: shift/reduce conflict (shift 19, reduce 8) on OP_DIV +27: shift/reduce conflict (shift 20, reduce 8) on OP_MOD +27: shift/reduce conflict (shift 21, reduce 8) on OP_AND +27: shift/reduce conflict (shift 22, reduce 8) on '|' +state 27 + expr : expr . OP_ADD expr (7) + expr : expr . OP_SUB expr (8) + expr : expr OP_SUB expr . (8) + expr : expr . OP_MUL expr (9) + expr : expr . OP_DIV expr (10) + expr : expr . OP_MOD expr (11) + expr : expr . OP_AND expr (12) + expr : expr . '|' expr (13) + + OP_ADD shift 16 + OP_SUB shift 17 + OP_MUL shift 18 + OP_DIV shift 19 + OP_MOD shift 20 + OP_AND shift 21 + '|' shift 22 + '\n' reduce 8 + ')' reduce 8 + + +28: shift/reduce conflict (shift 16, reduce 9) on OP_ADD +28: shift/reduce conflict (shift 17, reduce 9) on OP_SUB +28: shift/reduce conflict (shift 18, reduce 9) on OP_MUL +28: shift/reduce conflict (shift 19, reduce 9) on OP_DIV +28: shift/reduce conflict (shift 20, reduce 9) on OP_MOD +28: shift/reduce conflict (shift 21, reduce 9) on OP_AND +28: shift/reduce conflict (shift 22, reduce 9) on '|' +state 28 + expr : expr . OP_ADD expr (7) + expr : expr . OP_SUB expr (8) + expr : expr . OP_MUL expr (9) + expr : expr OP_MUL expr . (9) + expr : expr . OP_DIV expr (10) + expr : expr . OP_MOD expr (11) + expr : expr . OP_AND expr (12) + expr : expr . '|' expr (13) + + OP_ADD shift 16 + OP_SUB shift 17 + OP_MUL shift 18 + OP_DIV shift 19 + OP_MOD shift 20 + OP_AND shift 21 + '|' shift 22 + '\n' reduce 9 + ')' reduce 9 + + +29: shift/reduce conflict (shift 16, reduce 10) on OP_ADD +29: shift/reduce conflict (shift 17, reduce 10) on OP_SUB +29: shift/reduce conflict (shift 18, reduce 10) on OP_MUL +29: shift/reduce conflict (shift 19, reduce 10) on OP_DIV +29: shift/reduce conflict (shift 20, reduce 10) on OP_MOD +29: shift/reduce conflict (shift 21, reduce 10) on OP_AND +29: shift/reduce conflict (shift 22, reduce 10) on '|' +state 29 + expr : expr . OP_ADD expr (7) + expr : expr . OP_SUB expr (8) + expr : expr . OP_MUL expr (9) + expr : expr . OP_DIV expr (10) + expr : expr OP_DIV expr . (10) + expr : expr . OP_MOD expr (11) + expr : expr . OP_AND expr (12) + expr : expr . '|' expr (13) + + OP_ADD shift 16 + OP_SUB shift 17 + OP_MUL shift 18 + OP_DIV shift 19 + OP_MOD shift 20 + OP_AND shift 21 + '|' shift 22 + '\n' reduce 10 + ')' reduce 10 + + +30: shift/reduce conflict (shift 16, reduce 11) on OP_ADD +30: shift/reduce conflict (shift 17, reduce 11) on OP_SUB +30: shift/reduce conflict (shift 18, reduce 11) on OP_MUL +30: shift/reduce conflict (shift 19, reduce 11) on OP_DIV +30: shift/reduce conflict (shift 20, reduce 11) on OP_MOD +30: shift/reduce conflict (shift 21, reduce 11) on OP_AND +30: shift/reduce conflict (shift 22, reduce 11) on '|' +state 30 + expr : expr . OP_ADD expr (7) + expr : expr . OP_SUB expr (8) + expr : expr . OP_MUL expr (9) + expr : expr . OP_DIV expr (10) + expr : expr . OP_MOD expr (11) + expr : expr OP_MOD expr . (11) + expr : expr . OP_AND expr (12) + expr : expr . '|' expr (13) + + OP_ADD shift 16 + OP_SUB shift 17 + OP_MUL shift 18 + OP_DIV shift 19 + OP_MOD shift 20 + OP_AND shift 21 + '|' shift 22 + '\n' reduce 11 + ')' reduce 11 + + +31: shift/reduce conflict (shift 16, reduce 12) on OP_ADD +31: shift/reduce conflict (shift 17, reduce 12) on OP_SUB +31: shift/reduce conflict (shift 18, reduce 12) on OP_MUL +31: shift/reduce conflict (shift 19, reduce 12) on OP_DIV +31: shift/reduce conflict (shift 20, reduce 12) on OP_MOD +31: shift/reduce conflict (shift 21, reduce 12) on OP_AND +31: shift/reduce conflict (shift 22, reduce 12) on '|' +state 31 + expr : expr . OP_ADD expr (7) + expr : expr . OP_SUB expr (8) + expr : expr . OP_MUL expr (9) + expr : expr . OP_DIV expr (10) + expr : expr . OP_MOD expr (11) + expr : expr . OP_AND expr (12) + expr : expr OP_AND expr . (12) + expr : expr . '|' expr (13) + + OP_ADD shift 16 + OP_SUB shift 17 + OP_MUL shift 18 + OP_DIV shift 19 + OP_MOD shift 20 + OP_AND shift 21 + '|' shift 22 + '\n' reduce 12 + ')' reduce 12 + + +32: shift/reduce conflict (shift 16, reduce 13) on OP_ADD +32: shift/reduce conflict (shift 17, reduce 13) on OP_SUB +32: shift/reduce conflict (shift 18, reduce 13) on OP_MUL +32: shift/reduce conflict (shift 19, reduce 13) on OP_DIV +32: shift/reduce conflict (shift 20, reduce 13) on OP_MOD +32: shift/reduce conflict (shift 21, reduce 13) on OP_AND +state 32 + expr : expr . OP_ADD expr (7) + expr : expr . OP_SUB expr (8) + expr : expr . OP_MUL expr (9) + expr : expr . OP_DIV expr (10) + expr : expr . OP_MOD expr (11) + expr : expr . OP_AND expr (12) + expr : expr . '|' expr (13) + expr : expr '|' expr . (13) + + OP_ADD shift 16 + OP_SUB shift 17 + OP_MUL shift 18 + OP_DIV shift 19 + OP_MOD shift 20 + OP_AND shift 21 + '|' reduce 13 + '\n' reduce 13 + ')' reduce 13 + + +State 12 contains 6 shift/reduce conflicts. +State 26 contains 7 shift/reduce conflicts. +State 27 contains 7 shift/reduce conflicts. +State 28 contains 7 shift/reduce conflicts. +State 29 contains 7 shift/reduce conflicts. +State 30 contains 7 shift/reduce conflicts. +State 31 contains 7 shift/reduce conflicts. +State 32 contains 6 shift/reduce conflicts. + + +28 terminals, 5 nonterminals +19 grammar rules, 33 states diff --git a/test/quote_calc.tab.c b/test/quote_calc.tab.c new file mode 100644 index 000000000000..9a45472a0374 --- /dev/null +++ b/test/quote_calc.tab.c @@ -0,0 +1,693 @@ +#ifndef lint +static const char yysccsid[] = "@(#)yaccpar 1.9 (Berkeley) 02/21/93"; +#endif + +#define YYBYACC 1 +#define YYMAJOR 1 +#define YYMINOR 9 + +#define YYEMPTY (-1) +#define yyclearin (yychar = YYEMPTY) +#define yyerrok (yyerrflag = 0) +#define YYRECOVERING() (yyerrflag != 0) + + +#ifndef yyparse +#define yyparse quote_calc_parse +#endif /* yyparse */ + +#ifndef yylex +#define yylex quote_calc_lex +#endif /* yylex */ + +#ifndef yyerror +#define yyerror quote_calc_error +#endif /* yyerror */ + +#ifndef yychar +#define yychar quote_calc_char +#endif /* yychar */ + +#ifndef yyval +#define yyval quote_calc_val +#endif /* yyval */ + +#ifndef yylval +#define yylval quote_calc_lval +#endif /* yylval */ + +#ifndef yydebug +#define yydebug quote_calc_debug +#endif /* yydebug */ + +#ifndef yynerrs +#define yynerrs quote_calc_nerrs +#endif /* yynerrs */ + +#ifndef yyerrflag +#define yyerrflag quote_calc_errflag +#endif /* yyerrflag */ + +#ifndef yylhs +#define yylhs quote_calc_lhs +#endif /* yylhs */ + +#ifndef yylen +#define yylen quote_calc_len +#endif /* yylen */ + +#ifndef yydefred +#define yydefred quote_calc_defred +#endif /* yydefred */ + +#ifndef yydgoto +#define yydgoto quote_calc_dgoto +#endif /* yydgoto */ + +#ifndef yysindex +#define yysindex quote_calc_sindex +#endif /* yysindex */ + +#ifndef yyrindex +#define yyrindex quote_calc_rindex +#endif /* yyrindex */ + +#ifndef yygindex +#define yygindex quote_calc_gindex +#endif /* yygindex */ + +#ifndef yytable +#define yytable quote_calc_table +#endif /* yytable */ + +#ifndef yycheck +#define yycheck quote_calc_check +#endif /* yycheck */ + +#ifndef yyname +#define yyname quote_calc_name +#endif /* yyname */ + +#ifndef yyrule +#define yyrule quote_calc_rule +#endif /* yyrule */ +#define YYPREFIX "quote_calc_" + +#define YYPURE 0 + +#line 2 "quote_calc.y" +# include <stdio.h> +# include <ctype.h> + +int regs[26]; +int base; + +int yylex(void); +static void yyerror(const char *s); + +#line 109 "quote_calc.tab.c" + +#ifndef YYSTYPE +typedef int YYSTYPE; +#endif + +/* compatibility with bison */ +#ifdef YYPARSE_PARAM +/* compatibility with FreeBSD */ +# ifdef YYPARSE_PARAM_TYPE +# define YYPARSE_DECL() yyparse(YYPARSE_PARAM_TYPE YYPARSE_PARAM) +# else +# define YYPARSE_DECL() yyparse(void *YYPARSE_PARAM) +# endif +#else +# define YYPARSE_DECL() yyparse(void) +#endif + +/* Parameters sent to lex. */ +#ifdef YYLEX_PARAM +# define YYLEX_DECL() yylex(void *YYLEX_PARAM) +# define YYLEX yylex(YYLEX_PARAM) +#else +# define YYLEX_DECL() yylex(void) +# define YYLEX yylex() +#endif + +/* Parameters sent to yyerror. */ +#ifndef YYERROR_DECL +#define YYERROR_DECL() yyerror(const char *s) +#endif +#ifndef YYERROR_CALL +#define YYERROR_CALL(msg) yyerror(msg) +#endif + +extern int YYPARSE_DECL(); + +#define OP_ADD 257 +#define ADD 258 +#define OP_SUB 259 +#define SUB 260 +#define OP_MUL 261 +#define MUL 262 +#define OP_DIV 263 +#define DIV 264 +#define OP_MOD 265 +#define MOD 266 +#define OP_AND 267 +#define AND 268 +#define DIGIT 269 +#define LETTER 270 +#define UMINUS 271 +#define YYERRCODE 256 +static const short quote_calc_lhs[] = { -1, + 0, 0, 0, 1, 1, 2, 2, 2, 2, 2, + 2, 2, 2, 2, 2, 2, 3, 3, +}; +static const short quote_calc_len[] = { 2, + 0, 3, 3, 1, 3, 3, 3, 3, 3, 3, + 3, 3, 3, 2, 1, 1, 1, 2, +}; +static const short quote_calc_defred[] = { 1, + 0, 0, 0, 17, 0, 0, 0, 0, 0, 3, + 15, 0, 0, 0, 2, 0, 0, 0, 0, 0, + 0, 0, 18, 0, 6, 0, 0, 0, 0, 0, + 0, 0, +}; +static const short quote_calc_dgoto[] = { 1, + 7, 8, 9, +}; +static const short quote_calc_sindex[] = { 0, + -38, 5, -36, 0, -51, -36, 7, -121, -248, 0, + 0, -243, -36, -22, 0, -36, -36, -36, -36, -36, + -36, -36, 0, -121, 0, -121, -121, -121, -121, -121, + -121, -243, +}; +static const short quote_calc_rindex[] = { 0, + 0, 0, 0, 0, -9, 0, 0, 13, -10, 0, + 0, -5, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 15, 0, -3, -2, -1, 1, 2, + 3, -4, +}; +static const short quote_calc_gindex[] = { 0, + 0, 42, 0, +}; +#define YYTABLESIZE 258 +static const short quote_calc_table[] = { 16, + 15, 6, 22, 6, 14, 13, 7, 8, 9, 13, + 10, 11, 12, 16, 10, 17, 15, 18, 25, 19, + 23, 20, 4, 21, 5, 0, 0, 0, 0, 0, + 16, 0, 0, 0, 0, 14, 13, 7, 8, 9, + 0, 10, 11, 12, 12, 0, 0, 14, 0, 0, + 0, 0, 0, 0, 24, 0, 0, 26, 27, 28, + 29, 30, 31, 32, 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, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 22, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 16, 15, 0, 0, 0, 14, 13, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 16, 0, 17, 0, 18, + 0, 19, 0, 20, 0, 21, 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, 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, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 2, 0, 0, + 3, 0, 3, 0, 0, 0, 0, 0, 0, 0, + 4, 5, 4, 11, 16, 0, 17, 0, 18, 0, + 19, 0, 20, 0, 21, 0, 16, 15, 16, 15, + 16, 15, 16, 15, 16, 15, 16, 15, +}; +static const short quote_calc_check[] = { 10, + 10, 40, 124, 40, 10, 10, 10, 10, 10, 61, + 10, 10, 10, 257, 10, 259, 10, 261, 41, 263, + 269, 265, 10, 267, 10, -1, -1, -1, -1, -1, + 41, -1, -1, -1, -1, 41, 41, 41, 41, 41, + -1, 41, 41, 41, 3, -1, -1, 6, -1, -1, + -1, -1, -1, -1, 13, -1, -1, 16, 17, 18, + 19, 20, 21, 22, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, + -1, 124, -1, -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, 124, 124, -1, -1, -1, 124, 124, + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, 257, -1, 259, -1, 261, + -1, 263, -1, 265, -1, 267, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, 256, -1, -1, + 259, -1, 259, -1, -1, -1, -1, -1, -1, -1, + 269, 270, 269, 270, 257, -1, 259, -1, 261, -1, + 263, -1, 265, -1, 267, -1, 257, 257, 259, 259, + 261, 261, 263, 263, 265, 265, 267, 267, +}; +#define YYFINAL 1 +#ifndef YYDEBUG +#define YYDEBUG 0 +#endif +#define YYMAXTOKEN 271 +#if YYDEBUG +static const char *yyname[] = { + +"end-of-file",0,0,0,0,0,0,0,0,0,"'\\n'",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,"'-'",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,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,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,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,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,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,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,0,0,0,0,0,0, +0,0,0,0,0,0,"OP_ADD","\"ADD\"","OP_SUB","\"SUB\"","OP_MUL","\"MUL\"","OP_DIV", +"\"DIV\"","OP_MOD","\"MOD\"","OP_AND","\"AND\"","DIGIT","LETTER","UMINUS", +}; +static const char *yyrule[] = { +"$accept : list", +"list :", +"list : list stat '\\n'", +"list : list error '\\n'", +"stat : expr", +"stat : LETTER '=' expr", +"expr : '(' expr ')'", +"expr : expr OP_ADD expr", +"expr : expr OP_SUB expr", +"expr : expr OP_MUL expr", +"expr : expr OP_DIV expr", +"expr : expr OP_MOD expr", +"expr : expr OP_AND expr", +"expr : expr '|' expr", +"expr : OP_SUB expr", +"expr : LETTER", +"expr : number", +"number : DIGIT", +"number : number DIGIT", + +}; +#endif + +int yydebug; +int yynerrs; + +int yyerrflag; +int yychar; +YYSTYPE yyval; +YYSTYPE yylval; + +/* define the initial stack-sizes */ +#ifdef YYSTACKSIZE +#undef YYMAXDEPTH +#define YYMAXDEPTH YYSTACKSIZE +#else +#ifdef YYMAXDEPTH +#define YYSTACKSIZE YYMAXDEPTH +#else +#define YYSTACKSIZE 500 +#define YYMAXDEPTH 500 +#endif +#endif + +#define YYINITSTACKSIZE 500 + +typedef struct { + unsigned stacksize; + short *s_base; + short *s_mark; + short *s_last; + YYSTYPE *l_base; + YYSTYPE *l_mark; +} YYSTACKDATA; +/* variables for the parser stack */ +static YYSTACKDATA yystack; +#line 73 "quote_calc.y" + /* start of programs */ + +int +main (void) +{ + while(!feof(stdin)) { + yyparse(); + } + return 0; +} + +static void +yyerror(const char *s) +{ + fprintf(stderr, "%s\n", s); +} + +int +yylex(void) { + /* lexical analysis routine */ + /* returns LETTER for a lower case letter, yylval = 0 through 25 */ + /* return DIGIT for a digit, yylval = 0 through 9 */ + /* all other characters are returned immediately */ + + int c; + + while( (c=getchar()) == ' ' ) { /* skip blanks */ } + + /* c is now nonblank */ + + if( islower( c )) { + yylval = c - 'a'; + return ( LETTER ); + } + if( isdigit( c )) { + yylval = c - '0'; + return ( DIGIT ); + } + return( c ); +} +#line 367 "quote_calc.tab.c" + +#if YYDEBUG +#include <stdio.h> /* needed for printf */ +#endif + +#include <stdlib.h> /* needed for malloc, etc */ +#include <string.h> /* needed for memset */ + +/* allocate initial stack or double stack size, up to YYMAXDEPTH */ +static int yygrowstack(YYSTACKDATA *data) +{ + int i; + unsigned newsize; + short *newss; + YYSTYPE *newvs; + + if ((newsize = data->stacksize) == 0) + newsize = YYINITSTACKSIZE; + else if (newsize >= YYMAXDEPTH) + return -1; + else if ((newsize *= 2) > YYMAXDEPTH) + newsize = YYMAXDEPTH; + + i = data->s_mark - data->s_base; + newss = (short *)realloc(data->s_base, newsize * sizeof(*newss)); + if (newss == 0) + return -1; + + data->s_base = newss; + data->s_mark = newss + i; + + newvs = (YYSTYPE *)realloc(data->l_base, newsize * sizeof(*newvs)); + if (newvs == 0) + return -1; + + data->l_base = newvs; + data->l_mark = newvs + i; + + data->stacksize = newsize; + data->s_last = data->s_base + newsize - 1; + return 0; +} + +#if YYPURE || defined(YY_NO_LEAKS) +static void yyfreestack(YYSTACKDATA *data) +{ + free(data->s_base); + free(data->l_base); + memset(data, 0, sizeof(*data)); +} +#else +#define yyfreestack(data) /* nothing */ +#endif + +#define YYABORT goto yyabort +#define YYREJECT goto yyabort +#define YYACCEPT goto yyaccept +#define YYERROR goto yyerrlab + +int +YYPARSE_DECL() +{ + int yym, yyn, yystate; +#if YYDEBUG + const char *yys; + + if ((yys = getenv("YYDEBUG")) != 0) + { + yyn = *yys; + if (yyn >= '0' && yyn <= '9') + yydebug = yyn - '0'; + } +#endif + + yynerrs = 0; + yyerrflag = 0; + yychar = YYEMPTY; + yystate = 0; + +#if YYPURE + memset(&yystack, 0, sizeof(yystack)); +#endif + + if (yystack.s_base == NULL && yygrowstack(&yystack)) goto yyoverflow; + yystack.s_mark = yystack.s_base; + yystack.l_mark = yystack.l_base; + yystate = 0; + *yystack.s_mark = 0; + +yyloop: + if ((yyn = yydefred[yystate]) != 0) goto yyreduce; + if (yychar < 0) + { + if ((yychar = YYLEX) < 0) yychar = 0; +#if YYDEBUG + if (yydebug) + { + yys = 0; + if (yychar <= YYMAXTOKEN) yys = yyname[yychar]; + if (!yys) yys = "illegal-symbol"; + printf("%sdebug: state %d, reading %d (%s)\n", + YYPREFIX, yystate, yychar, yys); + } +#endif + } + if ((yyn = yysindex[yystate]) && (yyn += yychar) >= 0 && + yyn <= YYTABLESIZE && yycheck[yyn] == yychar) + { +#if YYDEBUG + if (yydebug) + printf("%sdebug: state %d, shifting to state %d\n", + YYPREFIX, yystate, yytable[yyn]); +#endif + if (yystack.s_mark >= yystack.s_last && yygrowstack(&yystack)) + { + goto yyoverflow; + } + yystate = yytable[yyn]; + *++yystack.s_mark = yytable[yyn]; + *++yystack.l_mark = yylval; + yychar = YYEMPTY; + if (yyerrflag > 0) --yyerrflag; + goto yyloop; + } + if ((yyn = yyrindex[yystate]) && (yyn += yychar) >= 0 && + yyn <= YYTABLESIZE && yycheck[yyn] == yychar) + { + yyn = yytable[yyn]; + goto yyreduce; + } + if (yyerrflag) goto yyinrecovery; + + yyerror("syntax error"); + + goto yyerrlab; + +yyerrlab: + ++yynerrs; + +yyinrecovery: + if (yyerrflag < 3) + { + yyerrflag = 3; + for (;;) + { + if ((yyn = yysindex[*yystack.s_mark]) && (yyn += YYERRCODE) >= 0 && + yyn <= YYTABLESIZE && yycheck[yyn] == YYERRCODE) + { +#if YYDEBUG + if (yydebug) + printf("%sdebug: state %d, error recovery shifting\ + to state %d\n", YYPREFIX, *yystack.s_mark, yytable[yyn]); +#endif + if (yystack.s_mark >= yystack.s_last && yygrowstack(&yystack)) + { + goto yyoverflow; + } + yystate = yytable[yyn]; + *++yystack.s_mark = yytable[yyn]; + *++yystack.l_mark = yylval; + goto yyloop; + } + else + { +#if YYDEBUG + if (yydebug) + printf("%sdebug: error recovery discarding state %d\n", + YYPREFIX, *yystack.s_mark); +#endif + if (yystack.s_mark <= yystack.s_base) goto yyabort; + --yystack.s_mark; + --yystack.l_mark; + } + } + } + else + { + if (yychar == 0) goto yyabort; +#if YYDEBUG + if (yydebug) + { + yys = 0; + if (yychar <= YYMAXTOKEN) yys = yyname[yychar]; + if (!yys) yys = "illegal-symbol"; + printf("%sdebug: state %d, error recovery discards token %d (%s)\n", + YYPREFIX, yystate, yychar, yys); + } +#endif + yychar = YYEMPTY; + goto yyloop; + } + +yyreduce: +#if YYDEBUG + if (yydebug) + printf("%sdebug: state %d, reducing by rule %d (%s)\n", + YYPREFIX, yystate, yyn, yyrule[yyn]); +#endif + yym = yylen[yyn]; + if (yym) + yyval = yystack.l_mark[1-yym]; + else + memset(&yyval, 0, sizeof yyval); + switch (yyn) + { +case 3: +#line 35 "quote_calc.y" + { yyerrok ; } +break; +case 4: +#line 39 "quote_calc.y" + { printf("%d\n",yystack.l_mark[0]);} +break; +case 5: +#line 41 "quote_calc.y" + { regs[yystack.l_mark[-2]] = yystack.l_mark[0]; } +break; +case 6: +#line 45 "quote_calc.y" + { yyval = yystack.l_mark[-1]; } +break; +case 7: +#line 47 "quote_calc.y" + { yyval = yystack.l_mark[-2] + yystack.l_mark[0]; } +break; +case 8: +#line 49 "quote_calc.y" + { yyval = yystack.l_mark[-2] - yystack.l_mark[0]; } +break; +case 9: +#line 51 "quote_calc.y" + { yyval = yystack.l_mark[-2] * yystack.l_mark[0]; } +break; +case 10: +#line 53 "quote_calc.y" + { yyval = yystack.l_mark[-2] / yystack.l_mark[0]; } +break; +case 11: +#line 55 "quote_calc.y" + { yyval = yystack.l_mark[-2] % yystack.l_mark[0]; } +break; +case 12: +#line 57 "quote_calc.y" + { yyval = yystack.l_mark[-2] & yystack.l_mark[0]; } +break; +case 13: +#line 59 "quote_calc.y" + { yyval = yystack.l_mark[-2] | yystack.l_mark[0]; } +break; +case 14: +#line 61 "quote_calc.y" + { yyval = - yystack.l_mark[0]; } +break; +case 15: +#line 63 "quote_calc.y" + { yyval = regs[yystack.l_mark[0]]; } +break; +case 17: +#line 68 "quote_calc.y" + { yyval = yystack.l_mark[0]; base = (yystack.l_mark[0]==0) ? 8 : 10; } +break; +case 18: +#line 70 "quote_calc.y" + { yyval = base * yystack.l_mark[-1] + yystack.l_mark[0]; } +break; +#line 633 "quote_calc.tab.c" + } + yystack.s_mark -= yym; + yystate = *yystack.s_mark; + yystack.l_mark -= yym; + yym = yylhs[yyn]; + if (yystate == 0 && yym == 0) + { +#if YYDEBUG + if (yydebug) + printf("%sdebug: after reduction, shifting from state 0 to\ + state %d\n", YYPREFIX, YYFINAL); +#endif + yystate = YYFINAL; + *++yystack.s_mark = YYFINAL; + *++yystack.l_mark = yyval; + if (yychar < 0) + { + if ((yychar = YYLEX) < 0) yychar = 0; +#if YYDEBUG + if (yydebug) + { + yys = 0; + if (yychar <= YYMAXTOKEN) yys = yyname[yychar]; + if (!yys) yys = "illegal-symbol"; + printf("%sdebug: state %d, reading %d (%s)\n", + YYPREFIX, YYFINAL, yychar, yys); + } +#endif + } + if (yychar == 0) goto yyaccept; + goto yyloop; + } + if ((yyn = yygindex[yym]) && (yyn += yystate) >= 0 && + yyn <= YYTABLESIZE && yycheck[yyn] == yystate) + yystate = yytable[yyn]; + else + yystate = yydgoto[yym]; +#if YYDEBUG + if (yydebug) + printf("%sdebug: after reduction, shifting from state %d \ +to state %d\n", YYPREFIX, *yystack.s_mark, yystate); +#endif + if (yystack.s_mark >= yystack.s_last && yygrowstack(&yystack)) + { + goto yyoverflow; + } + *++yystack.s_mark = (short) yystate; + *++yystack.l_mark = yyval; + goto yyloop; + +yyoverflow: + yyerror("yacc stack overflow"); + +yyabort: + yyfreestack(&yystack); + return (1); + +yyaccept: + yyfreestack(&yystack); + return (0); +} diff --git a/test/quote_calc.tab.h b/test/quote_calc.tab.h new file mode 100644 index 000000000000..498eff210dbe --- /dev/null +++ b/test/quote_calc.tab.h @@ -0,0 +1,15 @@ +#define OP_ADD 257 +#define ADD 258 +#define OP_SUB 259 +#define SUB 260 +#define OP_MUL 261 +#define MUL 262 +#define OP_DIV 263 +#define DIV 264 +#define OP_MOD 265 +#define MOD 266 +#define OP_AND 267 +#define AND 268 +#define DIGIT 269 +#define LETTER 270 +#define UMINUS 271 diff --git a/test/quote_calc.y b/test/quote_calc.y new file mode 100644 index 000000000000..9304dd8a7006 --- /dev/null +++ b/test/quote_calc.y @@ -0,0 +1,112 @@ +%{ +# include <stdio.h> +# include <ctype.h> + +int regs[26]; +int base; + +int yylex(void); +static void yyerror(const char *s); + +%} + +%start list + +%token OP_ADD "ADD" +%token OP_SUB "SUB" +%token OP_MUL "MUL" +%token OP_DIV "DIV" +%token OP_MOD "MOD" +%token OP_AND "AND" + +%token DIGIT LETTER + +%left '|' +%left '&' +%left '+' '-' +%left '*' '/' '%' +%left UMINUS /* supplies precedence for unary minus */ + +%% /* beginning of rules section */ + +list : /* empty */ + | list stat '\n' + | list error '\n' + { yyerrok ; } + ; + +stat : expr + { printf("%d\n",$1);} + | LETTER '=' expr + { regs[$1] = $3; } + ; + +expr : '(' expr ')' + { $$ = $2; } + | expr OP_ADD expr + { $$ = $1 + $3; } + | expr OP_SUB expr + { $$ = $1 - $3; } + | expr OP_MUL expr + { $$ = $1 * $3; } + | expr OP_DIV expr + { $$ = $1 / $3; } + | expr OP_MOD expr + { $$ = $1 % $3; } + | expr OP_AND expr + { $$ = $1 & $3; } + | expr '|' expr + { $$ = $1 | $3; } + | OP_SUB expr %prec UMINUS + { $$ = - $2; } + | LETTER + { $$ = regs[$1]; } + | number + ; + +number: DIGIT + { $$ = $1; base = ($1==0) ? 8 : 10; } + | number DIGIT + { $$ = base * $1 + $2; } + ; + +%% /* start of programs */ + +int +main (void) +{ + while(!feof(stdin)) { + yyparse(); + } + return 0; +} + +static void +yyerror(const char *s) +{ + fprintf(stderr, "%s\n", s); +} + +int +yylex(void) { + /* lexical analysis routine */ + /* returns LETTER for a lower case letter, yylval = 0 through 25 */ + /* return DIGIT for a digit, yylval = 0 through 9 */ + /* all other characters are returned immediately */ + + int c; + + while( (c=getchar()) == ' ' ) { /* skip blanks */ } + + /* c is now nonblank */ + + if( islower( c )) { + yylval = c - 'a'; + return ( LETTER ); + } + if( isdigit( c )) { + yylval = c - '0'; + return ( DIGIT ); + } + return( c ); +} diff --git a/test/quote_calc2-s.output b/test/quote_calc2-s.output new file mode 100644 index 000000000000..ed28ae2f21c0 --- /dev/null +++ b/test/quote_calc2-s.output @@ -0,0 +1,557 @@ + 0 $accept : list $end + + 1 list : + 2 | list stat '\n' + 3 | list error '\n' + + 4 stat : expr + 5 | LETTER '=' expr + + 6 expr : '(' expr ')' + 7 | expr "ADD" expr + 8 | expr "SUB" expr + 9 | expr "MUL" expr + 10 | expr "DIV" expr + 11 | expr "MOD" expr + 12 | expr "AND" expr + 13 | expr '|' expr + 14 | "SUB" expr + 15 | LETTER + 16 | number + + 17 number : DIGIT + 18 | number DIGIT + +state 0 + $accept : . list $end (0) + list : . (1) + + . reduce 1 + + list goto 1 + + +state 1 + $accept : list . $end (0) + list : list . stat '\n' (2) + list : list . error '\n' (3) + + $end accept + error shift 2 + "SUB" shift 3 + DIGIT shift 4 + LETTER shift 5 + '(' shift 6 + . error + + stat goto 7 + expr goto 8 + number goto 9 + + +state 2 + list : list error . '\n' (3) + + '\n' shift 10 + . error + + +state 3 + expr : "SUB" . expr (14) + + "SUB" shift 3 + DIGIT shift 4 + LETTER shift 11 + '(' shift 6 + . error + + expr goto 12 + number goto 9 + + +state 4 + number : DIGIT . (17) + + . reduce 17 + + +state 5 + stat : LETTER . '=' expr (5) + expr : LETTER . (15) + + '=' shift 13 + "ADD" reduce 15 + "SUB" reduce 15 + "MUL" reduce 15 + "DIV" reduce 15 + "MOD" reduce 15 + "AND" reduce 15 + '|' reduce 15 + '\n' reduce 15 + + +state 6 + expr : '(' . expr ')' (6) + + "SUB" shift 3 + DIGIT shift 4 + LETTER shift 11 + '(' shift 6 + . error + + expr goto 14 + number goto 9 + + +state 7 + list : list stat . '\n' (2) + + '\n' shift 15 + . error + + +state 8 + stat : expr . (4) + expr : expr . "ADD" expr (7) + expr : expr . "SUB" expr (8) + expr : expr . "MUL" expr (9) + expr : expr . "DIV" expr (10) + expr : expr . "MOD" expr (11) + expr : expr . "AND" expr (12) + expr : expr . '|' expr (13) + + "ADD" shift 16 + "SUB" shift 17 + "MUL" shift 18 + "DIV" shift 19 + "MOD" shift 20 + "AND" shift 21 + '|' shift 22 + '\n' reduce 4 + + +state 9 + expr : number . (16) + number : number . DIGIT (18) + + DIGIT shift 23 + "ADD" reduce 16 + "SUB" reduce 16 + "MUL" reduce 16 + "DIV" reduce 16 + "MOD" reduce 16 + "AND" reduce 16 + '|' reduce 16 + '\n' reduce 16 + ')' reduce 16 + + +state 10 + list : list error '\n' . (3) + + . reduce 3 + + +state 11 + expr : LETTER . (15) + + . reduce 15 + + +12: shift/reduce conflict (shift 16, reduce 14) on "ADD" +12: shift/reduce conflict (shift 17, reduce 14) on "SUB" +12: shift/reduce conflict (shift 18, reduce 14) on "MUL" +12: shift/reduce conflict (shift 19, reduce 14) on "DIV" +12: shift/reduce conflict (shift 20, reduce 14) on "MOD" +12: shift/reduce conflict (shift 21, reduce 14) on "AND" +state 12 + expr : expr . "ADD" expr (7) + expr : expr . "SUB" expr (8) + expr : expr . "MUL" expr (9) + expr : expr . "DIV" expr (10) + expr : expr . "MOD" expr (11) + expr : expr . "AND" expr (12) + expr : expr . '|' expr (13) + expr : "SUB" expr . (14) + + "ADD" shift 16 + "SUB" shift 17 + "MUL" shift 18 + "DIV" shift 19 + "MOD" shift 20 + "AND" shift 21 + '|' reduce 14 + '\n' reduce 14 + ')' reduce 14 + + +state 13 + stat : LETTER '=' . expr (5) + + "SUB" shift 3 + DIGIT shift 4 + LETTER shift 11 + '(' shift 6 + . error + + expr goto 24 + number goto 9 + + +state 14 + expr : '(' expr . ')' (6) + expr : expr . "ADD" expr (7) + expr : expr . "SUB" expr (8) + expr : expr . "MUL" expr (9) + expr : expr . "DIV" expr (10) + expr : expr . "MOD" expr (11) + expr : expr . "AND" expr (12) + expr : expr . '|' expr (13) + + "ADD" shift 16 + "SUB" shift 17 + "MUL" shift 18 + "DIV" shift 19 + "MOD" shift 20 + "AND" shift 21 + '|' shift 22 + ')' shift 25 + . error + + +state 15 + list : list stat '\n' . (2) + + . reduce 2 + + +state 16 + expr : expr "ADD" . expr (7) + + "SUB" shift 3 + DIGIT shift 4 + LETTER shift 11 + '(' shift 6 + . error + + expr goto 26 + number goto 9 + + +state 17 + expr : expr "SUB" . expr (8) + + "SUB" shift 3 + DIGIT shift 4 + LETTER shift 11 + '(' shift 6 + . error + + expr goto 27 + number goto 9 + + +state 18 + expr : expr "MUL" . expr (9) + + "SUB" shift 3 + DIGIT shift 4 + LETTER shift 11 + '(' shift 6 + . error + + expr goto 28 + number goto 9 + + +state 19 + expr : expr "DIV" . expr (10) + + "SUB" shift 3 + DIGIT shift 4 + LETTER shift 11 + '(' shift 6 + . error + + expr goto 29 + number goto 9 + + +state 20 + expr : expr "MOD" . expr (11) + + "SUB" shift 3 + DIGIT shift 4 + LETTER shift 11 + '(' shift 6 + . error + + expr goto 30 + number goto 9 + + +state 21 + expr : expr "AND" . expr (12) + + "SUB" shift 3 + DIGIT shift 4 + LETTER shift 11 + '(' shift 6 + . error + + expr goto 31 + number goto 9 + + +state 22 + expr : expr '|' . expr (13) + + "SUB" shift 3 + DIGIT shift 4 + LETTER shift 11 + '(' shift 6 + . error + + expr goto 32 + number goto 9 + + +state 23 + number : number DIGIT . (18) + + . reduce 18 + + +state 24 + stat : LETTER '=' expr . (5) + expr : expr . "ADD" expr (7) + expr : expr . "SUB" expr (8) + expr : expr . "MUL" expr (9) + expr : expr . "DIV" expr (10) + expr : expr . "MOD" expr (11) + expr : expr . "AND" expr (12) + expr : expr . '|' expr (13) + + "ADD" shift 16 + "SUB" shift 17 + "MUL" shift 18 + "DIV" shift 19 + "MOD" shift 20 + "AND" shift 21 + '|' shift 22 + '\n' reduce 5 + + +state 25 + expr : '(' expr ')' . (6) + + . reduce 6 + + +26: shift/reduce conflict (shift 16, reduce 7) on "ADD" +26: shift/reduce conflict (shift 17, reduce 7) on "SUB" +26: shift/reduce conflict (shift 18, reduce 7) on "MUL" +26: shift/reduce conflict (shift 19, reduce 7) on "DIV" +26: shift/reduce conflict (shift 20, reduce 7) on "MOD" +26: shift/reduce conflict (shift 21, reduce 7) on "AND" +26: shift/reduce conflict (shift 22, reduce 7) on '|' +state 26 + expr : expr . "ADD" expr (7) + expr : expr "ADD" expr . (7) + expr : expr . "SUB" expr (8) + expr : expr . "MUL" expr (9) + expr : expr . "DIV" expr (10) + expr : expr . "MOD" expr (11) + expr : expr . "AND" expr (12) + expr : expr . '|' expr (13) + + "ADD" shift 16 + "SUB" shift 17 + "MUL" shift 18 + "DIV" shift 19 + "MOD" shift 20 + "AND" shift 21 + '|' shift 22 + '\n' reduce 7 + ')' reduce 7 + + +27: shift/reduce conflict (shift 16, reduce 8) on "ADD" +27: shift/reduce conflict (shift 17, reduce 8) on "SUB" +27: shift/reduce conflict (shift 18, reduce 8) on "MUL" +27: shift/reduce conflict (shift 19, reduce 8) on "DIV" +27: shift/reduce conflict (shift 20, reduce 8) on "MOD" +27: shift/reduce conflict (shift 21, reduce 8) on "AND" +27: shift/reduce conflict (shift 22, reduce 8) on '|' +state 27 + expr : expr . "ADD" expr (7) + expr : expr . "SUB" expr (8) + expr : expr "SUB" expr . (8) + expr : expr . "MUL" expr (9) + expr : expr . "DIV" expr (10) + expr : expr . "MOD" expr (11) + expr : expr . "AND" expr (12) + expr : expr . '|' expr (13) + + "ADD" shift 16 + "SUB" shift 17 + "MUL" shift 18 + "DIV" shift 19 + "MOD" shift 20 + "AND" shift 21 + '|' shift 22 + '\n' reduce 8 + ')' reduce 8 + + +28: shift/reduce conflict (shift 16, reduce 9) on "ADD" +28: shift/reduce conflict (shift 17, reduce 9) on "SUB" +28: shift/reduce conflict (shift 18, reduce 9) on "MUL" +28: shift/reduce conflict (shift 19, reduce 9) on "DIV" +28: shift/reduce conflict (shift 20, reduce 9) on "MOD" +28: shift/reduce conflict (shift 21, reduce 9) on "AND" +28: shift/reduce conflict (shift 22, reduce 9) on '|' +state 28 + expr : expr . "ADD" expr (7) + expr : expr . "SUB" expr (8) + expr : expr . "MUL" expr (9) + expr : expr "MUL" expr . (9) + expr : expr . "DIV" expr (10) + expr : expr . "MOD" expr (11) + expr : expr . "AND" expr (12) + expr : expr . '|' expr (13) + + "ADD" shift 16 + "SUB" shift 17 + "MUL" shift 18 + "DIV" shift 19 + "MOD" shift 20 + "AND" shift 21 + '|' shift 22 + '\n' reduce 9 + ')' reduce 9 + + +29: shift/reduce conflict (shift 16, reduce 10) on "ADD" +29: shift/reduce conflict (shift 17, reduce 10) on "SUB" +29: shift/reduce conflict (shift 18, reduce 10) on "MUL" +29: shift/reduce conflict (shift 19, reduce 10) on "DIV" +29: shift/reduce conflict (shift 20, reduce 10) on "MOD" +29: shift/reduce conflict (shift 21, reduce 10) on "AND" +29: shift/reduce conflict (shift 22, reduce 10) on '|' +state 29 + expr : expr . "ADD" expr (7) + expr : expr . "SUB" expr (8) + expr : expr . "MUL" expr (9) + expr : expr . "DIV" expr (10) + expr : expr "DIV" expr . (10) + expr : expr . "MOD" expr (11) + expr : expr . "AND" expr (12) + expr : expr . '|' expr (13) + + "ADD" shift 16 + "SUB" shift 17 + "MUL" shift 18 + "DIV" shift 19 + "MOD" shift 20 + "AND" shift 21 + '|' shift 22 + '\n' reduce 10 + ')' reduce 10 + + +30: shift/reduce conflict (shift 16, reduce 11) on "ADD" +30: shift/reduce conflict (shift 17, reduce 11) on "SUB" +30: shift/reduce conflict (shift 18, reduce 11) on "MUL" +30: shift/reduce conflict (shift 19, reduce 11) on "DIV" +30: shift/reduce conflict (shift 20, reduce 11) on "MOD" +30: shift/reduce conflict (shift 21, reduce 11) on "AND" +30: shift/reduce conflict (shift 22, reduce 11) on '|' +state 30 + expr : expr . "ADD" expr (7) + expr : expr . "SUB" expr (8) + expr : expr . "MUL" expr (9) + expr : expr . "DIV" expr (10) + expr : expr . "MOD" expr (11) + expr : expr "MOD" expr . (11) + expr : expr . "AND" expr (12) + expr : expr . '|' expr (13) + + "ADD" shift 16 + "SUB" shift 17 + "MUL" shift 18 + "DIV" shift 19 + "MOD" shift 20 + "AND" shift 21 + '|' shift 22 + '\n' reduce 11 + ')' reduce 11 + + +31: shift/reduce conflict (shift 16, reduce 12) on "ADD" +31: shift/reduce conflict (shift 17, reduce 12) on "SUB" +31: shift/reduce conflict (shift 18, reduce 12) on "MUL" +31: shift/reduce conflict (shift 19, reduce 12) on "DIV" +31: shift/reduce conflict (shift 20, reduce 12) on "MOD" +31: shift/reduce conflict (shift 21, reduce 12) on "AND" +31: shift/reduce conflict (shift 22, reduce 12) on '|' +state 31 + expr : expr . "ADD" expr (7) + expr : expr . "SUB" expr (8) + expr : expr . "MUL" expr (9) + expr : expr . "DIV" expr (10) + expr : expr . "MOD" expr (11) + expr : expr . "AND" expr (12) + expr : expr "AND" expr . (12) + expr : expr . '|' expr (13) + + "ADD" shift 16 + "SUB" shift 17 + "MUL" shift 18 + "DIV" shift 19 + "MOD" shift 20 + "AND" shift 21 + '|' shift 22 + '\n' reduce 12 + ')' reduce 12 + + +32: shift/reduce conflict (shift 16, reduce 13) on "ADD" +32: shift/reduce conflict (shift 17, reduce 13) on "SUB" +32: shift/reduce conflict (shift 18, reduce 13) on "MUL" +32: shift/reduce conflict (shift 19, reduce 13) on "DIV" +32: shift/reduce conflict (shift 20, reduce 13) on "MOD" +32: shift/reduce conflict (shift 21, reduce 13) on "AND" +state 32 + expr : expr . "ADD" expr (7) + expr : expr . "SUB" expr (8) + expr : expr . "MUL" expr (9) + expr : expr . "DIV" expr (10) + expr : expr . "MOD" expr (11) + expr : expr . "AND" expr (12) + expr : expr . '|' expr (13) + expr : expr '|' expr . (13) + + "ADD" shift 16 + "SUB" shift 17 + "MUL" shift 18 + "DIV" shift 19 + "MOD" shift 20 + "AND" shift 21 + '|' reduce 13 + '\n' reduce 13 + ')' reduce 13 + + +State 12 contains 6 shift/reduce conflicts. +State 26 contains 7 shift/reduce conflicts. +State 27 contains 7 shift/reduce conflicts. +State 28 contains 7 shift/reduce conflicts. +State 29 contains 7 shift/reduce conflicts. +State 30 contains 7 shift/reduce conflicts. +State 31 contains 7 shift/reduce conflicts. +State 32 contains 6 shift/reduce conflicts. + + +28 terminals, 5 nonterminals +19 grammar rules, 33 states diff --git a/test/quote_calc2-s.tab.c b/test/quote_calc2-s.tab.c new file mode 100644 index 000000000000..06c574ba9c88 --- /dev/null +++ b/test/quote_calc2-s.tab.c @@ -0,0 +1,687 @@ +#ifndef lint +static const char yysccsid[] = "@(#)yaccpar 1.9 (Berkeley) 02/21/93"; +#endif + +#define YYBYACC 1 +#define YYMAJOR 1 +#define YYMINOR 9 + +#define YYEMPTY (-1) +#define yyclearin (yychar = YYEMPTY) +#define yyerrok (yyerrflag = 0) +#define YYRECOVERING() (yyerrflag != 0) + + +#ifndef yyparse +#define yyparse quote_calc2_parse +#endif /* yyparse */ + +#ifndef yylex +#define yylex quote_calc2_lex +#endif /* yylex */ + +#ifndef yyerror +#define yyerror quote_calc2_error +#endif /* yyerror */ + +#ifndef yychar +#define yychar quote_calc2_char +#endif /* yychar */ + +#ifndef yyval +#define yyval quote_calc2_val +#endif /* yyval */ + +#ifndef yylval +#define yylval quote_calc2_lval +#endif /* yylval */ + +#ifndef yydebug +#define yydebug quote_calc2_debug +#endif /* yydebug */ + +#ifndef yynerrs +#define yynerrs quote_calc2_nerrs +#endif /* yynerrs */ + +#ifndef yyerrflag +#define yyerrflag quote_calc2_errflag +#endif /* yyerrflag */ + +#ifndef yylhs +#define yylhs quote_calc2_lhs +#endif /* yylhs */ + +#ifndef yylen +#define yylen quote_calc2_len +#endif /* yylen */ + +#ifndef yydefred +#define yydefred quote_calc2_defred +#endif /* yydefred */ + +#ifndef yydgoto +#define yydgoto quote_calc2_dgoto +#endif /* yydgoto */ + +#ifndef yysindex +#define yysindex quote_calc2_sindex +#endif /* yysindex */ + +#ifndef yyrindex +#define yyrindex quote_calc2_rindex +#endif /* yyrindex */ + +#ifndef yygindex +#define yygindex quote_calc2_gindex +#endif /* yygindex */ + +#ifndef yytable +#define yytable quote_calc2_table +#endif /* yytable */ + +#ifndef yycheck +#define yycheck quote_calc2_check +#endif /* yycheck */ + +#ifndef yyname +#define yyname quote_calc2_name +#endif /* yyname */ + +#ifndef yyrule +#define yyrule quote_calc2_rule +#endif /* yyrule */ +#define YYPREFIX "quote_calc2_" + +#define YYPURE 0 + +#line 2 "quote_calc2.y" +# include <stdio.h> +# include <ctype.h> + +int regs[26]; +int base; + +int yylex(void); +static void yyerror(const char *s); + +#line 109 "quote_calc2-s.tab.c" + +#ifndef YYSTYPE +typedef int YYSTYPE; +#endif + +/* compatibility with bison */ +#ifdef YYPARSE_PARAM +/* compatibility with FreeBSD */ +# ifdef YYPARSE_PARAM_TYPE +# define YYPARSE_DECL() yyparse(YYPARSE_PARAM_TYPE YYPARSE_PARAM) +# else +# define YYPARSE_DECL() yyparse(void *YYPARSE_PARAM) +# endif +#else +# define YYPARSE_DECL() yyparse(void) +#endif + +/* Parameters sent to lex. */ +#ifdef YYLEX_PARAM +# define YYLEX_DECL() yylex(void *YYLEX_PARAM) +# define YYLEX yylex(YYLEX_PARAM) +#else +# define YYLEX_DECL() yylex(void) +# define YYLEX yylex() +#endif + +/* Parameters sent to yyerror. */ +#ifndef YYERROR_DECL +#define YYERROR_DECL() yyerror(const char *s) +#endif +#ifndef YYERROR_CALL +#define YYERROR_CALL(msg) yyerror(msg) +#endif + +extern int YYPARSE_DECL(); + +#define OP_ADD 257 +#define OP_SUB 259 +#define OP_MUL 261 +#define OP_DIV 263 +#define OP_MOD 265 +#define OP_AND 267 +#define DIGIT 269 +#define LETTER 270 +#define UMINUS 271 +#define YYERRCODE 256 +static const short quote_calc2_lhs[] = { -1, + 0, 0, 0, 1, 1, 2, 2, 2, 2, 2, + 2, 2, 2, 2, 2, 2, 3, 3, +}; +static const short quote_calc2_len[] = { 2, + 0, 3, 3, 1, 3, 3, 3, 3, 3, 3, + 3, 3, 3, 2, 1, 1, 1, 2, +}; +static const short quote_calc2_defred[] = { 1, + 0, 0, 0, 17, 0, 0, 0, 0, 0, 3, + 15, 0, 0, 0, 2, 0, 0, 0, 0, 0, + 0, 0, 18, 0, 6, 0, 0, 0, 0, 0, + 0, 0, +}; +static const short quote_calc2_dgoto[] = { 1, + 7, 8, 9, +}; +static const short quote_calc2_sindex[] = { 0, + -38, 4, -36, 0, -51, -36, 6, -121, -249, 0, + 0, -243, -36, -23, 0, -36, -36, -36, -36, -36, + -36, -36, 0, -121, 0, -121, -121, -121, -121, -121, + -121, -243, +}; +static const short quote_calc2_rindex[] = { 0, + 0, 0, 0, 0, -9, 0, 0, 12, -10, 0, + 0, -5, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 14, 0, -3, -2, -1, 1, 2, + 3, -4, +}; +static const short quote_calc2_gindex[] = { 0, + 0, 42, 0, +}; +#define YYTABLESIZE 259 +static const short quote_calc2_table[] = { 16, + 15, 6, 22, 6, 14, 13, 7, 8, 9, 13, + 10, 11, 12, 10, 16, 15, 17, 25, 18, 23, + 19, 4, 20, 5, 21, 0, 0, 0, 0, 0, + 16, 0, 0, 0, 0, 14, 13, 7, 8, 9, + 0, 10, 11, 12, 12, 0, 0, 14, 0, 0, + 0, 0, 0, 0, 24, 0, 0, 26, 27, 28, + 29, 30, 31, 32, 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, 0, 0, 0, 0, 0, 0, 0, 0, + 22, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 16, 15, 0, 0, 0, 14, 13, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 16, 0, 17, 0, + 18, 0, 19, 0, 20, 0, 21, 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, 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, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 2, 0, 0, + 0, 3, 0, 3, 0, 0, 0, 0, 0, 0, + 4, 5, 4, 11, 16, 0, 17, 0, 18, 0, + 19, 0, 20, 0, 21, 0, 0, 16, 15, 16, + 15, 16, 15, 16, 15, 16, 15, 16, 15, +}; +static const short quote_calc2_check[] = { 10, + 10, 40, 124, 40, 10, 10, 10, 10, 10, 61, + 10, 10, 10, 10, 258, 10, 260, 41, 262, 269, + 264, 10, 266, 10, 268, -1, -1, -1, -1, -1, + 41, -1, -1, -1, -1, 41, 41, 41, 41, 41, + -1, 41, 41, 41, 3, -1, -1, 6, -1, -1, + -1, -1, -1, -1, 13, -1, -1, 16, 17, 18, + 19, 20, 21, 22, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, + 124, -1, -1, -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, 124, 124, -1, -1, -1, 124, 124, + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, 258, -1, 260, -1, + 262, -1, 264, -1, 266, -1, 268, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, 256, -1, -1, + -1, 260, -1, 260, -1, -1, -1, -1, -1, -1, + 269, 270, 269, 270, 258, -1, 260, -1, 262, -1, + 264, -1, 266, -1, 268, -1, -1, 258, 258, 260, + 260, 262, 262, 264, 264, 266, 266, 268, 268, +}; +#define YYFINAL 1 +#ifndef YYDEBUG +#define YYDEBUG 0 +#endif +#define YYMAXTOKEN 271 +#if YYDEBUG +static const char *yyname[] = { + +"end-of-file",0,0,0,0,0,0,0,0,0,"'\\n'",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,"'-'",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,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,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,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,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,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,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,0,0,0,0,0,0, +0,0,0,0,0,0,"OP_ADD","\"ADD\"","OP_SUB","\"SUB\"","OP_MUL","\"MUL\"","OP_DIV", +"\"DIV\"","OP_MOD","\"MOD\"","OP_AND","\"AND\"","DIGIT","LETTER","UMINUS", +}; +static const char *yyrule[] = { +"$accept : list", +"list :", +"list : list stat '\\n'", +"list : list error '\\n'", +"stat : expr", +"stat : LETTER '=' expr", +"expr : '(' expr ')'", +"expr : expr \"ADD\" expr", +"expr : expr \"SUB\" expr", +"expr : expr \"MUL\" expr", +"expr : expr \"DIV\" expr", +"expr : expr \"MOD\" expr", +"expr : expr \"AND\" expr", +"expr : expr '|' expr", +"expr : \"SUB\" expr", +"expr : LETTER", +"expr : number", +"number : DIGIT", +"number : number DIGIT", + +}; +#endif + +int yydebug; +int yynerrs; + +int yyerrflag; +int yychar; +YYSTYPE yyval; +YYSTYPE yylval; + +/* define the initial stack-sizes */ +#ifdef YYSTACKSIZE +#undef YYMAXDEPTH +#define YYMAXDEPTH YYSTACKSIZE +#else +#ifdef YYMAXDEPTH +#define YYSTACKSIZE YYMAXDEPTH +#else +#define YYSTACKSIZE 500 +#define YYMAXDEPTH 500 +#endif +#endif + +#define YYINITSTACKSIZE 500 + +typedef struct { + unsigned stacksize; + short *s_base; + short *s_mark; + short *s_last; + YYSTYPE *l_base; + YYSTYPE *l_mark; +} YYSTACKDATA; +/* variables for the parser stack */ +static YYSTACKDATA yystack; +#line 73 "quote_calc2.y" + /* start of programs */ + +int +main (void) +{ + while(!feof(stdin)) { + yyparse(); + } + return 0; +} + +static void +yyerror(const char *s) +{ + fprintf(stderr, "%s\n", s); +} + +int +yylex(void) { + /* lexical analysis routine */ + /* returns LETTER for a lower case letter, yylval = 0 through 25 */ + /* return DIGIT for a digit, yylval = 0 through 9 */ + /* all other characters are returned immediately */ + + int c; + + while( (c=getchar()) == ' ' ) { /* skip blanks */ } + + /* c is now nonblank */ + + if( islower( c )) { + yylval = c - 'a'; + return ( LETTER ); + } + if( isdigit( c )) { + yylval = c - '0'; + return ( DIGIT ); + } + return( c ); +} +#line 361 "quote_calc2-s.tab.c" + +#if YYDEBUG +#include <stdio.h> /* needed for printf */ +#endif + +#include <stdlib.h> /* needed for malloc, etc */ +#include <string.h> /* needed for memset */ + +/* allocate initial stack or double stack size, up to YYMAXDEPTH */ +static int yygrowstack(YYSTACKDATA *data) +{ + int i; + unsigned newsize; + short *newss; + YYSTYPE *newvs; + + if ((newsize = data->stacksize) == 0) + newsize = YYINITSTACKSIZE; + else if (newsize >= YYMAXDEPTH) + return -1; + else if ((newsize *= 2) > YYMAXDEPTH) + newsize = YYMAXDEPTH; + + i = data->s_mark - data->s_base; + newss = (short *)realloc(data->s_base, newsize * sizeof(*newss)); + if (newss == 0) + return -1; + + data->s_base = newss; + data->s_mark = newss + i; + + newvs = (YYSTYPE *)realloc(data->l_base, newsize * sizeof(*newvs)); + if (newvs == 0) + return -1; + + data->l_base = newvs; + data->l_mark = newvs + i; + + data->stacksize = newsize; + data->s_last = data->s_base + newsize - 1; + return 0; +} + +#if YYPURE || defined(YY_NO_LEAKS) +static void yyfreestack(YYSTACKDATA *data) +{ + free(data->s_base); + free(data->l_base); + memset(data, 0, sizeof(*data)); +} +#else +#define yyfreestack(data) /* nothing */ +#endif + +#define YYABORT goto yyabort +#define YYREJECT goto yyabort +#define YYACCEPT goto yyaccept +#define YYERROR goto yyerrlab + +int +YYPARSE_DECL() +{ + int yym, yyn, yystate; +#if YYDEBUG + const char *yys; + + if ((yys = getenv("YYDEBUG")) != 0) + { + yyn = *yys; + if (yyn >= '0' && yyn <= '9') + yydebug = yyn - '0'; + } +#endif + + yynerrs = 0; + yyerrflag = 0; + yychar = YYEMPTY; + yystate = 0; + +#if YYPURE + memset(&yystack, 0, sizeof(yystack)); +#endif + + if (yystack.s_base == NULL && yygrowstack(&yystack)) goto yyoverflow; + yystack.s_mark = yystack.s_base; + yystack.l_mark = yystack.l_base; + yystate = 0; + *yystack.s_mark = 0; + +yyloop: + if ((yyn = yydefred[yystate]) != 0) goto yyreduce; + if (yychar < 0) + { + if ((yychar = YYLEX) < 0) yychar = 0; +#if YYDEBUG + if (yydebug) + { + yys = 0; + if (yychar <= YYMAXTOKEN) yys = yyname[yychar]; + if (!yys) yys = "illegal-symbol"; + printf("%sdebug: state %d, reading %d (%s)\n", + YYPREFIX, yystate, yychar, yys); + } +#endif + } + if ((yyn = yysindex[yystate]) && (yyn += yychar) >= 0 && + yyn <= YYTABLESIZE && yycheck[yyn] == yychar) + { +#if YYDEBUG + if (yydebug) + printf("%sdebug: state %d, shifting to state %d\n", + YYPREFIX, yystate, yytable[yyn]); +#endif + if (yystack.s_mark >= yystack.s_last && yygrowstack(&yystack)) + { + goto yyoverflow; + } + yystate = yytable[yyn]; + *++yystack.s_mark = yytable[yyn]; + *++yystack.l_mark = yylval; + yychar = YYEMPTY; + if (yyerrflag > 0) --yyerrflag; + goto yyloop; + } + if ((yyn = yyrindex[yystate]) && (yyn += yychar) >= 0 && + yyn <= YYTABLESIZE && yycheck[yyn] == yychar) + { + yyn = yytable[yyn]; + goto yyreduce; + } + if (yyerrflag) goto yyinrecovery; + + yyerror("syntax error"); + + goto yyerrlab; + +yyerrlab: + ++yynerrs; + +yyinrecovery: + if (yyerrflag < 3) + { + yyerrflag = 3; + for (;;) + { + if ((yyn = yysindex[*yystack.s_mark]) && (yyn += YYERRCODE) >= 0 && + yyn <= YYTABLESIZE && yycheck[yyn] == YYERRCODE) + { +#if YYDEBUG + if (yydebug) + printf("%sdebug: state %d, error recovery shifting\ + to state %d\n", YYPREFIX, *yystack.s_mark, yytable[yyn]); +#endif + if (yystack.s_mark >= yystack.s_last && yygrowstack(&yystack)) + { + goto yyoverflow; + } + yystate = yytable[yyn]; + *++yystack.s_mark = yytable[yyn]; + *++yystack.l_mark = yylval; + goto yyloop; + } + else + { +#if YYDEBUG + if (yydebug) + printf("%sdebug: error recovery discarding state %d\n", + YYPREFIX, *yystack.s_mark); +#endif + if (yystack.s_mark <= yystack.s_base) goto yyabort; + --yystack.s_mark; + --yystack.l_mark; + } + } + } + else + { + if (yychar == 0) goto yyabort; +#if YYDEBUG + if (yydebug) + { + yys = 0; + if (yychar <= YYMAXTOKEN) yys = yyname[yychar]; + if (!yys) yys = "illegal-symbol"; + printf("%sdebug: state %d, error recovery discards token %d (%s)\n", + YYPREFIX, yystate, yychar, yys); + } +#endif + yychar = YYEMPTY; + goto yyloop; + } + +yyreduce: +#if YYDEBUG + if (yydebug) + printf("%sdebug: state %d, reducing by rule %d (%s)\n", + YYPREFIX, yystate, yyn, yyrule[yyn]); +#endif + yym = yylen[yyn]; + if (yym) + yyval = yystack.l_mark[1-yym]; + else + memset(&yyval, 0, sizeof yyval); + switch (yyn) + { +case 3: +#line 35 "quote_calc2.y" + { yyerrok ; } +break; +case 4: +#line 39 "quote_calc2.y" + { printf("%d\n",yystack.l_mark[0]);} +break; +case 5: +#line 41 "quote_calc2.y" + { regs[yystack.l_mark[-2]] = yystack.l_mark[0]; } +break; +case 6: +#line 45 "quote_calc2.y" + { yyval = yystack.l_mark[-1]; } +break; +case 7: +#line 47 "quote_calc2.y" + { yyval = yystack.l_mark[-2] + yystack.l_mark[0]; } +break; +case 8: +#line 49 "quote_calc2.y" + { yyval = yystack.l_mark[-2] - yystack.l_mark[0]; } +break; +case 9: +#line 51 "quote_calc2.y" + { yyval = yystack.l_mark[-2] * yystack.l_mark[0]; } +break; +case 10: +#line 53 "quote_calc2.y" + { yyval = yystack.l_mark[-2] / yystack.l_mark[0]; } +break; +case 11: +#line 55 "quote_calc2.y" + { yyval = yystack.l_mark[-2] % yystack.l_mark[0]; } +break; +case 12: +#line 57 "quote_calc2.y" + { yyval = yystack.l_mark[-2] & yystack.l_mark[0]; } +break; +case 13: +#line 59 "quote_calc2.y" + { yyval = yystack.l_mark[-2] | yystack.l_mark[0]; } +break; +case 14: +#line 61 "quote_calc2.y" + { yyval = - yystack.l_mark[0]; } +break; +case 15: +#line 63 "quote_calc2.y" + { yyval = regs[yystack.l_mark[0]]; } +break; +case 17: +#line 68 "quote_calc2.y" + { yyval = yystack.l_mark[0]; base = (yystack.l_mark[0]==0) ? 8 : 10; } +break; +case 18: +#line 70 "quote_calc2.y" + { yyval = base * yystack.l_mark[-1] + yystack.l_mark[0]; } +break; +#line 627 "quote_calc2-s.tab.c" + } + yystack.s_mark -= yym; + yystate = *yystack.s_mark; + yystack.l_mark -= yym; + yym = yylhs[yyn]; + if (yystate == 0 && yym == 0) + { +#if YYDEBUG + if (yydebug) + printf("%sdebug: after reduction, shifting from state 0 to\ + state %d\n", YYPREFIX, YYFINAL); +#endif + yystate = YYFINAL; + *++yystack.s_mark = YYFINAL; + *++yystack.l_mark = yyval; + if (yychar < 0) + { + if ((yychar = YYLEX) < 0) yychar = 0; +#if YYDEBUG + if (yydebug) + { + yys = 0; + if (yychar <= YYMAXTOKEN) yys = yyname[yychar]; + if (!yys) yys = "illegal-symbol"; + printf("%sdebug: state %d, reading %d (%s)\n", + YYPREFIX, YYFINAL, yychar, yys); + } +#endif + } + if (yychar == 0) goto yyaccept; + goto yyloop; + } + if ((yyn = yygindex[yym]) && (yyn += yystate) >= 0 && + yyn <= YYTABLESIZE && yycheck[yyn] == yystate) + yystate = yytable[yyn]; + else + yystate = yydgoto[yym]; +#if YYDEBUG + if (yydebug) + printf("%sdebug: after reduction, shifting from state %d \ +to state %d\n", YYPREFIX, *yystack.s_mark, yystate); +#endif + if (yystack.s_mark >= yystack.s_last && yygrowstack(&yystack)) + { + goto yyoverflow; + } + *++yystack.s_mark = (short) yystate; + *++yystack.l_mark = yyval; + goto yyloop; + +yyoverflow: + yyerror("yacc stack overflow"); + +yyabort: + yyfreestack(&yystack); + return (1); + +yyaccept: + yyfreestack(&yystack); + return (0); +} diff --git a/test/quote_calc2-s.tab.h b/test/quote_calc2-s.tab.h new file mode 100644 index 000000000000..1a4657903411 --- /dev/null +++ b/test/quote_calc2-s.tab.h @@ -0,0 +1,9 @@ +#define OP_ADD 257 +#define OP_SUB 259 +#define OP_MUL 261 +#define OP_DIV 263 +#define OP_MOD 265 +#define OP_AND 267 +#define DIGIT 269 +#define LETTER 270 +#define UMINUS 271 diff --git a/test/quote_calc2.output b/test/quote_calc2.output new file mode 100644 index 000000000000..ed28ae2f21c0 --- /dev/null +++ b/test/quote_calc2.output @@ -0,0 +1,557 @@ + 0 $accept : list $end + + 1 list : + 2 | list stat '\n' + 3 | list error '\n' + + 4 stat : expr + 5 | LETTER '=' expr + + 6 expr : '(' expr ')' + 7 | expr "ADD" expr + 8 | expr "SUB" expr + 9 | expr "MUL" expr + 10 | expr "DIV" expr + 11 | expr "MOD" expr + 12 | expr "AND" expr + 13 | expr '|' expr + 14 | "SUB" expr + 15 | LETTER + 16 | number + + 17 number : DIGIT + 18 | number DIGIT + +state 0 + $accept : . list $end (0) + list : . (1) + + . reduce 1 + + list goto 1 + + +state 1 + $accept : list . $end (0) + list : list . stat '\n' (2) + list : list . error '\n' (3) + + $end accept + error shift 2 + "SUB" shift 3 + DIGIT shift 4 + LETTER shift 5 + '(' shift 6 + . error + + stat goto 7 + expr goto 8 + number goto 9 + + +state 2 + list : list error . '\n' (3) + + '\n' shift 10 + . error + + +state 3 + expr : "SUB" . expr (14) + + "SUB" shift 3 + DIGIT shift 4 + LETTER shift 11 + '(' shift 6 + . error + + expr goto 12 + number goto 9 + + +state 4 + number : DIGIT . (17) + + . reduce 17 + + +state 5 + stat : LETTER . '=' expr (5) + expr : LETTER . (15) + + '=' shift 13 + "ADD" reduce 15 + "SUB" reduce 15 + "MUL" reduce 15 + "DIV" reduce 15 + "MOD" reduce 15 + "AND" reduce 15 + '|' reduce 15 + '\n' reduce 15 + + +state 6 + expr : '(' . expr ')' (6) + + "SUB" shift 3 + DIGIT shift 4 + LETTER shift 11 + '(' shift 6 + . error + + expr goto 14 + number goto 9 + + +state 7 + list : list stat . '\n' (2) + + '\n' shift 15 + . error + + +state 8 + stat : expr . (4) + expr : expr . "ADD" expr (7) + expr : expr . "SUB" expr (8) + expr : expr . "MUL" expr (9) + expr : expr . "DIV" expr (10) + expr : expr . "MOD" expr (11) + expr : expr . "AND" expr (12) + expr : expr . '|' expr (13) + + "ADD" shift 16 + "SUB" shift 17 + "MUL" shift 18 + "DIV" shift 19 + "MOD" shift 20 + "AND" shift 21 + '|' shift 22 + '\n' reduce 4 + + +state 9 + expr : number . (16) + number : number . DIGIT (18) + + DIGIT shift 23 + "ADD" reduce 16 + "SUB" reduce 16 + "MUL" reduce 16 + "DIV" reduce 16 + "MOD" reduce 16 + "AND" reduce 16 + '|' reduce 16 + '\n' reduce 16 + ')' reduce 16 + + +state 10 + list : list error '\n' . (3) + + . reduce 3 + + +state 11 + expr : LETTER . (15) + + . reduce 15 + + +12: shift/reduce conflict (shift 16, reduce 14) on "ADD" +12: shift/reduce conflict (shift 17, reduce 14) on "SUB" +12: shift/reduce conflict (shift 18, reduce 14) on "MUL" +12: shift/reduce conflict (shift 19, reduce 14) on "DIV" +12: shift/reduce conflict (shift 20, reduce 14) on "MOD" +12: shift/reduce conflict (shift 21, reduce 14) on "AND" +state 12 + expr : expr . "ADD" expr (7) + expr : expr . "SUB" expr (8) + expr : expr . "MUL" expr (9) + expr : expr . "DIV" expr (10) + expr : expr . "MOD" expr (11) + expr : expr . "AND" expr (12) + expr : expr . '|' expr (13) + expr : "SUB" expr . (14) + + "ADD" shift 16 + "SUB" shift 17 + "MUL" shift 18 + "DIV" shift 19 + "MOD" shift 20 + "AND" shift 21 + '|' reduce 14 + '\n' reduce 14 + ')' reduce 14 + + +state 13 + stat : LETTER '=' . expr (5) + + "SUB" shift 3 + DIGIT shift 4 + LETTER shift 11 + '(' shift 6 + . error + + expr goto 24 + number goto 9 + + +state 14 + expr : '(' expr . ')' (6) + expr : expr . "ADD" expr (7) + expr : expr . "SUB" expr (8) + expr : expr . "MUL" expr (9) + expr : expr . "DIV" expr (10) + expr : expr . "MOD" expr (11) + expr : expr . "AND" expr (12) + expr : expr . '|' expr (13) + + "ADD" shift 16 + "SUB" shift 17 + "MUL" shift 18 + "DIV" shift 19 + "MOD" shift 20 + "AND" shift 21 + '|' shift 22 + ')' shift 25 + . error + + +state 15 + list : list stat '\n' . (2) + + . reduce 2 + + +state 16 + expr : expr "ADD" . expr (7) + + "SUB" shift 3 + DIGIT shift 4 + LETTER shift 11 + '(' shift 6 + . error + + expr goto 26 + number goto 9 + + +state 17 + expr : expr "SUB" . expr (8) + + "SUB" shift 3 + DIGIT shift 4 + LETTER shift 11 + '(' shift 6 + . error + + expr goto 27 + number goto 9 + + +state 18 + expr : expr "MUL" . expr (9) + + "SUB" shift 3 + DIGIT shift 4 + LETTER shift 11 + '(' shift 6 + . error + + expr goto 28 + number goto 9 + + +state 19 + expr : expr "DIV" . expr (10) + + "SUB" shift 3 + DIGIT shift 4 + LETTER shift 11 + '(' shift 6 + . error + + expr goto 29 + number goto 9 + + +state 20 + expr : expr "MOD" . expr (11) + + "SUB" shift 3 + DIGIT shift 4 + LETTER shift 11 + '(' shift 6 + . error + + expr goto 30 + number goto 9 + + +state 21 + expr : expr "AND" . expr (12) + + "SUB" shift 3 + DIGIT shift 4 + LETTER shift 11 + '(' shift 6 + . error + + expr goto 31 + number goto 9 + + +state 22 + expr : expr '|' . expr (13) + + "SUB" shift 3 + DIGIT shift 4 + LETTER shift 11 + '(' shift 6 + . error + + expr goto 32 + number goto 9 + + +state 23 + number : number DIGIT . (18) + + . reduce 18 + + +state 24 + stat : LETTER '=' expr . (5) + expr : expr . "ADD" expr (7) + expr : expr . "SUB" expr (8) + expr : expr . "MUL" expr (9) + expr : expr . "DIV" expr (10) + expr : expr . "MOD" expr (11) + expr : expr . "AND" expr (12) + expr : expr . '|' expr (13) + + "ADD" shift 16 + "SUB" shift 17 + "MUL" shift 18 + "DIV" shift 19 + "MOD" shift 20 + "AND" shift 21 + '|' shift 22 + '\n' reduce 5 + + +state 25 + expr : '(' expr ')' . (6) + + . reduce 6 + + +26: shift/reduce conflict (shift 16, reduce 7) on "ADD" +26: shift/reduce conflict (shift 17, reduce 7) on "SUB" +26: shift/reduce conflict (shift 18, reduce 7) on "MUL" +26: shift/reduce conflict (shift 19, reduce 7) on "DIV" +26: shift/reduce conflict (shift 20, reduce 7) on "MOD" +26: shift/reduce conflict (shift 21, reduce 7) on "AND" +26: shift/reduce conflict (shift 22, reduce 7) on '|' +state 26 + expr : expr . "ADD" expr (7) + expr : expr "ADD" expr . (7) + expr : expr . "SUB" expr (8) + expr : expr . "MUL" expr (9) + expr : expr . "DIV" expr (10) + expr : expr . "MOD" expr (11) + expr : expr . "AND" expr (12) + expr : expr . '|' expr (13) + + "ADD" shift 16 + "SUB" shift 17 + "MUL" shift 18 + "DIV" shift 19 + "MOD" shift 20 + "AND" shift 21 + '|' shift 22 + '\n' reduce 7 + ')' reduce 7 + + +27: shift/reduce conflict (shift 16, reduce 8) on "ADD" +27: shift/reduce conflict (shift 17, reduce 8) on "SUB" +27: shift/reduce conflict (shift 18, reduce 8) on "MUL" +27: shift/reduce conflict (shift 19, reduce 8) on "DIV" +27: shift/reduce conflict (shift 20, reduce 8) on "MOD" +27: shift/reduce conflict (shift 21, reduce 8) on "AND" +27: shift/reduce conflict (shift 22, reduce 8) on '|' +state 27 + expr : expr . "ADD" expr (7) + expr : expr . "SUB" expr (8) + expr : expr "SUB" expr . (8) + expr : expr . "MUL" expr (9) + expr : expr . "DIV" expr (10) + expr : expr . "MOD" expr (11) + expr : expr . "AND" expr (12) + expr : expr . '|' expr (13) + + "ADD" shift 16 + "SUB" shift 17 + "MUL" shift 18 + "DIV" shift 19 + "MOD" shift 20 + "AND" shift 21 + '|' shift 22 + '\n' reduce 8 + ')' reduce 8 + + +28: shift/reduce conflict (shift 16, reduce 9) on "ADD" +28: shift/reduce conflict (shift 17, reduce 9) on "SUB" +28: shift/reduce conflict (shift 18, reduce 9) on "MUL" +28: shift/reduce conflict (shift 19, reduce 9) on "DIV" +28: shift/reduce conflict (shift 20, reduce 9) on "MOD" +28: shift/reduce conflict (shift 21, reduce 9) on "AND" +28: shift/reduce conflict (shift 22, reduce 9) on '|' +state 28 + expr : expr . "ADD" expr (7) + expr : expr . "SUB" expr (8) + expr : expr . "MUL" expr (9) + expr : expr "MUL" expr . (9) + expr : expr . "DIV" expr (10) + expr : expr . "MOD" expr (11) + expr : expr . "AND" expr (12) + expr : expr . '|' expr (13) + + "ADD" shift 16 + "SUB" shift 17 + "MUL" shift 18 + "DIV" shift 19 + "MOD" shift 20 + "AND" shift 21 + '|' shift 22 + '\n' reduce 9 + ')' reduce 9 + + +29: shift/reduce conflict (shift 16, reduce 10) on "ADD" +29: shift/reduce conflict (shift 17, reduce 10) on "SUB" +29: shift/reduce conflict (shift 18, reduce 10) on "MUL" +29: shift/reduce conflict (shift 19, reduce 10) on "DIV" +29: shift/reduce conflict (shift 20, reduce 10) on "MOD" +29: shift/reduce conflict (shift 21, reduce 10) on "AND" +29: shift/reduce conflict (shift 22, reduce 10) on '|' +state 29 + expr : expr . "ADD" expr (7) + expr : expr . "SUB" expr (8) + expr : expr . "MUL" expr (9) + expr : expr . "DIV" expr (10) + expr : expr "DIV" expr . (10) + expr : expr . "MOD" expr (11) + expr : expr . "AND" expr (12) + expr : expr . '|' expr (13) + + "ADD" shift 16 + "SUB" shift 17 + "MUL" shift 18 + "DIV" shift 19 + "MOD" shift 20 + "AND" shift 21 + '|' shift 22 + '\n' reduce 10 + ')' reduce 10 + + +30: shift/reduce conflict (shift 16, reduce 11) on "ADD" +30: shift/reduce conflict (shift 17, reduce 11) on "SUB" +30: shift/reduce conflict (shift 18, reduce 11) on "MUL" +30: shift/reduce conflict (shift 19, reduce 11) on "DIV" +30: shift/reduce conflict (shift 20, reduce 11) on "MOD" +30: shift/reduce conflict (shift 21, reduce 11) on "AND" +30: shift/reduce conflict (shift 22, reduce 11) on '|' +state 30 + expr : expr . "ADD" expr (7) + expr : expr . "SUB" expr (8) + expr : expr . "MUL" expr (9) + expr : expr . "DIV" expr (10) + expr : expr . "MOD" expr (11) + expr : expr "MOD" expr . (11) + expr : expr . "AND" expr (12) + expr : expr . '|' expr (13) + + "ADD" shift 16 + "SUB" shift 17 + "MUL" shift 18 + "DIV" shift 19 + "MOD" shift 20 + "AND" shift 21 + '|' shift 22 + '\n' reduce 11 + ')' reduce 11 + + +31: shift/reduce conflict (shift 16, reduce 12) on "ADD" +31: shift/reduce conflict (shift 17, reduce 12) on "SUB" +31: shift/reduce conflict (shift 18, reduce 12) on "MUL" +31: shift/reduce conflict (shift 19, reduce 12) on "DIV" +31: shift/reduce conflict (shift 20, reduce 12) on "MOD" +31: shift/reduce conflict (shift 21, reduce 12) on "AND" +31: shift/reduce conflict (shift 22, reduce 12) on '|' +state 31 + expr : expr . "ADD" expr (7) + expr : expr . "SUB" expr (8) + expr : expr . "MUL" expr (9) + expr : expr . "DIV" expr (10) + expr : expr . "MOD" expr (11) + expr : expr . "AND" expr (12) + expr : expr "AND" expr . (12) + expr : expr . '|' expr (13) + + "ADD" shift 16 + "SUB" shift 17 + "MUL" shift 18 + "DIV" shift 19 + "MOD" shift 20 + "AND" shift 21 + '|' shift 22 + '\n' reduce 12 + ')' reduce 12 + + +32: shift/reduce conflict (shift 16, reduce 13) on "ADD" +32: shift/reduce conflict (shift 17, reduce 13) on "SUB" +32: shift/reduce conflict (shift 18, reduce 13) on "MUL" +32: shift/reduce conflict (shift 19, reduce 13) on "DIV" +32: shift/reduce conflict (shift 20, reduce 13) on "MOD" +32: shift/reduce conflict (shift 21, reduce 13) on "AND" +state 32 + expr : expr . "ADD" expr (7) + expr : expr . "SUB" expr (8) + expr : expr . "MUL" expr (9) + expr : expr . "DIV" expr (10) + expr : expr . "MOD" expr (11) + expr : expr . "AND" expr (12) + expr : expr . '|' expr (13) + expr : expr '|' expr . (13) + + "ADD" shift 16 + "SUB" shift 17 + "MUL" shift 18 + "DIV" shift 19 + "MOD" shift 20 + "AND" shift 21 + '|' reduce 13 + '\n' reduce 13 + ')' reduce 13 + + +State 12 contains 6 shift/reduce conflicts. +State 26 contains 7 shift/reduce conflicts. +State 27 contains 7 shift/reduce conflicts. +State 28 contains 7 shift/reduce conflicts. +State 29 contains 7 shift/reduce conflicts. +State 30 contains 7 shift/reduce conflicts. +State 31 contains 7 shift/reduce conflicts. +State 32 contains 6 shift/reduce conflicts. + + +28 terminals, 5 nonterminals +19 grammar rules, 33 states diff --git a/test/quote_calc2.tab.c b/test/quote_calc2.tab.c new file mode 100644 index 000000000000..958a736fb23a --- /dev/null +++ b/test/quote_calc2.tab.c @@ -0,0 +1,693 @@ +#ifndef lint +static const char yysccsid[] = "@(#)yaccpar 1.9 (Berkeley) 02/21/93"; +#endif + +#define YYBYACC 1 +#define YYMAJOR 1 +#define YYMINOR 9 + +#define YYEMPTY (-1) +#define yyclearin (yychar = YYEMPTY) +#define yyerrok (yyerrflag = 0) +#define YYRECOVERING() (yyerrflag != 0) + + +#ifndef yyparse +#define yyparse quote_calc2_parse +#endif /* yyparse */ + +#ifndef yylex +#define yylex quote_calc2_lex +#endif /* yylex */ + +#ifndef yyerror +#define yyerror quote_calc2_error +#endif /* yyerror */ + +#ifndef yychar +#define yychar quote_calc2_char +#endif /* yychar */ + +#ifndef yyval +#define yyval quote_calc2_val +#endif /* yyval */ + +#ifndef yylval +#define yylval quote_calc2_lval +#endif /* yylval */ + +#ifndef yydebug +#define yydebug quote_calc2_debug +#endif /* yydebug */ + +#ifndef yynerrs +#define yynerrs quote_calc2_nerrs +#endif /* yynerrs */ + +#ifndef yyerrflag +#define yyerrflag quote_calc2_errflag +#endif /* yyerrflag */ + +#ifndef yylhs +#define yylhs quote_calc2_lhs +#endif /* yylhs */ + +#ifndef yylen +#define yylen quote_calc2_len +#endif /* yylen */ + +#ifndef yydefred +#define yydefred quote_calc2_defred +#endif /* yydefred */ + +#ifndef yydgoto +#define yydgoto quote_calc2_dgoto +#endif /* yydgoto */ + +#ifndef yysindex +#define yysindex quote_calc2_sindex +#endif /* yysindex */ + +#ifndef yyrindex +#define yyrindex quote_calc2_rindex +#endif /* yyrindex */ + +#ifndef yygindex +#define yygindex quote_calc2_gindex +#endif /* yygindex */ + +#ifndef yytable +#define yytable quote_calc2_table +#endif /* yytable */ + +#ifndef yycheck +#define yycheck quote_calc2_check +#endif /* yycheck */ + +#ifndef yyname +#define yyname quote_calc2_name +#endif /* yyname */ + +#ifndef yyrule +#define yyrule quote_calc2_rule +#endif /* yyrule */ +#define YYPREFIX "quote_calc2_" + +#define YYPURE 0 + +#line 2 "quote_calc2.y" +# include <stdio.h> +# include <ctype.h> + +int regs[26]; +int base; + +int yylex(void); +static void yyerror(const char *s); + +#line 109 "quote_calc2.tab.c" + +#ifndef YYSTYPE +typedef int YYSTYPE; +#endif + +/* compatibility with bison */ +#ifdef YYPARSE_PARAM +/* compatibility with FreeBSD */ +# ifdef YYPARSE_PARAM_TYPE +# define YYPARSE_DECL() yyparse(YYPARSE_PARAM_TYPE YYPARSE_PARAM) +# else +# define YYPARSE_DECL() yyparse(void *YYPARSE_PARAM) +# endif +#else +# define YYPARSE_DECL() yyparse(void) +#endif + +/* Parameters sent to lex. */ +#ifdef YYLEX_PARAM +# define YYLEX_DECL() yylex(void *YYLEX_PARAM) +# define YYLEX yylex(YYLEX_PARAM) +#else +# define YYLEX_DECL() yylex(void) +# define YYLEX yylex() +#endif + +/* Parameters sent to yyerror. */ +#ifndef YYERROR_DECL +#define YYERROR_DECL() yyerror(const char *s) +#endif +#ifndef YYERROR_CALL +#define YYERROR_CALL(msg) yyerror(msg) +#endif + +extern int YYPARSE_DECL(); + +#define OP_ADD 257 +#define ADD 258 +#define OP_SUB 259 +#define SUB 260 +#define OP_MUL 261 +#define MUL 262 +#define OP_DIV 263 +#define DIV 264 +#define OP_MOD 265 +#define MOD 266 +#define OP_AND 267 +#define AND 268 +#define DIGIT 269 +#define LETTER 270 +#define UMINUS 271 +#define YYERRCODE 256 +static const short quote_calc2_lhs[] = { -1, + 0, 0, 0, 1, 1, 2, 2, 2, 2, 2, + 2, 2, 2, 2, 2, 2, 3, 3, +}; +static const short quote_calc2_len[] = { 2, + 0, 3, 3, 1, 3, 3, 3, 3, 3, 3, + 3, 3, 3, 2, 1, 1, 1, 2, +}; +static const short quote_calc2_defred[] = { 1, + 0, 0, 0, 17, 0, 0, 0, 0, 0, 3, + 15, 0, 0, 0, 2, 0, 0, 0, 0, 0, + 0, 0, 18, 0, 6, 0, 0, 0, 0, 0, + 0, 0, +}; +static const short quote_calc2_dgoto[] = { 1, + 7, 8, 9, +}; +static const short quote_calc2_sindex[] = { 0, + -38, 4, -36, 0, -51, -36, 6, -121, -249, 0, + 0, -243, -36, -23, 0, -36, -36, -36, -36, -36, + -36, -36, 0, -121, 0, -121, -121, -121, -121, -121, + -121, -243, +}; +static const short quote_calc2_rindex[] = { 0, + 0, 0, 0, 0, -9, 0, 0, 12, -10, 0, + 0, -5, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 14, 0, -3, -2, -1, 1, 2, + 3, -4, +}; +static const short quote_calc2_gindex[] = { 0, + 0, 42, 0, +}; +#define YYTABLESIZE 259 +static const short quote_calc2_table[] = { 16, + 15, 6, 22, 6, 14, 13, 7, 8, 9, 13, + 10, 11, 12, 10, 16, 15, 17, 25, 18, 23, + 19, 4, 20, 5, 21, 0, 0, 0, 0, 0, + 16, 0, 0, 0, 0, 14, 13, 7, 8, 9, + 0, 10, 11, 12, 12, 0, 0, 14, 0, 0, + 0, 0, 0, 0, 24, 0, 0, 26, 27, 28, + 29, 30, 31, 32, 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, 0, 0, 0, 0, 0, 0, 0, 0, + 22, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 16, 15, 0, 0, 0, 14, 13, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 16, 0, 17, 0, + 18, 0, 19, 0, 20, 0, 21, 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, 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, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 2, 0, 0, + 0, 3, 0, 3, 0, 0, 0, 0, 0, 0, + 4, 5, 4, 11, 16, 0, 17, 0, 18, 0, + 19, 0, 20, 0, 21, 0, 0, 16, 15, 16, + 15, 16, 15, 16, 15, 16, 15, 16, 15, +}; +static const short quote_calc2_check[] = { 10, + 10, 40, 124, 40, 10, 10, 10, 10, 10, 61, + 10, 10, 10, 10, 258, 10, 260, 41, 262, 269, + 264, 10, 266, 10, 268, -1, -1, -1, -1, -1, + 41, -1, -1, -1, -1, 41, 41, 41, 41, 41, + -1, 41, 41, 41, 3, -1, -1, 6, -1, -1, + -1, -1, -1, -1, 13, -1, -1, 16, 17, 18, + 19, 20, 21, 22, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, + 124, -1, -1, -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, 124, 124, -1, -1, -1, 124, 124, + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, 258, -1, 260, -1, + 262, -1, 264, -1, 266, -1, 268, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, 256, -1, -1, + -1, 260, -1, 260, -1, -1, -1, -1, -1, -1, + 269, 270, 269, 270, 258, -1, 260, -1, 262, -1, + 264, -1, 266, -1, 268, -1, -1, 258, 258, 260, + 260, 262, 262, 264, 264, 266, 266, 268, 268, +}; +#define YYFINAL 1 +#ifndef YYDEBUG +#define YYDEBUG 0 +#endif +#define YYMAXTOKEN 271 +#if YYDEBUG +static const char *yyname[] = { + +"end-of-file",0,0,0,0,0,0,0,0,0,"'\\n'",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,"'-'",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,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,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,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,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,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,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,0,0,0,0,0,0, +0,0,0,0,0,0,"OP_ADD","\"ADD\"","OP_SUB","\"SUB\"","OP_MUL","\"MUL\"","OP_DIV", +"\"DIV\"","OP_MOD","\"MOD\"","OP_AND","\"AND\"","DIGIT","LETTER","UMINUS", +}; +static const char *yyrule[] = { +"$accept : list", +"list :", +"list : list stat '\\n'", +"list : list error '\\n'", +"stat : expr", +"stat : LETTER '=' expr", +"expr : '(' expr ')'", +"expr : expr \"ADD\" expr", +"expr : expr \"SUB\" expr", +"expr : expr \"MUL\" expr", +"expr : expr \"DIV\" expr", +"expr : expr \"MOD\" expr", +"expr : expr \"AND\" expr", +"expr : expr '|' expr", +"expr : \"SUB\" expr", +"expr : LETTER", +"expr : number", +"number : DIGIT", +"number : number DIGIT", + +}; +#endif + +int yydebug; +int yynerrs; + +int yyerrflag; +int yychar; +YYSTYPE yyval; +YYSTYPE yylval; + +/* define the initial stack-sizes */ +#ifdef YYSTACKSIZE +#undef YYMAXDEPTH +#define YYMAXDEPTH YYSTACKSIZE +#else +#ifdef YYMAXDEPTH +#define YYSTACKSIZE YYMAXDEPTH +#else +#define YYSTACKSIZE 500 +#define YYMAXDEPTH 500 +#endif +#endif + +#define YYINITSTACKSIZE 500 + +typedef struct { + unsigned stacksize; + short *s_base; + short *s_mark; + short *s_last; + YYSTYPE *l_base; + YYSTYPE *l_mark; +} YYSTACKDATA; +/* variables for the parser stack */ +static YYSTACKDATA yystack; +#line 73 "quote_calc2.y" + /* start of programs */ + +int +main (void) +{ + while(!feof(stdin)) { + yyparse(); + } + return 0; +} + +static void +yyerror(const char *s) +{ + fprintf(stderr, "%s\n", s); +} + +int +yylex(void) { + /* lexical analysis routine */ + /* returns LETTER for a lower case letter, yylval = 0 through 25 */ + /* return DIGIT for a digit, yylval = 0 through 9 */ + /* all other characters are returned immediately */ + + int c; + + while( (c=getchar()) == ' ' ) { /* skip blanks */ } + + /* c is now nonblank */ + + if( islower( c )) { + yylval = c - 'a'; + return ( LETTER ); + } + if( isdigit( c )) { + yylval = c - '0'; + return ( DIGIT ); + } + return( c ); +} +#line 367 "quote_calc2.tab.c" + +#if YYDEBUG +#include <stdio.h> /* needed for printf */ +#endif + +#include <stdlib.h> /* needed for malloc, etc */ +#include <string.h> /* needed for memset */ + +/* allocate initial stack or double stack size, up to YYMAXDEPTH */ +static int yygrowstack(YYSTACKDATA *data) +{ + int i; + unsigned newsize; + short *newss; + YYSTYPE *newvs; + + if ((newsize = data->stacksize) == 0) + newsize = YYINITSTACKSIZE; + else if (newsize >= YYMAXDEPTH) + return -1; + else if ((newsize *= 2) > YYMAXDEPTH) + newsize = YYMAXDEPTH; + + i = data->s_mark - data->s_base; + newss = (short *)realloc(data->s_base, newsize * sizeof(*newss)); + if (newss == 0) + return -1; + + data->s_base = newss; + data->s_mark = newss + i; + + newvs = (YYSTYPE *)realloc(data->l_base, newsize * sizeof(*newvs)); + if (newvs == 0) + return -1; + + data->l_base = newvs; + data->l_mark = newvs + i; + + data->stacksize = newsize; + data->s_last = data->s_base + newsize - 1; + return 0; +} + +#if YYPURE || defined(YY_NO_LEAKS) +static void yyfreestack(YYSTACKDATA *data) +{ + free(data->s_base); + free(data->l_base); + memset(data, 0, sizeof(*data)); +} +#else +#define yyfreestack(data) /* nothing */ +#endif + +#define YYABORT goto yyabort +#define YYREJECT goto yyabort +#define YYACCEPT goto yyaccept +#define YYERROR goto yyerrlab + +int +YYPARSE_DECL() +{ + int yym, yyn, yystate; +#if YYDEBUG + const char *yys; + + if ((yys = getenv("YYDEBUG")) != 0) + { + yyn = *yys; + if (yyn >= '0' && yyn <= '9') + yydebug = yyn - '0'; + } +#endif + + yynerrs = 0; + yyerrflag = 0; + yychar = YYEMPTY; + yystate = 0; + +#if YYPURE + memset(&yystack, 0, sizeof(yystack)); +#endif + + if (yystack.s_base == NULL && yygrowstack(&yystack)) goto yyoverflow; + yystack.s_mark = yystack.s_base; + yystack.l_mark = yystack.l_base; + yystate = 0; + *yystack.s_mark = 0; + +yyloop: + if ((yyn = yydefred[yystate]) != 0) goto yyreduce; + if (yychar < 0) + { + if ((yychar = YYLEX) < 0) yychar = 0; +#if YYDEBUG + if (yydebug) + { + yys = 0; + if (yychar <= YYMAXTOKEN) yys = yyname[yychar]; + if (!yys) yys = "illegal-symbol"; + printf("%sdebug: state %d, reading %d (%s)\n", + YYPREFIX, yystate, yychar, yys); + } +#endif + } + if ((yyn = yysindex[yystate]) && (yyn += yychar) >= 0 && + yyn <= YYTABLESIZE && yycheck[yyn] == yychar) + { +#if YYDEBUG + if (yydebug) + printf("%sdebug: state %d, shifting to state %d\n", + YYPREFIX, yystate, yytable[yyn]); +#endif + if (yystack.s_mark >= yystack.s_last && yygrowstack(&yystack)) + { + goto yyoverflow; + } + yystate = yytable[yyn]; + *++yystack.s_mark = yytable[yyn]; + *++yystack.l_mark = yylval; + yychar = YYEMPTY; + if (yyerrflag > 0) --yyerrflag; + goto yyloop; + } + if ((yyn = yyrindex[yystate]) && (yyn += yychar) >= 0 && + yyn <= YYTABLESIZE && yycheck[yyn] == yychar) + { + yyn = yytable[yyn]; + goto yyreduce; + } + if (yyerrflag) goto yyinrecovery; + + yyerror("syntax error"); + + goto yyerrlab; + +yyerrlab: + ++yynerrs; + +yyinrecovery: + if (yyerrflag < 3) + { + yyerrflag = 3; + for (;;) + { + if ((yyn = yysindex[*yystack.s_mark]) && (yyn += YYERRCODE) >= 0 && + yyn <= YYTABLESIZE && yycheck[yyn] == YYERRCODE) + { +#if YYDEBUG + if (yydebug) + printf("%sdebug: state %d, error recovery shifting\ + to state %d\n", YYPREFIX, *yystack.s_mark, yytable[yyn]); +#endif + if (yystack.s_mark >= yystack.s_last && yygrowstack(&yystack)) + { + goto yyoverflow; + } + yystate = yytable[yyn]; + *++yystack.s_mark = yytable[yyn]; + *++yystack.l_mark = yylval; + goto yyloop; + } + else + { +#if YYDEBUG + if (yydebug) + printf("%sdebug: error recovery discarding state %d\n", + YYPREFIX, *yystack.s_mark); +#endif + if (yystack.s_mark <= yystack.s_base) goto yyabort; + --yystack.s_mark; + --yystack.l_mark; + } + } + } + else + { + if (yychar == 0) goto yyabort; +#if YYDEBUG + if (yydebug) + { + yys = 0; + if (yychar <= YYMAXTOKEN) yys = yyname[yychar]; + if (!yys) yys = "illegal-symbol"; + printf("%sdebug: state %d, error recovery discards token %d (%s)\n", + YYPREFIX, yystate, yychar, yys); + } +#endif + yychar = YYEMPTY; + goto yyloop; + } + +yyreduce: +#if YYDEBUG + if (yydebug) + printf("%sdebug: state %d, reducing by rule %d (%s)\n", + YYPREFIX, yystate, yyn, yyrule[yyn]); +#endif + yym = yylen[yyn]; + if (yym) + yyval = yystack.l_mark[1-yym]; + else + memset(&yyval, 0, sizeof yyval); + switch (yyn) + { +case 3: +#line 35 "quote_calc2.y" + { yyerrok ; } +break; +case 4: +#line 39 "quote_calc2.y" + { printf("%d\n",yystack.l_mark[0]);} +break; +case 5: +#line 41 "quote_calc2.y" + { regs[yystack.l_mark[-2]] = yystack.l_mark[0]; } +break; +case 6: +#line 45 "quote_calc2.y" + { yyval = yystack.l_mark[-1]; } +break; +case 7: +#line 47 "quote_calc2.y" + { yyval = yystack.l_mark[-2] + yystack.l_mark[0]; } +break; +case 8: +#line 49 "quote_calc2.y" + { yyval = yystack.l_mark[-2] - yystack.l_mark[0]; } +break; +case 9: +#line 51 "quote_calc2.y" + { yyval = yystack.l_mark[-2] * yystack.l_mark[0]; } +break; +case 10: +#line 53 "quote_calc2.y" + { yyval = yystack.l_mark[-2] / yystack.l_mark[0]; } +break; +case 11: +#line 55 "quote_calc2.y" + { yyval = yystack.l_mark[-2] % yystack.l_mark[0]; } +break; +case 12: +#line 57 "quote_calc2.y" + { yyval = yystack.l_mark[-2] & yystack.l_mark[0]; } +break; +case 13: +#line 59 "quote_calc2.y" + { yyval = yystack.l_mark[-2] | yystack.l_mark[0]; } +break; +case 14: +#line 61 "quote_calc2.y" + { yyval = - yystack.l_mark[0]; } +break; +case 15: +#line 63 "quote_calc2.y" + { yyval = regs[yystack.l_mark[0]]; } +break; +case 17: +#line 68 "quote_calc2.y" + { yyval = yystack.l_mark[0]; base = (yystack.l_mark[0]==0) ? 8 : 10; } +break; +case 18: +#line 70 "quote_calc2.y" + { yyval = base * yystack.l_mark[-1] + yystack.l_mark[0]; } +break; +#line 633 "quote_calc2.tab.c" + } + yystack.s_mark -= yym; + yystate = *yystack.s_mark; + yystack.l_mark -= yym; + yym = yylhs[yyn]; + if (yystate == 0 && yym == 0) + { +#if YYDEBUG + if (yydebug) + printf("%sdebug: after reduction, shifting from state 0 to\ + state %d\n", YYPREFIX, YYFINAL); +#endif + yystate = YYFINAL; + *++yystack.s_mark = YYFINAL; + *++yystack.l_mark = yyval; + if (yychar < 0) + { + if ((yychar = YYLEX) < 0) yychar = 0; +#if YYDEBUG + if (yydebug) + { + yys = 0; + if (yychar <= YYMAXTOKEN) yys = yyname[yychar]; + if (!yys) yys = "illegal-symbol"; + printf("%sdebug: state %d, reading %d (%s)\n", + YYPREFIX, YYFINAL, yychar, yys); + } +#endif + } + if (yychar == 0) goto yyaccept; + goto yyloop; + } + if ((yyn = yygindex[yym]) && (yyn += yystate) >= 0 && + yyn <= YYTABLESIZE && yycheck[yyn] == yystate) + yystate = yytable[yyn]; + else + yystate = yydgoto[yym]; +#if YYDEBUG + if (yydebug) + printf("%sdebug: after reduction, shifting from state %d \ +to state %d\n", YYPREFIX, *yystack.s_mark, yystate); +#endif + if (yystack.s_mark >= yystack.s_last && yygrowstack(&yystack)) + { + goto yyoverflow; + } + *++yystack.s_mark = (short) yystate; + *++yystack.l_mark = yyval; + goto yyloop; + +yyoverflow: + yyerror("yacc stack overflow"); + +yyabort: + yyfreestack(&yystack); + return (1); + +yyaccept: + yyfreestack(&yystack); + return (0); +} diff --git a/test/quote_calc2.tab.h b/test/quote_calc2.tab.h new file mode 100644 index 000000000000..498eff210dbe --- /dev/null +++ b/test/quote_calc2.tab.h @@ -0,0 +1,15 @@ +#define OP_ADD 257 +#define ADD 258 +#define OP_SUB 259 +#define SUB 260 +#define OP_MUL 261 +#define MUL 262 +#define OP_DIV 263 +#define DIV 264 +#define OP_MOD 265 +#define MOD 266 +#define OP_AND 267 +#define AND 268 +#define DIGIT 269 +#define LETTER 270 +#define UMINUS 271 diff --git a/test/quote_calc2.y b/test/quote_calc2.y new file mode 100644 index 000000000000..ab72a285fcb5 --- /dev/null +++ b/test/quote_calc2.y @@ -0,0 +1,112 @@ +%{ +# include <stdio.h> +# include <ctype.h> + +int regs[26]; +int base; + +int yylex(void); +static void yyerror(const char *s); + +%} + +%start list + +%token OP_ADD "ADD" +%token OP_SUB "SUB" +%token OP_MUL "MUL" +%token OP_DIV "DIV" +%token OP_MOD "MOD" +%token OP_AND "AND" + +%token DIGIT LETTER + +%left '|' +%left '&' +%left '+' '-' +%left '*' '/' '%' +%left UMINUS /* supplies precedence for unary minus */ + +%% /* beginning of rules section */ + +list : /* empty */ + | list stat '\n' + | list error '\n' + { yyerrok ; } + ; + +stat : expr + { printf("%d\n",$1);} + | LETTER '=' expr + { regs[$1] = $3; } + ; + +expr : '(' expr ')' + { $$ = $2; } + | expr "ADD" expr + { $$ = $1 + $3; } + | expr "SUB" expr + { $$ = $1 - $3; } + | expr "MUL" expr + { $$ = $1 * $3; } + | expr "DIV" expr + { $$ = $1 / $3; } + | expr "MOD" expr + { $$ = $1 % $3; } + | expr "AND" expr + { $$ = $1 & $3; } + | expr '|' expr + { $$ = $1 | $3; } + | "SUB" expr %prec UMINUS + { $$ = - $2; } + | LETTER + { $$ = regs[$1]; } + | number + ; + +number: DIGIT + { $$ = $1; base = ($1==0) ? 8 : 10; } + | number DIGIT + { $$ = base * $1 + $2; } + ; + +%% /* start of programs */ + +int +main (void) +{ + while(!feof(stdin)) { + yyparse(); + } + return 0; +} + +static void +yyerror(const char *s) +{ + fprintf(stderr, "%s\n", s); +} + +int +yylex(void) { + /* lexical analysis routine */ + /* returns LETTER for a lower case letter, yylval = 0 through 25 */ + /* return DIGIT for a digit, yylval = 0 through 9 */ + /* all other characters are returned immediately */ + + int c; + + while( (c=getchar()) == ' ' ) { /* skip blanks */ } + + /* c is now nonblank */ + + if( islower( c )) { + yylval = c - 'a'; + return ( LETTER ); + } + if( isdigit( c )) { + yylval = c - '0'; + return ( DIGIT ); + } + return( c ); +} diff --git a/test/quote_calc3-s.output b/test/quote_calc3-s.output new file mode 100644 index 000000000000..0306652bfaa1 --- /dev/null +++ b/test/quote_calc3-s.output @@ -0,0 +1,557 @@ + 0 $accept : list $end + + 1 list : + 2 | list stat '\n' + 3 | list error '\n' + + 4 stat : expr + 5 | LETTER '=' expr + + 6 expr : '(' expr ')' + 7 | expr OP_ADD expr + 8 | expr OP_SUB expr + 9 | expr OP_MUL expr + 10 | expr OP_DIV expr + 11 | expr OP_MOD expr + 12 | expr OP_AND expr + 13 | expr '|' expr + 14 | OP_SUB expr + 15 | LETTER + 16 | number + + 17 number : DIGIT + 18 | number DIGIT + +state 0 + $accept : . list $end (0) + list : . (1) + + . reduce 1 + + list goto 1 + + +state 1 + $accept : list . $end (0) + list : list . stat '\n' (2) + list : list . error '\n' (3) + + $end accept + error shift 2 + OP_SUB shift 3 + DIGIT shift 4 + LETTER shift 5 + '(' shift 6 + . error + + stat goto 7 + expr goto 8 + number goto 9 + + +state 2 + list : list error . '\n' (3) + + '\n' shift 10 + . error + + +state 3 + expr : OP_SUB . expr (14) + + OP_SUB shift 3 + DIGIT shift 4 + LETTER shift 11 + '(' shift 6 + . error + + expr goto 12 + number goto 9 + + +state 4 + number : DIGIT . (17) + + . reduce 17 + + +state 5 + stat : LETTER . '=' expr (5) + expr : LETTER . (15) + + '=' shift 13 + OP_ADD reduce 15 + OP_SUB reduce 15 + OP_MUL reduce 15 + OP_DIV reduce 15 + OP_MOD reduce 15 + OP_AND reduce 15 + '|' reduce 15 + '\n' reduce 15 + + +state 6 + expr : '(' . expr ')' (6) + + OP_SUB shift 3 + DIGIT shift 4 + LETTER shift 11 + '(' shift 6 + . error + + expr goto 14 + number goto 9 + + +state 7 + list : list stat . '\n' (2) + + '\n' shift 15 + . error + + +state 8 + stat : expr . (4) + expr : expr . OP_ADD expr (7) + expr : expr . OP_SUB expr (8) + expr : expr . OP_MUL expr (9) + expr : expr . OP_DIV expr (10) + expr : expr . OP_MOD expr (11) + expr : expr . OP_AND expr (12) + expr : expr . '|' expr (13) + + OP_ADD shift 16 + OP_SUB shift 17 + OP_MUL shift 18 + OP_DIV shift 19 + OP_MOD shift 20 + OP_AND shift 21 + '|' shift 22 + '\n' reduce 4 + + +state 9 + expr : number . (16) + number : number . DIGIT (18) + + DIGIT shift 23 + OP_ADD reduce 16 + OP_SUB reduce 16 + OP_MUL reduce 16 + OP_DIV reduce 16 + OP_MOD reduce 16 + OP_AND reduce 16 + '|' reduce 16 + '\n' reduce 16 + ')' reduce 16 + + +state 10 + list : list error '\n' . (3) + + . reduce 3 + + +state 11 + expr : LETTER . (15) + + . reduce 15 + + +12: shift/reduce conflict (shift 16, reduce 14) on OP_ADD +12: shift/reduce conflict (shift 17, reduce 14) on OP_SUB +12: shift/reduce conflict (shift 18, reduce 14) on OP_MUL +12: shift/reduce conflict (shift 19, reduce 14) on OP_DIV +12: shift/reduce conflict (shift 20, reduce 14) on OP_MOD +12: shift/reduce conflict (shift 21, reduce 14) on OP_AND +state 12 + expr : expr . OP_ADD expr (7) + expr : expr . OP_SUB expr (8) + expr : expr . OP_MUL expr (9) + expr : expr . OP_DIV expr (10) + expr : expr . OP_MOD expr (11) + expr : expr . OP_AND expr (12) + expr : expr . '|' expr (13) + expr : OP_SUB expr . (14) + + OP_ADD shift 16 + OP_SUB shift 17 + OP_MUL shift 18 + OP_DIV shift 19 + OP_MOD shift 20 + OP_AND shift 21 + '|' reduce 14 + '\n' reduce 14 + ')' reduce 14 + + +state 13 + stat : LETTER '=' . expr (5) + + OP_SUB shift 3 + DIGIT shift 4 + LETTER shift 11 + '(' shift 6 + . error + + expr goto 24 + number goto 9 + + +state 14 + expr : '(' expr . ')' (6) + expr : expr . OP_ADD expr (7) + expr : expr . OP_SUB expr (8) + expr : expr . OP_MUL expr (9) + expr : expr . OP_DIV expr (10) + expr : expr . OP_MOD expr (11) + expr : expr . OP_AND expr (12) + expr : expr . '|' expr (13) + + OP_ADD shift 16 + OP_SUB shift 17 + OP_MUL shift 18 + OP_DIV shift 19 + OP_MOD shift 20 + OP_AND shift 21 + '|' shift 22 + ')' shift 25 + . error + + +state 15 + list : list stat '\n' . (2) + + . reduce 2 + + +state 16 + expr : expr OP_ADD . expr (7) + + OP_SUB shift 3 + DIGIT shift 4 + LETTER shift 11 + '(' shift 6 + . error + + expr goto 26 + number goto 9 + + +state 17 + expr : expr OP_SUB . expr (8) + + OP_SUB shift 3 + DIGIT shift 4 + LETTER shift 11 + '(' shift 6 + . error + + expr goto 27 + number goto 9 + + +state 18 + expr : expr OP_MUL . expr (9) + + OP_SUB shift 3 + DIGIT shift 4 + LETTER shift 11 + '(' shift 6 + . error + + expr goto 28 + number goto 9 + + +state 19 + expr : expr OP_DIV . expr (10) + + OP_SUB shift 3 + DIGIT shift 4 + LETTER shift 11 + '(' shift 6 + . error + + expr goto 29 + number goto 9 + + +state 20 + expr : expr OP_MOD . expr (11) + + OP_SUB shift 3 + DIGIT shift 4 + LETTER shift 11 + '(' shift 6 + . error + + expr goto 30 + number goto 9 + + +state 21 + expr : expr OP_AND . expr (12) + + OP_SUB shift 3 + DIGIT shift 4 + LETTER shift 11 + '(' shift 6 + . error + + expr goto 31 + number goto 9 + + +state 22 + expr : expr '|' . expr (13) + + OP_SUB shift 3 + DIGIT shift 4 + LETTER shift 11 + '(' shift 6 + . error + + expr goto 32 + number goto 9 + + +state 23 + number : number DIGIT . (18) + + . reduce 18 + + +state 24 + stat : LETTER '=' expr . (5) + expr : expr . OP_ADD expr (7) + expr : expr . OP_SUB expr (8) + expr : expr . OP_MUL expr (9) + expr : expr . OP_DIV expr (10) + expr : expr . OP_MOD expr (11) + expr : expr . OP_AND expr (12) + expr : expr . '|' expr (13) + + OP_ADD shift 16 + OP_SUB shift 17 + OP_MUL shift 18 + OP_DIV shift 19 + OP_MOD shift 20 + OP_AND shift 21 + '|' shift 22 + '\n' reduce 5 + + +state 25 + expr : '(' expr ')' . (6) + + . reduce 6 + + +26: shift/reduce conflict (shift 16, reduce 7) on OP_ADD +26: shift/reduce conflict (shift 17, reduce 7) on OP_SUB +26: shift/reduce conflict (shift 18, reduce 7) on OP_MUL +26: shift/reduce conflict (shift 19, reduce 7) on OP_DIV +26: shift/reduce conflict (shift 20, reduce 7) on OP_MOD +26: shift/reduce conflict (shift 21, reduce 7) on OP_AND +26: shift/reduce conflict (shift 22, reduce 7) on '|' +state 26 + expr : expr . OP_ADD expr (7) + expr : expr OP_ADD expr . (7) + expr : expr . OP_SUB expr (8) + expr : expr . OP_MUL expr (9) + expr : expr . OP_DIV expr (10) + expr : expr . OP_MOD expr (11) + expr : expr . OP_AND expr (12) + expr : expr . '|' expr (13) + + OP_ADD shift 16 + OP_SUB shift 17 + OP_MUL shift 18 + OP_DIV shift 19 + OP_MOD shift 20 + OP_AND shift 21 + '|' shift 22 + '\n' reduce 7 + ')' reduce 7 + + +27: shift/reduce conflict (shift 16, reduce 8) on OP_ADD +27: shift/reduce conflict (shift 17, reduce 8) on OP_SUB +27: shift/reduce conflict (shift 18, reduce 8) on OP_MUL +27: shift/reduce conflict (shift 19, reduce 8) on OP_DIV +27: shift/reduce conflict (shift 20, reduce 8) on OP_MOD +27: shift/reduce conflict (shift 21, reduce 8) on OP_AND +27: shift/reduce conflict (shift 22, reduce 8) on '|' +state 27 + expr : expr . OP_ADD expr (7) + expr : expr . OP_SUB expr (8) + expr : expr OP_SUB expr . (8) + expr : expr . OP_MUL expr (9) + expr : expr . OP_DIV expr (10) + expr : expr . OP_MOD expr (11) + expr : expr . OP_AND expr (12) + expr : expr . '|' expr (13) + + OP_ADD shift 16 + OP_SUB shift 17 + OP_MUL shift 18 + OP_DIV shift 19 + OP_MOD shift 20 + OP_AND shift 21 + '|' shift 22 + '\n' reduce 8 + ')' reduce 8 + + +28: shift/reduce conflict (shift 16, reduce 9) on OP_ADD +28: shift/reduce conflict (shift 17, reduce 9) on OP_SUB +28: shift/reduce conflict (shift 18, reduce 9) on OP_MUL +28: shift/reduce conflict (shift 19, reduce 9) on OP_DIV +28: shift/reduce conflict (shift 20, reduce 9) on OP_MOD +28: shift/reduce conflict (shift 21, reduce 9) on OP_AND +28: shift/reduce conflict (shift 22, reduce 9) on '|' +state 28 + expr : expr . OP_ADD expr (7) + expr : expr . OP_SUB expr (8) + expr : expr . OP_MUL expr (9) + expr : expr OP_MUL expr . (9) + expr : expr . OP_DIV expr (10) + expr : expr . OP_MOD expr (11) + expr : expr . OP_AND expr (12) + expr : expr . '|' expr (13) + + OP_ADD shift 16 + OP_SUB shift 17 + OP_MUL shift 18 + OP_DIV shift 19 + OP_MOD shift 20 + OP_AND shift 21 + '|' shift 22 + '\n' reduce 9 + ')' reduce 9 + + +29: shift/reduce conflict (shift 16, reduce 10) on OP_ADD +29: shift/reduce conflict (shift 17, reduce 10) on OP_SUB +29: shift/reduce conflict (shift 18, reduce 10) on OP_MUL +29: shift/reduce conflict (shift 19, reduce 10) on OP_DIV +29: shift/reduce conflict (shift 20, reduce 10) on OP_MOD +29: shift/reduce conflict (shift 21, reduce 10) on OP_AND +29: shift/reduce conflict (shift 22, reduce 10) on '|' +state 29 + expr : expr . OP_ADD expr (7) + expr : expr . OP_SUB expr (8) + expr : expr . OP_MUL expr (9) + expr : expr . OP_DIV expr (10) + expr : expr OP_DIV expr . (10) + expr : expr . OP_MOD expr (11) + expr : expr . OP_AND expr (12) + expr : expr . '|' expr (13) + + OP_ADD shift 16 + OP_SUB shift 17 + OP_MUL shift 18 + OP_DIV shift 19 + OP_MOD shift 20 + OP_AND shift 21 + '|' shift 22 + '\n' reduce 10 + ')' reduce 10 + + +30: shift/reduce conflict (shift 16, reduce 11) on OP_ADD +30: shift/reduce conflict (shift 17, reduce 11) on OP_SUB +30: shift/reduce conflict (shift 18, reduce 11) on OP_MUL +30: shift/reduce conflict (shift 19, reduce 11) on OP_DIV +30: shift/reduce conflict (shift 20, reduce 11) on OP_MOD +30: shift/reduce conflict (shift 21, reduce 11) on OP_AND +30: shift/reduce conflict (shift 22, reduce 11) on '|' +state 30 + expr : expr . OP_ADD expr (7) + expr : expr . OP_SUB expr (8) + expr : expr . OP_MUL expr (9) + expr : expr . OP_DIV expr (10) + expr : expr . OP_MOD expr (11) + expr : expr OP_MOD expr . (11) + expr : expr . OP_AND expr (12) + expr : expr . '|' expr (13) + + OP_ADD shift 16 + OP_SUB shift 17 + OP_MUL shift 18 + OP_DIV shift 19 + OP_MOD shift 20 + OP_AND shift 21 + '|' shift 22 + '\n' reduce 11 + ')' reduce 11 + + +31: shift/reduce conflict (shift 16, reduce 12) on OP_ADD +31: shift/reduce conflict (shift 17, reduce 12) on OP_SUB +31: shift/reduce conflict (shift 18, reduce 12) on OP_MUL +31: shift/reduce conflict (shift 19, reduce 12) on OP_DIV +31: shift/reduce conflict (shift 20, reduce 12) on OP_MOD +31: shift/reduce conflict (shift 21, reduce 12) on OP_AND +31: shift/reduce conflict (shift 22, reduce 12) on '|' +state 31 + expr : expr . OP_ADD expr (7) + expr : expr . OP_SUB expr (8) + expr : expr . OP_MUL expr (9) + expr : expr . OP_DIV expr (10) + expr : expr . OP_MOD expr (11) + expr : expr . OP_AND expr (12) + expr : expr OP_AND expr . (12) + expr : expr . '|' expr (13) + + OP_ADD shift 16 + OP_SUB shift 17 + OP_MUL shift 18 + OP_DIV shift 19 + OP_MOD shift 20 + OP_AND shift 21 + '|' shift 22 + '\n' reduce 12 + ')' reduce 12 + + +32: shift/reduce conflict (shift 16, reduce 13) on OP_ADD +32: shift/reduce conflict (shift 17, reduce 13) on OP_SUB +32: shift/reduce conflict (shift 18, reduce 13) on OP_MUL +32: shift/reduce conflict (shift 19, reduce 13) on OP_DIV +32: shift/reduce conflict (shift 20, reduce 13) on OP_MOD +32: shift/reduce conflict (shift 21, reduce 13) on OP_AND +state 32 + expr : expr . OP_ADD expr (7) + expr : expr . OP_SUB expr (8) + expr : expr . OP_MUL expr (9) + expr : expr . OP_DIV expr (10) + expr : expr . OP_MOD expr (11) + expr : expr . OP_AND expr (12) + expr : expr . '|' expr (13) + expr : expr '|' expr . (13) + + OP_ADD shift 16 + OP_SUB shift 17 + OP_MUL shift 18 + OP_DIV shift 19 + OP_MOD shift 20 + OP_AND shift 21 + '|' reduce 13 + '\n' reduce 13 + ')' reduce 13 + + +State 12 contains 6 shift/reduce conflicts. +State 26 contains 7 shift/reduce conflicts. +State 27 contains 7 shift/reduce conflicts. +State 28 contains 7 shift/reduce conflicts. +State 29 contains 7 shift/reduce conflicts. +State 30 contains 7 shift/reduce conflicts. +State 31 contains 7 shift/reduce conflicts. +State 32 contains 6 shift/reduce conflicts. + + +28 terminals, 5 nonterminals +19 grammar rules, 33 states diff --git a/test/quote_calc3-s.tab.c b/test/quote_calc3-s.tab.c new file mode 100644 index 000000000000..0953fbb623c1 --- /dev/null +++ b/test/quote_calc3-s.tab.c @@ -0,0 +1,688 @@ +#ifndef lint +static const char yysccsid[] = "@(#)yaccpar 1.9 (Berkeley) 02/21/93"; +#endif + +#define YYBYACC 1 +#define YYMAJOR 1 +#define YYMINOR 9 + +#define YYEMPTY (-1) +#define yyclearin (yychar = YYEMPTY) +#define yyerrok (yyerrflag = 0) +#define YYRECOVERING() (yyerrflag != 0) + + +#ifndef yyparse +#define yyparse quote_calc3_parse +#endif /* yyparse */ + +#ifndef yylex +#define yylex quote_calc3_lex +#endif /* yylex */ + +#ifndef yyerror +#define yyerror quote_calc3_error +#endif /* yyerror */ + +#ifndef yychar +#define yychar quote_calc3_char +#endif /* yychar */ + +#ifndef yyval +#define yyval quote_calc3_val +#endif /* yyval */ + +#ifndef yylval +#define yylval quote_calc3_lval +#endif /* yylval */ + +#ifndef yydebug +#define yydebug quote_calc3_debug +#endif /* yydebug */ + +#ifndef yynerrs +#define yynerrs quote_calc3_nerrs +#endif /* yynerrs */ + +#ifndef yyerrflag +#define yyerrflag quote_calc3_errflag +#endif /* yyerrflag */ + +#ifndef yylhs +#define yylhs quote_calc3_lhs +#endif /* yylhs */ + +#ifndef yylen +#define yylen quote_calc3_len +#endif /* yylen */ + +#ifndef yydefred +#define yydefred quote_calc3_defred +#endif /* yydefred */ + +#ifndef yydgoto +#define yydgoto quote_calc3_dgoto +#endif /* yydgoto */ + +#ifndef yysindex +#define yysindex quote_calc3_sindex +#endif /* yysindex */ + +#ifndef yyrindex +#define yyrindex quote_calc3_rindex +#endif /* yyrindex */ + +#ifndef yygindex +#define yygindex quote_calc3_gindex +#endif /* yygindex */ + +#ifndef yytable +#define yytable quote_calc3_table +#endif /* yytable */ + +#ifndef yycheck +#define yycheck quote_calc3_check +#endif /* yycheck */ + +#ifndef yyname +#define yyname quote_calc3_name +#endif /* yyname */ + +#ifndef yyrule +#define yyrule quote_calc3_rule +#endif /* yyrule */ +#define YYPREFIX "quote_calc3_" + +#define YYPURE 0 + +#line 2 "quote_calc3.y" +# include <stdio.h> +# include <ctype.h> + +int regs[26]; +int base; + +int yylex(void); +static void yyerror(const char *s); + +#line 109 "quote_calc3-s.tab.c" + +#ifndef YYSTYPE +typedef int YYSTYPE; +#endif + +/* compatibility with bison */ +#ifdef YYPARSE_PARAM +/* compatibility with FreeBSD */ +# ifdef YYPARSE_PARAM_TYPE +# define YYPARSE_DECL() yyparse(YYPARSE_PARAM_TYPE YYPARSE_PARAM) +# else +# define YYPARSE_DECL() yyparse(void *YYPARSE_PARAM) +# endif +#else +# define YYPARSE_DECL() yyparse(void) +#endif + +/* Parameters sent to lex. */ +#ifdef YYLEX_PARAM +# define YYLEX_DECL() yylex(void *YYLEX_PARAM) +# define YYLEX yylex(YYLEX_PARAM) +#else +# define YYLEX_DECL() yylex(void) +# define YYLEX yylex() +#endif + +/* Parameters sent to yyerror. */ +#ifndef YYERROR_DECL +#define YYERROR_DECL() yyerror(const char *s) +#endif +#ifndef YYERROR_CALL +#define YYERROR_CALL(msg) yyerror(msg) +#endif + +extern int YYPARSE_DECL(); + +#define OP_ADD 257 +#define OP_SUB 259 +#define OP_MUL 261 +#define OP_DIV 263 +#define OP_MOD 265 +#define OP_AND 267 +#define DIGIT 269 +#define LETTER 270 +#define UMINUS 271 +#define YYERRCODE 256 +static const short quote_calc3_lhs[] = { -1, + 0, 0, 0, 1, 1, 2, 2, 2, 2, 2, + 2, 2, 2, 2, 2, 2, 3, 3, +}; +static const short quote_calc3_len[] = { 2, + 0, 3, 3, 1, 3, 3, 3, 3, 3, 3, + 3, 3, 3, 2, 1, 1, 1, 2, +}; +static const short quote_calc3_defred[] = { 1, + 0, 0, 0, 17, 0, 0, 0, 0, 0, 3, + 15, 0, 0, 0, 2, 0, 0, 0, 0, 0, + 0, 0, 18, 0, 6, 0, 0, 0, 0, 0, + 0, 0, +}; +static const short quote_calc3_dgoto[] = { 1, + 7, 8, 9, +}; +static const short quote_calc3_sindex[] = { 0, + -38, 5, -36, 0, -51, -36, 7, -121, -248, 0, + 0, -243, -36, -22, 0, -36, -36, -36, -36, -36, + -36, -36, 0, -121, 0, -121, -121, -121, -121, -121, + -121, -243, +}; +static const short quote_calc3_rindex[] = { 0, + 0, 0, 0, 0, -9, 0, 0, 13, -10, 0, + 0, -5, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 15, 0, -3, -2, -1, 1, 2, + 3, -4, +}; +static const short quote_calc3_gindex[] = { 0, + 0, 42, 0, +}; +#define YYTABLESIZE 258 +static const short quote_calc3_table[] = { 16, + 15, 6, 22, 6, 14, 13, 7, 8, 9, 13, + 10, 11, 12, 16, 10, 17, 15, 18, 25, 19, + 23, 20, 4, 21, 5, 0, 0, 0, 0, 0, + 16, 0, 0, 0, 0, 14, 13, 7, 8, 9, + 0, 10, 11, 12, 12, 0, 0, 14, 0, 0, + 0, 0, 0, 0, 24, 0, 0, 26, 27, 28, + 29, 30, 31, 32, 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, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 22, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 16, 15, 0, 0, 0, 14, 13, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 16, 0, 17, 0, 18, + 0, 19, 0, 20, 0, 21, 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, 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, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 2, 0, 0, + 3, 0, 3, 0, 0, 0, 0, 0, 0, 0, + 4, 5, 4, 11, 16, 0, 17, 0, 18, 0, + 19, 0, 20, 0, 21, 0, 16, 15, 16, 15, + 16, 15, 16, 15, 16, 15, 16, 15, +}; +static const short quote_calc3_check[] = { 10, + 10, 40, 124, 40, 10, 10, 10, 10, 10, 61, + 10, 10, 10, 257, 10, 259, 10, 261, 41, 263, + 269, 265, 10, 267, 10, -1, -1, -1, -1, -1, + 41, -1, -1, -1, -1, 41, 41, 41, 41, 41, + -1, 41, 41, 41, 3, -1, -1, 6, -1, -1, + -1, -1, -1, -1, 13, -1, -1, 16, 17, 18, + 19, 20, 21, 22, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, + -1, 124, -1, -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, 124, 124, -1, -1, -1, 124, 124, + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, 257, -1, 259, -1, 261, + -1, 263, -1, 265, -1, 267, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, 256, -1, -1, + 259, -1, 259, -1, -1, -1, -1, -1, -1, -1, + 269, 270, 269, 270, 257, -1, 259, -1, 261, -1, + 263, -1, 265, -1, 267, -1, 257, 257, 259, 259, + 261, 261, 263, 263, 265, 265, 267, 267, +}; +#define YYFINAL 1 +#ifndef YYDEBUG +#define YYDEBUG 0 +#endif +#define YYMAXTOKEN 271 +#if YYDEBUG +static const char *yyname[] = { + +"end-of-file",0,0,0,0,0,0,0,0,0,"'\\n'",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,"'-'",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,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,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,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,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,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,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,0,0,0,0,0,0, +0,0,0,0,0,0,"OP_ADD","\"ADD-operator\"","OP_SUB","\"SUB-operator\"","OP_MUL", +"\"MUL-operator\"","OP_DIV","\"DIV-operator\"","OP_MOD","\"MOD-operator\"", +"OP_AND","\"AND-operator\"","DIGIT","LETTER","UMINUS", +}; +static const char *yyrule[] = { +"$accept : list", +"list :", +"list : list stat '\\n'", +"list : list error '\\n'", +"stat : expr", +"stat : LETTER '=' expr", +"expr : '(' expr ')'", +"expr : expr OP_ADD expr", +"expr : expr OP_SUB expr", +"expr : expr OP_MUL expr", +"expr : expr OP_DIV expr", +"expr : expr OP_MOD expr", +"expr : expr OP_AND expr", +"expr : expr '|' expr", +"expr : OP_SUB expr", +"expr : LETTER", +"expr : number", +"number : DIGIT", +"number : number DIGIT", + +}; +#endif + +int yydebug; +int yynerrs; + +int yyerrflag; +int yychar; +YYSTYPE yyval; +YYSTYPE yylval; + +/* define the initial stack-sizes */ +#ifdef YYSTACKSIZE +#undef YYMAXDEPTH +#define YYMAXDEPTH YYSTACKSIZE +#else +#ifdef YYMAXDEPTH +#define YYSTACKSIZE YYMAXDEPTH +#else +#define YYSTACKSIZE 500 +#define YYMAXDEPTH 500 +#endif +#endif + +#define YYINITSTACKSIZE 500 + +typedef struct { + unsigned stacksize; + short *s_base; + short *s_mark; + short *s_last; + YYSTYPE *l_base; + YYSTYPE *l_mark; +} YYSTACKDATA; +/* variables for the parser stack */ +static YYSTACKDATA yystack; +#line 73 "quote_calc3.y" + /* start of programs */ + +int +main (void) +{ + while(!feof(stdin)) { + yyparse(); + } + return 0; +} + +static void +yyerror(const char *s) +{ + fprintf(stderr, "%s\n", s); +} + +int +yylex(void) { + /* lexical analysis routine */ + /* returns LETTER for a lower case letter, yylval = 0 through 25 */ + /* return DIGIT for a digit, yylval = 0 through 9 */ + /* all other characters are returned immediately */ + + int c; + + while( (c=getchar()) == ' ' ) { /* skip blanks */ } + + /* c is now nonblank */ + + if( islower( c )) { + yylval = c - 'a'; + return ( LETTER ); + } + if( isdigit( c )) { + yylval = c - '0'; + return ( DIGIT ); + } + return( c ); +} +#line 362 "quote_calc3-s.tab.c" + +#if YYDEBUG +#include <stdio.h> /* needed for printf */ +#endif + +#include <stdlib.h> /* needed for malloc, etc */ +#include <string.h> /* needed for memset */ + +/* allocate initial stack or double stack size, up to YYMAXDEPTH */ +static int yygrowstack(YYSTACKDATA *data) +{ + int i; + unsigned newsize; + short *newss; + YYSTYPE *newvs; + + if ((newsize = data->stacksize) == 0) + newsize = YYINITSTACKSIZE; + else if (newsize >= YYMAXDEPTH) + return -1; + else if ((newsize *= 2) > YYMAXDEPTH) + newsize = YYMAXDEPTH; + + i = data->s_mark - data->s_base; + newss = (short *)realloc(data->s_base, newsize * sizeof(*newss)); + if (newss == 0) + return -1; + + data->s_base = newss; + data->s_mark = newss + i; + + newvs = (YYSTYPE *)realloc(data->l_base, newsize * sizeof(*newvs)); + if (newvs == 0) + return -1; + + data->l_base = newvs; + data->l_mark = newvs + i; + + data->stacksize = newsize; + data->s_last = data->s_base + newsize - 1; + return 0; +} + +#if YYPURE || defined(YY_NO_LEAKS) +static void yyfreestack(YYSTACKDATA *data) +{ + free(data->s_base); + free(data->l_base); + memset(data, 0, sizeof(*data)); +} +#else +#define yyfreestack(data) /* nothing */ +#endif + +#define YYABORT goto yyabort +#define YYREJECT goto yyabort +#define YYACCEPT goto yyaccept +#define YYERROR goto yyerrlab + +int +YYPARSE_DECL() +{ + int yym, yyn, yystate; +#if YYDEBUG + const char *yys; + + if ((yys = getenv("YYDEBUG")) != 0) + { + yyn = *yys; + if (yyn >= '0' && yyn <= '9') + yydebug = yyn - '0'; + } +#endif + + yynerrs = 0; + yyerrflag = 0; + yychar = YYEMPTY; + yystate = 0; + +#if YYPURE + memset(&yystack, 0, sizeof(yystack)); +#endif + + if (yystack.s_base == NULL && yygrowstack(&yystack)) goto yyoverflow; + yystack.s_mark = yystack.s_base; + yystack.l_mark = yystack.l_base; + yystate = 0; + *yystack.s_mark = 0; + +yyloop: + if ((yyn = yydefred[yystate]) != 0) goto yyreduce; + if (yychar < 0) + { + if ((yychar = YYLEX) < 0) yychar = 0; +#if YYDEBUG + if (yydebug) + { + yys = 0; + if (yychar <= YYMAXTOKEN) yys = yyname[yychar]; + if (!yys) yys = "illegal-symbol"; + printf("%sdebug: state %d, reading %d (%s)\n", + YYPREFIX, yystate, yychar, yys); + } +#endif + } + if ((yyn = yysindex[yystate]) && (yyn += yychar) >= 0 && + yyn <= YYTABLESIZE && yycheck[yyn] == yychar) + { +#if YYDEBUG + if (yydebug) + printf("%sdebug: state %d, shifting to state %d\n", + YYPREFIX, yystate, yytable[yyn]); +#endif + if (yystack.s_mark >= yystack.s_last && yygrowstack(&yystack)) + { + goto yyoverflow; + } + yystate = yytable[yyn]; + *++yystack.s_mark = yytable[yyn]; + *++yystack.l_mark = yylval; + yychar = YYEMPTY; + if (yyerrflag > 0) --yyerrflag; + goto yyloop; + } + if ((yyn = yyrindex[yystate]) && (yyn += yychar) >= 0 && + yyn <= YYTABLESIZE && yycheck[yyn] == yychar) + { + yyn = yytable[yyn]; + goto yyreduce; + } + if (yyerrflag) goto yyinrecovery; + + yyerror("syntax error"); + + goto yyerrlab; + +yyerrlab: + ++yynerrs; + +yyinrecovery: + if (yyerrflag < 3) + { + yyerrflag = 3; + for (;;) + { + if ((yyn = yysindex[*yystack.s_mark]) && (yyn += YYERRCODE) >= 0 && + yyn <= YYTABLESIZE && yycheck[yyn] == YYERRCODE) + { +#if YYDEBUG + if (yydebug) + printf("%sdebug: state %d, error recovery shifting\ + to state %d\n", YYPREFIX, *yystack.s_mark, yytable[yyn]); +#endif + if (yystack.s_mark >= yystack.s_last && yygrowstack(&yystack)) + { + goto yyoverflow; + } + yystate = yytable[yyn]; + *++yystack.s_mark = yytable[yyn]; + *++yystack.l_mark = yylval; + goto yyloop; + } + else + { +#if YYDEBUG + if (yydebug) + printf("%sdebug: error recovery discarding state %d\n", + YYPREFIX, *yystack.s_mark); +#endif + if (yystack.s_mark <= yystack.s_base) goto yyabort; + --yystack.s_mark; + --yystack.l_mark; + } + } + } + else + { + if (yychar == 0) goto yyabort; +#if YYDEBUG + if (yydebug) + { + yys = 0; + if (yychar <= YYMAXTOKEN) yys = yyname[yychar]; + if (!yys) yys = "illegal-symbol"; + printf("%sdebug: state %d, error recovery discards token %d (%s)\n", + YYPREFIX, yystate, yychar, yys); + } +#endif + yychar = YYEMPTY; + goto yyloop; + } + +yyreduce: +#if YYDEBUG + if (yydebug) + printf("%sdebug: state %d, reducing by rule %d (%s)\n", + YYPREFIX, yystate, yyn, yyrule[yyn]); +#endif + yym = yylen[yyn]; + if (yym) + yyval = yystack.l_mark[1-yym]; + else + memset(&yyval, 0, sizeof yyval); + switch (yyn) + { +case 3: +#line 35 "quote_calc3.y" + { yyerrok ; } +break; +case 4: +#line 39 "quote_calc3.y" + { printf("%d\n",yystack.l_mark[0]);} +break; +case 5: +#line 41 "quote_calc3.y" + { regs[yystack.l_mark[-2]] = yystack.l_mark[0]; } +break; +case 6: +#line 45 "quote_calc3.y" + { yyval = yystack.l_mark[-1]; } +break; +case 7: +#line 47 "quote_calc3.y" + { yyval = yystack.l_mark[-2] + yystack.l_mark[0]; } +break; +case 8: +#line 49 "quote_calc3.y" + { yyval = yystack.l_mark[-2] - yystack.l_mark[0]; } +break; +case 9: +#line 51 "quote_calc3.y" + { yyval = yystack.l_mark[-2] * yystack.l_mark[0]; } +break; +case 10: +#line 53 "quote_calc3.y" + { yyval = yystack.l_mark[-2] / yystack.l_mark[0]; } +break; +case 11: +#line 55 "quote_calc3.y" + { yyval = yystack.l_mark[-2] % yystack.l_mark[0]; } +break; +case 12: +#line 57 "quote_calc3.y" + { yyval = yystack.l_mark[-2] & yystack.l_mark[0]; } +break; +case 13: +#line 59 "quote_calc3.y" + { yyval = yystack.l_mark[-2] | yystack.l_mark[0]; } +break; +case 14: +#line 61 "quote_calc3.y" + { yyval = - yystack.l_mark[0]; } +break; +case 15: +#line 63 "quote_calc3.y" + { yyval = regs[yystack.l_mark[0]]; } +break; +case 17: +#line 68 "quote_calc3.y" + { yyval = yystack.l_mark[0]; base = (yystack.l_mark[0]==0) ? 8 : 10; } +break; +case 18: +#line 70 "quote_calc3.y" + { yyval = base * yystack.l_mark[-1] + yystack.l_mark[0]; } +break; +#line 628 "quote_calc3-s.tab.c" + } + yystack.s_mark -= yym; + yystate = *yystack.s_mark; + yystack.l_mark -= yym; + yym = yylhs[yyn]; + if (yystate == 0 && yym == 0) + { +#if YYDEBUG + if (yydebug) + printf("%sdebug: after reduction, shifting from state 0 to\ + state %d\n", YYPREFIX, YYFINAL); +#endif + yystate = YYFINAL; + *++yystack.s_mark = YYFINAL; + *++yystack.l_mark = yyval; + if (yychar < 0) + { + if ((yychar = YYLEX) < 0) yychar = 0; +#if YYDEBUG + if (yydebug) + { + yys = 0; + if (yychar <= YYMAXTOKEN) yys = yyname[yychar]; + if (!yys) yys = "illegal-symbol"; + printf("%sdebug: state %d, reading %d (%s)\n", + YYPREFIX, YYFINAL, yychar, yys); + } +#endif + } + if (yychar == 0) goto yyaccept; + goto yyloop; + } + if ((yyn = yygindex[yym]) && (yyn += yystate) >= 0 && + yyn <= YYTABLESIZE && yycheck[yyn] == yystate) + yystate = yytable[yyn]; + else + yystate = yydgoto[yym]; +#if YYDEBUG + if (yydebug) + printf("%sdebug: after reduction, shifting from state %d \ +to state %d\n", YYPREFIX, *yystack.s_mark, yystate); +#endif + if (yystack.s_mark >= yystack.s_last && yygrowstack(&yystack)) + { + goto yyoverflow; + } + *++yystack.s_mark = (short) yystate; + *++yystack.l_mark = yyval; + goto yyloop; + +yyoverflow: + yyerror("yacc stack overflow"); + +yyabort: + yyfreestack(&yystack); + return (1); + +yyaccept: + yyfreestack(&yystack); + return (0); +} diff --git a/test/quote_calc3-s.tab.h b/test/quote_calc3-s.tab.h new file mode 100644 index 000000000000..1a4657903411 --- /dev/null +++ b/test/quote_calc3-s.tab.h @@ -0,0 +1,9 @@ +#define OP_ADD 257 +#define OP_SUB 259 +#define OP_MUL 261 +#define OP_DIV 263 +#define OP_MOD 265 +#define OP_AND 267 +#define DIGIT 269 +#define LETTER 270 +#define UMINUS 271 diff --git a/test/quote_calc3.output b/test/quote_calc3.output new file mode 100644 index 000000000000..0306652bfaa1 --- /dev/null +++ b/test/quote_calc3.output @@ -0,0 +1,557 @@ + 0 $accept : list $end + + 1 list : + 2 | list stat '\n' + 3 | list error '\n' + + 4 stat : expr + 5 | LETTER '=' expr + + 6 expr : '(' expr ')' + 7 | expr OP_ADD expr + 8 | expr OP_SUB expr + 9 | expr OP_MUL expr + 10 | expr OP_DIV expr + 11 | expr OP_MOD expr + 12 | expr OP_AND expr + 13 | expr '|' expr + 14 | OP_SUB expr + 15 | LETTER + 16 | number + + 17 number : DIGIT + 18 | number DIGIT + +state 0 + $accept : . list $end (0) + list : . (1) + + . reduce 1 + + list goto 1 + + +state 1 + $accept : list . $end (0) + list : list . stat '\n' (2) + list : list . error '\n' (3) + + $end accept + error shift 2 + OP_SUB shift 3 + DIGIT shift 4 + LETTER shift 5 + '(' shift 6 + . error + + stat goto 7 + expr goto 8 + number goto 9 + + +state 2 + list : list error . '\n' (3) + + '\n' shift 10 + . error + + +state 3 + expr : OP_SUB . expr (14) + + OP_SUB shift 3 + DIGIT shift 4 + LETTER shift 11 + '(' shift 6 + . error + + expr goto 12 + number goto 9 + + +state 4 + number : DIGIT . (17) + + . reduce 17 + + +state 5 + stat : LETTER . '=' expr (5) + expr : LETTER . (15) + + '=' shift 13 + OP_ADD reduce 15 + OP_SUB reduce 15 + OP_MUL reduce 15 + OP_DIV reduce 15 + OP_MOD reduce 15 + OP_AND reduce 15 + '|' reduce 15 + '\n' reduce 15 + + +state 6 + expr : '(' . expr ')' (6) + + OP_SUB shift 3 + DIGIT shift 4 + LETTER shift 11 + '(' shift 6 + . error + + expr goto 14 + number goto 9 + + +state 7 + list : list stat . '\n' (2) + + '\n' shift 15 + . error + + +state 8 + stat : expr . (4) + expr : expr . OP_ADD expr (7) + expr : expr . OP_SUB expr (8) + expr : expr . OP_MUL expr (9) + expr : expr . OP_DIV expr (10) + expr : expr . OP_MOD expr (11) + expr : expr . OP_AND expr (12) + expr : expr . '|' expr (13) + + OP_ADD shift 16 + OP_SUB shift 17 + OP_MUL shift 18 + OP_DIV shift 19 + OP_MOD shift 20 + OP_AND shift 21 + '|' shift 22 + '\n' reduce 4 + + +state 9 + expr : number . (16) + number : number . DIGIT (18) + + DIGIT shift 23 + OP_ADD reduce 16 + OP_SUB reduce 16 + OP_MUL reduce 16 + OP_DIV reduce 16 + OP_MOD reduce 16 + OP_AND reduce 16 + '|' reduce 16 + '\n' reduce 16 + ')' reduce 16 + + +state 10 + list : list error '\n' . (3) + + . reduce 3 + + +state 11 + expr : LETTER . (15) + + . reduce 15 + + +12: shift/reduce conflict (shift 16, reduce 14) on OP_ADD +12: shift/reduce conflict (shift 17, reduce 14) on OP_SUB +12: shift/reduce conflict (shift 18, reduce 14) on OP_MUL +12: shift/reduce conflict (shift 19, reduce 14) on OP_DIV +12: shift/reduce conflict (shift 20, reduce 14) on OP_MOD +12: shift/reduce conflict (shift 21, reduce 14) on OP_AND +state 12 + expr : expr . OP_ADD expr (7) + expr : expr . OP_SUB expr (8) + expr : expr . OP_MUL expr (9) + expr : expr . OP_DIV expr (10) + expr : expr . OP_MOD expr (11) + expr : expr . OP_AND expr (12) + expr : expr . '|' expr (13) + expr : OP_SUB expr . (14) + + OP_ADD shift 16 + OP_SUB shift 17 + OP_MUL shift 18 + OP_DIV shift 19 + OP_MOD shift 20 + OP_AND shift 21 + '|' reduce 14 + '\n' reduce 14 + ')' reduce 14 + + +state 13 + stat : LETTER '=' . expr (5) + + OP_SUB shift 3 + DIGIT shift 4 + LETTER shift 11 + '(' shift 6 + . error + + expr goto 24 + number goto 9 + + +state 14 + expr : '(' expr . ')' (6) + expr : expr . OP_ADD expr (7) + expr : expr . OP_SUB expr (8) + expr : expr . OP_MUL expr (9) + expr : expr . OP_DIV expr (10) + expr : expr . OP_MOD expr (11) + expr : expr . OP_AND expr (12) + expr : expr . '|' expr (13) + + OP_ADD shift 16 + OP_SUB shift 17 + OP_MUL shift 18 + OP_DIV shift 19 + OP_MOD shift 20 + OP_AND shift 21 + '|' shift 22 + ')' shift 25 + . error + + +state 15 + list : list stat '\n' . (2) + + . reduce 2 + + +state 16 + expr : expr OP_ADD . expr (7) + + OP_SUB shift 3 + DIGIT shift 4 + LETTER shift 11 + '(' shift 6 + . error + + expr goto 26 + number goto 9 + + +state 17 + expr : expr OP_SUB . expr (8) + + OP_SUB shift 3 + DIGIT shift 4 + LETTER shift 11 + '(' shift 6 + . error + + expr goto 27 + number goto 9 + + +state 18 + expr : expr OP_MUL . expr (9) + + OP_SUB shift 3 + DIGIT shift 4 + LETTER shift 11 + '(' shift 6 + . error + + expr goto 28 + number goto 9 + + +state 19 + expr : expr OP_DIV . expr (10) + + OP_SUB shift 3 + DIGIT shift 4 + LETTER shift 11 + '(' shift 6 + . error + + expr goto 29 + number goto 9 + + +state 20 + expr : expr OP_MOD . expr (11) + + OP_SUB shift 3 + DIGIT shift 4 + LETTER shift 11 + '(' shift 6 + . error + + expr goto 30 + number goto 9 + + +state 21 + expr : expr OP_AND . expr (12) + + OP_SUB shift 3 + DIGIT shift 4 + LETTER shift 11 + '(' shift 6 + . error + + expr goto 31 + number goto 9 + + +state 22 + expr : expr '|' . expr (13) + + OP_SUB shift 3 + DIGIT shift 4 + LETTER shift 11 + '(' shift 6 + . error + + expr goto 32 + number goto 9 + + +state 23 + number : number DIGIT . (18) + + . reduce 18 + + +state 24 + stat : LETTER '=' expr . (5) + expr : expr . OP_ADD expr (7) + expr : expr . OP_SUB expr (8) + expr : expr . OP_MUL expr (9) + expr : expr . OP_DIV expr (10) + expr : expr . OP_MOD expr (11) + expr : expr . OP_AND expr (12) + expr : expr . '|' expr (13) + + OP_ADD shift 16 + OP_SUB shift 17 + OP_MUL shift 18 + OP_DIV shift 19 + OP_MOD shift 20 + OP_AND shift 21 + '|' shift 22 + '\n' reduce 5 + + +state 25 + expr : '(' expr ')' . (6) + + . reduce 6 + + +26: shift/reduce conflict (shift 16, reduce 7) on OP_ADD +26: shift/reduce conflict (shift 17, reduce 7) on OP_SUB +26: shift/reduce conflict (shift 18, reduce 7) on OP_MUL +26: shift/reduce conflict (shift 19, reduce 7) on OP_DIV +26: shift/reduce conflict (shift 20, reduce 7) on OP_MOD +26: shift/reduce conflict (shift 21, reduce 7) on OP_AND +26: shift/reduce conflict (shift 22, reduce 7) on '|' +state 26 + expr : expr . OP_ADD expr (7) + expr : expr OP_ADD expr . (7) + expr : expr . OP_SUB expr (8) + expr : expr . OP_MUL expr (9) + expr : expr . OP_DIV expr (10) + expr : expr . OP_MOD expr (11) + expr : expr . OP_AND expr (12) + expr : expr . '|' expr (13) + + OP_ADD shift 16 + OP_SUB shift 17 + OP_MUL shift 18 + OP_DIV shift 19 + OP_MOD shift 20 + OP_AND shift 21 + '|' shift 22 + '\n' reduce 7 + ')' reduce 7 + + +27: shift/reduce conflict (shift 16, reduce 8) on OP_ADD +27: shift/reduce conflict (shift 17, reduce 8) on OP_SUB +27: shift/reduce conflict (shift 18, reduce 8) on OP_MUL +27: shift/reduce conflict (shift 19, reduce 8) on OP_DIV +27: shift/reduce conflict (shift 20, reduce 8) on OP_MOD +27: shift/reduce conflict (shift 21, reduce 8) on OP_AND +27: shift/reduce conflict (shift 22, reduce 8) on '|' +state 27 + expr : expr . OP_ADD expr (7) + expr : expr . OP_SUB expr (8) + expr : expr OP_SUB expr . (8) + expr : expr . OP_MUL expr (9) + expr : expr . OP_DIV expr (10) + expr : expr . OP_MOD expr (11) + expr : expr . OP_AND expr (12) + expr : expr . '|' expr (13) + + OP_ADD shift 16 + OP_SUB shift 17 + OP_MUL shift 18 + OP_DIV shift 19 + OP_MOD shift 20 + OP_AND shift 21 + '|' shift 22 + '\n' reduce 8 + ')' reduce 8 + + +28: shift/reduce conflict (shift 16, reduce 9) on OP_ADD +28: shift/reduce conflict (shift 17, reduce 9) on OP_SUB +28: shift/reduce conflict (shift 18, reduce 9) on OP_MUL +28: shift/reduce conflict (shift 19, reduce 9) on OP_DIV +28: shift/reduce conflict (shift 20, reduce 9) on OP_MOD +28: shift/reduce conflict (shift 21, reduce 9) on OP_AND +28: shift/reduce conflict (shift 22, reduce 9) on '|' +state 28 + expr : expr . OP_ADD expr (7) + expr : expr . OP_SUB expr (8) + expr : expr . OP_MUL expr (9) + expr : expr OP_MUL expr . (9) + expr : expr . OP_DIV expr (10) + expr : expr . OP_MOD expr (11) + expr : expr . OP_AND expr (12) + expr : expr . '|' expr (13) + + OP_ADD shift 16 + OP_SUB shift 17 + OP_MUL shift 18 + OP_DIV shift 19 + OP_MOD shift 20 + OP_AND shift 21 + '|' shift 22 + '\n' reduce 9 + ')' reduce 9 + + +29: shift/reduce conflict (shift 16, reduce 10) on OP_ADD +29: shift/reduce conflict (shift 17, reduce 10) on OP_SUB +29: shift/reduce conflict (shift 18, reduce 10) on OP_MUL +29: shift/reduce conflict (shift 19, reduce 10) on OP_DIV +29: shift/reduce conflict (shift 20, reduce 10) on OP_MOD +29: shift/reduce conflict (shift 21, reduce 10) on OP_AND +29: shift/reduce conflict (shift 22, reduce 10) on '|' +state 29 + expr : expr . OP_ADD expr (7) + expr : expr . OP_SUB expr (8) + expr : expr . OP_MUL expr (9) + expr : expr . OP_DIV expr (10) + expr : expr OP_DIV expr . (10) + expr : expr . OP_MOD expr (11) + expr : expr . OP_AND expr (12) + expr : expr . '|' expr (13) + + OP_ADD shift 16 + OP_SUB shift 17 + OP_MUL shift 18 + OP_DIV shift 19 + OP_MOD shift 20 + OP_AND shift 21 + '|' shift 22 + '\n' reduce 10 + ')' reduce 10 + + +30: shift/reduce conflict (shift 16, reduce 11) on OP_ADD +30: shift/reduce conflict (shift 17, reduce 11) on OP_SUB +30: shift/reduce conflict (shift 18, reduce 11) on OP_MUL +30: shift/reduce conflict (shift 19, reduce 11) on OP_DIV +30: shift/reduce conflict (shift 20, reduce 11) on OP_MOD +30: shift/reduce conflict (shift 21, reduce 11) on OP_AND +30: shift/reduce conflict (shift 22, reduce 11) on '|' +state 30 + expr : expr . OP_ADD expr (7) + expr : expr . OP_SUB expr (8) + expr : expr . OP_MUL expr (9) + expr : expr . OP_DIV expr (10) + expr : expr . OP_MOD expr (11) + expr : expr OP_MOD expr . (11) + expr : expr . OP_AND expr (12) + expr : expr . '|' expr (13) + + OP_ADD shift 16 + OP_SUB shift 17 + OP_MUL shift 18 + OP_DIV shift 19 + OP_MOD shift 20 + OP_AND shift 21 + '|' shift 22 + '\n' reduce 11 + ')' reduce 11 + + +31: shift/reduce conflict (shift 16, reduce 12) on OP_ADD +31: shift/reduce conflict (shift 17, reduce 12) on OP_SUB +31: shift/reduce conflict (shift 18, reduce 12) on OP_MUL +31: shift/reduce conflict (shift 19, reduce 12) on OP_DIV +31: shift/reduce conflict (shift 20, reduce 12) on OP_MOD +31: shift/reduce conflict (shift 21, reduce 12) on OP_AND +31: shift/reduce conflict (shift 22, reduce 12) on '|' +state 31 + expr : expr . OP_ADD expr (7) + expr : expr . OP_SUB expr (8) + expr : expr . OP_MUL expr (9) + expr : expr . OP_DIV expr (10) + expr : expr . OP_MOD expr (11) + expr : expr . OP_AND expr (12) + expr : expr OP_AND expr . (12) + expr : expr . '|' expr (13) + + OP_ADD shift 16 + OP_SUB shift 17 + OP_MUL shift 18 + OP_DIV shift 19 + OP_MOD shift 20 + OP_AND shift 21 + '|' shift 22 + '\n' reduce 12 + ')' reduce 12 + + +32: shift/reduce conflict (shift 16, reduce 13) on OP_ADD +32: shift/reduce conflict (shift 17, reduce 13) on OP_SUB +32: shift/reduce conflict (shift 18, reduce 13) on OP_MUL +32: shift/reduce conflict (shift 19, reduce 13) on OP_DIV +32: shift/reduce conflict (shift 20, reduce 13) on OP_MOD +32: shift/reduce conflict (shift 21, reduce 13) on OP_AND +state 32 + expr : expr . OP_ADD expr (7) + expr : expr . OP_SUB expr (8) + expr : expr . OP_MUL expr (9) + expr : expr . OP_DIV expr (10) + expr : expr . OP_MOD expr (11) + expr : expr . OP_AND expr (12) + expr : expr . '|' expr (13) + expr : expr '|' expr . (13) + + OP_ADD shift 16 + OP_SUB shift 17 + OP_MUL shift 18 + OP_DIV shift 19 + OP_MOD shift 20 + OP_AND shift 21 + '|' reduce 13 + '\n' reduce 13 + ')' reduce 13 + + +State 12 contains 6 shift/reduce conflicts. +State 26 contains 7 shift/reduce conflicts. +State 27 contains 7 shift/reduce conflicts. +State 28 contains 7 shift/reduce conflicts. +State 29 contains 7 shift/reduce conflicts. +State 30 contains 7 shift/reduce conflicts. +State 31 contains 7 shift/reduce conflicts. +State 32 contains 6 shift/reduce conflicts. + + +28 terminals, 5 nonterminals +19 grammar rules, 33 states diff --git a/test/quote_calc3.tab.c b/test/quote_calc3.tab.c new file mode 100644 index 000000000000..731b4ab24b6f --- /dev/null +++ b/test/quote_calc3.tab.c @@ -0,0 +1,688 @@ +#ifndef lint +static const char yysccsid[] = "@(#)yaccpar 1.9 (Berkeley) 02/21/93"; +#endif + +#define YYBYACC 1 +#define YYMAJOR 1 +#define YYMINOR 9 + +#define YYEMPTY (-1) +#define yyclearin (yychar = YYEMPTY) +#define yyerrok (yyerrflag = 0) +#define YYRECOVERING() (yyerrflag != 0) + + +#ifndef yyparse +#define yyparse quote_calc3_parse +#endif /* yyparse */ + +#ifndef yylex +#define yylex quote_calc3_lex +#endif /* yylex */ + +#ifndef yyerror +#define yyerror quote_calc3_error +#endif /* yyerror */ + +#ifndef yychar +#define yychar quote_calc3_char +#endif /* yychar */ + +#ifndef yyval +#define yyval quote_calc3_val +#endif /* yyval */ + +#ifndef yylval +#define yylval quote_calc3_lval +#endif /* yylval */ + +#ifndef yydebug +#define yydebug quote_calc3_debug +#endif /* yydebug */ + +#ifndef yynerrs +#define yynerrs quote_calc3_nerrs +#endif /* yynerrs */ + +#ifndef yyerrflag +#define yyerrflag quote_calc3_errflag +#endif /* yyerrflag */ + +#ifndef yylhs +#define yylhs quote_calc3_lhs +#endif /* yylhs */ + +#ifndef yylen +#define yylen quote_calc3_len +#endif /* yylen */ + +#ifndef yydefred +#define yydefred quote_calc3_defred +#endif /* yydefred */ + +#ifndef yydgoto +#define yydgoto quote_calc3_dgoto +#endif /* yydgoto */ + +#ifndef yysindex +#define yysindex quote_calc3_sindex +#endif /* yysindex */ + +#ifndef yyrindex +#define yyrindex quote_calc3_rindex +#endif /* yyrindex */ + +#ifndef yygindex +#define yygindex quote_calc3_gindex +#endif /* yygindex */ + +#ifndef yytable +#define yytable quote_calc3_table +#endif /* yytable */ + +#ifndef yycheck +#define yycheck quote_calc3_check +#endif /* yycheck */ + +#ifndef yyname +#define yyname quote_calc3_name +#endif /* yyname */ + +#ifndef yyrule +#define yyrule quote_calc3_rule +#endif /* yyrule */ +#define YYPREFIX "quote_calc3_" + +#define YYPURE 0 + +#line 2 "quote_calc3.y" +# include <stdio.h> +# include <ctype.h> + +int regs[26]; +int base; + +int yylex(void); +static void yyerror(const char *s); + +#line 109 "quote_calc3.tab.c" + +#ifndef YYSTYPE +typedef int YYSTYPE; +#endif + +/* compatibility with bison */ +#ifdef YYPARSE_PARAM +/* compatibility with FreeBSD */ +# ifdef YYPARSE_PARAM_TYPE +# define YYPARSE_DECL() yyparse(YYPARSE_PARAM_TYPE YYPARSE_PARAM) +# else +# define YYPARSE_DECL() yyparse(void *YYPARSE_PARAM) +# endif +#else +# define YYPARSE_DECL() yyparse(void) +#endif + +/* Parameters sent to lex. */ +#ifdef YYLEX_PARAM +# define YYLEX_DECL() yylex(void *YYLEX_PARAM) +# define YYLEX yylex(YYLEX_PARAM) +#else +# define YYLEX_DECL() yylex(void) +# define YYLEX yylex() +#endif + +/* Parameters sent to yyerror. */ +#ifndef YYERROR_DECL +#define YYERROR_DECL() yyerror(const char *s) +#endif +#ifndef YYERROR_CALL +#define YYERROR_CALL(msg) yyerror(msg) +#endif + +extern int YYPARSE_DECL(); + +#define OP_ADD 257 +#define OP_SUB 259 +#define OP_MUL 261 +#define OP_DIV 263 +#define OP_MOD 265 +#define OP_AND 267 +#define DIGIT 269 +#define LETTER 270 +#define UMINUS 271 +#define YYERRCODE 256 +static const short quote_calc3_lhs[] = { -1, + 0, 0, 0, 1, 1, 2, 2, 2, 2, 2, + 2, 2, 2, 2, 2, 2, 3, 3, +}; +static const short quote_calc3_len[] = { 2, + 0, 3, 3, 1, 3, 3, 3, 3, 3, 3, + 3, 3, 3, 2, 1, 1, 1, 2, +}; +static const short quote_calc3_defred[] = { 1, + 0, 0, 0, 17, 0, 0, 0, 0, 0, 3, + 15, 0, 0, 0, 2, 0, 0, 0, 0, 0, + 0, 0, 18, 0, 6, 0, 0, 0, 0, 0, + 0, 0, +}; +static const short quote_calc3_dgoto[] = { 1, + 7, 8, 9, +}; +static const short quote_calc3_sindex[] = { 0, + -38, 5, -36, 0, -51, -36, 7, -121, -248, 0, + 0, -243, -36, -22, 0, -36, -36, -36, -36, -36, + -36, -36, 0, -121, 0, -121, -121, -121, -121, -121, + -121, -243, +}; +static const short quote_calc3_rindex[] = { 0, + 0, 0, 0, 0, -9, 0, 0, 13, -10, 0, + 0, -5, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 15, 0, -3, -2, -1, 1, 2, + 3, -4, +}; +static const short quote_calc3_gindex[] = { 0, + 0, 42, 0, +}; +#define YYTABLESIZE 258 +static const short quote_calc3_table[] = { 16, + 15, 6, 22, 6, 14, 13, 7, 8, 9, 13, + 10, 11, 12, 16, 10, 17, 15, 18, 25, 19, + 23, 20, 4, 21, 5, 0, 0, 0, 0, 0, + 16, 0, 0, 0, 0, 14, 13, 7, 8, 9, + 0, 10, 11, 12, 12, 0, 0, 14, 0, 0, + 0, 0, 0, 0, 24, 0, 0, 26, 27, 28, + 29, 30, 31, 32, 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, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 22, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 16, 15, 0, 0, 0, 14, 13, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 16, 0, 17, 0, 18, + 0, 19, 0, 20, 0, 21, 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, 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, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 2, 0, 0, + 3, 0, 3, 0, 0, 0, 0, 0, 0, 0, + 4, 5, 4, 11, 16, 0, 17, 0, 18, 0, + 19, 0, 20, 0, 21, 0, 16, 15, 16, 15, + 16, 15, 16, 15, 16, 15, 16, 15, +}; +static const short quote_calc3_check[] = { 10, + 10, 40, 124, 40, 10, 10, 10, 10, 10, 61, + 10, 10, 10, 257, 10, 259, 10, 261, 41, 263, + 269, 265, 10, 267, 10, -1, -1, -1, -1, -1, + 41, -1, -1, -1, -1, 41, 41, 41, 41, 41, + -1, 41, 41, 41, 3, -1, -1, 6, -1, -1, + -1, -1, -1, -1, 13, -1, -1, 16, 17, 18, + 19, 20, 21, 22, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, + -1, 124, -1, -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, 124, 124, -1, -1, -1, 124, 124, + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, 257, -1, 259, -1, 261, + -1, 263, -1, 265, -1, 267, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, 256, -1, -1, + 259, -1, 259, -1, -1, -1, -1, -1, -1, -1, + 269, 270, 269, 270, 257, -1, 259, -1, 261, -1, + 263, -1, 265, -1, 267, -1, 257, 257, 259, 259, + 261, 261, 263, 263, 265, 265, 267, 267, +}; +#define YYFINAL 1 +#ifndef YYDEBUG +#define YYDEBUG 0 +#endif +#define YYMAXTOKEN 271 +#if YYDEBUG +static const char *yyname[] = { + +"end-of-file",0,0,0,0,0,0,0,0,0,"'\\n'",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,"'-'",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,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,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,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,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,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,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,0,0,0,0,0,0, +0,0,0,0,0,0,"OP_ADD","\"ADD-operator\"","OP_SUB","\"SUB-operator\"","OP_MUL", +"\"MUL-operator\"","OP_DIV","\"DIV-operator\"","OP_MOD","\"MOD-operator\"", +"OP_AND","\"AND-operator\"","DIGIT","LETTER","UMINUS", +}; +static const char *yyrule[] = { +"$accept : list", +"list :", +"list : list stat '\\n'", +"list : list error '\\n'", +"stat : expr", +"stat : LETTER '=' expr", +"expr : '(' expr ')'", +"expr : expr OP_ADD expr", +"expr : expr OP_SUB expr", +"expr : expr OP_MUL expr", +"expr : expr OP_DIV expr", +"expr : expr OP_MOD expr", +"expr : expr OP_AND expr", +"expr : expr '|' expr", +"expr : OP_SUB expr", +"expr : LETTER", +"expr : number", +"number : DIGIT", +"number : number DIGIT", + +}; +#endif + +int yydebug; +int yynerrs; + +int yyerrflag; +int yychar; +YYSTYPE yyval; +YYSTYPE yylval; + +/* define the initial stack-sizes */ +#ifdef YYSTACKSIZE +#undef YYMAXDEPTH +#define YYMAXDEPTH YYSTACKSIZE +#else +#ifdef YYMAXDEPTH +#define YYSTACKSIZE YYMAXDEPTH +#else +#define YYSTACKSIZE 500 +#define YYMAXDEPTH 500 +#endif +#endif + +#define YYINITSTACKSIZE 500 + +typedef struct { + unsigned stacksize; + short *s_base; + short *s_mark; + short *s_last; + YYSTYPE *l_base; + YYSTYPE *l_mark; +} YYSTACKDATA; +/* variables for the parser stack */ +static YYSTACKDATA yystack; +#line 73 "quote_calc3.y" + /* start of programs */ + +int +main (void) +{ + while(!feof(stdin)) { + yyparse(); + } + return 0; +} + +static void +yyerror(const char *s) +{ + fprintf(stderr, "%s\n", s); +} + +int +yylex(void) { + /* lexical analysis routine */ + /* returns LETTER for a lower case letter, yylval = 0 through 25 */ + /* return DIGIT for a digit, yylval = 0 through 9 */ + /* all other characters are returned immediately */ + + int c; + + while( (c=getchar()) == ' ' ) { /* skip blanks */ } + + /* c is now nonblank */ + + if( islower( c )) { + yylval = c - 'a'; + return ( LETTER ); + } + if( isdigit( c )) { + yylval = c - '0'; + return ( DIGIT ); + } + return( c ); +} +#line 362 "quote_calc3.tab.c" + +#if YYDEBUG +#include <stdio.h> /* needed for printf */ +#endif + +#include <stdlib.h> /* needed for malloc, etc */ +#include <string.h> /* needed for memset */ + +/* allocate initial stack or double stack size, up to YYMAXDEPTH */ +static int yygrowstack(YYSTACKDATA *data) +{ + int i; + unsigned newsize; + short *newss; + YYSTYPE *newvs; + + if ((newsize = data->stacksize) == 0) + newsize = YYINITSTACKSIZE; + else if (newsize >= YYMAXDEPTH) + return -1; + else if ((newsize *= 2) > YYMAXDEPTH) + newsize = YYMAXDEPTH; + + i = data->s_mark - data->s_base; + newss = (short *)realloc(data->s_base, newsize * sizeof(*newss)); + if (newss == 0) + return -1; + + data->s_base = newss; + data->s_mark = newss + i; + + newvs = (YYSTYPE *)realloc(data->l_base, newsize * sizeof(*newvs)); + if (newvs == 0) + return -1; + + data->l_base = newvs; + data->l_mark = newvs + i; + + data->stacksize = newsize; + data->s_last = data->s_base + newsize - 1; + return 0; +} + +#if YYPURE || defined(YY_NO_LEAKS) +static void yyfreestack(YYSTACKDATA *data) +{ + free(data->s_base); + free(data->l_base); + memset(data, 0, sizeof(*data)); +} +#else +#define yyfreestack(data) /* nothing */ +#endif + +#define YYABORT goto yyabort +#define YYREJECT goto yyabort +#define YYACCEPT goto yyaccept +#define YYERROR goto yyerrlab + +int +YYPARSE_DECL() +{ + int yym, yyn, yystate; +#if YYDEBUG + const char *yys; + + if ((yys = getenv("YYDEBUG")) != 0) + { + yyn = *yys; + if (yyn >= '0' && yyn <= '9') + yydebug = yyn - '0'; + } +#endif + + yynerrs = 0; + yyerrflag = 0; + yychar = YYEMPTY; + yystate = 0; + +#if YYPURE + memset(&yystack, 0, sizeof(yystack)); +#endif + + if (yystack.s_base == NULL && yygrowstack(&yystack)) goto yyoverflow; + yystack.s_mark = yystack.s_base; + yystack.l_mark = yystack.l_base; + yystate = 0; + *yystack.s_mark = 0; + +yyloop: + if ((yyn = yydefred[yystate]) != 0) goto yyreduce; + if (yychar < 0) + { + if ((yychar = YYLEX) < 0) yychar = 0; +#if YYDEBUG + if (yydebug) + { + yys = 0; + if (yychar <= YYMAXTOKEN) yys = yyname[yychar]; + if (!yys) yys = "illegal-symbol"; + printf("%sdebug: state %d, reading %d (%s)\n", + YYPREFIX, yystate, yychar, yys); + } +#endif + } + if ((yyn = yysindex[yystate]) && (yyn += yychar) >= 0 && + yyn <= YYTABLESIZE && yycheck[yyn] == yychar) + { +#if YYDEBUG + if (yydebug) + printf("%sdebug: state %d, shifting to state %d\n", + YYPREFIX, yystate, yytable[yyn]); +#endif + if (yystack.s_mark >= yystack.s_last && yygrowstack(&yystack)) + { + goto yyoverflow; + } + yystate = yytable[yyn]; + *++yystack.s_mark = yytable[yyn]; + *++yystack.l_mark = yylval; + yychar = YYEMPTY; + if (yyerrflag > 0) --yyerrflag; + goto yyloop; + } + if ((yyn = yyrindex[yystate]) && (yyn += yychar) >= 0 && + yyn <= YYTABLESIZE && yycheck[yyn] == yychar) + { + yyn = yytable[yyn]; + goto yyreduce; + } + if (yyerrflag) goto yyinrecovery; + + yyerror("syntax error"); + + goto yyerrlab; + +yyerrlab: + ++yynerrs; + +yyinrecovery: + if (yyerrflag < 3) + { + yyerrflag = 3; + for (;;) + { + if ((yyn = yysindex[*yystack.s_mark]) && (yyn += YYERRCODE) >= 0 && + yyn <= YYTABLESIZE && yycheck[yyn] == YYERRCODE) + { +#if YYDEBUG + if (yydebug) + printf("%sdebug: state %d, error recovery shifting\ + to state %d\n", YYPREFIX, *yystack.s_mark, yytable[yyn]); +#endif + if (yystack.s_mark >= yystack.s_last && yygrowstack(&yystack)) + { + goto yyoverflow; + } + yystate = yytable[yyn]; + *++yystack.s_mark = yytable[yyn]; + *++yystack.l_mark = yylval; + goto yyloop; + } + else + { +#if YYDEBUG + if (yydebug) + printf("%sdebug: error recovery discarding state %d\n", + YYPREFIX, *yystack.s_mark); +#endif + if (yystack.s_mark <= yystack.s_base) goto yyabort; + --yystack.s_mark; + --yystack.l_mark; + } + } + } + else + { + if (yychar == 0) goto yyabort; +#if YYDEBUG + if (yydebug) + { + yys = 0; + if (yychar <= YYMAXTOKEN) yys = yyname[yychar]; + if (!yys) yys = "illegal-symbol"; + printf("%sdebug: state %d, error recovery discards token %d (%s)\n", + YYPREFIX, yystate, yychar, yys); + } +#endif + yychar = YYEMPTY; + goto yyloop; + } + +yyreduce: +#if YYDEBUG + if (yydebug) + printf("%sdebug: state %d, reducing by rule %d (%s)\n", + YYPREFIX, yystate, yyn, yyrule[yyn]); +#endif + yym = yylen[yyn]; + if (yym) + yyval = yystack.l_mark[1-yym]; + else + memset(&yyval, 0, sizeof yyval); + switch (yyn) + { +case 3: +#line 35 "quote_calc3.y" + { yyerrok ; } +break; +case 4: +#line 39 "quote_calc3.y" + { printf("%d\n",yystack.l_mark[0]);} +break; +case 5: +#line 41 "quote_calc3.y" + { regs[yystack.l_mark[-2]] = yystack.l_mark[0]; } +break; +case 6: +#line 45 "quote_calc3.y" + { yyval = yystack.l_mark[-1]; } +break; +case 7: +#line 47 "quote_calc3.y" + { yyval = yystack.l_mark[-2] + yystack.l_mark[0]; } +break; +case 8: +#line 49 "quote_calc3.y" + { yyval = yystack.l_mark[-2] - yystack.l_mark[0]; } +break; +case 9: +#line 51 "quote_calc3.y" + { yyval = yystack.l_mark[-2] * yystack.l_mark[0]; } +break; +case 10: +#line 53 "quote_calc3.y" + { yyval = yystack.l_mark[-2] / yystack.l_mark[0]; } +break; +case 11: +#line 55 "quote_calc3.y" + { yyval = yystack.l_mark[-2] % yystack.l_mark[0]; } +break; +case 12: +#line 57 "quote_calc3.y" + { yyval = yystack.l_mark[-2] & yystack.l_mark[0]; } +break; +case 13: +#line 59 "quote_calc3.y" + { yyval = yystack.l_mark[-2] | yystack.l_mark[0]; } +break; +case 14: +#line 61 "quote_calc3.y" + { yyval = - yystack.l_mark[0]; } +break; +case 15: +#line 63 "quote_calc3.y" + { yyval = regs[yystack.l_mark[0]]; } +break; +case 17: +#line 68 "quote_calc3.y" + { yyval = yystack.l_mark[0]; base = (yystack.l_mark[0]==0) ? 8 : 10; } +break; +case 18: +#line 70 "quote_calc3.y" + { yyval = base * yystack.l_mark[-1] + yystack.l_mark[0]; } +break; +#line 628 "quote_calc3.tab.c" + } + yystack.s_mark -= yym; + yystate = *yystack.s_mark; + yystack.l_mark -= yym; + yym = yylhs[yyn]; + if (yystate == 0 && yym == 0) + { +#if YYDEBUG + if (yydebug) + printf("%sdebug: after reduction, shifting from state 0 to\ + state %d\n", YYPREFIX, YYFINAL); +#endif + yystate = YYFINAL; + *++yystack.s_mark = YYFINAL; + *++yystack.l_mark = yyval; + if (yychar < 0) + { + if ((yychar = YYLEX) < 0) yychar = 0; +#if YYDEBUG + if (yydebug) + { + yys = 0; + if (yychar <= YYMAXTOKEN) yys = yyname[yychar]; + if (!yys) yys = "illegal-symbol"; + printf("%sdebug: state %d, reading %d (%s)\n", + YYPREFIX, YYFINAL, yychar, yys); + } +#endif + } + if (yychar == 0) goto yyaccept; + goto yyloop; + } + if ((yyn = yygindex[yym]) && (yyn += yystate) >= 0 && + yyn <= YYTABLESIZE && yycheck[yyn] == yystate) + yystate = yytable[yyn]; + else + yystate = yydgoto[yym]; +#if YYDEBUG + if (yydebug) + printf("%sdebug: after reduction, shifting from state %d \ +to state %d\n", YYPREFIX, *yystack.s_mark, yystate); +#endif + if (yystack.s_mark >= yystack.s_last && yygrowstack(&yystack)) + { + goto yyoverflow; + } + *++yystack.s_mark = (short) yystate; + *++yystack.l_mark = yyval; + goto yyloop; + +yyoverflow: + yyerror("yacc stack overflow"); + +yyabort: + yyfreestack(&yystack); + return (1); + +yyaccept: + yyfreestack(&yystack); + return (0); +} diff --git a/test/quote_calc3.tab.h b/test/quote_calc3.tab.h new file mode 100644 index 000000000000..1a4657903411 --- /dev/null +++ b/test/quote_calc3.tab.h @@ -0,0 +1,9 @@ +#define OP_ADD 257 +#define OP_SUB 259 +#define OP_MUL 261 +#define OP_DIV 263 +#define OP_MOD 265 +#define OP_AND 267 +#define DIGIT 269 +#define LETTER 270 +#define UMINUS 271 diff --git a/test/quote_calc3.y b/test/quote_calc3.y new file mode 100644 index 000000000000..5feeb4a03ed6 --- /dev/null +++ b/test/quote_calc3.y @@ -0,0 +1,112 @@ +%{ +# include <stdio.h> +# include <ctype.h> + +int regs[26]; +int base; + +int yylex(void); +static void yyerror(const char *s); + +%} + +%start list + +%token OP_ADD "ADD-operator" +%token OP_SUB "SUB-operator" +%token OP_MUL "MUL-operator" +%token OP_DIV "DIV-operator" +%token OP_MOD "MOD-operator" +%token OP_AND "AND-operator" + +%token DIGIT LETTER + +%left '|' +%left '&' +%left '+' '-' +%left '*' '/' '%' +%left UMINUS /* supplies precedence for unary minus */ + +%% /* beginning of rules section */ + +list : /* empty */ + | list stat '\n' + | list error '\n' + { yyerrok ; } + ; + +stat : expr + { printf("%d\n",$1);} + | LETTER '=' expr + { regs[$1] = $3; } + ; + +expr : '(' expr ')' + { $$ = $2; } + | expr OP_ADD expr + { $$ = $1 + $3; } + | expr OP_SUB expr + { $$ = $1 - $3; } + | expr OP_MUL expr + { $$ = $1 * $3; } + | expr OP_DIV expr + { $$ = $1 / $3; } + | expr OP_MOD expr + { $$ = $1 % $3; } + | expr OP_AND expr + { $$ = $1 & $3; } + | expr '|' expr + { $$ = $1 | $3; } + | OP_SUB expr %prec UMINUS + { $$ = - $2; } + | LETTER + { $$ = regs[$1]; } + | number + ; + +number: DIGIT + { $$ = $1; base = ($1==0) ? 8 : 10; } + | number DIGIT + { $$ = base * $1 + $2; } + ; + +%% /* start of programs */ + +int +main (void) +{ + while(!feof(stdin)) { + yyparse(); + } + return 0; +} + +static void +yyerror(const char *s) +{ + fprintf(stderr, "%s\n", s); +} + +int +yylex(void) { + /* lexical analysis routine */ + /* returns LETTER for a lower case letter, yylval = 0 through 25 */ + /* return DIGIT for a digit, yylval = 0 through 9 */ + /* all other characters are returned immediately */ + + int c; + + while( (c=getchar()) == ' ' ) { /* skip blanks */ } + + /* c is now nonblank */ + + if( islower( c )) { + yylval = c - 'a'; + return ( LETTER ); + } + if( isdigit( c )) { + yylval = c - '0'; + return ( DIGIT ); + } + return( c ); +} diff --git a/test/quote_calc4-s.output b/test/quote_calc4-s.output new file mode 100644 index 000000000000..a1d5afc95796 --- /dev/null +++ b/test/quote_calc4-s.output @@ -0,0 +1,557 @@ + 0 $accept : list $end + + 1 list : + 2 | list stat '\n' + 3 | list error '\n' + + 4 stat : expr + 5 | LETTER '=' expr + + 6 expr : '(' expr ')' + 7 | expr "ADD-operator" expr + 8 | expr "SUB-operator" expr + 9 | expr "MUL-operator" expr + 10 | expr "DIV-operator" expr + 11 | expr "MOD-operator" expr + 12 | expr "AND-operator" expr + 13 | expr '|' expr + 14 | "SUB-operator" expr + 15 | LETTER + 16 | number + + 17 number : DIGIT + 18 | number DIGIT + +state 0 + $accept : . list $end (0) + list : . (1) + + . reduce 1 + + list goto 1 + + +state 1 + $accept : list . $end (0) + list : list . stat '\n' (2) + list : list . error '\n' (3) + + $end accept + error shift 2 + "SUB-operator" shift 3 + DIGIT shift 4 + LETTER shift 5 + '(' shift 6 + . error + + stat goto 7 + expr goto 8 + number goto 9 + + +state 2 + list : list error . '\n' (3) + + '\n' shift 10 + . error + + +state 3 + expr : "SUB-operator" . expr (14) + + "SUB-operator" shift 3 + DIGIT shift 4 + LETTER shift 11 + '(' shift 6 + . error + + expr goto 12 + number goto 9 + + +state 4 + number : DIGIT . (17) + + . reduce 17 + + +state 5 + stat : LETTER . '=' expr (5) + expr : LETTER . (15) + + '=' shift 13 + "ADD-operator" reduce 15 + "SUB-operator" reduce 15 + "MUL-operator" reduce 15 + "DIV-operator" reduce 15 + "MOD-operator" reduce 15 + "AND-operator" reduce 15 + '|' reduce 15 + '\n' reduce 15 + + +state 6 + expr : '(' . expr ')' (6) + + "SUB-operator" shift 3 + DIGIT shift 4 + LETTER shift 11 + '(' shift 6 + . error + + expr goto 14 + number goto 9 + + +state 7 + list : list stat . '\n' (2) + + '\n' shift 15 + . error + + +state 8 + stat : expr . (4) + expr : expr . "ADD-operator" expr (7) + expr : expr . "SUB-operator" expr (8) + expr : expr . "MUL-operator" expr (9) + expr : expr . "DIV-operator" expr (10) + expr : expr . "MOD-operator" expr (11) + expr : expr . "AND-operator" expr (12) + expr : expr . '|' expr (13) + + "ADD-operator" shift 16 + "SUB-operator" shift 17 + "MUL-operator" shift 18 + "DIV-operator" shift 19 + "MOD-operator" shift 20 + "AND-operator" shift 21 + '|' shift 22 + '\n' reduce 4 + + +state 9 + expr : number . (16) + number : number . DIGIT (18) + + DIGIT shift 23 + "ADD-operator" reduce 16 + "SUB-operator" reduce 16 + "MUL-operator" reduce 16 + "DIV-operator" reduce 16 + "MOD-operator" reduce 16 + "AND-operator" reduce 16 + '|' reduce 16 + '\n' reduce 16 + ')' reduce 16 + + +state 10 + list : list error '\n' . (3) + + . reduce 3 + + +state 11 + expr : LETTER . (15) + + . reduce 15 + + +12: shift/reduce conflict (shift 16, reduce 14) on "ADD-operator" +12: shift/reduce conflict (shift 17, reduce 14) on "SUB-operator" +12: shift/reduce conflict (shift 18, reduce 14) on "MUL-operator" +12: shift/reduce conflict (shift 19, reduce 14) on "DIV-operator" +12: shift/reduce conflict (shift 20, reduce 14) on "MOD-operator" +12: shift/reduce conflict (shift 21, reduce 14) on "AND-operator" +state 12 + expr : expr . "ADD-operator" expr (7) + expr : expr . "SUB-operator" expr (8) + expr : expr . "MUL-operator" expr (9) + expr : expr . "DIV-operator" expr (10) + expr : expr . "MOD-operator" expr (11) + expr : expr . "AND-operator" expr (12) + expr : expr . '|' expr (13) + expr : "SUB-operator" expr . (14) + + "ADD-operator" shift 16 + "SUB-operator" shift 17 + "MUL-operator" shift 18 + "DIV-operator" shift 19 + "MOD-operator" shift 20 + "AND-operator" shift 21 + '|' reduce 14 + '\n' reduce 14 + ')' reduce 14 + + +state 13 + stat : LETTER '=' . expr (5) + + "SUB-operator" shift 3 + DIGIT shift 4 + LETTER shift 11 + '(' shift 6 + . error + + expr goto 24 + number goto 9 + + +state 14 + expr : '(' expr . ')' (6) + expr : expr . "ADD-operator" expr (7) + expr : expr . "SUB-operator" expr (8) + expr : expr . "MUL-operator" expr (9) + expr : expr . "DIV-operator" expr (10) + expr : expr . "MOD-operator" expr (11) + expr : expr . "AND-operator" expr (12) + expr : expr . '|' expr (13) + + "ADD-operator" shift 16 + "SUB-operator" shift 17 + "MUL-operator" shift 18 + "DIV-operator" shift 19 + "MOD-operator" shift 20 + "AND-operator" shift 21 + '|' shift 22 + ')' shift 25 + . error + + +state 15 + list : list stat '\n' . (2) + + . reduce 2 + + +state 16 + expr : expr "ADD-operator" . expr (7) + + "SUB-operator" shift 3 + DIGIT shift 4 + LETTER shift 11 + '(' shift 6 + . error + + expr goto 26 + number goto 9 + + +state 17 + expr : expr "SUB-operator" . expr (8) + + "SUB-operator" shift 3 + DIGIT shift 4 + LETTER shift 11 + '(' shift 6 + . error + + expr goto 27 + number goto 9 + + +state 18 + expr : expr "MUL-operator" . expr (9) + + "SUB-operator" shift 3 + DIGIT shift 4 + LETTER shift 11 + '(' shift 6 + . error + + expr goto 28 + number goto 9 + + +state 19 + expr : expr "DIV-operator" . expr (10) + + "SUB-operator" shift 3 + DIGIT shift 4 + LETTER shift 11 + '(' shift 6 + . error + + expr goto 29 + number goto 9 + + +state 20 + expr : expr "MOD-operator" . expr (11) + + "SUB-operator" shift 3 + DIGIT shift 4 + LETTER shift 11 + '(' shift 6 + . error + + expr goto 30 + number goto 9 + + +state 21 + expr : expr "AND-operator" . expr (12) + + "SUB-operator" shift 3 + DIGIT shift 4 + LETTER shift 11 + '(' shift 6 + . error + + expr goto 31 + number goto 9 + + +state 22 + expr : expr '|' . expr (13) + + "SUB-operator" shift 3 + DIGIT shift 4 + LETTER shift 11 + '(' shift 6 + . error + + expr goto 32 + number goto 9 + + +state 23 + number : number DIGIT . (18) + + . reduce 18 + + +state 24 + stat : LETTER '=' expr . (5) + expr : expr . "ADD-operator" expr (7) + expr : expr . "SUB-operator" expr (8) + expr : expr . "MUL-operator" expr (9) + expr : expr . "DIV-operator" expr (10) + expr : expr . "MOD-operator" expr (11) + expr : expr . "AND-operator" expr (12) + expr : expr . '|' expr (13) + + "ADD-operator" shift 16 + "SUB-operator" shift 17 + "MUL-operator" shift 18 + "DIV-operator" shift 19 + "MOD-operator" shift 20 + "AND-operator" shift 21 + '|' shift 22 + '\n' reduce 5 + + +state 25 + expr : '(' expr ')' . (6) + + . reduce 6 + + +26: shift/reduce conflict (shift 16, reduce 7) on "ADD-operator" +26: shift/reduce conflict (shift 17, reduce 7) on "SUB-operator" +26: shift/reduce conflict (shift 18, reduce 7) on "MUL-operator" +26: shift/reduce conflict (shift 19, reduce 7) on "DIV-operator" +26: shift/reduce conflict (shift 20, reduce 7) on "MOD-operator" +26: shift/reduce conflict (shift 21, reduce 7) on "AND-operator" +26: shift/reduce conflict (shift 22, reduce 7) on '|' +state 26 + expr : expr . "ADD-operator" expr (7) + expr : expr "ADD-operator" expr . (7) + expr : expr . "SUB-operator" expr (8) + expr : expr . "MUL-operator" expr (9) + expr : expr . "DIV-operator" expr (10) + expr : expr . "MOD-operator" expr (11) + expr : expr . "AND-operator" expr (12) + expr : expr . '|' expr (13) + + "ADD-operator" shift 16 + "SUB-operator" shift 17 + "MUL-operator" shift 18 + "DIV-operator" shift 19 + "MOD-operator" shift 20 + "AND-operator" shift 21 + '|' shift 22 + '\n' reduce 7 + ')' reduce 7 + + +27: shift/reduce conflict (shift 16, reduce 8) on "ADD-operator" +27: shift/reduce conflict (shift 17, reduce 8) on "SUB-operator" +27: shift/reduce conflict (shift 18, reduce 8) on "MUL-operator" +27: shift/reduce conflict (shift 19, reduce 8) on "DIV-operator" +27: shift/reduce conflict (shift 20, reduce 8) on "MOD-operator" +27: shift/reduce conflict (shift 21, reduce 8) on "AND-operator" +27: shift/reduce conflict (shift 22, reduce 8) on '|' +state 27 + expr : expr . "ADD-operator" expr (7) + expr : expr . "SUB-operator" expr (8) + expr : expr "SUB-operator" expr . (8) + expr : expr . "MUL-operator" expr (9) + expr : expr . "DIV-operator" expr (10) + expr : expr . "MOD-operator" expr (11) + expr : expr . "AND-operator" expr (12) + expr : expr . '|' expr (13) + + "ADD-operator" shift 16 + "SUB-operator" shift 17 + "MUL-operator" shift 18 + "DIV-operator" shift 19 + "MOD-operator" shift 20 + "AND-operator" shift 21 + '|' shift 22 + '\n' reduce 8 + ')' reduce 8 + + +28: shift/reduce conflict (shift 16, reduce 9) on "ADD-operator" +28: shift/reduce conflict (shift 17, reduce 9) on "SUB-operator" +28: shift/reduce conflict (shift 18, reduce 9) on "MUL-operator" +28: shift/reduce conflict (shift 19, reduce 9) on "DIV-operator" +28: shift/reduce conflict (shift 20, reduce 9) on "MOD-operator" +28: shift/reduce conflict (shift 21, reduce 9) on "AND-operator" +28: shift/reduce conflict (shift 22, reduce 9) on '|' +state 28 + expr : expr . "ADD-operator" expr (7) + expr : expr . "SUB-operator" expr (8) + expr : expr . "MUL-operator" expr (9) + expr : expr "MUL-operator" expr . (9) + expr : expr . "DIV-operator" expr (10) + expr : expr . "MOD-operator" expr (11) + expr : expr . "AND-operator" expr (12) + expr : expr . '|' expr (13) + + "ADD-operator" shift 16 + "SUB-operator" shift 17 + "MUL-operator" shift 18 + "DIV-operator" shift 19 + "MOD-operator" shift 20 + "AND-operator" shift 21 + '|' shift 22 + '\n' reduce 9 + ')' reduce 9 + + +29: shift/reduce conflict (shift 16, reduce 10) on "ADD-operator" +29: shift/reduce conflict (shift 17, reduce 10) on "SUB-operator" +29: shift/reduce conflict (shift 18, reduce 10) on "MUL-operator" +29: shift/reduce conflict (shift 19, reduce 10) on "DIV-operator" +29: shift/reduce conflict (shift 20, reduce 10) on "MOD-operator" +29: shift/reduce conflict (shift 21, reduce 10) on "AND-operator" +29: shift/reduce conflict (shift 22, reduce 10) on '|' +state 29 + expr : expr . "ADD-operator" expr (7) + expr : expr . "SUB-operator" expr (8) + expr : expr . "MUL-operator" expr (9) + expr : expr . "DIV-operator" expr (10) + expr : expr "DIV-operator" expr . (10) + expr : expr . "MOD-operator" expr (11) + expr : expr . "AND-operator" expr (12) + expr : expr . '|' expr (13) + + "ADD-operator" shift 16 + "SUB-operator" shift 17 + "MUL-operator" shift 18 + "DIV-operator" shift 19 + "MOD-operator" shift 20 + "AND-operator" shift 21 + '|' shift 22 + '\n' reduce 10 + ')' reduce 10 + + +30: shift/reduce conflict (shift 16, reduce 11) on "ADD-operator" +30: shift/reduce conflict (shift 17, reduce 11) on "SUB-operator" +30: shift/reduce conflict (shift 18, reduce 11) on "MUL-operator" +30: shift/reduce conflict (shift 19, reduce 11) on "DIV-operator" +30: shift/reduce conflict (shift 20, reduce 11) on "MOD-operator" +30: shift/reduce conflict (shift 21, reduce 11) on "AND-operator" +30: shift/reduce conflict (shift 22, reduce 11) on '|' +state 30 + expr : expr . "ADD-operator" expr (7) + expr : expr . "SUB-operator" expr (8) + expr : expr . "MUL-operator" expr (9) + expr : expr . "DIV-operator" expr (10) + expr : expr . "MOD-operator" expr (11) + expr : expr "MOD-operator" expr . (11) + expr : expr . "AND-operator" expr (12) + expr : expr . '|' expr (13) + + "ADD-operator" shift 16 + "SUB-operator" shift 17 + "MUL-operator" shift 18 + "DIV-operator" shift 19 + "MOD-operator" shift 20 + "AND-operator" shift 21 + '|' shift 22 + '\n' reduce 11 + ')' reduce 11 + + +31: shift/reduce conflict (shift 16, reduce 12) on "ADD-operator" +31: shift/reduce conflict (shift 17, reduce 12) on "SUB-operator" +31: shift/reduce conflict (shift 18, reduce 12) on "MUL-operator" +31: shift/reduce conflict (shift 19, reduce 12) on "DIV-operator" +31: shift/reduce conflict (shift 20, reduce 12) on "MOD-operator" +31: shift/reduce conflict (shift 21, reduce 12) on "AND-operator" +31: shift/reduce conflict (shift 22, reduce 12) on '|' +state 31 + expr : expr . "ADD-operator" expr (7) + expr : expr . "SUB-operator" expr (8) + expr : expr . "MUL-operator" expr (9) + expr : expr . "DIV-operator" expr (10) + expr : expr . "MOD-operator" expr (11) + expr : expr . "AND-operator" expr (12) + expr : expr "AND-operator" expr . (12) + expr : expr . '|' expr (13) + + "ADD-operator" shift 16 + "SUB-operator" shift 17 + "MUL-operator" shift 18 + "DIV-operator" shift 19 + "MOD-operator" shift 20 + "AND-operator" shift 21 + '|' shift 22 + '\n' reduce 12 + ')' reduce 12 + + +32: shift/reduce conflict (shift 16, reduce 13) on "ADD-operator" +32: shift/reduce conflict (shift 17, reduce 13) on "SUB-operator" +32: shift/reduce conflict (shift 18, reduce 13) on "MUL-operator" +32: shift/reduce conflict (shift 19, reduce 13) on "DIV-operator" +32: shift/reduce conflict (shift 20, reduce 13) on "MOD-operator" +32: shift/reduce conflict (shift 21, reduce 13) on "AND-operator" +state 32 + expr : expr . "ADD-operator" expr (7) + expr : expr . "SUB-operator" expr (8) + expr : expr . "MUL-operator" expr (9) + expr : expr . "DIV-operator" expr (10) + expr : expr . "MOD-operator" expr (11) + expr : expr . "AND-operator" expr (12) + expr : expr . '|' expr (13) + expr : expr '|' expr . (13) + + "ADD-operator" shift 16 + "SUB-operator" shift 17 + "MUL-operator" shift 18 + "DIV-operator" shift 19 + "MOD-operator" shift 20 + "AND-operator" shift 21 + '|' reduce 13 + '\n' reduce 13 + ')' reduce 13 + + +State 12 contains 6 shift/reduce conflicts. +State 26 contains 7 shift/reduce conflicts. +State 27 contains 7 shift/reduce conflicts. +State 28 contains 7 shift/reduce conflicts. +State 29 contains 7 shift/reduce conflicts. +State 30 contains 7 shift/reduce conflicts. +State 31 contains 7 shift/reduce conflicts. +State 32 contains 6 shift/reduce conflicts. + + +28 terminals, 5 nonterminals +19 grammar rules, 33 states diff --git a/test/quote_calc4-s.tab.c b/test/quote_calc4-s.tab.c new file mode 100644 index 000000000000..29e176a61ac6 --- /dev/null +++ b/test/quote_calc4-s.tab.c @@ -0,0 +1,688 @@ +#ifndef lint +static const char yysccsid[] = "@(#)yaccpar 1.9 (Berkeley) 02/21/93"; +#endif + +#define YYBYACC 1 +#define YYMAJOR 1 +#define YYMINOR 9 + +#define YYEMPTY (-1) +#define yyclearin (yychar = YYEMPTY) +#define yyerrok (yyerrflag = 0) +#define YYRECOVERING() (yyerrflag != 0) + + +#ifndef yyparse +#define yyparse quote_calc4_parse +#endif /* yyparse */ + +#ifndef yylex +#define yylex quote_calc4_lex +#endif /* yylex */ + +#ifndef yyerror +#define yyerror quote_calc4_error +#endif /* yyerror */ + +#ifndef yychar +#define yychar quote_calc4_char +#endif /* yychar */ + +#ifndef yyval +#define yyval quote_calc4_val +#endif /* yyval */ + +#ifndef yylval +#define yylval quote_calc4_lval +#endif /* yylval */ + +#ifndef yydebug +#define yydebug quote_calc4_debug +#endif /* yydebug */ + +#ifndef yynerrs +#define yynerrs quote_calc4_nerrs +#endif /* yynerrs */ + +#ifndef yyerrflag +#define yyerrflag quote_calc4_errflag +#endif /* yyerrflag */ + +#ifndef yylhs +#define yylhs quote_calc4_lhs +#endif /* yylhs */ + +#ifndef yylen +#define yylen quote_calc4_len +#endif /* yylen */ + +#ifndef yydefred +#define yydefred quote_calc4_defred +#endif /* yydefred */ + +#ifndef yydgoto +#define yydgoto quote_calc4_dgoto +#endif /* yydgoto */ + +#ifndef yysindex +#define yysindex quote_calc4_sindex +#endif /* yysindex */ + +#ifndef yyrindex +#define yyrindex quote_calc4_rindex +#endif /* yyrindex */ + +#ifndef yygindex +#define yygindex quote_calc4_gindex +#endif /* yygindex */ + +#ifndef yytable +#define yytable quote_calc4_table +#endif /* yytable */ + +#ifndef yycheck +#define yycheck quote_calc4_check +#endif /* yycheck */ + +#ifndef yyname +#define yyname quote_calc4_name +#endif /* yyname */ + +#ifndef yyrule +#define yyrule quote_calc4_rule +#endif /* yyrule */ +#define YYPREFIX "quote_calc4_" + +#define YYPURE 0 + +#line 2 "quote_calc4.y" +# include <stdio.h> +# include <ctype.h> + +int regs[26]; +int base; + +int yylex(void); +static void yyerror(const char *s); + +#line 109 "quote_calc4-s.tab.c" + +#ifndef YYSTYPE +typedef int YYSTYPE; +#endif + +/* compatibility with bison */ +#ifdef YYPARSE_PARAM +/* compatibility with FreeBSD */ +# ifdef YYPARSE_PARAM_TYPE +# define YYPARSE_DECL() yyparse(YYPARSE_PARAM_TYPE YYPARSE_PARAM) +# else +# define YYPARSE_DECL() yyparse(void *YYPARSE_PARAM) +# endif +#else +# define YYPARSE_DECL() yyparse(void) +#endif + +/* Parameters sent to lex. */ +#ifdef YYLEX_PARAM +# define YYLEX_DECL() yylex(void *YYLEX_PARAM) +# define YYLEX yylex(YYLEX_PARAM) +#else +# define YYLEX_DECL() yylex(void) +# define YYLEX yylex() +#endif + +/* Parameters sent to yyerror. */ +#ifndef YYERROR_DECL +#define YYERROR_DECL() yyerror(const char *s) +#endif +#ifndef YYERROR_CALL +#define YYERROR_CALL(msg) yyerror(msg) +#endif + +extern int YYPARSE_DECL(); + +#define OP_ADD 257 +#define OP_SUB 259 +#define OP_MUL 261 +#define OP_DIV 263 +#define OP_MOD 265 +#define OP_AND 267 +#define DIGIT 269 +#define LETTER 270 +#define UMINUS 271 +#define YYERRCODE 256 +static const short quote_calc4_lhs[] = { -1, + 0, 0, 0, 1, 1, 2, 2, 2, 2, 2, + 2, 2, 2, 2, 2, 2, 3, 3, +}; +static const short quote_calc4_len[] = { 2, + 0, 3, 3, 1, 3, 3, 3, 3, 3, 3, + 3, 3, 3, 2, 1, 1, 1, 2, +}; +static const short quote_calc4_defred[] = { 1, + 0, 0, 0, 17, 0, 0, 0, 0, 0, 3, + 15, 0, 0, 0, 2, 0, 0, 0, 0, 0, + 0, 0, 18, 0, 6, 0, 0, 0, 0, 0, + 0, 0, +}; +static const short quote_calc4_dgoto[] = { 1, + 7, 8, 9, +}; +static const short quote_calc4_sindex[] = { 0, + -38, 4, -36, 0, -51, -36, 6, -121, -249, 0, + 0, -243, -36, -23, 0, -36, -36, -36, -36, -36, + -36, -36, 0, -121, 0, -121, -121, -121, -121, -121, + -121, -243, +}; +static const short quote_calc4_rindex[] = { 0, + 0, 0, 0, 0, -9, 0, 0, 12, -10, 0, + 0, -5, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 14, 0, -3, -2, -1, 1, 2, + 3, -4, +}; +static const short quote_calc4_gindex[] = { 0, + 0, 42, 0, +}; +#define YYTABLESIZE 259 +static const short quote_calc4_table[] = { 16, + 15, 6, 22, 6, 14, 13, 7, 8, 9, 13, + 10, 11, 12, 10, 16, 15, 17, 25, 18, 23, + 19, 4, 20, 5, 21, 0, 0, 0, 0, 0, + 16, 0, 0, 0, 0, 14, 13, 7, 8, 9, + 0, 10, 11, 12, 12, 0, 0, 14, 0, 0, + 0, 0, 0, 0, 24, 0, 0, 26, 27, 28, + 29, 30, 31, 32, 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, 0, 0, 0, 0, 0, 0, 0, 0, + 22, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 16, 15, 0, 0, 0, 14, 13, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 16, 0, 17, 0, + 18, 0, 19, 0, 20, 0, 21, 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, 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, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 2, 0, 0, + 0, 3, 0, 3, 0, 0, 0, 0, 0, 0, + 4, 5, 4, 11, 16, 0, 17, 0, 18, 0, + 19, 0, 20, 0, 21, 0, 0, 16, 15, 16, + 15, 16, 15, 16, 15, 16, 15, 16, 15, +}; +static const short quote_calc4_check[] = { 10, + 10, 40, 124, 40, 10, 10, 10, 10, 10, 61, + 10, 10, 10, 10, 258, 10, 260, 41, 262, 269, + 264, 10, 266, 10, 268, -1, -1, -1, -1, -1, + 41, -1, -1, -1, -1, 41, 41, 41, 41, 41, + -1, 41, 41, 41, 3, -1, -1, 6, -1, -1, + -1, -1, -1, -1, 13, -1, -1, 16, 17, 18, + 19, 20, 21, 22, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, + 124, -1, -1, -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, 124, 124, -1, -1, -1, 124, 124, + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, 258, -1, 260, -1, + 262, -1, 264, -1, 266, -1, 268, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, 256, -1, -1, + -1, 260, -1, 260, -1, -1, -1, -1, -1, -1, + 269, 270, 269, 270, 258, -1, 260, -1, 262, -1, + 264, -1, 266, -1, 268, -1, -1, 258, 258, 260, + 260, 262, 262, 264, 264, 266, 266, 268, 268, +}; +#define YYFINAL 1 +#ifndef YYDEBUG +#define YYDEBUG 0 +#endif +#define YYMAXTOKEN 271 +#if YYDEBUG +static const char *yyname[] = { + +"end-of-file",0,0,0,0,0,0,0,0,0,"'\\n'",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,"'-'",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,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,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,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,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,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,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,0,0,0,0,0,0, +0,0,0,0,0,0,"OP_ADD","\"ADD-operator\"","OP_SUB","\"SUB-operator\"","OP_MUL", +"\"MUL-operator\"","OP_DIV","\"DIV-operator\"","OP_MOD","\"MOD-operator\"", +"OP_AND","\"AND-operator\"","DIGIT","LETTER","UMINUS", +}; +static const char *yyrule[] = { +"$accept : list", +"list :", +"list : list stat '\\n'", +"list : list error '\\n'", +"stat : expr", +"stat : LETTER '=' expr", +"expr : '(' expr ')'", +"expr : expr \"ADD-operator\" expr", +"expr : expr \"SUB-operator\" expr", +"expr : expr \"MUL-operator\" expr", +"expr : expr \"DIV-operator\" expr", +"expr : expr \"MOD-operator\" expr", +"expr : expr \"AND-operator\" expr", +"expr : expr '|' expr", +"expr : \"SUB-operator\" expr", +"expr : LETTER", +"expr : number", +"number : DIGIT", +"number : number DIGIT", + +}; +#endif + +int yydebug; +int yynerrs; + +int yyerrflag; +int yychar; +YYSTYPE yyval; +YYSTYPE yylval; + +/* define the initial stack-sizes */ +#ifdef YYSTACKSIZE +#undef YYMAXDEPTH +#define YYMAXDEPTH YYSTACKSIZE +#else +#ifdef YYMAXDEPTH +#define YYSTACKSIZE YYMAXDEPTH +#else +#define YYSTACKSIZE 500 +#define YYMAXDEPTH 500 +#endif +#endif + +#define YYINITSTACKSIZE 500 + +typedef struct { + unsigned stacksize; + short *s_base; + short *s_mark; + short *s_last; + YYSTYPE *l_base; + YYSTYPE *l_mark; +} YYSTACKDATA; +/* variables for the parser stack */ +static YYSTACKDATA yystack; +#line 73 "quote_calc4.y" + /* start of programs */ + +int +main (void) +{ + while(!feof(stdin)) { + yyparse(); + } + return 0; +} + +static void +yyerror(const char *s) +{ + fprintf(stderr, "%s\n", s); +} + +int +yylex(void) { + /* lexical analysis routine */ + /* returns LETTER for a lower case letter, yylval = 0 through 25 */ + /* return DIGIT for a digit, yylval = 0 through 9 */ + /* all other characters are returned immediately */ + + int c; + + while( (c=getchar()) == ' ' ) { /* skip blanks */ } + + /* c is now nonblank */ + + if( islower( c )) { + yylval = c - 'a'; + return ( LETTER ); + } + if( isdigit( c )) { + yylval = c - '0'; + return ( DIGIT ); + } + return( c ); +} +#line 362 "quote_calc4-s.tab.c" + +#if YYDEBUG +#include <stdio.h> /* needed for printf */ +#endif + +#include <stdlib.h> /* needed for malloc, etc */ +#include <string.h> /* needed for memset */ + +/* allocate initial stack or double stack size, up to YYMAXDEPTH */ +static int yygrowstack(YYSTACKDATA *data) +{ + int i; + unsigned newsize; + short *newss; + YYSTYPE *newvs; + + if ((newsize = data->stacksize) == 0) + newsize = YYINITSTACKSIZE; + else if (newsize >= YYMAXDEPTH) + return -1; + else if ((newsize *= 2) > YYMAXDEPTH) + newsize = YYMAXDEPTH; + + i = data->s_mark - data->s_base; + newss = (short *)realloc(data->s_base, newsize * sizeof(*newss)); + if (newss == 0) + return -1; + + data->s_base = newss; + data->s_mark = newss + i; + + newvs = (YYSTYPE *)realloc(data->l_base, newsize * sizeof(*newvs)); + if (newvs == 0) + return -1; + + data->l_base = newvs; + data->l_mark = newvs + i; + + data->stacksize = newsize; + data->s_last = data->s_base + newsize - 1; + return 0; +} + +#if YYPURE || defined(YY_NO_LEAKS) +static void yyfreestack(YYSTACKDATA *data) +{ + free(data->s_base); + free(data->l_base); + memset(data, 0, sizeof(*data)); +} +#else +#define yyfreestack(data) /* nothing */ +#endif + +#define YYABORT goto yyabort +#define YYREJECT goto yyabort +#define YYACCEPT goto yyaccept +#define YYERROR goto yyerrlab + +int +YYPARSE_DECL() +{ + int yym, yyn, yystate; +#if YYDEBUG + const char *yys; + + if ((yys = getenv("YYDEBUG")) != 0) + { + yyn = *yys; + if (yyn >= '0' && yyn <= '9') + yydebug = yyn - '0'; + } +#endif + + yynerrs = 0; + yyerrflag = 0; + yychar = YYEMPTY; + yystate = 0; + +#if YYPURE + memset(&yystack, 0, sizeof(yystack)); +#endif + + if (yystack.s_base == NULL && yygrowstack(&yystack)) goto yyoverflow; + yystack.s_mark = yystack.s_base; + yystack.l_mark = yystack.l_base; + yystate = 0; + *yystack.s_mark = 0; + +yyloop: + if ((yyn = yydefred[yystate]) != 0) goto yyreduce; + if (yychar < 0) + { + if ((yychar = YYLEX) < 0) yychar = 0; +#if YYDEBUG + if (yydebug) + { + yys = 0; + if (yychar <= YYMAXTOKEN) yys = yyname[yychar]; + if (!yys) yys = "illegal-symbol"; + printf("%sdebug: state %d, reading %d (%s)\n", + YYPREFIX, yystate, yychar, yys); + } +#endif + } + if ((yyn = yysindex[yystate]) && (yyn += yychar) >= 0 && + yyn <= YYTABLESIZE && yycheck[yyn] == yychar) + { +#if YYDEBUG + if (yydebug) + printf("%sdebug: state %d, shifting to state %d\n", + YYPREFIX, yystate, yytable[yyn]); +#endif + if (yystack.s_mark >= yystack.s_last && yygrowstack(&yystack)) + { + goto yyoverflow; + } + yystate = yytable[yyn]; + *++yystack.s_mark = yytable[yyn]; + *++yystack.l_mark = yylval; + yychar = YYEMPTY; + if (yyerrflag > 0) --yyerrflag; + goto yyloop; + } + if ((yyn = yyrindex[yystate]) && (yyn += yychar) >= 0 && + yyn <= YYTABLESIZE && yycheck[yyn] == yychar) + { + yyn = yytable[yyn]; + goto yyreduce; + } + if (yyerrflag) goto yyinrecovery; + + yyerror("syntax error"); + + goto yyerrlab; + +yyerrlab: + ++yynerrs; + +yyinrecovery: + if (yyerrflag < 3) + { + yyerrflag = 3; + for (;;) + { + if ((yyn = yysindex[*yystack.s_mark]) && (yyn += YYERRCODE) >= 0 && + yyn <= YYTABLESIZE && yycheck[yyn] == YYERRCODE) + { +#if YYDEBUG + if (yydebug) + printf("%sdebug: state %d, error recovery shifting\ + to state %d\n", YYPREFIX, *yystack.s_mark, yytable[yyn]); +#endif + if (yystack.s_mark >= yystack.s_last && yygrowstack(&yystack)) + { + goto yyoverflow; + } + yystate = yytable[yyn]; + *++yystack.s_mark = yytable[yyn]; + *++yystack.l_mark = yylval; + goto yyloop; + } + else + { +#if YYDEBUG + if (yydebug) + printf("%sdebug: error recovery discarding state %d\n", + YYPREFIX, *yystack.s_mark); +#endif + if (yystack.s_mark <= yystack.s_base) goto yyabort; + --yystack.s_mark; + --yystack.l_mark; + } + } + } + else + { + if (yychar == 0) goto yyabort; +#if YYDEBUG + if (yydebug) + { + yys = 0; + if (yychar <= YYMAXTOKEN) yys = yyname[yychar]; + if (!yys) yys = "illegal-symbol"; + printf("%sdebug: state %d, error recovery discards token %d (%s)\n", + YYPREFIX, yystate, yychar, yys); + } +#endif + yychar = YYEMPTY; + goto yyloop; + } + +yyreduce: +#if YYDEBUG + if (yydebug) + printf("%sdebug: state %d, reducing by rule %d (%s)\n", + YYPREFIX, yystate, yyn, yyrule[yyn]); +#endif + yym = yylen[yyn]; + if (yym) + yyval = yystack.l_mark[1-yym]; + else + memset(&yyval, 0, sizeof yyval); + switch (yyn) + { +case 3: +#line 35 "quote_calc4.y" + { yyerrok ; } +break; +case 4: +#line 39 "quote_calc4.y" + { printf("%d\n",yystack.l_mark[0]);} +break; +case 5: +#line 41 "quote_calc4.y" + { regs[yystack.l_mark[-2]] = yystack.l_mark[0]; } +break; +case 6: +#line 45 "quote_calc4.y" + { yyval = yystack.l_mark[-1]; } +break; +case 7: +#line 47 "quote_calc4.y" + { yyval = yystack.l_mark[-2] + yystack.l_mark[0]; } +break; +case 8: +#line 49 "quote_calc4.y" + { yyval = yystack.l_mark[-2] - yystack.l_mark[0]; } +break; +case 9: +#line 51 "quote_calc4.y" + { yyval = yystack.l_mark[-2] * yystack.l_mark[0]; } +break; +case 10: +#line 53 "quote_calc4.y" + { yyval = yystack.l_mark[-2] / yystack.l_mark[0]; } +break; +case 11: +#line 55 "quote_calc4.y" + { yyval = yystack.l_mark[-2] % yystack.l_mark[0]; } +break; +case 12: +#line 57 "quote_calc4.y" + { yyval = yystack.l_mark[-2] & yystack.l_mark[0]; } +break; +case 13: +#line 59 "quote_calc4.y" + { yyval = yystack.l_mark[-2] | yystack.l_mark[0]; } +break; +case 14: +#line 61 "quote_calc4.y" + { yyval = - yystack.l_mark[0]; } +break; +case 15: +#line 63 "quote_calc4.y" + { yyval = regs[yystack.l_mark[0]]; } +break; +case 17: +#line 68 "quote_calc4.y" + { yyval = yystack.l_mark[0]; base = (yystack.l_mark[0]==0) ? 8 : 10; } +break; +case 18: +#line 70 "quote_calc4.y" + { yyval = base * yystack.l_mark[-1] + yystack.l_mark[0]; } +break; +#line 628 "quote_calc4-s.tab.c" + } + yystack.s_mark -= yym; + yystate = *yystack.s_mark; + yystack.l_mark -= yym; + yym = yylhs[yyn]; + if (yystate == 0 && yym == 0) + { +#if YYDEBUG + if (yydebug) + printf("%sdebug: after reduction, shifting from state 0 to\ + state %d\n", YYPREFIX, YYFINAL); +#endif + yystate = YYFINAL; + *++yystack.s_mark = YYFINAL; + *++yystack.l_mark = yyval; + if (yychar < 0) + { + if ((yychar = YYLEX) < 0) yychar = 0; +#if YYDEBUG + if (yydebug) + { + yys = 0; + if (yychar <= YYMAXTOKEN) yys = yyname[yychar]; + if (!yys) yys = "illegal-symbol"; + printf("%sdebug: state %d, reading %d (%s)\n", + YYPREFIX, YYFINAL, yychar, yys); + } +#endif + } + if (yychar == 0) goto yyaccept; + goto yyloop; + } + if ((yyn = yygindex[yym]) && (yyn += yystate) >= 0 && + yyn <= YYTABLESIZE && yycheck[yyn] == yystate) + yystate = yytable[yyn]; + else + yystate = yydgoto[yym]; +#if YYDEBUG + if (yydebug) + printf("%sdebug: after reduction, shifting from state %d \ +to state %d\n", YYPREFIX, *yystack.s_mark, yystate); +#endif + if (yystack.s_mark >= yystack.s_last && yygrowstack(&yystack)) + { + goto yyoverflow; + } + *++yystack.s_mark = (short) yystate; + *++yystack.l_mark = yyval; + goto yyloop; + +yyoverflow: + yyerror("yacc stack overflow"); + +yyabort: + yyfreestack(&yystack); + return (1); + +yyaccept: + yyfreestack(&yystack); + return (0); +} diff --git a/test/quote_calc4-s.tab.h b/test/quote_calc4-s.tab.h new file mode 100644 index 000000000000..1a4657903411 --- /dev/null +++ b/test/quote_calc4-s.tab.h @@ -0,0 +1,9 @@ +#define OP_ADD 257 +#define OP_SUB 259 +#define OP_MUL 261 +#define OP_DIV 263 +#define OP_MOD 265 +#define OP_AND 267 +#define DIGIT 269 +#define LETTER 270 +#define UMINUS 271 diff --git a/test/quote_calc4.output b/test/quote_calc4.output new file mode 100644 index 000000000000..a1d5afc95796 --- /dev/null +++ b/test/quote_calc4.output @@ -0,0 +1,557 @@ + 0 $accept : list $end + + 1 list : + 2 | list stat '\n' + 3 | list error '\n' + + 4 stat : expr + 5 | LETTER '=' expr + + 6 expr : '(' expr ')' + 7 | expr "ADD-operator" expr + 8 | expr "SUB-operator" expr + 9 | expr "MUL-operator" expr + 10 | expr "DIV-operator" expr + 11 | expr "MOD-operator" expr + 12 | expr "AND-operator" expr + 13 | expr '|' expr + 14 | "SUB-operator" expr + 15 | LETTER + 16 | number + + 17 number : DIGIT + 18 | number DIGIT + +state 0 + $accept : . list $end (0) + list : . (1) + + . reduce 1 + + list goto 1 + + +state 1 + $accept : list . $end (0) + list : list . stat '\n' (2) + list : list . error '\n' (3) + + $end accept + error shift 2 + "SUB-operator" shift 3 + DIGIT shift 4 + LETTER shift 5 + '(' shift 6 + . error + + stat goto 7 + expr goto 8 + number goto 9 + + +state 2 + list : list error . '\n' (3) + + '\n' shift 10 + . error + + +state 3 + expr : "SUB-operator" . expr (14) + + "SUB-operator" shift 3 + DIGIT shift 4 + LETTER shift 11 + '(' shift 6 + . error + + expr goto 12 + number goto 9 + + +state 4 + number : DIGIT . (17) + + . reduce 17 + + +state 5 + stat : LETTER . '=' expr (5) + expr : LETTER . (15) + + '=' shift 13 + "ADD-operator" reduce 15 + "SUB-operator" reduce 15 + "MUL-operator" reduce 15 + "DIV-operator" reduce 15 + "MOD-operator" reduce 15 + "AND-operator" reduce 15 + '|' reduce 15 + '\n' reduce 15 + + +state 6 + expr : '(' . expr ')' (6) + + "SUB-operator" shift 3 + DIGIT shift 4 + LETTER shift 11 + '(' shift 6 + . error + + expr goto 14 + number goto 9 + + +state 7 + list : list stat . '\n' (2) + + '\n' shift 15 + . error + + +state 8 + stat : expr . (4) + expr : expr . "ADD-operator" expr (7) + expr : expr . "SUB-operator" expr (8) + expr : expr . "MUL-operator" expr (9) + expr : expr . "DIV-operator" expr (10) + expr : expr . "MOD-operator" expr (11) + expr : expr . "AND-operator" expr (12) + expr : expr . '|' expr (13) + + "ADD-operator" shift 16 + "SUB-operator" shift 17 + "MUL-operator" shift 18 + "DIV-operator" shift 19 + "MOD-operator" shift 20 + "AND-operator" shift 21 + '|' shift 22 + '\n' reduce 4 + + +state 9 + expr : number . (16) + number : number . DIGIT (18) + + DIGIT shift 23 + "ADD-operator" reduce 16 + "SUB-operator" reduce 16 + "MUL-operator" reduce 16 + "DIV-operator" reduce 16 + "MOD-operator" reduce 16 + "AND-operator" reduce 16 + '|' reduce 16 + '\n' reduce 16 + ')' reduce 16 + + +state 10 + list : list error '\n' . (3) + + . reduce 3 + + +state 11 + expr : LETTER . (15) + + . reduce 15 + + +12: shift/reduce conflict (shift 16, reduce 14) on "ADD-operator" +12: shift/reduce conflict (shift 17, reduce 14) on "SUB-operator" +12: shift/reduce conflict (shift 18, reduce 14) on "MUL-operator" +12: shift/reduce conflict (shift 19, reduce 14) on "DIV-operator" +12: shift/reduce conflict (shift 20, reduce 14) on "MOD-operator" +12: shift/reduce conflict (shift 21, reduce 14) on "AND-operator" +state 12 + expr : expr . "ADD-operator" expr (7) + expr : expr . "SUB-operator" expr (8) + expr : expr . "MUL-operator" expr (9) + expr : expr . "DIV-operator" expr (10) + expr : expr . "MOD-operator" expr (11) + expr : expr . "AND-operator" expr (12) + expr : expr . '|' expr (13) + expr : "SUB-operator" expr . (14) + + "ADD-operator" shift 16 + "SUB-operator" shift 17 + "MUL-operator" shift 18 + "DIV-operator" shift 19 + "MOD-operator" shift 20 + "AND-operator" shift 21 + '|' reduce 14 + '\n' reduce 14 + ')' reduce 14 + + +state 13 + stat : LETTER '=' . expr (5) + + "SUB-operator" shift 3 + DIGIT shift 4 + LETTER shift 11 + '(' shift 6 + . error + + expr goto 24 + number goto 9 + + +state 14 + expr : '(' expr . ')' (6) + expr : expr . "ADD-operator" expr (7) + expr : expr . "SUB-operator" expr (8) + expr : expr . "MUL-operator" expr (9) + expr : expr . "DIV-operator" expr (10) + expr : expr . "MOD-operator" expr (11) + expr : expr . "AND-operator" expr (12) + expr : expr . '|' expr (13) + + "ADD-operator" shift 16 + "SUB-operator" shift 17 + "MUL-operator" shift 18 + "DIV-operator" shift 19 + "MOD-operator" shift 20 + "AND-operator" shift 21 + '|' shift 22 + ')' shift 25 + . error + + +state 15 + list : list stat '\n' . (2) + + . reduce 2 + + +state 16 + expr : expr "ADD-operator" . expr (7) + + "SUB-operator" shift 3 + DIGIT shift 4 + LETTER shift 11 + '(' shift 6 + . error + + expr goto 26 + number goto 9 + + +state 17 + expr : expr "SUB-operator" . expr (8) + + "SUB-operator" shift 3 + DIGIT shift 4 + LETTER shift 11 + '(' shift 6 + . error + + expr goto 27 + number goto 9 + + +state 18 + expr : expr "MUL-operator" . expr (9) + + "SUB-operator" shift 3 + DIGIT shift 4 + LETTER shift 11 + '(' shift 6 + . error + + expr goto 28 + number goto 9 + + +state 19 + expr : expr "DIV-operator" . expr (10) + + "SUB-operator" shift 3 + DIGIT shift 4 + LETTER shift 11 + '(' shift 6 + . error + + expr goto 29 + number goto 9 + + +state 20 + expr : expr "MOD-operator" . expr (11) + + "SUB-operator" shift 3 + DIGIT shift 4 + LETTER shift 11 + '(' shift 6 + . error + + expr goto 30 + number goto 9 + + +state 21 + expr : expr "AND-operator" . expr (12) + + "SUB-operator" shift 3 + DIGIT shift 4 + LETTER shift 11 + '(' shift 6 + . error + + expr goto 31 + number goto 9 + + +state 22 + expr : expr '|' . expr (13) + + "SUB-operator" shift 3 + DIGIT shift 4 + LETTER shift 11 + '(' shift 6 + . error + + expr goto 32 + number goto 9 + + +state 23 + number : number DIGIT . (18) + + . reduce 18 + + +state 24 + stat : LETTER '=' expr . (5) + expr : expr . "ADD-operator" expr (7) + expr : expr . "SUB-operator" expr (8) + expr : expr . "MUL-operator" expr (9) + expr : expr . "DIV-operator" expr (10) + expr : expr . "MOD-operator" expr (11) + expr : expr . "AND-operator" expr (12) + expr : expr . '|' expr (13) + + "ADD-operator" shift 16 + "SUB-operator" shift 17 + "MUL-operator" shift 18 + "DIV-operator" shift 19 + "MOD-operator" shift 20 + "AND-operator" shift 21 + '|' shift 22 + '\n' reduce 5 + + +state 25 + expr : '(' expr ')' . (6) + + . reduce 6 + + +26: shift/reduce conflict (shift 16, reduce 7) on "ADD-operator" +26: shift/reduce conflict (shift 17, reduce 7) on "SUB-operator" +26: shift/reduce conflict (shift 18, reduce 7) on "MUL-operator" +26: shift/reduce conflict (shift 19, reduce 7) on "DIV-operator" +26: shift/reduce conflict (shift 20, reduce 7) on "MOD-operator" +26: shift/reduce conflict (shift 21, reduce 7) on "AND-operator" +26: shift/reduce conflict (shift 22, reduce 7) on '|' +state 26 + expr : expr . "ADD-operator" expr (7) + expr : expr "ADD-operator" expr . (7) + expr : expr . "SUB-operator" expr (8) + expr : expr . "MUL-operator" expr (9) + expr : expr . "DIV-operator" expr (10) + expr : expr . "MOD-operator" expr (11) + expr : expr . "AND-operator" expr (12) + expr : expr . '|' expr (13) + + "ADD-operator" shift 16 + "SUB-operator" shift 17 + "MUL-operator" shift 18 + "DIV-operator" shift 19 + "MOD-operator" shift 20 + "AND-operator" shift 21 + '|' shift 22 + '\n' reduce 7 + ')' reduce 7 + + +27: shift/reduce conflict (shift 16, reduce 8) on "ADD-operator" +27: shift/reduce conflict (shift 17, reduce 8) on "SUB-operator" +27: shift/reduce conflict (shift 18, reduce 8) on "MUL-operator" +27: shift/reduce conflict (shift 19, reduce 8) on "DIV-operator" +27: shift/reduce conflict (shift 20, reduce 8) on "MOD-operator" +27: shift/reduce conflict (shift 21, reduce 8) on "AND-operator" +27: shift/reduce conflict (shift 22, reduce 8) on '|' +state 27 + expr : expr . "ADD-operator" expr (7) + expr : expr . "SUB-operator" expr (8) + expr : expr "SUB-operator" expr . (8) + expr : expr . "MUL-operator" expr (9) + expr : expr . "DIV-operator" expr (10) + expr : expr . "MOD-operator" expr (11) + expr : expr . "AND-operator" expr (12) + expr : expr . '|' expr (13) + + "ADD-operator" shift 16 + "SUB-operator" shift 17 + "MUL-operator" shift 18 + "DIV-operator" shift 19 + "MOD-operator" shift 20 + "AND-operator" shift 21 + '|' shift 22 + '\n' reduce 8 + ')' reduce 8 + + +28: shift/reduce conflict (shift 16, reduce 9) on "ADD-operator" +28: shift/reduce conflict (shift 17, reduce 9) on "SUB-operator" +28: shift/reduce conflict (shift 18, reduce 9) on "MUL-operator" +28: shift/reduce conflict (shift 19, reduce 9) on "DIV-operator" +28: shift/reduce conflict (shift 20, reduce 9) on "MOD-operator" +28: shift/reduce conflict (shift 21, reduce 9) on "AND-operator" +28: shift/reduce conflict (shift 22, reduce 9) on '|' +state 28 + expr : expr . "ADD-operator" expr (7) + expr : expr . "SUB-operator" expr (8) + expr : expr . "MUL-operator" expr (9) + expr : expr "MUL-operator" expr . (9) + expr : expr . "DIV-operator" expr (10) + expr : expr . "MOD-operator" expr (11) + expr : expr . "AND-operator" expr (12) + expr : expr . '|' expr (13) + + "ADD-operator" shift 16 + "SUB-operator" shift 17 + "MUL-operator" shift 18 + "DIV-operator" shift 19 + "MOD-operator" shift 20 + "AND-operator" shift 21 + '|' shift 22 + '\n' reduce 9 + ')' reduce 9 + + +29: shift/reduce conflict (shift 16, reduce 10) on "ADD-operator" +29: shift/reduce conflict (shift 17, reduce 10) on "SUB-operator" +29: shift/reduce conflict (shift 18, reduce 10) on "MUL-operator" +29: shift/reduce conflict (shift 19, reduce 10) on "DIV-operator" +29: shift/reduce conflict (shift 20, reduce 10) on "MOD-operator" +29: shift/reduce conflict (shift 21, reduce 10) on "AND-operator" +29: shift/reduce conflict (shift 22, reduce 10) on '|' +state 29 + expr : expr . "ADD-operator" expr (7) + expr : expr . "SUB-operator" expr (8) + expr : expr . "MUL-operator" expr (9) + expr : expr . "DIV-operator" expr (10) + expr : expr "DIV-operator" expr . (10) + expr : expr . "MOD-operator" expr (11) + expr : expr . "AND-operator" expr (12) + expr : expr . '|' expr (13) + + "ADD-operator" shift 16 + "SUB-operator" shift 17 + "MUL-operator" shift 18 + "DIV-operator" shift 19 + "MOD-operator" shift 20 + "AND-operator" shift 21 + '|' shift 22 + '\n' reduce 10 + ')' reduce 10 + + +30: shift/reduce conflict (shift 16, reduce 11) on "ADD-operator" +30: shift/reduce conflict (shift 17, reduce 11) on "SUB-operator" +30: shift/reduce conflict (shift 18, reduce 11) on "MUL-operator" +30: shift/reduce conflict (shift 19, reduce 11) on "DIV-operator" +30: shift/reduce conflict (shift 20, reduce 11) on "MOD-operator" +30: shift/reduce conflict (shift 21, reduce 11) on "AND-operator" +30: shift/reduce conflict (shift 22, reduce 11) on '|' +state 30 + expr : expr . "ADD-operator" expr (7) + expr : expr . "SUB-operator" expr (8) + expr : expr . "MUL-operator" expr (9) + expr : expr . "DIV-operator" expr (10) + expr : expr . "MOD-operator" expr (11) + expr : expr "MOD-operator" expr . (11) + expr : expr . "AND-operator" expr (12) + expr : expr . '|' expr (13) + + "ADD-operator" shift 16 + "SUB-operator" shift 17 + "MUL-operator" shift 18 + "DIV-operator" shift 19 + "MOD-operator" shift 20 + "AND-operator" shift 21 + '|' shift 22 + '\n' reduce 11 + ')' reduce 11 + + +31: shift/reduce conflict (shift 16, reduce 12) on "ADD-operator" +31: shift/reduce conflict (shift 17, reduce 12) on "SUB-operator" +31: shift/reduce conflict (shift 18, reduce 12) on "MUL-operator" +31: shift/reduce conflict (shift 19, reduce 12) on "DIV-operator" +31: shift/reduce conflict (shift 20, reduce 12) on "MOD-operator" +31: shift/reduce conflict (shift 21, reduce 12) on "AND-operator" +31: shift/reduce conflict (shift 22, reduce 12) on '|' +state 31 + expr : expr . "ADD-operator" expr (7) + expr : expr . "SUB-operator" expr (8) + expr : expr . "MUL-operator" expr (9) + expr : expr . "DIV-operator" expr (10) + expr : expr . "MOD-operator" expr (11) + expr : expr . "AND-operator" expr (12) + expr : expr "AND-operator" expr . (12) + expr : expr . '|' expr (13) + + "ADD-operator" shift 16 + "SUB-operator" shift 17 + "MUL-operator" shift 18 + "DIV-operator" shift 19 + "MOD-operator" shift 20 + "AND-operator" shift 21 + '|' shift 22 + '\n' reduce 12 + ')' reduce 12 + + +32: shift/reduce conflict (shift 16, reduce 13) on "ADD-operator" +32: shift/reduce conflict (shift 17, reduce 13) on "SUB-operator" +32: shift/reduce conflict (shift 18, reduce 13) on "MUL-operator" +32: shift/reduce conflict (shift 19, reduce 13) on "DIV-operator" +32: shift/reduce conflict (shift 20, reduce 13) on "MOD-operator" +32: shift/reduce conflict (shift 21, reduce 13) on "AND-operator" +state 32 + expr : expr . "ADD-operator" expr (7) + expr : expr . "SUB-operator" expr (8) + expr : expr . "MUL-operator" expr (9) + expr : expr . "DIV-operator" expr (10) + expr : expr . "MOD-operator" expr (11) + expr : expr . "AND-operator" expr (12) + expr : expr . '|' expr (13) + expr : expr '|' expr . (13) + + "ADD-operator" shift 16 + "SUB-operator" shift 17 + "MUL-operator" shift 18 + "DIV-operator" shift 19 + "MOD-operator" shift 20 + "AND-operator" shift 21 + '|' reduce 13 + '\n' reduce 13 + ')' reduce 13 + + +State 12 contains 6 shift/reduce conflicts. +State 26 contains 7 shift/reduce conflicts. +State 27 contains 7 shift/reduce conflicts. +State 28 contains 7 shift/reduce conflicts. +State 29 contains 7 shift/reduce conflicts. +State 30 contains 7 shift/reduce conflicts. +State 31 contains 7 shift/reduce conflicts. +State 32 contains 6 shift/reduce conflicts. + + +28 terminals, 5 nonterminals +19 grammar rules, 33 states diff --git a/test/quote_calc4.tab.c b/test/quote_calc4.tab.c new file mode 100644 index 000000000000..da2f25e800a1 --- /dev/null +++ b/test/quote_calc4.tab.c @@ -0,0 +1,688 @@ +#ifndef lint +static const char yysccsid[] = "@(#)yaccpar 1.9 (Berkeley) 02/21/93"; +#endif + +#define YYBYACC 1 +#define YYMAJOR 1 +#define YYMINOR 9 + +#define YYEMPTY (-1) +#define yyclearin (yychar = YYEMPTY) +#define yyerrok (yyerrflag = 0) +#define YYRECOVERING() (yyerrflag != 0) + + +#ifndef yyparse +#define yyparse quote_calc4_parse +#endif /* yyparse */ + +#ifndef yylex +#define yylex quote_calc4_lex +#endif /* yylex */ + +#ifndef yyerror +#define yyerror quote_calc4_error +#endif /* yyerror */ + +#ifndef yychar +#define yychar quote_calc4_char +#endif /* yychar */ + +#ifndef yyval +#define yyval quote_calc4_val +#endif /* yyval */ + +#ifndef yylval +#define yylval quote_calc4_lval +#endif /* yylval */ + +#ifndef yydebug +#define yydebug quote_calc4_debug +#endif /* yydebug */ + +#ifndef yynerrs +#define yynerrs quote_calc4_nerrs +#endif /* yynerrs */ + +#ifndef yyerrflag +#define yyerrflag quote_calc4_errflag +#endif /* yyerrflag */ + +#ifndef yylhs +#define yylhs quote_calc4_lhs +#endif /* yylhs */ + +#ifndef yylen +#define yylen quote_calc4_len +#endif /* yylen */ + +#ifndef yydefred +#define yydefred quote_calc4_defred +#endif /* yydefred */ + +#ifndef yydgoto +#define yydgoto quote_calc4_dgoto +#endif /* yydgoto */ + +#ifndef yysindex +#define yysindex quote_calc4_sindex +#endif /* yysindex */ + +#ifndef yyrindex +#define yyrindex quote_calc4_rindex +#endif /* yyrindex */ + +#ifndef yygindex +#define yygindex quote_calc4_gindex +#endif /* yygindex */ + +#ifndef yytable +#define yytable quote_calc4_table +#endif /* yytable */ + +#ifndef yycheck +#define yycheck quote_calc4_check +#endif /* yycheck */ + +#ifndef yyname +#define yyname quote_calc4_name +#endif /* yyname */ + +#ifndef yyrule +#define yyrule quote_calc4_rule +#endif /* yyrule */ +#define YYPREFIX "quote_calc4_" + +#define YYPURE 0 + +#line 2 "quote_calc4.y" +# include <stdio.h> +# include <ctype.h> + +int regs[26]; +int base; + +int yylex(void); +static void yyerror(const char *s); + +#line 109 "quote_calc4.tab.c" + +#ifndef YYSTYPE +typedef int YYSTYPE; +#endif + +/* compatibility with bison */ +#ifdef YYPARSE_PARAM +/* compatibility with FreeBSD */ +# ifdef YYPARSE_PARAM_TYPE +# define YYPARSE_DECL() yyparse(YYPARSE_PARAM_TYPE YYPARSE_PARAM) +# else +# define YYPARSE_DECL() yyparse(void *YYPARSE_PARAM) +# endif +#else +# define YYPARSE_DECL() yyparse(void) +#endif + +/* Parameters sent to lex. */ +#ifdef YYLEX_PARAM +# define YYLEX_DECL() yylex(void *YYLEX_PARAM) +# define YYLEX yylex(YYLEX_PARAM) +#else +# define YYLEX_DECL() yylex(void) +# define YYLEX yylex() +#endif + +/* Parameters sent to yyerror. */ +#ifndef YYERROR_DECL +#define YYERROR_DECL() yyerror(const char *s) +#endif +#ifndef YYERROR_CALL +#define YYERROR_CALL(msg) yyerror(msg) +#endif + +extern int YYPARSE_DECL(); + +#define OP_ADD 257 +#define OP_SUB 259 +#define OP_MUL 261 +#define OP_DIV 263 +#define OP_MOD 265 +#define OP_AND 267 +#define DIGIT 269 +#define LETTER 270 +#define UMINUS 271 +#define YYERRCODE 256 +static const short quote_calc4_lhs[] = { -1, + 0, 0, 0, 1, 1, 2, 2, 2, 2, 2, + 2, 2, 2, 2, 2, 2, 3, 3, +}; +static const short quote_calc4_len[] = { 2, + 0, 3, 3, 1, 3, 3, 3, 3, 3, 3, + 3, 3, 3, 2, 1, 1, 1, 2, +}; +static const short quote_calc4_defred[] = { 1, + 0, 0, 0, 17, 0, 0, 0, 0, 0, 3, + 15, 0, 0, 0, 2, 0, 0, 0, 0, 0, + 0, 0, 18, 0, 6, 0, 0, 0, 0, 0, + 0, 0, +}; +static const short quote_calc4_dgoto[] = { 1, + 7, 8, 9, +}; +static const short quote_calc4_sindex[] = { 0, + -38, 4, -36, 0, -51, -36, 6, -121, -249, 0, + 0, -243, -36, -23, 0, -36, -36, -36, -36, -36, + -36, -36, 0, -121, 0, -121, -121, -121, -121, -121, + -121, -243, +}; +static const short quote_calc4_rindex[] = { 0, + 0, 0, 0, 0, -9, 0, 0, 12, -10, 0, + 0, -5, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 14, 0, -3, -2, -1, 1, 2, + 3, -4, +}; +static const short quote_calc4_gindex[] = { 0, + 0, 42, 0, +}; +#define YYTABLESIZE 259 +static const short quote_calc4_table[] = { 16, + 15, 6, 22, 6, 14, 13, 7, 8, 9, 13, + 10, 11, 12, 10, 16, 15, 17, 25, 18, 23, + 19, 4, 20, 5, 21, 0, 0, 0, 0, 0, + 16, 0, 0, 0, 0, 14, 13, 7, 8, 9, + 0, 10, 11, 12, 12, 0, 0, 14, 0, 0, + 0, 0, 0, 0, 24, 0, 0, 26, 27, 28, + 29, 30, 31, 32, 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, 0, 0, 0, 0, 0, 0, 0, 0, + 22, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 16, 15, 0, 0, 0, 14, 13, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 16, 0, 17, 0, + 18, 0, 19, 0, 20, 0, 21, 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, 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, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 2, 0, 0, + 0, 3, 0, 3, 0, 0, 0, 0, 0, 0, + 4, 5, 4, 11, 16, 0, 17, 0, 18, 0, + 19, 0, 20, 0, 21, 0, 0, 16, 15, 16, + 15, 16, 15, 16, 15, 16, 15, 16, 15, +}; +static const short quote_calc4_check[] = { 10, + 10, 40, 124, 40, 10, 10, 10, 10, 10, 61, + 10, 10, 10, 10, 258, 10, 260, 41, 262, 269, + 264, 10, 266, 10, 268, -1, -1, -1, -1, -1, + 41, -1, -1, -1, -1, 41, 41, 41, 41, 41, + -1, 41, 41, 41, 3, -1, -1, 6, -1, -1, + -1, -1, -1, -1, 13, -1, -1, 16, 17, 18, + 19, 20, 21, 22, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, + 124, -1, -1, -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, 124, 124, -1, -1, -1, 124, 124, + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, 258, -1, 260, -1, + 262, -1, 264, -1, 266, -1, 268, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, 256, -1, -1, + -1, 260, -1, 260, -1, -1, -1, -1, -1, -1, + 269, 270, 269, 270, 258, -1, 260, -1, 262, -1, + 264, -1, 266, -1, 268, -1, -1, 258, 258, 260, + 260, 262, 262, 264, 264, 266, 266, 268, 268, +}; +#define YYFINAL 1 +#ifndef YYDEBUG +#define YYDEBUG 0 +#endif +#define YYMAXTOKEN 271 +#if YYDEBUG +static const char *yyname[] = { + +"end-of-file",0,0,0,0,0,0,0,0,0,"'\\n'",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,"'-'",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,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,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,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,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,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,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,0,0,0,0,0,0, +0,0,0,0,0,0,"OP_ADD","\"ADD-operator\"","OP_SUB","\"SUB-operator\"","OP_MUL", +"\"MUL-operator\"","OP_DIV","\"DIV-operator\"","OP_MOD","\"MOD-operator\"", +"OP_AND","\"AND-operator\"","DIGIT","LETTER","UMINUS", +}; +static const char *yyrule[] = { +"$accept : list", +"list :", +"list : list stat '\\n'", +"list : list error '\\n'", +"stat : expr", +"stat : LETTER '=' expr", +"expr : '(' expr ')'", +"expr : expr \"ADD-operator\" expr", +"expr : expr \"SUB-operator\" expr", +"expr : expr \"MUL-operator\" expr", +"expr : expr \"DIV-operator\" expr", +"expr : expr \"MOD-operator\" expr", +"expr : expr \"AND-operator\" expr", +"expr : expr '|' expr", +"expr : \"SUB-operator\" expr", +"expr : LETTER", +"expr : number", +"number : DIGIT", +"number : number DIGIT", + +}; +#endif + +int yydebug; +int yynerrs; + +int yyerrflag; +int yychar; +YYSTYPE yyval; +YYSTYPE yylval; + +/* define the initial stack-sizes */ +#ifdef YYSTACKSIZE +#undef YYMAXDEPTH +#define YYMAXDEPTH YYSTACKSIZE +#else +#ifdef YYMAXDEPTH +#define YYSTACKSIZE YYMAXDEPTH +#else +#define YYSTACKSIZE 500 +#define YYMAXDEPTH 500 +#endif +#endif + +#define YYINITSTACKSIZE 500 + +typedef struct { + unsigned stacksize; + short *s_base; + short *s_mark; + short *s_last; + YYSTYPE *l_base; + YYSTYPE *l_mark; +} YYSTACKDATA; +/* variables for the parser stack */ +static YYSTACKDATA yystack; +#line 73 "quote_calc4.y" + /* start of programs */ + +int +main (void) +{ + while(!feof(stdin)) { + yyparse(); + } + return 0; +} + +static void +yyerror(const char *s) +{ + fprintf(stderr, "%s\n", s); +} + +int +yylex(void) { + /* lexical analysis routine */ + /* returns LETTER for a lower case letter, yylval = 0 through 25 */ + /* return DIGIT for a digit, yylval = 0 through 9 */ + /* all other characters are returned immediately */ + + int c; + + while( (c=getchar()) == ' ' ) { /* skip blanks */ } + + /* c is now nonblank */ + + if( islower( c )) { + yylval = c - 'a'; + return ( LETTER ); + } + if( isdigit( c )) { + yylval = c - '0'; + return ( DIGIT ); + } + return( c ); +} +#line 362 "quote_calc4.tab.c" + +#if YYDEBUG +#include <stdio.h> /* needed for printf */ +#endif + +#include <stdlib.h> /* needed for malloc, etc */ +#include <string.h> /* needed for memset */ + +/* allocate initial stack or double stack size, up to YYMAXDEPTH */ +static int yygrowstack(YYSTACKDATA *data) +{ + int i; + unsigned newsize; + short *newss; + YYSTYPE *newvs; + + if ((newsize = data->stacksize) == 0) + newsize = YYINITSTACKSIZE; + else if (newsize >= YYMAXDEPTH) + return -1; + else if ((newsize *= 2) > YYMAXDEPTH) + newsize = YYMAXDEPTH; + + i = data->s_mark - data->s_base; + newss = (short *)realloc(data->s_base, newsize * sizeof(*newss)); + if (newss == 0) + return -1; + + data->s_base = newss; + data->s_mark = newss + i; + + newvs = (YYSTYPE *)realloc(data->l_base, newsize * sizeof(*newvs)); + if (newvs == 0) + return -1; + + data->l_base = newvs; + data->l_mark = newvs + i; + + data->stacksize = newsize; + data->s_last = data->s_base + newsize - 1; + return 0; +} + +#if YYPURE || defined(YY_NO_LEAKS) +static void yyfreestack(YYSTACKDATA *data) +{ + free(data->s_base); + free(data->l_base); + memset(data, 0, sizeof(*data)); +} +#else +#define yyfreestack(data) /* nothing */ +#endif + +#define YYABORT goto yyabort +#define YYREJECT goto yyabort +#define YYACCEPT goto yyaccept +#define YYERROR goto yyerrlab + +int +YYPARSE_DECL() +{ + int yym, yyn, yystate; +#if YYDEBUG + const char *yys; + + if ((yys = getenv("YYDEBUG")) != 0) + { + yyn = *yys; + if (yyn >= '0' && yyn <= '9') + yydebug = yyn - '0'; + } +#endif + + yynerrs = 0; + yyerrflag = 0; + yychar = YYEMPTY; + yystate = 0; + +#if YYPURE + memset(&yystack, 0, sizeof(yystack)); +#endif + + if (yystack.s_base == NULL && yygrowstack(&yystack)) goto yyoverflow; + yystack.s_mark = yystack.s_base; + yystack.l_mark = yystack.l_base; + yystate = 0; + *yystack.s_mark = 0; + +yyloop: + if ((yyn = yydefred[yystate]) != 0) goto yyreduce; + if (yychar < 0) + { + if ((yychar = YYLEX) < 0) yychar = 0; +#if YYDEBUG + if (yydebug) + { + yys = 0; + if (yychar <= YYMAXTOKEN) yys = yyname[yychar]; + if (!yys) yys = "illegal-symbol"; + printf("%sdebug: state %d, reading %d (%s)\n", + YYPREFIX, yystate, yychar, yys); + } +#endif + } + if ((yyn = yysindex[yystate]) && (yyn += yychar) >= 0 && + yyn <= YYTABLESIZE && yycheck[yyn] == yychar) + { +#if YYDEBUG + if (yydebug) + printf("%sdebug: state %d, shifting to state %d\n", + YYPREFIX, yystate, yytable[yyn]); +#endif + if (yystack.s_mark >= yystack.s_last && yygrowstack(&yystack)) + { + goto yyoverflow; + } + yystate = yytable[yyn]; + *++yystack.s_mark = yytable[yyn]; + *++yystack.l_mark = yylval; + yychar = YYEMPTY; + if (yyerrflag > 0) --yyerrflag; + goto yyloop; + } + if ((yyn = yyrindex[yystate]) && (yyn += yychar) >= 0 && + yyn <= YYTABLESIZE && yycheck[yyn] == yychar) + { + yyn = yytable[yyn]; + goto yyreduce; + } + if (yyerrflag) goto yyinrecovery; + + yyerror("syntax error"); + + goto yyerrlab; + +yyerrlab: + ++yynerrs; + +yyinrecovery: + if (yyerrflag < 3) + { + yyerrflag = 3; + for (;;) + { + if ((yyn = yysindex[*yystack.s_mark]) && (yyn += YYERRCODE) >= 0 && + yyn <= YYTABLESIZE && yycheck[yyn] == YYERRCODE) + { +#if YYDEBUG + if (yydebug) + printf("%sdebug: state %d, error recovery shifting\ + to state %d\n", YYPREFIX, *yystack.s_mark, yytable[yyn]); +#endif + if (yystack.s_mark >= yystack.s_last && yygrowstack(&yystack)) + { + goto yyoverflow; + } + yystate = yytable[yyn]; + *++yystack.s_mark = yytable[yyn]; + *++yystack.l_mark = yylval; + goto yyloop; + } + else + { +#if YYDEBUG + if (yydebug) + printf("%sdebug: error recovery discarding state %d\n", + YYPREFIX, *yystack.s_mark); +#endif + if (yystack.s_mark <= yystack.s_base) goto yyabort; + --yystack.s_mark; + --yystack.l_mark; + } + } + } + else + { + if (yychar == 0) goto yyabort; +#if YYDEBUG + if (yydebug) + { + yys = 0; + if (yychar <= YYMAXTOKEN) yys = yyname[yychar]; + if (!yys) yys = "illegal-symbol"; + printf("%sdebug: state %d, error recovery discards token %d (%s)\n", + YYPREFIX, yystate, yychar, yys); + } +#endif + yychar = YYEMPTY; + goto yyloop; + } + +yyreduce: +#if YYDEBUG + if (yydebug) + printf("%sdebug: state %d, reducing by rule %d (%s)\n", + YYPREFIX, yystate, yyn, yyrule[yyn]); +#endif + yym = yylen[yyn]; + if (yym) + yyval = yystack.l_mark[1-yym]; + else + memset(&yyval, 0, sizeof yyval); + switch (yyn) + { +case 3: +#line 35 "quote_calc4.y" + { yyerrok ; } +break; +case 4: +#line 39 "quote_calc4.y" + { printf("%d\n",yystack.l_mark[0]);} +break; +case 5: +#line 41 "quote_calc4.y" + { regs[yystack.l_mark[-2]] = yystack.l_mark[0]; } +break; +case 6: +#line 45 "quote_calc4.y" + { yyval = yystack.l_mark[-1]; } +break; +case 7: +#line 47 "quote_calc4.y" + { yyval = yystack.l_mark[-2] + yystack.l_mark[0]; } +break; +case 8: +#line 49 "quote_calc4.y" + { yyval = yystack.l_mark[-2] - yystack.l_mark[0]; } +break; +case 9: +#line 51 "quote_calc4.y" + { yyval = yystack.l_mark[-2] * yystack.l_mark[0]; } +break; +case 10: +#line 53 "quote_calc4.y" + { yyval = yystack.l_mark[-2] / yystack.l_mark[0]; } +break; +case 11: +#line 55 "quote_calc4.y" + { yyval = yystack.l_mark[-2] % yystack.l_mark[0]; } +break; +case 12: +#line 57 "quote_calc4.y" + { yyval = yystack.l_mark[-2] & yystack.l_mark[0]; } +break; +case 13: +#line 59 "quote_calc4.y" + { yyval = yystack.l_mark[-2] | yystack.l_mark[0]; } +break; +case 14: +#line 61 "quote_calc4.y" + { yyval = - yystack.l_mark[0]; } +break; +case 15: +#line 63 "quote_calc4.y" + { yyval = regs[yystack.l_mark[0]]; } +break; +case 17: +#line 68 "quote_calc4.y" + { yyval = yystack.l_mark[0]; base = (yystack.l_mark[0]==0) ? 8 : 10; } +break; +case 18: +#line 70 "quote_calc4.y" + { yyval = base * yystack.l_mark[-1] + yystack.l_mark[0]; } +break; +#line 628 "quote_calc4.tab.c" + } + yystack.s_mark -= yym; + yystate = *yystack.s_mark; + yystack.l_mark -= yym; + yym = yylhs[yyn]; + if (yystate == 0 && yym == 0) + { +#if YYDEBUG + if (yydebug) + printf("%sdebug: after reduction, shifting from state 0 to\ + state %d\n", YYPREFIX, YYFINAL); +#endif + yystate = YYFINAL; + *++yystack.s_mark = YYFINAL; + *++yystack.l_mark = yyval; + if (yychar < 0) + { + if ((yychar = YYLEX) < 0) yychar = 0; +#if YYDEBUG + if (yydebug) + { + yys = 0; + if (yychar <= YYMAXTOKEN) yys = yyname[yychar]; + if (!yys) yys = "illegal-symbol"; + printf("%sdebug: state %d, reading %d (%s)\n", + YYPREFIX, YYFINAL, yychar, yys); + } +#endif + } + if (yychar == 0) goto yyaccept; + goto yyloop; + } + if ((yyn = yygindex[yym]) && (yyn += yystate) >= 0 && + yyn <= YYTABLESIZE && yycheck[yyn] == yystate) + yystate = yytable[yyn]; + else + yystate = yydgoto[yym]; +#if YYDEBUG + if (yydebug) + printf("%sdebug: after reduction, shifting from state %d \ +to state %d\n", YYPREFIX, *yystack.s_mark, yystate); +#endif + if (yystack.s_mark >= yystack.s_last && yygrowstack(&yystack)) + { + goto yyoverflow; + } + *++yystack.s_mark = (short) yystate; + *++yystack.l_mark = yyval; + goto yyloop; + +yyoverflow: + yyerror("yacc stack overflow"); + +yyabort: + yyfreestack(&yystack); + return (1); + +yyaccept: + yyfreestack(&yystack); + return (0); +} diff --git a/test/quote_calc4.tab.h b/test/quote_calc4.tab.h new file mode 100644 index 000000000000..1a4657903411 --- /dev/null +++ b/test/quote_calc4.tab.h @@ -0,0 +1,9 @@ +#define OP_ADD 257 +#define OP_SUB 259 +#define OP_MUL 261 +#define OP_DIV 263 +#define OP_MOD 265 +#define OP_AND 267 +#define DIGIT 269 +#define LETTER 270 +#define UMINUS 271 diff --git a/test/quote_calc4.y b/test/quote_calc4.y new file mode 100644 index 000000000000..34b790e67f12 --- /dev/null +++ b/test/quote_calc4.y @@ -0,0 +1,112 @@ +%{ +# include <stdio.h> +# include <ctype.h> + +int regs[26]; +int base; + +int yylex(void); +static void yyerror(const char *s); + +%} + +%start list + +%token OP_ADD "ADD-operator" +%token OP_SUB "SUB-operator" +%token OP_MUL "MUL-operator" +%token OP_DIV "DIV-operator" +%token OP_MOD "MOD-operator" +%token OP_AND "AND-operator" + +%token DIGIT LETTER + +%left '|' +%left '&' +%left '+' '-' +%left '*' '/' '%' +%left UMINUS /* supplies precedence for unary minus */ + +%% /* beginning of rules section */ + +list : /* empty */ + | list stat '\n' + | list error '\n' + { yyerrok ; } + ; + +stat : expr + { printf("%d\n",$1);} + | LETTER '=' expr + { regs[$1] = $3; } + ; + +expr : '(' expr ')' + { $$ = $2; } + | expr "ADD-operator" expr + { $$ = $1 + $3; } + | expr "SUB-operator" expr + { $$ = $1 - $3; } + | expr "MUL-operator" expr + { $$ = $1 * $3; } + | expr "DIV-operator" expr + { $$ = $1 / $3; } + | expr "MOD-operator" expr + { $$ = $1 % $3; } + | expr "AND-operator" expr + { $$ = $1 & $3; } + | expr '|' expr + { $$ = $1 | $3; } + | "SUB-operator" expr %prec UMINUS + { $$ = - $2; } + | LETTER + { $$ = regs[$1]; } + | number + ; + +number: DIGIT + { $$ = $1; base = ($1==0) ? 8 : 10; } + | number DIGIT + { $$ = base * $1 + $2; } + ; + +%% /* start of programs */ + +int +main (void) +{ + while(!feof(stdin)) { + yyparse(); + } + return 0; +} + +static void +yyerror(const char *s) +{ + fprintf(stderr, "%s\n", s); +} + +int +yylex(void) { + /* lexical analysis routine */ + /* returns LETTER for a lower case letter, yylval = 0 through 25 */ + /* return DIGIT for a digit, yylval = 0 through 9 */ + /* all other characters are returned immediately */ + + int c; + + while( (c=getchar()) == ' ' ) { /* skip blanks */ } + + /* c is now nonblank */ + + if( islower( c )) { + yylval = c - 'a'; + return ( LETTER ); + } + if( isdigit( c )) { + yylval = c - '0'; + return ( DIGIT ); + } + return( c ); +} diff --git a/test/run_lint.sh b/test/run_lint.sh new file mode 100755 index 000000000000..3230551045c7 --- /dev/null +++ b/test/run_lint.sh @@ -0,0 +1,20 @@ +#!/bin/sh +# $Id: run_lint.sh,v 1.1 2010/06/08 09:00:58 tom Exp $ +# vi:ts=4 sw=4: + +# run lint on each of the ".c" files in the test directory + +if test $# = 1 +then + PROG_DIR=`pwd` + TEST_DIR=$1 +else + PROG_DIR=.. + TEST_DIR=. +fi + +echo '** '`date` +for i in ${TEST_DIR}/*.c +do + make -f $PROG_DIR/makefile lint C_FILES=$i srcdir=$PROG_DIR +done diff --git a/test/run_make.sh b/test/run_make.sh new file mode 100755 index 000000000000..2bbe95d1841f --- /dev/null +++ b/test/run_make.sh @@ -0,0 +1,139 @@ +#!/bin/sh +# $Id: run_make.sh,v 1.9 2012/01/15 22:35:01 tom Exp $ +# vi:ts=4 sw=4: + +# do a test-compile on each of the ".c" files in the test-directory + +BISON=`bison --version 2>/dev/null | head -n 1 | sed -e 's/^[^0-9.]*//' -e 's/[^0-9.]*$//'` + +if test $# = 1 +then + PROG_DIR=`pwd` + TEST_DIR=$1 +else + PROG_DIR=.. + TEST_DIR=. +fi + +MY_MAKE="make -f $PROG_DIR/makefile srcdir=$PROG_DIR VPATH=$TEST_DIR" + +echo '** '`date` +for input in ${TEST_DIR}/*.c +do + test -f "$input" || continue + + obj=`basename "$input" .c`.o + + $MY_MAKE $obj C_FILES=$input + test -f $obj && rm $obj + + DEFS= + case $input in #(vi + ${TEST_DIR}/pure_*) + # DEFS="-DYYLEX_PARAM=flag -DYYLEX_PARAM_TYPE=int" + ;; + esac + + if test "x$DEFS" != "x" + then + $MY_MAKE $obj C_FILES=$input DEFINES="$DEFS" + test -f $obj && rm -f $obj + fi +done + +if test -n "$BISON" +then + echo "** compare with bison $BISON" + for input in ${TEST_DIR}/*.y + do + test -f "$input" || continue + + # Bison does not support pure-parser from command-line. + # Also, its support for %expect is generally broken. + # Work around these issues using a temporary file. + + echo "... testing $input" + rm -f run_make.[coy] + + case $input in + pure_*) + if test -z `fgrep -l '%pure-parser' $input` + then + echo "%pure-parser" >>run_make.y + fi + ;; + esac + + sed -e '/^%expect/s,%expect.*,,' $input >>run_make.y + + bison -y run_make.y + sed -e '/^#line/s,"run_make.y","'$input'",' y.tab.c >run_make.c + + rm -f y.tab.c + + input=run_make.c + object=run_make.o + if test -f $input + then + $MY_MAKE $object DEFINES='-DYYENABLE_NLS=0 -DYYLTYPE_IS_TRIVIAL=1 -DYYSTACK_USE_ALLOCA=0 -DYYMAXDEPTH=0' + else + echo "?? $input not found" + fi + rm -f run_make.[coy] + done +fi + +YACC= +for name in /usr/ccs/bin/yacc +do + if test -f $name + then + YACC=$name + fi +done + +if test -n "$YACC" +then + echo "** compare with $YACC" + for input in ${TEST_DIR}/*.y + do + test -f "$input" || continue + + echo "... testing $input" + rm -f run_make.[coy] + + case $input in + pure_*) + echo "... skipping $input" + continue; + ;; + *) + if fgrep '%pure-parser' $input >/dev/null || + fgrep '%parse-param' $input >/dev/null || + fgrep '%lex-param' $input >/dev/null || + fgrep 'YYLEX_PARAM' $input >/dev/null + then + echo "... skipping $input" + continue; + fi + ;; + esac + + sed -e '/^%expect/s,%expect.*,,' $input >>run_make.y + + $YACC run_make.y + sed -e '/^#line/s,"run_make.y","'$input'",' y.tab.c >run_make.c + + rm -f y.tab.c + + input=run_make.c + object=run_make.o + if test -f $input + then + $MY_MAKE $object + else + echo "?? $input not found" + fi + rm -f run_make.[coy] + done +fi diff --git a/test/run_test.sh b/test/run_test.sh new file mode 100755 index 000000000000..ae8591b8c68f --- /dev/null +++ b/test/run_test.sh @@ -0,0 +1,82 @@ +#!/bin/sh +# $Id: run_test.sh,v 1.8 2012/01/15 11:50:35 tom Exp $ +# vi:ts=4 sw=4: + +if test $# = 1 +then + PROG_DIR=`pwd` + TEST_DIR=$1 +else + PROG_DIR=.. + TEST_DIR=. +fi + +YACC=$PROG_DIR/yacc + +tmpfile=temp$$ +rm -f test-* + +echo '** '`date` +for input in ${TEST_DIR}/*.y +do + case $input in + test*) + echo "?? ignored $input" + ;; + *) + root=`basename $input .y` + ROOT="test-$root" + prefix=${root}_ + + OPTS= + OPT2= + TYPE=".output .tab.c .tab.h" + case $input in + ${TEST_DIR}/code_*) + OPTS="$OPTS -r" + TYPE="$TYPE .code.c" + prefix=`echo "$prefix" | sed -e 's/^code_//'` + ;; + ${TEST_DIR}/pure_*) + OPTS="$OPTS -P" + prefix=`echo "$prefix" | sed -e 's/^pure_//'` + ;; + ${TEST_DIR}/quote_*) + OPT2="-s" + ;; + esac + + for opt2 in "" $OPT2 + do + $YACC $OPTS $opt2 -v -d -p $prefix -b $ROOT${opt2} $input + for type in $TYPE + do + REF=${TEST_DIR}/${root}${opt2}${type} + CMP=${ROOT}${opt2}${type} + if test ! -f $CMP + then + echo "...not found $CMP" + else + sed -e s,$CMP,$REF, \ + -e /YYPATCH/d \ + -e 's,#line \([1-9][0-9]*\) "'$TEST_DIR'/,#line \1 ",' \ + < $CMP >$tmpfile \ + && mv $tmpfile $CMP + if test ! -f $REF + then + mv $CMP $REF + echo "...saved $REF" + elif ( cmp -s $REF $CMP ) + then + echo "...ok $REF" + rm -f $CMP + else + echo "...diff $REF" + diff -u $REF $CMP + fi + fi + done + done + ;; + esac +done |