fixed location issues for error messages and scoping. Used location macros and the percent location as defined in guides to track location. Code may warrant cleanup as we don't need to manually keep track of locations ourselves any more through our line and column number variables

This commit is contained in:
Partho Bhattacharya
2025-03-06 02:05:47 -05:00
parent 6fdccb3d8e
commit 211919d70e
6 changed files with 524 additions and 60 deletions

View File

@ -14,7 +14,8 @@
extern int column_number;
extern FILE * yyin;
%}
//%define api.location.type {location_t}
%locations
%union {
int integ;
char * words;
@ -123,8 +124,8 @@ idlist:
;
sblock:
L_BRACE {column_number += yyleng; cur = CreateScope(cur,line_number,column_number);} statement_list {cur = getParent(cur);} R_BRACE
| L_BRACE {column_number += yyleng; cur = CreateScope(cur,line_number,column_number);} dblock statement_list {cur = getParent(cur);} R_BRACE
L_BRACE {cur = CreateScope(cur,@1.first_line,@1.first_column);} statement_list {cur = getParent(cur);} R_BRACE
| L_BRACE {cur = CreateScope(cur,@1.first_line,@1.first_column);} dblock statement_list {cur = getParent(cur);} R_BRACE
;
dblock:
@ -225,7 +226,7 @@ types:
%%
void yyerror(const char *err) {
fprintf(stderr, "ERROR: %s at token %s at line number %d,column number %d\n", err,yytext,line_number,column_number);
fprintf(stderr, "ERROR: %s at token %s at line number %d,column number %d\n", err,yytext,yylloc.first_line,yylloc.first_column);
}
/*
int main(int argc, char * argv[]) {