From cb9ddca848c14e800ca1626145d05feecfa68068 Mon Sep 17 00:00:00 2001 From: serr Date: Tue, 13 May 2025 15:33:59 +0300 Subject: [PATCH] yylineno --- analyzers/test/test.l | 13 ++++++------- analyzers/test/test.y | 2 +- 2 files changed, 7 insertions(+), 8 deletions(-) diff --git a/analyzers/test/test.l b/analyzers/test/test.l index b5d1d2c..6244dc9 100644 --- a/analyzers/test/test.l +++ b/analyzers/test/test.l @@ -4,10 +4,10 @@ #include #include -int CURRENT_LINE_NUMBER = 1; +extern int yylineno; void yyerror(const char *s) { - fprintf(stderr, "\033[91mError at line %i: %s\033[0m\n", CURRENT_LINE_NUMBER, s); + fprintf(stderr, "\033[91mError at line %i: %s\033[0m\n", yylineno, s); exit(1); } @@ -26,7 +26,6 @@ LETTER_OR_DIGIT [a-zA-Z0-9_] "uint16" { return UINT16; } "uint32" { return UINT32; } "uint64" { return UINT64; } - "int" { return INT; } "int8" { return INT8; } "int16" { return INT16; } @@ -40,7 +39,7 @@ LETTER_OR_DIGIT [a-zA-Z0-9_] "}" { return RBRACE; } ";" { return SEMICOLON; } -\"([^"\\]|\\.)*\" { +\"([^"\\]|\\.)*\" { // правило для строк с возможность экранирования через \спецсимвол yylval.str = strdup(yytext); return STRING_LITERAL; } @@ -54,11 +53,11 @@ LETTER_OR_DIGIT [a-zA-Z0-9_] return NUMBER; } -[ \t]+ ; // Пропускаем пробелы и табы -\n { CURRENT_LINE_NUMBER++; } +[ \t\r]+ ; // Пропускаем пробелы и табы +\n { yylineno++; } . { fprintf(stderr, "\033[91mUnexpected character at line %i: %c\033[0m\n", - CURRENT_LINE_NUMBER, yytext[0]); + yylineno, yytext[0]); exit(1); } diff --git a/analyzers/test/test.y b/analyzers/test/test.y index 1dbee70..f982714 100644 --- a/analyzers/test/test.y +++ b/analyzers/test/test.y @@ -3,7 +3,7 @@ #include #include -extern int CURRENT_LINE_NUMBER; +extern int yylineno; extern char *yytext; extern void yyerror(const char *s);