diff options
| author | Tom Harley | 2019-12-23 01:32:39 +0000 |
|---|---|---|
| committer | Tom Harley | 2019-12-23 01:32:39 +0000 |
| commit | 7bc67b95161a34f8eca635d4000d9602508a9243 (patch) | |
| tree | 585b3778dc1967832390e5829e4b3909b4184a2c /lex.l | |
| parent | Add basics for interpreter; add CLI options (diff) | |
| download | sinter-7bc67b95161a34f8eca635d4000d9602508a9243.tar.gz sinter-7bc67b95161a34f8eca635d4000d9602508a9243.zip | |
checkpoint
Diffstat (limited to 'lex.l')
| -rw-r--r-- | lex.l | 27 |
1 files changed, 23 insertions, 4 deletions
@@ -1,18 +1,35 @@ +%option noinput nounput %option noyywrap %option nodefault -%option yylineno -%option noinput nounput +/* %option reentrant bison-bridge bison-locations */ %{ #include <string.h> -#include "basic.h" +#include "sexpr.h" +#include "sinter.h" #include "parse.h" void yyerror(const char *s, ...); char *str_value(char *s); +void update_yylloc() { + yylloc.first_line = yylloc.last_line; + yylloc.first_column = yylloc.last_column; + + for (int i = 0; yytext[i]; i++) { + if (yytext[i] == '\n') { + yylloc.last_line++; + yylloc.last_column = 0; + } else { + yylloc.last_column++; + } + } +} + +#define YY_USER_ACTION update_yylloc(); + char *str_value(char *s) { s++; /* FIXME: strdup allocates memory! */ @@ -24,7 +41,9 @@ char *str_value(char *s) { %} -ID [-A-Za-z_+*!/.=<>][-A-Za-z0-9_+*!.=<>]* +%option yylineno + +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]+ |
