-
Notifications
You must be signed in to change notification settings - Fork 2
/
ci.l
168 lines (151 loc) · 4.03 KB
/
ci.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
%option bison-bridge
%option bison-locations
%option yylineno
%option stack
%{
#include <stdio.h>
#include "yystype.h"
#include "evaltree.h"
#include "y.tab.h"
void count(void);
#define YY_USER_ACTION yylloc->first_line = yylineno; if(fname) {yylloc->filename = fname;}
char * fname = 0;
%}
D [0-9]
L [a-zA-Z_]
H [a-fA-F0-9]
E [Ee][+-]?{D}+
P [Pp][+-]?{D}+
FS (f|F|l|L)
IS ((u|U)|(u|U)?(l|L|ll|LL)|(l|L|ll|LL)(u|U))
%x COMMENT
%%
"/*" { yy_push_state( COMMENT); }
<COMMENT>"*/" { yy_pop_state( ); }
<COMMENT>. {}
"//"[^\n]* { /* consume //-comment */ }
"auto" { return(AUTO); }
"_Bool" { return(BOOL); }
"bool" { return(BOOL); }
"break" { return(BREAK); }
"case" { return(CASE); }
"char" { return(CHAR); }
"_Complex" { return(COMPLEX); }
"const" { return(CONST); }
"continue" { return(CONTINUE); }
"default" { return(DEFAULT); }
"do" { return(DO); }
"double" { return(DOUBLE); }
"else" { return(ELSE); }
"enum" { return(ENUM); }
"extern" { return(EXTERN); }
"float" { return(FLOAT); }
"for" { return(FOR); }
"while" { return(WHILE); }
"goto" { return(GOTO); }
"if" { return(IF); }
"_Imaginary" { return(IMAGINARY); }
"inline" { return(INLINE); }
"int" { return(INT); }
"long" { return(LONG); }
"register" { return(REGISTER); }
"restrict" { return(RESTRICT); }
"return" { return(RETURN); }
"short" { return(SHORT); }
"signed" { return(SIGNED); }
"sizeof" { return(SIZEOF); }
"static" { return(STATIC); }
"struct" { return(STRUCT); }
"switch" { return(SWITCH); }
"typedef" { return(TYPEDEF); }
"union" { return(UNION); }
"unsigned" { return(UNSIGNED); }
"void" { return(VOID); }
"volatile" { return(VOLATILE); }
"#".+\n {
char * fn = strchr(yytext+2, ' ');
*fn = 0;
strchr(fn+2, '"')[1] = 0;
fname = strdup(fn+1);
yylineno = atoi(yytext+2);
}
{L}({L}|{D})* { yylval->txt_v = new std::string(yytext); return(check_type());}
0[xX]{H}+{IS}? { return(CONSTANT); }
0{D}+{IS}? { return(CONSTANT); }
{D}+{IS}? { yylval->long_v = atol(yytext); return(CONSTANT); }
L?'(\\.|[^\\'\n])+' { return(CONSTANT); }
{D}+{E}{FS}? { return(CONSTANT); }
{D}*"."{D}+({E})?{FS}? { return(CONSTANT); }
{D}+"."{D}*({E})?{FS}? { return(CONSTANT); }
0[xX]{H}+{P}{FS}? { return(CONSTANT); }
0[xX]{H}*"."{H}+({P})?{FS}? { return(CONSTANT); }
0[xX]{H}+"."{H}*({P})?{FS}? { return(CONSTANT); }
L?\"(\\.|[^\\"\n])*\" { yytext[strlen(yytext)-1] = 0; yylval->txt_v = new std::string(yytext+1); return(STRING_LITERAL); }
"..." { return(ELLIPSIS); }
">>=" { return(RIGHT_ASSIGN); }
"<<=" { return(LEFT_ASSIGN); }
"+=" { return(ADD_ASSIGN); }
"-=" { return(SUB_ASSIGN); }
"*=" { return(MUL_ASSIGN); }
"/=" { return(DIV_ASSIGN); }
"%=" { return(MOD_ASSIGN); }
"&=" { return(AND_ASSIGN); }
"^=" { return(XOR_ASSIGN); }
"|=" { return(OR_ASSIGN); }
">>" { return(RIGHT_OP); }
"<<" { return(LEFT_OP); }
"++" { return(INC_OP); }
"--" { return(DEC_OP); }
"->" { return(PTR_OP); }
"&&" { return(AND_OP); }
"||" { return(OR_OP); }
"<=" { return(LE_OP); }
">=" { return(GE_OP); }
"==" { return(EQ_OP); }
"!=" { return(NE_OP); }
";" { return(';'); }
("{"|"<%") { return('{'); }
("}"|"%>") { return('}'); }
"," { return(','); }
":" { return(':'); }
"=" { return('='); }
"(" { return('('); }
")" { return(')'); }
("["|"<:") { return('['); }
("]"|":>") { return(']'); }
"." { return('.'); }
"&" { return('&'); }
"!" { return('!'); }
"~" { return('~'); }
"-" { return('-'); }
"+" { return('+'); }
"*" { return('*'); }
"/" { return('/'); }
"%" { return('%'); }
"<" { return('<'); }
">" { return('>'); }
"^" { return('^'); }
"|" { return('|'); }
"?" { return('?'); }
[ \t\v\n\f] { }
. { /* Add code to complain about unmatched characters */ }
%%
int yywrap(void)
{
return 1;
}
int check_type(void)
{
/*
* pseudo code --- this is what it should check
*
* if (yytext == type_name)
* return TYPE_NAME;
*
* return IDENTIFIER;
*/
/*
* it actually will only return IDENTIFIER
*/
return IDENTIFIER;
}