diff --git a/analyzers/c_analyzer/c_analyzer.l b/analyzers/c_analyzer/c_analyzer.l index edaf2eb..43cf727 100644 --- a/analyzers/c_analyzer/c_analyzer.l +++ b/analyzers/c_analyzer/c_analyzer.l @@ -27,14 +27,31 @@ void yyerror(const char *s) { "*" { return MULT; } "/" { return DIV; } "%" { return MOD; } -"&&" { return AND; } -"||" { return OR; } +"&&" { return AND; } +"||" { return OR; } "!" { return NOT; } "return" { return RET; } "print" { return PRINT; } "while" { return WHILE; } -"if" { return IF; } -"else" { return ELSE; } +"if" { return IF; } +"else" { return ELSE; } + +"//" { + int c; + while ((c = input()) != '\n' && c != 0); // Используем input() вместо yyinput() + if (c == '\n') line_number++; +} + +"/*" { + int c, prev = 0; + while ((c = input()) != 0) { // Используем input() вместо yyinput() + if (c == '\n') line_number++; + if (prev == '*' && c == '/') break; + prev = c; + } + if (c == 0) yyerror("Unterminated comment"); +} + [0-9]+ { yylval.str = strdup(yytext); return NUMBER; } [a-zA-Z_][a-zA-Z0-9_]* { yylval.str = strdup(yytext); return IDENTIFIER; } [ \t] ; diff --git a/code.txt b/code.txt index 3ebf332..5ae8113 100644 --- a/code.txt +++ b/code.txt @@ -1,30 +1,32 @@ { + // 123123132 + /* test */ x = 2 + 1 % 1; - if (!x && 1 || (x + (-100))) { + if (!x && 1 || (x + (-100))) { // comment x = 3; if (x) { x = 5; } } else { - x = 5; + x = 5; // comment } if (x) { - x = 3; + x = 3; // comment } - x = z + 3 + 5; + x = z + 3 + 5; // comment { x = -10; y = (x + +5) % 2; while (x + 1) { - z = y * +2 / -(5 * ( ((3)) )); + z = y * +2 / -(5 * ( ((3)) )); /* comment*/ } } print x; while (1) { x = x + 1; } - return x / 2 + 5; + return x / 2 + 5; /* comment*//* comment*//* comment*/ } \ No newline at end of file