forked from anand-b/Compiler
-
Notifications
You must be signed in to change notification settings - Fork 0
/
c.l
70 lines (70 loc) · 1.9 KB
/
c.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
/*
@author "Anand.B & Ganesh Prabu.R"
@Date Modified "06/04/2014"
*/
%{
#include<stdio.h>
#include<string.h>
#include "y.tab.h"
extern YYSTYPE yylval;
int line=1;
%}
%%
[#][^#^\r^\n.]*[#] {;}
[#][^\r\n.]* {;}
[ \t\r\f] {;}
[\n] {line++;}
"till" {return TILL;}
"with" {return WITH;}
"do" {return DO;}
"loop" {return LOOP;}
"out" {return OUT;}
"in" {return IN;}
"then" {return THEN;}
"if" {return IF;}
"else" {return ELSE;}
"finish" {return END;}
"int" {return INT;}
"break" {return BREAK;}
"continue" {return CONTINUE;}
"fi" {return FI;}
"go" {return MAIN;}
"return" {return RETURN;}
"++" {return INC;}
"--" {return DEC;}
"!" {return NOT;}
"~" {return BITCOMPLEMENT;}
"+" {return PLUS;}
"-" {return BMINUS;}
"*" {return MULTIPLY;}
"/" {return DIVIDE;}
"%" {return MOD;}
"=" {return EQ;}
"," {return COMMA;}
">>" {return SRIGHT;}
"<<" {return SLEFT;}
"<=" {return LE;}
">=" {return GE;}
"<" {return L;}
">" {return G;}
"!=" {return NE;}
"==" {return EE;}
"$" {return PERIOD;}
"(" {return OP;}
")" {return CP;}
"&&" {return AND;}
"||" {return OR;}
"&" {return BAND;}
"|" {return BOR;}
"^" {return BXOR;}
0|[1-9][0-9]* {yylval.number=atoi(yytext);
return NUMBER;
}
[a-z][a-z0-9]* {yylval.var_name=strdup(yytext);return VAR;}
[A-Z]+ {return FUNC_NAME;}
[\"][^\".]*[\"] {
yytext[strlen(yytext)-1]='\r';
yylval.var_name=strdup(yytext+1);
return STRING;
}
%%