proper eof handling

This commit is contained in:
bronku 2025-11-25 13:05:01 +01:00
parent 6a66b63680
commit 1c21aede4b
8 changed files with 9 additions and 8 deletions

View file

@ -23,6 +23,7 @@ in { return yy::parser::token::TOK_KW_IF;}
\" { yymore(); BEGIN(STRING); } \" { yymore(); BEGIN(STRING); }
[0-9]+ { yylval->as<std::string>() = yytext; return yy::parser::token::TOK_NUMBER; } [0-9]+ { yylval->as<std::string>() = yytext; return yy::parser::token::TOK_NUMBER; }
[_a-zA-Z]+ { yylval->as<std::string>() = yytext; return yy::parser::token::TOK_IDENTIFIER; } [_a-zA-Z]+ { yylval->as<std::string>() = yytext; return yy::parser::token::TOK_IDENTIFIER; }
<<EOF>> { return yy::parser::token::TOK_EOF; }
. { /* the last rule, ignore anything else (there should be nothing) */} . { /* the last rule, ignore anything else (there should be nothing) */}
<STRING>\"\" { yymore(); } <STRING>\"\" { yymore(); }

View file

@ -13,9 +13,9 @@ void dump_tokens(Scanner &scanner)
while (true) while (true)
{ {
int tok = scanner.lex(&lval); 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<kind>(tok));
break; break;
} }