From fbe39f58fc0d757f8ffe54c6dc96bbc690862ded Mon Sep 17 00:00:00 2001 From: Tom Harley Date: Mon, 30 Sep 2019 01:56:15 +0100 Subject: Initial commit --- lex.l | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) create mode 100644 lex.l (limited to 'lex.l') diff --git a/lex.l b/lex.l new file mode 100644 index 0000000..e7591d4 --- /dev/null +++ b/lex.l @@ -0,0 +1,38 @@ +%option noyywrap +%option nodefault +%option yylineno +%option noinput nounput + +%{ + +#include + +#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]); } -- cgit v1.2.1