summaryrefslogtreecommitdiff
path: root/lex.l
diff options
context:
space:
mode:
authorTom Harley2019-10-03 02:42:28 +0100
committerTom Harley2019-10-03 02:42:28 +0100
commit64d093247985f759669b7726542291382c1e3fc5 (patch)
tree4b8324373c4b267cd1affcab8a8ece20b920323b /lex.l
parentInitial commit (diff)
downloadsinter-64d093247985f759669b7726542291382c1e3fc5.tar.gz
sinter-64d093247985f759669b7726542291382c1e3fc5.zip

Support + and * operations

Diffstat (limited to 'lex.l')
-rw-r--r--lex.l20
1 files changed, 17 insertions, 3 deletions
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; }