blob: eca9c3db53bec6e99a8a1a1b3e1d3f60fbd10685 [file] [log] [blame]
alokp@chromium.org04d7d222012-05-16 19:24:07 +00001#line 16 "./Tokenizer.l"
2//
3// Copyright (c) 2011 The ANGLE Project Authors. All rights reserved.
4// Use of this source code is governed by a BSD-style license that can be
5// found in the LICENSE file.
6//
7
8// This file is auto-generated by generate_parser.sh. DO NOT EDIT!
9
10
11
12#line 13 "./Tokenizer.cpp"
13
14#define YY_INT_ALIGNED short int
15
16/* A lexical scanner generated by flex */
17
18#define FLEX_SCANNER
19#define YY_FLEX_MAJOR_VERSION 2
20#define YY_FLEX_MINOR_VERSION 5
21#define YY_FLEX_SUBMINOR_VERSION 35
22#if YY_FLEX_SUBMINOR_VERSION > 0
23#define FLEX_BETA
24#endif
25
26/* First, we deal with platform-specific or compiler-specific issues. */
27
28/* begin standard C headers. */
29#include <stdio.h>
30#include <string.h>
31#include <errno.h>
32#include <stdlib.h>
33
34/* end standard C headers. */
35
36/* flex integer type definitions */
37
38#ifndef FLEXINT_H
39#define FLEXINT_H
40
41/* C99 systems have <inttypes.h>. Non-C99 systems may or may not. */
42
43#if defined (__STDC_VERSION__) && __STDC_VERSION__ >= 199901L
44
45/* C99 says to define __STDC_LIMIT_MACROS before including stdint.h,
46 * if you want the limit (max/min) macros for int types.
47 */
48#ifndef __STDC_LIMIT_MACROS
49#define __STDC_LIMIT_MACROS 1
50#endif
51
52#include <inttypes.h>
53typedef int8_t flex_int8_t;
54typedef uint8_t flex_uint8_t;
55typedef int16_t flex_int16_t;
56typedef uint16_t flex_uint16_t;
57typedef int32_t flex_int32_t;
58typedef uint32_t flex_uint32_t;
59#else
60typedef signed char flex_int8_t;
61typedef short int flex_int16_t;
62typedef int flex_int32_t;
63typedef unsigned char flex_uint8_t;
64typedef unsigned short int flex_uint16_t;
65typedef unsigned int flex_uint32_t;
66#endif /* ! C99 */
67
68/* Limits of integral types. */
69#ifndef INT8_MIN
70#define INT8_MIN (-128)
71#endif
72#ifndef INT16_MIN
73#define INT16_MIN (-32767-1)
74#endif
75#ifndef INT32_MIN
76#define INT32_MIN (-2147483647-1)
77#endif
78#ifndef INT8_MAX
79#define INT8_MAX (127)
80#endif
81#ifndef INT16_MAX
82#define INT16_MAX (32767)
83#endif
84#ifndef INT32_MAX
85#define INT32_MAX (2147483647)
86#endif
87#ifndef UINT8_MAX
88#define UINT8_MAX (255U)
89#endif
90#ifndef UINT16_MAX
91#define UINT16_MAX (65535U)
92#endif
93#ifndef UINT32_MAX
94#define UINT32_MAX (4294967295U)
95#endif
96
97#endif /* ! FLEXINT_H */
98
99#ifdef __cplusplus
100
101/* The "const" storage-class-modifier is valid. */
102#define YY_USE_CONST
103
104#else /* ! __cplusplus */
105
106/* C99 requires __STDC__ to be defined as 1. */
107#if defined (__STDC__)
108
109#define YY_USE_CONST
110
111#endif /* defined (__STDC__) */
112#endif /* ! __cplusplus */
113
114#ifdef YY_USE_CONST
115#define yyconst const
116#else
117#define yyconst
118#endif
119
120/* Returned upon end-of-file. */
121#define YY_NULL 0
122
123/* Promotes a possibly negative, possibly signed char to an unsigned
124 * integer for use as an array index. If the signed char is negative,
125 * we want to instead treat it as an 8-bit unsigned char, hence the
126 * double cast.
127 */
128#define YY_SC_TO_UI(c) ((unsigned int) (unsigned char) c)
129
130/* An opaque pointer. */
131#ifndef YY_TYPEDEF_YY_SCANNER_T
132#define YY_TYPEDEF_YY_SCANNER_T
133typedef void* yyscan_t;
134#endif
135
136/* For convenience, these vars (plus the bison vars far below)
137 are macros in the reentrant scanner. */
138#define yyin yyg->yyin_r
139#define yyout yyg->yyout_r
140#define yyextra yyg->yyextra_r
141#define yyleng yyg->yyleng_r
142#define yytext yyg->yytext_r
143#define yylineno (YY_CURRENT_BUFFER_LVALUE->yy_bs_lineno)
144#define yycolumn (YY_CURRENT_BUFFER_LVALUE->yy_bs_column)
145#define yy_flex_debug yyg->yy_flex_debug_r
146
147/* Enter a start condition. This macro really ought to take a parameter,
148 * but we do it the disgusting crufty way forced on us by the ()-less
149 * definition of BEGIN.
150 */
151#define BEGIN yyg->yy_start = 1 + 2 *
152
153/* Translate the current start state into a value that can be later handed
154 * to BEGIN to return to the state. The YYSTATE alias is for lex
155 * compatibility.
156 */
157#define YY_START ((yyg->yy_start - 1) / 2)
158#define YYSTATE YY_START
159
160/* Action number for EOF rule of a given start state. */
161#define YY_STATE_EOF(state) (YY_END_OF_BUFFER + state + 1)
162
163/* Special action meaning "start processing a new file". */
164#define YY_NEW_FILE pprestart(yyin ,yyscanner )
165
166#define YY_END_OF_BUFFER_CHAR 0
167
168/* Size of default input buffer. */
169#ifndef YY_BUF_SIZE
170#define YY_BUF_SIZE 16384
171#endif
172
173/* The state buf must be large enough to hold one state per character in the main buffer.
174 */
175#define YY_STATE_BUF_SIZE ((YY_BUF_SIZE + 2) * sizeof(yy_state_type))
176
177#ifndef YY_TYPEDEF_YY_BUFFER_STATE
178#define YY_TYPEDEF_YY_BUFFER_STATE
179typedef struct yy_buffer_state *YY_BUFFER_STATE;
180#endif
181
182#define EOB_ACT_CONTINUE_SCAN 0
183#define EOB_ACT_END_OF_FILE 1
184#define EOB_ACT_LAST_MATCH 2
185
186 #define YY_LESS_LINENO(n)
187
188/* Return all but the first "n" matched characters back to the input stream. */
189#define yyless(n) \
190 do \
191 { \
192 /* Undo effects of setting up yytext. */ \
193 int yyless_macro_arg = (n); \
194 YY_LESS_LINENO(yyless_macro_arg);\
195 *yy_cp = yyg->yy_hold_char; \
196 YY_RESTORE_YY_MORE_OFFSET \
197 yyg->yy_c_buf_p = yy_cp = yy_bp + yyless_macro_arg - YY_MORE_ADJ; \
198 YY_DO_BEFORE_ACTION; /* set up yytext again */ \
199 } \
200 while ( 0 )
201
202#define unput(c) yyunput( c, yyg->yytext_ptr , yyscanner )
203
204#ifndef YY_TYPEDEF_YY_SIZE_T
205#define YY_TYPEDEF_YY_SIZE_T
206typedef size_t yy_size_t;
207#endif
208
209#ifndef YY_STRUCT_YY_BUFFER_STATE
210#define YY_STRUCT_YY_BUFFER_STATE
211struct yy_buffer_state
212 {
213 FILE *yy_input_file;
214
215 char *yy_ch_buf; /* input buffer */
216 char *yy_buf_pos; /* current position in input buffer */
217
218 /* Size of input buffer in bytes, not including room for EOB
219 * characters.
220 */
221 yy_size_t yy_buf_size;
222
223 /* Number of characters read into yy_ch_buf, not including EOB
224 * characters.
225 */
226 int yy_n_chars;
227
228 /* Whether we "own" the buffer - i.e., we know we created it,
229 * and can realloc() it to grow it, and should free() it to
230 * delete it.
231 */
232 int yy_is_our_buffer;
233
234 /* Whether this is an "interactive" input source; if so, and
235 * if we're using stdio for input, then we want to use getc()
236 * instead of fread(), to make sure we stop fetching input after
237 * each newline.
238 */
239 int yy_is_interactive;
240
241 /* Whether we're considered to be at the beginning of a line.
242 * If so, '^' rules will be active on the next match, otherwise
243 * not.
244 */
245 int yy_at_bol;
246
247 int yy_bs_lineno; /**< The line count. */
248 int yy_bs_column; /**< The column count. */
249
250 /* Whether to try to fill the input buffer when we reach the
251 * end of it.
252 */
253 int yy_fill_buffer;
254
255 int yy_buffer_status;
256
257#define YY_BUFFER_NEW 0
258#define YY_BUFFER_NORMAL 1
259 /* When an EOF's been seen but there's still some text to process
260 * then we mark the buffer as YY_EOF_PENDING, to indicate that we
261 * shouldn't try reading from the input source any more. We might
262 * still have a bunch of tokens to match, though, because of
263 * possible backing-up.
264 *
265 * When we actually see the EOF, we change the status to "new"
266 * (via pprestart()), so that the user can continue scanning by
267 * just pointing yyin at a new input file.
268 */
269#define YY_BUFFER_EOF_PENDING 2
270
271 };
272#endif /* !YY_STRUCT_YY_BUFFER_STATE */
273
274/* We provide macros for accessing buffer states in case in the
275 * future we want to put the buffer states in a more general
276 * "scanner state".
277 *
278 * Returns the top of the stack, or NULL.
279 */
280#define YY_CURRENT_BUFFER ( yyg->yy_buffer_stack \
281 ? yyg->yy_buffer_stack[yyg->yy_buffer_stack_top] \
282 : NULL)
283
284/* Same as previous macro, but useful when we know that the buffer stack is not
285 * NULL or when we need an lvalue. For internal use only.
286 */
287#define YY_CURRENT_BUFFER_LVALUE yyg->yy_buffer_stack[yyg->yy_buffer_stack_top]
288
289void pprestart (FILE *input_file ,yyscan_t yyscanner );
290void pp_switch_to_buffer (YY_BUFFER_STATE new_buffer ,yyscan_t yyscanner );
291YY_BUFFER_STATE pp_create_buffer (FILE *file,int size ,yyscan_t yyscanner );
292void pp_delete_buffer (YY_BUFFER_STATE b ,yyscan_t yyscanner );
293void pp_flush_buffer (YY_BUFFER_STATE b ,yyscan_t yyscanner );
294void pppush_buffer_state (YY_BUFFER_STATE new_buffer ,yyscan_t yyscanner );
295void pppop_buffer_state (yyscan_t yyscanner );
296
297static void ppensure_buffer_stack (yyscan_t yyscanner );
298static void pp_load_buffer_state (yyscan_t yyscanner );
299static void pp_init_buffer (YY_BUFFER_STATE b,FILE *file ,yyscan_t yyscanner );
300
301#define YY_FLUSH_BUFFER pp_flush_buffer(YY_CURRENT_BUFFER ,yyscanner)
302
303YY_BUFFER_STATE pp_scan_buffer (char *base,yy_size_t size ,yyscan_t yyscanner );
304YY_BUFFER_STATE pp_scan_string (yyconst char *yy_str ,yyscan_t yyscanner );
305YY_BUFFER_STATE pp_scan_bytes (yyconst char *bytes,int len ,yyscan_t yyscanner );
306
307void *ppalloc (yy_size_t ,yyscan_t yyscanner );
308void *pprealloc (void *,yy_size_t ,yyscan_t yyscanner );
309void ppfree (void * ,yyscan_t yyscanner );
310
311#define yy_new_buffer pp_create_buffer
312
313#define yy_set_interactive(is_interactive) \
314 { \
315 if ( ! YY_CURRENT_BUFFER ){ \
316 ppensure_buffer_stack (yyscanner); \
317 YY_CURRENT_BUFFER_LVALUE = \
318 pp_create_buffer(yyin,YY_BUF_SIZE ,yyscanner); \
319 } \
320 YY_CURRENT_BUFFER_LVALUE->yy_is_interactive = is_interactive; \
321 }
322
323#define yy_set_bol(at_bol) \
324 { \
325 if ( ! YY_CURRENT_BUFFER ){\
326 ppensure_buffer_stack (yyscanner); \
327 YY_CURRENT_BUFFER_LVALUE = \
328 pp_create_buffer(yyin,YY_BUF_SIZE ,yyscanner); \
329 } \
330 YY_CURRENT_BUFFER_LVALUE->yy_at_bol = at_bol; \
331 }
332
333#define YY_AT_BOL() (YY_CURRENT_BUFFER_LVALUE->yy_at_bol)
334
335/* Begin user sect3 */
336
337#define ppwrap(n) 1
338#define YY_SKIP_YYWRAP
339
340typedef unsigned char YY_CHAR;
341
342typedef int yy_state_type;
343
344#define yytext_ptr yytext_r
345
346static yy_state_type yy_get_previous_state (yyscan_t yyscanner );
347static yy_state_type yy_try_NUL_trans (yy_state_type current_state ,yyscan_t yyscanner);
348static int yy_get_next_buffer (yyscan_t yyscanner );
349static void yy_fatal_error (yyconst char msg[] ,yyscan_t yyscanner );
350
351/* Done after the current pattern has been matched and before the
352 * corresponding action - sets up yytext.
353 */
354#define YY_DO_BEFORE_ACTION \
355 yyg->yytext_ptr = yy_bp; \
356 yyleng = (size_t) (yy_cp - yy_bp); \
357 yyg->yy_hold_char = *yy_cp; \
358 *yy_cp = '\0'; \
359 yyg->yy_c_buf_p = yy_cp;
360
361#define YY_NUM_RULES 37
362#define YY_END_OF_BUFFER 38
363/* This struct is not used in this scanner,
364 but its presence is necessary. */
365struct yy_trans_info
366 {
367 flex_int32_t yy_verify;
368 flex_int32_t yy_nxt;
369 };
370static yyconst flex_int16_t yy_accept[84] =
371 { 0,
372 0, 0, 0, 0, 38, 36, 34, 35, 35, 33,
373 7, 33, 33, 33, 33, 33, 33, 33, 33, 9,
374 9, 33, 33, 33, 8, 33, 33, 3, 5, 5,
375 4, 34, 35, 19, 27, 20, 30, 25, 12, 23,
376 13, 24, 10, 2, 1, 26, 10, 9, 11, 11,
377 11, 11, 9, 14, 16, 18, 17, 15, 8, 31,
378 21, 32, 22, 3, 5, 6, 11, 10, 11, 1,
379 10, 11, 0, 10, 9, 28, 29, 0, 10, 10,
380 10, 10, 0
381 } ;
382
383static yyconst flex_int32_t yy_ec[256] =
384 { 0,
385 1, 1, 1, 1, 1, 1, 1, 1, 2, 3,
386 2, 2, 4, 1, 1, 1, 1, 1, 1, 1,
387 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
388 1, 2, 5, 1, 6, 1, 7, 8, 1, 9,
389 9, 10, 11, 9, 12, 13, 14, 15, 16, 16,
390 16, 16, 16, 16, 16, 17, 17, 9, 9, 18,
391 19, 20, 9, 1, 21, 21, 21, 21, 22, 21,
392 23, 23, 23, 23, 23, 23, 23, 23, 23, 23,
393 23, 23, 23, 23, 23, 23, 23, 24, 23, 23,
394 9, 1, 9, 25, 23, 1, 21, 21, 21, 21,
395
396 22, 21, 23, 23, 23, 23, 23, 23, 23, 23,
397 23, 23, 23, 23, 23, 23, 23, 23, 23, 24,
398 23, 23, 9, 26, 9, 9, 1, 1, 1, 1,
399 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
400 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
401 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
402 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
403 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
404 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
405 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
406
407 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
408 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
409 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
410 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
411 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
412 1, 1, 1, 1, 1
413 } ;
414
415static yyconst flex_int32_t yy_meta[27] =
416 { 0,
417 1, 1, 2, 2, 1, 1, 1, 1, 1, 3,
418 1, 1, 4, 1, 5, 5, 5, 1, 1, 1,
419 5, 5, 5, 5, 1, 1
420 } ;
421
422static yyconst flex_int16_t yy_base[89] =
423 { 0,
424 0, 0, 24, 26, 158, 159, 150, 159, 145, 128,
425 159, 112, 23, 159, 111, 21, 25, 30, 29, 36,
426 46, 36, 100, 45, 0, 16, 47, 0, 159, 84,
427 65, 73, 159, 159, 159, 159, 159, 159, 159, 159,
428 159, 159, 61, 159, 0, 159, 73, 32, 56, 83,
429 95, 68, 0, 31, 159, 159, 159, 19, 0, 159,
430 159, 159, 159, 0, 159, 159, 98, 0, 110, 0,
431 0, 117, 52, 90, 80, 159, 159, 101, 97, 112,
432 120, 123, 159, 140, 28, 145, 150, 152
433 } ;
434
435static yyconst flex_int16_t yy_def[89] =
436 { 0,
437 83, 1, 84, 84, 83, 83, 83, 83, 83, 83,
438 83, 83, 83, 83, 83, 83, 83, 83, 83, 83,
439 20, 83, 83, 83, 85, 83, 83, 86, 83, 83,
440 83, 83, 83, 83, 83, 83, 83, 83, 83, 83,
441 83, 83, 83, 83, 87, 83, 83, 20, 20, 47,
442 50, 88, 21, 83, 83, 83, 83, 83, 85, 83,
443 83, 83, 83, 86, 83, 83, 43, 43, 67, 87,
444 47, 50, 83, 51, 88, 83, 83, 83, 69, 72,
445 83, 83, 0, 83, 83, 83, 83, 83
446 } ;
447
448static yyconst flex_int16_t yy_nxt[186] =
449 { 0,
450 6, 7, 8, 9, 10, 11, 12, 13, 14, 15,
451 16, 17, 18, 19, 20, 21, 21, 22, 23, 24,
452 25, 25, 25, 25, 26, 27, 29, 30, 29, 30,
453 36, 39, 59, 31, 60, 31, 41, 77, 44, 40,
454 61, 37, 45, 42, 43, 43, 43, 46, 47, 76,
455 48, 48, 49, 54, 55, 50, 50, 51, 50, 52,
456 53, 53, 53, 57, 58, 62, 81, 81, 81, 50,
457 49, 49, 63, 67, 32, 68, 68, 68, 66, 50,
458 50, 67, 69, 67, 67, 50, 65, 71, 71, 71,
459 50, 50, 50, 50, 72, 50, 50, 50, 50, 50,
460
461 83, 83, 50, 50, 50, 73, 73, 83, 83, 74,
462 74, 74, 67, 67, 67, 82, 82, 82, 56, 67,
463 78, 78, 83, 83, 79, 79, 79, 78, 78, 38,
464 35, 80, 80, 80, 81, 81, 81, 82, 82, 82,
465 28, 28, 28, 28, 28, 64, 34, 33, 64, 64,
466 70, 32, 70, 70, 70, 75, 75, 83, 5, 83,
467 83, 83, 83, 83, 83, 83, 83, 83, 83, 83,
468 83, 83, 83, 83, 83, 83, 83, 83, 83, 83,
469 83, 83, 83, 83, 83
470 } ;
471
472static yyconst flex_int16_t yy_chk[186] =
473 { 0,
474 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
475 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
476 1, 1, 1, 1, 1, 1, 3, 3, 4, 4,
477 13, 16, 85, 3, 26, 4, 17, 58, 19, 16,
478 26, 13, 19, 17, 18, 18, 18, 19, 20, 54,
479 20, 20, 20, 22, 22, 48, 20, 20, 20, 20,
480 21, 21, 21, 24, 24, 27, 73, 73, 73, 21,
481 49, 49, 27, 43, 32, 43, 43, 43, 31, 49,
482 52, 43, 43, 43, 43, 47, 30, 47, 47, 47,
483 52, 52, 75, 47, 47, 47, 47, 50, 50, 50,
484
485 74, 74, 75, 75, 50, 51, 51, 79, 79, 51,
486 51, 51, 67, 67, 67, 78, 78, 78, 23, 67,
487 69, 69, 80, 80, 69, 69, 69, 72, 72, 15,
488 12, 72, 72, 72, 81, 81, 81, 82, 82, 82,
489 84, 84, 84, 84, 84, 86, 10, 9, 86, 86,
490 87, 7, 87, 87, 87, 88, 88, 5, 83, 83,
491 83, 83, 83, 83, 83, 83, 83, 83, 83, 83,
492 83, 83, 83, 83, 83, 83, 83, 83, 83, 83,
493 83, 83, 83, 83, 83
494 } ;
495
496/* The intent behind this definition is that it'll catch
497 * any uses of REJECT which flex missed.
498 */
499#define REJECT reject_used_but_not_detected
500#define yymore() yymore_used_but_not_detected
501#define YY_MORE_ADJ 0
502#define YY_RESTORE_YY_MORE_OFFSET
503/*
504//
505// Copyright (c) 2002-2011 The ANGLE Project Authors. All rights reserved.
506// Use of this source code is governed by a BSD-style license that can be
507// found in the LICENSE file.
508//
509
510This file contains the Lex specification for GLSL ES preprocessor.
511Based on Microsoft Visual Studio 2010 Preprocessor Grammar:
512http://msdn.microsoft.com/en-us/library/2scxys89.aspx
513
514IF YOU MODIFY THIS FILE YOU ALSO NEED TO RUN generate_parser.sh.
515*/
516
517#include "Tokenizer.h"
alokp@chromium.org2c958ee2012-05-17 20:35:42 +0000518
519#include "Diagnostics.h"
alokp@chromium.org04d7d222012-05-16 19:24:07 +0000520#include "Token.h"
521
maxvujovic@gmail.comc6b3b3c2012-06-27 22:49:39 +0000522#if defined(__GNUC__)
523// Triggered by the auto-generated yy_fatal_error function.
524#pragma GCC diagnostic ignored "-Wmissing-noreturn"
525#endif
526
alokp@chromium.org04d7d222012-05-16 19:24:07 +0000527typedef std::string YYSTYPE;
alokp@chromium.org2c958ee2012-05-17 20:35:42 +0000528typedef pp::SourceLocation YYLTYPE;
alokp@chromium.org04d7d222012-05-16 19:24:07 +0000529
530// Use the unused yycolumn variable to track file (string) number.
531#define yyfileno yycolumn
532
533#define YY_USER_INIT \
534 do { \
535 yyfileno = 0; \
536 yylineno = 1; \
537 yyextra->leadingSpace = false; \
538 yyextra->lineStart = true; \
539 } while(0);
540
alokp@chromium.org19d7aa62012-05-31 17:34:05 +0000541#define YY_USER_ACTION \
542 do \
543 { \
544 pp::Input* input = &yyextra->input; \
545 pp::Input::Location* scanLoc = &yyextra->scanLoc; \
546 while ((scanLoc->sIndex < input->count()) && \
547 (scanLoc->cIndex >= input->length(scanLoc->sIndex))) \
548 { \
549 scanLoc->cIndex -= input->length(scanLoc->sIndex++); \
550 ++yyfileno; yylineno = 1; \
551 } \
552 yylloc->file = yyfileno; \
553 yylloc->line = yylineno; \
554 scanLoc->cIndex += yyleng; \
alokp@chromium.org04d7d222012-05-16 19:24:07 +0000555 } while(0);
556
557#define YY_INPUT(buf, result, maxSize) \
558 result = yyextra->input.read(buf, maxSize);
559
560#define INITIAL 0
561#define COMMENT 1
562
563#define YY_EXTRA_TYPE pp::Tokenizer::Context*
564
565/* Holds the entire state of the reentrant scanner. */
566struct yyguts_t
567 {
568
569 /* User-defined. Not touched by flex. */
570 YY_EXTRA_TYPE yyextra_r;
571
572 /* The rest are the same as the globals declared in the non-reentrant scanner. */
573 FILE *yyin_r, *yyout_r;
574 size_t yy_buffer_stack_top; /**< index of top of stack. */
575 size_t yy_buffer_stack_max; /**< capacity of stack. */
576 YY_BUFFER_STATE * yy_buffer_stack; /**< Stack as an array. */
577 char yy_hold_char;
578 int yy_n_chars;
579 int yyleng_r;
580 char *yy_c_buf_p;
581 int yy_init;
582 int yy_start;
583 int yy_did_buffer_switch_on_eof;
584 int yy_start_stack_ptr;
585 int yy_start_stack_depth;
586 int *yy_start_stack;
587 yy_state_type yy_last_accepting_state;
588 char* yy_last_accepting_cpos;
589
590 int yylineno_r;
591 int yy_flex_debug_r;
592
593 char *yytext_r;
594 int yy_more_flag;
595 int yy_more_len;
596
597 YYSTYPE * yylval_r;
598
599 YYLTYPE * yylloc_r;
600
601 }; /* end struct yyguts_t */
602
603static int yy_init_globals (yyscan_t yyscanner );
604
605 /* This must go here because YYSTYPE and YYLTYPE are included
606 * from bison output in section 1.*/
607 # define yylval yyg->yylval_r
608
609 # define yylloc yyg->yylloc_r
610
611int pplex_init (yyscan_t* scanner);
612
613int pplex_init_extra (YY_EXTRA_TYPE user_defined,yyscan_t* scanner);
614
615/* Accessor methods to globals.
616 These are made visible to non-reentrant scanners for convenience. */
617
618int pplex_destroy (yyscan_t yyscanner );
619
620int ppget_debug (yyscan_t yyscanner );
621
622void ppset_debug (int debug_flag ,yyscan_t yyscanner );
623
624YY_EXTRA_TYPE ppget_extra (yyscan_t yyscanner );
625
626void ppset_extra (YY_EXTRA_TYPE user_defined ,yyscan_t yyscanner );
627
628FILE *ppget_in (yyscan_t yyscanner );
629
630void ppset_in (FILE * in_str ,yyscan_t yyscanner );
631
632FILE *ppget_out (yyscan_t yyscanner );
633
634void ppset_out (FILE * out_str ,yyscan_t yyscanner );
635
636int ppget_leng (yyscan_t yyscanner );
637
638char *ppget_text (yyscan_t yyscanner );
639
640int ppget_lineno (yyscan_t yyscanner );
641
642void ppset_lineno (int line_number ,yyscan_t yyscanner );
643
644YYSTYPE * ppget_lval (yyscan_t yyscanner );
645
646void ppset_lval (YYSTYPE * yylval_param ,yyscan_t yyscanner );
647
648 YYLTYPE *ppget_lloc (yyscan_t yyscanner );
649
650 void ppset_lloc (YYLTYPE * yylloc_param ,yyscan_t yyscanner );
651
652/* Macros after this point can all be overridden by user definitions in
653 * section 1.
654 */
655
656#ifndef YY_SKIP_YYWRAP
657#ifdef __cplusplus
658extern "C" int ppwrap (yyscan_t yyscanner );
659#else
660extern int ppwrap (yyscan_t yyscanner );
661#endif
662#endif
663
664#ifndef yytext_ptr
665static void yy_flex_strncpy (char *,yyconst char *,int ,yyscan_t yyscanner);
666#endif
667
668#ifdef YY_NEED_STRLEN
669static int yy_flex_strlen (yyconst char * ,yyscan_t yyscanner);
670#endif
671
672#ifndef YY_NO_INPUT
673
674#ifdef __cplusplus
675static int yyinput (yyscan_t yyscanner );
676#else
677static int input (yyscan_t yyscanner );
678#endif
679
680#endif
681
682/* Amount of stuff to slurp up with each read. */
683#ifndef YY_READ_BUF_SIZE
684#define YY_READ_BUF_SIZE 8192
685#endif
686
687/* Copy whatever the last rule matched to the standard output. */
688#ifndef ECHO
689/* This used to be an fputs(), but since the string might contain NUL's,
690 * we now use fwrite().
691 */
692#define ECHO fwrite( yytext, yyleng, 1, yyout )
693#endif
694
695/* Gets input and stuffs it into "buf". number of characters read, or YY_NULL,
696 * is returned in "result".
697 */
698#ifndef YY_INPUT
699#define YY_INPUT(buf,result,max_size) \
700 if ( YY_CURRENT_BUFFER_LVALUE->yy_is_interactive ) \
701 { \
702 int c = '*'; \
703 int n; \
704 for ( n = 0; n < max_size && \
705 (c = getc( yyin )) != EOF && c != '\n'; ++n ) \
706 buf[n] = (char) c; \
707 if ( c == '\n' ) \
708 buf[n++] = (char) c; \
709 if ( c == EOF && ferror( yyin ) ) \
710 YY_FATAL_ERROR( "input in flex scanner failed" ); \
711 result = n; \
712 } \
713 else \
714 { \
715 errno=0; \
716 while ( (result = fread(buf, 1, max_size, yyin))==0 && ferror(yyin)) \
717 { \
718 if( errno != EINTR) \
719 { \
720 YY_FATAL_ERROR( "input in flex scanner failed" ); \
721 break; \
722 } \
723 errno=0; \
724 clearerr(yyin); \
725 } \
726 }\
727\
728
729#endif
730
731/* No semi-colon after return; correct usage is to write "yyterminate();" -
732 * we don't want an extra ';' after the "return" because that will cause
733 * some compilers to complain about unreachable statements.
734 */
735#ifndef yyterminate
736#define yyterminate() return YY_NULL
737#endif
738
739/* Number of entries by which start-condition stack grows. */
740#ifndef YY_START_STACK_INCR
741#define YY_START_STACK_INCR 25
742#endif
743
744/* Report a fatal error. */
745#ifndef YY_FATAL_ERROR
746#define YY_FATAL_ERROR(msg) yy_fatal_error( msg , yyscanner)
747#endif
748
749/* end tables serialization structures and prototypes */
750
751/* Default declaration of generated scanner - a define so the user can
752 * easily add parameters.
753 */
754#ifndef YY_DECL
755#define YY_DECL_IS_OURS 1
756
757extern int pplex \
758 (YYSTYPE * yylval_param,YYLTYPE * yylloc_param ,yyscan_t yyscanner);
759
760#define YY_DECL int pplex \
761 (YYSTYPE * yylval_param, YYLTYPE * yylloc_param , yyscan_t yyscanner)
762#endif /* !YY_DECL */
763
764/* Code executed at the beginning of each rule, after yytext and yyleng
765 * have been set up.
766 */
767#ifndef YY_USER_ACTION
768#define YY_USER_ACTION
769#endif
770
771/* Code executed at the end of each rule. */
772#ifndef YY_BREAK
773#define YY_BREAK break;
774#endif
775
776#define YY_RULE_SETUP \
777 YY_USER_ACTION
778
779/** The main scanner function which does all the work.
780 */
781YY_DECL
782{
783 register yy_state_type yy_current_state;
784 register char *yy_cp, *yy_bp;
785 register int yy_act;
786 struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
787
788 /* Line comment */
789
790 yylval = yylval_param;
791
792 yylloc = yylloc_param;
793
794 if ( !yyg->yy_init )
795 {
796 yyg->yy_init = 1;
797
798#ifdef YY_USER_INIT
799 YY_USER_INIT;
800#endif
801
802 if ( ! yyg->yy_start )
803 yyg->yy_start = 1; /* first start state */
804
805 if ( ! yyin )
806 yyin = stdin;
807
808 if ( ! yyout )
809 yyout = stdout;
810
811 if ( ! YY_CURRENT_BUFFER ) {
812 ppensure_buffer_stack (yyscanner);
813 YY_CURRENT_BUFFER_LVALUE =
814 pp_create_buffer(yyin,YY_BUF_SIZE ,yyscanner);
815 }
816
817 pp_load_buffer_state(yyscanner );
818 }
819
820 while ( 1 ) /* loops until end-of-file is reached */
821 {
822 yy_cp = yyg->yy_c_buf_p;
823
824 /* Support of yytext. */
825 *yy_cp = yyg->yy_hold_char;
826
827 /* yy_bp points to the position in yy_ch_buf of the start of
828 * the current run.
829 */
830 yy_bp = yy_cp;
831
832 yy_current_state = yyg->yy_start;
833yy_match:
834 do
835 {
836 register YY_CHAR yy_c = yy_ec[YY_SC_TO_UI(*yy_cp)];
837 if ( yy_accept[yy_current_state] )
838 {
839 yyg->yy_last_accepting_state = yy_current_state;
840 yyg->yy_last_accepting_cpos = yy_cp;
841 }
842 while ( yy_chk[yy_base[yy_current_state] + yy_c] != yy_current_state )
843 {
844 yy_current_state = (int) yy_def[yy_current_state];
845 if ( yy_current_state >= 84 )
846 yy_c = yy_meta[(unsigned int) yy_c];
847 }
848 yy_current_state = yy_nxt[yy_base[yy_current_state] + (unsigned int) yy_c];
849 ++yy_cp;
850 }
851 while ( yy_current_state != 83 );
852 yy_cp = yyg->yy_last_accepting_cpos;
853 yy_current_state = yyg->yy_last_accepting_state;
854
855yy_find_action:
856 yy_act = yy_accept[yy_current_state];
857
858 YY_DO_BEFORE_ACTION;
859
860do_action: /* This label is used only to access EOF actions. */
861
862 switch ( yy_act )
863 { /* beginning of action switch */
864 case 0: /* must back up */
865 /* undo the effects of YY_DO_BEFORE_ACTION */
866 *yy_cp = yyg->yy_hold_char;
867 yy_cp = yyg->yy_last_accepting_cpos;
868 yy_current_state = yyg->yy_last_accepting_state;
869 goto yy_find_action;
870
871case 1:
872YY_RULE_SETUP
873
874 YY_BREAK
875/* Block comment */
876/* Line breaks are just counted - not returned. */
877/* The comment is replaced by a single space. */
878case 2:
879YY_RULE_SETUP
880{ BEGIN(COMMENT); }
881 YY_BREAK
882case 3:
883YY_RULE_SETUP
884
885 YY_BREAK
886case 4:
887YY_RULE_SETUP
888
889 YY_BREAK
890case 5:
891/* rule 5 can match eol */
892YY_RULE_SETUP
893{ ++yylineno; }
894 YY_BREAK
alokp@chromium.org04d7d222012-05-16 19:24:07 +0000895case 6:
896YY_RULE_SETUP
alokp@chromium.org2c958ee2012-05-17 20:35:42 +0000897{
898 yyextra->leadingSpace = true;
899 BEGIN(INITIAL);
900}
alokp@chromium.org04d7d222012-05-16 19:24:07 +0000901 YY_BREAK
902case 7:
903YY_RULE_SETUP
904{
905 // # is only valid at start of line for preprocessor directives.
alokp@chromium.org432d6fc2012-06-27 22:13:21 +0000906 yylval->assign(1, yytext[0]);
907 return yyextra->lineStart ? pp::Token::PP_HASH : pp::Token::PP_OTHER;
alokp@chromium.org04d7d222012-05-16 19:24:07 +0000908}
909 YY_BREAK
910case 8:
911YY_RULE_SETUP
912{
913 yylval->assign(yytext, yyleng);
914 return pp::Token::IDENTIFIER;
915}
916 YY_BREAK
917case 9:
918YY_RULE_SETUP
919{
920 yylval->assign(yytext, yyleng);
921 return pp::Token::CONST_INT;
922}
923 YY_BREAK
924case 10:
925YY_RULE_SETUP
926{
927 yylval->assign(yytext, yyleng);
928 return pp::Token::CONST_FLOAT;
929}
930 YY_BREAK
931/* Anything that starts with a {DIGIT} or .{DIGIT} must be a number. */
932/* Rule to catch all invalid integers and floats. */
933case 11:
934YY_RULE_SETUP
935{
alokp@chromium.org432d6fc2012-06-27 22:13:21 +0000936 yylval->assign(yytext, yyleng);
937 return pp::Token::PP_NUMBER;
alokp@chromium.org04d7d222012-05-16 19:24:07 +0000938}
939 YY_BREAK
940case 12:
941YY_RULE_SETUP
alokp@chromium.org07d921d2012-05-22 20:22:08 +0000942{
943 yylval->assign(yytext, yyleng);
944 return pp::Token::OP_INC;
945}
alokp@chromium.org04d7d222012-05-16 19:24:07 +0000946 YY_BREAK
947case 13:
948YY_RULE_SETUP
alokp@chromium.org07d921d2012-05-22 20:22:08 +0000949{
950 yylval->assign(yytext, yyleng);
951 return pp::Token::OP_DEC;
952}
alokp@chromium.org04d7d222012-05-16 19:24:07 +0000953 YY_BREAK
954case 14:
955YY_RULE_SETUP
alokp@chromium.org07d921d2012-05-22 20:22:08 +0000956{
957 yylval->assign(yytext, yyleng);
958 return pp::Token::OP_LEFT;
959}
alokp@chromium.org04d7d222012-05-16 19:24:07 +0000960 YY_BREAK
961case 15:
962YY_RULE_SETUP
alokp@chromium.org07d921d2012-05-22 20:22:08 +0000963{
964 yylval->assign(yytext, yyleng);
965 return pp::Token::OP_RIGHT;
966}
alokp@chromium.org04d7d222012-05-16 19:24:07 +0000967 YY_BREAK
968case 16:
969YY_RULE_SETUP
alokp@chromium.org07d921d2012-05-22 20:22:08 +0000970{
971 yylval->assign(yytext, yyleng);
972 return pp::Token::OP_LE;
973}
alokp@chromium.org04d7d222012-05-16 19:24:07 +0000974 YY_BREAK
975case 17:
976YY_RULE_SETUP
alokp@chromium.org07d921d2012-05-22 20:22:08 +0000977{
978 yylval->assign(yytext, yyleng);
979 return pp::Token::OP_GE;
980}
alokp@chromium.org04d7d222012-05-16 19:24:07 +0000981 YY_BREAK
982case 18:
983YY_RULE_SETUP
alokp@chromium.org07d921d2012-05-22 20:22:08 +0000984{
985 yylval->assign(yytext, yyleng);
986 return pp::Token::OP_EQ;
987}
alokp@chromium.org04d7d222012-05-16 19:24:07 +0000988 YY_BREAK
989case 19:
990YY_RULE_SETUP
alokp@chromium.org07d921d2012-05-22 20:22:08 +0000991{
992 yylval->assign(yytext, yyleng);
993 return pp::Token::OP_NE;
994}
alokp@chromium.org04d7d222012-05-16 19:24:07 +0000995 YY_BREAK
996case 20:
997YY_RULE_SETUP
alokp@chromium.org07d921d2012-05-22 20:22:08 +0000998{
999 yylval->assign(yytext, yyleng);
1000 return pp::Token::OP_AND;
1001}
alokp@chromium.org04d7d222012-05-16 19:24:07 +00001002 YY_BREAK
1003case 21:
1004YY_RULE_SETUP
alokp@chromium.org07d921d2012-05-22 20:22:08 +00001005{
1006 yylval->assign(yytext, yyleng);
1007 return pp::Token::OP_XOR;
1008}
alokp@chromium.org04d7d222012-05-16 19:24:07 +00001009 YY_BREAK
1010case 22:
1011YY_RULE_SETUP
alokp@chromium.org07d921d2012-05-22 20:22:08 +00001012{
1013 yylval->assign(yytext, yyleng);
1014 return pp::Token::OP_OR;
1015}
alokp@chromium.org04d7d222012-05-16 19:24:07 +00001016 YY_BREAK
1017case 23:
1018YY_RULE_SETUP
alokp@chromium.org07d921d2012-05-22 20:22:08 +00001019{
1020 yylval->assign(yytext, yyleng);
1021 return pp::Token::OP_ADD_ASSIGN;
1022}
alokp@chromium.org04d7d222012-05-16 19:24:07 +00001023 YY_BREAK
1024case 24:
1025YY_RULE_SETUP
alokp@chromium.org07d921d2012-05-22 20:22:08 +00001026{
1027 yylval->assign(yytext, yyleng);
1028 return pp::Token::OP_SUB_ASSIGN;
1029}
alokp@chromium.org04d7d222012-05-16 19:24:07 +00001030 YY_BREAK
1031case 25:
1032YY_RULE_SETUP
alokp@chromium.org07d921d2012-05-22 20:22:08 +00001033{
1034 yylval->assign(yytext, yyleng);
1035 return pp::Token::OP_MUL_ASSIGN;
1036}
alokp@chromium.org04d7d222012-05-16 19:24:07 +00001037 YY_BREAK
1038case 26:
1039YY_RULE_SETUP
alokp@chromium.org07d921d2012-05-22 20:22:08 +00001040{
1041 yylval->assign(yytext, yyleng);
1042 return pp::Token::OP_DIV_ASSIGN;
1043}
alokp@chromium.org04d7d222012-05-16 19:24:07 +00001044 YY_BREAK
1045case 27:
1046YY_RULE_SETUP
alokp@chromium.org07d921d2012-05-22 20:22:08 +00001047{
1048 yylval->assign(yytext, yyleng);
1049 return pp::Token::OP_MOD_ASSIGN;
1050}
alokp@chromium.org04d7d222012-05-16 19:24:07 +00001051 YY_BREAK
1052case 28:
1053YY_RULE_SETUP
alokp@chromium.org07d921d2012-05-22 20:22:08 +00001054{
1055 yylval->assign(yytext, yyleng);
1056 return pp::Token::OP_LEFT_ASSIGN;
1057}
alokp@chromium.org04d7d222012-05-16 19:24:07 +00001058 YY_BREAK
1059case 29:
1060YY_RULE_SETUP
alokp@chromium.org07d921d2012-05-22 20:22:08 +00001061{
1062 yylval->assign(yytext, yyleng);
1063 return pp::Token::OP_RIGHT_ASSIGN;
1064}
alokp@chromium.org04d7d222012-05-16 19:24:07 +00001065 YY_BREAK
1066case 30:
1067YY_RULE_SETUP
alokp@chromium.org07d921d2012-05-22 20:22:08 +00001068{
1069 yylval->assign(yytext, yyleng);
1070 return pp::Token::OP_AND_ASSIGN;
1071}
alokp@chromium.org04d7d222012-05-16 19:24:07 +00001072 YY_BREAK
1073case 31:
1074YY_RULE_SETUP
alokp@chromium.org07d921d2012-05-22 20:22:08 +00001075{
1076 yylval->assign(yytext, yyleng);
1077 return pp::Token::OP_XOR_ASSIGN;
1078}
alokp@chromium.org04d7d222012-05-16 19:24:07 +00001079 YY_BREAK
1080case 32:
1081YY_RULE_SETUP
alokp@chromium.org07d921d2012-05-22 20:22:08 +00001082{
1083 yylval->assign(yytext, yyleng);
1084 return pp::Token::OP_OR_ASSIGN;
1085}
alokp@chromium.org04d7d222012-05-16 19:24:07 +00001086 YY_BREAK
1087case 33:
1088YY_RULE_SETUP
alokp@chromium.org07d921d2012-05-22 20:22:08 +00001089{
1090 yylval->assign(1, yytext[0]);
1091 return yytext[0];
1092}
alokp@chromium.org04d7d222012-05-16 19:24:07 +00001093 YY_BREAK
1094case 34:
1095YY_RULE_SETUP
1096{ yyextra->leadingSpace = true; }
1097 YY_BREAK
1098case 35:
1099/* rule 35 can match eol */
1100YY_RULE_SETUP
1101{
1102 ++yylineno;
alokp@chromium.org07d921d2012-05-22 20:22:08 +00001103 yylval->assign(1, '\n');
alokp@chromium.org04d7d222012-05-16 19:24:07 +00001104 return '\n';
1105}
1106 YY_BREAK
1107case 36:
1108YY_RULE_SETUP
1109{
alokp@chromium.org432d6fc2012-06-27 22:13:21 +00001110 yylval->assign(1, yytext[0]);
1111 return pp::Token::PP_OTHER;
alokp@chromium.org04d7d222012-05-16 19:24:07 +00001112}
1113 YY_BREAK
1114case YY_STATE_EOF(INITIAL):
alokp@chromium.org07d921d2012-05-22 20:22:08 +00001115case YY_STATE_EOF(COMMENT):
1116{
alokp@chromium.org19d7aa62012-05-31 17:34:05 +00001117 // YY_USER_ACTION is not invoked for handling EOF.
1118 // Set the location for EOF token manually.
1119 pp::Input* input = &yyextra->input;
1120 pp::Input::Location* scanLoc = &yyextra->scanLoc;
1121 int sIndexMax = std::max(0, input->count() - 1);
1122 if (scanLoc->sIndex != sIndexMax)
1123 {
1124 // We can only reach here if there are empty strings at the
1125 // end of the input.
1126 scanLoc->sIndex = sIndexMax; scanLoc->cIndex = 0;
1127 yyfileno = sIndexMax; yylineno = 1;
1128 }
1129 yylloc->file = yyfileno;
1130 yylloc->line = yylineno;
1131 yylval->clear();
1132
alokp@chromium.org07d921d2012-05-22 20:22:08 +00001133 if (YY_START == COMMENT)
1134 {
1135 yyextra->diagnostics->report(pp::Diagnostics::EOF_IN_COMMENT,
1136 pp::SourceLocation(yyfileno, yylineno),
1137 "");
1138 }
alokp@chromium.org07d921d2012-05-22 20:22:08 +00001139 yyterminate();
1140}
alokp@chromium.org04d7d222012-05-16 19:24:07 +00001141 YY_BREAK
1142case 37:
1143YY_RULE_SETUP
1144ECHO;
1145 YY_BREAK
1146
1147 case YY_END_OF_BUFFER:
1148 {
1149 /* Amount of text matched not including the EOB char. */
1150 int yy_amount_of_matched_text = (int) (yy_cp - yyg->yytext_ptr) - 1;
1151
1152 /* Undo the effects of YY_DO_BEFORE_ACTION. */
1153 *yy_cp = yyg->yy_hold_char;
1154 YY_RESTORE_YY_MORE_OFFSET
1155
1156 if ( YY_CURRENT_BUFFER_LVALUE->yy_buffer_status == YY_BUFFER_NEW )
1157 {
1158 /* We're scanning a new file or input source. It's
1159 * possible that this happened because the user
1160 * just pointed yyin at a new source and called
1161 * pplex(). If so, then we have to assure
1162 * consistency between YY_CURRENT_BUFFER and our
1163 * globals. Here is the right place to do so, because
1164 * this is the first action (other than possibly a
1165 * back-up) that will match for the new input source.
1166 */
1167 yyg->yy_n_chars = YY_CURRENT_BUFFER_LVALUE->yy_n_chars;
1168 YY_CURRENT_BUFFER_LVALUE->yy_input_file = yyin;
1169 YY_CURRENT_BUFFER_LVALUE->yy_buffer_status = YY_BUFFER_NORMAL;
1170 }
1171
1172 /* Note that here we test for yy_c_buf_p "<=" to the position
1173 * of the first EOB in the buffer, since yy_c_buf_p will
1174 * already have been incremented past the NUL character
1175 * (since all states make transitions on EOB to the
1176 * end-of-buffer state). Contrast this with the test
1177 * in input().
1178 */
1179 if ( yyg->yy_c_buf_p <= &YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[yyg->yy_n_chars] )
1180 { /* This was really a NUL. */
1181 yy_state_type yy_next_state;
1182
1183 yyg->yy_c_buf_p = yyg->yytext_ptr + yy_amount_of_matched_text;
1184
1185 yy_current_state = yy_get_previous_state( yyscanner );
1186
1187 /* Okay, we're now positioned to make the NUL
1188 * transition. We couldn't have
1189 * yy_get_previous_state() go ahead and do it
1190 * for us because it doesn't know how to deal
1191 * with the possibility of jamming (and we don't
1192 * want to build jamming into it because then it
1193 * will run more slowly).
1194 */
1195
1196 yy_next_state = yy_try_NUL_trans( yy_current_state , yyscanner);
1197
1198 yy_bp = yyg->yytext_ptr + YY_MORE_ADJ;
1199
1200 if ( yy_next_state )
1201 {
1202 /* Consume the NUL. */
1203 yy_cp = ++yyg->yy_c_buf_p;
1204 yy_current_state = yy_next_state;
1205 goto yy_match;
1206 }
1207
1208 else
1209 {
1210 yy_cp = yyg->yy_last_accepting_cpos;
1211 yy_current_state = yyg->yy_last_accepting_state;
1212 goto yy_find_action;
1213 }
1214 }
1215
1216 else switch ( yy_get_next_buffer( yyscanner ) )
1217 {
1218 case EOB_ACT_END_OF_FILE:
1219 {
1220 yyg->yy_did_buffer_switch_on_eof = 0;
1221
1222 if ( ppwrap(yyscanner ) )
1223 {
1224 /* Note: because we've taken care in
1225 * yy_get_next_buffer() to have set up
1226 * yytext, we can now set up
1227 * yy_c_buf_p so that if some total
1228 * hoser (like flex itself) wants to
1229 * call the scanner after we return the
1230 * YY_NULL, it'll still work - another
1231 * YY_NULL will get returned.
1232 */
1233 yyg->yy_c_buf_p = yyg->yytext_ptr + YY_MORE_ADJ;
1234
1235 yy_act = YY_STATE_EOF(YY_START);
1236 goto do_action;
1237 }
1238
1239 else
1240 {
1241 if ( ! yyg->yy_did_buffer_switch_on_eof )
1242 YY_NEW_FILE;
1243 }
1244 break;
1245 }
1246
1247 case EOB_ACT_CONTINUE_SCAN:
1248 yyg->yy_c_buf_p =
1249 yyg->yytext_ptr + yy_amount_of_matched_text;
1250
1251 yy_current_state = yy_get_previous_state( yyscanner );
1252
1253 yy_cp = yyg->yy_c_buf_p;
1254 yy_bp = yyg->yytext_ptr + YY_MORE_ADJ;
1255 goto yy_match;
1256
1257 case EOB_ACT_LAST_MATCH:
1258 yyg->yy_c_buf_p =
1259 &YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[yyg->yy_n_chars];
1260
1261 yy_current_state = yy_get_previous_state( yyscanner );
1262
1263 yy_cp = yyg->yy_c_buf_p;
1264 yy_bp = yyg->yytext_ptr + YY_MORE_ADJ;
1265 goto yy_find_action;
1266 }
1267 break;
1268 }
1269
1270 default:
1271 YY_FATAL_ERROR(
1272 "fatal flex scanner internal error--no action found" );
1273 } /* end of action switch */
1274 } /* end of scanning one token */
1275} /* end of pplex */
1276
1277/* yy_get_next_buffer - try to read in a new buffer
1278 *
1279 * Returns a code representing an action:
1280 * EOB_ACT_LAST_MATCH -
1281 * EOB_ACT_CONTINUE_SCAN - continue scanning from current position
1282 * EOB_ACT_END_OF_FILE - end of file
1283 */
1284static int yy_get_next_buffer (yyscan_t yyscanner)
1285{
1286 struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
1287 register char *dest = YY_CURRENT_BUFFER_LVALUE->yy_ch_buf;
1288 register char *source = yyg->yytext_ptr;
1289 register int number_to_move, i;
1290 int ret_val;
1291
1292 if ( yyg->yy_c_buf_p > &YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[yyg->yy_n_chars + 1] )
1293 YY_FATAL_ERROR(
1294 "fatal flex scanner internal error--end of buffer missed" );
1295
1296 if ( YY_CURRENT_BUFFER_LVALUE->yy_fill_buffer == 0 )
1297 { /* Don't try to fill the buffer, so this is an EOF. */
1298 if ( yyg->yy_c_buf_p - yyg->yytext_ptr - YY_MORE_ADJ == 1 )
1299 {
1300 /* We matched a single character, the EOB, so
1301 * treat this as a final EOF.
1302 */
1303 return EOB_ACT_END_OF_FILE;
1304 }
1305
1306 else
1307 {
1308 /* We matched some text prior to the EOB, first
1309 * process it.
1310 */
1311 return EOB_ACT_LAST_MATCH;
1312 }
1313 }
1314
1315 /* Try to read more data. */
1316
1317 /* First move last chars to start of buffer. */
1318 number_to_move = (int) (yyg->yy_c_buf_p - yyg->yytext_ptr) - 1;
1319
1320 for ( i = 0; i < number_to_move; ++i )
1321 *(dest++) = *(source++);
1322
1323 if ( YY_CURRENT_BUFFER_LVALUE->yy_buffer_status == YY_BUFFER_EOF_PENDING )
1324 /* don't do the read, it's not guaranteed to return an EOF,
1325 * just force an EOF
1326 */
1327 YY_CURRENT_BUFFER_LVALUE->yy_n_chars = yyg->yy_n_chars = 0;
1328
1329 else
1330 {
1331 int num_to_read =
1332 YY_CURRENT_BUFFER_LVALUE->yy_buf_size - number_to_move - 1;
1333
1334 while ( num_to_read <= 0 )
1335 { /* Not enough room in the buffer - grow it. */
1336
1337 /* just a shorter name for the current buffer */
1338 YY_BUFFER_STATE b = YY_CURRENT_BUFFER;
1339
1340 int yy_c_buf_p_offset =
1341 (int) (yyg->yy_c_buf_p - b->yy_ch_buf);
1342
1343 if ( b->yy_is_our_buffer )
1344 {
1345 int new_size = b->yy_buf_size * 2;
1346
1347 if ( new_size <= 0 )
1348 b->yy_buf_size += b->yy_buf_size / 8;
1349 else
1350 b->yy_buf_size *= 2;
1351
1352 b->yy_ch_buf = (char *)
1353 /* Include room in for 2 EOB chars. */
1354 pprealloc((void *) b->yy_ch_buf,b->yy_buf_size + 2 ,yyscanner );
1355 }
1356 else
1357 /* Can't grow it, we don't own it. */
1358 b->yy_ch_buf = 0;
1359
1360 if ( ! b->yy_ch_buf )
1361 YY_FATAL_ERROR(
1362 "fatal error - scanner input buffer overflow" );
1363
1364 yyg->yy_c_buf_p = &b->yy_ch_buf[yy_c_buf_p_offset];
1365
1366 num_to_read = YY_CURRENT_BUFFER_LVALUE->yy_buf_size -
1367 number_to_move - 1;
1368
1369 }
1370
1371 if ( num_to_read > YY_READ_BUF_SIZE )
1372 num_to_read = YY_READ_BUF_SIZE;
1373
1374 /* Read in more data. */
1375 YY_INPUT( (&YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[number_to_move]),
1376 yyg->yy_n_chars, (size_t) num_to_read );
1377
1378 YY_CURRENT_BUFFER_LVALUE->yy_n_chars = yyg->yy_n_chars;
1379 }
1380
1381 if ( yyg->yy_n_chars == 0 )
1382 {
1383 if ( number_to_move == YY_MORE_ADJ )
1384 {
1385 ret_val = EOB_ACT_END_OF_FILE;
1386 pprestart(yyin ,yyscanner);
1387 }
1388
1389 else
1390 {
1391 ret_val = EOB_ACT_LAST_MATCH;
1392 YY_CURRENT_BUFFER_LVALUE->yy_buffer_status =
1393 YY_BUFFER_EOF_PENDING;
1394 }
1395 }
1396
1397 else
1398 ret_val = EOB_ACT_CONTINUE_SCAN;
1399
1400 if ((yy_size_t) (yyg->yy_n_chars + number_to_move) > YY_CURRENT_BUFFER_LVALUE->yy_buf_size) {
1401 /* Extend the array by 50%, plus the number we really need. */
1402 yy_size_t new_size = yyg->yy_n_chars + number_to_move + (yyg->yy_n_chars >> 1);
1403 YY_CURRENT_BUFFER_LVALUE->yy_ch_buf = (char *) pprealloc((void *) YY_CURRENT_BUFFER_LVALUE->yy_ch_buf,new_size ,yyscanner );
1404 if ( ! YY_CURRENT_BUFFER_LVALUE->yy_ch_buf )
1405 YY_FATAL_ERROR( "out of dynamic memory in yy_get_next_buffer()" );
1406 }
1407
1408 yyg->yy_n_chars += number_to_move;
1409 YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[yyg->yy_n_chars] = YY_END_OF_BUFFER_CHAR;
1410 YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[yyg->yy_n_chars + 1] = YY_END_OF_BUFFER_CHAR;
1411
1412 yyg->yytext_ptr = &YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[0];
1413
1414 return ret_val;
1415}
1416
1417/* yy_get_previous_state - get the state just before the EOB char was reached */
1418
1419 static yy_state_type yy_get_previous_state (yyscan_t yyscanner)
1420{
1421 register yy_state_type yy_current_state;
1422 register char *yy_cp;
1423 struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
1424
1425 yy_current_state = yyg->yy_start;
1426
1427 for ( yy_cp = yyg->yytext_ptr + YY_MORE_ADJ; yy_cp < yyg->yy_c_buf_p; ++yy_cp )
1428 {
1429 register YY_CHAR yy_c = (*yy_cp ? yy_ec[YY_SC_TO_UI(*yy_cp)] : 1);
1430 if ( yy_accept[yy_current_state] )
1431 {
1432 yyg->yy_last_accepting_state = yy_current_state;
1433 yyg->yy_last_accepting_cpos = yy_cp;
1434 }
1435 while ( yy_chk[yy_base[yy_current_state] + yy_c] != yy_current_state )
1436 {
1437 yy_current_state = (int) yy_def[yy_current_state];
1438 if ( yy_current_state >= 84 )
1439 yy_c = yy_meta[(unsigned int) yy_c];
1440 }
1441 yy_current_state = yy_nxt[yy_base[yy_current_state] + (unsigned int) yy_c];
1442 }
1443
1444 return yy_current_state;
1445}
1446
1447/* yy_try_NUL_trans - try to make a transition on the NUL character
1448 *
1449 * synopsis
1450 * next_state = yy_try_NUL_trans( current_state );
1451 */
1452 static yy_state_type yy_try_NUL_trans (yy_state_type yy_current_state , yyscan_t yyscanner)
1453{
1454 register int yy_is_jam;
1455 struct yyguts_t * yyg = (struct yyguts_t*)yyscanner; /* This var may be unused depending upon options. */
1456 register char *yy_cp = yyg->yy_c_buf_p;
1457
1458 register YY_CHAR yy_c = 1;
1459 if ( yy_accept[yy_current_state] )
1460 {
1461 yyg->yy_last_accepting_state = yy_current_state;
1462 yyg->yy_last_accepting_cpos = yy_cp;
1463 }
1464 while ( yy_chk[yy_base[yy_current_state] + yy_c] != yy_current_state )
1465 {
1466 yy_current_state = (int) yy_def[yy_current_state];
1467 if ( yy_current_state >= 84 )
1468 yy_c = yy_meta[(unsigned int) yy_c];
1469 }
1470 yy_current_state = yy_nxt[yy_base[yy_current_state] + (unsigned int) yy_c];
1471 yy_is_jam = (yy_current_state == 83);
1472
1473 return yy_is_jam ? 0 : yy_current_state;
1474}
1475
1476#ifndef YY_NO_INPUT
1477#ifdef __cplusplus
1478 static int yyinput (yyscan_t yyscanner)
1479#else
1480 static int input (yyscan_t yyscanner)
1481#endif
1482
1483{
1484 int c;
1485 struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
1486
1487 *yyg->yy_c_buf_p = yyg->yy_hold_char;
1488
1489 if ( *yyg->yy_c_buf_p == YY_END_OF_BUFFER_CHAR )
1490 {
1491 /* yy_c_buf_p now points to the character we want to return.
1492 * If this occurs *before* the EOB characters, then it's a
1493 * valid NUL; if not, then we've hit the end of the buffer.
1494 */
1495 if ( yyg->yy_c_buf_p < &YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[yyg->yy_n_chars] )
1496 /* This was really a NUL. */
1497 *yyg->yy_c_buf_p = '\0';
1498
1499 else
1500 { /* need more input */
1501 int offset = yyg->yy_c_buf_p - yyg->yytext_ptr;
1502 ++yyg->yy_c_buf_p;
1503
1504 switch ( yy_get_next_buffer( yyscanner ) )
1505 {
1506 case EOB_ACT_LAST_MATCH:
1507 /* This happens because yy_g_n_b()
1508 * sees that we've accumulated a
1509 * token and flags that we need to
1510 * try matching the token before
1511 * proceeding. But for input(),
1512 * there's no matching to consider.
1513 * So convert the EOB_ACT_LAST_MATCH
1514 * to EOB_ACT_END_OF_FILE.
1515 */
1516
1517 /* Reset buffer status. */
1518 pprestart(yyin ,yyscanner);
1519
1520 /*FALLTHROUGH*/
1521
1522 case EOB_ACT_END_OF_FILE:
1523 {
1524 if ( ppwrap(yyscanner ) )
1525 return EOF;
1526
1527 if ( ! yyg->yy_did_buffer_switch_on_eof )
1528 YY_NEW_FILE;
1529#ifdef __cplusplus
1530 return yyinput(yyscanner);
1531#else
1532 return input(yyscanner);
1533#endif
1534 }
1535
1536 case EOB_ACT_CONTINUE_SCAN:
1537 yyg->yy_c_buf_p = yyg->yytext_ptr + offset;
1538 break;
1539 }
1540 }
1541 }
1542
1543 c = *(unsigned char *) yyg->yy_c_buf_p; /* cast for 8-bit char's */
1544 *yyg->yy_c_buf_p = '\0'; /* preserve yytext */
1545 yyg->yy_hold_char = *++yyg->yy_c_buf_p;
1546
1547 return c;
1548}
1549#endif /* ifndef YY_NO_INPUT */
1550
1551/** Immediately switch to a different input stream.
1552 * @param input_file A readable stream.
1553 * @param yyscanner The scanner object.
1554 * @note This function does not reset the start condition to @c INITIAL .
1555 */
1556 void pprestart (FILE * input_file , yyscan_t yyscanner)
1557{
1558 struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
1559
1560 if ( ! YY_CURRENT_BUFFER ){
1561 ppensure_buffer_stack (yyscanner);
1562 YY_CURRENT_BUFFER_LVALUE =
1563 pp_create_buffer(yyin,YY_BUF_SIZE ,yyscanner);
1564 }
1565
1566 pp_init_buffer(YY_CURRENT_BUFFER,input_file ,yyscanner);
1567 pp_load_buffer_state(yyscanner );
1568}
1569
1570/** Switch to a different input buffer.
1571 * @param new_buffer The new input buffer.
1572 * @param yyscanner The scanner object.
1573 */
1574 void pp_switch_to_buffer (YY_BUFFER_STATE new_buffer , yyscan_t yyscanner)
1575{
1576 struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
1577
1578 /* TODO. We should be able to replace this entire function body
1579 * with
1580 * pppop_buffer_state();
1581 * pppush_buffer_state(new_buffer);
1582 */
1583 ppensure_buffer_stack (yyscanner);
1584 if ( YY_CURRENT_BUFFER == new_buffer )
1585 return;
1586
1587 if ( YY_CURRENT_BUFFER )
1588 {
1589 /* Flush out information for old buffer. */
1590 *yyg->yy_c_buf_p = yyg->yy_hold_char;
1591 YY_CURRENT_BUFFER_LVALUE->yy_buf_pos = yyg->yy_c_buf_p;
1592 YY_CURRENT_BUFFER_LVALUE->yy_n_chars = yyg->yy_n_chars;
1593 }
1594
1595 YY_CURRENT_BUFFER_LVALUE = new_buffer;
1596 pp_load_buffer_state(yyscanner );
1597
1598 /* We don't actually know whether we did this switch during
1599 * EOF (ppwrap()) processing, but the only time this flag
1600 * is looked at is after ppwrap() is called, so it's safe
1601 * to go ahead and always set it.
1602 */
1603 yyg->yy_did_buffer_switch_on_eof = 1;
1604}
1605
1606static void pp_load_buffer_state (yyscan_t yyscanner)
1607{
1608 struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
1609 yyg->yy_n_chars = YY_CURRENT_BUFFER_LVALUE->yy_n_chars;
1610 yyg->yytext_ptr = yyg->yy_c_buf_p = YY_CURRENT_BUFFER_LVALUE->yy_buf_pos;
1611 yyin = YY_CURRENT_BUFFER_LVALUE->yy_input_file;
1612 yyg->yy_hold_char = *yyg->yy_c_buf_p;
1613}
1614
1615/** Allocate and initialize an input buffer state.
1616 * @param file A readable stream.
1617 * @param size The character buffer size in bytes. When in doubt, use @c YY_BUF_SIZE.
1618 * @param yyscanner The scanner object.
1619 * @return the allocated buffer state.
1620 */
1621 YY_BUFFER_STATE pp_create_buffer (FILE * file, int size , yyscan_t yyscanner)
1622{
1623 YY_BUFFER_STATE b;
1624
1625 b = (YY_BUFFER_STATE) ppalloc(sizeof( struct yy_buffer_state ) ,yyscanner );
1626 if ( ! b )
1627 YY_FATAL_ERROR( "out of dynamic memory in pp_create_buffer()" );
1628
1629 b->yy_buf_size = size;
1630
1631 /* yy_ch_buf has to be 2 characters longer than the size given because
1632 * we need to put in 2 end-of-buffer characters.
1633 */
1634 b->yy_ch_buf = (char *) ppalloc(b->yy_buf_size + 2 ,yyscanner );
1635 if ( ! b->yy_ch_buf )
1636 YY_FATAL_ERROR( "out of dynamic memory in pp_create_buffer()" );
1637
1638 b->yy_is_our_buffer = 1;
1639
1640 pp_init_buffer(b,file ,yyscanner);
1641
1642 return b;
1643}
1644
1645/** Destroy the buffer.
1646 * @param b a buffer created with pp_create_buffer()
1647 * @param yyscanner The scanner object.
1648 */
1649 void pp_delete_buffer (YY_BUFFER_STATE b , yyscan_t yyscanner)
1650{
1651 struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
1652
1653 if ( ! b )
1654 return;
1655
1656 if ( b == YY_CURRENT_BUFFER ) /* Not sure if we should pop here. */
1657 YY_CURRENT_BUFFER_LVALUE = (YY_BUFFER_STATE) 0;
1658
1659 if ( b->yy_is_our_buffer )
1660 ppfree((void *) b->yy_ch_buf ,yyscanner );
1661
1662 ppfree((void *) b ,yyscanner );
1663}
1664
1665/* Initializes or reinitializes a buffer.
1666 * This function is sometimes called more than once on the same buffer,
1667 * such as during a pprestart() or at EOF.
1668 */
1669 static void pp_init_buffer (YY_BUFFER_STATE b, FILE * file , yyscan_t yyscanner)
1670
1671{
1672 int oerrno = errno;
1673 struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
1674
1675 pp_flush_buffer(b ,yyscanner);
1676
1677 b->yy_input_file = file;
1678 b->yy_fill_buffer = 1;
1679
1680 /* If b is the current buffer, then pp_init_buffer was _probably_
1681 * called from pprestart() or through yy_get_next_buffer.
1682 * In that case, we don't want to reset the lineno or column.
1683 */
1684 if (b != YY_CURRENT_BUFFER){
1685 b->yy_bs_lineno = 1;
1686 b->yy_bs_column = 0;
1687 }
1688
1689 b->yy_is_interactive = 0;
1690
1691 errno = oerrno;
1692}
1693
1694/** Discard all buffered characters. On the next scan, YY_INPUT will be called.
1695 * @param b the buffer state to be flushed, usually @c YY_CURRENT_BUFFER.
1696 * @param yyscanner The scanner object.
1697 */
1698 void pp_flush_buffer (YY_BUFFER_STATE b , yyscan_t yyscanner)
1699{
1700 struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
1701 if ( ! b )
1702 return;
1703
1704 b->yy_n_chars = 0;
1705
1706 /* We always need two end-of-buffer characters. The first causes
1707 * a transition to the end-of-buffer state. The second causes
1708 * a jam in that state.
1709 */
1710 b->yy_ch_buf[0] = YY_END_OF_BUFFER_CHAR;
1711 b->yy_ch_buf[1] = YY_END_OF_BUFFER_CHAR;
1712
1713 b->yy_buf_pos = &b->yy_ch_buf[0];
1714
1715 b->yy_at_bol = 1;
1716 b->yy_buffer_status = YY_BUFFER_NEW;
1717
1718 if ( b == YY_CURRENT_BUFFER )
1719 pp_load_buffer_state(yyscanner );
1720}
1721
1722/** Pushes the new state onto the stack. The new state becomes
1723 * the current state. This function will allocate the stack
1724 * if necessary.
1725 * @param new_buffer The new state.
1726 * @param yyscanner The scanner object.
1727 */
1728void pppush_buffer_state (YY_BUFFER_STATE new_buffer , yyscan_t yyscanner)
1729{
1730 struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
1731 if (new_buffer == NULL)
1732 return;
1733
1734 ppensure_buffer_stack(yyscanner);
1735
1736 /* This block is copied from pp_switch_to_buffer. */
1737 if ( YY_CURRENT_BUFFER )
1738 {
1739 /* Flush out information for old buffer. */
1740 *yyg->yy_c_buf_p = yyg->yy_hold_char;
1741 YY_CURRENT_BUFFER_LVALUE->yy_buf_pos = yyg->yy_c_buf_p;
1742 YY_CURRENT_BUFFER_LVALUE->yy_n_chars = yyg->yy_n_chars;
1743 }
1744
1745 /* Only push if top exists. Otherwise, replace top. */
1746 if (YY_CURRENT_BUFFER)
1747 yyg->yy_buffer_stack_top++;
1748 YY_CURRENT_BUFFER_LVALUE = new_buffer;
1749
1750 /* copied from pp_switch_to_buffer. */
1751 pp_load_buffer_state(yyscanner );
1752 yyg->yy_did_buffer_switch_on_eof = 1;
1753}
1754
1755/** Removes and deletes the top of the stack, if present.
1756 * The next element becomes the new top.
1757 * @param yyscanner The scanner object.
1758 */
1759void pppop_buffer_state (yyscan_t yyscanner)
1760{
1761 struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
1762 if (!YY_CURRENT_BUFFER)
1763 return;
1764
1765 pp_delete_buffer(YY_CURRENT_BUFFER ,yyscanner);
1766 YY_CURRENT_BUFFER_LVALUE = NULL;
1767 if (yyg->yy_buffer_stack_top > 0)
1768 --yyg->yy_buffer_stack_top;
1769
1770 if (YY_CURRENT_BUFFER) {
1771 pp_load_buffer_state(yyscanner );
1772 yyg->yy_did_buffer_switch_on_eof = 1;
1773 }
1774}
1775
1776/* Allocates the stack if it does not exist.
1777 * Guarantees space for at least one push.
1778 */
1779static void ppensure_buffer_stack (yyscan_t yyscanner)
1780{
1781 int num_to_alloc;
1782 struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
1783
1784 if (!yyg->yy_buffer_stack) {
1785
1786 /* First allocation is just for 2 elements, since we don't know if this
1787 * scanner will even need a stack. We use 2 instead of 1 to avoid an
1788 * immediate realloc on the next call.
1789 */
1790 num_to_alloc = 1;
1791 yyg->yy_buffer_stack = (struct yy_buffer_state**)ppalloc
1792 (num_to_alloc * sizeof(struct yy_buffer_state*)
1793 , yyscanner);
1794 if ( ! yyg->yy_buffer_stack )
1795 YY_FATAL_ERROR( "out of dynamic memory in ppensure_buffer_stack()" );
1796
1797 memset(yyg->yy_buffer_stack, 0, num_to_alloc * sizeof(struct yy_buffer_state*));
1798
1799 yyg->yy_buffer_stack_max = num_to_alloc;
1800 yyg->yy_buffer_stack_top = 0;
1801 return;
1802 }
1803
1804 if (yyg->yy_buffer_stack_top >= (yyg->yy_buffer_stack_max) - 1){
1805
1806 /* Increase the buffer to prepare for a possible push. */
1807 int grow_size = 8 /* arbitrary grow size */;
1808
1809 num_to_alloc = yyg->yy_buffer_stack_max + grow_size;
1810 yyg->yy_buffer_stack = (struct yy_buffer_state**)pprealloc
1811 (yyg->yy_buffer_stack,
1812 num_to_alloc * sizeof(struct yy_buffer_state*)
1813 , yyscanner);
1814 if ( ! yyg->yy_buffer_stack )
1815 YY_FATAL_ERROR( "out of dynamic memory in ppensure_buffer_stack()" );
1816
1817 /* zero only the new slots.*/
1818 memset(yyg->yy_buffer_stack + yyg->yy_buffer_stack_max, 0, grow_size * sizeof(struct yy_buffer_state*));
1819 yyg->yy_buffer_stack_max = num_to_alloc;
1820 }
1821}
1822
1823/** Setup the input buffer state to scan directly from a user-specified character buffer.
1824 * @param base the character buffer
1825 * @param size the size in bytes of the character buffer
1826 * @param yyscanner The scanner object.
1827 * @return the newly allocated buffer state object.
1828 */
1829YY_BUFFER_STATE pp_scan_buffer (char * base, yy_size_t size , yyscan_t yyscanner)
1830{
1831 YY_BUFFER_STATE b;
1832
1833 if ( size < 2 ||
1834 base[size-2] != YY_END_OF_BUFFER_CHAR ||
1835 base[size-1] != YY_END_OF_BUFFER_CHAR )
1836 /* They forgot to leave room for the EOB's. */
1837 return 0;
1838
1839 b = (YY_BUFFER_STATE) ppalloc(sizeof( struct yy_buffer_state ) ,yyscanner );
1840 if ( ! b )
1841 YY_FATAL_ERROR( "out of dynamic memory in pp_scan_buffer()" );
1842
1843 b->yy_buf_size = size - 2; /* "- 2" to take care of EOB's */
1844 b->yy_buf_pos = b->yy_ch_buf = base;
1845 b->yy_is_our_buffer = 0;
1846 b->yy_input_file = 0;
1847 b->yy_n_chars = b->yy_buf_size;
1848 b->yy_is_interactive = 0;
1849 b->yy_at_bol = 1;
1850 b->yy_fill_buffer = 0;
1851 b->yy_buffer_status = YY_BUFFER_NEW;
1852
1853 pp_switch_to_buffer(b ,yyscanner );
1854
1855 return b;
1856}
1857
1858/** Setup the input buffer state to scan a string. The next call to pplex() will
1859 * scan from a @e copy of @a str.
1860 * @param yystr a NUL-terminated string to scan
1861 * @param yyscanner The scanner object.
1862 * @return the newly allocated buffer state object.
1863 * @note If you want to scan bytes that may contain NUL values, then use
1864 * pp_scan_bytes() instead.
1865 */
1866YY_BUFFER_STATE pp_scan_string (yyconst char * yystr , yyscan_t yyscanner)
1867{
1868
1869 return pp_scan_bytes(yystr,strlen(yystr) ,yyscanner);
1870}
1871
1872/** Setup the input buffer state to scan the given bytes. The next call to pplex() will
1873 * scan from a @e copy of @a bytes.
1874 * @param bytes the byte buffer to scan
1875 * @param len the number of bytes in the buffer pointed to by @a bytes.
1876 * @param yyscanner The scanner object.
1877 * @return the newly allocated buffer state object.
1878 */
1879YY_BUFFER_STATE pp_scan_bytes (yyconst char * yybytes, int _yybytes_len , yyscan_t yyscanner)
1880{
1881 YY_BUFFER_STATE b;
1882 char *buf;
1883 yy_size_t n;
1884 int i;
1885
1886 /* Get memory for full buffer, including space for trailing EOB's. */
1887 n = _yybytes_len + 2;
1888 buf = (char *) ppalloc(n ,yyscanner );
1889 if ( ! buf )
1890 YY_FATAL_ERROR( "out of dynamic memory in pp_scan_bytes()" );
1891
1892 for ( i = 0; i < _yybytes_len; ++i )
1893 buf[i] = yybytes[i];
1894
1895 buf[_yybytes_len] = buf[_yybytes_len+1] = YY_END_OF_BUFFER_CHAR;
1896
1897 b = pp_scan_buffer(buf,n ,yyscanner);
1898 if ( ! b )
1899 YY_FATAL_ERROR( "bad buffer in pp_scan_bytes()" );
1900
1901 /* It's okay to grow etc. this buffer, and we should throw it
1902 * away when we're done.
1903 */
1904 b->yy_is_our_buffer = 1;
1905
1906 return b;
1907}
1908
1909#ifndef YY_EXIT_FAILURE
1910#define YY_EXIT_FAILURE 2
1911#endif
1912
1913static void yy_fatal_error (yyconst char* msg , yyscan_t yyscanner)
1914{
1915 (void) fprintf( stderr, "%s\n", msg );
1916 exit( YY_EXIT_FAILURE );
1917}
1918
1919/* Redefine yyless() so it works in section 3 code. */
1920
1921#undef yyless
1922#define yyless(n) \
1923 do \
1924 { \
1925 /* Undo effects of setting up yytext. */ \
1926 int yyless_macro_arg = (n); \
1927 YY_LESS_LINENO(yyless_macro_arg);\
1928 yytext[yyleng] = yyg->yy_hold_char; \
1929 yyg->yy_c_buf_p = yytext + yyless_macro_arg; \
1930 yyg->yy_hold_char = *yyg->yy_c_buf_p; \
1931 *yyg->yy_c_buf_p = '\0'; \
1932 yyleng = yyless_macro_arg; \
1933 } \
1934 while ( 0 )
1935
1936/* Accessor methods (get/set functions) to struct members. */
1937
1938/** Get the user-defined data for this scanner.
1939 * @param yyscanner The scanner object.
1940 */
1941YY_EXTRA_TYPE ppget_extra (yyscan_t yyscanner)
1942{
1943 struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
1944 return yyextra;
1945}
1946
1947/** Get the current line number.
1948 * @param yyscanner The scanner object.
1949 */
1950int ppget_lineno (yyscan_t yyscanner)
1951{
1952 struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
1953
1954 if (! YY_CURRENT_BUFFER)
1955 return 0;
1956
1957 return yylineno;
1958}
1959
1960/** Get the current column number.
1961 * @param yyscanner The scanner object.
1962 */
1963int ppget_column (yyscan_t yyscanner)
1964{
1965 struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
1966
1967 if (! YY_CURRENT_BUFFER)
1968 return 0;
1969
1970 return yycolumn;
1971}
1972
1973/** Get the input stream.
1974 * @param yyscanner The scanner object.
1975 */
1976FILE *ppget_in (yyscan_t yyscanner)
1977{
1978 struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
1979 return yyin;
1980}
1981
1982/** Get the output stream.
1983 * @param yyscanner The scanner object.
1984 */
1985FILE *ppget_out (yyscan_t yyscanner)
1986{
1987 struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
1988 return yyout;
1989}
1990
1991/** Get the length of the current token.
1992 * @param yyscanner The scanner object.
1993 */
1994int ppget_leng (yyscan_t yyscanner)
1995{
1996 struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
1997 return yyleng;
1998}
1999
2000/** Get the current token.
2001 * @param yyscanner The scanner object.
2002 */
2003
2004char *ppget_text (yyscan_t yyscanner)
2005{
2006 struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
2007 return yytext;
2008}
2009
2010/** Set the user-defined data. This data is never touched by the scanner.
2011 * @param user_defined The data to be associated with this scanner.
2012 * @param yyscanner The scanner object.
2013 */
2014void ppset_extra (YY_EXTRA_TYPE user_defined , yyscan_t yyscanner)
2015{
2016 struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
2017 yyextra = user_defined ;
2018}
2019
2020/** Set the current line number.
2021 * @param line_number
2022 * @param yyscanner The scanner object.
2023 */
2024void ppset_lineno (int line_number , yyscan_t yyscanner)
2025{
2026 struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
2027
2028 /* lineno is only valid if an input buffer exists. */
2029 if (! YY_CURRENT_BUFFER )
2030 yy_fatal_error( "ppset_lineno called with no buffer" , yyscanner);
2031
2032 yylineno = line_number;
2033}
2034
2035/** Set the current column.
2036 * @param line_number
2037 * @param yyscanner The scanner object.
2038 */
2039void ppset_column (int column_no , yyscan_t yyscanner)
2040{
2041 struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
2042
2043 /* column is only valid if an input buffer exists. */
2044 if (! YY_CURRENT_BUFFER )
2045 yy_fatal_error( "ppset_column called with no buffer" , yyscanner);
2046
2047 yycolumn = column_no;
2048}
2049
2050/** Set the input stream. This does not discard the current
2051 * input buffer.
2052 * @param in_str A readable stream.
2053 * @param yyscanner The scanner object.
2054 * @see pp_switch_to_buffer
2055 */
2056void ppset_in (FILE * in_str , yyscan_t yyscanner)
2057{
2058 struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
2059 yyin = in_str ;
2060}
2061
2062void ppset_out (FILE * out_str , yyscan_t yyscanner)
2063{
2064 struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
2065 yyout = out_str ;
2066}
2067
2068int ppget_debug (yyscan_t yyscanner)
2069{
2070 struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
2071 return yy_flex_debug;
2072}
2073
2074void ppset_debug (int bdebug , yyscan_t yyscanner)
2075{
2076 struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
2077 yy_flex_debug = bdebug ;
2078}
2079
2080/* Accessor methods for yylval and yylloc */
2081
2082YYSTYPE * ppget_lval (yyscan_t yyscanner)
2083{
2084 struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
2085 return yylval;
2086}
2087
2088void ppset_lval (YYSTYPE * yylval_param , yyscan_t yyscanner)
2089{
2090 struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
2091 yylval = yylval_param;
2092}
2093
2094YYLTYPE *ppget_lloc (yyscan_t yyscanner)
2095{
2096 struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
2097 return yylloc;
2098}
2099
2100void ppset_lloc (YYLTYPE * yylloc_param , yyscan_t yyscanner)
2101{
2102 struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
2103 yylloc = yylloc_param;
2104}
2105
2106/* User-visible API */
2107
2108/* pplex_init is special because it creates the scanner itself, so it is
2109 * the ONLY reentrant function that doesn't take the scanner as the last argument.
2110 * That's why we explicitly handle the declaration, instead of using our macros.
2111 */
2112
2113int pplex_init(yyscan_t* ptr_yy_globals)
2114
2115{
2116 if (ptr_yy_globals == NULL){
2117 errno = EINVAL;
2118 return 1;
2119 }
2120
2121 *ptr_yy_globals = (yyscan_t) ppalloc ( sizeof( struct yyguts_t ), NULL );
2122
2123 if (*ptr_yy_globals == NULL){
2124 errno = ENOMEM;
2125 return 1;
2126 }
2127
2128 /* By setting to 0xAA, we expose bugs in yy_init_globals. Leave at 0x00 for releases. */
2129 memset(*ptr_yy_globals,0x00,sizeof(struct yyguts_t));
2130
2131 return yy_init_globals ( *ptr_yy_globals );
2132}
2133
2134/* pplex_init_extra has the same functionality as pplex_init, but follows the
2135 * convention of taking the scanner as the last argument. Note however, that
2136 * this is a *pointer* to a scanner, as it will be allocated by this call (and
2137 * is the reason, too, why this function also must handle its own declaration).
2138 * The user defined value in the first argument will be available to ppalloc in
2139 * the yyextra field.
2140 */
2141
2142int pplex_init_extra(YY_EXTRA_TYPE yy_user_defined,yyscan_t* ptr_yy_globals )
2143
2144{
2145 struct yyguts_t dummy_yyguts;
2146
2147 ppset_extra (yy_user_defined, &dummy_yyguts);
2148
2149 if (ptr_yy_globals == NULL){
2150 errno = EINVAL;
2151 return 1;
2152 }
2153
2154 *ptr_yy_globals = (yyscan_t) ppalloc ( sizeof( struct yyguts_t ), &dummy_yyguts );
2155
2156 if (*ptr_yy_globals == NULL){
2157 errno = ENOMEM;
2158 return 1;
2159 }
2160
2161 /* By setting to 0xAA, we expose bugs in
2162 yy_init_globals. Leave at 0x00 for releases. */
2163 memset(*ptr_yy_globals,0x00,sizeof(struct yyguts_t));
2164
2165 ppset_extra (yy_user_defined, *ptr_yy_globals);
2166
2167 return yy_init_globals ( *ptr_yy_globals );
2168}
2169
2170static int yy_init_globals (yyscan_t yyscanner)
2171{
2172 struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
2173 /* Initialization is the same as for the non-reentrant scanner.
2174 * This function is called from pplex_destroy(), so don't allocate here.
2175 */
2176
2177 yyg->yy_buffer_stack = 0;
2178 yyg->yy_buffer_stack_top = 0;
2179 yyg->yy_buffer_stack_max = 0;
2180 yyg->yy_c_buf_p = (char *) 0;
2181 yyg->yy_init = 0;
2182 yyg->yy_start = 0;
2183
2184 yyg->yy_start_stack_ptr = 0;
2185 yyg->yy_start_stack_depth = 0;
2186 yyg->yy_start_stack = NULL;
2187
2188/* Defined in main.c */
2189#ifdef YY_STDINIT
2190 yyin = stdin;
2191 yyout = stdout;
2192#else
2193 yyin = (FILE *) 0;
2194 yyout = (FILE *) 0;
2195#endif
2196
2197 /* For future reference: Set errno on error, since we are called by
2198 * pplex_init()
2199 */
2200 return 0;
2201}
2202
2203/* pplex_destroy is for both reentrant and non-reentrant scanners. */
2204int pplex_destroy (yyscan_t yyscanner)
2205{
2206 struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
2207
2208 /* Pop the buffer stack, destroying each element. */
2209 while(YY_CURRENT_BUFFER){
2210 pp_delete_buffer(YY_CURRENT_BUFFER ,yyscanner );
2211 YY_CURRENT_BUFFER_LVALUE = NULL;
2212 pppop_buffer_state(yyscanner);
2213 }
2214
2215 /* Destroy the stack itself. */
2216 ppfree(yyg->yy_buffer_stack ,yyscanner);
2217 yyg->yy_buffer_stack = NULL;
2218
2219 /* Destroy the start condition stack. */
2220 ppfree(yyg->yy_start_stack ,yyscanner );
2221 yyg->yy_start_stack = NULL;
2222
2223 /* Reset the globals. This is important in a non-reentrant scanner so the next time
2224 * pplex() is called, initialization will occur. */
2225 yy_init_globals( yyscanner);
2226
2227 /* Destroy the main struct (reentrant only). */
2228 ppfree ( yyscanner , yyscanner );
2229 yyscanner = NULL;
2230 return 0;
2231}
2232
2233/*
2234 * Internal utility routines.
2235 */
2236
2237#ifndef yytext_ptr
2238static void yy_flex_strncpy (char* s1, yyconst char * s2, int n , yyscan_t yyscanner)
2239{
2240 register int i;
2241 for ( i = 0; i < n; ++i )
2242 s1[i] = s2[i];
2243}
2244#endif
2245
2246#ifdef YY_NEED_STRLEN
2247static int yy_flex_strlen (yyconst char * s , yyscan_t yyscanner)
2248{
2249 register int n;
2250 for ( n = 0; s[n]; ++n )
2251 ;
2252
2253 return n;
2254}
2255#endif
2256
2257void *ppalloc (yy_size_t size , yyscan_t yyscanner)
2258{
2259 return (void *) malloc( size );
2260}
2261
2262void *pprealloc (void * ptr, yy_size_t size , yyscan_t yyscanner)
2263{
2264 /* The cast to (char *) in the following accommodates both
2265 * implementations that use char* generic pointers, and those
2266 * that use void* generic pointers. It works with the latter
2267 * because both ANSI C and C++ allow castless assignment from
2268 * any pointer type to void*, and deal with argument conversions
2269 * as though doing an assignment.
2270 */
2271 return (void *) realloc( (char *) ptr, size );
2272}
2273
2274void ppfree (void * ptr , yyscan_t yyscanner)
2275{
2276 free( (char *) ptr ); /* see pprealloc() for (char *) cast */
2277}
2278
2279#define YYTABLES_NAME "yytables"
2280
2281namespace pp {
2282
alokp@chromium.orgc022c3a2012-07-09 15:56:42 +00002283// TODO(alokp): Maximum token length should ideally be specified by
2284// the preprocessor client, i.e., the compiler.
2285const size_t Tokenizer::kMaxTokenLength = 256;
2286
alokp@chromium.org2c958ee2012-05-17 20:35:42 +00002287Tokenizer::Tokenizer(Diagnostics* diagnostics) : mHandle(0)
alokp@chromium.org04d7d222012-05-16 19:24:07 +00002288{
alokp@chromium.org2c958ee2012-05-17 20:35:42 +00002289 mContext.diagnostics = diagnostics;
alokp@chromium.org04d7d222012-05-16 19:24:07 +00002290}
2291
2292Tokenizer::~Tokenizer()
2293{
2294 destroyScanner();
2295}
2296
2297bool Tokenizer::init(int count, const char* const string[], const int length[])
2298{
2299 if (count < 0) return false;
2300 if ((count > 0) && (string == 0)) return false;
2301
2302 mContext.input = Input(count, string, length);
2303 return initScanner();
2304}
2305
alokp@chromium.org46aa13d2012-06-15 15:40:27 +00002306void Tokenizer::setFileNumber(int file)
2307{
2308 // We use column number as file number.
2309 // See macro yyfileno.
2310 ppset_column(file,mHandle);
2311}
2312
2313void Tokenizer::setLineNumber(int line)
2314{
2315 ppset_lineno(line,mHandle);
2316}
2317
alokp@chromium.org04d7d222012-05-16 19:24:07 +00002318void Tokenizer::lex(Token* token)
2319{
alokp@chromium.org5b6a68e2012-06-28 20:29:13 +00002320 token->type = pplex(&token->text,&token->location,mHandle);
alokp@chromium.orgc022c3a2012-07-09 15:56:42 +00002321 if (token->text.size() > kMaxTokenLength)
2322 {
2323 mContext.diagnostics->report(Diagnostics::TOKEN_TOO_LONG,
2324 token->location, token->text);
2325 token->text.erase(kMaxTokenLength);
2326 }
2327
alokp@chromium.org7fc38dd2012-06-14 18:23:23 +00002328 token->flags = 0;
alokp@chromium.org04d7d222012-05-16 19:24:07 +00002329
alokp@chromium.org19d7aa62012-05-31 17:34:05 +00002330 token->setAtStartOfLine(mContext.lineStart);
2331 mContext.lineStart = token->type == '\n';
2332
alokp@chromium.org04d7d222012-05-16 19:24:07 +00002333 token->setHasLeadingSpace(mContext.leadingSpace);
2334 mContext.leadingSpace = false;
alokp@chromium.org04d7d222012-05-16 19:24:07 +00002335}
2336
2337bool Tokenizer::initScanner()
2338{
2339 if ((mHandle == NULL) && pplex_init_extra(&mContext,&mHandle))
2340 return false;
2341
2342 pprestart(0,mHandle);
2343 return true;
2344}
2345
2346void Tokenizer::destroyScanner()
2347{
2348 if (mHandle == NULL)
2349 return;
2350
2351 pplex_destroy(mHandle);
2352 mHandle = NULL;
2353}
2354
2355} // namespace pp
2356