diff options
| author | Tom Harley | 2019-10-03 02:42:28 +0100 |
|---|---|---|
| committer | Tom Harley | 2019-10-03 02:42:28 +0100 |
| commit | 64d093247985f759669b7726542291382c1e3fc5 (patch) | |
| tree | 4b8324373c4b267cd1affcab8a8ece20b920323b /lex.l | |
| parent | Initial commit (diff) | |
| download | sinter-64d093247985f759669b7726542291382c1e3fc5.tar.gz sinter-64d093247985f759669b7726542291382c1e3fc5.zip | |
Support + and * operations
Diffstat (limited to 'lex.l')
| -rw-r--r-- | lex.l | 20 |
1 files changed, 17 insertions, 3 deletions
@@ -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; } |
