From b662201aefec7104e7d289981828a66a8226f7bb Mon Sep 17 00:00:00 2001 From: Daniel Weipert Date: Sun, 20 Nov 2022 15:20:26 +0100 Subject: Initial commit --- lex.l | 47 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) create mode 100644 lex.l (limited to 'lex.l') diff --git a/lex.l b/lex.l new file mode 100644 index 0000000..2f79474 --- /dev/null +++ b/lex.l @@ -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"); + } +} -- cgit v1.2.3