├── .gitignore
├── CMakeLists.txt
├── MSVC
├── calc
│ ├── calc.vcxproj
│ └── calc.vcxproj.filters
├── getopt.c
├── getopt.h
├── greg-vs120.sln
├── greg-vs120.vcxproj
└── greg-vs120.vcxproj.filters
├── Makefile
├── README.md
├── compile.c
├── greg.c
├── greg.g
├── greg.h
├── greg.use
├── samples
├── .gitignore
├── Makefile
├── accept.c
├── accept.leg
├── accept.ref
├── basic.c
├── basic.leg
├── basic.ref
├── bench.bas
├── calc.leg
├── calc.ref
├── dc.c
├── dc.leg
├── dc.ref
├── dcv.c
├── dcv.leg
├── dcv.ref
├── fibonacci.bas
├── left.leg
├── rule.c
├── rule.leg
├── rule.ref
├── test.bas
├── test.c
├── test.leg
├── test.ref
├── username.leg
├── wc.leg
└── wc.ref
└── tree.c
/.gitignore:
--------------------------------------------------------------------------------
1 | *.[oa]
2 | greg
3 | greg.exe
4 | samples/*.leg.c
5 |
--------------------------------------------------------------------------------
/CMakeLists.txt:
--------------------------------------------------------------------------------
1 | cmake_minimum_required(VERSION 2.8)
2 | if(POLICY CMP0026)
3 | cmake_policy(SET CMP0026 OLD) # allow LOCATION usage
4 | endif(POLICY CMP0026)
5 | project(greg)
6 |
7 | set(sources greg.c compile.c tree.c)
8 |
9 | if (NOT MSVC)
10 | add_definitions(-g -Wall -O3 -DNDEBUG)
11 | else()
12 | add_library(wingetopt STATIC MSVC/getopt.c MSVC/getopt.h)
13 | include_directories(${CMAKE_CURRENT_LIST_DIR}/MSVC)
14 | add_definitions(-D_CRT_SECURE_NO_WARNINGS -D_CRT_NONSTDC_NO_DEPRECATE)
15 | # build as C++ for MSVC because C99 require VS2013+.
16 | set_source_files_properties(${sources} PROPERTIES LANGUAGE CXX)
17 | endif()
18 |
19 | add_executable(greg ${sources})
20 |
21 | if (MSVC)
22 | target_link_libraries(greg wingetopt)
23 | endif()
24 |
25 | # grammar
26 | get_target_property(greg_loc greg LOCATION)
27 | set(greg_c "${CMAKE_CURRENT_LIST_DIR}/greg.c")
28 | set(greg_g "${CMAKE_CURRENT_LIST_DIR}/greg.g")
29 | add_custom_target(grammar COMMAND ${greg_loc} -o ${greg_c} ${greg_g})
30 |
31 | # install
32 | install(TARGETS greg RUNTIME DESTINATION ${CMAKE_INSTALL_PREFIX}/bin)
33 |
34 |
--------------------------------------------------------------------------------
/MSVC/calc/calc.vcxproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | Debug
6 | Win32
7 |
8 |
9 | Release
10 | Win32
11 |
12 |
13 |
14 | {607AA625-3E9D-4691-B9A5-9BDBB4620AF1}
15 | Win32Proj
16 | calc
17 |
18 |
19 |
20 | Application
21 | true
22 | v120
23 | Unicode
24 |
25 |
26 | Application
27 | false
28 | v120
29 | true
30 | Unicode
31 |
32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 | true
44 |
45 |
46 | false
47 |
48 |
49 |
50 |
51 |
52 | Level3
53 | Disabled
54 | WIN32;_CRT_SECURE_NO_WARNINGS;_DEBUG;_CONSOLE;_LIB;YY_DEBUG=1;%(PreprocessorDefinitions)
55 |
56 |
57 | Console
58 | true
59 |
60 |
61 |
62 |
63 | Level3
64 |
65 |
66 | MaxSpeed
67 | true
68 | true
69 | WIN32;_CRT_SECURE_NO_WARNINGS;NDEBUG;_CONSOLE;_LIB;%(PreprocessorDefinitions)
70 |
71 |
72 | Console
73 | true
74 | true
75 | true
76 |
77 |
78 |
79 |
80 |
81 |
82 |
83 |
84 |
85 |
86 |
87 |
88 |
--------------------------------------------------------------------------------
/MSVC/calc/calc.vcxproj.filters:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | {4FC737F1-C7A5-4376-A066-2A32D752A2FF}
6 | cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx
7 |
8 |
9 | {93995380-89BD-4b04-88EB-625FBE52EBFB}
10 | h;hh;hpp;hxx;hm;inl;inc;xsd
11 |
12 |
13 | {67DA6AB6-F800-4c08-8B7A-83BB121AAD01}
14 | rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 | Fichiers sources
24 |
25 |
26 |
--------------------------------------------------------------------------------
/MSVC/getopt.c:
--------------------------------------------------------------------------------
1 | /* $OpenBSD: getopt_long.c,v 1.23 2007/10/31 12:34:57 chl Exp $ */
2 | /* $NetBSD: getopt_long.c,v 1.15 2002/01/31 22:43:40 tv Exp $ */
3 |
4 | /*
5 | * Copyright (c) 2002 Todd C. Miller
6 | *
7 | * Permission to use, copy, modify, and distribute this software for any
8 | * purpose with or without fee is hereby granted, provided that the above
9 | * copyright notice and this permission notice appear in all copies.
10 | *
11 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
12 | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
13 | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
14 | * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
15 | * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
16 | * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
17 | * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
18 | *
19 | * Sponsored in part by the Defense Advanced Research Projects
20 | * Agency (DARPA) and Air Force Research Laboratory, Air Force
21 | * Materiel Command, USAF, under agreement number F39502-99-1-0512.
22 | */
23 | /*-
24 | * Copyright (c) 2000 The NetBSD Foundation, Inc.
25 | * All rights reserved.
26 | *
27 | * This code is derived from software contributed to The NetBSD Foundation
28 | * by Dieter Baron and Thomas Klausner.
29 | *
30 | * Redistribution and use in source and binary forms, with or without
31 | * modification, are permitted provided that the following conditions
32 | * are met:
33 | * 1. Redistributions of source code must retain the above copyright
34 | * notice, this list of conditions and the following disclaimer.
35 | * 2. Redistributions in binary form must reproduce the above copyright
36 | * notice, this list of conditions and the following disclaimer in the
37 | * documentation and/or other materials provided with the distribution.
38 | *
39 | * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
40 | * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
41 | * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
42 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
43 | * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
44 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
45 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
46 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
47 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
48 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
49 | * POSSIBILITY OF SUCH DAMAGE.
50 | */
51 |
52 | #include
53 | #include
54 | #include
55 | #include
56 | #include
57 | #include
58 | #include
59 |
60 | #define REPLACE_GETOPT /* use this getopt as the system getopt(3) */
61 |
62 | #ifdef REPLACE_GETOPT
63 | int opterr = 1; /* if error message should be printed */
64 | int optind = 1; /* index into parent argv vector */
65 | int optopt = '?'; /* character checked for validity */
66 | #undef optreset /* see getopt.h */
67 | #define optreset __mingw_optreset
68 | int optreset; /* reset getopt */
69 | char *optarg; /* argument associated with option */
70 | #endif
71 |
72 | #define PRINT_ERROR ((opterr) && (*options != ':'))
73 |
74 | #define FLAG_PERMUTE 0x01 /* permute non-options to the end of argv */
75 | #define FLAG_ALLARGS 0x02 /* treat non-options as args to option "-1" */
76 | #define FLAG_LONGONLY 0x04 /* operate as getopt_long_only */
77 |
78 | /* return values */
79 | #define BADCH (int)'?'
80 | #define BADARG ((*options == ':') ? (int)':' : (int)'?')
81 | #define INORDER (int)1
82 |
83 | #ifndef __CYGWIN__
84 | #define __progname __argv[0]
85 | #else
86 | extern char __declspec(dllimport) *__progname;
87 | #endif
88 |
89 | #ifdef __CYGWIN__
90 | static char EMSG[] = "";
91 | #else
92 | #define EMSG ""
93 | #endif
94 |
95 | static int getopt_internal(int, char * const *, const char *,
96 | const struct option *, int *, int);
97 | static int parse_long_options(char * const *, const char *,
98 | const struct option *, int *, int);
99 | static int gcd(int, int);
100 | static void permute_args(int, int, int, char * const *);
101 |
102 | static char *place = EMSG; /* option letter processing */
103 |
104 | /* XXX: set optreset to 1 rather than these two */
105 | static int nonopt_start = -1; /* first non option argument (for permute) */
106 | static int nonopt_end = -1; /* first option after non options (for permute) */
107 |
108 | /* Error messages */
109 | static const char recargchar[] = "option requires an argument -- %c";
110 | static const char recargstring[] = "option requires an argument -- %s";
111 | static const char ambig[] = "ambiguous option -- %.*s";
112 | static const char noarg[] = "option doesn't take an argument -- %.*s";
113 | static const char illoptchar[] = "unknown option -- %c";
114 | static const char illoptstring[] = "unknown option -- %s";
115 |
116 | static void
117 | _vwarnx(const char *fmt,va_list ap)
118 | {
119 | (void)fprintf(stderr,"%s: ",__progname);
120 | if (fmt != NULL)
121 | (void)vfprintf(stderr,fmt,ap);
122 | (void)fprintf(stderr,"\n");
123 | }
124 |
125 | static void
126 | warnx(const char *fmt,...)
127 | {
128 | va_list ap;
129 | va_start(ap,fmt);
130 | _vwarnx(fmt,ap);
131 | va_end(ap);
132 | }
133 |
134 | /*
135 | * Compute the greatest common divisor of a and b.
136 | */
137 | static int
138 | gcd(int a, int b)
139 | {
140 | int c;
141 |
142 | c = a % b;
143 | while (c != 0) {
144 | a = b;
145 | b = c;
146 | c = a % b;
147 | }
148 |
149 | return (b);
150 | }
151 |
152 | /*
153 | * Exchange the block from nonopt_start to nonopt_end with the block
154 | * from nonopt_end to opt_end (keeping the same order of arguments
155 | * in each block).
156 | */
157 | static void
158 | permute_args(int panonopt_start, int panonopt_end, int opt_end,
159 | char * const *nargv)
160 | {
161 | int cstart, cyclelen, i, j, ncycle, nnonopts, nopts, pos;
162 | char *swap;
163 |
164 | /*
165 | * compute lengths of blocks and number and size of cycles
166 | */
167 | nnonopts = panonopt_end - panonopt_start;
168 | nopts = opt_end - panonopt_end;
169 | ncycle = gcd(nnonopts, nopts);
170 | cyclelen = (opt_end - panonopt_start) / ncycle;
171 |
172 | for (i = 0; i < ncycle; i++) {
173 | cstart = panonopt_end+i;
174 | pos = cstart;
175 | for (j = 0; j < cyclelen; j++) {
176 | if (pos >= panonopt_end)
177 | pos -= nnonopts;
178 | else
179 | pos += nopts;
180 | swap = nargv[pos];
181 | /* LINTED const cast */
182 | ((char **) nargv)[pos] = nargv[cstart];
183 | /* LINTED const cast */
184 | ((char **)nargv)[cstart] = swap;
185 | }
186 | }
187 | }
188 |
189 | /*
190 | * parse_long_options --
191 | * Parse long options in argc/argv argument vector.
192 | * Returns -1 if short_too is set and the option does not match long_options.
193 | */
194 | static int
195 | parse_long_options(char * const *nargv, const char *options,
196 | const struct option *long_options, int *idx, int short_too)
197 | {
198 | char *current_argv, *has_equal;
199 | size_t current_argv_len;
200 | int i, ambiguous, match;
201 |
202 | #define IDENTICAL_INTERPRETATION(_x, _y) \
203 | (long_options[(_x)].has_arg == long_options[(_y)].has_arg && \
204 | long_options[(_x)].flag == long_options[(_y)].flag && \
205 | long_options[(_x)].val == long_options[(_y)].val)
206 |
207 | current_argv = place;
208 | match = -1;
209 | ambiguous = 0;
210 |
211 | optind++;
212 |
213 | if ((has_equal = strchr(current_argv, '=')) != NULL) {
214 | /* argument found (--option=arg) */
215 | current_argv_len = has_equal - current_argv;
216 | has_equal++;
217 | } else
218 | current_argv_len = strlen(current_argv);
219 |
220 | for (i = 0; long_options[i].name; i++) {
221 | /* find matching long option */
222 | if (strncmp(current_argv, long_options[i].name,
223 | current_argv_len))
224 | continue;
225 |
226 | if (strlen(long_options[i].name) == current_argv_len) {
227 | /* exact match */
228 | match = i;
229 | ambiguous = 0;
230 | break;
231 | }
232 | /*
233 | * If this is a known short option, don't allow
234 | * a partial match of a single character.
235 | */
236 | if (short_too && current_argv_len == 1)
237 | continue;
238 |
239 | if (match == -1) /* partial match */
240 | match = i;
241 | else if (!IDENTICAL_INTERPRETATION(i, match))
242 | ambiguous = 1;
243 | }
244 | if (ambiguous) {
245 | /* ambiguous abbreviation */
246 | if (PRINT_ERROR)
247 | warnx(ambig, (int)current_argv_len,
248 | current_argv);
249 | optopt = 0;
250 | return (BADCH);
251 | }
252 | if (match != -1) { /* option found */
253 | if (long_options[match].has_arg == no_argument
254 | && has_equal) {
255 | if (PRINT_ERROR)
256 | warnx(noarg, (int)current_argv_len,
257 | current_argv);
258 | /*
259 | * XXX: GNU sets optopt to val regardless of flag
260 | */
261 | if (long_options[match].flag == NULL)
262 | optopt = long_options[match].val;
263 | else
264 | optopt = 0;
265 | return (BADARG);
266 | }
267 | if (long_options[match].has_arg == required_argument ||
268 | long_options[match].has_arg == optional_argument) {
269 | if (has_equal)
270 | optarg = has_equal;
271 | else if (long_options[match].has_arg ==
272 | required_argument) {
273 | /*
274 | * optional argument doesn't use next nargv
275 | */
276 | optarg = nargv[optind++];
277 | }
278 | }
279 | if ((long_options[match].has_arg == required_argument)
280 | && (optarg == NULL)) {
281 | /*
282 | * Missing argument; leading ':' indicates no error
283 | * should be generated.
284 | */
285 | if (PRINT_ERROR)
286 | warnx(recargstring,
287 | current_argv);
288 | /*
289 | * XXX: GNU sets optopt to val regardless of flag
290 | */
291 | if (long_options[match].flag == NULL)
292 | optopt = long_options[match].val;
293 | else
294 | optopt = 0;
295 | --optind;
296 | return (BADARG);
297 | }
298 | } else { /* unknown option */
299 | if (short_too) {
300 | --optind;
301 | return (-1);
302 | }
303 | if (PRINT_ERROR)
304 | warnx(illoptstring, current_argv);
305 | optopt = 0;
306 | return (BADCH);
307 | }
308 | if (idx)
309 | *idx = match;
310 | if (long_options[match].flag) {
311 | *long_options[match].flag = long_options[match].val;
312 | return (0);
313 | } else
314 | return (long_options[match].val);
315 | #undef IDENTICAL_INTERPRETATION
316 | }
317 |
318 | /*
319 | * getopt_internal --
320 | * Parse argc/argv argument vector. Called by user level routines.
321 | */
322 | static int
323 | getopt_internal(int nargc, char * const *nargv, const char *options,
324 | const struct option *long_options, int *idx, int flags)
325 | {
326 | char *oli; /* option letter list index */
327 | int optchar, short_too;
328 | static int posixly_correct = -1;
329 |
330 | if (options == NULL)
331 | return (-1);
332 |
333 | /*
334 | * XXX Some GNU programs (like cvs) set optind to 0 instead of
335 | * XXX using optreset. Work around this braindamage.
336 | */
337 | if (optind == 0)
338 | optind = optreset = 1;
339 |
340 | /*
341 | * Disable GNU extensions if POSIXLY_CORRECT is set or options
342 | * string begins with a '+'.
343 | *
344 | * CV, 2009-12-14: Check POSIXLY_CORRECT anew if optind == 0 or
345 | * optreset != 0 for GNU compatibility.
346 | */
347 | if (posixly_correct == -1 || optreset != 0)
348 | posixly_correct = (getenv("POSIXLY_CORRECT") != NULL);
349 | if (*options == '-')
350 | flags |= FLAG_ALLARGS;
351 | else if (posixly_correct || *options == '+')
352 | flags &= ~FLAG_PERMUTE;
353 | if (*options == '+' || *options == '-')
354 | options++;
355 |
356 | optarg = NULL;
357 | if (optreset)
358 | nonopt_start = nonopt_end = -1;
359 | start:
360 | if (optreset || !*place) { /* update scanning pointer */
361 | optreset = 0;
362 | if (optind >= nargc) { /* end of argument vector */
363 | place = EMSG;
364 | if (nonopt_end != -1) {
365 | /* do permutation, if we have to */
366 | permute_args(nonopt_start, nonopt_end,
367 | optind, nargv);
368 | optind -= nonopt_end - nonopt_start;
369 | }
370 | else if (nonopt_start != -1) {
371 | /*
372 | * If we skipped non-options, set optind
373 | * to the first of them.
374 | */
375 | optind = nonopt_start;
376 | }
377 | nonopt_start = nonopt_end = -1;
378 | return (-1);
379 | }
380 | if (*(place = nargv[optind]) != '-' ||
381 | (place[1] == '\0' && strchr(options, '-') == NULL)) {
382 | place = EMSG; /* found non-option */
383 | if (flags & FLAG_ALLARGS) {
384 | /*
385 | * GNU extension:
386 | * return non-option as argument to option 1
387 | */
388 | optarg = nargv[optind++];
389 | return (INORDER);
390 | }
391 | if (!(flags & FLAG_PERMUTE)) {
392 | /*
393 | * If no permutation wanted, stop parsing
394 | * at first non-option.
395 | */
396 | return (-1);
397 | }
398 | /* do permutation */
399 | if (nonopt_start == -1)
400 | nonopt_start = optind;
401 | else if (nonopt_end != -1) {
402 | permute_args(nonopt_start, nonopt_end,
403 | optind, nargv);
404 | nonopt_start = optind -
405 | (nonopt_end - nonopt_start);
406 | nonopt_end = -1;
407 | }
408 | optind++;
409 | /* process next argument */
410 | goto start;
411 | }
412 | if (nonopt_start != -1 && nonopt_end == -1)
413 | nonopt_end = optind;
414 |
415 | /*
416 | * If we have "-" do nothing, if "--" we are done.
417 | */
418 | if (place[1] != '\0' && *++place == '-' && place[1] == '\0') {
419 | optind++;
420 | place = EMSG;
421 | /*
422 | * We found an option (--), so if we skipped
423 | * non-options, we have to permute.
424 | */
425 | if (nonopt_end != -1) {
426 | permute_args(nonopt_start, nonopt_end,
427 | optind, nargv);
428 | optind -= nonopt_end - nonopt_start;
429 | }
430 | nonopt_start = nonopt_end = -1;
431 | return (-1);
432 | }
433 | }
434 |
435 | /*
436 | * Check long options if:
437 | * 1) we were passed some
438 | * 2) the arg is not just "-"
439 | * 3) either the arg starts with -- we are getopt_long_only()
440 | */
441 | if (long_options != NULL && place != nargv[optind] &&
442 | (*place == '-' || (flags & FLAG_LONGONLY))) {
443 | short_too = 0;
444 | if (*place == '-')
445 | place++; /* --foo long option */
446 | else if (*place != ':' && strchr(options, *place) != NULL)
447 | short_too = 1; /* could be short option too */
448 |
449 | optchar = parse_long_options(nargv, options, long_options,
450 | idx, short_too);
451 | if (optchar != -1) {
452 | place = EMSG;
453 | return (optchar);
454 | }
455 | }
456 |
457 | if ((optchar = (int)*place++) == (int)':' ||
458 | (optchar == (int)'-' && *place != '\0') ||
459 | (oli = strchr(options, optchar)) == NULL) {
460 | /*
461 | * If the user specified "-" and '-' isn't listed in
462 | * options, return -1 (non-option) as per POSIX.
463 | * Otherwise, it is an unknown option character (or ':').
464 | */
465 | if (optchar == (int)'-' && *place == '\0')
466 | return (-1);
467 | if (!*place)
468 | ++optind;
469 | if (PRINT_ERROR)
470 | warnx(illoptchar, optchar);
471 | optopt = optchar;
472 | return (BADCH);
473 | }
474 | if (long_options != NULL && optchar == 'W' && oli[1] == ';') {
475 | /* -W long-option */
476 | if (*place) /* no space */
477 | /* NOTHING */;
478 | else if (++optind >= nargc) { /* no arg */
479 | place = EMSG;
480 | if (PRINT_ERROR)
481 | warnx(recargchar, optchar);
482 | optopt = optchar;
483 | return (BADARG);
484 | } else /* white space */
485 | place = nargv[optind];
486 | optchar = parse_long_options(nargv, options, long_options,
487 | idx, 0);
488 | place = EMSG;
489 | return (optchar);
490 | }
491 | if (*++oli != ':') { /* doesn't take argument */
492 | if (!*place)
493 | ++optind;
494 | } else { /* takes (optional) argument */
495 | optarg = NULL;
496 | if (*place) /* no white space */
497 | optarg = place;
498 | else if (oli[1] != ':') { /* arg not optional */
499 | if (++optind >= nargc) { /* no arg */
500 | place = EMSG;
501 | if (PRINT_ERROR)
502 | warnx(recargchar, optchar);
503 | optopt = optchar;
504 | return (BADARG);
505 | } else
506 | optarg = nargv[optind];
507 | }
508 | place = EMSG;
509 | ++optind;
510 | }
511 | /* dump back option letter */
512 | return (optchar);
513 | }
514 |
515 | #ifdef REPLACE_GETOPT
516 | /*
517 | * getopt --
518 | * Parse argc/argv argument vector.
519 | *
520 | * [eventually this will replace the BSD getopt]
521 | */
522 | int
523 | getopt(int nargc, char * const *nargv, const char *options)
524 | {
525 |
526 | /*
527 | * We don't pass FLAG_PERMUTE to getopt_internal() since
528 | * the BSD getopt(3) (unlike GNU) has never done this.
529 | *
530 | * Furthermore, since many privileged programs call getopt()
531 | * before dropping privileges it makes sense to keep things
532 | * as simple (and bug-free) as possible.
533 | */
534 | return (getopt_internal(nargc, nargv, options, NULL, NULL, 0));
535 | }
536 | #endif /* REPLACE_GETOPT */
537 |
538 | /*
539 | * getopt_long --
540 | * Parse argc/argv argument vector.
541 | */
542 | int
543 | getopt_long(int nargc, char * const *nargv, const char *options,
544 | const struct option *long_options, int *idx)
545 | {
546 |
547 | return (getopt_internal(nargc, nargv, options, long_options, idx,
548 | FLAG_PERMUTE));
549 | }
550 |
551 | /*
552 | * getopt_long_only --
553 | * Parse argc/argv argument vector.
554 | */
555 | int
556 | getopt_long_only(int nargc, char * const *nargv, const char *options,
557 | const struct option *long_options, int *idx)
558 | {
559 |
560 | return (getopt_internal(nargc, nargv, options, long_options, idx,
561 | FLAG_PERMUTE|FLAG_LONGONLY));
562 | }
--------------------------------------------------------------------------------
/MSVC/getopt.h:
--------------------------------------------------------------------------------
1 | #ifndef __GETOPT_H__
2 | /**
3 | * DISCLAIMER
4 | * This file has no copyright assigned and is placed in the Public Domain.
5 | * This file is a part of the w64 mingw-runtime package.
6 | *
7 | * The w64 mingw-runtime package and its code is distributed in the hope that it
8 | * will be useful but WITHOUT ANY WARRANTY. ALL WARRANTIES, EXPRESSED OR
9 | * IMPLIED ARE HEREBY DISCLAIMED. This includes but is not limited to
10 | * warranties of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
11 | */
12 |
13 | #define __GETOPT_H__
14 |
15 | /* All the headers include this file. */
16 | #include
17 |
18 | #ifdef __cplusplus
19 | extern "C" {
20 | #endif
21 |
22 | extern int optind; /* index of first non-option in argv */
23 | extern int optopt; /* single option character, as parsed */
24 | extern int opterr; /* flag to enable built-in diagnostics... */
25 | /* (user may set to zero, to suppress) */
26 |
27 | extern char *optarg; /* pointer to argument of current option */
28 |
29 | extern int getopt(int nargc, char * const *nargv, const char *options);
30 |
31 | #ifdef _BSD_SOURCE
32 | /*
33 | * BSD adds the non-standard `optreset' feature, for reinitialisation
34 | * of `getopt' parsing. We support this feature, for applications which
35 | * proclaim their BSD heritage, before including this header; however,
36 | * to maintain portability, developers are advised to avoid it.
37 | */
38 | # define optreset __mingw_optreset
39 | extern int optreset;
40 | #endif
41 | #ifdef __cplusplus
42 | }
43 | #endif
44 | /*
45 | * POSIX requires the `getopt' API to be specified in `unistd.h';
46 | * thus, `unistd.h' includes this header. However, we do not want
47 | * to expose the `getopt_long' or `getopt_long_only' APIs, when
48 | * included in this manner. Thus, close the standard __GETOPT_H__
49 | * declarations block, and open an additional __GETOPT_LONG_H__
50 | * specific block, only when *not* __UNISTD_H_SOURCED__, in which
51 | * to declare the extended API.
52 | */
53 | #endif /* !defined(__GETOPT_H__) */
54 |
55 | #if !defined(__UNISTD_H_SOURCED__) && !defined(__GETOPT_LONG_H__)
56 | #define __GETOPT_LONG_H__
57 |
58 | #ifdef __cplusplus
59 | extern "C" {
60 | #endif
61 |
62 | struct option /* specification for a long form option... */
63 | {
64 | const char *name; /* option name, without leading hyphens */
65 | int has_arg; /* does it take an argument? */
66 | int *flag; /* where to save its status, or NULL */
67 | int val; /* its associated status value */
68 | };
69 |
70 | enum /* permitted values for its `has_arg' field... */
71 | {
72 | no_argument = 0, /* option never takes an argument */
73 | required_argument, /* option always requires an argument */
74 | optional_argument /* option may take an argument */
75 | };
76 |
77 | extern int getopt_long(int nargc, char * const *nargv, const char *options,
78 | const struct option *long_options, int *idx);
79 | extern int getopt_long_only(int nargc, char * const *nargv, const char *options,
80 | const struct option *long_options, int *idx);
81 | /*
82 | * Previous MinGW implementation had...
83 | */
84 | #ifndef HAVE_DECL_GETOPT
85 | /*
86 | * ...for the long form API only; keep this for compatibility.
87 | */
88 | # define HAVE_DECL_GETOPT 1
89 | #endif
90 |
91 | #ifdef __cplusplus
92 | }
93 | #endif
94 |
95 | #endif /* !defined(__UNISTD_H_SOURCED__) && !defined(__GETOPT_LONG_H__) */
--------------------------------------------------------------------------------
/MSVC/greg-vs120.sln:
--------------------------------------------------------------------------------
1 |
2 | Microsoft Visual Studio Solution File, Format Version 12.00
3 | # Visual Studio Express 2013 for Windows Desktop
4 | VisualStudioVersion = 12.0.40629.0
5 | MinimumVisualStudioVersion = 10.0.40219.1
6 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "greg", "greg-vs120.vcxproj", "{DE253F1D-68B4-4A2B-A6FD-1A7176934DD1}"
7 | EndProject
8 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "calc", "calc\calc.vcxproj", "{607AA625-3E9D-4691-B9A5-9BDBB4620AF1}"
9 | EndProject
10 | Global
11 | GlobalSection(SolutionConfigurationPlatforms) = preSolution
12 | Debug|Win32 = Debug|Win32
13 | Release|Win32 = Release|Win32
14 | Unicode Debug|Win32 = Unicode Debug|Win32
15 | Unicode Release|Win32 = Unicode Release|Win32
16 | EndGlobalSection
17 | GlobalSection(ProjectConfigurationPlatforms) = postSolution
18 | {DE253F1D-68B4-4A2B-A6FD-1A7176934DD1}.Debug|Win32.ActiveCfg = Debug|Win32
19 | {DE253F1D-68B4-4A2B-A6FD-1A7176934DD1}.Debug|Win32.Build.0 = Debug|Win32
20 | {DE253F1D-68B4-4A2B-A6FD-1A7176934DD1}.Release|Win32.ActiveCfg = Release|Win32
21 | {DE253F1D-68B4-4A2B-A6FD-1A7176934DD1}.Release|Win32.Build.0 = Release|Win32
22 | {DE253F1D-68B4-4A2B-A6FD-1A7176934DD1}.Unicode Debug|Win32.ActiveCfg = Debug|Win32
23 | {DE253F1D-68B4-4A2B-A6FD-1A7176934DD1}.Unicode Debug|Win32.Build.0 = Debug|Win32
24 | {DE253F1D-68B4-4A2B-A6FD-1A7176934DD1}.Unicode Release|Win32.ActiveCfg = Release|Win32
25 | {DE253F1D-68B4-4A2B-A6FD-1A7176934DD1}.Unicode Release|Win32.Build.0 = Release|Win32
26 | {607AA625-3E9D-4691-B9A5-9BDBB4620AF1}.Debug|Win32.ActiveCfg = Debug|Win32
27 | {607AA625-3E9D-4691-B9A5-9BDBB4620AF1}.Debug|Win32.Build.0 = Debug|Win32
28 | {607AA625-3E9D-4691-B9A5-9BDBB4620AF1}.Release|Win32.ActiveCfg = Release|Win32
29 | {607AA625-3E9D-4691-B9A5-9BDBB4620AF1}.Release|Win32.Build.0 = Release|Win32
30 | {607AA625-3E9D-4691-B9A5-9BDBB4620AF1}.Unicode Debug|Win32.ActiveCfg = Debug|Win32
31 | {607AA625-3E9D-4691-B9A5-9BDBB4620AF1}.Unicode Debug|Win32.Build.0 = Debug|Win32
32 | {607AA625-3E9D-4691-B9A5-9BDBB4620AF1}.Unicode Release|Win32.ActiveCfg = Release|Win32
33 | {607AA625-3E9D-4691-B9A5-9BDBB4620AF1}.Unicode Release|Win32.Build.0 = Release|Win32
34 | EndGlobalSection
35 | GlobalSection(SolutionProperties) = preSolution
36 | HideSolutionNode = FALSE
37 | EndGlobalSection
38 | EndGlobal
39 |
--------------------------------------------------------------------------------
/MSVC/greg-vs120.vcxproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | Debug
6 | Win32
7 |
8 |
9 | Release
10 | Win32
11 |
12 |
13 |
14 | {DE253F1D-68B4-4A2B-A6FD-1A7176934DD1}
15 | Win32Proj
16 | gregvs120
17 | greg
18 |
19 |
20 |
21 | Application
22 | true
23 | v120
24 | Unicode
25 |
26 |
27 | Application
28 | false
29 | v120
30 | true
31 | Unicode
32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
44 | true
45 | $(SolutionDir)
46 | $(ProjectName)d
47 |
48 |
49 | false
50 | $(SolutionDir)
51 |
52 |
53 |
54 |
55 |
56 | Level3
57 | Disabled
58 | WIN32;_CRT_SECURE_NO_WARNINGS;_DEBUG;_CONSOLE;_LIB;%(PreprocessorDefinitions)
59 | .
60 |
61 |
62 | Console
63 | true
64 |
65 |
66 |
67 |
68 | Level3
69 |
70 |
71 | MaxSpeed
72 | true
73 | true
74 | WIN32;_CRT_SECURE_NO_WARNINGS;NDEBUG;_CONSOLE;_LIB;%(PreprocessorDefinitions)
75 | .
76 |
77 |
78 | Console
79 | true
80 | true
81 | true
82 |
83 |
84 |
85 |
86 |
87 |
88 |
89 |
90 |
91 |
92 |
93 |
94 |
95 |
96 |
97 |
98 |
99 |
100 |
101 |
--------------------------------------------------------------------------------
/MSVC/greg-vs120.vcxproj.filters:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | {4FC737F1-C7A5-4376-A066-2A32D752A2FF}
6 | cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx
7 |
8 |
9 | {93995380-89BD-4b04-88EB-625FBE52EBFB}
10 | h;hh;hpp;hxx;hm;inl;inc;xsd
11 |
12 |
13 | {67DA6AB6-F800-4c08-8B7A-83BB121AAD01}
14 | rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms
15 |
16 |
17 |
18 |
19 | Fichiers sources
20 |
21 |
22 | Fichiers sources
23 |
24 |
25 | Fichiers sources
26 |
27 |
28 | Fichiers sources
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
37 | Fichiers d%27en-tête
38 |
39 |
40 | Fichiers d%27en-tête
41 |
42 |
43 |
--------------------------------------------------------------------------------
/Makefile:
--------------------------------------------------------------------------------
1 | CFLAGS = -g -Wall $(OFLAGS) $(XFLAGS)
2 | OFLAGS = -O3 -DNDEBUG
3 | #OFLAGS = -pg
4 |
5 | OBJS = tree.o compile.o
6 |
7 | all : greg
8 |
9 | greg : greg.o $(OBJS)
10 | $(CC) $(CFLAGS) -o $@-new greg.o $(OBJS)
11 | mv $@-new $@
12 |
13 | ROOT =
14 | PREFIX ?= /usr
15 | BINDIR = $(ROOT)$(PREFIX)/bin
16 |
17 | install : $(BINDIR)/greg
18 |
19 | $(BINDIR)/% : %
20 | cp -p $< $@
21 | strip $@
22 |
23 | uninstall : .FORCE
24 | rm -f $(BINDIR)/greg
25 |
26 | greg.o : greg.c
27 |
28 | grammar : .FORCE
29 | ./greg -o greg.c greg.g
30 |
31 | clean : .FORCE
32 | rm -rf *~ *.o *.greg.[cd] greg samples/*.o samples/calc samples/*.dSYM testing1.c testing2.c *.dSYM selftest/
33 |
34 | spotless : clean .FORCE
35 | rm -f greg
36 |
37 | samples/calc.c: samples/calc.leg greg
38 | ./greg -o $@ $<
39 |
40 | samples/calc: samples/calc.c
41 | $(CC) $(CFLAGS) -o $@ $<
42 |
43 | test: samples/calc greg-testing
44 | echo '21 * 2 + 0' | ./samples/calc | grep 42
45 |
46 | run: greg.g greg
47 | mkdir -p selftest
48 | ./greg -o testing1.c greg.g
49 | $(CC) $(CFLAGS) -o selftest/testing1 testing1.c $(OBJS)
50 | $(TOOL) ./selftest/testing1 -o testing2.c greg.g
51 | $(CC) $(CFLAGS) -o selftest/testing2 testing2.c $(OBJS)
52 | $(TOOL) ./selftest/testing2 -o selftest/calc.c ./samples/calc.leg
53 | $(CC) $(CFLAGS) -o selftest/calc selftest/calc.c
54 | $(TOOL) echo '21 * 2 + 0' | ./selftest/calc | grep 42
55 |
56 | .FORCE :
57 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # greg
2 |
3 | greg used to be _why's fork of Ian Piumarta's peg/leg, with the following differences:
4 |
5 | * Re-entrant
6 | * Some bug fixes
7 |
8 | Since then, better error handling and other various features have been added.
9 |
10 | ## Links
11 |
12 | * [Ian Piumarta's peg/leg](http://piumarta.com/software/peg/)
13 | * [2004 PEG paper](http://pdos.csail.mit.edu/papers/parsing%3Apopl04.pdf)
14 |
15 | The most comprehensive example of greg usage is in [nagaqueen][nagaqueen],
16 | an ooc grammar, used in [rock][rock], an [ooc][ooc] compiler written in ooc.
17 |
18 | [nagaqueen]: http://github.com/nddrylliog/nagaqueen
19 | [rock]: http://github.com/nddrylliog/rock
20 | [ooc]: http://ooc-lang.org
21 |
22 | ## Build instructions
23 |
24 | With a GCC-like compiler, `make` should give you a greg executable.
25 |
26 | If you modify `greg.g` (greg's own grammar is written in LEG), run `make grammar` to
27 | regenerate `greg.c` using greg itself, then run `make` again to build it.
28 |
29 | ## Contributor guidelines
30 |
31 | * [GitHub pull requests](https://github.com/nddrylliog/greg/pulls) are the preferred way to submit contributions.
32 | * Don't modify `greg.c`, instead, modify `greg.g` and regenerate it as shown above.
33 | * Make sure greg is still self-hosting before you submit your code.
34 | * Major changes warrant a version bump, but they also warrant discussions.
35 |
36 | For a list of contributors, see the [GitHub contributor graph](https://github.com/nddrylliog/greg/graphs/contributors).
37 |
38 | ## License
39 |
40 | peg/leg is copyright (c) 2007 by Ian Piumarta released under an MIT license. As is greg.
41 |
--------------------------------------------------------------------------------
/compile.c:
--------------------------------------------------------------------------------
1 | /* Copyright (c) 2007 by Ian Piumarta
2 | * All rights reserved.
3 | *
4 | * Permission is hereby granted, free of charge, to any person obtaining a
5 | * copy of this software and associated documentation files (the 'Software'),
6 | * to deal in the Software without restriction, including without limitation
7 | * the rights to use, copy, modify, merge, publish, distribute, and/or sell
8 | * copies of the Software, and to permit persons to whom the Software is
9 | * furnished to do so, provided that the above copyright notice(s) and this
10 | * permission notice appear in all copies of the Software. Acknowledgement
11 | * of the use of this Software in supporting documentation would be
12 | * appreciated but is not required.
13 | *
14 | * THE SOFTWARE IS PROVIDED 'AS IS'. USE ENTIRELY AT YOUR OWN RISK.
15 | *
16 | * Last edited: 2007-08-31 13:55:23 by piumarta on emilia.local
17 | */
18 |
19 | #include
20 | #include
21 | #include
22 | #include
23 |
24 | #include "greg.h"
25 |
26 | static int yyl(void)
27 | {
28 | static int prev= 0;
29 | return ++prev;
30 | }
31 |
32 | static void charClassSet (unsigned char bits[], int c) { bits[c >> 3] |= (1 << (c & 7)); }
33 | static void charClassClear(unsigned char bits[], int c) { bits[c >> 3] &= ~(1 << (c & 7)); }
34 |
35 | typedef void (*setter)(unsigned char bits[], int c);
36 |
37 | static int readChar(unsigned char **cp)
38 | {
39 | unsigned char *cclass = *cp;
40 | int c= *cclass++, i = 0;
41 | if ('\\' == c && *cclass)
42 | {
43 | c= *cclass++;
44 | if (c >= '0' && c <= '9')
45 | {
46 | unsigned char oct= 0;
47 | for (i= 2; i >= 0; i--) {
48 | if (!(c >= '0' && c <= '9'))
49 | break;
50 | oct= (oct * 8) + (c - '0');
51 | c= *cclass++;
52 | }
53 | cclass--;
54 | c= oct;
55 | goto done;
56 | }
57 |
58 | switch (c)
59 | {
60 | case 'a': c= '\a'; break; /* bel */
61 | case 'b': c= '\b'; break; /* bs */
62 | case 'e': c= '\033'; break; /* esc */
63 | case 'f': c= '\f'; break; /* ff */
64 | case 'n': c= '\n'; break; /* nl */
65 | case 'r': c= '\r'; break; /* cr */
66 | case 't': c= '\t'; break; /* ht */
67 | case 'v': c= '\v'; break; /* vt */
68 | default: break;
69 | }
70 | }
71 |
72 | done:
73 | *cp = cclass;
74 | return c;
75 | }
76 |
77 | static char *yyqq(char* s) {
78 | char *d = s;
79 | char *dst;
80 | int sl = 0, dl = 0;
81 | while (*s++) {
82 | dl++; sl++;
83 | if (*s==7||*s==8||*s==9||*s==11||*s==12||*s==13||*s==27||*s==34||*s=='%'||*s==92) { dl++; } /* escape with '\' */
84 | else if (*s==10) { dl += 3; } /* \n\^J */
85 | else if (*(signed char*)s<32) { dl += 4; } /* octal \000 */
86 | }
87 | if (dl == sl) return d;
88 | s = d;
89 | dst = d = (char *)malloc(dl+1);
90 | while (*s) {
91 | if (*s == '"') {
92 | *d++ = '\\'; *d++ = *s++;
93 | } else if (*s == '%') { /* '%' in printf */
94 | *d++ = '%'; *d++ = *s++;
95 | } else if (*s == '\n') { /* \n\^J */
96 | *d++ = '\\'; *d++ = 'n'; *d++ = '\\'; *d++ = 10; s++;
97 | } else if (*s == '\t') { /* ht */
98 | *d++ = '\\'; *d++ = 't'; s++;
99 | } else if (*s == '\r') { /*cr */
100 | *d++ = '\\'; *d++ = 'r'; s++;
101 | } else if (*s == '\a') { /*bel*/
102 | *d++ = '\\'; *d++ = 'a'; s++;
103 | } else if (*s == '\b') { /*bs*/
104 | *d++ = '\\'; *d++ = 'b'; s++;
105 | } else if (*s == '\033') { /*esc*/
106 | *d++ = '\\'; *d++ = 'e'; s++;
107 | } else if (*s == '\f') { /*ff*/
108 | *d++ = '\\'; *d++ = 'f'; s++;
109 | } else if (*s == '\v') { /*vt*/
110 | *d++ = '\\'; *d++ = 'v'; s++;
111 | } else if (*s == 92) { /* '\' */
112 | *d++ = '\\'; *d++ = *s++;
113 | } else if (*(signed char*)s<32) {
114 | sprintf(d,"\\%03o", *s); /* octal \000 */
115 | d += 4; s++;
116 | } else {
117 | *d++ = *s++;
118 | }
119 | }
120 | *d = 0;
121 | return dst;
122 | }
123 |
124 | static char *makeCharClass(unsigned char *cclass)
125 | {
126 | unsigned char bits[32];
127 | setter set;
128 | int c, prev= -1;
129 | static char string[256];
130 | char *ptr;
131 |
132 | if ('^' == *cclass)
133 | {
134 | memset(bits, 255, 32);
135 | set= charClassClear;
136 | ++cclass;
137 | }
138 | else
139 | {
140 | memset(bits, 0, 32);
141 | set= charClassSet;
142 | }
143 | while (0 != (c= readChar(&cclass)))
144 | {
145 | if ('-' == c && *cclass && prev >= 0)
146 | {
147 | for (c= readChar(&cclass); prev <= c; ++prev)
148 | set(bits, prev);
149 | prev= -1;
150 | }
151 | else
152 | {
153 | set(bits, prev= c);
154 | }
155 | }
156 |
157 | ptr= string;
158 | for (c= 0; c < 32; ++c)
159 | ptr += sprintf(ptr, "\\%03o", bits[c]);
160 |
161 | return string;
162 | }
163 |
164 | static void begin(void) { fprintf(output, "\n {"); }
165 | static void end(void) { fprintf(output, "\n }"); }
166 | static void label(int n) { fprintf(output, "\n l%d:;\t", n); }
167 | static void jump(int n) { fprintf(output, " goto l%d;", n); }
168 | static void save(int n) { fprintf(output, " int yypos%d= G->pos, yythunkpos%d= G->thunkpos;", n, n); }
169 | static void restore(int n) { fprintf(output, " G->pos= yypos%d; G->thunkpos= yythunkpos%d;", n, n); }
170 |
171 | static void callErrBlock(Node * node) {
172 | fprintf(output, " { YY_XTYPE YY_XVAR = (YY_XTYPE) G->data; int yyindex = G->offset + G->pos; %s; }", ((struct Any*) node)->errblock);
173 | }
174 |
175 | static void Node_compile_c_ko(Node *node, int ko)
176 | {
177 | assert(node);
178 | switch (node->type)
179 | {
180 | case Rule:
181 | fprintf(stderr, "\ninternal error #1 (%s)\n", node->rule.name);
182 | exit(1);
183 | break;
184 |
185 | case Dot:
186 | fprintf(output, " if (!yymatchDot(G)) goto l%d;", ko);
187 | break;
188 |
189 | case Name:
190 | fprintf(output, " if (!yy_%s(G)) ", node->name.rule->rule.name);
191 | if(((struct Any*) node)->errblock) {
192 | fprintf(output, "{ ");
193 | callErrBlock(node);
194 | fprintf(output, " goto l%d; }\n", ko);
195 | } else {
196 | fprintf(output, " goto l%d;\n", ko);
197 | }
198 | if (node->name.variable)
199 | fprintf(output, " yyDo(G, yySet, %d, 0, \"yySet\");\n", node->name.variable->variable.offset);
200 | break;
201 |
202 | case Character:
203 | case String:
204 | {
205 | int len= strlen(node->string.value);
206 | if (1 == len)
207 | {
208 | if ('\'' == node->string.value[0])
209 | fprintf(output, " if (!yymatchChar(G, '\\'')) goto l%d;\n", ko);
210 | else
211 | fprintf(output, " if (!yymatchChar(G, '%s')) goto l%d;\n", node->string.value, ko);
212 | }
213 | else
214 | if (2 == len && '\\' == node->string.value[0])
215 | fprintf(output, " if (!yymatchChar(G, '%s')) goto l%d;\n", node->string.value, ko);
216 | else
217 | fprintf(output, " if (!yymatchString(G, \"%s\")) goto l%d;\n", node->string.value, ko);
218 | }
219 | break;
220 |
221 | case Class:
222 | fprintf(output, " if (!yymatchClass(G, (const unsigned char *)\"%s\", \"%s\")) goto l%d;\n", makeCharClass(node->cclass.value), yyqq((char*)node->cclass.value), ko);
223 | break;
224 |
225 | case Action:
226 | fprintf(output, " yyDo(G, yy%s, G->begin, G->end, \"yy%s\");\n", node->action.name, node->action.name);
227 | break;
228 |
229 | case Predicate:
230 | fprintf(output, " yyText(G, G->begin, G->end); if (!(%s)) goto l%d;", node->action.text, ko);
231 | break;
232 |
233 | case Alternate:
234 | {
235 | int ok= yyl();
236 | begin();
237 | save(ok);
238 | for (node= node->alternate.first; node; node= node->alternate.next)
239 | if (node->alternate.next)
240 | {
241 | int next= yyl();
242 | Node_compile_c_ko(node, next);
243 | jump(ok);
244 | label(next);
245 | restore(ok);
246 | }
247 | else
248 | Node_compile_c_ko(node, ko);
249 | end();
250 | label(ok);
251 | }
252 | break;
253 |
254 | case Sequence:
255 | for (node= node->sequence.first; node; node= node->sequence.next)
256 | Node_compile_c_ko(node, ko);
257 | break;
258 |
259 | case PeekFor:
260 | {
261 | int ok= yyl();
262 | begin();
263 | save(ok);
264 | Node_compile_c_ko(node->peekFor.element, ko);
265 | restore(ok);
266 | end();
267 | }
268 | break;
269 |
270 | case PeekNot:
271 | {
272 | int ok= yyl();
273 | begin();
274 | save(ok);
275 | Node_compile_c_ko(node->peekFor.element, ok);
276 | jump(ko);
277 | label(ok);
278 | restore(ok);
279 | end();
280 | }
281 | break;
282 |
283 | case Query:
284 | {
285 | int qko= yyl(), qok= yyl();
286 | begin();
287 | save(qko);
288 | Node_compile_c_ko(node->query.element, qko);
289 | jump(qok);
290 | label(qko);
291 | restore(qko);
292 | end();
293 | label(qok);
294 | }
295 | break;
296 |
297 | case Star:
298 | {
299 | int again= yyl(), out= yyl();
300 | label(again);
301 | begin();
302 | save(out);
303 | Node_compile_c_ko(node->star.element, out);
304 | jump(again);
305 | label(out);
306 | restore(out);
307 | end();
308 | }
309 | break;
310 |
311 | case Plus:
312 | {
313 | int again= yyl(), out= yyl();
314 | Node_compile_c_ko(node->plus.element, ko);
315 | label(again);
316 | begin();
317 | save(out);
318 | Node_compile_c_ko(node->plus.element, out);
319 | jump(again);
320 | label(out);
321 | restore(out);
322 | end();
323 | }
324 | break;
325 |
326 | default:
327 | fprintf(stderr, "\nNode_compile_c_ko: illegal node type %d\n", node->type);
328 | exit(1);
329 | }
330 | }
331 |
332 |
333 | static int countVariables(Node *node)
334 | {
335 | int count= 0;
336 | while (node)
337 | {
338 | ++count;
339 | node= node->variable.next;
340 | }
341 | return count;
342 | }
343 |
344 | static void defineVariables(Node *node)
345 | {
346 | int count= 0;
347 | while (node)
348 | {
349 | fprintf(output, "#define %s G->val[%d]\n", node->variable.name, --count);
350 | node->variable.offset= count;
351 | node= node->variable.next;
352 | }
353 | }
354 |
355 | static void undefineVariables(Node *node)
356 | {
357 | while (node)
358 | {
359 | fprintf(output, "#undef %s\n", node->variable.name);
360 | node= node->variable.next;
361 | }
362 | }
363 |
364 |
365 | static void Rule_compile_c2(Node *node)
366 | {
367 | assert(node);
368 | assert(Rule == node->type);
369 |
370 | if (!node->rule.expression)
371 | fprintf(stderr, "rule '%s' used but not defined\n", node->rule.name);
372 | else
373 | {
374 | int ko= yyl(), safe;
375 |
376 | if ((!(RuleUsed & node->rule.flags)) && (node != start))
377 | fprintf(stderr, "rule '%s' defined but not used\n", node->rule.name);
378 |
379 | safe= ((Query == node->rule.expression->type) || (Star == node->rule.expression->type));
380 |
381 | fprintf(output, "\nYY_RULE(int) yy_%s(GREG *G)\n{", node->rule.name);
382 | if (!safe) save(0);
383 | if (node->rule.variables)
384 | fprintf(output, " yyDo(G, yyPush, %d, 0, \"yyPush\");\n", countVariables(node->rule.variables));
385 | fprintf(output, " yyprintfv((stderr, \"%%s\\n\", \"%s\"));\n", node->rule.name);
386 | Node_compile_c_ko(node->rule.expression, ko);
387 | fprintf(output, " yyprintf((stderr, \" ok %s\"));\n", node->rule.name);
388 | fprintf(output, " yyprintfGcontext;\n");
389 | fprintf(output, " yyprintf((stderr, \"\\n\"));\n");
390 | if (node->rule.variables)
391 | fprintf(output, " yyDo(G, yyPop, %d, 0, \"yyPop\");", countVariables(node->rule.variables));
392 | fprintf(output, "\n return 1;");
393 | if (!safe)
394 | {
395 | label(ko);
396 | restore(0);
397 | fprintf(output, " yyprintfv((stderr, \" fail %%s\", \"%s\"));\n", node->rule.name);
398 | fprintf(output, " yyprintfvGcontext;\n");
399 | fprintf(output, " yyprintfv((stderr, \"\\n\"));\n");
400 | fprintf(output, "\n return 0;");
401 | }
402 | fprintf(output, "\n}");
403 | }
404 |
405 | if (node->rule.next)
406 | Rule_compile_c2(node->rule.next);
407 | }
408 |
409 | #ifdef YY_DEBUG
410 | static void yyprintcontext(FILE *stream, char *s)
411 | {
412 | char *context = s;
413 | char *nl = strchr(context, 10);
414 | if (nl) {
415 | context = (char*)malloc(nl-s+1);
416 | strncpy(context, s, nl-s);
417 | context[nl-s] = '\0'; /* replace nl by 0 */
418 | }
419 | fprintf(stream, " @ \"%s\"", context);
420 | if (nl) free(context);
421 | }
422 | #endif
423 |
424 | static const char *header= "\
425 | #include \n\
426 | #include \n\
427 | #include \n\
428 | struct _GREG;\n\
429 | ";
430 |
431 | static const char *preamble= "\
432 | #ifndef YY_ALLOC\n\
433 | #define YY_ALLOC(N, D) malloc(N)\n\
434 | #endif\n\
435 | #ifndef YY_CALLOC\n\
436 | #define YY_CALLOC(N, S, D) calloc(N, S)\n\
437 | #endif\n\
438 | #ifndef YY_REALLOC\n\
439 | #define YY_REALLOC(B, N, D) realloc(B, N)\n\
440 | #endif\n\
441 | #ifndef YY_FREE\n\
442 | #define YY_FREE free\n\
443 | #endif\n\
444 | #ifndef YY_LOCAL\n\
445 | #define YY_LOCAL(T) static T\n\
446 | #endif\n\
447 | #ifndef YY_ACTION\n\
448 | #define YY_ACTION(T) static T\n\
449 | #endif\n\
450 | #ifndef YY_RULE\n\
451 | #define YY_RULE(T) static T\n\
452 | #endif\n\
453 | #ifndef YY_PARSE\n\
454 | #define YY_PARSE(T) T\n\
455 | #endif\n\
456 | #ifndef YY_NAME\n\
457 | #define YY_NAME(N) yy##N\n\
458 | #endif\n\
459 | #ifndef YY_INPUT\n\
460 | #define YY_INPUT(buf, result, max_size, D) \\\n\
461 | { \\\n\
462 | int yyc= getchar(); \\\n\
463 | result= (EOF == yyc) ? 0 : (*(buf)= yyc, 1); \\\n\
464 | yyprintf((stderr, \"<%c>\", yyc)); \\\n\
465 | }\n\
466 | #endif\n\
467 | #ifndef YY_BEGIN\n\
468 | #define YY_BEGIN ( G->begin= G->pos, 1)\n\
469 | #endif\n\
470 | #ifndef YY_END\n\
471 | #define YY_END ( G->end= G->pos, 1)\n\
472 | #endif\n\
473 | #ifdef YY_DEBUG\n\
474 | # ifndef DEBUG_PARSE\n\
475 | # define DEBUG_PARSE 1\n\
476 | # endif\n\
477 | # ifndef DEBUG_VERBOSE\n\
478 | # define DEBUG_VERBOSE 2\n\
479 | # endif\n\
480 | # define yyprintf(args) if (G->debug & DEBUG_PARSE) fprintf args\n\
481 | # define yyprintfv(args) if (G->debug == (DEBUG_PARSE|DEBUG_VERBOSE)) fprintf args\n\
482 | # define yyprintfGcontext if (G->debug & DEBUG_PARSE) yyprintcontext(stderr,G->buf+G->pos)\n\
483 | # define yyprintfvGcontext if (G->debug == (DEBUG_PARSE|DEBUG_VERBOSE)) yyprintcontext(stderr,G->buf+G->pos)\n\
484 | # define yyprintfvTcontext(text) if (G->debug == (DEBUG_PARSE|DEBUG_VERBOSE)) yyprintcontext(stderr,text)\n\
485 | #else\n\
486 | # define yyprintf(args)\n\
487 | # define yyprintfv(args)\n\
488 | # define yyprintfGcontext\n\
489 | # define yyprintfvGcontext\n\
490 | # define yyprintfvTcontext(text)\n\
491 | #endif\n\
492 | #ifndef YYSTYPE\n\
493 | #define YYSTYPE int\n\
494 | #endif\n\
495 | #ifndef YY_XTYPE\n\
496 | #define YY_XTYPE void *\n\
497 | #endif\n\
498 | #ifndef YY_XVAR\n\
499 | #define YY_XVAR yyxvar\n\
500 | #endif\n\
501 | \n\
502 | #ifndef YY_STACK_SIZE\n\
503 | #define YY_STACK_SIZE 128\n\
504 | #endif\n\
505 | \n\
506 | #ifndef YY_BUFFER_START_SIZE\n\
507 | #define YY_BUFFER_START_SIZE 1024\n\
508 | #endif\n\
509 | \n\
510 | #ifndef YY_PART\n\
511 | #define yydata G->data\n\
512 | #define yy G->ss\n\
513 | \n\
514 | struct _yythunk; /* forward declaration */\n\
515 | typedef void (*yyaction)(struct _GREG *G, char *yytext, int yyleng, struct _yythunk *thunkpos, YY_XTYPE YY_XVAR);\n\
516 | typedef struct _yythunk { int begin, end; yyaction action; const char *name; struct _yythunk *next; } yythunk;\n\
517 | \n\
518 | typedef struct _GREG {\n\
519 | char *buf;\n\
520 | int buflen;\n\
521 | int offset;\n\
522 | int pos;\n\
523 | int limit;\n\
524 | char *text;\n\
525 | int textlen;\n\
526 | int begin;\n\
527 | int end;\n\
528 | yythunk *thunks;\n\
529 | int thunkslen;\n\
530 | int thunkpos;\n\
531 | YYSTYPE ss;\n\
532 | YYSTYPE *val;\n\
533 | YYSTYPE *vals;\n\
534 | int valslen;\n\
535 | YY_XTYPE data;\n\
536 | #ifdef YY_DEBUG\n\
537 | int debug;\n\
538 | #endif\n\
539 | } GREG;\n\
540 | \n\
541 | YY_LOCAL(int) yyrefill(GREG *G)\n\
542 | {\n\
543 | int yyn;\n\
544 | while (G->buflen - G->pos < 512)\n\
545 | {\n\
546 | G->buflen *= 2;\n\
547 | G->buf= (char*)YY_REALLOC(G->buf, G->buflen, G->data);\n\
548 | }\n\
549 | YY_INPUT((G->buf + G->pos), yyn, (G->buflen - G->pos), G->data);\n\
550 | if (!yyn) return 0;\n\
551 | G->limit += yyn;\n\
552 | return 1;\n\
553 | }\n\
554 | \n\
555 | YY_LOCAL(int) yymatchDot(GREG *G)\n\
556 | {\n\
557 | if (G->pos >= G->limit && !yyrefill(G)) return 0;\n\
558 | ++G->pos;\n\
559 | return 1;\n\
560 | }\n\
561 | \n\
562 | #ifdef YY_DEBUG\n\
563 | YY_LOCAL(void) yyprintcontext(FILE *stream, char *s)\n\
564 | {\n\
565 | char *context = s;\n\
566 | char *nl = strchr(context, 10);\n\
567 | if (nl) {\n\
568 | context = (char*)malloc(nl-s+1);\n\
569 | strncpy(context, s, nl-s);\n\
570 | context[nl-s] = '\\0'; /* replace nl by 0 */\n\
571 | }\n\
572 | fprintf(stream, \" @ \\\"%s\\\"\", context);\n\
573 | if (nl) free(context);\n\
574 | }\n\
575 | #endif\n\
576 | \n\
577 | YY_LOCAL(int) yymatchChar(GREG *G, int c)\n\
578 | {\n\
579 | if (G->pos >= G->limit && !yyrefill(G)) return 0;\n\
580 | if ((unsigned char)G->buf[G->pos] == c)\n\
581 | {\n\
582 | ++G->pos;\n\
583 | if (c<32) { yyprintf((stderr, \" ok yymatchChar '0x%x'\", c));}\n\
584 | else { yyprintf((stderr, \" ok yymatchChar '%c'\", c));}\n\
585 | yyprintfGcontext;\n\
586 | yyprintf((stderr, \"\\n\"));\n\
587 | return 1;\n\
588 | }\n\
589 | if (c<32) { yyprintfv((stderr, \" fail yymatchChar '0x%x'\", c));}\n\
590 | else { yyprintfv((stderr, \" fail yymatchChar '%c'\", c));}\n\
591 | yyprintfvGcontext;\n\
592 | yyprintfv((stderr, \"\\n\"));\n\
593 | return 0;\n\
594 | }\n\
595 | \n\
596 | YY_LOCAL(int) yymatchString(GREG *G, const char *s)\n\
597 | {\n\
598 | int yysav= G->pos;\n\
599 | while (*s)\n\
600 | {\n\
601 | if (G->pos >= G->limit && !yyrefill(G)) return 0;\n\
602 | if (G->buf[G->pos] != *s)\n\
603 | {\n\
604 | G->pos= yysav;\n\
605 | return 0;\n\
606 | }\n\
607 | ++s;\n\
608 | ++G->pos;\n\
609 | }\n\
610 | return 1;\n\
611 | }\n\
612 | \n\
613 | YY_LOCAL(int) yymatchClass(GREG *G, const unsigned char *bits, const char *cclass)\n\
614 | {\n\
615 | int c;\n\
616 | if (G->pos >= G->limit && !yyrefill(G)) return 0;\n\
617 | c= (unsigned char)G->buf[G->pos];\n\
618 | if (bits[c >> 3] & (1 << (c & 7)))\n\
619 | {\n\
620 | ++G->pos;\n\
621 | yyprintf((stderr, \" ok yymatchClass [%s]\", cclass));\n\
622 | yyprintfGcontext;\n\
623 | yyprintf((stderr, \"\\n\"));\n\
624 | return 1;\n\
625 | }\n\
626 | yyprintfv((stderr, \" fail yymatchClass [%s]\", cclass));\n\
627 | yyprintfvGcontext;\n\
628 | yyprintfv((stderr, \"\\n\"));\n\
629 | return 0;\n\
630 | }\n\
631 | \n\
632 | YY_LOCAL(void) yyDo(GREG *G, yyaction action, int begin, int end, const char *name)\n\
633 | {\n\
634 | while (G->thunkpos >= G->thunkslen)\n\
635 | {\n\
636 | G->thunkslen *= 2;\n\
637 | G->thunks= (yythunk*)YY_REALLOC(G->thunks, sizeof(yythunk) * G->thunkslen, G->data);\n\
638 | }\n\
639 | G->thunks[G->thunkpos].begin= begin;\n\
640 | G->thunks[G->thunkpos].end= end;\n\
641 | G->thunks[G->thunkpos].action= action;\n\
642 | G->thunks[G->thunkpos].name= name;\n\
643 | ++G->thunkpos;\n\
644 | }\n\
645 | \n\
646 | YY_LOCAL(int) yyText(GREG *G, int begin, int end)\n\
647 | {\n\
648 | int yyleng= end - begin;\n\
649 | if (yyleng <= 0)\n\
650 | yyleng= 0;\n\
651 | else\n\
652 | {\n\
653 | while (G->textlen < (yyleng + 1))\n\
654 | {\n\
655 | G->textlen *= 2;\n\
656 | G->text= (char*)YY_REALLOC(G->text, G->textlen, G->data);\n\
657 | }\n\
658 | memcpy(G->text, G->buf + begin, yyleng);\n\
659 | }\n\
660 | G->text[yyleng]= '\\0';\n\
661 | return yyleng;\n\
662 | }\n\
663 | \n\
664 | YY_LOCAL(void) yyDone(GREG *G)\n\
665 | {\n\
666 | int pos;\n\
667 | for (pos= 0; pos < G->thunkpos; ++pos)\n\
668 | {\n\
669 | yythunk *thunk= &G->thunks[pos];\n\
670 | int yyleng= thunk->end ? yyText(G, thunk->begin, thunk->end) : thunk->begin;\n\
671 | yyprintf((stderr, \"DO [%d] %s\", pos, thunk->name));\n\
672 | yyprintfvTcontext(G->text);\n\
673 | yyprintf((stderr, \"\\n\"));\n\
674 | thunk->action(G, G->text, yyleng, thunk, G->data);\n\
675 | }\n\
676 | G->thunkpos= 0;\n\
677 | }\n\
678 | \n\
679 | YY_LOCAL(void) yyCommit(GREG *G)\n\
680 | {\n\
681 | if ((G->limit -= G->pos))\n\
682 | {\n\
683 | memmove(G->buf, G->buf + G->pos, G->limit);\n\
684 | }\n\
685 | G->offset += G->pos;\n\
686 | G->begin -= G->pos;\n\
687 | G->end -= G->pos;\n\
688 | G->pos= G->thunkpos= 0;\n\
689 | }\n\
690 | \n\
691 | YY_LOCAL(int) yyAccept(GREG *G, int tp0)\n\
692 | {\n\
693 | if (tp0)\n\
694 | {\n\
695 | fprintf(stderr, \"accept denied at %d\\n\", tp0);\n\
696 | return 0;\n\
697 | }\n\
698 | else\n\
699 | {\n\
700 | yyDone(G);\n\
701 | yyCommit(G);\n\
702 | }\n\
703 | return 1;\n\
704 | }\n\
705 | \n\
706 | YY_LOCAL(void) yyPush(GREG *G, char *text, int count, yythunk *thunk, YY_XTYPE YY_XVAR) {\n\
707 | size_t off = (G->val - G->vals) + count;\n\
708 | if (off > G->valslen) {\n\
709 | while (G->valslen < off + 1)\n\
710 | G->valslen *= 2;\n\
711 | G->vals= (YYSTYPE*)YY_REALLOC((void *)G->vals, sizeof(YYSTYPE) * G->valslen, G->data);\n\
712 | G->val= G->vals + off;\n\
713 | } else {\n\
714 | G->val += count;\n\
715 | }\n\
716 | }\n\
717 | YY_LOCAL(void) yyPop(GREG *G, char *text, int count, yythunk *thunk, YY_XTYPE YY_XVAR) { G->val -= count; }\n\
718 | YY_LOCAL(void) yySet(GREG *G, char *text, int count, yythunk *thunk, YY_XTYPE YY_XVAR) { G->val[count]= G->ss; }\n\
719 | \n\
720 | #endif /* YY_PART */\n\
721 | \n\
722 | #define YYACCEPT yyAccept(G, yythunkpos0)\n\
723 | \n\
724 | ";
725 |
726 | static const char *footer= "\n\
727 | \n\
728 | #ifndef YY_PART\n\
729 | \n\
730 | typedef int (*yyrule)(GREG *G);\n\
731 | \n\
732 | YY_PARSE(int) YY_NAME(parse_from)(GREG *G, yyrule yystart)\n\
733 | {\n\
734 | int yyok;\n\
735 | if (!G->buflen)\n\
736 | {\n\
737 | G->buflen= YY_BUFFER_START_SIZE;\n\
738 | G->buf= (char*)YY_ALLOC(G->buflen, G->data);\n\
739 | G->textlen= YY_BUFFER_START_SIZE;\n\
740 | G->text= (char*)YY_ALLOC(G->textlen, G->data);\n\
741 | G->thunkslen= YY_STACK_SIZE;\n\
742 | G->thunks= (yythunk*)YY_ALLOC(sizeof(yythunk) * G->thunkslen, G->data);\n\
743 | G->valslen= YY_STACK_SIZE;\n\
744 | G->vals= (YYSTYPE*)YY_ALLOC(sizeof(YYSTYPE) * G->valslen, G->data);\n\
745 | G->begin= G->end= G->pos= G->limit= G->thunkpos= 0;\n\
746 | }\n\
747 | G->pos = 0;\n\
748 | G->begin= G->end= G->pos;\n\
749 | G->thunkpos= 0;\n\
750 | G->val= G->vals;\n\
751 | yyok= yystart(G);\n\
752 | if (yyok) yyDone(G);\n\
753 | yyCommit(G);\n\
754 | return yyok;\n\
755 | (void)yyrefill;\n\
756 | (void)yymatchDot;\n\
757 | (void)yymatchChar;\n\
758 | (void)yymatchString;\n\
759 | (void)yymatchClass;\n\
760 | (void)yyDo;\n\
761 | (void)yyText;\n\
762 | (void)yyDone;\n\
763 | (void)yyCommit;\n\
764 | (void)yyAccept;\n\
765 | (void)yyPush;\n\
766 | (void)yyPop;\n\
767 | (void)yySet;\n\
768 | }\n\
769 | \n\
770 | YY_PARSE(int) YY_NAME(parse)(GREG *G)\n\
771 | {\n\
772 | return YY_NAME(parse_from)(G, yy_%s);\n\
773 | }\n\
774 | \n\
775 | YY_PARSE(void) YY_NAME(init)(GREG *G)\n\
776 | {\n\
777 | memset(G, 0, sizeof(GREG));\n\
778 | }\n\
779 | YY_PARSE(void) YY_NAME(deinit)(GREG *G)\n\
780 | {\n\
781 | if (G->buf) YY_FREE(G->buf);\n\
782 | if (G->text) YY_FREE(G->text);\n\
783 | if (G->thunks) YY_FREE(G->thunks);\n\
784 | if (G->vals) YY_FREE((void*)G->vals);\n\
785 | }\n\
786 | YY_PARSE(GREG *) YY_NAME(parse_new)(YY_XTYPE data)\n\
787 | {\n\
788 | GREG *G = (GREG *)YY_CALLOC(1, sizeof(GREG), G->data);\n\
789 | G->data = data;\n\
790 | return G;\n\
791 | }\n\
792 | \n\
793 | YY_PARSE(void) YY_NAME(parse_free)(GREG *G)\n\
794 | {\n\
795 | YY_NAME(deinit)(G);\n\
796 | YY_FREE(G);\n\
797 | }\n\
798 | \n\
799 | #endif\n\
800 | ";
801 |
802 | void Rule_compile_c_header(void)
803 | {
804 | fprintf(output, "/* A recursive-descent parser generated by greg %d.%d.%d */\n", GREG_MAJOR, GREG_MINOR, GREG_LEVEL);
805 | fprintf(output, "\n");
806 | fprintf(output, "%s", header);
807 | fprintf(output, "#define YYRULECOUNT %d\n", ruleCount);
808 | }
809 |
810 | int consumesInput(Node *node)
811 | {
812 | if (!node) return 0;
813 |
814 | switch (node->type)
815 | {
816 | case Rule:
817 | {
818 | int result= 0;
819 | if (RuleReached & node->rule.flags)
820 | fprintf(stderr, "possible infinite left recursion in rule '%s'\n", node->rule.name);
821 | else
822 | {
823 | node->rule.flags |= RuleReached;
824 | result= consumesInput(node->rule.expression);
825 | node->rule.flags &= ~RuleReached;
826 | }
827 | return result;
828 | }
829 | break;
830 |
831 | case Dot: return 1;
832 | case Name: return consumesInput(node->name.rule);
833 | case Character:
834 | case String: return strlen(node->string.value) > 0;
835 | case Class: return 1;
836 | case Action: return 0;
837 | case Predicate: return 0;
838 |
839 | case Alternate:
840 | {
841 | Node *n;
842 | for (n= node->alternate.first; n; n= n->alternate.next)
843 | if (!consumesInput(n))
844 | return 0;
845 | }
846 | return 1;
847 |
848 | case Sequence:
849 | {
850 | Node *n;
851 | for (n= node->alternate.first; n; n= n->alternate.next)
852 | if (consumesInput(n))
853 | return 1;
854 | }
855 | return 0;
856 |
857 | case PeekFor: return 0;
858 | case PeekNot: return 0;
859 | case Query: return 0;
860 | case Star: return 0;
861 | case Plus: return consumesInput(node->plus.element);
862 |
863 | default:
864 | fprintf(stderr, "\nconsumesInput: illegal node type %d\n", node->type);
865 | exit(1);
866 | }
867 | return 0;
868 | }
869 |
870 |
871 | void Rule_compile_c(Node *node)
872 | {
873 | Node *n;
874 |
875 | for (n= rules; n; n= n->rule.next)
876 | consumesInput(n);
877 |
878 | fprintf(output, "%s", preamble);
879 | for (n= node; n; n= n->rule.next)
880 | fprintf(output, "YY_RULE(int) yy_%s(GREG *G); /* %d */\n", n->rule.name, n->rule.id);
881 | fprintf(output, "\n");
882 | for (n= actions; n; n= n->action.list)
883 | {
884 | char *block = n->action.text;
885 | fprintf(output, "YY_ACTION(void) yy%s(GREG *G, char *yytext, int yyleng, yythunk *thunk, YY_XTYPE YY_XVAR)\n{\n", n->action.name);
886 | defineVariables(n->action.rule->rule.variables);
887 | while (*block == 0x20 || *block == 0x9) block++;
888 | fprintf(output, " yyprintf((stderr, \"do yy%s\"));\n", n->action.name);
889 | fprintf(output, " yyprintfvTcontext(yytext);\n");
890 | fprintf(output, " yyprintf((stderr, \"\\n {%s}\\n\"));\n", yyqq(block));
891 | fprintf(output, " %s;\n", block);
892 | undefineVariables(n->action.rule->rule.variables);
893 | fprintf(output, "}\n");
894 | }
895 | Rule_compile_c2(node);
896 | fprintf(output, footer, start->rule.name);
897 | }
898 |
--------------------------------------------------------------------------------
/greg.c:
--------------------------------------------------------------------------------
1 | /* A recursive-descent parser generated by greg 0.4.5 */
2 |
3 | #include
4 | #include
5 | #include
6 | struct _GREG;
7 | #define YYRULECOUNT 39
8 |
9 | # include "greg.h"
10 |
11 | # include
12 | # include
13 | # include
14 | # include
15 | # if !_MSC_VER
16 | # include
17 | # include
18 | # else
19 | # include
20 | # include
21 | # include "getopt.h"
22 | # endif
23 |
24 | typedef struct Header Header;
25 |
26 | struct Header {
27 | char *text;
28 | Header *next;
29 | };
30 |
31 | FILE *input= 0;
32 |
33 | int verboseFlag= 0;
34 |
35 | static int lineNumber= 0;
36 | static const char *fileName= 0;
37 | static char *trailer= 0;
38 | static Header *headers= 0;
39 |
40 | void makeHeader(char *text);
41 | void makeTrailer(char *text);
42 |
43 | void yyerror(struct _GREG *, const char *message);
44 |
45 | # define YY_INPUT(buf, result, max, D) \
46 | { \
47 | int c= getc(input); \
48 | if ('\n' == c || '\r' == c) ++lineNumber; \
49 | result= (EOF == c) ? 0 : (*(buf)= c, 1); \
50 | }
51 |
52 | # define YY_LOCAL(T) static T
53 | # define YY_RULE(T) static T
54 |
55 | #ifndef YY_ALLOC
56 | #define YY_ALLOC(N, D) malloc(N)
57 | #endif
58 | #ifndef YY_CALLOC
59 | #define YY_CALLOC(N, S, D) calloc(N, S)
60 | #endif
61 | #ifndef YY_REALLOC
62 | #define YY_REALLOC(B, N, D) realloc(B, N)
63 | #endif
64 | #ifndef YY_FREE
65 | #define YY_FREE free
66 | #endif
67 | #ifndef YY_LOCAL
68 | #define YY_LOCAL(T) static T
69 | #endif
70 | #ifndef YY_ACTION
71 | #define YY_ACTION(T) static T
72 | #endif
73 | #ifndef YY_RULE
74 | #define YY_RULE(T) static T
75 | #endif
76 | #ifndef YY_PARSE
77 | #define YY_PARSE(T) T
78 | #endif
79 | #ifndef YY_NAME
80 | #define YY_NAME(N) yy##N
81 | #endif
82 | #ifndef YY_INPUT
83 | #define YY_INPUT(buf, result, max_size, D) \
84 | { \
85 | int yyc= getchar(); \
86 | result= (EOF == yyc) ? 0 : (*(buf)= yyc, 1); \
87 | yyprintf((stderr, "<%c>", yyc)); \
88 | }
89 | #endif
90 | #ifndef YY_BEGIN
91 | #define YY_BEGIN ( G->begin= G->pos, 1)
92 | #endif
93 | #ifndef YY_END
94 | #define YY_END ( G->end= G->pos, 1)
95 | #endif
96 | #ifdef YY_DEBUG
97 | # ifndef DEBUG_PARSE
98 | # define DEBUG_PARSE 1
99 | # endif
100 | # ifndef DEBUG_VERBOSE
101 | # define DEBUG_VERBOSE 2
102 | # endif
103 | # define yyprintf(args) if (G->debug & DEBUG_PARSE) fprintf args
104 | # define yyprintfv(args) if (G->debug == (DEBUG_PARSE|DEBUG_VERBOSE)) fprintf args
105 | # define yyprintfGcontext if (G->debug & DEBUG_PARSE) yyprintcontext(stderr,G->buf+G->pos)
106 | # define yyprintfvGcontext if (G->debug == (DEBUG_PARSE|DEBUG_VERBOSE)) yyprintcontext(stderr,G->buf+G->pos)
107 | # define yyprintfvTcontext(text) if (G->debug == (DEBUG_PARSE|DEBUG_VERBOSE)) yyprintcontext(stderr,text)
108 | #else
109 | # define yyprintf(args)
110 | # define yyprintfv(args)
111 | # define yyprintfGcontext
112 | # define yyprintfvGcontext
113 | # define yyprintfvTcontext(text)
114 | #endif
115 | #ifndef YYSTYPE
116 | #define YYSTYPE int
117 | #endif
118 | #ifndef YY_XTYPE
119 | #define YY_XTYPE void *
120 | #endif
121 | #ifndef YY_XVAR
122 | #define YY_XVAR yyxvar
123 | #endif
124 |
125 | #ifndef YY_STACK_SIZE
126 | #define YY_STACK_SIZE 128
127 | #endif
128 |
129 | #ifndef YY_BUFFER_START_SIZE
130 | #define YY_BUFFER_START_SIZE 1024
131 | #endif
132 |
133 | #ifndef YY_PART
134 | #define yydata G->data
135 | #define yy G->ss
136 |
137 | struct _yythunk; /* forward declaration */
138 | typedef void (*yyaction)(struct _GREG *G, char *yytext, int yyleng, struct _yythunk *thunkpos, YY_XTYPE YY_XVAR);
139 | typedef struct _yythunk { int begin, end; yyaction action; const char *name; struct _yythunk *next; } yythunk;
140 |
141 | typedef struct _GREG {
142 | char *buf;
143 | int buflen;
144 | int offset;
145 | int pos;
146 | int limit;
147 | char *text;
148 | int textlen;
149 | int begin;
150 | int end;
151 | yythunk *thunks;
152 | int thunkslen;
153 | int thunkpos;
154 | YYSTYPE ss;
155 | YYSTYPE *val;
156 | YYSTYPE *vals;
157 | int valslen;
158 | YY_XTYPE data;
159 | #ifdef YY_DEBUG
160 | int debug;
161 | #endif
162 | } GREG;
163 |
164 | YY_LOCAL(int) yyrefill(GREG *G)
165 | {
166 | int yyn;
167 | while (G->buflen - G->pos < 512)
168 | {
169 | G->buflen *= 2;
170 | G->buf= (char*)YY_REALLOC(G->buf, G->buflen, G->data);
171 | }
172 | YY_INPUT((G->buf + G->pos), yyn, (G->buflen - G->pos), G->data);
173 | if (!yyn) return 0;
174 | G->limit += yyn;
175 | return 1;
176 | }
177 |
178 | YY_LOCAL(int) yymatchDot(GREG *G)
179 | {
180 | if (G->pos >= G->limit && !yyrefill(G)) return 0;
181 | ++G->pos;
182 | return 1;
183 | }
184 |
185 | #ifdef YY_DEBUG
186 | YY_LOCAL(void) yyprintcontext(FILE *stream, char *s)
187 | {
188 | char *context = s;
189 | char *nl = strchr(context, 10);
190 | if (nl) {
191 | context = (char*)malloc(nl-s+1);
192 | strncpy(context, s, nl-s);
193 | context[nl-s] = '\0'; /* replace nl by 0 */
194 | }
195 | fprintf(stream, " @ \"%s\"", context);
196 | if (nl) free(context);
197 | }
198 | #endif
199 |
200 | YY_LOCAL(int) yymatchChar(GREG *G, int c)
201 | {
202 | if (G->pos >= G->limit && !yyrefill(G)) return 0;
203 | if ((unsigned char)G->buf[G->pos] == c)
204 | {
205 | ++G->pos;
206 | if (c<32) { yyprintf((stderr, " ok yymatchChar '0x%x'", c));}
207 | else { yyprintf((stderr, " ok yymatchChar '%c'", c));}
208 | yyprintfGcontext;
209 | yyprintf((stderr, "\n"));
210 | return 1;
211 | }
212 | if (c<32) { yyprintfv((stderr, " fail yymatchChar '0x%x'", c));}
213 | else { yyprintfv((stderr, " fail yymatchChar '%c'", c));}
214 | yyprintfvGcontext;
215 | yyprintfv((stderr, "\n"));
216 | return 0;
217 | }
218 |
219 | YY_LOCAL(int) yymatchString(GREG *G, const char *s)
220 | {
221 | int yysav= G->pos;
222 | while (*s)
223 | {
224 | if (G->pos >= G->limit && !yyrefill(G)) return 0;
225 | if (G->buf[G->pos] != *s)
226 | {
227 | G->pos= yysav;
228 | return 0;
229 | }
230 | ++s;
231 | ++G->pos;
232 | }
233 | return 1;
234 | }
235 |
236 | YY_LOCAL(int) yymatchClass(GREG *G, const unsigned char *bits, const char *cclass)
237 | {
238 | int c;
239 | if (G->pos >= G->limit && !yyrefill(G)) return 0;
240 | c= (unsigned char)G->buf[G->pos];
241 | if (bits[c >> 3] & (1 << (c & 7)))
242 | {
243 | ++G->pos;
244 | yyprintf((stderr, " ok yymatchClass [%s]", cclass));
245 | yyprintfGcontext;
246 | yyprintf((stderr, "\n"));
247 | return 1;
248 | }
249 | yyprintfv((stderr, " fail yymatchClass [%s]", cclass));
250 | yyprintfvGcontext;
251 | yyprintfv((stderr, "\n"));
252 | return 0;
253 | }
254 |
255 | YY_LOCAL(void) yyDo(GREG *G, yyaction action, int begin, int end, const char *name)
256 | {
257 | while (G->thunkpos >= G->thunkslen)
258 | {
259 | G->thunkslen *= 2;
260 | G->thunks= (yythunk*)YY_REALLOC(G->thunks, sizeof(yythunk) * G->thunkslen, G->data);
261 | }
262 | G->thunks[G->thunkpos].begin= begin;
263 | G->thunks[G->thunkpos].end= end;
264 | G->thunks[G->thunkpos].action= action;
265 | G->thunks[G->thunkpos].name= name;
266 | ++G->thunkpos;
267 | }
268 |
269 | YY_LOCAL(int) yyText(GREG *G, int begin, int end)
270 | {
271 | int yyleng= end - begin;
272 | if (yyleng <= 0)
273 | yyleng= 0;
274 | else
275 | {
276 | while (G->textlen < (yyleng + 1))
277 | {
278 | G->textlen *= 2;
279 | G->text= (char*)YY_REALLOC(G->text, G->textlen, G->data);
280 | }
281 | memcpy(G->text, G->buf + begin, yyleng);
282 | }
283 | G->text[yyleng]= '\0';
284 | return yyleng;
285 | }
286 |
287 | YY_LOCAL(void) yyDone(GREG *G)
288 | {
289 | int pos;
290 | for (pos= 0; pos < G->thunkpos; ++pos)
291 | {
292 | yythunk *thunk= &G->thunks[pos];
293 | int yyleng= thunk->end ? yyText(G, thunk->begin, thunk->end) : thunk->begin;
294 | yyprintf((stderr, "DO [%d] %s", pos, thunk->name));
295 | yyprintfvTcontext(G->text);
296 | yyprintf((stderr, "\n"));
297 | thunk->action(G, G->text, yyleng, thunk, G->data);
298 | }
299 | G->thunkpos= 0;
300 | }
301 |
302 | YY_LOCAL(void) yyCommit(GREG *G)
303 | {
304 | if ((G->limit -= G->pos))
305 | {
306 | memmove(G->buf, G->buf + G->pos, G->limit);
307 | }
308 | G->offset += G->pos;
309 | G->begin -= G->pos;
310 | G->end -= G->pos;
311 | G->pos= G->thunkpos= 0;
312 | }
313 |
314 | YY_LOCAL(int) yyAccept(GREG *G, int tp0)
315 | {
316 | if (tp0)
317 | {
318 | fprintf(stderr, "accept denied at %d\n", tp0);
319 | return 0;
320 | }
321 | else
322 | {
323 | yyDone(G);
324 | yyCommit(G);
325 | }
326 | return 1;
327 | }
328 |
329 | YY_LOCAL(void) yyPush(GREG *G, char *text, int count, yythunk *thunk, YY_XTYPE YY_XVAR) {
330 | size_t off = (G->val - G->vals) + count;
331 | if (off > G->valslen) {
332 | while (G->valslen < off + 1)
333 | G->valslen *= 2;
334 | G->vals= (YYSTYPE*)YY_REALLOC((void *)G->vals, sizeof(YYSTYPE) * G->valslen, G->data);
335 | G->val= G->vals + off;
336 | } else {
337 | G->val += count;
338 | }
339 | }
340 | YY_LOCAL(void) yyPop(GREG *G, char *text, int count, yythunk *thunk, YY_XTYPE YY_XVAR) { G->val -= count; }
341 | YY_LOCAL(void) yySet(GREG *G, char *text, int count, yythunk *thunk, YY_XTYPE YY_XVAR) { G->val[count]= G->ss; }
342 |
343 | #endif /* YY_PART */
344 |
345 | #define YYACCEPT yyAccept(G, yythunkpos0)
346 |
347 | YY_RULE(int) yy_till_end_of_line(GREG *G); /* 39 */
348 | YY_RULE(int) yy_end_of_line(GREG *G); /* 38 */
349 | YY_RULE(int) yy_quoted_comment(GREG *G); /* 37 */
350 | YY_RULE(int) yy_single_line_comment(GREG *G); /* 36 */
351 | YY_RULE(int) yy_space(GREG *G); /* 35 */
352 | YY_RULE(int) yy_braces(GREG *G); /* 34 */
353 | YY_RULE(int) yy_range(GREG *G); /* 33 */
354 | YY_RULE(int) yy_char(GREG *G); /* 32 */
355 | YY_RULE(int) yy_errblock(GREG *G); /* 31 */
356 | YY_RULE(int) yy_END(GREG *G); /* 30 */
357 | YY_RULE(int) yy_BEGIN(GREG *G); /* 29 */
358 | YY_RULE(int) yy_DOT(GREG *G); /* 28 */
359 | YY_RULE(int) yy_class(GREG *G); /* 27 */
360 | YY_RULE(int) yy_literal(GREG *G); /* 26 */
361 | YY_RULE(int) yy_CLOSE(GREG *G); /* 25 */
362 | YY_RULE(int) yy_OPEN(GREG *G); /* 24 */
363 | YY_RULE(int) yy_COLON(GREG *G); /* 23 */
364 | YY_RULE(int) yy_PLUS(GREG *G); /* 22 */
365 | YY_RULE(int) yy_STAR(GREG *G); /* 21 */
366 | YY_RULE(int) yy_QUESTION(GREG *G); /* 20 */
367 | YY_RULE(int) yy_primary(GREG *G); /* 19 */
368 | YY_RULE(int) yy_NOT(GREG *G); /* 18 */
369 | YY_RULE(int) yy_suffix(GREG *G); /* 17 */
370 | YY_RULE(int) yy_action(GREG *G); /* 16 */
371 | YY_RULE(int) yy_AND(GREG *G); /* 15 */
372 | YY_RULE(int) yy_prefix(GREG *G); /* 14 */
373 | YY_RULE(int) yy_BAR(GREG *G); /* 13 */
374 | YY_RULE(int) yy_sequence(GREG *G); /* 12 */
375 | YY_RULE(int) yy_SEMICOLON(GREG *G); /* 11 */
376 | YY_RULE(int) yy_expression(GREG *G); /* 10 */
377 | YY_RULE(int) yy_EQUAL(GREG *G); /* 9 */
378 | YY_RULE(int) yy_identifier(GREG *G); /* 8 */
379 | YY_RULE(int) yy_RPERCENT(GREG *G); /* 7 */
380 | YY_RULE(int) yy_end_of_file(GREG *G); /* 6 */
381 | YY_RULE(int) yy_trailer(GREG *G); /* 5 */
382 | YY_RULE(int) yy_definition(GREG *G); /* 4 */
383 | YY_RULE(int) yy_declaration(GREG *G); /* 3 */
384 | YY_RULE(int) yy__(GREG *G); /* 2 */
385 | YY_RULE(int) yy_grammar(GREG *G); /* 1 */
386 |
387 | YY_ACTION(void) yy_10_primary(GREG *G, char *yytext, int yyleng, yythunk *thunk, YY_XTYPE YY_XVAR)
388 | {
389 | yyprintf((stderr, "do yy_10_primary"));
390 | yyprintfvTcontext(yytext);
391 | yyprintf((stderr, "\n {Node *node = pop(); ((struct Any *) node)->errblock = strdup(yytext); push(node); }\n"));
392 | Node *node = pop(); ((struct Any *) node)->errblock = strdup(yytext); push(node); ;
393 | }
394 | YY_ACTION(void) yy_9_primary(GREG *G, char *yytext, int yyleng, yythunk *thunk, YY_XTYPE YY_XVAR)
395 | {
396 | yyprintf((stderr, "do yy_9_primary"));
397 | yyprintfvTcontext(yytext);
398 | yyprintf((stderr, "\n {push(makePredicate(\"YY_END\")); }\n"));
399 | push(makePredicate("YY_END")); ;
400 | }
401 | YY_ACTION(void) yy_8_primary(GREG *G, char *yytext, int yyleng, yythunk *thunk, YY_XTYPE YY_XVAR)
402 | {
403 | yyprintf((stderr, "do yy_8_primary"));
404 | yyprintfvTcontext(yytext);
405 | yyprintf((stderr, "\n {push(makePredicate(\"YY_BEGIN\")); }\n"));
406 | push(makePredicate("YY_BEGIN")); ;
407 | }
408 | YY_ACTION(void) yy_7_primary(GREG *G, char *yytext, int yyleng, yythunk *thunk, YY_XTYPE YY_XVAR)
409 | {
410 | yyprintf((stderr, "do yy_7_primary"));
411 | yyprintfvTcontext(yytext);
412 | yyprintf((stderr, "\n {push(makeAction(yytext)); }\n"));
413 | push(makeAction(yytext)); ;
414 | }
415 | YY_ACTION(void) yy_6_primary(GREG *G, char *yytext, int yyleng, yythunk *thunk, YY_XTYPE YY_XVAR)
416 | {
417 | yyprintf((stderr, "do yy_6_primary"));
418 | yyprintfvTcontext(yytext);
419 | yyprintf((stderr, "\n {push(makeDot()); }\n"));
420 | push(makeDot()); ;
421 | }
422 | YY_ACTION(void) yy_5_primary(GREG *G, char *yytext, int yyleng, yythunk *thunk, YY_XTYPE YY_XVAR)
423 | {
424 | yyprintf((stderr, "do yy_5_primary"));
425 | yyprintfvTcontext(yytext);
426 | yyprintf((stderr, "\n {push(makeClass(yytext)); }\n"));
427 | push(makeClass(yytext)); ;
428 | }
429 | YY_ACTION(void) yy_4_primary(GREG *G, char *yytext, int yyleng, yythunk *thunk, YY_XTYPE YY_XVAR)
430 | {
431 | yyprintf((stderr, "do yy_4_primary"));
432 | yyprintfvTcontext(yytext);
433 | yyprintf((stderr, "\n {push(makeString(yytext)); }\n"));
434 | push(makeString(yytext)); ;
435 | }
436 | YY_ACTION(void) yy_3_primary(GREG *G, char *yytext, int yyleng, yythunk *thunk, YY_XTYPE YY_XVAR)
437 | {
438 | yyprintf((stderr, "do yy_3_primary"));
439 | yyprintfvTcontext(yytext);
440 | yyprintf((stderr, "\n {push(makeName(findRule(yytext,0))); }\n"));
441 | push(makeName(findRule(yytext,0))); ;
442 | }
443 | YY_ACTION(void) yy_2_primary(GREG *G, char *yytext, int yyleng, yythunk *thunk, YY_XTYPE YY_XVAR)
444 | {
445 | yyprintf((stderr, "do yy_2_primary"));
446 | yyprintfvTcontext(yytext);
447 | yyprintf((stderr, "\n {Node *name= makeName(findRule(yytext,0)); name->name.variable= pop(); push(name); }\n"));
448 | Node *name= makeName(findRule(yytext,0)); name->name.variable= pop(); push(name); ;
449 | }
450 | YY_ACTION(void) yy_1_primary(GREG *G, char *yytext, int yyleng, yythunk *thunk, YY_XTYPE YY_XVAR)
451 | {
452 | yyprintf((stderr, "do yy_1_primary"));
453 | yyprintfvTcontext(yytext);
454 | yyprintf((stderr, "\n {push(makeVariable(yytext)); }\n"));
455 | push(makeVariable(yytext)); ;
456 | }
457 | YY_ACTION(void) yy_3_suffix(GREG *G, char *yytext, int yyleng, yythunk *thunk, YY_XTYPE YY_XVAR)
458 | {
459 | yyprintf((stderr, "do yy_3_suffix"));
460 | yyprintfvTcontext(yytext);
461 | yyprintf((stderr, "\n {push(makePlus (pop())); }\n"));
462 | push(makePlus (pop())); ;
463 | }
464 | YY_ACTION(void) yy_2_suffix(GREG *G, char *yytext, int yyleng, yythunk *thunk, YY_XTYPE YY_XVAR)
465 | {
466 | yyprintf((stderr, "do yy_2_suffix"));
467 | yyprintfvTcontext(yytext);
468 | yyprintf((stderr, "\n {push(makeStar (pop())); }\n"));
469 | push(makeStar (pop())); ;
470 | }
471 | YY_ACTION(void) yy_1_suffix(GREG *G, char *yytext, int yyleng, yythunk *thunk, YY_XTYPE YY_XVAR)
472 | {
473 | yyprintf((stderr, "do yy_1_suffix"));
474 | yyprintfvTcontext(yytext);
475 | yyprintf((stderr, "\n {push(makeQuery(pop())); }\n"));
476 | push(makeQuery(pop())); ;
477 | }
478 | YY_ACTION(void) yy_3_prefix(GREG *G, char *yytext, int yyleng, yythunk *thunk, YY_XTYPE YY_XVAR)
479 | {
480 | yyprintf((stderr, "do yy_3_prefix"));
481 | yyprintfvTcontext(yytext);
482 | yyprintf((stderr, "\n {push(makePeekNot(pop())); }\n"));
483 | push(makePeekNot(pop())); ;
484 | }
485 | YY_ACTION(void) yy_2_prefix(GREG *G, char *yytext, int yyleng, yythunk *thunk, YY_XTYPE YY_XVAR)
486 | {
487 | yyprintf((stderr, "do yy_2_prefix"));
488 | yyprintfvTcontext(yytext);
489 | yyprintf((stderr, "\n {push(makePeekFor(pop())); }\n"));
490 | push(makePeekFor(pop())); ;
491 | }
492 | YY_ACTION(void) yy_1_prefix(GREG *G, char *yytext, int yyleng, yythunk *thunk, YY_XTYPE YY_XVAR)
493 | {
494 | yyprintf((stderr, "do yy_1_prefix"));
495 | yyprintfvTcontext(yytext);
496 | yyprintf((stderr, "\n {push(makePredicate(yytext)); }\n"));
497 | push(makePredicate(yytext)); ;
498 | }
499 | YY_ACTION(void) yy_1_sequence(GREG *G, char *yytext, int yyleng, yythunk *thunk, YY_XTYPE YY_XVAR)
500 | {
501 | yyprintf((stderr, "do yy_1_sequence"));
502 | yyprintfvTcontext(yytext);
503 | yyprintf((stderr, "\n {Node *f= pop(); push(Sequence_append(pop(), f)); }\n"));
504 | Node *f= pop(); push(Sequence_append(pop(), f)); ;
505 | }
506 | YY_ACTION(void) yy_1_expression(GREG *G, char *yytext, int yyleng, yythunk *thunk, YY_XTYPE YY_XVAR)
507 | {
508 | yyprintf((stderr, "do yy_1_expression"));
509 | yyprintfvTcontext(yytext);
510 | yyprintf((stderr, "\n {Node *f= pop(); push(Alternate_append(pop(), f)); }\n"));
511 | Node *f= pop(); push(Alternate_append(pop(), f)); ;
512 | }
513 | YY_ACTION(void) yy_2_definition(GREG *G, char *yytext, int yyleng, yythunk *thunk, YY_XTYPE YY_XVAR)
514 | {
515 | #define s G->val[-1]
516 | yyprintf((stderr, "do yy_2_definition"));
517 | yyprintfvTcontext(yytext);
518 | yyprintf((stderr, "\n {Node *e= pop(); Rule_setExpression(pop(), e); }\n"));
519 | Node *e= pop(); Rule_setExpression(pop(), e); ;
520 | #undef s
521 | }
522 | YY_ACTION(void) yy_1_definition(GREG *G, char *yytext, int yyleng, yythunk *thunk, YY_XTYPE YY_XVAR)
523 | {
524 | #define s G->val[-1]
525 | yyprintf((stderr, "do yy_1_definition"));
526 | yyprintfvTcontext(yytext);
527 | yyprintf((stderr, "\n {if (push(beginRule(findRule(yytext,1)))->rule.expression)\n\
528 | \t\t\t\t\t\t\t fprintf(stderr, \"rule '%%s' redefined\\n\", yytext); }\n"));
529 | if (push(beginRule(findRule(yytext,1)))->rule.expression)
530 | fprintf(stderr, "rule '%s' redefined\n", yytext); ;
531 | #undef s
532 | }
533 | YY_ACTION(void) yy_1_trailer(GREG *G, char *yytext, int yyleng, yythunk *thunk, YY_XTYPE YY_XVAR)
534 | {
535 | yyprintf((stderr, "do yy_1_trailer"));
536 | yyprintfvTcontext(yytext);
537 | yyprintf((stderr, "\n {makeTrailer(yytext); }\n"));
538 | makeTrailer(yytext); ;
539 | }
540 | YY_ACTION(void) yy_1_declaration(GREG *G, char *yytext, int yyleng, yythunk *thunk, YY_XTYPE YY_XVAR)
541 | {
542 | yyprintf((stderr, "do yy_1_declaration"));
543 | yyprintfvTcontext(yytext);
544 | yyprintf((stderr, "\n {makeHeader(yytext); }\n"));
545 | makeHeader(yytext); ;
546 | }
547 |
548 | YY_RULE(int) yy_till_end_of_line(GREG *G)
549 | { int yypos0= G->pos, yythunkpos0= G->thunkpos; yyprintfv((stderr, "%s\n", "till_end_of_line"));
550 |
551 | l2:;
552 | { int yypos3= G->pos, yythunkpos3= G->thunkpos;
553 | { int yypos4= G->pos, yythunkpos4= G->thunkpos; if (!yy_end_of_line(G)) goto l4;
554 | goto l3;
555 | l4:; G->pos= yypos4; G->thunkpos= yythunkpos4;
556 | } if (!yymatchDot(G)) goto l3; goto l2;
557 | l3:; G->pos= yypos3; G->thunkpos= yythunkpos3;
558 | } if (!yy_end_of_line(G)) goto l1;
559 | yyprintf((stderr, " ok till_end_of_line"));
560 | yyprintfGcontext;
561 | yyprintf((stderr, "\n"));
562 |
563 | return 1;
564 | l1:; G->pos= yypos0; G->thunkpos= yythunkpos0; yyprintfv((stderr, " fail %s", "till_end_of_line"));
565 | yyprintfvGcontext;
566 | yyprintfv((stderr, "\n"));
567 |
568 | return 0;
569 | }
570 | YY_RULE(int) yy_end_of_line(GREG *G)
571 | { int yypos0= G->pos, yythunkpos0= G->thunkpos; yyprintfv((stderr, "%s\n", "end_of_line"));
572 |
573 | { int yypos6= G->pos, yythunkpos6= G->thunkpos; if (!yymatchString(G, "\r\n")) goto l7;
574 | goto l6;
575 | l7:; G->pos= yypos6; G->thunkpos= yythunkpos6; if (!yymatchChar(G, '\n')) goto l8;
576 | goto l6;
577 | l8:; G->pos= yypos6; G->thunkpos= yythunkpos6; if (!yymatchChar(G, '\r')) goto l5;
578 |
579 | }
580 | l6:; yyprintf((stderr, " ok end_of_line"));
581 | yyprintfGcontext;
582 | yyprintf((stderr, "\n"));
583 |
584 | return 1;
585 | l5:; G->pos= yypos0; G->thunkpos= yythunkpos0; yyprintfv((stderr, " fail %s", "end_of_line"));
586 | yyprintfvGcontext;
587 | yyprintfv((stderr, "\n"));
588 |
589 | return 0;
590 | }
591 | YY_RULE(int) yy_quoted_comment(GREG *G)
592 | { int yypos0= G->pos, yythunkpos0= G->thunkpos; yyprintfv((stderr, "%s\n", "quoted_comment"));
593 | if (!yymatchString(G, "/*")) goto l9;
594 |
595 | l10:;
596 | { int yypos11= G->pos, yythunkpos11= G->thunkpos;
597 | { int yypos12= G->pos, yythunkpos12= G->thunkpos; if (!yymatchString(G, "*/")) goto l12;
598 | goto l11;
599 | l12:; G->pos= yypos12; G->thunkpos= yythunkpos12;
600 | } if (!yymatchDot(G)) goto l11; goto l10;
601 | l11:; G->pos= yypos11; G->thunkpos= yythunkpos11;
602 | } if (!yymatchString(G, "*/")) goto l9;
603 | yyprintf((stderr, " ok quoted_comment"));
604 | yyprintfGcontext;
605 | yyprintf((stderr, "\n"));
606 |
607 | return 1;
608 | l9:; G->pos= yypos0; G->thunkpos= yythunkpos0; yyprintfv((stderr, " fail %s", "quoted_comment"));
609 | yyprintfvGcontext;
610 | yyprintfv((stderr, "\n"));
611 |
612 | return 0;
613 | }
614 | YY_RULE(int) yy_single_line_comment(GREG *G)
615 | { int yypos0= G->pos, yythunkpos0= G->thunkpos; yyprintfv((stderr, "%s\n", "single_line_comment"));
616 |
617 | { int yypos14= G->pos, yythunkpos14= G->thunkpos; if (!yymatchChar(G, '#')) goto l15;
618 | goto l14;
619 | l15:; G->pos= yypos14; G->thunkpos= yythunkpos14; if (!yymatchString(G, "//")) goto l13;
620 |
621 | }
622 | l14:; if (!yy_till_end_of_line(G)) goto l13;
623 | yyprintf((stderr, " ok single_line_comment"));
624 | yyprintfGcontext;
625 | yyprintf((stderr, "\n"));
626 |
627 | return 1;
628 | l13:; G->pos= yypos0; G->thunkpos= yythunkpos0; yyprintfv((stderr, " fail %s", "single_line_comment"));
629 | yyprintfvGcontext;
630 | yyprintfv((stderr, "\n"));
631 |
632 | return 0;
633 | }
634 | YY_RULE(int) yy_space(GREG *G)
635 | { int yypos0= G->pos, yythunkpos0= G->thunkpos; yyprintfv((stderr, "%s\n", "space"));
636 |
637 | { int yypos17= G->pos, yythunkpos17= G->thunkpos; if (!yymatchChar(G, ' ')) goto l18;
638 | goto l17;
639 | l18:; G->pos= yypos17; G->thunkpos= yythunkpos17; if (!yymatchChar(G, '\t')) goto l19;
640 | goto l17;
641 | l19:; G->pos= yypos17; G->thunkpos= yythunkpos17; if (!yy_end_of_line(G)) goto l16;
642 |
643 | }
644 | l17:; yyprintf((stderr, " ok space"));
645 | yyprintfGcontext;
646 | yyprintf((stderr, "\n"));
647 |
648 | return 1;
649 | l16:; G->pos= yypos0; G->thunkpos= yythunkpos0; yyprintfv((stderr, " fail %s", "space"));
650 | yyprintfvGcontext;
651 | yyprintfv((stderr, "\n"));
652 |
653 | return 0;
654 | }
655 | YY_RULE(int) yy_braces(GREG *G)
656 | { int yypos0= G->pos, yythunkpos0= G->thunkpos; yyprintfv((stderr, "%s\n", "braces"));
657 |
658 | { int yypos21= G->pos, yythunkpos21= G->thunkpos; if (!yymatchChar(G, '{')) goto l22;
659 |
660 | l23:;
661 | { int yypos24= G->pos, yythunkpos24= G->thunkpos;
662 | { int yypos25= G->pos, yythunkpos25= G->thunkpos; if (!yymatchChar(G, '}')) goto l25;
663 | goto l24;
664 | l25:; G->pos= yypos25; G->thunkpos= yythunkpos25;
665 | } if (!yymatchDot(G)) goto l24; goto l23;
666 | l24:; G->pos= yypos24; G->thunkpos= yythunkpos24;
667 | } if (!yymatchChar(G, '}')) goto l22;
668 | goto l21;
669 | l22:; G->pos= yypos21; G->thunkpos= yythunkpos21;
670 | { int yypos26= G->pos, yythunkpos26= G->thunkpos; if (!yymatchChar(G, '}')) goto l26;
671 | goto l20;
672 | l26:; G->pos= yypos26; G->thunkpos= yythunkpos26;
673 | } if (!yymatchDot(G)) goto l20;
674 | }
675 | l21:; yyprintf((stderr, " ok braces"));
676 | yyprintfGcontext;
677 | yyprintf((stderr, "\n"));
678 |
679 | return 1;
680 | l20:; G->pos= yypos0; G->thunkpos= yythunkpos0; yyprintfv((stderr, " fail %s", "braces"));
681 | yyprintfvGcontext;
682 | yyprintfv((stderr, "\n"));
683 |
684 | return 0;
685 | }
686 | YY_RULE(int) yy_range(GREG *G)
687 | { int yypos0= G->pos, yythunkpos0= G->thunkpos; yyprintfv((stderr, "%s\n", "range"));
688 |
689 | { int yypos28= G->pos, yythunkpos28= G->thunkpos; if (!yy_char(G)) goto l29;
690 | if (!yymatchChar(G, '-')) goto l29;
691 | if (!yy_char(G)) goto l29;
692 | goto l28;
693 | l29:; G->pos= yypos28; G->thunkpos= yythunkpos28; if (!yy_char(G)) goto l27;
694 |
695 | }
696 | l28:; yyprintf((stderr, " ok range"));
697 | yyprintfGcontext;
698 | yyprintf((stderr, "\n"));
699 |
700 | return 1;
701 | l27:; G->pos= yypos0; G->thunkpos= yythunkpos0; yyprintfv((stderr, " fail %s", "range"));
702 | yyprintfvGcontext;
703 | yyprintfv((stderr, "\n"));
704 |
705 | return 0;
706 | }
707 | YY_RULE(int) yy_char(GREG *G)
708 | { int yypos0= G->pos, yythunkpos0= G->thunkpos; yyprintfv((stderr, "%s\n", "char"));
709 |
710 | { int yypos31= G->pos, yythunkpos31= G->thunkpos; if (!yymatchChar(G, '\\')) goto l32;
711 | if (!yymatchClass(G, (const unsigned char *)"\000\000\000\000\204\000\000\000\000\000\000\070\146\100\124\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000", "abefnrtv'\"\\[\\]\\\\")) goto l32;
712 | goto l31;
713 | l32:; G->pos= yypos31; G->thunkpos= yythunkpos31; if (!yymatchChar(G, '\\')) goto l33;
714 | if (!yymatchClass(G, (const unsigned char *)"\000\000\000\000\000\000\017\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000", "0-3")) goto l33;
715 | if (!yymatchClass(G, (const unsigned char *)"\000\000\000\000\000\000\377\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000", "0-7")) goto l33;
716 | if (!yymatchClass(G, (const unsigned char *)"\000\000\000\000\000\000\377\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000", "0-7")) goto l33;
717 | goto l31;
718 | l33:; G->pos= yypos31; G->thunkpos= yythunkpos31; if (!yymatchChar(G, '\\')) goto l34;
719 | if (!yymatchClass(G, (const unsigned char *)"\000\000\000\000\000\000\377\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000", "0-7")) goto l34;
720 |
721 | { int yypos35= G->pos, yythunkpos35= G->thunkpos; if (!yymatchClass(G, (const unsigned char *)"\000\000\000\000\000\000\377\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000", "0-7")) goto l35;
722 | goto l36;
723 | l35:; G->pos= yypos35; G->thunkpos= yythunkpos35;
724 | }
725 | l36:; goto l31;
726 | l34:; G->pos= yypos31; G->thunkpos= yythunkpos31;
727 | { int yypos37= G->pos, yythunkpos37= G->thunkpos; if (!yymatchChar(G, '\\')) goto l37;
728 | goto l30;
729 | l37:; G->pos= yypos37; G->thunkpos= yythunkpos37;
730 | } if (!yymatchDot(G)) goto l30;
731 | }
732 | l31:; yyprintf((stderr, " ok char"));
733 | yyprintfGcontext;
734 | yyprintf((stderr, "\n"));
735 |
736 | return 1;
737 | l30:; G->pos= yypos0; G->thunkpos= yythunkpos0; yyprintfv((stderr, " fail %s", "char"));
738 | yyprintfvGcontext;
739 | yyprintfv((stderr, "\n"));
740 |
741 | return 0;
742 | }
743 | YY_RULE(int) yy_errblock(GREG *G)
744 | { int yypos0= G->pos, yythunkpos0= G->thunkpos; yyprintfv((stderr, "%s\n", "errblock"));
745 | if (!yymatchString(G, "~{")) goto l38;
746 | yyText(G, G->begin, G->end); if (!(YY_BEGIN)) goto l38;
747 | l39:;
748 | { int yypos40= G->pos, yythunkpos40= G->thunkpos; if (!yy_braces(G)) goto l40;
749 | goto l39;
750 | l40:; G->pos= yypos40; G->thunkpos= yythunkpos40;
751 | } yyText(G, G->begin, G->end); if (!(YY_END)) goto l38; if (!yymatchChar(G, '}')) goto l38;
752 | if (!yy__(G)) goto l38;
753 | yyprintf((stderr, " ok errblock"));
754 | yyprintfGcontext;
755 | yyprintf((stderr, "\n"));
756 |
757 | return 1;
758 | l38:; G->pos= yypos0; G->thunkpos= yythunkpos0; yyprintfv((stderr, " fail %s", "errblock"));
759 | yyprintfvGcontext;
760 | yyprintfv((stderr, "\n"));
761 |
762 | return 0;
763 | }
764 | YY_RULE(int) yy_END(GREG *G)
765 | { int yypos0= G->pos, yythunkpos0= G->thunkpos; yyprintfv((stderr, "%s\n", "END"));
766 | if (!yymatchChar(G, '>')) goto l41;
767 | if (!yy__(G)) goto l41;
768 | yyprintf((stderr, " ok END"));
769 | yyprintfGcontext;
770 | yyprintf((stderr, "\n"));
771 |
772 | return 1;
773 | l41:; G->pos= yypos0; G->thunkpos= yythunkpos0; yyprintfv((stderr, " fail %s", "END"));
774 | yyprintfvGcontext;
775 | yyprintfv((stderr, "\n"));
776 |
777 | return 0;
778 | }
779 | YY_RULE(int) yy_BEGIN(GREG *G)
780 | { int yypos0= G->pos, yythunkpos0= G->thunkpos; yyprintfv((stderr, "%s\n", "BEGIN"));
781 | if (!yymatchChar(G, '<')) goto l42;
782 | if (!yy__(G)) goto l42;
783 | yyprintf((stderr, " ok BEGIN"));
784 | yyprintfGcontext;
785 | yyprintf((stderr, "\n"));
786 |
787 | return 1;
788 | l42:; G->pos= yypos0; G->thunkpos= yythunkpos0; yyprintfv((stderr, " fail %s", "BEGIN"));
789 | yyprintfvGcontext;
790 | yyprintfv((stderr, "\n"));
791 |
792 | return 0;
793 | }
794 | YY_RULE(int) yy_DOT(GREG *G)
795 | { int yypos0= G->pos, yythunkpos0= G->thunkpos; yyprintfv((stderr, "%s\n", "DOT"));
796 | if (!yymatchChar(G, '.')) goto l43;
797 | if (!yy__(G)) goto l43;
798 | yyprintf((stderr, " ok DOT"));
799 | yyprintfGcontext;
800 | yyprintf((stderr, "\n"));
801 |
802 | return 1;
803 | l43:; G->pos= yypos0; G->thunkpos= yythunkpos0; yyprintfv((stderr, " fail %s", "DOT"));
804 | yyprintfvGcontext;
805 | yyprintfv((stderr, "\n"));
806 |
807 | return 0;
808 | }
809 | YY_RULE(int) yy_class(GREG *G)
810 | { int yypos0= G->pos, yythunkpos0= G->thunkpos; yyprintfv((stderr, "%s\n", "class"));
811 | if (!yymatchChar(G, '[')) goto l44;
812 | yyText(G, G->begin, G->end); if (!(YY_BEGIN)) goto l44;
813 | l45:;
814 | { int yypos46= G->pos, yythunkpos46= G->thunkpos;
815 | { int yypos47= G->pos, yythunkpos47= G->thunkpos; if (!yymatchChar(G, ']')) goto l47;
816 | goto l46;
817 | l47:; G->pos= yypos47; G->thunkpos= yythunkpos47;
818 | } if (!yy_range(G)) goto l46;
819 | goto l45;
820 | l46:; G->pos= yypos46; G->thunkpos= yythunkpos46;
821 | } yyText(G, G->begin, G->end); if (!(YY_END)) goto l44; if (!yymatchChar(G, ']')) goto l44;
822 | if (!yy__(G)) goto l44;
823 | yyprintf((stderr, " ok class"));
824 | yyprintfGcontext;
825 | yyprintf((stderr, "\n"));
826 |
827 | return 1;
828 | l44:; G->pos= yypos0; G->thunkpos= yythunkpos0; yyprintfv((stderr, " fail %s", "class"));
829 | yyprintfvGcontext;
830 | yyprintfv((stderr, "\n"));
831 |
832 | return 0;
833 | }
834 | YY_RULE(int) yy_literal(GREG *G)
835 | { int yypos0= G->pos, yythunkpos0= G->thunkpos; yyprintfv((stderr, "%s\n", "literal"));
836 |
837 | { int yypos49= G->pos, yythunkpos49= G->thunkpos; if (!yymatchClass(G, (const unsigned char *)"\000\000\000\000\200\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000", "'")) goto l50;
838 | yyText(G, G->begin, G->end); if (!(YY_BEGIN)) goto l50;
839 | l51:;
840 | { int yypos52= G->pos, yythunkpos52= G->thunkpos;
841 | { int yypos53= G->pos, yythunkpos53= G->thunkpos; if (!yymatchClass(G, (const unsigned char *)"\000\000\000\000\200\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000", "'")) goto l53;
842 | goto l52;
843 | l53:; G->pos= yypos53; G->thunkpos= yythunkpos53;
844 | } if (!yy_char(G)) goto l52;
845 | goto l51;
846 | l52:; G->pos= yypos52; G->thunkpos= yythunkpos52;
847 | } yyText(G, G->begin, G->end); if (!(YY_END)) goto l50; if (!yymatchClass(G, (const unsigned char *)"\000\000\000\000\200\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000", "'")) goto l50;
848 | if (!yy__(G)) goto l50;
849 | goto l49;
850 | l50:; G->pos= yypos49; G->thunkpos= yythunkpos49; if (!yymatchClass(G, (const unsigned char *)"\000\000\000\000\004\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000", "\"")) goto l48;
851 | yyText(G, G->begin, G->end); if (!(YY_BEGIN)) goto l48;
852 | l54:;
853 | { int yypos55= G->pos, yythunkpos55= G->thunkpos;
854 | { int yypos56= G->pos, yythunkpos56= G->thunkpos; if (!yymatchClass(G, (const unsigned char *)"\000\000\000\000\004\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000", "\"")) goto l56;
855 | goto l55;
856 | l56:; G->pos= yypos56; G->thunkpos= yythunkpos56;
857 | } if (!yy_char(G)) goto l55;
858 | goto l54;
859 | l55:; G->pos= yypos55; G->thunkpos= yythunkpos55;
860 | } yyText(G, G->begin, G->end); if (!(YY_END)) goto l48; if (!yymatchClass(G, (const unsigned char *)"\000\000\000\000\004\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000", "\"")) goto l48;
861 | if (!yy__(G)) goto l48;
862 |
863 | }
864 | l49:; yyprintf((stderr, " ok literal"));
865 | yyprintfGcontext;
866 | yyprintf((stderr, "\n"));
867 |
868 | return 1;
869 | l48:; G->pos= yypos0; G->thunkpos= yythunkpos0; yyprintfv((stderr, " fail %s", "literal"));
870 | yyprintfvGcontext;
871 | yyprintfv((stderr, "\n"));
872 |
873 | return 0;
874 | }
875 | YY_RULE(int) yy_CLOSE(GREG *G)
876 | { int yypos0= G->pos, yythunkpos0= G->thunkpos; yyprintfv((stderr, "%s\n", "CLOSE"));
877 | if (!yymatchChar(G, ')')) goto l57;
878 | if (!yy__(G)) goto l57;
879 | yyprintf((stderr, " ok CLOSE"));
880 | yyprintfGcontext;
881 | yyprintf((stderr, "\n"));
882 |
883 | return 1;
884 | l57:; G->pos= yypos0; G->thunkpos= yythunkpos0; yyprintfv((stderr, " fail %s", "CLOSE"));
885 | yyprintfvGcontext;
886 | yyprintfv((stderr, "\n"));
887 |
888 | return 0;
889 | }
890 | YY_RULE(int) yy_OPEN(GREG *G)
891 | { int yypos0= G->pos, yythunkpos0= G->thunkpos; yyprintfv((stderr, "%s\n", "OPEN"));
892 | if (!yymatchChar(G, '(')) goto l58;
893 | if (!yy__(G)) goto l58;
894 | yyprintf((stderr, " ok OPEN"));
895 | yyprintfGcontext;
896 | yyprintf((stderr, "\n"));
897 |
898 | return 1;
899 | l58:; G->pos= yypos0; G->thunkpos= yythunkpos0; yyprintfv((stderr, " fail %s", "OPEN"));
900 | yyprintfvGcontext;
901 | yyprintfv((stderr, "\n"));
902 |
903 | return 0;
904 | }
905 | YY_RULE(int) yy_COLON(GREG *G)
906 | { int yypos0= G->pos, yythunkpos0= G->thunkpos; yyprintfv((stderr, "%s\n", "COLON"));
907 | if (!yymatchChar(G, ':')) goto l59;
908 | if (!yy__(G)) goto l59;
909 | yyprintf((stderr, " ok COLON"));
910 | yyprintfGcontext;
911 | yyprintf((stderr, "\n"));
912 |
913 | return 1;
914 | l59:; G->pos= yypos0; G->thunkpos= yythunkpos0; yyprintfv((stderr, " fail %s", "COLON"));
915 | yyprintfvGcontext;
916 | yyprintfv((stderr, "\n"));
917 |
918 | return 0;
919 | }
920 | YY_RULE(int) yy_PLUS(GREG *G)
921 | { int yypos0= G->pos, yythunkpos0= G->thunkpos; yyprintfv((stderr, "%s\n", "PLUS"));
922 | if (!yymatchChar(G, '+')) goto l60;
923 | if (!yy__(G)) goto l60;
924 | yyprintf((stderr, " ok PLUS"));
925 | yyprintfGcontext;
926 | yyprintf((stderr, "\n"));
927 |
928 | return 1;
929 | l60:; G->pos= yypos0; G->thunkpos= yythunkpos0; yyprintfv((stderr, " fail %s", "PLUS"));
930 | yyprintfvGcontext;
931 | yyprintfv((stderr, "\n"));
932 |
933 | return 0;
934 | }
935 | YY_RULE(int) yy_STAR(GREG *G)
936 | { int yypos0= G->pos, yythunkpos0= G->thunkpos; yyprintfv((stderr, "%s\n", "STAR"));
937 | if (!yymatchChar(G, '*')) goto l61;
938 | if (!yy__(G)) goto l61;
939 | yyprintf((stderr, " ok STAR"));
940 | yyprintfGcontext;
941 | yyprintf((stderr, "\n"));
942 |
943 | return 1;
944 | l61:; G->pos= yypos0; G->thunkpos= yythunkpos0; yyprintfv((stderr, " fail %s", "STAR"));
945 | yyprintfvGcontext;
946 | yyprintfv((stderr, "\n"));
947 |
948 | return 0;
949 | }
950 | YY_RULE(int) yy_QUESTION(GREG *G)
951 | { int yypos0= G->pos, yythunkpos0= G->thunkpos; yyprintfv((stderr, "%s\n", "QUESTION"));
952 | if (!yymatchChar(G, '?')) goto l62;
953 | if (!yy__(G)) goto l62;
954 | yyprintf((stderr, " ok QUESTION"));
955 | yyprintfGcontext;
956 | yyprintf((stderr, "\n"));
957 |
958 | return 1;
959 | l62:; G->pos= yypos0; G->thunkpos= yythunkpos0; yyprintfv((stderr, " fail %s", "QUESTION"));
960 | yyprintfvGcontext;
961 | yyprintfv((stderr, "\n"));
962 |
963 | return 0;
964 | }
965 | YY_RULE(int) yy_primary(GREG *G)
966 | { int yypos0= G->pos, yythunkpos0= G->thunkpos; yyprintfv((stderr, "%s\n", "primary"));
967 |
968 | { int yypos64= G->pos, yythunkpos64= G->thunkpos; if (!yy_identifier(G)) goto l65;
969 | yyDo(G, yy_1_primary, G->begin, G->end, "yy_1_primary");
970 | if (!yy_COLON(G)) goto l65;
971 | if (!yy_identifier(G)) goto l65;
972 |
973 | { int yypos66= G->pos, yythunkpos66= G->thunkpos; if (!yy_EQUAL(G)) goto l66;
974 | goto l65;
975 | l66:; G->pos= yypos66; G->thunkpos= yythunkpos66;
976 | } yyDo(G, yy_2_primary, G->begin, G->end, "yy_2_primary");
977 | goto l64;
978 | l65:; G->pos= yypos64; G->thunkpos= yythunkpos64; if (!yy_identifier(G)) goto l67;
979 |
980 | { int yypos68= G->pos, yythunkpos68= G->thunkpos; if (!yy_EQUAL(G)) goto l68;
981 | goto l67;
982 | l68:; G->pos= yypos68; G->thunkpos= yythunkpos68;
983 | } yyDo(G, yy_3_primary, G->begin, G->end, "yy_3_primary");
984 | goto l64;
985 | l67:; G->pos= yypos64; G->thunkpos= yythunkpos64; if (!yy_OPEN(G)) goto l69;
986 | if (!yy_expression(G)) goto l69;
987 | if (!yy_CLOSE(G)) goto l69;
988 | goto l64;
989 | l69:; G->pos= yypos64; G->thunkpos= yythunkpos64; if (!yy_literal(G)) goto l70;
990 | yyDo(G, yy_4_primary, G->begin, G->end, "yy_4_primary");
991 | goto l64;
992 | l70:; G->pos= yypos64; G->thunkpos= yythunkpos64; if (!yy_class(G)) goto l71;
993 | yyDo(G, yy_5_primary, G->begin, G->end, "yy_5_primary");
994 | goto l64;
995 | l71:; G->pos= yypos64; G->thunkpos= yythunkpos64; if (!yy_DOT(G)) goto l72;
996 | yyDo(G, yy_6_primary, G->begin, G->end, "yy_6_primary");
997 | goto l64;
998 | l72:; G->pos= yypos64; G->thunkpos= yythunkpos64; if (!yy_action(G)) goto l73;
999 | yyDo(G, yy_7_primary, G->begin, G->end, "yy_7_primary");
1000 | goto l64;
1001 | l73:; G->pos= yypos64; G->thunkpos= yythunkpos64; if (!yy_BEGIN(G)) goto l74;
1002 | yyDo(G, yy_8_primary, G->begin, G->end, "yy_8_primary");
1003 | goto l64;
1004 | l74:; G->pos= yypos64; G->thunkpos= yythunkpos64; if (!yy_END(G)) goto l63;
1005 | yyDo(G, yy_9_primary, G->begin, G->end, "yy_9_primary");
1006 |
1007 | }
1008 | l64:;
1009 | { int yypos75= G->pos, yythunkpos75= G->thunkpos; if (!yy_errblock(G)) goto l75;
1010 | yyDo(G, yy_10_primary, G->begin, G->end, "yy_10_primary");
1011 | goto l76;
1012 | l75:; G->pos= yypos75; G->thunkpos= yythunkpos75;
1013 | }
1014 | l76:; yyprintf((stderr, " ok primary"));
1015 | yyprintfGcontext;
1016 | yyprintf((stderr, "\n"));
1017 |
1018 | return 1;
1019 | l63:; G->pos= yypos0; G->thunkpos= yythunkpos0; yyprintfv((stderr, " fail %s", "primary"));
1020 | yyprintfvGcontext;
1021 | yyprintfv((stderr, "\n"));
1022 |
1023 | return 0;
1024 | }
1025 | YY_RULE(int) yy_NOT(GREG *G)
1026 | { int yypos0= G->pos, yythunkpos0= G->thunkpos; yyprintfv((stderr, "%s\n", "NOT"));
1027 | if (!yymatchChar(G, '!')) goto l77;
1028 | if (!yy__(G)) goto l77;
1029 | yyprintf((stderr, " ok NOT"));
1030 | yyprintfGcontext;
1031 | yyprintf((stderr, "\n"));
1032 |
1033 | return 1;
1034 | l77:; G->pos= yypos0; G->thunkpos= yythunkpos0; yyprintfv((stderr, " fail %s", "NOT"));
1035 | yyprintfvGcontext;
1036 | yyprintfv((stderr, "\n"));
1037 |
1038 | return 0;
1039 | }
1040 | YY_RULE(int) yy_suffix(GREG *G)
1041 | { int yypos0= G->pos, yythunkpos0= G->thunkpos; yyprintfv((stderr, "%s\n", "suffix"));
1042 | if (!yy_primary(G)) goto l78;
1043 |
1044 | { int yypos79= G->pos, yythunkpos79= G->thunkpos;
1045 | { int yypos81= G->pos, yythunkpos81= G->thunkpos; if (!yy_QUESTION(G)) goto l82;
1046 | yyDo(G, yy_1_suffix, G->begin, G->end, "yy_1_suffix");
1047 | goto l81;
1048 | l82:; G->pos= yypos81; G->thunkpos= yythunkpos81; if (!yy_STAR(G)) goto l83;
1049 | yyDo(G, yy_2_suffix, G->begin, G->end, "yy_2_suffix");
1050 | goto l81;
1051 | l83:; G->pos= yypos81; G->thunkpos= yythunkpos81; if (!yy_PLUS(G)) goto l79;
1052 | yyDo(G, yy_3_suffix, G->begin, G->end, "yy_3_suffix");
1053 |
1054 | }
1055 | l81:; goto l80;
1056 | l79:; G->pos= yypos79; G->thunkpos= yythunkpos79;
1057 | }
1058 | l80:; yyprintf((stderr, " ok suffix"));
1059 | yyprintfGcontext;
1060 | yyprintf((stderr, "\n"));
1061 |
1062 | return 1;
1063 | l78:; G->pos= yypos0; G->thunkpos= yythunkpos0; yyprintfv((stderr, " fail %s", "suffix"));
1064 | yyprintfvGcontext;
1065 | yyprintfv((stderr, "\n"));
1066 |
1067 | return 0;
1068 | }
1069 | YY_RULE(int) yy_action(GREG *G)
1070 | { int yypos0= G->pos, yythunkpos0= G->thunkpos; yyprintfv((stderr, "%s\n", "action"));
1071 | if (!yymatchChar(G, '{')) goto l84;
1072 | yyText(G, G->begin, G->end); if (!(YY_BEGIN)) goto l84;
1073 | l85:;
1074 | { int yypos86= G->pos, yythunkpos86= G->thunkpos; if (!yy_braces(G)) goto l86;
1075 | goto l85;
1076 | l86:; G->pos= yypos86; G->thunkpos= yythunkpos86;
1077 | } yyText(G, G->begin, G->end); if (!(YY_END)) goto l84; if (!yymatchChar(G, '}')) goto l84;
1078 | if (!yy__(G)) goto l84;
1079 | yyprintf((stderr, " ok action"));
1080 | yyprintfGcontext;
1081 | yyprintf((stderr, "\n"));
1082 |
1083 | return 1;
1084 | l84:; G->pos= yypos0; G->thunkpos= yythunkpos0; yyprintfv((stderr, " fail %s", "action"));
1085 | yyprintfvGcontext;
1086 | yyprintfv((stderr, "\n"));
1087 |
1088 | return 0;
1089 | }
1090 | YY_RULE(int) yy_AND(GREG *G)
1091 | { int yypos0= G->pos, yythunkpos0= G->thunkpos; yyprintfv((stderr, "%s\n", "AND"));
1092 | if (!yymatchChar(G, '&')) goto l87;
1093 | if (!yy__(G)) goto l87;
1094 | yyprintf((stderr, " ok AND"));
1095 | yyprintfGcontext;
1096 | yyprintf((stderr, "\n"));
1097 |
1098 | return 1;
1099 | l87:; G->pos= yypos0; G->thunkpos= yythunkpos0; yyprintfv((stderr, " fail %s", "AND"));
1100 | yyprintfvGcontext;
1101 | yyprintfv((stderr, "\n"));
1102 |
1103 | return 0;
1104 | }
1105 | YY_RULE(int) yy_prefix(GREG *G)
1106 | { int yypos0= G->pos, yythunkpos0= G->thunkpos; yyprintfv((stderr, "%s\n", "prefix"));
1107 |
1108 | { int yypos89= G->pos, yythunkpos89= G->thunkpos; if (!yy_AND(G)) goto l90;
1109 | if (!yy_action(G)) goto l90;
1110 | yyDo(G, yy_1_prefix, G->begin, G->end, "yy_1_prefix");
1111 | goto l89;
1112 | l90:; G->pos= yypos89; G->thunkpos= yythunkpos89; if (!yy_AND(G)) goto l91;
1113 | if (!yy_suffix(G)) goto l91;
1114 | yyDo(G, yy_2_prefix, G->begin, G->end, "yy_2_prefix");
1115 | goto l89;
1116 | l91:; G->pos= yypos89; G->thunkpos= yythunkpos89; if (!yy_NOT(G)) goto l92;
1117 | if (!yy_suffix(G)) goto l92;
1118 | yyDo(G, yy_3_prefix, G->begin, G->end, "yy_3_prefix");
1119 | goto l89;
1120 | l92:; G->pos= yypos89; G->thunkpos= yythunkpos89; if (!yy_suffix(G)) goto l88;
1121 |
1122 | }
1123 | l89:; yyprintf((stderr, " ok prefix"));
1124 | yyprintfGcontext;
1125 | yyprintf((stderr, "\n"));
1126 |
1127 | return 1;
1128 | l88:; G->pos= yypos0; G->thunkpos= yythunkpos0; yyprintfv((stderr, " fail %s", "prefix"));
1129 | yyprintfvGcontext;
1130 | yyprintfv((stderr, "\n"));
1131 |
1132 | return 0;
1133 | }
1134 | YY_RULE(int) yy_BAR(GREG *G)
1135 | { int yypos0= G->pos, yythunkpos0= G->thunkpos; yyprintfv((stderr, "%s\n", "BAR"));
1136 | if (!yymatchChar(G, '|')) goto l93;
1137 | if (!yy__(G)) goto l93;
1138 | yyprintf((stderr, " ok BAR"));
1139 | yyprintfGcontext;
1140 | yyprintf((stderr, "\n"));
1141 |
1142 | return 1;
1143 | l93:; G->pos= yypos0; G->thunkpos= yythunkpos0; yyprintfv((stderr, " fail %s", "BAR"));
1144 | yyprintfvGcontext;
1145 | yyprintfv((stderr, "\n"));
1146 |
1147 | return 0;
1148 | }
1149 | YY_RULE(int) yy_sequence(GREG *G)
1150 | { int yypos0= G->pos, yythunkpos0= G->thunkpos; yyprintfv((stderr, "%s\n", "sequence"));
1151 | if (!yy_prefix(G)) goto l94;
1152 |
1153 | l95:;
1154 | { int yypos96= G->pos, yythunkpos96= G->thunkpos; if (!yy_prefix(G)) goto l96;
1155 | yyDo(G, yy_1_sequence, G->begin, G->end, "yy_1_sequence");
1156 | goto l95;
1157 | l96:; G->pos= yypos96; G->thunkpos= yythunkpos96;
1158 | } yyprintf((stderr, " ok sequence"));
1159 | yyprintfGcontext;
1160 | yyprintf((stderr, "\n"));
1161 |
1162 | return 1;
1163 | l94:; G->pos= yypos0; G->thunkpos= yythunkpos0; yyprintfv((stderr, " fail %s", "sequence"));
1164 | yyprintfvGcontext;
1165 | yyprintfv((stderr, "\n"));
1166 |
1167 | return 0;
1168 | }
1169 | YY_RULE(int) yy_SEMICOLON(GREG *G)
1170 | { int yypos0= G->pos, yythunkpos0= G->thunkpos; yyprintfv((stderr, "%s\n", "SEMICOLON"));
1171 | if (!yymatchChar(G, ';')) goto l97;
1172 | if (!yy__(G)) goto l97;
1173 | yyprintf((stderr, " ok SEMICOLON"));
1174 | yyprintfGcontext;
1175 | yyprintf((stderr, "\n"));
1176 |
1177 | return 1;
1178 | l97:; G->pos= yypos0; G->thunkpos= yythunkpos0; yyprintfv((stderr, " fail %s", "SEMICOLON"));
1179 | yyprintfvGcontext;
1180 | yyprintfv((stderr, "\n"));
1181 |
1182 | return 0;
1183 | }
1184 | YY_RULE(int) yy_expression(GREG *G)
1185 | { int yypos0= G->pos, yythunkpos0= G->thunkpos; yyprintfv((stderr, "%s\n", "expression"));
1186 | if (!yy_sequence(G)) goto l98;
1187 |
1188 | l99:;
1189 | { int yypos100= G->pos, yythunkpos100= G->thunkpos; if (!yy_BAR(G)) goto l100;
1190 | if (!yy_sequence(G)) goto l100;
1191 | yyDo(G, yy_1_expression, G->begin, G->end, "yy_1_expression");
1192 | goto l99;
1193 | l100:; G->pos= yypos100; G->thunkpos= yythunkpos100;
1194 | } yyprintf((stderr, " ok expression"));
1195 | yyprintfGcontext;
1196 | yyprintf((stderr, "\n"));
1197 |
1198 | return 1;
1199 | l98:; G->pos= yypos0; G->thunkpos= yythunkpos0; yyprintfv((stderr, " fail %s", "expression"));
1200 | yyprintfvGcontext;
1201 | yyprintfv((stderr, "\n"));
1202 |
1203 | return 0;
1204 | }
1205 | YY_RULE(int) yy_EQUAL(GREG *G)
1206 | { int yypos0= G->pos, yythunkpos0= G->thunkpos; yyprintfv((stderr, "%s\n", "EQUAL"));
1207 | if (!yymatchChar(G, '=')) goto l101;
1208 | if (!yy__(G)) goto l101;
1209 | yyprintf((stderr, " ok EQUAL"));
1210 | yyprintfGcontext;
1211 | yyprintf((stderr, "\n"));
1212 |
1213 | return 1;
1214 | l101:; G->pos= yypos0; G->thunkpos= yythunkpos0; yyprintfv((stderr, " fail %s", "EQUAL"));
1215 | yyprintfvGcontext;
1216 | yyprintfv((stderr, "\n"));
1217 |
1218 | return 0;
1219 | }
1220 | YY_RULE(int) yy_identifier(GREG *G)
1221 | { int yypos0= G->pos, yythunkpos0= G->thunkpos; yyprintfv((stderr, "%s\n", "identifier"));
1222 | yyText(G, G->begin, G->end); if (!(YY_BEGIN)) goto l102; if (!yymatchClass(G, (const unsigned char *)"\000\000\000\000\000\040\000\000\376\377\377\207\376\377\377\007\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000", "-a-zA-Z_")) goto l102;
1223 |
1224 | l103:;
1225 | { int yypos104= G->pos, yythunkpos104= G->thunkpos; if (!yymatchClass(G, (const unsigned char *)"\000\000\000\000\000\040\377\003\376\377\377\207\376\377\377\007\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000", "-a-zA-Z_0-9")) goto l104;
1226 | goto l103;
1227 | l104:; G->pos= yypos104; G->thunkpos= yythunkpos104;
1228 | } yyText(G, G->begin, G->end); if (!(YY_END)) goto l102; if (!yy__(G)) goto l102;
1229 | yyprintf((stderr, " ok identifier"));
1230 | yyprintfGcontext;
1231 | yyprintf((stderr, "\n"));
1232 |
1233 | return 1;
1234 | l102:; G->pos= yypos0; G->thunkpos= yythunkpos0; yyprintfv((stderr, " fail %s", "identifier"));
1235 | yyprintfvGcontext;
1236 | yyprintfv((stderr, "\n"));
1237 |
1238 | return 0;
1239 | }
1240 | YY_RULE(int) yy_RPERCENT(GREG *G)
1241 | { int yypos0= G->pos, yythunkpos0= G->thunkpos; yyprintfv((stderr, "%s\n", "RPERCENT"));
1242 | if (!yymatchString(G, "%}")) goto l105;
1243 | if (!yy__(G)) goto l105;
1244 | yyprintf((stderr, " ok RPERCENT"));
1245 | yyprintfGcontext;
1246 | yyprintf((stderr, "\n"));
1247 |
1248 | return 1;
1249 | l105:; G->pos= yypos0; G->thunkpos= yythunkpos0; yyprintfv((stderr, " fail %s", "RPERCENT"));
1250 | yyprintfvGcontext;
1251 | yyprintfv((stderr, "\n"));
1252 |
1253 | return 0;
1254 | }
1255 | YY_RULE(int) yy_end_of_file(GREG *G)
1256 | { int yypos0= G->pos, yythunkpos0= G->thunkpos; yyprintfv((stderr, "%s\n", "end_of_file"));
1257 |
1258 | { int yypos107= G->pos, yythunkpos107= G->thunkpos; if (!yymatchDot(G)) goto l107; goto l106;
1259 | l107:; G->pos= yypos107; G->thunkpos= yythunkpos107;
1260 | } yyprintf((stderr, " ok end_of_file"));
1261 | yyprintfGcontext;
1262 | yyprintf((stderr, "\n"));
1263 |
1264 | return 1;
1265 | l106:; G->pos= yypos0; G->thunkpos= yythunkpos0; yyprintfv((stderr, " fail %s", "end_of_file"));
1266 | yyprintfvGcontext;
1267 | yyprintfv((stderr, "\n"));
1268 |
1269 | return 0;
1270 | }
1271 | YY_RULE(int) yy_trailer(GREG *G)
1272 | { int yypos0= G->pos, yythunkpos0= G->thunkpos; yyprintfv((stderr, "%s\n", "trailer"));
1273 | if (!yymatchString(G, "%%")) goto l108;
1274 | yyText(G, G->begin, G->end); if (!(YY_BEGIN)) goto l108;
1275 | l109:;
1276 | { int yypos110= G->pos, yythunkpos110= G->thunkpos; if (!yymatchDot(G)) goto l110; goto l109;
1277 | l110:; G->pos= yypos110; G->thunkpos= yythunkpos110;
1278 | } yyText(G, G->begin, G->end); if (!(YY_END)) goto l108; yyDo(G, yy_1_trailer, G->begin, G->end, "yy_1_trailer");
1279 | yyprintf((stderr, " ok trailer"));
1280 | yyprintfGcontext;
1281 | yyprintf((stderr, "\n"));
1282 |
1283 | return 1;
1284 | l108:; G->pos= yypos0; G->thunkpos= yythunkpos0; yyprintfv((stderr, " fail %s", "trailer"));
1285 | yyprintfvGcontext;
1286 | yyprintfv((stderr, "\n"));
1287 |
1288 | return 0;
1289 | }
1290 | YY_RULE(int) yy_definition(GREG *G)
1291 | { int yypos0= G->pos, yythunkpos0= G->thunkpos; yyDo(G, yyPush, 1, 0, "yyPush");
1292 | yyprintfv((stderr, "%s\n", "definition"));
1293 | if (!yy_identifier(G)) goto l111;
1294 | yyDo(G, yySet, -1, 0, "yySet");
1295 | yyDo(G, yy_1_definition, G->begin, G->end, "yy_1_definition");
1296 | if (!yy_EQUAL(G)) goto l111;
1297 | if (!yy_expression(G)) goto l111;
1298 | yyDo(G, yy_2_definition, G->begin, G->end, "yy_2_definition");
1299 |
1300 | { int yypos112= G->pos, yythunkpos112= G->thunkpos; if (!yy_SEMICOLON(G)) goto l112;
1301 | goto l113;
1302 | l112:; G->pos= yypos112; G->thunkpos= yythunkpos112;
1303 | }
1304 | l113:; yyprintf((stderr, " ok definition"));
1305 | yyprintfGcontext;
1306 | yyprintf((stderr, "\n"));
1307 | yyDo(G, yyPop, 1, 0, "yyPop");
1308 | return 1;
1309 | l111:; G->pos= yypos0; G->thunkpos= yythunkpos0; yyprintfv((stderr, " fail %s", "definition"));
1310 | yyprintfvGcontext;
1311 | yyprintfv((stderr, "\n"));
1312 |
1313 | return 0;
1314 | }
1315 | YY_RULE(int) yy_declaration(GREG *G)
1316 | { int yypos0= G->pos, yythunkpos0= G->thunkpos; yyprintfv((stderr, "%s\n", "declaration"));
1317 | if (!yymatchString(G, "%{")) goto l114;
1318 | yyText(G, G->begin, G->end); if (!(YY_BEGIN)) goto l114;
1319 | l115:;
1320 | { int yypos116= G->pos, yythunkpos116= G->thunkpos;
1321 | { int yypos117= G->pos, yythunkpos117= G->thunkpos; if (!yymatchString(G, "%}")) goto l117;
1322 | goto l116;
1323 | l117:; G->pos= yypos117; G->thunkpos= yythunkpos117;
1324 | } if (!yymatchDot(G)) goto l116; goto l115;
1325 | l116:; G->pos= yypos116; G->thunkpos= yythunkpos116;
1326 | } yyText(G, G->begin, G->end); if (!(YY_END)) goto l114; if (!yy_RPERCENT(G)) goto l114;
1327 | yyDo(G, yy_1_declaration, G->begin, G->end, "yy_1_declaration");
1328 | yyprintf((stderr, " ok declaration"));
1329 | yyprintfGcontext;
1330 | yyprintf((stderr, "\n"));
1331 |
1332 | return 1;
1333 | l114:; G->pos= yypos0; G->thunkpos= yythunkpos0; yyprintfv((stderr, " fail %s", "declaration"));
1334 | yyprintfvGcontext;
1335 | yyprintfv((stderr, "\n"));
1336 |
1337 | return 0;
1338 | }
1339 | YY_RULE(int) yy__(GREG *G)
1340 | { yyprintfv((stderr, "%s\n", "_"));
1341 |
1342 | l119:;
1343 | { int yypos120= G->pos, yythunkpos120= G->thunkpos;
1344 | { int yypos121= G->pos, yythunkpos121= G->thunkpos; if (!yy_space(G)) goto l122;
1345 | goto l121;
1346 | l122:; G->pos= yypos121; G->thunkpos= yythunkpos121; if (!yy_single_line_comment(G)) goto l123;
1347 | goto l121;
1348 | l123:; G->pos= yypos121; G->thunkpos= yythunkpos121; if (!yy_quoted_comment(G)) goto l120;
1349 |
1350 | }
1351 | l121:; goto l119;
1352 | l120:; G->pos= yypos120; G->thunkpos= yythunkpos120;
1353 | } yyprintf((stderr, " ok _"));
1354 | yyprintfGcontext;
1355 | yyprintf((stderr, "\n"));
1356 |
1357 | return 1;
1358 | }
1359 | YY_RULE(int) yy_grammar(GREG *G)
1360 | { int yypos0= G->pos, yythunkpos0= G->thunkpos; yyprintfv((stderr, "%s\n", "grammar"));
1361 | if (!yy__(G)) goto l124;
1362 |
1363 | { int yypos127= G->pos, yythunkpos127= G->thunkpos; if (!yy_declaration(G)) goto l128;
1364 | goto l127;
1365 | l128:; G->pos= yypos127; G->thunkpos= yythunkpos127; if (!yy_definition(G)) goto l124;
1366 |
1367 | }
1368 | l127:;
1369 | l125:;
1370 | { int yypos126= G->pos, yythunkpos126= G->thunkpos;
1371 | { int yypos129= G->pos, yythunkpos129= G->thunkpos; if (!yy_declaration(G)) goto l130;
1372 | goto l129;
1373 | l130:; G->pos= yypos129; G->thunkpos= yythunkpos129; if (!yy_definition(G)) goto l126;
1374 |
1375 | }
1376 | l129:; goto l125;
1377 | l126:; G->pos= yypos126; G->thunkpos= yythunkpos126;
1378 | }
1379 | { int yypos131= G->pos, yythunkpos131= G->thunkpos; if (!yy_trailer(G)) goto l131;
1380 | goto l132;
1381 | l131:; G->pos= yypos131; G->thunkpos= yythunkpos131;
1382 | }
1383 | l132:; if (!yy_end_of_file(G)) goto l124;
1384 | yyprintf((stderr, " ok grammar"));
1385 | yyprintfGcontext;
1386 | yyprintf((stderr, "\n"));
1387 |
1388 | return 1;
1389 | l124:; G->pos= yypos0; G->thunkpos= yythunkpos0; yyprintfv((stderr, " fail %s", "grammar"));
1390 | yyprintfvGcontext;
1391 | yyprintfv((stderr, "\n"));
1392 |
1393 | return 0;
1394 | }
1395 |
1396 | #ifndef YY_PART
1397 |
1398 | typedef int (*yyrule)(GREG *G);
1399 |
1400 | YY_PARSE(int) YY_NAME(parse_from)(GREG *G, yyrule yystart)
1401 | {
1402 | int yyok;
1403 | if (!G->buflen)
1404 | {
1405 | G->buflen= YY_BUFFER_START_SIZE;
1406 | G->buf= (char*)YY_ALLOC(G->buflen, G->data);
1407 | G->textlen= YY_BUFFER_START_SIZE;
1408 | G->text= (char*)YY_ALLOC(G->textlen, G->data);
1409 | G->thunkslen= YY_STACK_SIZE;
1410 | G->thunks= (yythunk*)YY_ALLOC(sizeof(yythunk) * G->thunkslen, G->data);
1411 | G->valslen= YY_STACK_SIZE;
1412 | G->vals= (YYSTYPE*)YY_ALLOC(sizeof(YYSTYPE) * G->valslen, G->data);
1413 | G->begin= G->end= G->pos= G->limit= G->thunkpos= 0;
1414 | }
1415 | G->pos = 0;
1416 | G->begin= G->end= G->pos;
1417 | G->thunkpos= 0;
1418 | G->val= G->vals;
1419 | yyok= yystart(G);
1420 | if (yyok) yyDone(G);
1421 | yyCommit(G);
1422 | return yyok;
1423 | (void)yyrefill;
1424 | (void)yymatchDot;
1425 | (void)yymatchChar;
1426 | (void)yymatchString;
1427 | (void)yymatchClass;
1428 | (void)yyDo;
1429 | (void)yyText;
1430 | (void)yyDone;
1431 | (void)yyCommit;
1432 | (void)yyAccept;
1433 | (void)yyPush;
1434 | (void)yyPop;
1435 | (void)yySet;
1436 | }
1437 |
1438 | YY_PARSE(int) YY_NAME(parse)(GREG *G)
1439 | {
1440 | return YY_NAME(parse_from)(G, yy_grammar);
1441 | }
1442 |
1443 | YY_PARSE(void) YY_NAME(init)(GREG *G)
1444 | {
1445 | memset(G, 0, sizeof(GREG));
1446 | }
1447 | YY_PARSE(void) YY_NAME(deinit)(GREG *G)
1448 | {
1449 | if (G->buf) YY_FREE(G->buf);
1450 | if (G->text) YY_FREE(G->text);
1451 | if (G->thunks) YY_FREE(G->thunks);
1452 | if (G->vals) YY_FREE((void*)G->vals);
1453 | }
1454 | YY_PARSE(GREG *) YY_NAME(parse_new)(YY_XTYPE data)
1455 | {
1456 | GREG *G = (GREG *)YY_CALLOC(1, sizeof(GREG), G->data);
1457 | G->data = data;
1458 | return G;
1459 | }
1460 |
1461 | YY_PARSE(void) YY_NAME(parse_free)(GREG *G)
1462 | {
1463 | YY_NAME(deinit)(G);
1464 | YY_FREE(G);
1465 | }
1466 |
1467 | #endif
1468 |
1469 |
1470 | void yyerror(struct _GREG *G, const char *message)
1471 | {
1472 | int error_line = 1;
1473 | while ( (G->pos < G->limit) && (error_line < lineNumber) )
1474 | {
1475 | switch(G->buf[G->pos++]) {
1476 | case '\n':
1477 | if(G->buf[G->pos] == '\r') { ++G->pos;}
1478 | ++error_line;
1479 | break;
1480 | case '\r':
1481 | if(G->buf[G->pos] == '\n') { ++G->pos;}
1482 | ++error_line;
1483 | break;
1484 | }
1485 | }
1486 | fprintf(stderr, "%s:%d:%d %s", fileName, lineNumber, G->limit - G->pos, message);
1487 | if (G->text[0]) fprintf(stderr, " near token '%s'", G->text);
1488 | if (G->pos < G->limit || !feof(input))
1489 | {
1490 | G->buf[G->limit]= '\0';
1491 | fprintf(stderr, " before text \"");
1492 | while (G->pos < G->limit)
1493 | {
1494 | if ('\n' == G->buf[G->pos] || '\r' == G->buf[G->pos]) break;
1495 | fputc(G->buf[G->pos++], stderr);
1496 | }
1497 | if (G->pos == G->limit)
1498 | {
1499 | int c;
1500 | while (EOF != (c= fgetc(input)) && '\n' != c && '\r' != c)
1501 | fputc(c, stderr);
1502 | }
1503 | fputc('\"', stderr);
1504 | }
1505 | fprintf(stderr, "\n");
1506 | exit(1);
1507 | }
1508 |
1509 | void makeHeader(char *text)
1510 | {
1511 | Header *header= (Header *)malloc(sizeof(Header));
1512 | header->text= strdup(text);
1513 | header->next= headers;
1514 | headers= header;
1515 | }
1516 |
1517 | void makeTrailer(char *text)
1518 | {
1519 | trailer= strdup(text);
1520 | }
1521 |
1522 | static void version(char *name)
1523 | {
1524 | printf("%s version %d.%d.%d\n", name, GREG_MAJOR, GREG_MINOR, GREG_LEVEL);
1525 | }
1526 |
1527 | static void usage(char *name)
1528 | {
1529 | version(name);
1530 | fprintf(stderr, "usage: %s [