-
Notifications
You must be signed in to change notification settings - Fork 0
/
tok.l
68 lines (44 loc) · 1.34 KB
/
tok.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
61
62
63
64
65
66
67
68
%{
#include <stdio.h>
#include "enums.h"
#include "golang.tab.h"
%}
floatnum [0-9]+\.[0-9]*|[0-9]*\.[0-9]+
integer [0-9]+
id [a-zA-Z_][a-zA-Z0-9_]*
%%
[ \t] {}
{floatnum} {sscanf(yytext,"%s",yylval.val);return FLT;}
{integer} {sscanf(yytext,"%s",yylval.val);return NUM;}
"package" {return(PACKAGE);}
"import" {return(IMPORT);}
"func" {return(FUNC);}
"{" {Level++; return (LCPAREN);}
"}" {Level--; return (RCPAREN);}
"if" {Level++; return (IF);}
"else" {Level++; return (ELSE);}
"print" {return (PRINT);}
"while" {LoopAdd(); Level++; return (WHILE);}
"(" {return (LRPAREN);}
")" {return (RRPAREN);}
"[" {return (LSPAREN);}
"]" {return (RSPAREN);}
";" {return (SEMICOLON); }
"\"" {return (DOUBLEQUOTE); }
"==" {yylval.Relop = Equal; return (RELOP);}
"!=" {yylval.Relop = NEqual; return (RELOP);}
"<=" {yylval.Relop = Leq; return (RELOP);}
"<" {yylval.Relop = Le; return (RELOP);}
">=" {yylval.Relop = Geq; return (RELOP);}
">" {yylval.Relop = Ge; return (RELOP);}
"++" {return (INCREMENT); }
"--" {return (DECREMENT); }
":=" {return (ASSIGN);}
"=" {return (EQUAL);}
"+" {return (ADD); }
"-" {return (SUB); }
"*" {return (MUL); }
"/" {return (DIV); }
{id} {sscanf(yytext,"%s",yylval.val);return VAR;}
\n+|. {return yytext[0];}
%%