passing first test

This commit is contained in:
bronku 2025-11-21 18:08:06 +01:00
parent 1ce662294b
commit 9c493f543a
3 changed files with 19 additions and 11 deletions

View file

@ -1,14 +1,22 @@
%option c++
%option noyywrap
%option yyclass="Scanner"
%x STRING
%{
#include "scanner.hpp"
%}
%%
[0-9]+ { return yy::parser::token::TOK_NUMBER; }
[a-zA-Z]+ { yylval->as<std::string>() = yytext; return yy::parser::token::TOK_WORD; }
[ \t\r\n]+ { /* skip */ }
. { return yy::parser::token::TOK_CHAR; }
[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; }
\n { return yy::parser::token::TOK_NEWLINE; }
\= { return yy::parser::token::TOK_EQUALS; }
\+ { return yy::parser::token::TOK_PLUS; }
\- { return yy::parser::token::TOK_MINUS; }
\" { yymore(); BEGIN(STRING); }
<STRING>\"\" { yymore(); }
<STRING>\" { BEGIN(INITIAL); yylval->as<std::string>() = yytext; return yy::parser::token::TOK_STRING; }
<STRING>. { yymore(); }
. { /* the last rule, ignore anything else (there should be nothing) */}
%%