blob: 300508da526f0ef42f4cab2a20f8566abb907153 (
plain)
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
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
|
%{
typedef struct _rented_coder rented_coder;
#include "d2c-d2c_gram.h"
#include <ctype.h>
#include <string.h>
/* Tente de libérer autant de mémoire que possible... */
void free_flex_memory(void) ;
%}
%option noyywrap
%option nounput
%option noinput
%option yylineno
%option stack
%option noyy_top_state
%x comments
%x ins_name try_details ins_details
%x encoding encoding_type encoding_content
%x encoding_bits encoding_bits_size
%x syntax syntax_name syntax_int syntax_ext
%x conv_begin conv_content
%x arg arg_binval arg_hexval
%x hooks_begin hooks_content
%x rules_begin rules_content rules_cond rules_cond_binval rules_cond_hexval rules_action rules_action_see rules_action_call
%%
[ \t\n]+ { }
"/*" { BEGIN(comments); }
<comments>"*/" { BEGIN(INITIAL); }
<comments>[^*\n] { }
<comments>"Copyright"[^\n]* { d2c_lval.string = strdup(yytext); return COPYRIGHT; }
<comments>"*" { }
<comments>"\n" { }
"@title" { BEGIN(ins_name); return TITLE; }
<ins_name>[ ][A-Za-z-]+ { d2c_lval.string = strdup(yytext + 1); BEGIN(try_details); return INS_NAME; }
<try_details>[ ,/] { BEGIN(ins_details); }
<try_details>[\n] { BEGIN(INITIAL); }
<ins_details>[^\n]* { d2c_lval.cstring = yytext; return INS_DETAILS; }
<ins_details>[\n] { BEGIN(INITIAL); }
"@encoding" { BEGIN(encoding); return ENCODING; }
<encoding>[ ] { }
<encoding>"(" { BEGIN(encoding_type); }
<encoding_type>[A-Za-z] { d2c_lval.string = strdup(yytext); return TYPE; }
<encoding_type>[0-9]+ { d2c_lval.integer = atoi(yytext); return NUMBER; }
<encoding_type>")" { BEGIN(encoding); }
<encoding>"{" { BEGIN(encoding_content); }
<encoding_content>[ \t\n]+ { }
<encoding_content>"}" { BEGIN(INITIAL); }
<encoding_content>"@half" { BEGIN(encoding_bits); return HALF; }
<encoding_content>"@word" { BEGIN(encoding_bits); return WORD; }
<encoding_bits>" " { }
<encoding_bits>"\n" { BEGIN(encoding_content); }
<encoding_bits>[A-Za-z_][A-Za-z0-9__]* { d2c_lval.string = strdup(yytext); return NAME; }
<encoding_bits>"(" { BEGIN(encoding_bits_size); }
<encoding_bits_size>[0-9]+ { d2c_lval.integer = atoi(yytext); return SIZE; }
<encoding_bits_size>")" { BEGIN(encoding_bits); }
<encoding_bits>[01] { d2c_lval.integer = atoi(yytext); return BIT; }
<encoding_content>"@syntax" { BEGIN(syntax); return SYNTAX; }
<syntax>[ ]+ { }
<syntax>"\n" { BEGIN(encoding_content); }
<syntax>[\"] { BEGIN(syntax_name); }
<syntax_name>[^ \n\"]+ { d2c_lval.string = strdup(yytext); return OPERAND_NAME; }
<syntax_name>[\"] { BEGIN(syntax); }
<syntax>"{" { BEGIN(syntax_int); }
<syntax_int>[^ \n}]+ { d2c_lval.string = strdup(yytext); return OPERAND_INTERNAL; }
<syntax_int>"}" { BEGIN(syntax); }
<syntax>"<" { BEGIN(syntax_ext); }
<syntax_ext>[^ \n>]+ { d2c_lval.string = strdup(yytext); return OPERAND_VISIBLE; }
<syntax_ext>">" { BEGIN(syntax); }
<encoding_content>"@conv" { BEGIN(conv_begin); return CONV; }
<conv_begin>[ ]+ { }
<conv_begin>"{" { BEGIN(conv_content); }
<conv_content>"}" { BEGIN(encoding_content); }
<conv_content>[ \t\n]+ { }
<conv_content>[A-Za-z_][A-Za-z0-9_]* {
if (strcmp(yytext, "NOT") == 0) return NOT;
else
{
d2c_lval.string = strdup(yytext);
return NAME;
}
}
<conv_content>"=" { return EQ; }
<conv_content>"(" { yy_push_state(arg); return OP; }
<arg>[A-Za-z_][A-Za-z0-9_]* {
if (strcmp(yytext, "NOT") == 0) return NOT;
else if (strcmp(yytext, "AND") == 0) return AND_LOG;
else if (strcmp(yytext, "EOR") == 0) return EOR;
else
{
d2c_lval.string = strdup(yytext);
return NAME;
}
}
<arg>[0-9][0-9]* { d2c_lval.integer = atoi(yytext); return NUMBER; }
<arg>"'" { BEGIN(arg_binval); }
<arg_binval>[01][01]* { d2c_lval.string = strdup(yytext); return BINVAL; }
<arg_binval>"'" { BEGIN(arg); }
<arg>"0x" { BEGIN(arg_hexval); }
<arg_hexval>[0-9a-f][0-9a-f]* { d2c_lval.string = strdup(yytext); BEGIN(arg); return HEXVAL; }
<arg>"," { return COMMA; }
<arg>":" { return COLON; }
<arg>"&" { return AND_LOG; }
<arg>[ ]+ { }
<arg>"(" { yy_push_state(arg); return OP; }
<arg>")" { yy_pop_state(); return CP; }
<encoding_content>"@hooks" { BEGIN(hooks_begin); return HOOKS; }
<hooks_begin>[ ]+ { }
<hooks_begin>"{" { BEGIN(hooks_content); }
<hooks_content>"}" { BEGIN(encoding_content); }
<hooks_content>[ \t\n]+ { }
<hooks_content>[a-z_][a-z0-9_]* { d2c_lval.string = strdup(yytext); return NAME; }
<hooks_content>"=" { return EQ; }
<encoding_content>"@rules" { BEGIN(rules_begin); return RULES; }
<rules_content>\/\/[^\n]+ { printf("SKIP '%s'\n", yytext); }
<rules_begin>[ ]+ { }
<rules_begin>"{" { BEGIN(rules_content); }
<rules_content>[ \t\n]+ { }
<rules_content>"}" { BEGIN(encoding_content); }
<rules_content>"see " { BEGIN(rules_action_see); return SEE; }
<rules_content>"unpredictable" { return UNPREDICTABLE; }
<rules_content>"call" { BEGIN(rules_action_call); return CALL; }
<rules_content>"chk_call" { BEGIN(rules_action_call); return CHK_CALL; }
<rules_content>"if" { BEGIN(rules_cond); return IF; }
<rules_cond>[ ]+ { }
<rules_cond>"(" { return EXPR_START; }
<rules_cond>[A-Za-z_][A-Za-z0-9_]* { d2c_lval.string = strdup(yytext); return NAME; }
<rules_cond>"==" { return EQUAL; }
<rules_cond>"'" { BEGIN(rules_cond_binval); }
<rules_cond_binval>[01][01]* { d2c_lval.string = strdup(yytext); return BINVAL; }
<rules_cond_binval>"'" { BEGIN(rules_cond); }
<rules_cond>"0x" { BEGIN(rules_cond_hexval); }
<rules_cond_hexval>[0-9a-f][0-9a-f]* { d2c_lval.string = strdup(yytext); BEGIN(rules_cond); return HEXVAL; }
<rules_cond>")" { return EXPR_END; }
<rules_cond>"&&" { return AND; }
<rules_cond>"&" { return AND_LOG; }
<rules_cond>";" { BEGIN(rules_action); return THEN; }
<rules_action>[ ]+ { }
<rules_action>"see " { BEGIN(rules_action_see); return SEE; }
<rules_action_see>[^\n]* { d2c_lval.cstring = yytext; BEGIN(rules_content); return INS_DETAILS; }
<rules_action>"unpredictable" { BEGIN(rules_content); return UNPREDICTABLE; }
<rules_action>"call" { BEGIN(rules_action_call); return CALL; }
<rules_action>"chk_call" { BEGIN(rules_action_call); return CHK_CALL; }
<rules_action_call>[\t ]+ { }
<rules_action_call>[A-Za-z_][A-Za-z0-9_]* { d2c_lval.string = strdup(yytext); return NAME; }
<rules_action_call>"(" { yy_push_state(arg); return OP; }
<rules_action_call>[\n] { BEGIN(rules_content); }
%%
/******************************************************************************
* *
* Paramètres : - *
* *
* Description : Tente de libérer autant de mémoire que possible... *
* *
* Retour : - *
* *
* Remarques : - *
* *
******************************************************************************/
void free_flex_memory(void)
{
yy_delete_buffer(YY_CURRENT_BUFFER);
}
|