ilya
serr 2025-05-13 15:33:59 +03:00
parent eb474dcd26
commit cb9ddca848
2 changed files with 7 additions and 8 deletions

View File

@ -4,10 +4,10 @@
#include <string.h> #include <string.h>
#include <stdlib.h> #include <stdlib.h>
int CURRENT_LINE_NUMBER = 1; extern int yylineno;
void yyerror(const char *s) { 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); exit(1);
} }
@ -26,7 +26,6 @@ LETTER_OR_DIGIT [a-zA-Z0-9_]
"uint16" { return UINT16; } "uint16" { return UINT16; }
"uint32" { return UINT32; } "uint32" { return UINT32; }
"uint64" { return UINT64; } "uint64" { return UINT64; }
"int" { return INT; } "int" { return INT; }
"int8" { return INT8; } "int8" { return INT8; }
"int16" { return INT16; } "int16" { return INT16; }
@ -40,7 +39,7 @@ LETTER_OR_DIGIT [a-zA-Z0-9_]
"}" { return RBRACE; } "}" { return RBRACE; }
";" { return SEMICOLON; } ";" { return SEMICOLON; }
\"([^"\\]|\\.)*\" { \"([^"\\]|\\.)*\" { // правило для строк с возможность экранирования через \спецсимвол
yylval.str = strdup(yytext); yylval.str = strdup(yytext);
return STRING_LITERAL; return STRING_LITERAL;
} }
@ -54,11 +53,11 @@ LETTER_OR_DIGIT [a-zA-Z0-9_]
return NUMBER; return NUMBER;
} }
[ \t]+ ; // Пропускаем пробелы и табы [ \t\r]+ ; // Пропускаем пробелы и табы
\n { CURRENT_LINE_NUMBER++; } \n { yylineno++; }
. { . {
fprintf(stderr, "\033[91mUnexpected character at line %i: %c\033[0m\n", fprintf(stderr, "\033[91mUnexpected character at line %i: %c\033[0m\n",
CURRENT_LINE_NUMBER, yytext[0]); yylineno, yytext[0]);
exit(1); exit(1);
} }

View File

@ -3,7 +3,7 @@
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
extern int CURRENT_LINE_NUMBER; extern int yylineno;
extern char *yytext; extern char *yytext;
extern void yyerror(const char *s); extern void yyerror(const char *s);