some changes
parent
54be26ab2b
commit
8080e13a2e
|
@ -5,6 +5,7 @@
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
extern int yylineno;
|
extern int yylineno;
|
||||||
|
char *last_lexeme; // Глобальная переменная для хранения текущей лексемы
|
||||||
void yyerror(const char *s);
|
void yyerror(const char *s);
|
||||||
%}
|
%}
|
||||||
|
|
||||||
|
@ -16,36 +17,36 @@ WS [ \t]+
|
||||||
|
|
||||||
%%
|
%%
|
||||||
|
|
||||||
"if" { return IF; }
|
"if" { last_lexeme = strdup("if"); return IF; }
|
||||||
"else" { return ELSE; }
|
"else" { last_lexeme = strdup("else"); return ELSE; }
|
||||||
"while" { return WHILE; }
|
"while" { last_lexeme = strdup("while"); return WHILE; }
|
||||||
"return" { return RETURN; }
|
"return" { last_lexeme = strdup("return"); return RETURN; }
|
||||||
"print" { return PRINT; }
|
"print" { last_lexeme = strdup("print"); return PRINT; }
|
||||||
"&&" { return AND; }
|
"&&" { last_lexeme = strdup("&&"); return AND; }
|
||||||
"||" { return OR; }
|
"||" { last_lexeme = strdup("||"); return OR; }
|
||||||
"!" { return NOT; }
|
"!" { last_lexeme = strdup("!"); return NOT; }
|
||||||
">=" { return GE; }
|
">=" { last_lexeme = strdup(">="); return GE; }
|
||||||
"<=" { return LE; }
|
"<=" { last_lexeme = strdup("<="); return LE; }
|
||||||
"==" { return EQ; }
|
"==" { last_lexeme = strdup("=="); return EQ; }
|
||||||
"!=" { return NE; }
|
"!=" { last_lexeme = strdup("!="); return NE; }
|
||||||
">" { return '>'; }
|
">" { last_lexeme = strdup(">"); return '>'; }
|
||||||
"<" { return '<'; }
|
"<" { last_lexeme = strdup("<"); return '<'; }
|
||||||
"+" { return '+'; }
|
"+" { last_lexeme = strdup("+"); return '+'; }
|
||||||
"-" { return '-'; }
|
"-" { last_lexeme = strdup("-"); return '-'; }
|
||||||
"*" { return '*'; }
|
"*" { last_lexeme = strdup("*"); return '*'; }
|
||||||
"/" { return '/'; }
|
"/" { last_lexeme = strdup("/"); return '/'; }
|
||||||
"%" { return '%'; }
|
"%" { last_lexeme = strdup("%"); return '%'; }
|
||||||
"(" { return '('; }
|
"(" { last_lexeme = strdup("("); return '('; }
|
||||||
")" { return ')'; }
|
")" { last_lexeme = strdup(")"); return ')'; }
|
||||||
";" { return ';'; }
|
";" { last_lexeme = strdup(";"); return ';'; }
|
||||||
"=" { return '='; }
|
"=" { last_lexeme = strdup("="); return '='; }
|
||||||
"{" { return '{'; }
|
"{" { last_lexeme = strdup("{"); return '{'; }
|
||||||
"}" { return '}'; }
|
"}" { last_lexeme = strdup("}"); return '}'; }
|
||||||
|
|
||||||
{DIGIT}+ { yylval.num = atoi(yytext); return NUMBER; }
|
{DIGIT}+ { last_lexeme = strdup(yytext); yylval.num = atoi(yytext); return NUMBER; }
|
||||||
{ID} { yylval.str = strdup(yytext); return IDENTIFIER; }
|
{ID} { last_lexeme = strdup(yytext); yylval.str = strdup(yytext); return IDENTIFIER; }
|
||||||
{WS} /* skip whitespace */
|
{WS} /* skip whitespace */
|
||||||
\n { yylineno++; }
|
\n { yylineno++; }
|
||||||
. { yyerror("Invalid character"); }
|
. { last_lexeme = strdup(yytext); yyerror("invalid character"); }
|
||||||
|
|
||||||
%%
|
%%
|
Loading…
Reference in New Issue