-
Notifications
You must be signed in to change notification settings - Fork 0
/
lexico.l
71 lines (58 loc) · 2.57 KB
/
lexico.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
69
70
71
/*MIT License
Copyright (c) 2017 Marino Hohenheim
Copyright (c) 2017 Jefferson Renè
*/
DIGIT [0-9]
ID [a-zA-Z][a-zA-Z0-9_]*
DOIDO [0-9]+[a-zA-Z0-9_]*
COMMENT [//].*
WHITESPACE [ \t]
%%
let {fprintf(yyout, "KEY \"%s\" %d\n",yytext, yylineno);}
def {fprintf(yyout, "KEY \"%s\" %d\n",yytext, yylineno);}
if {fprintf(yyout, "KEY \"%s\" %d\n",yytext, yylineno);}
else {fprintf(yyout, "KEY \"%s\" %d\n",yytext, yylineno);}
while {fprintf(yyout, "KEY \"%s\" %d\n",yytext, yylineno);}
return {fprintf(yyout, "KEY \"%s\" %d\n",yytext, yylineno);}
break {fprintf(yyout, "KEY \"%s\" %d\n",yytext, yylineno);}
continue {fprintf(yyout, "KEY \"%s\" %d\n",yytext, yylineno);}
"(" {fprintf(yyout, "SYM \"%s\" %d\n",yytext, yylineno);}
"{" {fprintf(yyout, "SYM \"%s\" %d\n",yytext, yylineno);}
"}" {fprintf(yyout, "SYM \"%s\" %d\n",yytext, yylineno);}
")" {fprintf(yyout, "SYM \"%s\" %d\n",yytext, yylineno);}
"," {fprintf(yyout, "SYM \"%s\" %d\n",yytext, yylineno);}
";" {fprintf(yyout, "SYM \"%s\" %d\n",yytext, yylineno);}
"=" {fprintf(yyout, "SYM \"%s\" %d\n",yytext, yylineno);}
"+" {fprintf(yyout, "SYM \"%s\" %d\n",yytext, yylineno);}
"-" {fprintf(yyout, "SYM \"%s\" %d\n",yytext, yylineno);}
"*" {fprintf(yyout, "SYM \"%s\" %d\n",yytext, yylineno);}
"/" {fprintf(yyout, "SYM \"%s\" %d\n",yytext, yylineno);}
"<" {fprintf(yyout, "SYM \"%s\" %d\n",yytext, yylineno);}
">" {fprintf(yyout, "SYM \"%s\" %d\n",yytext, yylineno);}
"<=" {fprintf(yyout, "SYM \"%s\" %d\n",yytext, yylineno);}
">=" {fprintf(yyout, "SYM \"%s\" %d\n",yytext, yylineno);}
"==" {fprintf(yyout, "SYM \"%s\" %d\n",yytext, yylineno);}
"!=" {fprintf(yyout, "SYM \"%s\" %d\n",yytext, yylineno);}
"&&" {fprintf(yyout, "SYM \"%s\" %d\n",yytext, yylineno);}
"||" {fprintf(yyout, "SYM \"%s\" %d\n",yytext, yylineno);}
"!" {fprintf(yyout, "SYM \"%s\" %d\n",yytext, yylineno);}
{DIGIT}+ {fprintf(yyout, "DEC \"%s\" %d\n",yytext, yylineno);}
{ID} {fprintf(yyout, "ID \"%s\" %d\n",yytext, yylineno);}
{WHITESPACE}+ /*Terminate it*/
{COMMENT}+ /*Terminate it*/
"\n" yylineno++;
{DOIDO} {fprintf(yyout, "ERROR \"%s\" %d\n",yytext, yylineno);}
. {fprintf(yyout, "ERROR \"%s\" %d\n",yytext, yylineno);}
%%
int yywrap();
int main(int argc, char *argv[]){
yyin = fopen(argv[1], "r");
yyout = fopen(argv[2], "w");
yylex();
fclose(yyin);
fclose(yyout);
return 0;
}
int yywrap(){
return 1;
}