diff options
author | Daniel Weipert <code@drogueronin.de> | 2022-11-20 15:20:26 +0100 |
---|---|---|
committer | Daniel Weipert <code@drogueronin.de> | 2022-11-20 15:20:26 +0100 |
commit | b662201aefec7104e7d289981828a66a8226f7bb (patch) | |
tree | c4442d4386e90cb85754579ed787097cbca2a30e /lex.l |
Initial commit
Diffstat (limited to 'lex.l')
-rw-r--r-- | lex.l | 47 |
1 files changed, 47 insertions, 0 deletions
@@ -0,0 +1,47 @@ +%{ +#include "grammar.tab.h" +%} + +%% +"+" { return OPERATOR_PLUS; } +"-" { return OPERATOR_MINUS; } +"=" { return ASSIGN; } + +"function" { return FUNCTION; } +"if" { return IF; } +"else" { return ELSE; } +"return" { return RETURN; } +"const" { return CONST; } +"var" { return VAR; } + +"(" { return PARENTHESIS_LEFT; } +")" { return PARENTHESIS_RIGHT; } +"{" { return BRACE_LEFT; } +"}" { return BRACE_RIGHT; } +"[" { return BRACKET_LEFT; } +"]" { return BRACKET_RIGHT; } + +"," { return COMMA; } + +[0-9]+ { yylval = atoi(yytext); return NUMBER; } +[a-zA-Z]+[a-zA-Z0-9]* { return IDENTIFIER; } +"//".* { return COMMENT; } + +\n { return END_OF_LINE; } +[ \t] {} + +. { printf("undefined: %c\n", *yytext); } +%% + +void henshin_lex(int argc, char **argv) +{ + int tok; + + while (tok = yylex()) { + printf("%d", tok); + if (tok == NUMBER) { + printf(" = %d", yylval); + } + printf("\n"); + } +} |