diff --git a/.gitignore b/.gitignore index 47977605ceb34efc8a263add78ab13062306f31e..e763a90e2e05103c2d4b983203cefb805cfa70dc 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,5 @@ -.idea +.idea/ Appendix*.pdf -Project*.pdf \ No newline at end of file +Project*.pdf +.vscode/ +*/*.o \ No newline at end of file diff --git a/Code/lex.yy.c b/Code/lex.yy.c index 9cea2454c55707afa075438bb7258346de988679..a61d60b802ebf97935d63bd2d1bcb86acc7e674a 100644 --- a/Code/lex.yy.c +++ b/Code/lex.yy.c @@ -528,24 +528,8 @@ char *yytext; #include <stdio.h> #include "debug.h" #include "syntax.tab.h" - - struct YYLTYPE { - int first_line; - int first_column; - int last_line; - int last_column; - }; - - struct YYLTYPE yylloc = {0}; - - int yycolumn = 1; - #define YY_USER_ACTION \ - yylloc.first_line = yylloc.last_line = yylineno; \ - yylloc.first_column = yycolumn; \ - yylloc.last_column = yycolumn + yyleng - 1; \ - yycolumn += yyleng; -#line 547 "./lex.yy.c" -#line 548 "./lex.yy.c" +#line 531 "./lex.yy.c" +#line 532 "./lex.yy.c" #define INITIAL 0 @@ -762,9 +746,9 @@ YY_DECL } { -#line 51 "./lexical.l" +#line 35 "./lexical.l" -#line 767 "./lex.yy.c" +#line 751 "./lex.yy.c" while ( /*CONSTCOND*/1 ) /* loops until end-of-file is reached */ { @@ -823,157 +807,157 @@ do_action: /* This label is used only to access EOF actions. */ case 1: YY_RULE_SETUP -#line 52 "./lexical.l" +#line 36 "./lexical.l" { ELEMENT("STRUCT"); return STRUCT; } YY_BREAK case 2: YY_RULE_SETUP -#line 53 "./lexical.l" +#line 37 "./lexical.l" { ELEMENT("RETURN"); return RETURN; } YY_BREAK case 3: YY_RULE_SETUP -#line 54 "./lexical.l" +#line 38 "./lexical.l" { ELEMENT("IF"); return IF; } YY_BREAK case 4: YY_RULE_SETUP -#line 55 "./lexical.l" +#line 39 "./lexical.l" { ELEMENT("ELSE"); return ELSE; } YY_BREAK case 5: YY_RULE_SETUP -#line 56 "./lexical.l" +#line 40 "./lexical.l" { ELEMENT("WHILE"); return WHILE; } YY_BREAK case 6: YY_RULE_SETUP -#line 57 "./lexical.l" +#line 41 "./lexical.l" { ELEMENT("TYPE"); return TYPE; } YY_BREAK case 7: /* rule 7 can match eol */ YY_RULE_SETUP -#line 58 "./lexical.l" +#line 42 "./lexical.l" { unput(yytext[yyleng-1]); yycolumn--,yytext[yyleng-1] = 0; Log("TYPE = INT:( %s )",yytext); return INT;} YY_BREAK case 8: YY_RULE_SETUP -#line 59 "./lexical.l" +#line 43 "./lexical.l" { Log("TYPE = FLOAT: %s",yytext); return FLOAT;} YY_BREAK case 9: YY_RULE_SETUP -#line 60 "./lexical.l" +#line 44 "./lexical.l" { ELEMENT("ID"); return ID; } YY_BREAK case 10: YY_RULE_SETUP -#line 61 "./lexical.l" +#line 45 "./lexical.l" { ELEMENT("SEMI"); return SEMI;} YY_BREAK case 11: YY_RULE_SETUP -#line 62 "./lexical.l" +#line 46 "./lexical.l" { ELEMENT("COMMA"); return COMMA;} YY_BREAK case 12: YY_RULE_SETUP -#line 63 "./lexical.l" +#line 47 "./lexical.l" { ELEMENT("ASSIGNOP"); return ASSIGNOP;} YY_BREAK case 13: YY_RULE_SETUP -#line 64 "./lexical.l" +#line 48 "./lexical.l" { ELEMENT("PLUS"); return PLUS;} YY_BREAK case 14: YY_RULE_SETUP -#line 65 "./lexical.l" +#line 49 "./lexical.l" { ELEMENT("MINUS"); return MINUS;} YY_BREAK case 15: YY_RULE_SETUP -#line 66 "./lexical.l" +#line 50 "./lexical.l" { ELEMENT("STAR"); return STAR;} YY_BREAK case 16: YY_RULE_SETUP -#line 67 "./lexical.l" +#line 51 "./lexical.l" { ELEMENT("DIV"); return DIV;} YY_BREAK case 17: YY_RULE_SETUP -#line 68 "./lexical.l" +#line 52 "./lexical.l" { ELEMENT("AND"); return AND;} YY_BREAK case 18: YY_RULE_SETUP -#line 69 "./lexical.l" +#line 53 "./lexical.l" { ELEMENT("OR"); return OR;} YY_BREAK case 19: YY_RULE_SETUP -#line 70 "./lexical.l" +#line 54 "./lexical.l" { ELEMENT("DOT"); return DOT;} YY_BREAK case 20: YY_RULE_SETUP -#line 71 "./lexical.l" +#line 55 "./lexical.l" { ELEMENT("NOT"); return NOT;} YY_BREAK case 21: YY_RULE_SETUP -#line 72 "./lexical.l" +#line 56 "./lexical.l" { ELEMENT("LP"); return LP;} YY_BREAK case 22: YY_RULE_SETUP -#line 73 "./lexical.l" +#line 57 "./lexical.l" { ELEMENT("RP"); return RP;} YY_BREAK case 23: YY_RULE_SETUP -#line 74 "./lexical.l" +#line 58 "./lexical.l" { ELEMENT("LB"); return LB;} YY_BREAK case 24: YY_RULE_SETUP -#line 75 "./lexical.l" +#line 59 "./lexical.l" { ELEMENT("RB"); return RB;} YY_BREAK case 25: YY_RULE_SETUP -#line 76 "./lexical.l" +#line 60 "./lexical.l" { ELEMENT("LC"); return LC;} YY_BREAK case 26: YY_RULE_SETUP -#line 77 "./lexical.l" +#line 61 "./lexical.l" { ELEMENT("RC"); return RC;} YY_BREAK case 27: YY_RULE_SETUP -#line 78 "./lexical.l" +#line 62 "./lexical.l" { ;} YY_BREAK case 28: /* rule 28 can match eol */ YY_RULE_SETUP -#line 79 "./lexical.l" +#line 63 "./lexical.l" { yycolumn += 1; } YY_BREAK case 29: YY_RULE_SETUP -#line 80 "./lexical.l" +#line 64 "./lexical.l" { printf("Error type A at Line %d: Mysterious characters \'%s\'\n", yylineno, yytext); } YY_BREAK case 30: YY_RULE_SETUP -#line 82 "./lexical.l" +#line 66 "./lexical.l" ECHO; YY_BREAK -#line 976 "./lex.yy.c" +#line 960 "./lex.yy.c" case YY_STATE_EOF(INITIAL): yyterminate(); @@ -1978,7 +1962,7 @@ void yyfree (void * ptr ) #define YYTABLES_NAME "yytables" -#line 82 "./lexical.l" +#line 66 "./lexical.l" // #ifdef SCANNER_DEBUG diff --git a/Code/lexical.l b/Code/lexical.l index e1918b3d57351a6d771fa0715bf7728fa770d65e..7aba43e8f9d2dc793a53c71c1e0a9ff56c8c0173 100755 --- a/Code/lexical.l +++ b/Code/lexical.l @@ -2,22 +2,6 @@ #include <stdio.h> #include "debug.h" #include "syntax.tab.h" - - struct YYLTYPE { - int first_line; - int first_column; - int last_line; - int last_column; - }; - - struct YYLTYPE yylloc = {0}; - - int yycolumn = 1; - #define YY_USER_ACTION \ - yylloc.first_line = yylloc.last_line = yylineno; \ - yylloc.first_column = yycolumn; \ - yylloc.last_column = yycolumn + yyleng - 1; \ - yycolumn += yyleng; %} INT (([+-]?[0-9])|([+-]?[1-9][0-9]+)|(0[xX][0-9A-Fa-f]+)|(0[1-7][0-7]*))[^.] diff --git a/Code/main.c b/Code/main.c index 0aff32478c4035f576caa5741ee58180aca3f7c6..aed16547902a382dc5c4419b575300c5d3328e2e 100755 --- a/Code/main.c +++ b/Code/main.c @@ -1,6 +1,10 @@ -#include "lex.yy.c" #include <stdio.h> +int yyrestart(FILE*); +int yyparse (void); +int yylex(void); +void yyerror(char* s); + int main(int argc,char *argv[]) { if (argc <= 1) { printf("Usage:%s $FILE\n",argv[0]); diff --git a/Code/parser b/Code/parser index 2b32798072bfb6ddebaec0a47e4dff80a039168d..aed685946d9d3fb1860af77994c285b1e0ec4f7f 100755 Binary files a/Code/parser and b/Code/parser differ diff --git a/Code/syntax.tab.c b/Code/syntax.tab.c index e0b11dd0cf05ab369ca94e1dd3ef076d5013f0b2..ee2b932805a9f282cd2a7d48d4b9c3b9901508f2 100644 --- a/Code/syntax.tab.c +++ b/Code/syntax.tab.c @@ -67,11 +67,22 @@ /* First part of user prologue. */ -#line 1 "./syntax.y" +#line 3 "./syntax.y" + + int yycolumn = 1; + #define YY_USER_ACTION \ + yylloc.first_line = yylloc.last_line = yylineno; \ + yylloc.first_column = yycolumn; \ + yylloc.last_column = yycolumn + yyleng - 1; \ + yycolumn += yyleng; +#line 12 "./syntax.y" #include <stdio.h> + #include "lex.yy.c" + + void yyerror(char* s); -#line 75 "./syntax.tab.c" +#line 86 "./syntax.tab.c" # ifndef YY_CAST # ifdef __cplusplus @@ -417,13 +428,15 @@ void free (void *); /* INFRINGES ON USER NAME SPACE */ #if (! defined yyoverflow \ && (! defined __cplusplus \ - || (defined YYSTYPE_IS_TRIVIAL && YYSTYPE_IS_TRIVIAL))) + || (defined YYLTYPE_IS_TRIVIAL && YYLTYPE_IS_TRIVIAL \ + && defined YYSTYPE_IS_TRIVIAL && YYSTYPE_IS_TRIVIAL))) /* A type that is properly aligned for any stack member. */ union yyalloc { yy_state_t yyss_alloc; YYSTYPE yyvs_alloc; + YYLTYPE yyls_alloc; }; /* The size of the maximum gap between one aligned stack and the next. */ @@ -432,8 +445,9 @@ union yyalloc /* The size of an array large to enough to hold all stacks, each with N elements. */ # define YYSTACK_BYTES(N) \ - ((N) * (YYSIZEOF (yy_state_t) + YYSIZEOF (YYSTYPE)) \ - + YYSTACK_GAP_MAXIMUM) + ((N) * (YYSIZEOF (yy_state_t) + YYSIZEOF (YYSTYPE) \ + + YYSIZEOF (YYLTYPE)) \ + + 2 * YYSTACK_GAP_MAXIMUM) # define YYCOPY_NEEDED 1 @@ -539,12 +553,12 @@ static const yytype_int8 yytranslate[] = /* YYRLINE[YYN] -- Source line where rule number YYN was defined. */ static const yytype_uint8 yyrline[] = { - 0, 38, 38, 40, 41, 43, 44, 45, 47, 48, - 53, 54, 56, 57, 59, 60, 62, 66, 67, 69, - 70, 72, 73, 75, 80, 82, 83, 85, 86, 87, - 88, 89, 90, 95, 96, 98, 100, 101, 103, 104, - 108, 109, 110, 111, 112, 113, 114, 115, 116, 117, - 118, 119, 120, 121, 122, 123, 124, 125, 127, 128 + 0, 53, 53, 55, 56, 58, 59, 60, 62, 63, + 68, 69, 71, 72, 74, 75, 77, 81, 82, 84, + 85, 87, 88, 90, 95, 97, 98, 100, 101, 102, + 103, 104, 105, 110, 111, 113, 115, 116, 118, 119, + 123, 124, 125, 126, 127, 128, 129, 130, 131, 132, + 133, 134, 135, 136, 137, 138, 139, 140, 142, 143 }; #endif @@ -765,6 +779,32 @@ enum { YYENOMEM = -2 }; Use YYerror or YYUNDEF. */ #define YYERRCODE YYUNDEF +/* YYLLOC_DEFAULT -- Set CURRENT to span from RHS[1] to RHS[N]. + If N is 0, then set CURRENT to the empty location which ends + the previous symbol: RHS[0] (always defined). */ + +#ifndef YYLLOC_DEFAULT +# define YYLLOC_DEFAULT(Current, Rhs, N) \ + do \ + if (N) \ + { \ + (Current).first_line = YYRHSLOC (Rhs, 1).first_line; \ + (Current).first_column = YYRHSLOC (Rhs, 1).first_column; \ + (Current).last_line = YYRHSLOC (Rhs, N).last_line; \ + (Current).last_column = YYRHSLOC (Rhs, N).last_column; \ + } \ + else \ + { \ + (Current).first_line = (Current).last_line = \ + YYRHSLOC (Rhs, 0).last_line; \ + (Current).first_column = (Current).last_column = \ + YYRHSLOC (Rhs, 0).last_column; \ + } \ + while (0) +#endif + +#define YYRHSLOC(Rhs, K) ((Rhs)[K]) + /* Enable debugging if requested. */ #if YYDEBUG @@ -781,6 +821,63 @@ do { \ } while (0) +/* YYLOCATION_PRINT -- Print the location on the stream. + This macro was not mandated originally: define only if we know + we won't break user code: when these are the locations we know. */ + +# ifndef YYLOCATION_PRINT + +# if defined YY_LOCATION_PRINT + + /* Temporary convenience wrapper in case some people defined the + undocumented and private YY_LOCATION_PRINT macros. */ +# define YYLOCATION_PRINT(File, Loc) YY_LOCATION_PRINT(File, *(Loc)) + +# elif defined YYLTYPE_IS_TRIVIAL && YYLTYPE_IS_TRIVIAL + +/* Print *YYLOCP on YYO. Private, do not rely on its existence. */ + +YY_ATTRIBUTE_UNUSED +static int +yy_location_print_ (FILE *yyo, YYLTYPE const * const yylocp) +{ + int res = 0; + int end_col = 0 != yylocp->last_column ? yylocp->last_column - 1 : 0; + if (0 <= yylocp->first_line) + { + res += YYFPRINTF (yyo, "%d", yylocp->first_line); + if (0 <= yylocp->first_column) + res += YYFPRINTF (yyo, ".%d", yylocp->first_column); + } + if (0 <= yylocp->last_line) + { + if (yylocp->first_line < yylocp->last_line) + { + res += YYFPRINTF (yyo, "-%d", yylocp->last_line); + if (0 <= end_col) + res += YYFPRINTF (yyo, ".%d", end_col); + } + else if (0 <= end_col && yylocp->first_column < end_col) + res += YYFPRINTF (yyo, "-%d", end_col); + } + return res; +} + +# define YYLOCATION_PRINT yy_location_print_ + + /* Temporary convenience wrapper in case some people defined the + undocumented and private YY_LOCATION_PRINT macros. */ +# define YY_LOCATION_PRINT(File, Loc) YYLOCATION_PRINT(File, &(Loc)) + +# else + +# define YYLOCATION_PRINT(File, Loc) ((void) 0) + /* Temporary convenience wrapper in case some people defined the + undocumented and private YY_LOCATION_PRINT macros. */ +# define YY_LOCATION_PRINT YYLOCATION_PRINT + +# endif +# endif /* !defined YYLOCATION_PRINT */ # define YY_SYMBOL_PRINT(Title, Kind, Value, Location) \ @@ -789,7 +886,7 @@ do { \ { \ YYFPRINTF (stderr, "%s ", Title); \ yy_symbol_print (stderr, \ - Kind, Value); \ + Kind, Value, Location); \ YYFPRINTF (stderr, "\n"); \ } \ } while (0) @@ -801,10 +898,11 @@ do { \ static void yy_symbol_value_print (FILE *yyo, - yysymbol_kind_t yykind, YYSTYPE const * const yyvaluep) + yysymbol_kind_t yykind, YYSTYPE const * const yyvaluep, YYLTYPE const * const yylocationp) { FILE *yyoutput = yyo; YY_USE (yyoutput); + YY_USE (yylocationp); if (!yyvaluep) return; YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN @@ -819,12 +917,14 @@ yy_symbol_value_print (FILE *yyo, static void yy_symbol_print (FILE *yyo, - yysymbol_kind_t yykind, YYSTYPE const * const yyvaluep) + yysymbol_kind_t yykind, YYSTYPE const * const yyvaluep, YYLTYPE const * const yylocationp) { YYFPRINTF (yyo, "%s %s (", yykind < YYNTOKENS ? "token" : "nterm", yysymbol_name (yykind)); - yy_symbol_value_print (yyo, yykind, yyvaluep); + YYLOCATION_PRINT (yyo, yylocationp); + YYFPRINTF (yyo, ": "); + yy_symbol_value_print (yyo, yykind, yyvaluep, yylocationp); YYFPRINTF (yyo, ")"); } @@ -857,7 +957,7 @@ do { \ `------------------------------------------------*/ static void -yy_reduce_print (yy_state_t *yyssp, YYSTYPE *yyvsp, +yy_reduce_print (yy_state_t *yyssp, YYSTYPE *yyvsp, YYLTYPE *yylsp, int yyrule) { int yylno = yyrline[yyrule]; @@ -871,7 +971,8 @@ yy_reduce_print (yy_state_t *yyssp, YYSTYPE *yyvsp, YYFPRINTF (stderr, " $%d = ", yyi + 1); yy_symbol_print (stderr, YY_ACCESSING_SYMBOL (+yyssp[yyi + 1 - yynrhs]), - &yyvsp[(yyi + 1) - (yynrhs)]); + &yyvsp[(yyi + 1) - (yynrhs)], + &(yylsp[(yyi + 1) - (yynrhs)])); YYFPRINTF (stderr, "\n"); } } @@ -879,7 +980,7 @@ yy_reduce_print (yy_state_t *yyssp, YYSTYPE *yyvsp, # define YY_REDUCE_PRINT(Rule) \ do { \ if (yydebug) \ - yy_reduce_print (yyssp, yyvsp, Rule); \ + yy_reduce_print (yyssp, yyvsp, yylsp, Rule); \ } while (0) /* Nonzero means print parse trace. It is left uninitialized so that @@ -920,9 +1021,10 @@ int yydebug; static void yydestruct (const char *yymsg, - yysymbol_kind_t yykind, YYSTYPE *yyvaluep) + yysymbol_kind_t yykind, YYSTYPE *yyvaluep, YYLTYPE *yylocationp) { YY_USE (yyvaluep); + YY_USE (yylocationp); if (!yymsg) yymsg = "Deleting"; YY_SYMBOL_PRINT (yymsg, yykind, yyvaluep, yylocationp); @@ -938,6 +1040,12 @@ int yychar; /* The semantic value of the lookahead symbol. */ YYSTYPE yylval; +/* Location data for the lookahead symbol. */ +YYLTYPE yylloc +# if defined YYLTYPE_IS_TRIVIAL && YYLTYPE_IS_TRIVIAL + = { 1, 1, 1, 1 } +# endif +; /* Number of syntax errors so far. */ int yynerrs; @@ -971,6 +1079,11 @@ yyparse (void) YYSTYPE *yyvs = yyvsa; YYSTYPE *yyvsp = yyvs; + /* The location stack: array, bottom, top. */ + YYLTYPE yylsa[YYINITDEPTH]; + YYLTYPE *yyls = yylsa; + YYLTYPE *yylsp = yyls; + int yyn; /* The return value of yyparse. */ int yyresult; @@ -979,10 +1092,14 @@ yyparse (void) /* The variables used to return semantic value and location from the action routines. */ YYSTYPE yyval; + YYLTYPE yyloc; + + /* The locations where the error started and ended. */ + YYLTYPE yyerror_range[3]; -#define YYPOPSTACK(N) (yyvsp -= (N), yyssp -= (N)) +#define YYPOPSTACK(N) (yyvsp -= (N), yyssp -= (N), yylsp -= (N)) /* The number of symbols on the RHS of the reduced rule. Keep to zero when no symbol should be popped. */ @@ -992,6 +1109,7 @@ yyparse (void) yychar = YYEMPTY; /* Cause a token to be read. */ + yylsp[0] = yylloc; goto yysetstate; @@ -1030,6 +1148,7 @@ yysetstate: memory. */ yy_state_t *yyss1 = yyss; YYSTYPE *yyvs1 = yyvs; + YYLTYPE *yyls1 = yyls; /* Each stack pointer address is followed by the size of the data in use in that stack, in bytes. This used to be a @@ -1038,9 +1157,11 @@ yysetstate: yyoverflow (YY_("memory exhausted"), &yyss1, yysize * YYSIZEOF (*yyssp), &yyvs1, yysize * YYSIZEOF (*yyvsp), + &yyls1, yysize * YYSIZEOF (*yylsp), &yystacksize); yyss = yyss1; yyvs = yyvs1; + yyls = yyls1; } # else /* defined YYSTACK_RELOCATE */ /* Extend the stack our own way. */ @@ -1059,6 +1180,7 @@ yysetstate: YYNOMEM; YYSTACK_RELOCATE (yyss_alloc, yyss); YYSTACK_RELOCATE (yyvs_alloc, yyvs); + YYSTACK_RELOCATE (yyls_alloc, yyls); # undef YYSTACK_RELOCATE if (yyss1 != yyssa) YYSTACK_FREE (yyss1); @@ -1067,6 +1189,7 @@ yysetstate: yyssp = yyss + yysize - 1; yyvsp = yyvs + yysize - 1; + yylsp = yyls + yysize - 1; YY_IGNORE_USELESS_CAST_BEGIN YYDPRINTF ((stderr, "Stack size increased to %ld\n", @@ -1120,6 +1243,7 @@ yybackup: loop in error recovery. */ yychar = YYUNDEF; yytoken = YYSYMBOL_YYerror; + yyerror_range[1] = yylloc; goto yyerrlab1; } else @@ -1153,6 +1277,7 @@ yybackup: YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN *++yyvsp = yylval; YY_IGNORE_MAYBE_UNINITIALIZED_END + *++yylsp = yylloc; /* Discard the shifted token. */ yychar = YYEMPTY; @@ -1186,12 +1311,14 @@ yyreduce: GCC warning that YYVAL may be used uninitialized. */ yyval = yyvsp[1-yylen]; - + /* Default location. */ + YYLLOC_DEFAULT (yyloc, (yylsp - yylen), yylen); + yyerror_range[1] = yyloc; YY_REDUCE_PRINT (yyn); switch (yyn) { -#line 1195 "./syntax.tab.c" +#line 1322 "./syntax.tab.c" default: break; } @@ -1212,6 +1339,7 @@ yyreduce: yylen = 0; *++yyvsp = yyval; + *++yylsp = yyloc; /* Now 'shift' the result of the reduction. Determine what state that goes to, based on the state we popped back to and the rule @@ -1241,6 +1369,7 @@ yyerrlab: yyerror (YY_("syntax error")); } + yyerror_range[1] = yylloc; if (yyerrstatus == 3) { /* If just tried and failed to reuse lookahead token after an @@ -1255,7 +1384,7 @@ yyerrlab: else { yydestruct ("Error: discarding", - yytoken, &yylval); + yytoken, &yylval, &yylloc); yychar = YYEMPTY; } } @@ -1309,9 +1438,9 @@ yyerrlab1: if (yyssp == yyss) YYABORT; - + yyerror_range[1] = *yylsp; yydestruct ("Error: popping", - YY_ACCESSING_SYMBOL (yystate), yyvsp); + YY_ACCESSING_SYMBOL (yystate), yyvsp, yylsp); YYPOPSTACK (1); yystate = *yyssp; YY_STACK_PRINT (yyss, yyssp); @@ -1321,6 +1450,9 @@ yyerrlab1: *++yyvsp = yylval; YY_IGNORE_MAYBE_UNINITIALIZED_END + yyerror_range[2] = yylloc; + ++yylsp; + YYLLOC_DEFAULT (*yylsp, yyerror_range, 2); /* Shift the error token. */ YY_SYMBOL_PRINT ("Shifting", YY_ACCESSING_SYMBOL (yyn), yyvsp, yylsp); @@ -1364,7 +1496,7 @@ yyreturnlab: user semantic actions for why this is necessary. */ yytoken = YYTRANSLATE (yychar); yydestruct ("Cleanup: discarding lookahead", - yytoken, &yylval); + yytoken, &yylval, &yylloc); } /* Do not reclaim the symbols of the rule whose action triggered this YYABORT or YYACCEPT. */ @@ -1373,7 +1505,7 @@ yyreturnlab: while (yyssp != yyss) { yydestruct ("Cleanup: popping", - YY_ACCESSING_SYMBOL (+*yyssp), yyvsp); + YY_ACCESSING_SYMBOL (+*yyssp), yyvsp, yylsp); YYPOPSTACK (1); } #ifndef yyoverflow @@ -1384,5 +1516,5 @@ yyreturnlab: return yyresult; } -#line 132 "./syntax.y" +#line 147 "./syntax.y" diff --git a/Code/syntax.tab.h b/Code/syntax.tab.h index 33770583166d87a85592af89bad2b8f82bc0048e..1b91d457730152a633ebc9d809d3aa62aec4f7d4 100644 --- a/Code/syntax.tab.h +++ b/Code/syntax.tab.h @@ -92,9 +92,23 @@ typedef int YYSTYPE; # define YYSTYPE_IS_DECLARED 1 #endif +/* Location type. */ +#if ! defined YYLTYPE && ! defined YYLTYPE_IS_DECLARED +typedef struct YYLTYPE YYLTYPE; +struct YYLTYPE +{ + int first_line; + int first_column; + int last_line; + int last_column; +}; +# define YYLTYPE_IS_DECLARED 1 +# define YYLTYPE_IS_TRIVIAL 1 +#endif -extern YYSTYPE yylval; +extern YYSTYPE yylval; +extern YYLTYPE yylloc; int yyparse (void); diff --git a/Code/syntax.y b/Code/syntax.y index 001cb406bbb0ad64b73381b1950c1b5b6df2b6fd..e43103cf1a4fb0d0dfb91d8fa384df7209bca172 100755 --- a/Code/syntax.y +++ b/Code/syntax.y @@ -1,7 +1,22 @@ +%locations + +%{ + int yycolumn = 1; + #define YY_USER_ACTION \ + yylloc.first_line = yylloc.last_line = yylineno; \ + yylloc.first_column = yycolumn; \ + yylloc.last_column = yycolumn + yyleng - 1; \ + yycolumn += yyleng; +%} + %{ #include <stdio.h> + #include "lex.yy.c" + + void yyerror(char* s); %} + /* declared tokens */ %token INT %token FLOAT