yylineno
parent
eb474dcd26
commit
cb9ddca848
|
@ -4,10 +4,10 @@
|
|||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
|
|
|
@ -3,7 +3,7 @@
|
|||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
extern int CURRENT_LINE_NUMBER;
|
||||
extern int yylineno;
|
||||
extern char *yytext;
|
||||
|
||||
extern void yyerror(const char *s);
|
||||
|
|
Loading…
Reference in New Issue