This repository has been archived by the owner on Jan 1, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathflexon.l
66 lines (58 loc) · 1.87 KB
/
flexon.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
%{
#include "flexon.h"
#include "flexon.tab.h"
%}
Letter [a-zA-Z]
Digit [0-9]
%option noyywrap yylineno
%%
/* single character operators */
"+" |
"-" |
"*" |
"/" |
"!" |
";" |
"." |
"," |
"=" |
"(" |
")" |
"[" |
"]" |
":" { yylval.sval = strdup(yytext); return yytext[0]; }
/* comparison operators */
"<" |
"<=" |
">=" |
">" |
"==" |
"!=" { yylval.sval = strdup(yytext); return Comparator; }
/* keywords */
"mainprog" { yylval.sval = strdup(yytext); return Mainprog; }
"function" { yylval.sval = strdup(yytext); return Function; }
"procedure" { yylval.sval = strdup(yytext); return Procedure; }
"begin" { yylval.sval = strdup(yytext); return Begin; }
"end" { yylval.sval = strdup(yytext); return End; }
"if" { yylval.sval = strdup(yytext); return If; }
"then" { yylval.sval = strdup(yytext); return Then; }
"else" { yylval.sval = strdup(yytext); return Else; }
"nop" { yylval.sval = strdup(yytext); return Nop; }
"while" { yylval.sval = strdup(yytext); return While; }
"return" { yylval.sval = strdup(yytext); return Return; }
"print" { yylval.sval = strdup(yytext); return Print; }
"in" { yylval.sval = strdup(yytext); return In; }
"for" { yylval.sval = strdup(yytext); return For; }
"elif" { yylval.sval = strdup(yytext); return Elif; }
/* type */
"int" { yylval.sval = strdup(yytext); return IntType; }
"float" { yylval.sval = strdup(yytext); return FloatType; }
{Letter}({Letter}|{Digit})* { yylval.sval = strdup(yytext); return ID; }
{Digit}+ { yylval.ival = atoi(yytext); return Integer; }
{Digit}+\.{Digit}* { yylval.fval = atof(yytext); return Float; }
/* things to ignore */
"//".* ; // comments
[ \t\r\n] ; // all whitespace
\\\n ; // line continuation
. { fprintf(stderr, "Line %d: Unknown character %c\n", yylineno, yytext[0]); exit(1); }
%%