-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathLexer.l
60 lines (43 loc) · 1.23 KB
/
Lexer.l
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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
%{
#include <stdio.h>
#include <math.h>
#include <string.h>
// bridge headers
#include <parser.h>
%}
whitespace [ \r\n\t]
digit [0-9]
alpha [A-Za-z_]
id {alpha}*
%%
{digit}+ {
yylval->ival = atoi(yytext);
return TOKEN_INTEGER;
}
{digit}+"."{digit}* {
yylval->fval = atof(yytext);
return TOKEN_DECIMAL;
}
{id} {
strcpy(yylval->sval, yytext);
return TOKEN_ID;
}
"+" { return TOKEN_PLUS; }
"*" { return TOKEN_STAR; }
"-" { return TOKEN_HYPH; }
"/" { return TOKEN_FSLASH; }
"^" { return TOKEN_CARET; }
"(" { return TOKEN_LPAREN; }
")" { return TOKEN_RPAREN; }
"{" { return TOKEN_LBRACE; }
"}" { return TOKEN_RBRACE; }
"," { return TOKEN_COMMA; }
"=" { return TOKEN_EQUALS; }
"//"[^\n]* {
// printf("comment\n");
continue;
}
{whitespace}* { continue; }
. {
// printf("unrecognized character: %s\n", yytext);
}