From 8080e13a2e65e2f701d1b08a3f7e820c5c0eeddd Mon Sep 17 00:00:00 2001 From: serr Date: Sun, 30 Mar 2025 20:00:18 +0300 Subject: [PATCH] some changes --- analyzers/cpl/cpl.l | 57 +++++++++++++++++++++++---------------------- 1 file changed, 29 insertions(+), 28 deletions(-) diff --git a/analyzers/cpl/cpl.l b/analyzers/cpl/cpl.l index 115679c..ddd8c9a 100644 --- a/analyzers/cpl/cpl.l +++ b/analyzers/cpl/cpl.l @@ -5,6 +5,7 @@ #include extern int yylineno; +char *last_lexeme; // Глобальная переменная для хранения текущей лексемы void yyerror(const char *s); %} @@ -16,36 +17,36 @@ WS [ \t]+ %% -"if" { return IF; } -"else" { return ELSE; } -"while" { return WHILE; } -"return" { return RETURN; } -"print" { return PRINT; } -"&&" { return AND; } -"||" { return OR; } -"!" { return NOT; } -">=" { return GE; } -"<=" { return LE; } -"==" { return EQ; } -"!=" { return NE; } -">" { return '>'; } -"<" { return '<'; } -"+" { return '+'; } -"-" { return '-'; } -"*" { return '*'; } -"/" { return '/'; } -"%" { return '%'; } -"(" { return '('; } -")" { return ')'; } -";" { return ';'; } -"=" { return '='; } -"{" { return '{'; } -"}" { return '}'; } +"if" { last_lexeme = strdup("if"); return IF; } +"else" { last_lexeme = strdup("else"); return ELSE; } +"while" { last_lexeme = strdup("while"); return WHILE; } +"return" { last_lexeme = strdup("return"); return RETURN; } +"print" { last_lexeme = strdup("print"); return PRINT; } +"&&" { last_lexeme = strdup("&&"); return AND; } +"||" { last_lexeme = strdup("||"); return OR; } +"!" { last_lexeme = strdup("!"); return NOT; } +">=" { last_lexeme = strdup(">="); return GE; } +"<=" { last_lexeme = strdup("<="); return LE; } +"==" { last_lexeme = strdup("=="); return EQ; } +"!=" { last_lexeme = strdup("!="); return NE; } +">" { last_lexeme = strdup(">"); return '>'; } +"<" { last_lexeme = strdup("<"); return '<'; } +"+" { last_lexeme = strdup("+"); return '+'; } +"-" { last_lexeme = strdup("-"); return '-'; } +"*" { last_lexeme = strdup("*"); return '*'; } +"/" { last_lexeme = strdup("/"); return '/'; } +"%" { last_lexeme = strdup("%"); return '%'; } +"(" { last_lexeme = strdup("("); return '('; } +")" { last_lexeme = strdup(")"); return ')'; } +";" { last_lexeme = strdup(";"); return ';'; } +"=" { last_lexeme = strdup("="); return '='; } +"{" { last_lexeme = strdup("{"); return '{'; } +"}" { last_lexeme = strdup("}"); return '}'; } -{DIGIT}+ { yylval.num = atoi(yytext); return NUMBER; } -{ID} { yylval.str = strdup(yytext); return IDENTIFIER; } +{DIGIT}+ { last_lexeme = strdup(yytext); yylval.num = atoi(yytext); return NUMBER; } +{ID} { last_lexeme = strdup(yytext); yylval.str = strdup(yytext); return IDENTIFIER; } {WS} /* skip whitespace */ \n { yylineno++; } -. { yyerror("Invalid character"); } +. { last_lexeme = strdup(yytext); yyerror("invalid character"); } %% \ No newline at end of file