summaryrefslogtreecommitdiff
path: root/lex.l
blob: e7591d4946a9083208799c186690d8772035ab36 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
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]); }