blob: d5d2c69a46c7f2aa7d101bb39b6835838dff76a5 (
plain)
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
39
40
41
42
|
%{
#include <stdlib.h>
#include "lisp.h"
#include "lisp.tab.h"
int tcnt = 0;
%}
%%
[[:space:]]+ { /* ignore whitespace */ }
";"[^\n]* { /* ignore comment */ }
"(" { return LPAREN; }
")" { return RPAREN; }
"\." { return DOT; }
"'" { return QUOTE; }
[+-]?([0-9]+|([0-9]*\.[0-9]+))([eE][-+]?[0-9]+)? {
yylval.dval = atof(yytext);
return NUMBER;
}
\"(\\.|[^"\\])*\" {
// remove starting and ending quotes
int len = yyleng - 2;
char *str = (char*)malloc(len + 1);
if (!str) { fprintf(stderr, "out of memory!\n"); exit(1); }
strncpy(str, yytext + 1, len);
str[len] = '\0';
yylval.strval = str;
return STRING;
}
[^[:space:]\"()'.]+ {
yylval.strval = strdup(yytext);
return SYMBOL;
}
. ; // do nothing
%%
|