diff options
| author | Tom Harley | 2019-09-30 01:56:15 +0100 |
|---|---|---|
| committer | Tom Harley | 2019-09-30 01:56:15 +0100 |
| commit | fbe39f58fc0d757f8ffe54c6dc96bbc690862ded (patch) | |
| tree | 94d861774ded89f82363bcc2877ec2cc3f94c024 /lex.l | |
| download | sinter-fbe39f58fc0d757f8ffe54c6dc96bbc690862ded.tar.gz sinter-fbe39f58fc0d757f8ffe54c6dc96bbc690862ded.zip | |
Initial commit
Diffstat (limited to 'lex.l')
| -rw-r--r-- | lex.l | 38 |
1 files changed, 38 insertions, 0 deletions
@@ -0,0 +1,38 @@ +%option noyywrap +%option nodefault +%option yylineno +%option noinput nounput + +%{ + +#include <string.h> + +#include "basic.h" +#include "parse.h" + +void yyerror(const char *s, ...); + +%} + +ID [-A-Za-z_+*!/][-A-Za-z0-9_+*!]* +FLOAT [+-]?([0-9]+[.][0-9]*([Ee][+-]?[0-9]+)?|[.][0-9]+([Ee][+-]?[0-9]+)?) +INT [+-]?[0-9]+ + +%% + +"(" | +")" | +";" { return yytext[0]; } + +"()" { return NIL; } + +{ID} { /* TODO: strdup allocates memory! */ + yylval.s = strdup(yytext); return ID; } + +{INT} { yylval.i = atoi(yytext); return INT; } + +{FLOAT} { yylval.f = atof(yytext); return FLOAT; } + +[ \t\n] /* ignore whitespace */ + +. { yyerror("Unexpected character %c\n", yytext[0]); } |
