source: trunk/tools/linguist/lupdate/qscript.cpp@ 561

Last change on this file since 561 was 561, checked in by Dmitry A. Kuminov, 15 years ago

trunk: Merged in qt 4.6.1 sources.

  • Property svn:eol-style set to native
File size: 82.5 KB
Line 
1// This file was generated by qlalr - DO NOT EDIT!
2/****************************************************************************
3**
4** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
5** All rights reserved.
6** Contact: Nokia Corporation (qt-info@nokia.com)
7**
8** This file is part of the Qt Linguist of the Qt Toolkit.
9**
10** $QT_BEGIN_LICENSE:LGPL$
11** Commercial Usage
12** Licensees holding valid Qt Commercial licenses may use this file in
13** accordance with the Qt Commercial License Agreement provided with the
14** Software or, alternatively, in accordance with the terms contained in
15** a written agreement between you and Nokia.
16**
17** GNU Lesser General Public License Usage
18** Alternatively, this file may be used under the terms of the GNU Lesser
19** General Public License version 2.1 as published by the Free Software
20** Foundation and appearing in the file LICENSE.LGPL included in the
21** packaging of this file. Please review the following information to
22** ensure the GNU Lesser General Public License version 2.1 requirements
23** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
24**
25** In addition, as a special exception, Nokia gives you certain additional
26** rights. These rights are described in the Nokia Qt LGPL Exception
27** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
28**
29** GNU General Public License Usage
30** Alternatively, this file may be used under the terms of the GNU
31** General Public License version 3.0 as published by the Free Software
32** Foundation and appearing in the file LICENSE.GPL included in the
33** packaging of this file. Please review the following information to
34** ensure the GNU General Public License version 3.0 requirements will be
35** met: http://www.gnu.org/copyleft/gpl.html.
36**
37** If you have questions regarding the use of this file, please contact
38** Nokia at qt-info@nokia.com.
39** $QT_END_LICENSE$
40**
41****************************************************************************/
42
43class QScriptGrammar
44{
45public:
46 enum {
47 EOF_SYMBOL = 0,
48 T_AND = 1,
49 T_AND_AND = 2,
50 T_AND_EQ = 3,
51 T_AUTOMATIC_SEMICOLON = 62,
52 T_BREAK = 4,
53 T_CASE = 5,
54 T_CATCH = 6,
55 T_COLON = 7,
56 T_COMMA = 8,
57 T_CONST = 81,
58 T_CONTINUE = 9,
59 T_DEBUGGER = 82,
60 T_DEFAULT = 10,
61 T_DELETE = 11,
62 T_DIVIDE_ = 12,
63 T_DIVIDE_EQ = 13,
64 T_DO = 14,
65 T_DOT = 15,
66 T_ELSE = 16,
67 T_EQ = 17,
68 T_EQ_EQ = 18,
69 T_EQ_EQ_EQ = 19,
70 T_FALSE = 80,
71 T_FINALLY = 20,
72 T_FOR = 21,
73 T_FUNCTION = 22,
74 T_GE = 23,
75 T_GT = 24,
76 T_GT_GT = 25,
77 T_GT_GT_EQ = 26,
78 T_GT_GT_GT = 27,
79 T_GT_GT_GT_EQ = 28,
80 T_IDENTIFIER = 29,
81 T_IF = 30,
82 T_IN = 31,
83 T_INSTANCEOF = 32,
84 T_LBRACE = 33,
85 T_LBRACKET = 34,
86 T_LE = 35,
87 T_LPAREN = 36,
88 T_LT = 37,
89 T_LT_LT = 38,
90 T_LT_LT_EQ = 39,
91 T_MINUS = 40,
92 T_MINUS_EQ = 41,
93 T_MINUS_MINUS = 42,
94 T_NEW = 43,
95 T_NOT = 44,
96 T_NOT_EQ = 45,
97 T_NOT_EQ_EQ = 46,
98 T_NULL = 78,
99 T_NUMERIC_LITERAL = 47,
100 T_OR = 48,
101 T_OR_EQ = 49,
102 T_OR_OR = 50,
103 T_PLUS = 51,
104 T_PLUS_EQ = 52,
105 T_PLUS_PLUS = 53,
106 T_QUESTION = 54,
107 T_RBRACE = 55,
108 T_RBRACKET = 56,
109 T_REMAINDER = 57,
110 T_REMAINDER_EQ = 58,
111 T_RESERVED_WORD = 83,
112 T_RETURN = 59,
113 T_RPAREN = 60,
114 T_SEMICOLON = 61,
115 T_STAR = 63,
116 T_STAR_EQ = 64,
117 T_STRING_LITERAL = 65,
118 T_SWITCH = 66,
119 T_THIS = 67,
120 T_THROW = 68,
121 T_TILDE = 69,
122 T_TRUE = 79,
123 T_TRY = 70,
124 T_TYPEOF = 71,
125 T_VAR = 72,
126 T_VOID = 73,
127 T_WHILE = 74,
128 T_WITH = 75,
129 T_XOR = 76,
130 T_XOR_EQ = 77,
131
132 ACCEPT_STATE = 236,
133 RULE_COUNT = 267,
134 STATE_COUNT = 465,
135 TERMINAL_COUNT = 84,
136 NON_TERMINAL_COUNT = 88,
137
138 GOTO_INDEX_OFFSET = 465,
139 GOTO_INFO_OFFSET = 1374,
140 GOTO_CHECK_OFFSET = 1374
141 };
142
143 static const char *const spell [];
144 static const int lhs [];
145 static const int rhs [];
146 static const int goto_default [];
147 static const int action_default [];
148 static const int action_index [];
149 static const int action_info [];
150 static const int action_check [];
151
152 static inline int nt_action (int state, int nt)
153 {
154 const int *const goto_index = &action_index [GOTO_INDEX_OFFSET];
155 const int *const goto_check = &action_check [GOTO_CHECK_OFFSET];
156
157 const int yyn = goto_index [state] + nt;
158
159 if (yyn < 0 || goto_check [yyn] != nt)
160 return goto_default [nt];
161
162 const int *const goto_info = &action_info [GOTO_INFO_OFFSET];
163 return goto_info [yyn];
164 }
165
166 static inline int t_action (int state, int token)
167 {
168 const int yyn = action_index [state] + token;
169
170 if (yyn < 0 || action_check [yyn] != token)
171 return - action_default [state];
172
173 return action_info [yyn];
174 }
175};
176
177
178const char *const QScriptGrammar::spell [] = {
179 "end of file", "&", "&&", "&=", "break", "case", "catch", ":", ";", "continue",
180 "default", "delete", "/", "/=", "do", ".", "else", "=", "==", "===",
181 "finally", "for", "function", ">=", ">", ">>", ">>=", ">>>", ">>>=", "identifier",
182 "if", "in", "instanceof", "{", "[", "<=", "(", "<", "<<", "<<=",
183 "-", "-=", "--", "new", "!", "!=", "!==", "numeric literal", "|", "|=",
184 "||", "+", "+=", "++", "?", "}", "]", "%", "%=", "return",
185 ")", ";", 0, "*", "*=", "string literal", "switch", "this", "throw", "~",
186 "try", "typeof", "var", "void", "while", "with", "^", "^=", "null", "true",
187 "false", "const", "debugger", "reserved word"};
188
189const int QScriptGrammar::lhs [] = {
190 85, 85, 85, 85, 85, 85, 85, 85, 85, 85,
191 85, 85, 85, 85, 87, 87, 91, 91, 86, 86,
192 92, 92, 93, 93, 93, 93, 94, 94, 94, 94,
193 94, 94, 94, 94, 94, 94, 94, 94, 94, 94,
194 94, 94, 94, 94, 94, 94, 94, 94, 94, 94,
195 94, 94, 94, 94, 94, 94, 94, 95, 95, 96,
196 96, 96, 96, 96, 99, 99, 100, 100, 100, 100,
197 98, 98, 101, 101, 102, 102, 103, 103, 103, 104,
198 104, 104, 104, 104, 104, 104, 104, 104, 104, 105,
199 105, 105, 105, 106, 106, 106, 107, 107, 107, 107,
200 108, 108, 108, 108, 108, 108, 108, 109, 109, 109,
201 109, 109, 109, 110, 110, 110, 110, 110, 111, 111,
202 111, 111, 111, 112, 112, 113, 113, 114, 114, 115,
203 115, 116, 116, 117, 117, 118, 118, 119, 119, 120,
204 120, 121, 121, 122, 122, 123, 123, 90, 90, 124,
205 124, 125, 125, 125, 125, 125, 125, 125, 125, 125,
206 125, 125, 125, 89, 89, 126, 126, 127, 127, 128,
207 128, 129, 129, 129, 129, 129, 129, 129, 129, 129,
208 129, 129, 129, 129, 129, 129, 130, 146, 146, 145,
209 145, 131, 131, 147, 147, 148, 148, 150, 150, 149,
210 151, 154, 152, 152, 155, 153, 153, 132, 133, 133,
211 134, 134, 135, 135, 135, 135, 135, 135, 135, 136,
212 136, 136, 136, 137, 137, 137, 137, 138, 138, 139,
213 141, 156, 156, 159, 159, 157, 157, 160, 158, 140,
214 142, 142, 143, 143, 143, 161, 162, 144, 163, 97,
215 167, 167, 164, 164, 165, 165, 168, 84, 169, 169,
216 170, 170, 166, 166, 88, 88, 171};
217
218const int QScriptGrammar:: rhs[] = {
219 1, 1, 1, 1, 1, 1, 1, 1, 1, 3,
220 3, 5, 3, 3, 2, 4, 1, 2, 0, 1,
221 3, 5, 1, 1, 1, 1, 1, 1, 1, 1,
222 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
223 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
224 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
225 1, 4, 3, 3, 1, 2, 2, 2, 4, 3,
226 2, 3, 1, 3, 1, 1, 1, 2, 2, 1,
227 2, 2, 2, 2, 2, 2, 2, 2, 2, 1,
228 3, 3, 3, 1, 3, 3, 1, 3, 3, 3,
229 1, 3, 3, 3, 3, 3, 3, 1, 3, 3,
230 3, 3, 3, 1, 3, 3, 3, 3, 1, 3,
231 3, 3, 3, 1, 3, 1, 3, 1, 3, 1,
232 3, 1, 3, 1, 3, 1, 3, 1, 3, 1,
233 3, 1, 3, 1, 5, 1, 5, 1, 3, 1,
234 3, 1, 1, 1, 1, 1, 1, 1, 1, 1,
235 1, 1, 1, 1, 3, 0, 1, 1, 3, 0,
236 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
237 1, 1, 1, 1, 1, 1, 3, 1, 2, 0,
238 1, 3, 3, 1, 1, 1, 3, 1, 3, 2,
239 2, 2, 0, 1, 2, 0, 1, 1, 2, 2,
240 7, 5, 7, 7, 5, 9, 10, 7, 8, 2,
241 2, 3, 3, 2, 2, 3, 3, 3, 3, 5,
242 5, 3, 5, 1, 2, 0, 1, 4, 3, 3,
243 3, 3, 3, 3, 4, 5, 2, 1, 8, 8,
244 1, 3, 0, 1, 0, 1, 1, 1, 1, 2,
245 1, 1, 0, 1, 0, 1, 2};
246
247const int QScriptGrammar::action_default [] = {
248 0, 97, 164, 128, 136, 132, 172, 179, 76, 148,
249 178, 186, 174, 124, 0, 175, 262, 61, 176, 177,
250 182, 77, 140, 144, 65, 94, 75, 80, 60, 0,
251 114, 180, 101, 259, 258, 261, 183, 0, 194, 0,
252 248, 0, 8, 9, 0, 5, 0, 263, 2, 0,
253 265, 19, 0, 0, 0, 0, 0, 3, 6, 0,
254 0, 166, 208, 7, 0, 1, 0, 0, 4, 0,
255 0, 195, 0, 0, 0, 184, 185, 90, 0, 173,
256 181, 0, 0, 77, 96, 263, 2, 265, 79, 78,
257 0, 0, 0, 92, 93, 91, 0, 264, 253, 254,
258 0, 251, 0, 252, 0, 255, 256, 0, 257, 250,
259 260, 0, 266, 0, 26, 27, 28, 29, 30, 31,
260 32, 33, 34, 35, 36, 37, 38, 39, 40, 23,
261 41, 42, 43, 44, 45, 25, 46, 47, 24, 48,
262 49, 50, 51, 52, 53, 54, 55, 56, 57, 0,
263 21, 0, 0, 0, 22, 13, 95, 0, 125, 0,
264 0, 0, 0, 115, 0, 0, 0, 0, 0, 0,
265 105, 0, 0, 0, 99, 100, 98, 103, 107, 106,
266 104, 102, 117, 116, 118, 0, 133, 0, 129, 68,
267 0, 0, 0, 70, 59, 58, 0, 0, 69, 165,
268 0, 73, 71, 0, 72, 74, 209, 210, 0, 161,
269 154, 152, 159, 160, 158, 157, 163, 156, 155, 153,
270 162, 149, 0, 137, 0, 0, 141, 0, 0, 145,
271 67, 0, 0, 63, 0, 62, 267, 224, 0, 225,
272 226, 227, 220, 0, 221, 222, 223, 81, 0, 0,
273 0, 0, 0, 213, 214, 170, 168, 130, 138, 134,
274 150, 126, 171, 0, 77, 142, 146, 119, 108, 0,
275 0, 127, 0, 0, 0, 0, 120, 0, 0, 0,
276 0, 0, 112, 110, 113, 111, 109, 122, 121, 123,
277 0, 135, 0, 131, 0, 169, 77, 0, 151, 166,
278 167, 0, 166, 0, 0, 216, 0, 0, 0, 218,
279 0, 139, 0, 0, 143, 0, 0, 147, 206, 0,
280 198, 207, 201, 0, 205, 0, 166, 199, 0, 166,
281 0, 0, 217, 0, 0, 0, 219, 264, 253, 0,
282 0, 255, 0, 249, 0, 240, 0, 0, 0, 212,
283 0, 211, 188, 191, 0, 27, 30, 31, 248, 34,
284 35, 5, 39, 40, 2, 41, 44, 3, 6, 166,
285 7, 48, 1, 50, 4, 52, 53, 54, 55, 56,
286 57, 189, 187, 65, 66, 64, 0, 228, 229, 0,
287 0, 0, 231, 236, 234, 237, 0, 0, 235, 236,
288 0, 232, 0, 233, 190, 239, 0, 190, 238, 0,
289 241, 242, 0, 190, 243, 244, 0, 0, 245, 0,
290 0, 0, 246, 247, 83, 82, 0, 0, 0, 215,
291 0, 0, 0, 230, 0, 20, 0, 17, 19, 11,
292 0, 16, 12, 18, 15, 10, 0, 14, 87, 85,
293 89, 86, 84, 88, 203, 196, 0, 204, 200, 0,
294 202, 192, 0, 193, 197};
295
296const int QScriptGrammar::goto_default [] = {
297 29, 28, 436, 434, 113, 14, 2, 435, 112, 111,
298 114, 193, 24, 17, 189, 26, 8, 200, 21, 27,
299 77, 25, 1, 32, 30, 267, 13, 261, 3, 257,
300 5, 259, 4, 258, 22, 265, 23, 266, 9, 260,
301 256, 297, 386, 262, 263, 35, 6, 79, 12, 15,
302 18, 19, 10, 7, 31, 80, 20, 36, 75, 76,
303 11, 354, 353, 78, 456, 455, 319, 320, 458, 322,
304 457, 321, 392, 396, 399, 395, 394, 414, 415, 16,
305 100, 107, 96, 99, 106, 108, 33, 0};
306
307const int QScriptGrammar::action_index [] = {
308 1210, 59, -84, 71, 41, -1, -84, -84, 148, -84,
309 -84, -84, -84, 201, 130, -84, -84, -84, -84, -84,
310 -84, 343, 67, 62, 122, 109, -84, -84, -84, 85,
311 273, -84, 184, -84, 1210, -84, -84, 119, -84, 112,
312 -84, 521, -84, -84, 1130, -84, 45, 54, 58, 38,
313 1290, 50, 521, 521, 521, 376, 521, -84, -84, 521,
314 521, 521, -84, -84, 25, -84, 521, 521, -84, 43,
315 521, -84, 521, 18, 15, -84, -84, -84, 24, -84,
316 -84, 521, 521, 64, 153, 27, -84, 1050, -84, -84,
317 521, 521, 521, -84, -84, -84, 28, -84, 37, 55,
318 19, -84, 33, -84, 34, 1210, -84, 16, 1210, -84,
319 -84, 39, 52, -3, -84, -84, -84, -84, -84, -84,
320 -84, -84, -84, -84, -84, -84, -84, -84, -84, -84,
321 -84, -84, -84, -84, -84, -84, -84, -84, -84, -84,
322 -84, -84, -84, -84, -84, -84, -84, -84, -84, 521,
323 -84, 1050, 125, 521, -84, -84, 155, 521, 189, 521,
324 521, 521, 521, 248, 521, 521, 521, 521, 521, 521,
325 243, 521, 521, 521, 75, 82, 94, 177, 184, 184,
326 184, 184, 263, 283, 298, 521, 44, 521, 77, -84,
327 970, 521, 817, -84, -84, -84, 95, 521, -84, -84,
328 93, -84, -84, 521, -84, -84, -84, -84, 521, -84,
329 -84, -84, -84, -84, -84, -84, -84, -84, -84, -84,
330 -84, -84, 521, 41, 521, 521, 68, 66, 521, -84,
331 -84, 970, 521, -84, 103, -84, -84, -84, 63, -84,
332 -84, -84, -84, 69, -84, -84, -84, -84, -27, 12,
333 521, 92, 100, -84, -84, 890, -84, 31, -13, -45,
334 -84, 210, 32, -28, 387, 20, 73, 304, 117, -5,
335 521, 212, 521, 521, 521, 521, 213, 521, 521, 521,
336 521, 521, 151, 150, 176, 158, 168, 304, 304, 228,
337 521, -72, 521, 4, 521, -84, 306, 521, -84, 521,
338 8, -50, 521, -48, 1130, -84, 521, 80, 1130, -84,
339 521, -33, 521, 521, 5, 48, 521, -84, 17, 88,
340 11, -84, -84, 521, -84, -29, 521, -84, -41, 521,
341 -39, 1130, -84, 521, 87, 1130, -84, -8, -2, -35,
342 10, 1210, -16, -84, 1130, -84, 521, 86, 1130, -14,
343 1130, -84, -84, 1130, -36, 107, -21, 165, 3, 521,
344 1130, 6, 14, 61, 7, -19, 448, -4, -6, 671,
345 29, 13, 23, 521, 30, -10, 521, 9, 521, -30,
346 -18, -84, -84, 164, -84, -84, 46, -84, -84, 521,
347 111, -24, -84, 36, -84, 40, 99, 521, -84, 21,
348 22, -84, -11, -84, 1130, -84, 106, 1130, -84, 178,
349 -84, -84, 98, 1130, 57, -84, 56, 60, -84, 51,
350 26, 35, -84, -84, -84, -84, 521, 97, 1130, -84,
351 521, 90, 1130, -84, 79, 76, 744, -84, 49, -84,
352 594, -84, -84, -84, -84, -84, 83, -84, -84, -84,
353 -84, -84, -84, -84, 42, -84, 162, -84, -84, 521,
354 -84, -84, 53, -84, -84,
355
356 -61, -88, -88, -88, -88, -88, -88, -88, -88, -88,
357 -88, -88, -88, -88, -88, -88, -88, -88, -88, -88,
358 -88, -4, -88, -88, 22, -88, -88, -88, -88, -88,
359 -88, -88, -88, -88, -51, -88, -88, -88, -88, -88,
360 -88, 105, -88, -88, -12, -88, -88, -88, -88, -88,
361 -7, -88, 35, 132, 62, 154, 79, -88, -88, 100,
362 75, 36, -88, -88, -88, -88, 37, 70, -88, -1,
363 86, -88, 92, -88, -88, -88, -88, -88, -88, -88,
364 -88, 90, 95, -88, -88, -88, -88, -88, -88, -88,
365 87, 82, 74, -88, -88, -88, -88, -88, -88, -88,
366 -88, -88, -88, -88, -88, -88, -88, -88, -47, -88,
367 -88, -88, -88, -88, -88, -88, -88, -88, -88, -88,
368 -88, -88, -88, -88, -88, -88, -88, -88, -88, -88,
369 -88, -88, -88, -88, -88, -88, -88, -88, -88, -88,
370 -88, -88, -88, -88, -88, -88, -88, -88, -88, 28,
371 -88, 20, -88, 19, -88, -88, -88, 39, -88, 42,
372 43, 106, 61, -88, 63, 55, 52, 53, 91, 125,
373 -88, 120, 123, 118, -88, -88, -88, -88, -88, -88,
374 -88, -88, -88, -88, -88, 116, -88, 59, -88, -88,
375 16, 18, 15, -88, -88, -88, -88, 21, -88, -88,
376 -88, -88, -88, 24, -88, -88, -88, -88, 38, -88,
377 -88, -88, -88, -88, -88, -88, -88, -88, -88, -88,
378 -88, -88, 97, -88, 115, 25, -88, -88, 26, -88,
379 -88, 111, 14, -88, -88, -88, -88, -88, -88, -88,
380 -88, -88, -88, -88, -88, -88, -88, -88, -88, -88,
381 23, -88, -88, -88, -88, 108, -88, -88, -88, -88,
382 -88, -88, -88, -88, -88, -88, -88, -88, -88, -88,
383 160, -88, 171, 163, 145, 179, -88, 135, 45, 41,
384 66, 80, -88, -88, -88, -88, -88, -88, -88, -88,
385 172, -88, 156, -88, 142, -88, -88, 144, -88, 122,
386 -88, -88, 114, -88, -23, -88, 48, -88, 29, -88,
387 224, -88, 157, 175, -88, -88, 182, -88, -88, -88,
388 -88, -88, -88, 183, -88, -21, 134, -88, -88, 49,
389 -88, 3, -88, 44, -88, 2, -88, -88, -37, -88,
390 -88, -31, -88, -88, 10, -88, 47, -88, 17, -88,
391 27, -88, -88, 13, -88, -88, -88, -88, -88, 117,
392 6, -88, -88, -88, -88, -88, 154, -88, -88, 1,
393 -88, -88, -88, 7, -88, -35, 137, -88, 141, -88,
394 -88, -88, -88, -6, -88, -88, -88, -88, -88, 78,
395 -88, -88, -88, -88, -88, -69, -88, 11, -88, -59,
396 -88, -88, -88, -88, 83, -88, -88, 56, -88, -88,
397 -88, -88, -88, -40, -58, -88, -88, -29, -88, -88,
398 -88, -45, -88, -88, -88, -88, -3, -88, -42, -88,
399 -5, -88, -32, -88, -88, -88, 9, -88, 8, -88,
400 -2, -88, -88, -88, -88, -88, -88, -88, -88, -88,
401 -88, -88, -88, -88, -88, -88, -88, -88, -88, 12,
402 -88, -88, -56, -88, -88};
403
404const int QScriptGrammar::action_info [] = {
405 318, -25, 350, -45, 292, 270, 426, 310, -194, 393,
406 -32, 302, 304, -37, 344, 290, 197, 346, 430, 382,
407 329, 331, 310, 413, 318, 340, 397, 101, 338, 404,
408 -49, 292, 270, 299, 323, 290, -24, -51, -195, 343,
409 294, 397, 333, 341, 403, 397, 149, 249, 250, 389,
410 255, 430, 155, 454, 426, 316, 97, 437, 437, 459,
411 151, 389, 103, 102, 98, 344, 101, 105, 413, 222,
412 222, 109, 157, 228, 346, 187, 413, 417, 157, 104,
413 420, 255, 454, 337, 443, 236, 421, 438, 197, 185,
414 97, 197, 419, 413, 197, 197, 325, -263, 197, 81,
415 197, 203, 0, 197, 416, 197, 88, 388, 387, 400,
416 82, 197, 224, 407, 197, 81, 225, 89, 417, 197,
417 187, 90, 81, 312, 241, 240, 82, 313, 0, 0,
418 246, 245, 153, 82, 81, 439, 238, 231, 197, 0,
419 308, 243, 171, 447, 172, 82, 348, 335, 238, 326,
420 432, 198, 252, 204, 401, 173, 232, 428, 192, 235,
421 0, 254, 253, 190, 0, 90, 91, 90, 239, 237,
422 462, 391, 92, 244, 242, 171, 171, 172, 172, 231,
423 239, 237, 191, 171, 192, 172, 197, 0, 173, 173,
424 0, 207, 206, 171, 243, 172, 173, 0, 232, 0,
425 192, 171, 171, 172, 172, 0, 173, 159, 160, 171,
426 91, 172, 91, 0, 173, 173, 92, 0, 92, 159,
427 160, 0, 173, 463, 461, 0, 244, 242, 272, 273,
428 272, 273, 0, 0, 161, 162, 277, 278, 0, 411,
429 410, 0, 0, 0, 0, 279, 161, 162, 280, 0,
430 281, 277, 278, 0, 0, 274, 275, 274, 275, 0,
431 279, 0, 0, 280, 0, 281, 0, 0, 171, 0,
432 172, 164, 165, 0, 0, 0, 0, 0, 0, 166,
433 167, 173, 0, 168, 0, 169, 164, 165, 0, 0,
434 0, 0, 0, 0, 166, 167, 164, 165, 168, 0,
435 169, 0, 0, 0, 166, 167, 164, 165, 168, 209,
436 169, 0, 0, 0, 166, 167, 0, 0, 168, 210,
437 169, 164, 165, 211, 0, 0, 0, 277, 278, 166,
438 167, 0, 212, 168, 213, 169, 279, 0, 0, 280,
439 0, 281, 0, 0, 0, 214, 209, 215, 88, 0,
440 0, 0, 0, 0, 0, 216, 210, 0, 217, 89,
441 211, 0, 0, 0, 218, 0, 0, 0, 0, 212,
442 219, 213, 0, 0, 0, 0, 0, 0, 0, 0,
443 0, 0, 214, 220, 215, 88, 0, 0, 42, 43,
444 209, 0, 216, 0, 0, 217, 89, 0, 85, 0,
445 210, 218, 0, 0, 211, 86, 0, 219, 0, 87,
446 51, 0, 52, 212, 0, 213, 0, 0, 306, 55,
447 220, 0, 0, 58, 0, 0, 214, 0, 215, 88,
448 0, 0, 0, 0, 0, 0, 216, 0, 0, 217,
449 89, 63, 0, 65, 0, 218, 0, 0, 0, 0,
450 0, 219, 0, 0, 57, 68, 45, 0, 0, 0,
451 42, 43, 0, 0, 220, 0, 0, 0, 0, 0,
452 85, 0, 0, 0, 0, 0, 0, 86, 0, 0,
453 0, 87, 51, 0, 52, 0, 0, 0, 0, 0,
454 0, 55, 0, 0, 0, 58, 0, 0, 0, 0,
455 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
456 0, 0, 0, 63, 0, 65, 0, 0, 0, 0,
457 0, 0, 0, 0, 0, 0, 57, 68, 45, 0,
458 0, 0, 41, 42, 43, 0, 0, 0, 0, 0,
459 0, 0, 0, 85, 0, 0, 0, 0, 0, 0,
460 86, 0, 0, 0, 87, 51, 0, 52, 0, 0,
461 0, 53, 0, 54, 55, 56, 0, 0, 58, 0,
462 0, 0, 59, 0, 60, 0, 0, 0, 0, 0,
463 0, 0, 0, 0, 0, 0, 63, 0, 65, 0,
464 67, 0, 70, 0, 72, 0, 0, 0, 0, 57,
465 68, 45, 0, 0, 0, 41, 42, 43, 0, 0,
466 0, 0, 0, 0, 0, 0, 85, 0, 0, 0,
467 0, 0, 0, 86, 0, 0, 0, 87, 51, 0,
468 52, 0, 0, 0, 53, 0, 54, 55, 56, 0,
469 0, 58, 0, 0, 0, 59, 0, 60, 0, 0,
470 442, 0, 0, 0, 0, 0, 0, 0, 0, 63,
471 0, 65, 0, 67, 0, 70, 0, 72, 0, 0,
472 0, 0, 57, 68, 45, 0, 0, 0, -47, 0,
473 0, 0, 41, 42, 43, 0, 0, 0, 0, 0,
474 0, 0, 0, 85, 0, 0, 0, 0, 0, 0,
475 86, 0, 0, 0, 87, 51, 0, 52, 0, 0,
476 0, 53, 0, 54, 55, 56, 0, 0, 58, 0,
477 0, 0, 59, 0, 60, 0, 0, 0, 0, 0,
478 0, 0, 0, 0, 0, 0, 63, 0, 65, 0,
479 67, 0, 70, 0, 72, 0, 0, 0, 0, 57,
480 68, 45, 0, 0, 0, 41, 42, 43, 0, 0,
481 0, 0, 0, 0, 0, 0, 85, 0, 0, 0,
482 0, 0, 0, 86, 0, 0, 0, 87, 51, 0,
483 52, 0, 0, 0, 53, 0, 54, 55, 56, 0,
484 0, 58, 0, 0, 0, 59, 0, 60, 0, 0,
485 445, 0, 0, 0, 0, 0, 0, 0, 0, 63,
486 0, 65, 0, 67, 0, 70, 0, 72, 0, 0,
487 0, 0, 57, 68, 45, 0, 0, 0, 41, 42,
488 43, 0, 0, 0, 0, 0, 0, 0, 0, 85,
489 0, 0, 0, 0, 0, 0, 86, 0, 0, 0,
490 87, 51, 0, 52, 0, 0, 0, 53, 0, 54,
491 55, 56, 0, 0, 58, 0, 0, 0, 59, 0,
492 60, 0, 0, 0, 0, 0, 0, 202, 0, 0,
493 0, 0, 63, 0, 65, 0, 67, 0, 70, 0,
494 72, 0, 0, 0, 0, 57, 68, 45, 0, 0,
495 0, 41, 42, 43, 0, 0, 0, 0, 0, 0,
496 0, 0, 85, 0, 0, 0, 0, 0, 0, 86,
497 0, 0, 0, 87, 51, 0, 52, 0, 0, 0,
498 53, 0, 54, 55, 56, 0, 0, 58, 0, 0,
499 0, 59, 0, 60, 0, 0, 0, 0, 0, 0,
500 0, 0, 0, 0, 0, 63, 0, 65, 0, 67,
501 0, 70, 269, 72, 0, 0, 0, 0, 57, 68,
502 45, 0, 0, 0, 115, 116, 117, 0, 0, 119,
503 121, 122, 0, 0, 123, 0, 124, 0, 0, 0,
504 126, 127, 128, 0, 0, 0, 0, 0, 0, 195,
505 130, 131, 132, 0, 0, 0, 0, 0, 0, 0,
506 0, 0, 0, 133, 0, 0, 0, 0, 0, 0,
507 0, 0, 0, 0, 0, 0, 0, 0, 0, 137,
508 0, 0, 0, 0, 0, 0, 139, 140, 141, 0,
509 143, 144, 145, 146, 147, 148, 0, 0, 134, 142,
510 125, 118, 120, 136, 115, 116, 117, 0, 0, 119,
511 121, 122, 0, 0, 123, 0, 124, 0, 0, 0,
512 126, 127, 128, 0, 0, 0, 0, 0, 0, 129,
513 130, 131, 132, 0, 0, 0, 0, 0, 0, 0,
514 0, 0, 0, 133, 0, 0, 0, 135, 0, 0,
515 0, 0, 0, 0, 0, 0, 0, 0, 0, 137,
516 0, 0, 0, 0, 0, 138, 139, 140, 141, 0,
517 143, 144, 145, 146, 147, 148, 0, 0, 134, 142,
518 125, 118, 120, 136, 37, 0, 0, 0, 0, 39,
519 0, 41, 42, 43, 44, 0, 0, 0, 0, 0,
520 0, 46, 85, 0, 0, 0, 0, 0, 0, 48,
521 49, 0, 0, 50, 51, 0, 52, 0, 0, 0,
522 53, 0, 54, 55, 56, 0, 0, 58, 0, 0,
523 0, 59, 0, 60, 0, 0, 0, 0, 0, 61,
524 0, 62, 0, 0, 0, 63, 64, 65, 66, 67,
525 69, 70, 71, 72, 73, 74, 0, 0, 57, 68,
526 45, 38, 40, 0, 37, 0, 0, 0, 0, 39,
527 0, 41, 42, 43, 44, 0, 0, 0, 0, 0,
528 0, 46, 47, 0, 0, 0, 0, 0, 0, 48,
529 49, 0, 0, 50, 51, 0, 52, 0, 0, 0,
530 53, 0, 54, 55, 56, 0, 0, 58, 0, 0,
531 0, 59, 0, 60, 0, 0, 0, 0, 0, 61,
532 0, 62, 0, 0, 0, 63, 64, 65, 66, 67,
533 69, 70, 71, 72, 73, 74, 0, 0, 57, 68,
534 45, 38, 40, 0, 355, 116, 117, 0, 0, 357,
535 121, 359, 42, 43, 360, 0, 124, 0, 0, 0,
536 126, 362, 363, 0, 0, 0, 0, 0, 0, 364,
537 365, 131, 132, 50, 51, 0, 52, 0, 0, 0,
538 53, 0, 54, 366, 56, 0, 0, 368, 0, 0,
539 0, 59, 0, 60, 0, -190, 0, 0, 0, 369,
540 0, 62, 0, 0, 0, 370, 371, 372, 373, 67,
541 375, 376, 377, 378, 379, 380, 0, 0, 367, 374,
542 361, 356, 358, 136,
543
544 431, 422, 427, 429, 441, 352, 300, 398, 385, 464,
545 440, 412, 409, 433, 402, 444, 406, 423, 460, 234,
546 418, 201, 305, 196, 34, 154, 194, 199, 251, 152,
547 205, 227, 229, 248, 150, 110, 230, 208, 352, 110,
548 446, 300, 409, 339, 221, 412, 327, 336, 332, 334,
549 342, 248, 347, 307, 300, 345, 0, 83, 381, 83,
550 83, 83, 349, 83, 284, 158, 163, 182, 283, 0,
551 83, 83, 351, 83, 309, 178, 179, 83, 177, 83,
552 83, 83, 449, 390, 83, 184, 170, 188, 83, 285,
553 453, 330, 83, 83, 95, 452, 0, 83, 83, 450,
554 83, 352, 94, 286, 83, 83, 424, 93, 83, 83,
555 83, 84, 425, 83, 180, 83, 156, 408, 83, 300,
556 451, 194, 233, 83, 83, 247, 264, 300, 352, 223,
557 183, 268, 0, 83, 83, 83, 83, 247, 83, 300,
558 176, 83, 174, 83, 405, 175, 186, 0, 181, 226,
559 83, 0, 448, 83, 0, 83, 303, 424, 282, 83,
560 296, 425, 296, 83, 301, 268, 383, 268, 268, 384,
561 288, 0, 0, 0, 83, 83, 328, 0, 83, 268,
562 268, 83, 295, 268, 298, 293, 268, 271, 287, 83,
563 83, 0, 314, 296, 268, 268, 276, 83, 268, 0,
564 296, 296, 268, 291, 289, 268, 268, 0, 0, 0,
565 0, 0, 0, 0, 0, 315, 0, 0, 0, 0,
566 0, 0, 317, 324, 0, 0, 0, 0, 0, 0,
567 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
568 0, 0, 83, 0, 0, 0, 0, 268, 0, 0,
569 0, 0, 0, 0, 0, 0, 0, 311, 0, 0,
570 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
571 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
572 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
573 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
574 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
575 0, 0};
576
577const int QScriptGrammar::action_check [] = {
578 29, 7, 16, 7, 76, 1, 36, 2, 29, 33,
579 7, 61, 60, 7, 7, 48, 8, 36, 36, 55,
580 61, 60, 2, 33, 29, 60, 5, 29, 36, 7,
581 7, 76, 1, 61, 17, 48, 7, 7, 29, 55,
582 8, 5, 31, 33, 55, 5, 7, 74, 36, 36,
583 36, 36, 55, 29, 36, 7, 29, 8, 8, 17,
584 8, 36, 29, 8, 36, 7, 29, 33, 33, 2,
585 2, 55, 1, 7, 36, 76, 33, 20, 1, 60,
586 29, 36, 29, 29, 8, 0, 60, 8, 8, 48,
587 29, 8, 36, 33, 8, 8, 8, 36, 8, 40,
588 8, 8, -1, 8, 6, 8, 42, 61, 62, 10,
589 51, 8, 50, 7, 8, 40, 54, 53, 20, 8,
590 76, 12, 40, 50, 61, 62, 51, 54, -1, -1,
591 61, 62, 7, 51, 40, 56, 29, 15, 8, -1,
592 60, 29, 25, 60, 27, 51, 60, 60, 29, 61,
593 60, 56, 60, 60, 55, 38, 34, 60, 36, 56,
594 -1, 61, 62, 15, -1, 12, 57, 12, 61, 62,
595 8, 60, 63, 61, 62, 25, 25, 27, 27, 15,
596 61, 62, 34, 25, 36, 27, 8, -1, 38, 38,
597 -1, 61, 62, 25, 29, 27, 38, -1, 34, -1,
598 36, 25, 25, 27, 27, -1, 38, 18, 19, 25,
599 57, 27, 57, -1, 38, 38, 63, -1, 63, 18,
600 19, -1, 38, 61, 62, -1, 61, 62, 18, 19,
601 18, 19, -1, -1, 45, 46, 23, 24, -1, 61,
602 62, -1, -1, -1, -1, 32, 45, 46, 35, -1,
603 37, 23, 24, -1, -1, 45, 46, 45, 46, -1,
604 32, -1, -1, 35, -1, 37, -1, -1, 25, -1,
605 27, 23, 24, -1, -1, -1, -1, -1, -1, 31,
606 32, 38, -1, 35, -1, 37, 23, 24, -1, -1,
607 -1, -1, -1, -1, 31, 32, 23, 24, 35, -1,
608 37, -1, -1, -1, 31, 32, 23, 24, 35, 3,
609 37, -1, -1, -1, 31, 32, -1, -1, 35, 13,
610 37, 23, 24, 17, -1, -1, -1, 23, 24, 31,
611 32, -1, 26, 35, 28, 37, 32, -1, -1, 35,
612 -1, 37, -1, -1, -1, 39, 3, 41, 42, -1,
613 -1, -1, -1, -1, -1, 49, 13, -1, 52, 53,
614 17, -1, -1, -1, 58, -1, -1, -1, -1, 26,
615 64, 28, -1, -1, -1, -1, -1, -1, -1, -1,
616 -1, -1, 39, 77, 41, 42, -1, -1, 12, 13,
617 3, -1, 49, -1, -1, 52, 53, -1, 22, -1,
618 13, 58, -1, -1, 17, 29, -1, 64, -1, 33,
619 34, -1, 36, 26, -1, 28, -1, -1, 31, 43,
620 77, -1, -1, 47, -1, -1, 39, -1, 41, 42,
621 -1, -1, -1, -1, -1, -1, 49, -1, -1, 52,
622 53, 65, -1, 67, -1, 58, -1, -1, -1, -1,
623 -1, 64, -1, -1, 78, 79, 80, -1, -1, -1,
624 12, 13, -1, -1, 77, -1, -1, -1, -1, -1,
625 22, -1, -1, -1, -1, -1, -1, 29, -1, -1,
626 -1, 33, 34, -1, 36, -1, -1, -1, -1, -1,
627 -1, 43, -1, -1, -1, 47, -1, -1, -1, -1,
628 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
629 -1, -1, -1, 65, -1, 67, -1, -1, -1, -1,
630 -1, -1, -1, -1, -1, -1, 78, 79, 80, -1,
631 -1, -1, 11, 12, 13, -1, -1, -1, -1, -1,
632 -1, -1, -1, 22, -1, -1, -1, -1, -1, -1,
633 29, -1, -1, -1, 33, 34, -1, 36, -1, -1,
634 -1, 40, -1, 42, 43, 44, -1, -1, 47, -1,
635 -1, -1, 51, -1, 53, -1, -1, -1, -1, -1,
636 -1, -1, -1, -1, -1, -1, 65, -1, 67, -1,
637 69, -1, 71, -1, 73, -1, -1, -1, -1, 78,
638 79, 80, -1, -1, -1, 11, 12, 13, -1, -1,
639 -1, -1, -1, -1, -1, -1, 22, -1, -1, -1,
640 -1, -1, -1, 29, -1, -1, -1, 33, 34, -1,
641 36, -1, -1, -1, 40, -1, 42, 43, 44, -1,
642 -1, 47, -1, -1, -1, 51, -1, 53, -1, -1,
643 56, -1, -1, -1, -1, -1, -1, -1, -1, 65,
644 -1, 67, -1, 69, -1, 71, -1, 73, -1, -1,
645 -1, -1, 78, 79, 80, -1, -1, -1, 7, -1,
646 -1, -1, 11, 12, 13, -1, -1, -1, -1, -1,
647 -1, -1, -1, 22, -1, -1, -1, -1, -1, -1,
648 29, -1, -1, -1, 33, 34, -1, 36, -1, -1,
649 -1, 40, -1, 42, 43, 44, -1, -1, 47, -1,
650 -1, -1, 51, -1, 53, -1, -1, -1, -1, -1,
651 -1, -1, -1, -1, -1, -1, 65, -1, 67, -1,
652 69, -1, 71, -1, 73, -1, -1, -1, -1, 78,
653 79, 80, -1, -1, -1, 11, 12, 13, -1, -1,
654 -1, -1, -1, -1, -1, -1, 22, -1, -1, -1,
655 -1, -1, -1, 29, -1, -1, -1, 33, 34, -1,
656 36, -1, -1, -1, 40, -1, 42, 43, 44, -1,
657 -1, 47, -1, -1, -1, 51, -1, 53, -1, -1,
658 56, -1, -1, -1, -1, -1, -1, -1, -1, 65,
659 -1, 67, -1, 69, -1, 71, -1, 73, -1, -1,
660 -1, -1, 78, 79, 80, -1, -1, -1, 11, 12,
661 13, -1, -1, -1, -1, -1, -1, -1, -1, 22,
662 -1, -1, -1, -1, -1, -1, 29, -1, -1, -1,
663 33, 34, -1, 36, -1, -1, -1, 40, -1, 42,
664 43, 44, -1, -1, 47, -1, -1, -1, 51, -1,
665 53, -1, -1, -1, -1, -1, -1, 60, -1, -1,
666 -1, -1, 65, -1, 67, -1, 69, -1, 71, -1,
667 73, -1, -1, -1, -1, 78, 79, 80, -1, -1,
668 -1, 11, 12, 13, -1, -1, -1, -1, -1, -1,
669 -1, -1, 22, -1, -1, -1, -1, -1, -1, 29,
670 -1, -1, -1, 33, 34, -1, 36, -1, -1, -1,
671 40, -1, 42, 43, 44, -1, -1, 47, -1, -1,
672 -1, 51, -1, 53, -1, -1, -1, -1, -1, -1,
673 -1, -1, -1, -1, -1, 65, -1, 67, -1, 69,
674 -1, 71, 72, 73, -1, -1, -1, -1, 78, 79,
675 80, -1, -1, -1, 4, 5, 6, -1, -1, 9,
676 10, 11, -1, -1, 14, -1, 16, -1, -1, -1,
677 20, 21, 22, -1, -1, -1, -1, -1, -1, 29,
678 30, 31, 32, -1, -1, -1, -1, -1, -1, -1,
679 -1, -1, -1, 43, -1, -1, -1, -1, -1, -1,
680 -1, -1, -1, -1, -1, -1, -1, -1, -1, 59,
681 -1, -1, -1, -1, -1, -1, 66, 67, 68, -1,
682 70, 71, 72, 73, 74, 75, -1, -1, 78, 79,
683 80, 81, 82, 83, 4, 5, 6, -1, -1, 9,
684 10, 11, -1, -1, 14, -1, 16, -1, -1, -1,
685 20, 21, 22, -1, -1, -1, -1, -1, -1, 29,
686 30, 31, 32, -1, -1, -1, -1, -1, -1, -1,
687 -1, -1, -1, 43, -1, -1, -1, 47, -1, -1,
688 -1, -1, -1, -1, -1, -1, -1, -1, -1, 59,
689 -1, -1, -1, -1, -1, 65, 66, 67, 68, -1,
690 70, 71, 72, 73, 74, 75, -1, -1, 78, 79,
691 80, 81, 82, 83, 4, -1, -1, -1, -1, 9,
692 -1, 11, 12, 13, 14, -1, -1, -1, -1, -1,
693 -1, 21, 22, -1, -1, -1, -1, -1, -1, 29,
694 30, -1, -1, 33, 34, -1, 36, -1, -1, -1,
695 40, -1, 42, 43, 44, -1, -1, 47, -1, -1,
696 -1, 51, -1, 53, -1, -1, -1, -1, -1, 59,
697 -1, 61, -1, -1, -1, 65, 66, 67, 68, 69,
698 70, 71, 72, 73, 74, 75, -1, -1, 78, 79,
699 80, 81, 82, -1, 4, -1, -1, -1, -1, 9,
700 -1, 11, 12, 13, 14, -1, -1, -1, -1, -1,
701 -1, 21, 22, -1, -1, -1, -1, -1, -1, 29,
702 30, -1, -1, 33, 34, -1, 36, -1, -1, -1,
703 40, -1, 42, 43, 44, -1, -1, 47, -1, -1,
704 -1, 51, -1, 53, -1, -1, -1, -1, -1, 59,
705 -1, 61, -1, -1, -1, 65, 66, 67, 68, 69,
706 70, 71, 72, 73, 74, 75, -1, -1, 78, 79,
707 80, 81, 82, -1, 4, 5, 6, -1, -1, 9,
708 10, 11, 12, 13, 14, -1, 16, -1, -1, -1,
709 20, 21, 22, -1, -1, -1, -1, -1, -1, 29,
710 30, 31, 32, 33, 34, -1, 36, -1, -1, -1,
711 40, -1, 42, 43, 44, -1, -1, 47, -1, -1,
712 -1, 51, -1, 53, -1, 55, -1, -1, -1, 59,
713 -1, 61, -1, -1, -1, 65, 66, 67, 68, 69,
714 70, 71, 72, 73, 74, 75, -1, -1, 78, 79,
715 80, 81, 82, 83,
716
717 5, 46, 5, 45, 6, 45, 5, 76, 14, 65,
718 2, 46, 5, 45, 73, 6, 5, 46, 6, 5,
719 78, 6, 45, 5, 85, 6, 10, 6, 5, 9,
720 6, 6, 6, 45, 6, 86, 14, 41, 45, 86,
721 5, 5, 5, 80, 6, 46, 67, 45, 45, 5,
722 81, 45, 5, 5, 5, 45, -1, 18, 45, 18,
723 18, 18, 45, 18, 23, 26, 24, 24, 23, -1,
724 18, 18, 45, 18, 45, 23, 23, 18, 23, 18,
725 18, 18, 20, 5, 18, 24, 23, 28, 18, 23,
726 20, 42, 18, 18, 20, 20, -1, 18, 18, 20,
727 18, 45, 20, 23, 18, 18, 20, 20, 18, 18,
728 18, 21, 20, 18, 23, 18, 21, 61, 18, 5,
729 20, 10, 11, 18, 18, 20, 18, 5, 45, 32,
730 24, 23, -1, 18, 18, 18, 18, 20, 18, 5,
731 22, 18, 22, 18, 61, 22, 30, -1, 23, 34,
732 18, -1, 20, 18, -1, 18, 42, 20, 23, 18,
733 18, 20, 18, 18, 42, 23, 12, 23, 23, 15,
734 25, -1, -1, -1, 18, 18, 42, -1, 18, 23,
735 23, 18, 40, 23, 40, 29, 23, 27, 25, 18,
736 18, -1, 35, 18, 23, 23, 25, 18, 23, -1,
737 18, 18, 23, 31, 25, 23, 23, -1, -1, -1,
738 -1, -1, -1, -1, -1, 40, -1, -1, -1, -1,
739 -1, -1, 40, 40, -1, -1, -1, -1, -1, -1,
740 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
741 -1, -1, 18, -1, -1, -1, -1, 23, -1, -1,
742 -1, -1, -1, -1, -1, -1, -1, 33, -1, -1,
743 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
744 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
745 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
746 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
747 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
748 -1, -1};
749
750
751#define Q_SCRIPT_REGEXPLITERAL_RULE1 7
752
753#define Q_SCRIPT_REGEXPLITERAL_RULE2 8
754
755#include <translator.h>
756
757#include <QtCore/qdebug.h>
758#include <QtCore/qnumeric.h>
759#include <QtCore/qstring.h>
760#include <QtCore/qtextcodec.h>
761#include <QtCore/qvariant.h>
762
763#include <ctype.h>
764#include <stdlib.h>
765#include <stdio.h>
766#include <string.h>
767
768QT_BEGIN_NAMESPACE
769
770static void recordMessage(
771 Translator *tor, const QString &context, const QString &text, const QString &comment,
772 const QString &extracomment, bool plural, const QString &fileName, int lineNo)
773{
774 TranslatorMessage msg(
775 context, text, comment, QString(),
776 fileName, lineNo, QStringList(),
777 TranslatorMessage::Unfinished, plural);
778 msg.setExtraComment(extracomment.simplified());
779 tor->extend(msg);
780}
781
782
783namespace QScript
784{
785
786class Lexer
787{
788public:
789 Lexer();
790 ~Lexer();
791
792 void setCode(const QString &c, int lineno);
793 int lex();
794
795 int currentLineNo() const { return yylineno; }
796 int currentColumnNo() const { return yycolumn; }
797
798 int startLineNo() const { return startlineno; }
799 int startColumnNo() const { return startcolumn; }
800
801 int endLineNo() const { return currentLineNo(); }
802 int endColumnNo() const
803 { int col = currentColumnNo(); return (col > 0) ? col - 1 : col; }
804
805 bool prevTerminator() const { return terminator; }
806
807 enum State { Start,
808 Identifier,
809 InIdentifier,
810 InSingleLineComment,
811 InMultiLineComment,
812 InNum,
813 InNum0,
814 InHex,
815 InOctal,
816 InDecimal,
817 InExponentIndicator,
818 InExponent,
819 Hex,
820 Octal,
821 Number,
822 String,
823 Eof,
824 InString,
825 InEscapeSequence,
826 InHexEscape,
827 InUnicodeEscape,
828 Other,
829 Bad };
830
831 enum Error {
832 NoError,
833 IllegalCharacter,
834 UnclosedStringLiteral,
835 IllegalEscapeSequence,
836 IllegalUnicodeEscapeSequence,
837 UnclosedComment,
838 IllegalExponentIndicator,
839 IllegalIdentifier
840 };
841
842 enum ParenthesesState {
843 IgnoreParentheses,
844 CountParentheses,
845 BalancedParentheses
846 };
847
848 enum RegExpBodyPrefix {
849 NoPrefix,
850 EqualPrefix
851 };
852
853 bool scanRegExp(RegExpBodyPrefix prefix = NoPrefix);
854
855 QString pattern;
856 int flags;
857
858 State lexerState() const
859 { return state; }
860
861 QString errorMessage() const
862 { return errmsg; }
863 void setErrorMessage(const QString &err)
864 { errmsg = err; }
865 void setErrorMessage(const char *err)
866 { setErrorMessage(QString::fromLatin1(err)); }
867
868 Error error() const
869 { return err; }
870 void clearError()
871 { err = NoError; }
872
873private:
874 int yylineno;
875 bool done;
876 char *buffer8;
877 QChar *buffer16;
878 uint size8, size16;
879 uint pos8, pos16;
880 bool terminator;
881 bool restrKeyword;
882 // encountered delimiter like "'" and "}" on last run
883 bool delimited;
884 int stackToken;
885
886 State state;
887 void setDone(State s);
888 uint pos;
889 void shift(uint p);
890 int lookupKeyword(const char *);
891
892 bool isWhiteSpace() const;
893 bool isLineTerminator() const;
894 bool isHexDigit(ushort c) const;
895 bool isOctalDigit(ushort c) const;
896
897 int matchPunctuator(ushort c1, ushort c2,
898 ushort c3, ushort c4);
899 ushort singleEscape(ushort c) const;
900 ushort convertOctal(ushort c1, ushort c2,
901 ushort c3) const;
902public:
903 static unsigned char convertHex(ushort c1);
904 static unsigned char convertHex(ushort c1, ushort c2);
905 static QChar convertUnicode(ushort c1, ushort c2,
906 ushort c3, ushort c4);
907 static bool isIdentLetter(ushort c);
908 static bool isDecimalDigit(ushort c);
909
910 inline int ival() const { return qsyylval.toInt(); }
911 inline double dval() const { return qsyylval.toDouble(); }
912 inline QString ustr() const { return qsyylval.toString(); }
913 inline QVariant val() const { return qsyylval; }
914
915 const QChar *characterBuffer() const { return buffer16; }
916 int characterCount() const { return pos16; }
917
918private:
919 void record8(ushort c);
920 void record16(QChar c);
921 void recordStartPos();
922
923 int findReservedWord(const QChar *buffer, int size) const;
924
925 void syncProhibitAutomaticSemicolon();
926
927 const QChar *code;
928 uint length;
929 int yycolumn;
930 int startlineno;
931 int startcolumn;
932 int bol; // begin of line
933
934 QVariant qsyylval;
935
936 // current and following unicode characters
937 ushort current, next1, next2, next3;
938
939 struct keyword {
940 const char *name;
941 int token;
942 };
943
944 QString errmsg;
945 Error err;
946
947 bool wantRx;
948 bool check_reserved;
949
950 ParenthesesState parenthesesState;
951 int parenthesesCount;
952 bool prohibitAutomaticSemicolon;
953};
954
955} // namespace QScript
956
957extern double qstrtod(const char *s00, char const **se, bool *ok);
958
959#define shiftWindowsLineBreak() if(current == '\r' && next1 == '\n') shift(1);
960
961namespace QScript {
962
963static int toDigit(char c)
964{
965 if ((c >= '0') && (c <= '9'))
966 return c - '0';
967 else if ((c >= 'a') && (c <= 'z'))
968 return 10 + c - 'a';
969 else if ((c >= 'A') && (c <= 'Z'))
970 return 10 + c - 'A';
971 return -1;
972}
973
974double integerFromString(const char *buf, int size, int radix)
975{
976 if (size == 0)
977 return qSNaN();
978
979 double sign = 1.0;
980 int i = 0;
981 if (buf[0] == '+') {
982 ++i;
983 } else if (buf[0] == '-') {
984 sign = -1.0;
985 ++i;
986 }
987
988 if (((size-i) >= 2) && (buf[i] == '0')) {
989 if (((buf[i+1] == 'x') || (buf[i+1] == 'X'))
990 && (radix < 34)) {
991 if ((radix != 0) && (radix != 16))
992 return 0;
993 radix = 16;
994 i += 2;
995 } else {
996 if (radix == 0) {
997 radix = 8;
998 ++i;
999 }
1000 }
1001 } else if (radix == 0) {
1002 radix = 10;
1003 }
1004
1005 int j = i;
1006 for ( ; i < size; ++i) {
1007 int d = toDigit(buf[i]);
1008 if ((d == -1) || (d >= radix))
1009 break;
1010 }
1011 double result;
1012 if (j == i) {
1013 if (!qstrcmp(buf, "Infinity"))
1014 result = qInf();
1015 else
1016 result = qSNaN();
1017 } else {
1018 result = 0;
1019 double multiplier = 1;
1020 for (--i ; i >= j; --i, multiplier *= radix)
1021 result += toDigit(buf[i]) * multiplier;
1022 }
1023 result *= sign;
1024 return result;
1025}
1026
1027} // namespace QScript
1028
1029QScript::Lexer::Lexer()
1030 :
1031 yylineno(0),
1032 size8(128), size16(128), restrKeyword(false),
1033 stackToken(-1), pos(0),
1034 code(0), length(0),
1035 bol(true),
1036 current(0), next1(0), next2(0), next3(0),
1037 err(NoError),
1038 check_reserved(true),
1039 parenthesesState(IgnoreParentheses),
1040 prohibitAutomaticSemicolon(false)
1041{
1042 // allocate space for read buffers
1043 buffer8 = new char[size8];
1044 buffer16 = new QChar[size16];
1045 flags = 0;
1046
1047}
1048
1049QScript::Lexer::~Lexer()
1050{
1051 delete [] buffer8;
1052 delete [] buffer16;
1053}
1054
1055void QScript::Lexer::setCode(const QString &c, int lineno)
1056{
1057 errmsg = QString();
1058 yylineno = lineno;
1059 yycolumn = 1;
1060 restrKeyword = false;
1061 delimited = false;
1062 stackToken = -1;
1063 pos = 0;
1064 code = c.unicode();
1065 length = c.length();
1066 bol = true;
1067
1068 // read first characters
1069 current = (length > 0) ? code[0].unicode() : 0;
1070 next1 = (length > 1) ? code[1].unicode() : 0;
1071 next2 = (length > 2) ? code[2].unicode() : 0;
1072 next3 = (length > 3) ? code[3].unicode() : 0;
1073}
1074
1075void QScript::Lexer::shift(uint p)
1076{
1077 while (p--) {
1078 ++pos;
1079 ++yycolumn;
1080 current = next1;
1081 next1 = next2;
1082 next2 = next3;
1083 next3 = (pos + 3 < length) ? code[pos+3].unicode() : 0;
1084 }
1085}
1086
1087void QScript::Lexer::setDone(State s)
1088{
1089 state = s;
1090 done = true;
1091}
1092
1093int QScript::Lexer::findReservedWord(const QChar *c, int size) const
1094{
1095 switch (size) {
1096 case 2: {
1097 if (c[0] == QLatin1Char('d') && c[1] == QLatin1Char('o'))
1098 return QScriptGrammar::T_DO;
1099 else if (c[0] == QLatin1Char('i') && c[1] == QLatin1Char('f'))
1100 return QScriptGrammar::T_IF;
1101 else if (c[0] == QLatin1Char('i') && c[1] == QLatin1Char('n'))
1102 return QScriptGrammar::T_IN;
1103 } break;
1104
1105 case 3: {
1106 if (c[0] == QLatin1Char('f') && c[1] == QLatin1Char('o') && c[2] == QLatin1Char('r'))
1107 return QScriptGrammar::T_FOR;
1108 else if (c[0] == QLatin1Char('n') && c[1] == QLatin1Char('e') && c[2] == QLatin1Char('w'))
1109 return QScriptGrammar::T_NEW;
1110 else if (c[0] == QLatin1Char('t') && c[1] == QLatin1Char('r') && c[2] == QLatin1Char('y'))
1111 return QScriptGrammar::T_TRY;
1112 else if (c[0] == QLatin1Char('v') && c[1] == QLatin1Char('a') && c[2] == QLatin1Char('r'))
1113 return QScriptGrammar::T_VAR;
1114 else if (check_reserved) {
1115 if (c[0] == QLatin1Char('i') && c[1] == QLatin1Char('n') && c[2] == QLatin1Char('t'))
1116 return QScriptGrammar::T_RESERVED_WORD;
1117 }
1118 } break;
1119
1120 case 4: {
1121 if (c[0] == QLatin1Char('c') && c[1] == QLatin1Char('a')
1122 && c[2] == QLatin1Char('s') && c[3] == QLatin1Char('e'))
1123 return QScriptGrammar::T_CASE;
1124 else if (c[0] == QLatin1Char('e') && c[1] == QLatin1Char('l')
1125 && c[2] == QLatin1Char('s') && c[3] == QLatin1Char('e'))
1126 return QScriptGrammar::T_ELSE;
1127 else if (c[0] == QLatin1Char('t') && c[1] == QLatin1Char('h')
1128 && c[2] == QLatin1Char('i') && c[3] == QLatin1Char('s'))
1129 return QScriptGrammar::T_THIS;
1130 else if (c[0] == QLatin1Char('v') && c[1] == QLatin1Char('o')
1131 && c[2] == QLatin1Char('i') && c[3] == QLatin1Char('d'))
1132 return QScriptGrammar::T_VOID;
1133 else if (c[0] == QLatin1Char('w') && c[1] == QLatin1Char('i')
1134 && c[2] == QLatin1Char('t') && c[3] == QLatin1Char('h'))
1135 return QScriptGrammar::T_WITH;
1136 else if (c[0] == QLatin1Char('t') && c[1] == QLatin1Char('r')
1137 && c[2] == QLatin1Char('u') && c[3] == QLatin1Char('e'))
1138 return QScriptGrammar::T_TRUE;
1139 else if (c[0] == QLatin1Char('n') && c[1] == QLatin1Char('u')
1140 && c[2] == QLatin1Char('l') && c[3] == QLatin1Char('l'))
1141 return QScriptGrammar::T_NULL;
1142 else if (check_reserved) {
1143 if (c[0] == QLatin1Char('e') && c[1] == QLatin1Char('n')
1144 && c[2] == QLatin1Char('u') && c[3] == QLatin1Char('m'))
1145 return QScriptGrammar::T_RESERVED_WORD;
1146 else if (c[0] == QLatin1Char('b') && c[1] == QLatin1Char('y')
1147 && c[2] == QLatin1Char('t') && c[3] == QLatin1Char('e'))
1148 return QScriptGrammar::T_RESERVED_WORD;
1149 else if (c[0] == QLatin1Char('l') && c[1] == QLatin1Char('o')
1150 && c[2] == QLatin1Char('n') && c[3] == QLatin1Char('g'))
1151 return QScriptGrammar::T_RESERVED_WORD;
1152 else if (c[0] == QLatin1Char('c') && c[1] == QLatin1Char('h')
1153 && c[2] == QLatin1Char('a') && c[3] == QLatin1Char('r'))
1154 return QScriptGrammar::T_RESERVED_WORD;
1155 else if (c[0] == QLatin1Char('g') && c[1] == QLatin1Char('o')
1156 && c[2] == QLatin1Char('t') && c[3] == QLatin1Char('o'))
1157 return QScriptGrammar::T_RESERVED_WORD;
1158 }
1159 } break;
1160
1161 case 5: {
1162 if (c[0] == QLatin1Char('b') && c[1] == QLatin1Char('r')
1163 && c[2] == QLatin1Char('e') && c[3] == QLatin1Char('a')
1164 && c[4] == QLatin1Char('k'))
1165 return QScriptGrammar::T_BREAK;
1166 else if (c[0] == QLatin1Char('c') && c[1] == QLatin1Char('a')
1167 && c[2] == QLatin1Char('t') && c[3] == QLatin1Char('c')
1168 && c[4] == QLatin1Char('h'))
1169 return QScriptGrammar::T_CATCH;
1170 else if (c[0] == QLatin1Char('t') && c[1] == QLatin1Char('h')
1171 && c[2] == QLatin1Char('r') && c[3] == QLatin1Char('o')
1172 && c[4] == QLatin1Char('w'))
1173 return QScriptGrammar::T_THROW;
1174 else if (c[0] == QLatin1Char('w') && c[1] == QLatin1Char('h')
1175 && c[2] == QLatin1Char('i') && c[3] == QLatin1Char('l')
1176 && c[4] == QLatin1Char('e'))
1177 return QScriptGrammar::T_WHILE;
1178 else if (c[0] == QLatin1Char('c') && c[1] == QLatin1Char('o')
1179 && c[2] == QLatin1Char('n') && c[3] == QLatin1Char('s')
1180 && c[4] == QLatin1Char('t'))
1181 return QScriptGrammar::T_CONST;
1182 else if (c[0] == QLatin1Char('f') && c[1] == QLatin1Char('a')
1183 && c[2] == QLatin1Char('l') && c[3] == QLatin1Char('s')
1184 && c[4] == QLatin1Char('e'))
1185 return QScriptGrammar::T_FALSE;
1186 else if (check_reserved) {
1187 if (c[0] == QLatin1Char('s') && c[1] == QLatin1Char('h')
1188 && c[2] == QLatin1Char('o') && c[3] == QLatin1Char('r')
1189 && c[4] == QLatin1Char('t'))
1190 return QScriptGrammar::T_RESERVED_WORD;
1191 else if (c[0] == QLatin1Char('s') && c[1] == QLatin1Char('u')
1192 && c[2] == QLatin1Char('p') && c[3] == QLatin1Char('e')
1193 && c[4] == QLatin1Char('r'))
1194 return QScriptGrammar::T_RESERVED_WORD;
1195 else if (c[0] == QLatin1Char('f') && c[1] == QLatin1Char('i')
1196 && c[2] == QLatin1Char('n') && c[3] == QLatin1Char('a')
1197 && c[4] == QLatin1Char('l'))
1198 return QScriptGrammar::T_RESERVED_WORD;
1199 else if (c[0] == QLatin1Char('c') && c[1] == QLatin1Char('l')
1200 && c[2] == QLatin1Char('a') && c[3] == QLatin1Char('s')
1201 && c[4] == QLatin1Char('s'))
1202 return QScriptGrammar::T_RESERVED_WORD;
1203 else if (c[0] == QLatin1Char('f') && c[1] == QLatin1Char('l')
1204 && c[2] == QLatin1Char('o') && c[3] == QLatin1Char('a')
1205 && c[4] == QLatin1Char('t'))
1206 return QScriptGrammar::T_RESERVED_WORD;
1207 }
1208 } break;
1209
1210 case 6: {
1211 if (c[0] == QLatin1Char('d') && c[1] == QLatin1Char('e')
1212 && c[2] == QLatin1Char('l') && c[3] == QLatin1Char('e')
1213 && c[4] == QLatin1Char('t') && c[5] == QLatin1Char('e'))
1214 return QScriptGrammar::T_DELETE;
1215 else if (c[0] == QLatin1Char('r') && c[1] == QLatin1Char('e')
1216 && c[2] == QLatin1Char('t') && c[3] == QLatin1Char('u')
1217 && c[4] == QLatin1Char('r') && c[5] == QLatin1Char('n'))
1218 return QScriptGrammar::T_RETURN;
1219 else if (c[0] == QLatin1Char('s') && c[1] == QLatin1Char('w')
1220 && c[2] == QLatin1Char('i') && c[3] == QLatin1Char('t')
1221 && c[4] == QLatin1Char('c') && c[5] == QLatin1Char('h'))
1222 return QScriptGrammar::T_SWITCH;
1223 else if (c[0] == QLatin1Char('t') && c[1] == QLatin1Char('y')
1224 && c[2] == QLatin1Char('p') && c[3] == QLatin1Char('e')
1225 && c[4] == QLatin1Char('o') && c[5] == QLatin1Char('f'))
1226 return QScriptGrammar::T_TYPEOF;
1227 else if (check_reserved) {
1228 if (c[0] == QLatin1Char('e') && c[1] == QLatin1Char('x')
1229 && c[2] == QLatin1Char('p') && c[3] == QLatin1Char('o')
1230 && c[4] == QLatin1Char('r') && c[5] == QLatin1Char('t'))
1231 return QScriptGrammar::T_RESERVED_WORD;
1232 else if (c[0] == QLatin1Char('s') && c[1] == QLatin1Char('t')
1233 && c[2] == QLatin1Char('a') && c[3] == QLatin1Char('t')
1234 && c[4] == QLatin1Char('i') && c[5] == QLatin1Char('c'))
1235 return QScriptGrammar::T_RESERVED_WORD;
1236 else if (c[0] == QLatin1Char('d') && c[1] == QLatin1Char('o')
1237 && c[2] == QLatin1Char('u') && c[3] == QLatin1Char('b')
1238 && c[4] == QLatin1Char('l') && c[5] == QLatin1Char('e'))
1239 return QScriptGrammar::T_RESERVED_WORD;
1240 else if (c[0] == QLatin1Char('i') && c[1] == QLatin1Char('m')
1241 && c[2] == QLatin1Char('p') && c[3] == QLatin1Char('o')
1242 && c[4] == QLatin1Char('r') && c[5] == QLatin1Char('t'))
1243 return QScriptGrammar::T_RESERVED_WORD;
1244 else if (c[0] == QLatin1Char('p') && c[1] == QLatin1Char('u')
1245 && c[2] == QLatin1Char('b') && c[3] == QLatin1Char('l')
1246 && c[4] == QLatin1Char('i') && c[5] == QLatin1Char('c'))
1247 return QScriptGrammar::T_RESERVED_WORD;
1248 else if (c[0] == QLatin1Char('n') && c[1] == QLatin1Char('a')
1249 && c[2] == QLatin1Char('t') && c[3] == QLatin1Char('i')
1250 && c[4] == QLatin1Char('v') && c[5] == QLatin1Char('e'))
1251 return QScriptGrammar::T_RESERVED_WORD;
1252 else if (c[0] == QLatin1Char('t') && c[1] == QLatin1Char('h')
1253 && c[2] == QLatin1Char('r') && c[3] == QLatin1Char('o')
1254 && c[4] == QLatin1Char('w') && c[5] == QLatin1Char('s'))
1255 return QScriptGrammar::T_RESERVED_WORD;
1256 }
1257 } break;
1258
1259 case 7: {
1260 if (c[0] == QLatin1Char('d') && c[1] == QLatin1Char('e')
1261 && c[2] == QLatin1Char('f') && c[3] == QLatin1Char('a')
1262 && c[4] == QLatin1Char('u') && c[5] == QLatin1Char('l')
1263 && c[6] == QLatin1Char('t'))
1264 return QScriptGrammar::T_DEFAULT;
1265 else if (c[0] == QLatin1Char('f') && c[1] == QLatin1Char('i')
1266 && c[2] == QLatin1Char('n') && c[3] == QLatin1Char('a')
1267 && c[4] == QLatin1Char('l') && c[5] == QLatin1Char('l')
1268 && c[6] == QLatin1Char('y'))
1269 return QScriptGrammar::T_FINALLY;
1270 else if (check_reserved) {
1271 if (c[0] == QLatin1Char('b') && c[1] == QLatin1Char('o')
1272 && c[2] == QLatin1Char('o') && c[3] == QLatin1Char('l')
1273 && c[4] == QLatin1Char('e') && c[5] == QLatin1Char('a')
1274 && c[6] == QLatin1Char('n'))
1275 return QScriptGrammar::T_RESERVED_WORD;
1276 else if (c[0] == QLatin1Char('e') && c[1] == QLatin1Char('x')
1277 && c[2] == QLatin1Char('t') && c[3] == QLatin1Char('e')
1278 && c[4] == QLatin1Char('n') && c[5] == QLatin1Char('d')
1279 && c[6] == QLatin1Char('s'))
1280 return QScriptGrammar::T_RESERVED_WORD;
1281 else if (c[0] == QLatin1Char('p') && c[1] == QLatin1Char('a')
1282 && c[2] == QLatin1Char('c') && c[3] == QLatin1Char('k')
1283 && c[4] == QLatin1Char('a') && c[5] == QLatin1Char('g')
1284 && c[6] == QLatin1Char('e'))
1285 return QScriptGrammar::T_RESERVED_WORD;
1286 else if (c[0] == QLatin1Char('p') && c[1] == QLatin1Char('r')
1287 && c[2] == QLatin1Char('i') && c[3] == QLatin1Char('v')
1288 && c[4] == QLatin1Char('a') && c[5] == QLatin1Char('t')
1289 && c[6] == QLatin1Char('e'))
1290 return QScriptGrammar::T_RESERVED_WORD;
1291 }
1292 } break;
1293
1294 case 8: {
1295 if (c[0] == QLatin1Char('c') && c[1] == QLatin1Char('o')
1296 && c[2] == QLatin1Char('n') && c[3] == QLatin1Char('t')
1297 && c[4] == QLatin1Char('i') && c[5] == QLatin1Char('n')
1298 && c[6] == QLatin1Char('u') && c[7] == QLatin1Char('e'))
1299 return QScriptGrammar::T_CONTINUE;
1300 else if (c[0] == QLatin1Char('f') && c[1] == QLatin1Char('u')
1301 && c[2] == QLatin1Char('n') && c[3] == QLatin1Char('c')
1302 && c[4] == QLatin1Char('t') && c[5] == QLatin1Char('i')
1303 && c[6] == QLatin1Char('o') && c[7] == QLatin1Char('n'))
1304 return QScriptGrammar::T_FUNCTION;
1305 else if (c[0] == QLatin1Char('d') && c[1] == QLatin1Char('e')
1306 && c[2] == QLatin1Char('b') && c[3] == QLatin1Char('u')
1307 && c[4] == QLatin1Char('g') && c[5] == QLatin1Char('g')
1308 && c[6] == QLatin1Char('e') && c[7] == QLatin1Char('r'))
1309 return QScriptGrammar::T_DEBUGGER;
1310 else if (check_reserved) {
1311 if (c[0] == QLatin1Char('a') && c[1] == QLatin1Char('b')
1312 && c[2] == QLatin1Char('s') && c[3] == QLatin1Char('t')
1313 && c[4] == QLatin1Char('r') && c[5] == QLatin1Char('a')
1314 && c[6] == QLatin1Char('c') && c[7] == QLatin1Char('t'))
1315 return QScriptGrammar::T_RESERVED_WORD;
1316 else if (c[0] == QLatin1Char('v') && c[1] == QLatin1Char('o')
1317 && c[2] == QLatin1Char('l') && c[3] == QLatin1Char('a')
1318 && c[4] == QLatin1Char('t') && c[5] == QLatin1Char('i')
1319 && c[6] == QLatin1Char('l') && c[7] == QLatin1Char('e'))
1320 return QScriptGrammar::T_RESERVED_WORD;
1321 }
1322 } break;
1323
1324 case 9: {
1325 if (check_reserved) {
1326 if (c[0] == QLatin1Char('i') && c[1] == QLatin1Char('n')
1327 && c[2] == QLatin1Char('t') && c[3] == QLatin1Char('e')
1328 && c[4] == QLatin1Char('r') && c[5] == QLatin1Char('f')
1329 && c[6] == QLatin1Char('a') && c[7] == QLatin1Char('c')
1330 && c[8] == QLatin1Char('e'))
1331 return QScriptGrammar::T_RESERVED_WORD;
1332 else if (c[0] == QLatin1Char('t') && c[1] == QLatin1Char('r')
1333 && c[2] == QLatin1Char('a') && c[3] == QLatin1Char('n')
1334 && c[4] == QLatin1Char('s') && c[5] == QLatin1Char('i')
1335 && c[6] == QLatin1Char('e') && c[7] == QLatin1Char('n')
1336 && c[8] == QLatin1Char('t'))
1337 return QScriptGrammar::T_RESERVED_WORD;
1338 else if (c[0] == QLatin1Char('p') && c[1] == QLatin1Char('r')
1339 && c[2] == QLatin1Char('o') && c[3] == QLatin1Char('t')
1340 && c[4] == QLatin1Char('e') && c[5] == QLatin1Char('c')
1341 && c[6] == QLatin1Char('t') && c[7] == QLatin1Char('e')
1342 && c[8] == QLatin1Char('d'))
1343 return QScriptGrammar::T_RESERVED_WORD;
1344 }
1345 } break;
1346
1347 case 10: {
1348 if (c[0] == QLatin1Char('i') && c[1] == QLatin1Char('n')
1349 && c[2] == QLatin1Char('s') && c[3] == QLatin1Char('t')
1350 && c[4] == QLatin1Char('a') && c[5] == QLatin1Char('n')
1351 && c[6] == QLatin1Char('c') && c[7] == QLatin1Char('e')
1352 && c[8] == QLatin1Char('o') && c[9] == QLatin1Char('f'))
1353 return QScriptGrammar::T_INSTANCEOF;
1354 else if (check_reserved) {
1355 if (c[0] == QLatin1Char('i') && c[1] == QLatin1Char('m')
1356 && c[2] == QLatin1Char('p') && c[3] == QLatin1Char('l')
1357 && c[4] == QLatin1Char('e') && c[5] == QLatin1Char('m')
1358 && c[6] == QLatin1Char('e') && c[7] == QLatin1Char('n')
1359 && c[8] == QLatin1Char('t') && c[9] == QLatin1Char('s'))
1360 return QScriptGrammar::T_RESERVED_WORD;
1361 }
1362 } break;
1363
1364 case 12: {
1365 if (check_reserved) {
1366 if (c[0] == QLatin1Char('s') && c[1] == QLatin1Char('y')
1367 && c[2] == QLatin1Char('n') && c[3] == QLatin1Char('c')
1368 && c[4] == QLatin1Char('h') && c[5] == QLatin1Char('r')
1369 && c[6] == QLatin1Char('o') && c[7] == QLatin1Char('n')
1370 && c[8] == QLatin1Char('i') && c[9] == QLatin1Char('z')
1371 && c[10] == QLatin1Char('e') && c[11] == QLatin1Char('d'))
1372 return QScriptGrammar::T_RESERVED_WORD;
1373 }
1374 } break;
1375
1376 } // switch
1377
1378 return -1;
1379}
1380
1381int QScript::Lexer::lex()
1382{
1383 int token = 0;
1384 state = Start;
1385 ushort stringType = 0; // either single or double quotes
1386 pos8 = pos16 = 0;
1387 done = false;
1388 terminator = false;
1389
1390 // did we push a token on the stack previously ?
1391 // (after an automatic semicolon insertion)
1392 if (stackToken >= 0) {
1393 setDone(Other);
1394 token = stackToken;
1395 stackToken = -1;
1396 }
1397
1398 while (!done) {
1399 switch (state) {
1400 case Start:
1401 if (isWhiteSpace()) {
1402 // do nothing
1403 } else if (current == '/' && next1 == '/') {
1404 recordStartPos();
1405 shift(1);
1406 state = InSingleLineComment;
1407 } else if (current == '/' && next1 == '*') {
1408 recordStartPos();
1409 shift(1);
1410 state = InMultiLineComment;
1411 } else if (current == 0) {
1412 syncProhibitAutomaticSemicolon();
1413 if (!terminator && !delimited && !prohibitAutomaticSemicolon) {
1414 // automatic semicolon insertion if program incomplete
1415 token = QScriptGrammar::T_SEMICOLON;
1416 stackToken = 0;
1417 setDone(Other);
1418 } else {
1419 setDone(Eof);
1420 }
1421 } else if (isLineTerminator()) {
1422 shiftWindowsLineBreak();
1423 yylineno++;
1424 yycolumn = 0;
1425 bol = true;
1426 terminator = true;
1427 syncProhibitAutomaticSemicolon();
1428 if (restrKeyword) {
1429 token = QScriptGrammar::T_SEMICOLON;
1430 setDone(Other);
1431 }
1432 } else if (current == '"' || current == '\'') {
1433 recordStartPos();
1434 state = InString;
1435 stringType = current;
1436 } else if (isIdentLetter(current)) {
1437 recordStartPos();
1438 record16(current);
1439 state = InIdentifier;
1440 } else if (current == '0') {
1441 recordStartPos();
1442 record8(current);
1443 state = InNum0;
1444 } else if (isDecimalDigit(current)) {
1445 recordStartPos();
1446 record8(current);
1447 state = InNum;
1448 } else if (current == '.' && isDecimalDigit(next1)) {
1449 recordStartPos();
1450 record8(current);
1451 state = InDecimal;
1452 } else {
1453 recordStartPos();
1454 token = matchPunctuator(current, next1, next2, next3);
1455 if (token != -1) {
1456 if (terminator && !delimited && !prohibitAutomaticSemicolon
1457 && (token == QScriptGrammar::T_PLUS_PLUS
1458 || token == QScriptGrammar::T_MINUS_MINUS)) {
1459 // automatic semicolon insertion
1460 stackToken = token;
1461 token = QScriptGrammar::T_SEMICOLON;
1462 }
1463 setDone(Other);
1464 }
1465 else {
1466 setDone(Bad);
1467 err = IllegalCharacter;
1468 errmsg = QLatin1String("Illegal character");
1469 }
1470 }
1471 break;
1472 case InString:
1473 if (current == stringType) {
1474 shift(1);
1475 setDone(String);
1476 } else if (current == 0 || isLineTerminator()) {
1477 setDone(Bad);
1478 err = UnclosedStringLiteral;
1479 errmsg = QLatin1String("Unclosed string at end of line");
1480 } else if (current == '\\') {
1481 state = InEscapeSequence;
1482 } else {
1483 record16(current);
1484 }
1485 break;
1486 // Escape Sequences inside of strings
1487 case InEscapeSequence:
1488 if (isOctalDigit(current)) {
1489 if (current >= '0' && current <= '3' &&
1490 isOctalDigit(next1) && isOctalDigit(next2)) {
1491 record16(convertOctal(current, next1, next2));
1492 shift(2);
1493 state = InString;
1494 } else if (isOctalDigit(current) &&
1495 isOctalDigit(next1)) {
1496 record16(convertOctal('0', current, next1));
1497 shift(1);
1498 state = InString;
1499 } else if (isOctalDigit(current)) {
1500 record16(convertOctal('0', '0', current));
1501 state = InString;
1502 } else {
1503 setDone(Bad);
1504 err = IllegalEscapeSequence;
1505 errmsg = QLatin1String("Illegal escape squence");
1506 }
1507 } else if (current == 'x')
1508 state = InHexEscape;
1509 else if (current == 'u')
1510 state = InUnicodeEscape;
1511 else {
1512 record16(singleEscape(current));
1513 state = InString;
1514 }
1515 break;
1516 case InHexEscape:
1517 if (isHexDigit(current) && isHexDigit(next1)) {
1518 state = InString;
1519 record16(QLatin1Char(convertHex(current, next1)));
1520 shift(1);
1521 } else if (current == stringType) {
1522 record16(QLatin1Char('x'));
1523 shift(1);
1524 setDone(String);
1525 } else {
1526 record16(QLatin1Char('x'));
1527 record16(current);
1528 state = InString;
1529 }
1530 break;
1531 case InUnicodeEscape:
1532 if (isHexDigit(current) && isHexDigit(next1) &&
1533 isHexDigit(next2) && isHexDigit(next3)) {
1534 record16(convertUnicode(current, next1, next2, next3));
1535 shift(3);
1536 state = InString;
1537 } else if (current == stringType) {
1538 record16(QLatin1Char('u'));
1539 shift(1);
1540 setDone(String);
1541 } else {
1542 setDone(Bad);
1543 err = IllegalUnicodeEscapeSequence;
1544 errmsg = QLatin1String("Illegal unicode escape sequence");
1545 }
1546 break;
1547 case InSingleLineComment:
1548 if (isLineTerminator()) {
1549 shiftWindowsLineBreak();
1550 yylineno++;
1551 yycolumn = 0;
1552 terminator = true;
1553 bol = true;
1554 if (restrKeyword) {
1555 token = QScriptGrammar::T_SEMICOLON;
1556 setDone(Other);
1557 } else
1558 state = Start;
1559 } else if (current == 0) {
1560 setDone(Eof);
1561 }
1562 break;
1563 case InMultiLineComment:
1564 if (current == 0) {
1565 setDone(Bad);
1566 err = UnclosedComment;
1567 errmsg = QLatin1String("Unclosed comment at end of file");
1568 } else if (isLineTerminator()) {
1569 shiftWindowsLineBreak();
1570 yylineno++;
1571 } else if (current == '*' && next1 == '/') {
1572 state = Start;
1573 shift(1);
1574 }
1575 break;
1576 case InIdentifier:
1577 if (isIdentLetter(current) || isDecimalDigit(current)) {
1578 record16(current);
1579 break;
1580 }
1581 setDone(Identifier);
1582 break;
1583 case InNum0:
1584 if (current == 'x' || current == 'X') {
1585 record8(current);
1586 state = InHex;
1587 } else if (current == '.') {
1588 record8(current);
1589 state = InDecimal;
1590 } else if (current == 'e' || current == 'E') {
1591 record8(current);
1592 state = InExponentIndicator;
1593 } else if (isOctalDigit(current)) {
1594 record8(current);
1595 state = InOctal;
1596 } else if (isDecimalDigit(current)) {
1597 record8(current);
1598 state = InDecimal;
1599 } else {
1600 setDone(Number);
1601 }
1602 break;
1603 case InHex:
1604 if (isHexDigit(current))
1605 record8(current);
1606 else
1607 setDone(Hex);
1608 break;
1609 case InOctal:
1610 if (isOctalDigit(current)) {
1611 record8(current);
1612 } else if (isDecimalDigit(current)) {
1613 record8(current);
1614 state = InDecimal;
1615 } else {
1616 setDone(Octal);
1617 }
1618 break;
1619 case InNum:
1620 if (isDecimalDigit(current)) {
1621 record8(current);
1622 } else if (current == '.') {
1623 record8(current);
1624 state = InDecimal;
1625 } else if (current == 'e' || current == 'E') {
1626 record8(current);
1627 state = InExponentIndicator;
1628 } else {
1629 setDone(Number);
1630 }
1631 break;
1632 case InDecimal:
1633 if (isDecimalDigit(current)) {
1634 record8(current);
1635 } else if (current == 'e' || current == 'E') {
1636 record8(current);
1637 state = InExponentIndicator;
1638 } else {
1639 setDone(Number);
1640 }
1641 break;
1642 case InExponentIndicator:
1643 if (current == '+' || current == '-') {
1644 record8(current);
1645 } else if (isDecimalDigit(current)) {
1646 record8(current);
1647 state = InExponent;
1648 } else {
1649 setDone(Bad);
1650 err = IllegalExponentIndicator;
1651 errmsg = QLatin1String("Illegal syntax for exponential number");
1652 }
1653 break;
1654 case InExponent:
1655 if (isDecimalDigit(current)) {
1656 record8(current);
1657 } else {
1658 setDone(Number);
1659 }
1660 break;
1661 default:
1662 Q_ASSERT_X(0, "Lexer::lex", "Unhandled state in switch statement");
1663 }
1664
1665 // move on to the next character
1666 if (!done)
1667 shift(1);
1668 if (state != Start && state != InSingleLineComment)
1669 bol = false;
1670 }
1671
1672 // no identifiers allowed directly after numeric literal, e.g. "3in" is bad
1673 if ((state == Number || state == Octal || state == Hex)
1674 && isIdentLetter(current)) {
1675 state = Bad;
1676 err = IllegalIdentifier;
1677 errmsg = QLatin1String("Identifier cannot start with numeric literal");
1678 }
1679
1680 // terminate string
1681 buffer8[pos8] = '\0';
1682
1683 double dval = 0;
1684 if (state == Number) {
1685 dval = qstrtod(buffer8, 0, 0);
1686 } else if (state == Hex) { // scan hex numbers
1687 dval = QScript::integerFromString(buffer8, pos8, 16);
1688 state = Number;
1689 } else if (state == Octal) { // scan octal number
1690 dval = QScript::integerFromString(buffer8, pos8, 8);
1691 state = Number;
1692 }
1693
1694 restrKeyword = false;
1695 delimited = false;
1696
1697 switch (parenthesesState) {
1698 case IgnoreParentheses:
1699 break;
1700 case CountParentheses:
1701 if (token == QScriptGrammar::T_RPAREN) {
1702 --parenthesesCount;
1703 if (parenthesesCount == 0)
1704 parenthesesState = BalancedParentheses;
1705 } else if (token == QScriptGrammar::T_LPAREN) {
1706 ++parenthesesCount;
1707 }
1708 break;
1709 case BalancedParentheses:
1710 parenthesesState = IgnoreParentheses;
1711 break;
1712 }
1713
1714 switch (state) {
1715 case Eof:
1716 return 0;
1717 case Other:
1718 if(token == QScriptGrammar::T_RBRACE || token == QScriptGrammar::T_SEMICOLON)
1719 delimited = true;
1720 return token;
1721 case Identifier:
1722 if ((token = findReservedWord(buffer16, pos16)) < 0) {
1723 /* TODO: close leak on parse error. same holds true for String */
1724 qsyylval = QString(buffer16, pos16);
1725 return QScriptGrammar::T_IDENTIFIER;
1726 }
1727 if (token == QScriptGrammar::T_CONTINUE || token == QScriptGrammar::T_BREAK
1728 || token == QScriptGrammar::T_RETURN || token == QScriptGrammar::T_THROW) {
1729 restrKeyword = true;
1730 } else if (token == QScriptGrammar::T_IF || token == QScriptGrammar::T_FOR
1731 || token == QScriptGrammar::T_WHILE || token == QScriptGrammar::T_WITH) {
1732 parenthesesState = CountParentheses;
1733 parenthesesCount = 0;
1734 } else if (token == QScriptGrammar::T_DO) {
1735 parenthesesState = BalancedParentheses;
1736 }
1737 return token;
1738 case String:
1739 qsyylval = QString(buffer16, pos16);
1740 return QScriptGrammar::T_STRING_LITERAL;
1741 case Number:
1742 qsyylval = dval;
1743 return QScriptGrammar::T_NUMERIC_LITERAL;
1744 case Bad:
1745 return -1;
1746 default:
1747 Q_ASSERT(!"unhandled numeration value in switch");
1748 return -1;
1749 }
1750}
1751
1752bool QScript::Lexer::isWhiteSpace() const
1753{
1754 return (current == ' ' || current == '\t' ||
1755 current == 0x0b || current == 0x0c);
1756}
1757
1758bool QScript::Lexer::isLineTerminator() const
1759{
1760 return (current == '\n' || current == '\r');
1761}
1762
1763bool QScript::Lexer::isIdentLetter(ushort c)
1764{
1765 /* TODO: allow other legitimate unicode chars */
1766 return ((c >= 'a' && c <= 'z')
1767 || (c >= 'A' && c <= 'Z')
1768 || c == '$'
1769 || c == '_');
1770}
1771
1772bool QScript::Lexer::isDecimalDigit(ushort c)
1773{
1774 return (c >= '0' && c <= '9');
1775}
1776
1777bool QScript::Lexer::isHexDigit(ushort c) const
1778{
1779 return ((c >= '0' && c <= '9')
1780 || (c >= 'a' && c <= 'f')
1781 || (c >= 'A' && c <= 'F'));
1782}
1783
1784bool QScript::Lexer::isOctalDigit(ushort c) const
1785{
1786 return (c >= '0' && c <= '7');
1787}
1788
1789int QScript::Lexer::matchPunctuator(ushort c1, ushort c2,
1790 ushort c3, ushort c4)
1791{
1792 if (c1 == '>' && c2 == '>' && c3 == '>' && c4 == '=') {
1793 shift(4);
1794 return QScriptGrammar::T_GT_GT_GT_EQ;
1795 } else if (c1 == '=' && c2 == '=' && c3 == '=') {
1796 shift(3);
1797 return QScriptGrammar::T_EQ_EQ_EQ;
1798 } else if (c1 == '!' && c2 == '=' && c3 == '=') {
1799 shift(3);
1800 return QScriptGrammar::T_NOT_EQ_EQ;
1801 } else if (c1 == '>' && c2 == '>' && c3 == '>') {
1802 shift(3);
1803 return QScriptGrammar::T_GT_GT_GT;
1804 } else if (c1 == '<' && c2 == '<' && c3 == '=') {
1805 shift(3);
1806 return QScriptGrammar::T_LT_LT_EQ;
1807 } else if (c1 == '>' && c2 == '>' && c3 == '=') {
1808 shift(3);
1809 return QScriptGrammar::T_GT_GT_EQ;
1810 } else if (c1 == '<' && c2 == '=') {
1811 shift(2);
1812 return QScriptGrammar::T_LE;
1813 } else if (c1 == '>' && c2 == '=') {
1814 shift(2);
1815 return QScriptGrammar::T_GE;
1816 } else if (c1 == '!' && c2 == '=') {
1817 shift(2);
1818 return QScriptGrammar::T_NOT_EQ;
1819 } else if (c1 == '+' && c2 == '+') {
1820 shift(2);
1821 return QScriptGrammar::T_PLUS_PLUS;
1822 } else if (c1 == '-' && c2 == '-') {
1823 shift(2);
1824 return QScriptGrammar::T_MINUS_MINUS;
1825 } else if (c1 == '=' && c2 == '=') {
1826 shift(2);
1827 return QScriptGrammar::T_EQ_EQ;
1828 } else if (c1 == '+' && c2 == '=') {
1829 shift(2);
1830 return QScriptGrammar::T_PLUS_EQ;
1831 } else if (c1 == '-' && c2 == '=') {
1832 shift(2);
1833 return QScriptGrammar::T_MINUS_EQ;
1834 } else if (c1 == '*' && c2 == '=') {
1835 shift(2);
1836 return QScriptGrammar::T_STAR_EQ;
1837 } else if (c1 == '/' && c2 == '=') {
1838 shift(2);
1839 return QScriptGrammar::T_DIVIDE_EQ;
1840 } else if (c1 == '&' && c2 == '=') {
1841 shift(2);
1842 return QScriptGrammar::T_AND_EQ;
1843 } else if (c1 == '^' && c2 == '=') {
1844 shift(2);
1845 return QScriptGrammar::T_XOR_EQ;
1846 } else if (c1 == '%' && c2 == '=') {
1847 shift(2);
1848 return QScriptGrammar::T_REMAINDER_EQ;
1849 } else if (c1 == '|' && c2 == '=') {
1850 shift(2);
1851 return QScriptGrammar::T_OR_EQ;
1852 } else if (c1 == '<' && c2 == '<') {
1853 shift(2);
1854 return QScriptGrammar::T_LT_LT;
1855 } else if (c1 == '>' && c2 == '>') {
1856 shift(2);
1857 return QScriptGrammar::T_GT_GT;
1858 } else if (c1 == '&' && c2 == '&') {
1859 shift(2);
1860 return QScriptGrammar::T_AND_AND;
1861 } else if (c1 == '|' && c2 == '|') {
1862 shift(2);
1863 return QScriptGrammar::T_OR_OR;
1864 }
1865
1866 switch(c1) {
1867 case '=': shift(1); return QScriptGrammar::T_EQ;
1868 case '>': shift(1); return QScriptGrammar::T_GT;
1869 case '<': shift(1); return QScriptGrammar::T_LT;
1870 case ',': shift(1); return QScriptGrammar::T_COMMA;
1871 case '!': shift(1); return QScriptGrammar::T_NOT;
1872 case '~': shift(1); return QScriptGrammar::T_TILDE;
1873 case '?': shift(1); return QScriptGrammar::T_QUESTION;
1874 case ':': shift(1); return QScriptGrammar::T_COLON;
1875 case '.': shift(1); return QScriptGrammar::T_DOT;
1876 case '+': shift(1); return QScriptGrammar::T_PLUS;
1877 case '-': shift(1); return QScriptGrammar::T_MINUS;
1878 case '*': shift(1); return QScriptGrammar::T_STAR;
1879 case '/': shift(1); return QScriptGrammar::T_DIVIDE_;
1880 case '&': shift(1); return QScriptGrammar::T_AND;
1881 case '|': shift(1); return QScriptGrammar::T_OR;
1882 case '^': shift(1); return QScriptGrammar::T_XOR;
1883 case '%': shift(1); return QScriptGrammar::T_REMAINDER;
1884 case '(': shift(1); return QScriptGrammar::T_LPAREN;
1885 case ')': shift(1); return QScriptGrammar::T_RPAREN;
1886 case '{': shift(1); return QScriptGrammar::T_LBRACE;
1887 case '}': shift(1); return QScriptGrammar::T_RBRACE;
1888 case '[': shift(1); return QScriptGrammar::T_LBRACKET;
1889 case ']': shift(1); return QScriptGrammar::T_RBRACKET;
1890 case ';': shift(1); return QScriptGrammar::T_SEMICOLON;
1891
1892 default: return -1;
1893 }
1894}
1895
1896ushort QScript::Lexer::singleEscape(ushort c) const
1897{
1898 switch(c) {
1899 case 'b':
1900 return 0x08;
1901 case 't':
1902 return 0x09;
1903 case 'n':
1904 return 0x0A;
1905 case 'v':
1906 return 0x0B;
1907 case 'f':
1908 return 0x0C;
1909 case 'r':
1910 return 0x0D;
1911 case '"':
1912 return 0x22;
1913 case '\'':
1914 return 0x27;
1915 case '\\':
1916 return 0x5C;
1917 default:
1918 return c;
1919 }
1920}
1921
1922ushort QScript::Lexer::convertOctal(ushort c1, ushort c2,
1923 ushort c3) const
1924{
1925 return ((c1 - '0') * 64 + (c2 - '0') * 8 + c3 - '0');
1926}
1927
1928unsigned char QScript::Lexer::convertHex(ushort c)
1929{
1930 if (c >= '0' && c <= '9')
1931 return (c - '0');
1932 else if (c >= 'a' && c <= 'f')
1933 return (c - 'a' + 10);
1934 else
1935 return (c - 'A' + 10);
1936}
1937
1938unsigned char QScript::Lexer::convertHex(ushort c1, ushort c2)
1939{
1940 return ((convertHex(c1) << 4) + convertHex(c2));
1941}
1942
1943QChar QScript::Lexer::convertUnicode(ushort c1, ushort c2,
1944 ushort c3, ushort c4)
1945{
1946 return QChar((convertHex(c3) << 4) + convertHex(c4),
1947 (convertHex(c1) << 4) + convertHex(c2));
1948}
1949
1950void QScript::Lexer::record8(ushort c)
1951{
1952 Q_ASSERT(c <= 0xff);
1953
1954 // enlarge buffer if full
1955 if (pos8 >= size8 - 1) {
1956 char *tmp = new char[2 * size8];
1957 memcpy(tmp, buffer8, size8 * sizeof(char));
1958 delete [] buffer8;
1959 buffer8 = tmp;
1960 size8 *= 2;
1961 }
1962
1963 buffer8[pos8++] = (char) c;
1964}
1965
1966void QScript::Lexer::record16(QChar c)
1967{
1968 // enlarge buffer if full
1969 if (pos16 >= size16 - 1) {
1970 QChar *tmp = new QChar[2 * size16];
1971 memcpy(tmp, buffer16, size16 * sizeof(QChar));
1972 delete [] buffer16;
1973 buffer16 = tmp;
1974 size16 *= 2;
1975 }
1976
1977 buffer16[pos16++] = c;
1978}
1979
1980void QScript::Lexer::recordStartPos()
1981{
1982 startlineno = yylineno;
1983 startcolumn = yycolumn;
1984}
1985
1986bool QScript::Lexer::scanRegExp(RegExpBodyPrefix prefix)
1987{
1988 pos16 = 0;
1989 bool lastWasEscape = false;
1990
1991 if (prefix == EqualPrefix)
1992 record16(QLatin1Char('='));
1993
1994 while (1) {
1995 if (isLineTerminator() || current == 0) {
1996 errmsg = QLatin1String("Unterminated regular expression literal");
1997 return false;
1998 }
1999 else if (current != '/' || lastWasEscape == true)
2000 {
2001 record16(current);
2002 lastWasEscape = !lastWasEscape && (current == '\\');
2003 }
2004 else {
2005 pattern = QString(buffer16, pos16);
2006 pos16 = 0;
2007 shift(1);
2008 break;
2009 }
2010 shift(1);
2011 }
2012
2013 flags = 0;
2014 while (isIdentLetter(current)) {
2015 record16(current);
2016 shift(1);
2017 }
2018
2019 return true;
2020}
2021
2022void QScript::Lexer::syncProhibitAutomaticSemicolon()
2023{
2024 if (parenthesesState == BalancedParentheses) {
2025 // we have seen something like "if (foo)", which means we should
2026 // never insert an automatic semicolon at this point, since it would
2027 // then be expanded into an empty statement (ECMA-262 7.9.1)
2028 prohibitAutomaticSemicolon = true;
2029 parenthesesState = IgnoreParentheses;
2030 } else {
2031 prohibitAutomaticSemicolon = false;
2032 }
2033}
2034
2035
2036class Translator;
2037
2038class QScriptParser: protected QScriptGrammar
2039{
2040public:
2041 QVariant val;
2042
2043 struct Location {
2044 int startLine;
2045 int startColumn;
2046 int endLine;
2047 int endColumn;
2048 };
2049
2050public:
2051 QScriptParser();
2052 ~QScriptParser();
2053
2054 bool parse(QScript::Lexer *lexer,
2055 const QString &fileName,
2056 Translator *translator);
2057
2058 inline QString errorMessage() const
2059 { return error_message; }
2060 inline int errorLineNumber() const
2061 { return error_lineno; }
2062 inline int errorColumnNumber() const
2063 { return error_column; }
2064
2065protected:
2066 inline void reallocateStack();
2067
2068 inline QVariant &sym(int index)
2069 { return sym_stack [tos + index - 1]; }
2070
2071 inline Location &loc(int index)
2072 { return location_stack [tos + index - 2]; }
2073
2074protected:
2075 int tos;
2076 int stack_size;
2077 QVector<QVariant> sym_stack;
2078 int *state_stack;
2079 Location *location_stack;
2080 QString error_message;
2081 int error_lineno;
2082 int error_column;
2083};
2084
2085inline void QScriptParser::reallocateStack()
2086{
2087 if (! stack_size)
2088 stack_size = 128;
2089 else
2090 stack_size <<= 1;
2091
2092 sym_stack.resize(stack_size);
2093 state_stack = reinterpret_cast<int*> (qRealloc(state_stack, stack_size * sizeof(int)));
2094 location_stack = reinterpret_cast<Location*> (qRealloc(location_stack, stack_size * sizeof(Location)));
2095}
2096
2097inline static bool automatic(QScript::Lexer *lexer, int token)
2098{
2099 return (token == QScriptGrammar::T_RBRACE)
2100 || (token == 0)
2101 || lexer->prevTerminator();
2102}
2103
2104QScriptParser::QScriptParser():
2105 tos(0),
2106 stack_size(0),
2107 sym_stack(0),
2108 state_stack(0),
2109 location_stack(0)
2110{
2111}
2112
2113QScriptParser::~QScriptParser()
2114{
2115 if (stack_size) {
2116 qFree(state_stack);
2117 qFree(location_stack);
2118 }
2119}
2120
2121static inline QScriptParser::Location location(QScript::Lexer *lexer)
2122{
2123 QScriptParser::Location loc;
2124 loc.startLine = lexer->startLineNo();
2125 loc.startColumn = lexer->startColumnNo();
2126 loc.endLine = lexer->endLineNo();
2127 loc.endColumn = lexer->endColumnNo();
2128 return loc;
2129}
2130
2131bool QScriptParser::parse(QScript::Lexer *lexer,
2132 const QString &fileName,
2133 Translator *translator)
2134{
2135 const int INITIAL_STATE = 0;
2136
2137 int yytoken = -1;
2138 int saved_yytoken = -1;
2139 int identLineNo = -1;
2140
2141 reallocateStack();
2142
2143 tos = 0;
2144 state_stack[++tos] = INITIAL_STATE;
2145
2146 while (true)
2147 {
2148 const int state = state_stack [tos];
2149 if (yytoken == -1 && - TERMINAL_COUNT != action_index [state])
2150 {
2151 if (saved_yytoken == -1)
2152 {
2153 yytoken = lexer->lex();
2154 location_stack [tos] = location(lexer);
2155 }
2156 else
2157 {
2158 yytoken = saved_yytoken;
2159 saved_yytoken = -1;
2160 }
2161 }
2162
2163 int act = t_action (state, yytoken);
2164
2165 if (act == ACCEPT_STATE)
2166 return true;
2167
2168 else if (act > 0)
2169 {
2170 if (++tos == stack_size)
2171 reallocateStack();
2172
2173 sym_stack [tos] = lexer->val ();
2174 state_stack [tos] = act;
2175 location_stack [tos] = location(lexer);
2176 yytoken = -1;
2177 }
2178
2179 else if (act < 0)
2180 {
2181 int r = - act - 1;
2182
2183 tos -= rhs [r];
2184 act = state_stack [tos++];
2185
2186 switch (r) {
2187
2188case 1: {
2189 sym(1) = sym(1).toByteArray();
2190 identLineNo = lexer->startLineNo();
2191} break;
2192
2193case 7: {
2194 bool rx = lexer->scanRegExp(QScript::Lexer::NoPrefix);
2195 if (!rx) {
2196 error_message = lexer->errorMessage();
2197 error_lineno = lexer->startLineNo();
2198 error_column = lexer->startColumnNo();
2199 return false;
2200 }
2201} break;
2202
2203case 8: {
2204 bool rx = lexer->scanRegExp(QScript::Lexer::EqualPrefix);
2205 if (!rx) {
2206 error_message = lexer->errorMessage();
2207 error_lineno = lexer->startLineNo();
2208 error_column = lexer->startColumnNo();
2209 return false;
2210 }
2211} break;
2212
2213case 66: {
2214 QString name = sym(1).toString();
2215 if ((name == QLatin1String("qsTranslate")) || (name == QLatin1String("QT_TRANSLATE_NOOP"))) {
2216 QVariantList args = sym(2).toList();
2217 if (args.size() < 2) {
2218 qWarning("%s:%d: %s() requires at least two arguments",
2219 qPrintable(fileName), identLineNo, qPrintable(name));
2220 } else {
2221 if ((args.at(0).type() != QVariant::String)
2222 || (args.at(1).type() != QVariant::String)) {
2223 qWarning("%s:%d: %s(): both arguments must be literal strings",
2224 qPrintable(fileName), identLineNo, qPrintable(name));
2225 } else {
2226 QString context = args.at(0).toString();
2227 QString text = args.at(1).toString();
2228 QString comment = args.value(2).toString();
2229 QString extracomment;
2230 bool plural = (args.size() > 4);
2231 recordMessage(translator, context, text, comment, extracomment,
2232 plural, fileName, identLineNo);
2233 }
2234 }
2235 } else if ((name == QLatin1String("qsTr")) || (name == QLatin1String("QT_TR_NOOP"))) {
2236 QVariantList args = sym(2).toList();
2237 if (args.size() < 1) {
2238 qWarning("%s:%d: %s() requires at least one argument",
2239 qPrintable(fileName), identLineNo, qPrintable(name));
2240 } else {
2241 if (args.at(0).type() != QVariant::String) {
2242 qWarning("%s:%d: %s(): text to translate must be a literal string",
2243 qPrintable(fileName), identLineNo, qPrintable(name));
2244 } else {
2245 QString context = QFileInfo(fileName).baseName();
2246 QString text = args.at(0).toString();
2247 QString comment = args.value(1).toString();
2248 QString extracomment;
2249 bool plural = (args.size() > 2);
2250 recordMessage(translator, context, text, comment, extracomment,
2251 plural, fileName, identLineNo);
2252 }
2253 }
2254 }
2255} break;
2256
2257case 70: {
2258 sym(1) = QVariantList();
2259} break;
2260
2261case 71: {
2262 sym(1) = sym(2);
2263} break;
2264
2265case 72: {
2266 sym(1) = QVariantList() << sym(1);
2267} break;
2268
2269case 73: {
2270 sym(1) = sym(1).toList() << sym(3);
2271} break;
2272
2273case 94: {
2274 if ((sym(1).type() == QVariant::String) || (sym(3).type() == QVariant::String))
2275 sym(1) = sym(1).toString() + sym(3).toString();
2276 else
2277 sym(1) = QVariant();
2278} break;
2279
2280 } // switch
2281
2282 state_stack [tos] = nt_action (act, lhs [r] - TERMINAL_COUNT);
2283
2284 if (rhs[r] > 1) {
2285 location_stack[tos - 1].endLine = location_stack[tos + rhs[r] - 2].endLine;
2286 location_stack[tos - 1].endColumn = location_stack[tos + rhs[r] - 2].endColumn;
2287 location_stack[tos] = location_stack[tos + rhs[r] - 1];
2288 }
2289 }
2290
2291 else
2292 {
2293 if (saved_yytoken == -1 && automatic (lexer, yytoken) && t_action (state, T_AUTOMATIC_SEMICOLON) > 0)
2294 {
2295 saved_yytoken = yytoken;
2296 yytoken = T_SEMICOLON;
2297 continue;
2298 }
2299
2300 else if ((state == INITIAL_STATE) && (yytoken == 0)) {
2301 // accept empty input
2302 yytoken = T_SEMICOLON;
2303 continue;
2304 }
2305
2306 int ers = state;
2307 int shifts = 0;
2308 int reduces = 0;
2309 int expected_tokens [3];
2310 for (int tk = 0; tk < TERMINAL_COUNT; ++tk)
2311 {
2312 int k = t_action (ers, tk);
2313
2314 if (! k)
2315 continue;
2316 else if (k < 0)
2317 ++reduces;
2318 else if (spell [tk])
2319 {
2320 if (shifts < 3)
2321 expected_tokens [shifts] = tk;
2322 ++shifts;
2323 }
2324 }
2325
2326 error_message.clear ();
2327 if (shifts && shifts < 3)
2328 {
2329 bool first = true;
2330
2331 for (int s = 0; s < shifts; ++s)
2332 {
2333 if (first)
2334 error_message += QLatin1String ("Expected ");
2335 else
2336 error_message += QLatin1String (", ");
2337
2338 first = false;
2339 error_message += QLatin1String("`");
2340 error_message += QLatin1String (spell [expected_tokens [s]]);
2341 error_message += QLatin1String("'");
2342 }
2343 }
2344
2345 if (error_message.isEmpty())
2346 error_message = lexer->errorMessage();
2347
2348 error_lineno = lexer->startLineNo();
2349 error_column = lexer->startColumnNo();
2350
2351 return false;
2352 }
2353 }
2354
2355 return false;
2356}
2357
2358
2359bool loadQScript(Translator &translator, const QString &filename, ConversionData &cd)
2360{
2361 QFile file(filename);
2362 if (!file.open(QIODevice::ReadOnly)) {
2363 cd.appendError(QString::fromLatin1("Cannot open %1: %2")
2364 .arg(filename, file.errorString()));
2365 return false;
2366 }
2367 QTextStream ts(&file);
2368 QByteArray codecName;
2369 if (!cd.m_codecForSource.isEmpty())
2370 codecName = cd.m_codecForSource;
2371 else
2372 codecName = translator.codecName(); // Just because it should be latin1 already
2373 ts.setCodec(QTextCodec::codecForName(codecName));
2374 ts.setAutoDetectUnicode(true);
2375
2376 QString code = ts.readAll();
2377 QScript::Lexer lexer;
2378 lexer.setCode(code, /*lineNumber=*/1);
2379 QScriptParser parser;
2380 if (!parser.parse(&lexer, filename, &translator)) {
2381 qWarning("%s:%d: %s", qPrintable(filename), parser.errorLineNumber(),
2382 qPrintable(parser.errorMessage()));
2383 return false;
2384 }
2385
2386 // Java uses UTF-16 internally and Jambi makes UTF-8 for tr() purposes of it.
2387 translator.setCodecName("UTF-8");
2388 return true;
2389}
2390
2391QT_END_NAMESPACE
Note: See TracBrowser for help on using the repository browser.