From 64d093247985f759669b7726542291382c1e3fc5 Mon Sep 17 00:00:00 2001 From: Tom Harley Date: Thu, 3 Oct 2019 02:42:28 +0100 Subject: Support + and * operations --- lex.l | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) (limited to 'lex.l') diff --git a/lex.l b/lex.l index e7591d4..5bfc7a4 100644 --- a/lex.l +++ b/lex.l @@ -12,20 +12,34 @@ void yyerror(const char *s, ...); +char *str_value(char *s) { + s++; + /* TODO: strdup allocates memory! */ + char *ret = strdup(s); + ret[strlen(s) - 2] = 0; + + return ret; +} + %} -ID [-A-Za-z_+*!/][-A-Za-z0-9_+*!]* -FLOAT [+-]?([0-9]+[.][0-9]*([Ee][+-]?[0-9]+)?|[.][0-9]+([Ee][+-]?[0-9]+)?) -INT [+-]?[0-9]+ +ID [-A-Za-z_+*!/][-A-Za-z0-9_+*!]* +STRING ["][^"]*["] +FLOAT [+-]?([0-9]+[.][0-9]*([Ee][+-]?[0-9]+)?|[.][0-9]+([Ee][+-]?[0-9]+)?) +INT [+-]?[0-9]+ %% "(" | ")" | +"[" | +"]" | ";" { return yytext[0]; } "()" { return NIL; } +{STRING} { yylval.s = str_value(yytext); return STRING; } + {ID} { /* TODO: strdup allocates memory! */ yylval.s = strdup(yytext); return ID; } -- cgit v1.2.1