-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtoy.l
More file actions
69 lines (51 loc) · 1.17 KB
/
toy.l
File metadata and controls
69 lines (51 loc) · 1.17 KB
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
61
62
63
64
65
66
67
68
69
%{
# include "ast.h"
# include "sym.h"
# include "toy.tab.h"
# include <string.h>
%}
%%
"bool" {return BOOL;}
"int" {return INT;}
"true" {return TRUE;}
"false" {return FALSE;}
"void" {return VOID;}
"printf" {return PRINTF;}
"string" {return STRING;}
"struct" {return STRUCT;}
"if" {return IF;}
"then" {return THEN;}
"else" {return ELSE;}
"for" {return FOR;}
"and" {return AND;}
"or" {return OR;}
"not" {return NOT;}
"mod" {return MOD;}
"return" {return RETURN;}
[_a-zA-Z][_a-zA-Z0-9]* {yylval.str = strdup(yytext); return ID;}
-?[1-9][0-9]*|0 {
yylval.val = atoi(yytext);
return NUMBER;}
["][^\\"]*["] {return STRING_LITERAL;}
"==" {return EQU;}
"<=" {return LTE;}
">=" {return GTE;}
"!=" {return NEQ;}
"{" {return OB;}
"}" {return CB;}
";" {return SEMICOLON;}
"!" {return NEGATE;}
"(" {return OP;}
")" {return CP;}
"+" {return ADD;}
"-" {return SUB;}
"." {return DOT;}
"," {return COMMA;}
"*" {return MUL;}
"/" {return DIV;}
"=" {return ASSIGN;}
"<" {return LT;}
">" {return GT;}
(\/\/|##).*(\n) {}
[ \n\t]+ { }
%%