41 lines
873 B
Plaintext
41 lines
873 B
Plaintext
%{
|
|
#include "test.tab.h"
|
|
#include <stdio.h>
|
|
#include <string.h>
|
|
#include <stdlib.h>
|
|
|
|
int CURRENT_LINE_NUMBER = 1;
|
|
|
|
void yyerror(const char *s) {
|
|
fprintf(stderr, "\033[91mError at line %i: %s\033[0m\n", CURRENT_LINE_NUMBER, s);
|
|
exit(1);
|
|
}
|
|
|
|
%}
|
|
|
|
%%
|
|
|
|
[a-zA-Z_][a-zA-Z0-9_]* {
|
|
yylval.str = strdup(yytext);
|
|
return IDENTIFIER;
|
|
}
|
|
[0-9]+ {
|
|
yylval.str = strdup(yytext);
|
|
return NUMBER;
|
|
}
|
|
":=" { return ASSIGN; }
|
|
"{" { return LBRACE; }
|
|
"}" { return RBRACE; }
|
|
[ \t]+ ; // Пропускаем пробелы и табы
|
|
\n { CURRENT_LINE_NUMBER++; }
|
|
. {
|
|
fprintf(stderr, "\033[91mUnexpected character at line %i: %c\033[0m\n",
|
|
CURRENT_LINE_NUMBER, yytext[0]);
|
|
exit(1);
|
|
}
|
|
|
|
%%
|
|
|
|
int yywrap() {
|
|
return 1;
|
|
} |