|
1 %option yylineno |
|
2 %{ |
|
3 // Copyright (c) 1997-2009 Nokia Corporation and/or its subsidiary(-ies). |
|
4 // All rights reserved. |
|
5 // This component and the accompanying materials are made available |
|
6 // under the terms of the License "Eclipse Public License v1.0" |
|
7 // which accompanies this distribution, and is available |
|
8 // at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
9 // |
|
10 // Initial Contributors: |
|
11 // Nokia Corporation - initial contribution. |
|
12 // |
|
13 // Contributors: |
|
14 // |
|
15 // Description: |
|
16 // RCOMPL.INL |
|
17 // Generated from RCOMP.L |
|
18 |
|
19 |
|
20 #include <limits.h> |
|
21 #include <string.h> |
|
22 #include "main.h" |
|
23 #include "structst.h" |
|
24 #include "parser.h" |
|
25 #include "localise.h" |
|
26 |
|
27 #define YY_SKIP_YYWRAP 1 |
|
28 #define YY_NEVER_INTERACTIVE 1 |
|
29 int yywrap(); |
|
30 void yyerror(const char* string, ...); |
|
31 |
|
32 // Redefine YY_INPUT so we can parse binary data. |
|
33 #undef YY_INPUT |
|
34 #define YY_INPUT(buf, result, max_size) (result = new_yy_input(buf, max_size)) |
|
35 |
|
36 int new_yy_input(char *buf, int max_size) |
|
37 { |
|
38 int result; |
|
39 result = fread(buf, 1, max_size, yyin); |
|
40 if (result == 0) |
|
41 return YY_NULL; |
|
42 |
|
43 // check for utf8 (BOM) header in buf |
|
44 for (int i = 0; i < result-3; i++) |
|
45 { |
|
46 if (buf[i] == 0xffffffef && buf[i+1] == 0xffffffbb && buf[i+2] == 0xffffffbf) |
|
47 { |
|
48 buf[i] = ' '; |
|
49 buf[i+1] = ' '; |
|
50 buf[i+2] = ' '; |
|
51 } |
|
52 } |
|
53 return result; |
|
54 } |
|
55 |
|
56 #include "rcomp.hpp" |
|
57 #include "fileline.h" |
|
58 |
|
59 #define VALUE_LEN (1024*8) // must match sizeof(YYSTYPE.Value) |
|
60 char buf[VALUE_LEN]; |
|
61 char * pCh; |
|
62 #define CHECK_APPEND(x) \ |
|
63 if (pCh-buf==VALUE_LEN-1) { yyerror("string too long - %c ignored", (x)); } else {*pCh++ = (x); } |
|
64 |
|
65 int isCharLiteral; |
|
66 |
|
67 extern String InputBaseName; |
|
68 extern FileLineManager* pFileLineHandler; |
|
69 extern int* pCurrentLineNumber; |
|
70 char RealLineNumber[200]; |
|
71 // |
|
72 // Disable MSVC warnings |
|
73 // |
|
74 #ifdef __VC32__ |
|
75 #if 0 |
|
76 ..\src\RCOMP.L(95) : warning C4127: conditional expression is constant |
|
77 ..\src\RCOMP.L(114) : warning C4244: 'initializing' : conversion from 'const int' to 'YY_CHAR', possible loss of data |
|
78 ..\src\RCOMP.L(119) : warning C4244: '=' : conversion from 'const int' to 'YY_CHAR', possible loss of data |
|
79 ..\src\RCOMP.L(130) : warning C4102: 'find_rule' : unreferenced label |
|
80 ..\src\RCOMP.L(513) : warning C4244: 'initializing' : conversion from 'int' to 'YY_CHAR', possible loss of data |
|
81 ..\src\RCOMP.L(518) : warning C4244: '=' : conversion from 'const int' to 'YY_CHAR', possible loss of data |
|
82 ..\src\RCOMP.L(548) : warning C4244: '=' : conversion from 'const int' to 'YY_CHAR', possible loss of data |
|
83 ..\src\RCOMP.L(63) : warning C4505: 'yyunput' : unreferenced local function has been removed |
|
84 \epoc32\BUILD\generatedcpp\rcomp\rcompl.cpp(243) : warning C4505: 'yy_flex_realloc' : unreferenced local function has been removed |
|
85 #endif |
|
86 |
|
87 #pragma warning( disable : 4100 ) |
|
88 #pragma warning( disable : 4102 ) |
|
89 #pragma warning( disable : 4127 ) |
|
90 #pragma warning( disable : 4244 ) |
|
91 #pragma warning( disable : 4245 ) |
|
92 #pragma warning( disable : 4505 ) |
|
93 #endif //__VC32__ |
|
94 |
|
95 #include "errorhan.h" |
|
96 |
|
97 #define REGISTER_LINE ErrorHandler::Register(pFileLineHandler->GetCurrentFile(), pFileLineHandler->GetErrorLine(* pCurrentLineNumber)) |
|
98 |
|
99 |
|
100 %} |
|
101 |
|
102 Digit [0-9] |
|
103 Lower [a-z] |
|
104 Upper [A-Z] |
|
105 Letter {Lower}|{Upper} |
|
106 Alphanumeric {Letter}|{Digit} |
|
107 LetterOrUnderscore {Letter}|_ |
|
108 AlphanumUscore {Alphanumeric}|_ |
|
109 HexChar [A-Fa-f0-9] |
|
110 ExpChar [eE] |
|
111 FileNameChar [^"] |
|
112 |
|
113 %s string_rules |
|
114 /* Rule set for string literals. */ |
|
115 /* n.b. Exclusive rule sets i.e. %x are available in MKS only */ |
|
116 /* so they are not used here; hence all the <INITIAL>'s. */ |
|
117 |
|
118 %s file_line_rules |
|
119 /* Rule set for file_line_directive.*/ |
|
120 |
|
121 %s cpp_comment |
|
122 /* C++ comment to end of line */ |
|
123 |
|
124 %s c_comment |
|
125 /* C comment */ |
|
126 |
|
127 %s comment_tag |
|
128 /* Doxygen-style comment tag */ |
|
129 |
|
130 %% |
|
131 |
|
132 |
|
133 /* Translations section */ |
|
134 /* ==================== */ |
|
135 |
|
136 /*******************************************/ |
|
137 /* Main keywords */ |
|
138 /*******************************************/ |
|
139 <INITIAL>STRUCT return L_STRUCT; |
|
140 <INITIAL>RESOURCE return L_RESOURCE; |
|
141 <INITIAL>NAME return L_NAME; |
|
142 <INITIAL>CHARACTER_SET return L_CHARACTER_SET; |
|
143 <INITIAL>OFFSET return L_OFFSET; |
|
144 <INITIAL>SYSTEM return L_SYSTEM; |
|
145 <INITIAL>GLOBAL return L_GLOBAL; |
|
146 <INITIAL>LOCAL return L_LOCAL; |
|
147 <INITIAL>ENUM return L_ENUM; |
|
148 <INITIAL>enum return L_ENUM; |
|
149 <INITIAL>UID2 return L_UID_TWO; |
|
150 <INITIAL>UID3 return L_UID_THREE; |
|
151 <INITIAL>rls_string return L_RLS_STRING; |
|
152 <INITIAL>rls_string8 return L_RLS_STRING8; |
|
153 <INITIAL>rls_double return L_RLS_DOUBLE; |
|
154 <INITIAL>rls_byte return L_RLS_BYTE; |
|
155 <INITIAL>rls_word return L_RLS_WORD; |
|
156 <INITIAL>rls_long return L_RLS_LONG; |
|
157 <INITIAL>multi return L_MULTI; |
|
158 |
|
159 /*******************************************/ |
|
160 /* Types */ |
|
161 /*******************************************/ |
|
162 <INITIAL>BUF return L_BUF; |
|
163 <INITIAL>BUF8 return L_BUF8; |
|
164 <INITIAL>BUF16 return L_BUF16; |
|
165 <INITIAL>WORD return L_WORD; |
|
166 <INITIAL>BYTE return L_BYTE; |
|
167 <INITIAL>LONG return L_LONG; |
|
168 <INITIAL>DOUBLE return L_DOUBLE; |
|
169 <INITIAL>TEXT return L_TEXT; |
|
170 <INITIAL>LTEXT return L_LTEXT; |
|
171 <INITIAL>TEXT8 return L_TEXT8; |
|
172 <INITIAL>LTEXT8 return L_LTEXT8; |
|
173 <INITIAL>TEXT16 return L_TEXT16; |
|
174 <INITIAL>LTEXT16 return L_LTEXT16; |
|
175 <INITIAL>LINK return L_LINK; |
|
176 <INITIAL>LLINK return L_LLINK; |
|
177 <INITIAL>SRLINK return L_SRLINK; |
|
178 |
|
179 |
|
180 /*******************************************/ |
|
181 /* Others */ |
|
182 /*******************************************/ |
|
183 <INITIAL>LEN return L_LEN; |
|
184 |
|
185 |
|
186 /*******************************************/ |
|
187 /* String & character literals */ |
|
188 /*******************************************/ |
|
189 <INITIAL>\" { BEGIN(string_rules); pCh = buf; isCharLiteral=0; } |
|
190 <INITIAL>' { BEGIN(string_rules); pCh = buf; isCharLiteral=1; } |
|
191 |
|
192 /* Escaped single- and double-quotes.*/ |
|
193 <string_rules>\\\" { CHECK_APPEND('"'); } |
|
194 <string_rules>\\' { CHECK_APPEND('\''); }; |
|
195 |
|
196 /* Convert escaped character into corresponding actual character e.g. \t to tab. */ |
|
197 <string_rules>\\[rbfntv] { CHECK_APPEND( * ( strchr("\rr\bb\ff\nn\tt\vv\aa", yytext[1])-1));} |
|
198 |
|
199 /* Escaped backslash */ |
|
200 <string_rules>\\\\ { CHECK_APPEND('\\'); } |
|
201 |
|
202 <string_rules>\\\n /* Escaped newline ignored*/ ; |
|
203 |
|
204 /* End of line before terminating double-quotes.*/ |
|
205 <string_rules>(\r)?\n { yyerror( isCharLiteral?"Unterminated character literal":"Unterminated string"); BEGIN 0; } |
|
206 |
|
207 /* End of string reached.*/ |
|
208 <string_rules>\" { |
|
209 if (!isCharLiteral) |
|
210 { |
|
211 *pCh = '\0'; BEGIN(0); strcpy( yylval.Value, buf); |
|
212 return L_STRING_LITERAL; |
|
213 } |
|
214 CHECK_APPEND(*yytext); |
|
215 } |
|
216 |
|
217 <string_rules>' { |
|
218 if (isCharLiteral) |
|
219 { |
|
220 *pCh = '\0'; BEGIN(0); strcpy( yylval.Value, buf); return L_CHAR_LITERAL; |
|
221 } |
|
222 CHECK_APPEND(*yytext); |
|
223 } |
|
224 |
|
225 /* Anything other than \n is stored.*/ |
|
226 <string_rules>. { CHECK_APPEND(*yytext); } |
|
227 |
|
228 |
|
229 /*******************************************/ |
|
230 /* Labels */ |
|
231 /*******************************************/ |
|
232 <INITIAL>{LetterOrUnderscore}{AlphanumUscore}* { |
|
233 BEGIN(0); |
|
234 strcpy( yylval.Value, yytext); |
|
235 return L_LABEL; |
|
236 } |
|
237 |
|
238 /*******************************************/ |
|
239 /* Numbers */ |
|
240 /*******************************************/ |
|
241 <INITIAL>{Digit}+ { strcpy( yylval.Value, yytext); return L_NUM_NATURAL; } |
|
242 <INITIAL>0x{HexChar}+ { strcpy( yylval.Value, yytext); return L_NUM_NATURAL; } |
|
243 <INITIAL>{Digit}+\.{Digit}+{ExpChar}{Digit}+ { strcpy( yylval.Value, yytext); return L_NUM_FLOAT;} |
|
244 <INITIAL>-{Digit}+\.{Digit}+{ExpChar}{Digit}+ { strcpy( yylval.Value, yytext); return L_NUM_FLOAT;} |
|
245 <INITIAL>{Digit}+\.{Digit}+ { strcpy( yylval.Value, yytext); return L_NUM_FLOAT;} |
|
246 <INITIAL>-{Digit}+\.{Digit}+ { strcpy( yylval.Value, yytext); return L_NUM_FLOAT;} |
|
247 <INITIAL>{Digit}+{ExpChar}{Digit}+ { strcpy( yylval.Value, yytext); return L_NUM_FLOAT;} |
|
248 <INITIAL>-{Digit}+{ExpChar}{Digit}+ { strcpy( yylval.Value, yytext); return L_NUM_FLOAT;} |
|
249 |
|
250 /*******************************************/ |
|
251 /* file_line_directive */ |
|
252 /*******************************************/ |
|
253 <INITIAL>[#][ ]{Digit}+[ ]\" { BEGIN(file_line_rules); strcpy( RealLineNumber, yytext+2); } |
|
254 |
|
255 <file_line_rules>\"(\r)?$ { BEGIN(0); // # <line> "" means start of base file. |
|
256 pFileLineHandler->SetBase( InputBaseName, * pCurrentLineNumber); |
|
257 } |
|
258 |
|
259 <file_line_rules>{FileNameChar}*\"(\r)?$ { BEGIN(0); // # <line> <filename> means @ line <line> of named base file. |
|
260 pFileLineHandler->PostInclude( yytext, RealLineNumber, * pCurrentLineNumber); |
|
261 } |
|
262 |
|
263 <file_line_rules>{FileNameChar}*\"[ ]1([ ]3){0,1}(\r)?$ { |
|
264 BEGIN(0); // # <line> <filename> 1 means start of an included file. |
|
265 pFileLineHandler->SetInclude( yytext, * pCurrentLineNumber); |
|
266 } |
|
267 |
|
268 <file_line_rules>{FileNameChar}*\"[ ]2([ ]3){0,1}(\r)?$ { |
|
269 BEGIN(0); // # <line> <filename> 2 means end of an included file and now at <line> in <filename>. |
|
270 pFileLineHandler->PostInclude( yytext, RealLineNumber, * pCurrentLineNumber); |
|
271 } |
|
272 |
|
273 |
|
274 |
|
275 /*******************************************/ |
|
276 /* White space */ |
|
277 /*******************************************/ |
|
278 <INITIAL,file_line_rules>[ \t] ; // skipped |
|
279 <INITIAL>[\n\r] ; // skipped |
|
280 <file_line_rules>[\n\r] ; // skipped |
|
281 <INITIAL,file_line_rules>"//" { BEGIN(cpp_comment); } |
|
282 <cpp_comment>[\n\r] { BEGIN(0); } |
|
283 <cpp_comment>. ; // skipped |
|
284 <INITIAL,file_line_rules>"/*"/[^&\n] { BEGIN(c_comment); } |
|
285 <INITIAL,file_line_rules>"/*"[\n\r] { BEGIN(c_comment); } |
|
286 <c_comment>"*/" { BEGIN(0); } |
|
287 <c_comment>[\n\r] ; // skipped |
|
288 <c_comment>. ; // skipped |
|
289 |
|
290 /*******************************************/ |
|
291 /* Comment tags */ |
|
292 /*******************************************/ |
|
293 |
|
294 <INITIAL,file_line_rules>[ \t]*"/*&" { |
|
295 BEGIN(comment_tag); |
|
296 pGL->SetStart(*(pFileLineHandler->GetCurrentFile()), pFileLineHandler->GetErrorLine(* pCurrentLineNumber)); |
|
297 return L_TAG_START; |
|
298 } // any comment beginning with a slash followed by a star followed by an ampersand |
|
299 <comment_tag>"*/" { |
|
300 BEGIN(0); |
|
301 return L_TAG_END; |
|
302 } |
|
303 <comment_tag>"@"[^* \t\r\n]+ { strcpy( yylval.Value, yytext); return L_TAG_COMMAND; } |
|
304 <comment_tag>[^*@ \t\n\r][^ *\t\r\n]* { strcpy( yylval.Value, yytext); return L_TAG_WORD; } |
|
305 <comment_tag>[\n\r] { strcpy( yylval.Value, "\n"); return L_TAG_NEW_LINE; } |
|
306 <comment_tag>[* \t] ; |
|
307 |
|
308 /*******************************************/ |
|
309 /* Special single characters */ |
|
310 /*******************************************/ |
|
311 <INITIAL>[.{};=\[\],()+\-*/|<>] return * yytext; |
|
312 |
|
313 |
|
314 /*******************************************/ |
|
315 /* Everything else cannot be recognised */ |
|
316 /*******************************************/ |
|
317 . { yyerror("*** Unknown character '%c' (value 0x%x) ", *yytext, *yytext);} |