-
Notifications
You must be signed in to change notification settings - Fork 1
/
1505057.l
183 lines (166 loc) · 2.96 KB
/
1505057.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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
%option noyywrap yylineno
%{
#include<cstdio>
#include<cstdlib>
#include<string>
#include <algorithm>
#include <bitset>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
#include <ctime>
#include <sstream>
using namespace std;
#define FOR(i, a, b) for (int i = a; i <= b; i++)
#define REP(i, n) for (int i = 0; i < n; i++)
#define ll long long
#define ull unsigned long long
#define inf 1e9
#define sf(a) scanf("%d",&a);
#define sf2(a, b) scanf("%d %d",&a,&b);
#define sf3(a, b, c) scanf("%d %d %d",&a,&b,&c);
#define pf printf
#define mset(a, b) memset(a,b,sizeof(a))
#define itf it->first
#define its it->second
#include "SymbolTable.h"
#include "y.tab.h"
void yyerror(char *);
extern SymbolTable *table;
%}
WHITESPACE [ \t\f\r\v]+
LETTER [a-zA-Z]
DIGIT [0-9]
INTEGER {DIGIT}+
FLOAT ({DIGIT}+[Ee][+-]?{DIGIT}+)|((({DIGIT}+\.{DIGIT}*)|({DIGIT}*\.{DIGIT}+))([eE][+-]?{DIGIT}+)?)
CHAR \'([^'\\\n]|\\[nt\\\'\"afrbv0])\'
INCOP \+\+
DECOP \-\-
RELOP \<\=|\>\=|\>|\<|\=\=|\!\=
BITOP \&|\||\^|\<\<|\>\>
ADDOP \+|\-
MULOP \*|\/|\%
IDENTIFIER [A-Za-z_][_A-Za-z0-9]*
STRING \"(\\[nt\\\'\"afrbv0]|[^\n\"\\]|\\\n)*\"
UNTSTRING \"(\\[nt\\\'\"afrbv0]|[^\n\"\\]|\\\n)*
COMMENT1 \/\/(\\\n|[^\n])*
COMMENT2 \/\*([^\*]|\*+[^\/\*])*\*+\/
UNFCOMMENT \/\*([^\*]|\*+[^\/\*])*
IFN ({INTEGER}[Ee]{FLOAT})|({FLOAT}[Ee]{FLOAT})
ISP [0-9]+[_0-9A-Za-z]+
MULTICHAR \'([^'\n])([^'\n])+\'
UNFCHAR (\'\\\')|(\'[^'\n]*)
UNRECCHAR \'\\[^nt\\\'\"afrbv0]\'
NEWLINE \n
%%
"int" {
return INT;
}
"float" {
return FLOAT;
}
"void" {
return VOID;
}
"for" {
return FOR;
}
"if" {
return IF;
}
"else" {
return ELSE;
}
"while" {
return WHILE;
}
"println" {
return PRINTLN;
}
"return" {
return RETURN;
}
{INTEGER} {
SymbolInfo *temp= new SymbolInfo(yytext,"CONST_INT");
yylval.s = temp;
return CONST_INT;
}
{FLOAT} {
SymbolInfo *temp= new SymbolInfo(yytext,"CONST_FLOAT");
yylval.s = temp;
return CONST_FLOAT;
}
{IDENTIFIER} {
SymbolInfo *temp= new SymbolInfo(yytext,"ID");
yylval.s = temp;
return ID;
}
{INCOP} {
return INCOP;
}
{DECOP} {
return DECOP;
}
{ADDOP} {
SymbolInfo *temp= new SymbolInfo(yytext,"ADDOP");
yylval.s = temp;
return ADDOP;
}
{MULOP} {
SymbolInfo *temp= new SymbolInfo(yytext,"MULOP");
yylval.s = temp;
return MULOP;
}
{RELOP} {
SymbolInfo *temp= new SymbolInfo(yytext,"RELOP");
yylval.s = temp;
return RELOP;
}
\&\&|\|\| {
SymbolInfo *temp= new SymbolInfo(yytext,"LOGICOP");
yylval.s = temp;
return LOGICOP;
}
\! {
return NOT;
}
\( {
return LPAREN;
}
\) {
return RPAREN;
}
\{ {
return LCURL;
}
\} {
return RCURL;
}
\[ {
return LTHIRD;
}
\] {
return RTHIRD;
}
\= {
return ASSIGNOP;
}
\, {
return COMMA;
}
\; {
return SEMICOLON;
}
{COMMENT1} {
}
[\n] {
}
%%