diff --git a/src/lexer.l b/src/lexer.l index 259e23a..d21f334 100644 --- a/src/lexer.l +++ b/src/lexer.l @@ -23,6 +23,7 @@ in { return yy::parser::token::TOK_KW_IF;} \" { yymore(); BEGIN(STRING); } [0-9]+ { yylval->as() = yytext; return yy::parser::token::TOK_NUMBER; } [_a-zA-Z]+ { yylval->as() = yytext; return yy::parser::token::TOK_IDENTIFIER; } +<> { return yy::parser::token::TOK_EOF; } . { /* the last rule, ignore anything else (there should be nothing) */} \"\" { yymore(); } diff --git a/src/main.cpp b/src/main.cpp index d37685f..bae4349 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -13,9 +13,9 @@ void dump_tokens(Scanner &scanner) while (true) { int tok = scanner.lex(&lval); - if (tok == Parser::token::TOK_YYEOF) + if (tok == Parser::token::TOK_EOF) { - std::cout << "NEWLINE\nEOF"; + std::cout << Parser::symbol_name(static_cast(tok)); break; } diff --git a/test/lexer/1.in b/test/lexer/1.in index 012f05c..1af5d5b 100644 --- a/test/lexer/1.in +++ b/test/lexer/1.in @@ -1,3 +1,3 @@ hello = 42 name = "world" -x + y - z \ No newline at end of file +x + y - z diff --git a/test/lexer/2.in b/test/lexer/2.in index a665b92..d2be888 100644 --- a/test/lexer/2.in +++ b/test/lexer/2.in @@ -2,4 +2,4 @@ def function_name(): if condition: return value for item in list: - print(item) \ No newline at end of file + print(item) diff --git a/test/lexer/3.in b/test/lexer/3.in index 884f900..03eb065 100644 --- a/test/lexer/3.in +++ b/test/lexer/3.in @@ -1,3 +1,3 @@ x == y != z < > <= >= a + b - c * d / e % f -( ) [ ] { } , : . ; \ No newline at end of file +( ) [ ] { } , : . ; diff --git a/test/lexer/4.in b/test/lexer/4.in index 4330d1b..f49d75e 100644 --- a/test/lexer/4.in +++ b/test/lexer/4.in @@ -1,3 +1,3 @@ 42 3.14 0xFF 0b1010 "hello" 'world' """multiline""" -'test' "escaped\"quote" \ No newline at end of file +'test' "escaped\"quote" diff --git a/test/lexer/5.in b/test/lexer/5.in index 4269296..3ae113c 100644 --- a/test/lexer/5.in +++ b/test/lexer/5.in @@ -5,4 +5,4 @@ def calculate(a, b=10): return result # This is a comment -x = calculate(5, 15) \ No newline at end of file +x = calculate(5, 15) diff --git a/test/lexer/6.in b/test/lexer/6.in index 3427e0e..3ae7214 100644 --- a/test/lexer/6.in +++ b/test/lexer/6.in @@ -2,4 +2,4 @@ _private = "valid" var123 = 456 CamelCase = True snake_case = False -very_long_variable_name_123 = "test" \ No newline at end of file +very_long_variable_name_123 = "test"