some progress towards test 2
This commit is contained in:
parent
9c493f543a
commit
87695ebb20
5 changed files with 52 additions and 10 deletions
15
src/lexer.l
15
src/lexer.l
|
|
@ -8,15 +8,24 @@
|
|||
%}
|
||||
|
||||
%%
|
||||
[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; }
|
||||
def { return yy::parser::token::TOK_KW_DEF;}
|
||||
if { return yy::parser::token::TOK_KW_IF;}
|
||||
return { return yy::parser::token::TOK_KW_RETURN;}
|
||||
for { return yy::parser::token::TOK_KW_FOR;}
|
||||
in { return yy::parser::token::TOK_KW_IF;}
|
||||
\n { return yy::parser::token::TOK_NEWLINE; }
|
||||
\( { return yy::parser::token::TOK_L_PAREN; }
|
||||
\) { return yy::parser::token::TOK_R_PAREN; }
|
||||
\: { return yy::parser::token::TOK_COLON; }
|
||||
\= { return yy::parser::token::TOK_EQUALS; }
|
||||
\+ { return yy::parser::token::TOK_PLUS; }
|
||||
\- { return yy::parser::token::TOK_MINUS; }
|
||||
\" { yymore(); BEGIN(STRING); }
|
||||
[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; }
|
||||
. { /* the last rule, ignore anything else (there should be nothing) */}
|
||||
|
||||
<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) */}
|
||||
%%
|
||||
Loading…
Add table
Add a link
Reference in a new issue