]> git.proxmox.com Git - mirror_edk2.git/blob - BaseTools/Source/C/VfrCompile/Pccts/antlr/antlr.g
BaseTools: Various typo
[mirror_edk2.git] / BaseTools / Source / C / VfrCompile / Pccts / antlr / antlr.g
1 /*
2 * antlr.g -- PCCTS Version 1.xx ANTLR
3 *
4 * Parse an antlr input grammar and build a syntax-diagram.
5 *
6 * Written in itself (needs at least 1.06 to work)
7 *
8 * SOFTWARE RIGHTS
9 *
10 * We reserve no LEGAL rights to the Purdue Compiler Construction Tool
11 * Set (PCCTS) -- PCCTS is in the public domain. An individual or
12 * company may do whatever they wish with source code distributed with
13 * PCCTS or the code generated by PCCTS, including the incorporation of
14 * PCCTS, or its output, into commerical software.
15 *
16 * We encourage users to develop software with PCCTS. However, we do ask
17 * that credit is given to us for developing PCCTS. By "credit",
18 * we mean that if you incorporate our source code into one of your
19 * programs (commercial product, research project, or otherwise) that you
20 * acknowledge this fact somewhere in the documentation, research report,
21 * etc... If you like PCCTS and have developed a nice tool with the
22 * output, please mention that you developed it using PCCTS. In
23 * addition, we ask that this header remain intact in our source code.
24 * As long as these guidelines are kept, we expect to continue enhancing
25 * this system and expect to make other tools available as they are
26 * completed.
27 *
28 * ANTLR 1.33
29 * Terence Parr
30 * Parr Research Corporation
31 * with Purdue University and AHPCRC, University of Minnesota
32 * 1989-1995
33 */
34
35 /* MR1 */
36 /* MR1 10-Apr-97 MR1 Replace #if logic with #include "pcctscfg.h" */
37 /* MR1 */
38
39 #header <<
40 #include "pcctscfg.h"
41 #include "set.h"
42 #include <ctype.h>
43 #include "syn.h"
44 #include "hash.h"
45 #include "generic.h"
46 #define zzcr_attr(attr,tok,t)
47 >>
48
49 <<
50
51 /* MR20 G. Hobbelt For Borland C++ 4.x & 5.x compiling with ALL warnings enabled */
52 #if defined(__TURBOC__)
53 #pragma warn -aus /* unused assignment of 'xxx' */
54 #endif
55
56 #pragma clang diagnostic ignored "-Wparentheses-equality"
57
58 #ifdef __USE_PROTOS
59 static void chkToken(char *, char *, char *, int);
60 #else
61 static void chkToken();
62 #endif
63
64 #ifdef __USE_PROTOS
65 static int isDLGmaxToken(char *Token); /* MR3 */
66 #else
67 static int isDLGmaxToken(); /* MR3 */
68 #endif
69
70 static int class_nest_level = 0;
71
72 /* MR20 G. Hobbelt extern definitions moved to antlr.h */
73
74 >>
75
76 #lexaction <<
77 /* maintained, but not used for now */
78 set AST_nodes_refd_in_actions = set_init;
79 int inAlt = 0;
80 set attribsRefdFromAction = set_init; /* MR20 */
81 int UsedOldStyleAttrib = 0;
82 int UsedNewStyleLabel = 0;
83 #ifdef __USE_PROTOS
84 char *inline_set(char *);
85 #else
86 char *inline_set();
87 #endif
88
89 /* MR1 10-Apr-97 MR1 Previously unable to put right shift operator */
90 /* MR1 in DLG action */
91
92 int tokenActionActive=0; /* MR1 */
93
94 >>
95
96 #lexclass STRINGS
97 #token QuotedTerm "\"" << zzmode(START); >>
98 #token "\n|\r|\r\n" <<
99 zzline++;
100 warn("eoln found in string");
101 zzskip();
102 >>
103 #token "\\(\n|\r|\r\n)" << zzline++; zzmore(); >>
104 #token "\\~[]" << zzmore(); >>
105 #token "~[\n\r\"\\]+" << zzmore(); >>
106
107 #lexclass ACTION_STRINGS
108 #token "\"" << zzmode(ACTIONS); zzmore(); >>
109 #token "\n|\r|\r\n" <<
110 zzline++;
111 warn("eoln found in string (in user action)");
112 zzskip();
113 >>
114 #token "\\(\n|\r|\r\n)" << zzline++; zzmore(); >>
115 #token "\\~[]" << zzmore(); >>
116 #token "~[\n\r\"\\]+" << zzmore(); >>
117
118 #lexclass ACTION_CHARS
119 #token "'" << zzmode(ACTIONS); zzmore(); >>
120 #token "\n|\r|\r\n" <<
121 zzline++;
122 warn("eoln found in char literal (in user action)");
123 zzskip();
124 >>
125 #token "\\~[]" << zzmore(); >>
126 #token "~[\n\r'\\]+" << zzmore(); >>
127
128 #lexclass ACTION_COMMENTS
129 #token "\*/" << zzmode(ACTIONS); zzmore(); >>
130 #token "\*" << zzmore(); >>
131 #token "\n|\r|\r\n" << zzline++; zzmore(); DAWDLE; >>
132 #token "~[\n\r\*]+" << zzmore(); >>
133
134 #lexclass TOK_DEF_COMMENTS
135 #token "\*/" << zzmode(PARSE_ENUM_FILE);
136 zzmore(); >>
137 #token "\*" << zzmore(); >>
138 #token "\n|\r|\r\n" << zzline++; zzmore(); DAWDLE; >>
139 #token "~[\n\r\*]+" << zzmore(); >>
140
141 #lexclass TOK_DEF_CPP_COMMENTS
142 #token "\n|\r|\r\n" << zzline++; zzmode(PARSE_ENUM_FILE); zzskip(); DAWDLE; >>
143 #token "~[\n\r]+" << zzskip(); >>
144
145 #lexclass ACTION_CPP_COMMENTS
146 #token "\n|\r|\r\n" << zzline++; zzmode(ACTIONS); zzmore(); DAWDLE; >>
147 #token "~[\n\r]+" << zzmore(); >>
148
149 #lexclass CPP_COMMENTS
150 #token "\n|\r|\r\n" << zzline++; zzmode(START); zzskip(); DAWDLE; >>
151 #token "~[\n\r]+" << zzskip(); >>
152
153 #lexclass COMMENTS
154 #token "\*/" << zzmode(START); zzskip(); >>
155 #token "\*" << zzskip(); >>
156 #token "\n|\r|\r\n" << zzline++; zzskip(); DAWDLE; >>
157 #token "~[\n\r\*]+" << zzskip(); >>
158
159 /*
160 * This lexical class accepts actions of type [..] and <<..>>
161 *
162 * It translates the following special items for C:
163 *
164 * $j --> "zzaArg(current zztasp, j)"
165 * $i.j --> "zzaArg(zztaspi, j)"
166 * $i.nondigit> "zzaArg(current zztasp, i).nondigit"
167 * $$ --> "zzaRet"
168 * $alnum --> "alnum" (used to ref parameters)
169 * $rule --> "zzaRet"
170 * $retval --> "_retv.retval" if > 1 return values else "_retv"
171 * $[token, text] --> "zzconstr_attr(token, text)"
172 * $[] --> "zzempty_attr()"
173 *
174 * It translates the following special items for C++:
175 * (attributes are now stored with 'Token' and $i's are only
176 * pointers to the Tokens. Rules don't have attributes now.)
177 *
178 * $j --> "_tbj" where b is the block level
179 * $i.j --> "_tij"
180 * $j->nondigit> "_tbj->nondigit"
181 * $$ --> "$$"
182 * $alnum --> "alnum" (used to ref parameters)
183 * $rule --> "$rule"
184 * $retval --> "_retv.retval" if > 1 return values else "_retv"
185 * $[token, text] --> invalid
186 * $[] --> invalid
187 *
188 * And, for trees:
189 *
190 * #0 --> "(*_root)"
191 * #i --> "zzastArg(i)"
192 * #[args] --> "zzmk_ast(zzastnew(), args)"
193 * #[] --> "zzastnew()"
194 * #( root, child1, ..., childn )
195 * --> "zztmake(root, child1, ...., childn, NULL)"
196 * #() --> "NULL"
197 *
198 * For C++, ...
199 *
200 * #0 --> "(*_root)"
201 * #i --> "_astbi" where b is the block level
202 * #alnum --> "alnum_ast" (used to ref #label)
203 * #[args] --> "new AST(args)"
204 * #[] --> "new AST"
205 * #( root, child1, ..., childn )
206 * --> "AST::tmake(root, child1, ...., childn, NULL)"
207 * #() --> "NULL"
208 *
209 * To escape,
210 *
211 * \] --> ]
212 * \) --> )
213 * \$ --> $
214 * \# --> #
215 *
216 * A stack is used to nest action terminators because they can be nested
217 * like crazy: << #[$[..],..] >>
218 */
219 #lexclass ACTIONS
220 #token Action "\>\>" << /* these do not nest */
221 zzmode(START);
222 NLATEXT[0] = ' ';
223 NLATEXT[1] = ' ';
224 zzbegexpr[0] = ' ';
225 zzbegexpr[1] = ' ';
226 if ( zzbufovf ) {
227 err( eMsgd("action buffer overflow; size %d",ZZLEXBUFSIZE));
228 }
229
230 /* MR1 10-Apr-97 MR1 Previously unable to put right shift operator */
231 /* MR1 in DLG action */
232 /* MR1 Doesn't matter what kind of action it is - reset*/
233
234 tokenActionActive=0; /* MR1 */
235 >>
236 #token Pred "\>\>?" << /* these do not nest */
237 zzmode(START);
238 NLATEXT[0] = ' ';
239 NLATEXT[1] = ' ';
240 zzbegexpr[0] = '\0';
241 if ( zzbufovf ) {
242 err( eMsgd("predicate buffer overflow; size %d",ZZLEXBUFSIZE));
243 };
244 #ifdef __cplusplus__
245 /* MR10 */ list_apply(CurActionLabels, (void (*)(void *))mark_label_used_in_sem_pred);
246 #else
247 #ifdef __STDC__
248 /* MR10 */ list_apply(CurActionLabels, (void (*)(void *))mark_label_used_in_sem_pred);
249 #else
250 #ifdef __USE_PROTOS
251 /* MRxx */ list_apply(CurActionLabels, (void (*)(void *))mark_label_used_in_sem_pred);
252 #else
253 /* MR10 */ list_apply(CurActionLabels,mark_label_used_in_sem_pred);
254 #endif
255 #endif
256 #endif
257 >>
258 #token PassAction "\]" << if ( topint() == ']' ) {
259 popint();
260 if ( istackempty() ) /* terminate action */
261 {
262 zzmode(START);
263 NLATEXT[0] = ' ';
264 zzbegexpr[0] = ' ';
265 if ( zzbufovf ) {
266 err( eMsgd("parameter buffer overflow; size %d",ZZLEXBUFSIZE));
267 }
268 }
269 else {
270 /* terminate $[..] and #[..] */
271 if ( GenCC ) zzreplstr("))");
272 else zzreplstr(")");
273 zzmore();
274 }
275 }
276 else if ( topint() == '|' ) { /* end of simple [...] */
277 popint();
278 zzmore();
279 }
280 else zzmore();
281 >>
282 #token "consumeUntil\( [\ \t]* \{~[\}]+\} [\ \t]* \)"
283 <<
284 zzmore();
285 zzreplstr(inline_set(zzbegexpr+
286 strlen("consumeUntil(")));
287 >>
288 #token "consumeUntil\( ~[\)]+ \)"
289 << zzmore(); >>
290 #token "\n|\r|\r\n" << zzline++; zzmore(); DAWDLE; >>
291 #token "\>" << zzmore(); >>
292 #token "$" << zzmore(); >>
293 #token "$$" << if ( !GenCC ) {zzreplstr("zzaRet"); zzmore();}
294 else err("$$ use invalid in C++ mode"); >>
295
296 #token "$\[\]" << if ( !GenCC ) {zzreplstr("zzempty_attr"); zzmore();}
297 else err("$[] use invalid in C++ mode"); >>
298 #token "$\[" <<
299 pushint(']');
300 if ( !GenCC ) zzreplstr("zzconstr_attr(");
301 else err("$[..] use invalid in C++ mode");
302 zzmore();
303 >>
304 #token "$[0-9]+" <<{
305 static char buf[100];
306 numericActionLabel=1; /* MR10 */
307 if ( strlen(zzbegexpr)>(size_t)85 )
308 fatal("$i attrib ref too big");
309 set_orel(atoi(zzbegexpr+1), &attribsRefdFromAction);
310 if ( !GenCC ) sprintf(buf,"zzaArg(zztasp%d,%s)",
311 BlkLevel-1,zzbegexpr+1);
312 else sprintf(buf,"_t%d%s",
313 BlkLevel-1,zzbegexpr+1);
314 zzreplstr(buf);
315 zzmore();
316 UsedOldStyleAttrib = 1;
317 if ( UsedNewStyleLabel )
318 err("cannot mix old-style $i with new-style labels");
319 }
320 >>
321 #token "$[0-9]+." <<{
322 static char buf[100];
323 numericActionLabel=1; /* MR10 */
324 if ( strlen(zzbegexpr)>(size_t)85 )
325 fatal("$i.field attrib ref too big");
326 zzbegexpr[strlen(zzbegexpr)-1] = ' ';
327 set_orel(atoi(zzbegexpr+1), &attribsRefdFromAction);
328 if ( !GenCC ) sprintf(buf,"zzaArg(zztasp%d,%s).",
329 BlkLevel-1,zzbegexpr+1);
330 else sprintf(buf,"_t%d%s.",
331 BlkLevel-1,zzbegexpr+1);
332 zzreplstr(buf);
333 zzmore();
334 UsedOldStyleAttrib = 1;
335 if ( UsedNewStyleLabel )
336 err("cannot mix old-style $i with new-style labels");
337 }
338 >>
339 #token "$[0-9]+.[0-9]+" <<{
340 static char buf[100];
341 static char i[20], j[20];
342 char *p,*q;
343 numericActionLabel=1; /* MR10 */
344 if (strlen(zzbegexpr)>(size_t)85) fatal("$i.j attrib ref too big");
345 for (p=zzbegexpr+1,q= &i[0]; *p!='.'; p++) {
346 if ( q == &i[20] )
347 fatalFL("i of $i.j attrib ref too big",
348 FileStr[CurFile], zzline );
349 *q++ = *p;
350 }
351 *q = '\0';
352 for (p++, q= &j[0]; *p!='\0'; p++) {
353 if ( q == &j[20] )
354 fatalFL("j of $i.j attrib ref too big",
355 FileStr[CurFile], zzline );
356 *q++ = *p;
357 }
358 *q = '\0';
359 if ( !GenCC ) sprintf(buf,"zzaArg(zztasp%s,%s)",i,j);
360 else sprintf(buf,"_t%s%s",i,j);
361 zzreplstr(buf);
362 zzmore();
363 UsedOldStyleAttrib = 1;
364 if ( UsedNewStyleLabel )
365 err("cannot mix old-style $i with new-style labels");
366 }
367 >>
368 #token "$[_a-zA-Z][_a-zA-Z0-9]*"
369 <<{ static char buf[300]; LabelEntry *el;
370 zzbegexpr[0] = ' ';
371 if ( CurRule != NULL &&
372 strcmp(CurRule, &zzbegexpr[1])==0 ) {
373 if ( !GenCC ) zzreplstr("zzaRet");
374 }
375 else if ( CurRetDef != NULL &&
376 strmember(CurRetDef, &zzbegexpr[1])) {
377 if ( hasMultipleOperands( CurRetDef ) ) {
378 require (strlen(zzbegexpr)<=(size_t)285,
379 "$retval attrib ref too big");
380 sprintf(buf,"_retv.%s",&zzbegexpr[1]);
381 zzreplstr(buf);
382 }
383 else zzreplstr("_retv");
384 }
385 else if ( CurParmDef != NULL &&
386 strmember(CurParmDef, &zzbegexpr[1])) {
387 ;
388 }
389 else if ( Elabel==NULL ) {
390 { err("$-variables in actions outside of rules are not allowed"); }
391 } else if ( (el=(LabelEntry *)hash_get(Elabel, &zzbegexpr[1]))!=NULL ) {
392 /* MR10 */
393 /* MR10 */ /* element labels might exist without an elem when */
394 /* MR10 */ /* it is a forward reference (to a rule) */
395 /* MR10 */
396 /* MR10 */ if ( GenCC && (el->elem == NULL || el->elem->ntype==nRuleRef) )
397 /* MR10 */ { err(eMsg1("There are no token ptrs for rule references: '$%s'",&zzbegexpr[1])); }
398 /* MR10 */
399 /* MR10 */ if ( !GenCC && (el->elem == NULL || el->elem->ntype==nRuleRef) && GenAST) {
400 /* MR10 */ err("You can no longer use attributes returned by rules when also using ASTs");
401 /* MR10 */ err(" Use upward inheritance (\"rule >[Attrib a] : ... <<$a=...\>\>\")");
402 /* MR10 */ };
403 /* MR10 */
404 /* MR10 */ /* keep track of <<... $label ...>> for semantic predicates in guess mode */
405 /* MR10 */ /* element labels contain pointer to the owners node */
406 /* MR10 */
407 /* MR10 */ if (el->elem != NULL && el->elem->ntype == nToken) {
408 /* MR10 */ list_add(&CurActionLabels,el);
409 /* MR10 */ };
410 }
411 else
412 warn(eMsg1("$%s not parameter, return value, (defined) element label",&zzbegexpr[1]));
413 }
414 zzmore();
415 >>
416 #token "#0" << zzreplstr("(*_root)"); zzmore(); chkGTFlag(); >>
417 #token "#\[\]" << if ( GenCC ) {
418 if (NewAST) zzreplstr("(newAST)");
419 else zzreplstr("(new AST)");}
420 else {zzreplstr("zzastnew()");} zzmore();
421 chkGTFlag();
422 >>
423 #token "#\(\)" << zzreplstr("NULL"); zzmore(); chkGTFlag(); >>
424 #token "#[0-9]+" <<{
425 static char buf[100];
426 if ( strlen(zzbegexpr)>(size_t)85 )
427 fatal("#i AST ref too big");
428 if ( GenCC ) sprintf(buf,"_ast%d%s",BlkLevel-1,zzbegexpr+1);
429 else sprintf(buf,"zzastArg(%s)",zzbegexpr+1);
430 zzreplstr(buf);
431 zzmore();
432 set_orel(atoi(zzbegexpr+1), &AST_nodes_refd_in_actions);
433 chkGTFlag();
434 }
435 >>
436
437 /* MR14 Arpad Beszedes 26-May-98
438 Add support for #line directives when antlr source is pre-processed
439 #lexclass ACTIONS
440 */
441
442 #token "#line[\ \t]* [0-9]+ {[\ \t]* \"~[\"]+\" ([\ \t]* [0-9]*)* } (\n|\r|\r\n)"
443 <<
444 zzline = atoi(zzbegexpr+5) - 1; zzline++; zzmore();
445 getFileNameFromTheLineInfo(FileStr[CurFile], zzbegexpr);
446 >>
447
448 #token "#line ~[\n\r]* (\n|\r|\r\n)"
449 <<
450 zzline++; zzmore();
451 >>
452
453 /* MR14 end of a block to support #line in antlr source code */
454
455 #token "#[_a-zA-Z][_a-zA-Z0-9]*"
456 <<
457 if ( !(strcmp(zzbegexpr, "#ifdef")==0 ||
458 strcmp(zzbegexpr, "#if")==0 ||
459 strcmp(zzbegexpr, "#else")==0 ||
460 strcmp(zzbegexpr, "#endif")==0 ||
461 strcmp(zzbegexpr, "#ifndef")==0 ||
462 strcmp(zzbegexpr, "#define")==0 ||
463 strcmp(zzbegexpr, "#pragma")==0 ||
464 strcmp(zzbegexpr, "#undef")==0 ||
465 strcmp(zzbegexpr, "#import")==0 ||
466 strcmp(zzbegexpr, "#line")==0 ||
467 strcmp(zzbegexpr, "#include")==0 ||
468 strcmp(zzbegexpr, "#error")==0) )
469 {
470 static char buf[100];
471 sprintf(buf, "%s_ast", zzbegexpr+1);
472 /* MR27 */ list_add(&CurAstLabelsInActions, mystrdup(zzbegexpr+1));
473 zzreplstr(buf);
474 chkGTFlag();
475 }
476 zzmore();
477 >>
478 #token "#\[" <<
479 pushint(']');
480 if ( GenCC ) {
481 if (NewAST) zzreplstr("(newAST(");
482 else zzreplstr("(new AST("); }
483 else zzreplstr("zzmk_ast(zzastnew(),");
484 zzmore();
485 chkGTFlag();
486 >>
487 #token "#\(" <<
488 pushint('}');
489 if ( GenCC ) {
490 if (tmakeInParser) {
491 zzreplstr("tmake(");
492 }
493 else {
494 zzreplstr("ASTBase::tmake(");
495 }
496 }
497 else {
498 zzreplstr("zztmake(");
499 }
500 zzmore();
501 chkGTFlag();
502 >>
503 #token "#" << zzmore(); >>
504 #token "\)" <<
505 if ( istackempty() )
506 zzmore();
507 else if ( topint()==')' ) {
508 popint();
509 }
510 else if ( topint()=='}' ) {
511 popint();
512 /* terminate #(..) */
513 zzreplstr(", NULL)");
514 }
515 zzmore();
516 >>
517 #token "\[" <<
518 pushint('|'); /* look for '|' to terminate simple [...] */
519 zzmore();
520 >>
521 #token "\(" <<
522 pushint(')');
523 zzmore();
524 >>
525
526 #token "\\\]" << zzreplstr("]"); zzmore(); >>
527 #token "\\\)" << zzreplstr(")"); zzmore(); >>
528
529 /* MR1 10-Apr-97 MR1 Previously unable to put right shift operator */
530 /* MR1 in DLG action */
531
532 #token "\\>" << if (! tokenActionActive) zzreplstr(">"); /* MR1 */
533 zzmore(); /* MR1 */
534 >> /* MR1 */
535
536
537 #token "'" << zzmode(ACTION_CHARS); zzmore();>>
538 #token "\"" << zzmode(ACTION_STRINGS); zzmore();>>
539 #token "\\$" << zzreplstr("$"); zzmore(); >>
540 #token "\\#" << zzreplstr("#"); zzmore(); >>
541 #token "\\(\n|\r|\r\n)" << zzline++; zzmore(); >>
542 #token "\\~[\]\)>$#]" << zzmore(); >> /* escaped char, always ignore */
543 #token "/" << zzmore(); >>
544 #token "/\*" << zzmode(ACTION_COMMENTS); zzmore(); >>
545 #token "\*/" << warn("Missing /*; found dangling */ in action"); zzmore(); >>
546 #token "//" << zzmode(ACTION_CPP_COMMENTS); zzmore(); >>
547 #token "~[\n\r\)\(\\$#\>\]\[\"'/]+" << zzmore(); >>
548
549 #lexclass START
550 #token "[\t\ ]+" << zzskip(); >> /* Ignore White */
551 #token "\n|\r|\r\n" << zzline++; zzskip(); >> /* Track Line # */
552 #token "\[" << zzmode(ACTIONS); zzmore();
553 istackreset();
554 pushint(']'); >>
555 #token "\<\<" << action_file=CurFile; action_line=zzline;
556 zzmode(ACTIONS); zzmore();
557 list_free(&CurActionLabels,0); /* MR10 */
558 numericActionLabel=0; /* MR10 */
559 istackreset();
560 pushint('>'); >>
561 #token "\"" << zzmode(STRINGS); zzmore(); >>
562 #token "/\*" << zzmode(COMMENTS); zzskip(); >>
563 #token "\*/" << warn("Missing /*; found dangling */"); zzskip(); >>
564 #token "//" << zzmode(CPP_COMMENTS); zzskip(); >>
565
566 /* MR14 Arpad Beszedes 26-May-98
567 Add support for #line directives when antlr source is pre-processed
568 #lexclass START
569 */
570
571 #token "#line[\ \t]* [0-9]+ {[\ \t]* \"~[\"]+\" ([\ \t]* [0-9]*)* } (\n|\r|\r\n)"
572 <<
573 zzline = atoi(zzbegexpr+5) - 1; zzline++; zzmore();
574 getFileNameFromTheLineInfo(FileStr[CurFile], zzbegexpr);
575 >>
576
577 #token "#line ~[\n\r]* (\n|\r|\r\n)"
578 <<
579 zzline++; zzmore();
580 >>
581
582 /* MR14 end of a block to support #line in antlr source code */
583
584 /* */
585 /* 8-Apr-97 Regularize escape sequence for ">>" */
586 /* appearing in string literals */
587 /* */
588
589 #token "\>\>" << warn("Missing <<; found dangling \>\>"); zzskip(); >> /* MR1 */
590 #token WildCard "."
591 #token "\@" <<FoundException = 1; /* MR6 */
592 FoundAtOperator = 1;>> /* MR6 */
593 #token Eof "@"
594 << /* L o o k F o r A n o t h e r F i l e */
595 {
596 FILE *new_input;
597 new_input = NextFile();
598 if ( new_input == NULL ) { NLA=Eof; return; }
599 fclose( input );
600 input = new_input;
601 zzrdstream( input );
602 zzskip(); /* Skip the Eof (@) char i.e continue */
603 }
604 >>
605
606 #token LABEL
607
608 #errclass "grammar-element" { element }
609 #errclass "meta-symbol" { "\}" "!" ";" "\|" "\~" "^" "\)" }
610
611 #token Pragma "{\\}#pragma" /* MR21 */
612 #token FirstSetSymbol "{\\}#FirstSetSymbol" /* MR21 */
613 /*
614 * Get a grammar -- Build a list of rules like:
615 *
616 * o-->Rule1--o
617 * |
618 * o-->Rule2--o
619 * |
620 * ...
621 * |
622 * o-->RuleN--o
623 */
624
625 /* rule grammar */
626
627 grammar : <<Graph g;>>
628 ( "{\\}#header" Action /* MR13 */
629 <<
630 if ( HdrAction==NULL ) {
631 HdrAction = (char *) calloc(strlen(LATEXT(1))+1, sizeof(char));
632 require(HdrAction!=NULL, "rule grammar: cannot allocate header action");
633 strcpy(HdrAction, LATEXT(1));
634 }
635 else warn("additional #header statement ignored");
636 >>
637 | "{\\}#first" Action
638 <<
639 if ( FirstAction==NULL ) {
640 FirstAction = (char *) calloc(strlen(LATEXT(1))+1, sizeof(char));
641 require(FirstAction!=NULL, "rule grammar: cannot allocate #first action");
642 strcpy(FirstAction, LATEXT(1));
643 } else {
644 warn("additional #first statement ignored");
645 };
646 >>
647
648 | "{\\}#parser" QuotedTerm
649 <<
650 if ( GenCC ) {
651 warn("#parser meta-op incompatible with -CC; ignored");
652 }
653 else {
654 if ( strcmp(ParserName,"zzparser")==0 ) {
655 ParserName=StripQuotes(mystrdup(LATEXT(1)));
656 if ( RulePrefix[0]!='\0' )
657 {
658 warn("#parser meta-op incompatible with '-gp prefix'; '-gp' ignored");
659 RulePrefix[0]='\0';
660 }
661 }
662 else warn("additional #parser statement ignored");
663 }
664 >>
665 | "{\\}#tokdefs" QuotedTerm
666 <<{
667 char *fname;
668 zzantlr_state st; FILE *f; struct zzdlg_state dst;
669 UserTokenDefsFile = mystrdup(LATEXT(1));
670 zzsave_antlr_state(&st);
671 zzsave_dlg_state(&dst);
672 fname = mystrdup(LATEXT(1));
673 f = fopen(StripQuotes(fname), "r");
674 if ( f==NULL ) {warn(eMsg1("cannot open token defs file '%s'", fname+1));}
675 else {
676 ANTLRm(enum_file(fname+1), f, PARSE_ENUM_FILE);
677 UserDefdTokens = 1;
678 }
679 zzrestore_antlr_state(&st);
680 zzrestore_dlg_state(&dst);
681 }>>
682 )*
683 ( Action
684 <<{
685 UserAction *ua = newUserAction(LATEXT(1));
686 ua->file = action_file; ua->line = action_line;
687 if ( class_nest_level>0 ) list_add(&class_before_actions, ua);
688 else list_add(&BeforeActions, ua);
689 }>>
690 | laction
691 | lmember /* MR1 */
692 | lprefix /* MR1 */
693 | aLexclass
694 | token
695 | error
696 | tclass
697 | aPred /* MR11 */
698 | default_exception_handler
699 | class_def
700 | "\}"
701 <<
702 if ( class_nest_level==0 )
703 warn("missing class definition for trailing '}'");
704 class_nest_level--;
705 >>
706 )*
707
708 rule <<g=$3; SynDiag = (Junction *) $3.left;>>
709 ( rule
710
711 <<if ( $1.left!=NULL ) {
712 g.right = NULL;
713
714 /* MR21a */ /* Avoid use of a malformed graph when CannotContinue */
715 /* MR21a */ /* is already set */
716 /* MR21a */
717 /* MR21a */ if (! (CannotContinue && g.left == NULL)) {
718 /* MR21a */ g = Or(g, $1);
719 /* MR21a */ }
720 /* MR21a */ }
721 >>
722
723 | aLexclass
724 | token
725 | error
726 | tclass
727 | aPred /* MR11 */
728 | class_def
729 | "\}"
730 <<
731 if ( class_nest_level==0 )
732 warn("missing class definition for trailing '}'");
733 class_nest_level--;
734 >>
735 )*
736 ( Action
737 <<{
738 UserAction *ua = newUserAction(LATEXT(1));
739 ua->file = action_file; ua->line = action_line;
740 if ( class_nest_level>0 ) list_add(&class_after_actions, ua);
741 else list_add(&AfterActions, ua);
742 }>>
743 | laction
744 | lmember /* MR1 */
745 | lprefix /* MR1 */
746 | error
747 | tclass
748 | class_def
749 | aPred /* MR11 */
750 | "\}"
751 <<
752 if ( class_nest_level==0 )
753 warn("missing class definition for trailing '}'");
754 class_nest_level--;
755 >>
756 )*
757 Eof
758 ;
759 <<CannotContinue=TRUE;>>
760
761 /* rule class_def */
762
763 class_def
764 : <<int go=1; char name[MaxRuleName+1];>>
765 "class"
766 ( NonTerminal <<if(go) strncpy(name,LATEXT(1),MaxRuleName);>>
767 | TokenTerm <<if(go) strncpy(name,LATEXT(1),MaxRuleName);>>
768 )
769 <<
770 if ( CurrentClassName[0]!='\0' && strcmp(CurrentClassName,name)!=0
771 && GenCC ) {
772 err("only one grammar class allowed in this release");
773 go = 0;
774 }
775 else strcpy(CurrentClassName, name);
776 >>
777 <<if ( !GenCC ) { err("class meta-op used without C++ option"); }>>
778
779 /* MR10 */ (~ "\{"
780 /* MR10 */ <<if (ClassDeclStuff == NULL) {
781 /* MR10 */ ClassDeclStuff=(char *)calloc(MaxClassDeclStuff+1,sizeof(char));
782 /* MR10 */ };
783 /* MR10 */ strncat(ClassDeclStuff," ",MaxClassDeclStuff);
784 /* MR10 */ strncat(ClassDeclStuff,LATEXT(1),MaxClassDeclStuff);
785 /* MR22 */ do {
786 /* MR22 */ if (0 == strcmp(LATEXT(1),"public")) break;
787 /* MR22 */ if (0 == strcmp(LATEXT(1),"private")) break;
788 /* MR22 */ if (0 == strcmp(LATEXT(1),"protected")) break;
789 /* MR22 */ if (0 == strcmp(LATEXT(1),"virtual")) break;
790 /* MR22 */ if (0 == strcmp(LATEXT(1),",")) break;
791 /* MR22 */ if (0 == strcmp(LATEXT(1),":")) break;
792 /* MR22 */ if (BaseClassName != NULL) break;
793 /* MR22 */ BaseClassName=(char *)calloc(strlen(LATEXT(1))+1,sizeof(char));
794 /* MR22 */ require(BaseClassName!=NULL, "rule grammar: cannot allocate base class name");
795 /* MR22 */ strcpy(BaseClassName,LATEXT(1));
796 /* MR22 */ } while (0);
797 /* MR10 */ >>
798 /* MR10 */ )*
799
800 "\{"
801 <<
802 no_classes_found = 0;
803 if ( class_nest_level>=1 ) {warn("cannot have nested classes");}
804 else class_nest_level++;
805 >>
806 ;
807 <<CannotContinue=TRUE;>>
808
809 /*
810 * Build -o-->o-R-o-->o- where -o-R-o- is the block from rule 'block'.
811 * Construct the RuleBlk front and EndRule node on the end of the
812 * block. This is used to add FOLLOW pointers to the rule end. Add the
813 * new rule name to the Rname hash table and sets its rulenum.
814 * Store the parameter definitions if any are found.
815 *
816 * Note that locks are required on the RuleBlk and EndRule nodes to thwart
817 * infinite recursion.
818 *
819 * Return the left graph pointer == NULL to indicate error/dupl rule def.
820 */
821
822 /* rule rule */
823
824 rule : <<
825
826 ExceptionGroup *eg;
827 RuleEntry *q; Junction *p; Graph r; int f, l; ECnode *e;
828 set toksrefd, rulesrefd;
829 char *pdecl=NULL, *ret=NULL, *a; CurRetDef = CurParmDef = NULL;
830 CurExGroups = NULL;
831 CurElementLabels = NULL;
832 CurAstLabelsInActions = NULL; /* MR27 */
833 /* We want a new element label hash table for each rule */
834 if ( Elabel!=NULL ) killHashTable(Elabel);
835 Elabel = newHashTable();
836 attribsRefdFromAction = empty;
837 >>
838 NonTerminal
839 <<q=NULL;
840 if ( hash_get(Rname, LATEXT(1))!=NULL ) {
841 err(eMsg1("duplicate rule definition: '%s'",LATEXT(1)));
842 CannotContinue=TRUE;
843 }
844 else
845 {
846 q = (RuleEntry *)hash_add(Rname,
847 LATEXT(1),
848 (Entry *)newRuleEntry(LATEXT(1)));
849 CurRule = q->str;
850 }
851 CurRuleNode = q;
852 f = CurFile; l = zzline;
853 NumRules++;
854 >>
855 { "!" <<if ( q!=NULL ) q->noAST = TRUE;>> }
856 { <<;>>
857 {"\<"}
858 PassAction
859 << pdecl = (char *) calloc(strlen(LATEXT(1))+1, sizeof(char));
860 require(pdecl!=NULL, "rule rule: cannot allocate param decl");
861 strcpy(pdecl, LATEXT(1));
862 CurParmDef = pdecl;
863 >>
864 }
865 { "\>"
866 PassAction
867 << ret = (char *) calloc(strlen(LATEXT(1))+1, sizeof(char));
868 require(ret!=NULL, "rule rule: cannot allocate ret type");
869 strcpy(ret, LATEXT(1));
870 CurRetDef = ret;
871 >>
872 }
873 { QuotedTerm <<if ( q!=NULL ) q->egroup=mystrdup(LATEXT(1));>> }
874 <<
875 if ( GenEClasseForRules && q!=NULL ) {
876 e = newECnode;
877 require(e!=NULL, "cannot allocate error class node");
878 if ( q->egroup == NULL ) {a = q->str; a[0] = (char)toupper(a[0]);}
879 else a = q->egroup;
880 if ( Tnum( a ) == 0 )
881 {
882 e->tok = addTname( a );
883 list_add(&eclasses, (char *)e);
884 if ( q->egroup == NULL ) a[0] = (char)tolower(a[0]);
885 /* refers to itself */
886 list_add(&(e->elist), mystrdup(q->str));
887 }
888 else {
889 warn(eMsg1("default errclass for '%s' would conflict with token/errclass/tokclass",a));
890 if ( q->egroup == NULL ) a[0] = (char)tolower(a[0]);
891 free((char *)e);
892 }
893 }
894 >>
895 <<BlkLevel++;
896 if (BlkLevel >= MAX_BLK_LEVEL) fatal("Blocks nested too deeply");
897 /* MR23 */ CurBlockID_array[BlkLevel] = CurBlockID;
898 /* MR23 */ CurAltNum_array[BlkLevel] = CurAltNum;
899 >>
900
901 ":" <<inAlt=1;>>
902 block[&toksrefd, &rulesrefd]
903 <<r = makeBlk($7,0, NULL /* pFirstSetSymbol */ );
904 CurRuleBlk = (Junction *)r.left;
905 CurRuleBlk->blockid = CurBlockID;
906 CurRuleBlk->jtype = RuleBlk;
907 if ( q!=NULL ) CurRuleBlk->rname = q->str;
908 CurRuleBlk->file = f;
909 CurRuleBlk->line = l;
910 CurRuleBlk->pdecl = pdecl;
911 CurRuleBlk->ret = ret;
912 CurRuleBlk->lock = makelocks();
913 CurRuleBlk->pred_lock = makelocks();
914 CurRuleBlk->tokrefs = toksrefd;
915 CurRuleBlk->rulerefs = rulesrefd;
916 p = newJunction(); /* add EndRule Node */
917 ((Junction *)r.right)->p1 = (Node *)p;
918 r.right = (Node *) p;
919 p->jtype = EndRule;
920 p->lock = makelocks();
921 p->pred_lock = makelocks();
922 CurRuleBlk->end = p;
923 if ( q!=NULL ) q->rulenum = NumRules;
924 $7 = r;
925 >>
926 <<
927 /* MR23 */ CurBlockID_array[BlkLevel] = (-1);
928 /* MR23 */ CurAltNum_array[BlkLevel] = (-1);
929 --BlkLevel;
930 >>
931 <<altFixup();leFixup();egFixup();>> /* MR7 */
932 ";" <<inAlt=0;>>
933 { Action
934 << a = (char *) calloc(strlen(LATEXT(1))+1, sizeof(char));
935 require(a!=NULL, "rule rule: cannot allocate error action");
936 strcpy(a, LATEXT(1));
937 CurRuleBlk->erraction = a;
938 >>
939 }
940 ( exception_group > [eg]
941 <<if ( eg!=NULL ) {
942 list_add(&CurExGroups, (void *)eg);
943 if (eg->label == NULL || *eg->label=='\0' ) q->has_rule_exception = 1;
944 }
945 >>
946 )*
947 <<if ( q==NULL ) $0.left = NULL; else $0 = $7;>>
948 <<CurRuleBlk->exceptions = CurExGroups;>>
949 <<CurRuleBlk->el_labels = CurElementLabels;>>
950 <<CurRuleNode->ast_labels_in_actions = CurAstLabelsInActions;>> /* MR27 */
951 <<CurRuleNode = NULL;>> /* MR27 Moved */
952 ;
953 <<CannotContinue=TRUE;>>
954
955 /*
956 * pragma : "{\\}#pragma" "dup\-labeled\-tokens"
957 * <<Pragma_DupLabeledTokens=1;>>
958 * ;
959 */
960
961 /* rule laction */
962
963 laction : <<char *a;>>
964
965 "{\\}#lexaction"
966 Action
967 <<
968 a = (char *) calloc(strlen(LATEXT(1))+1, sizeof(char));
969 require(a!=NULL, "rule laction: cannot allocate action");
970 strcpy(a, LATEXT(1));
971 list_add(&LexActions, a);
972 >>
973 ;
974 <<CannotContinue=TRUE;>>
975
976 /* MR1 */
977 /* MR1 11-Apr-97 Provide mechanism for inserting code into DLG class */
978 /* MR1 via #lexmember <<....>> & #lexprefix <<...>> */
979 /* MR1 */
980
981 /* rule lmember */
982
983 lmember: <<char *a;>> /* MR1 */
984
985 /* MR1 */ "{\\}#lexmember"
986 /* MR1 */ Action
987 /* MR1 */ <<
988 /* MR1 */ if (! GenCC) {
989 /* MR1 */ err("Use #lexmember only in C++ mode (to insert code in DLG class header");
990 /* MR1 */ } else {
991 /* MR1 */ a = (char *) calloc(strlen(LATEXT(1))+1, sizeof(char));
992 /* MR1 */ require(a!=NULL, "rule lmember: cannot allocate action");
993 /* MR1 */ strcpy(a, LATEXT(1));
994 /* MR1 */ list_add(&LexMemberActions, a);
995 /* MR1 */ };
996 /* MR1 */ >>
997 /* MR1 */ ;
998 /* MR1 */ <<CannotContinue=TRUE;>>
999
1000 /* rule lprefix */
1001
1002 lprefix: <<char *a;>> /* MR1 */
1003
1004 /* MR1 */ "{\\}#lexprefix"
1005 /* MR1 */ Action
1006 /* MR1 */ <<
1007 /* MR1 */ if (! GenCC) {
1008 /* MR1 */ err("Use #lexprefix only in C++ mode (to insert code in DLG class header");
1009 /* MR1 */ } else {
1010 /* MR1 */ a = (char *) calloc(strlen(LATEXT(1))+1, sizeof(char));
1011 /* MR1 */ require(a!=NULL, "rule lprefix: cannot allocate action");
1012 /* MR1 */ strcpy(a, LATEXT(1));
1013 /* MR1 */ list_add(&LexPrefixActions, a);
1014 /* MR1 */ };
1015 /* MR1 */ >>
1016 /* MR1 */ ;
1017 /* MR1 */ <<CannotContinue=TRUE;>>
1018
1019 /*
1020 * #pred upper <<isupper()>>? predicate literal
1021 * #pred lower <<islower()>>? predicate literal
1022 * #pred up_or_low upper || lower predicate expression
1023 * concealed interdependence
1024 * #pred up_or_low_2 <<isletter()>>? A || B predicate literal equals predicate expr
1025 * analyze using lower||upper
1026 * generate using isLetter()
1027 */
1028
1029 /* rule aPref */
1030
1031 aPred: <<PredEntry *predEntry=NULL;
1032 char *name=NULL;
1033 Predicate *predExpr=NULL;
1034 char *predLiteral=NULL;
1035 int save_file;
1036 int save_line;
1037 int predExprPresent=0;
1038 >>
1039
1040 "{\\}#pred"
1041
1042 <<
1043 MR_usingPredNames=1; /* will need to use -mrhoist version of genPredTree */
1044 >>
1045
1046 /* used to allow NonTerminal but it caused problems
1047 when a rule name immediately followed a #pred statement */
1048
1049 TokenTerm <<name=mystrdup(LATEXT(1));>>
1050
1051 <<
1052 /* don't free - referenced in predicates */
1053
1054 CurPredName=(char *)calloc(1,strlen(name) + 10);
1055 strcat(CurPredName,"#pred ");
1056 strcat(CurPredName,name);
1057
1058 predEntry=(PredEntry *) hash_get(Pname,name);
1059 if (predEntry != NULL) {
1060 warnFL(eMsg1("#pred %s previously defined - ignored",name),
1061 FileStr[action_file],action_line);
1062 name=NULL;
1063 };
1064 >>
1065
1066 (
1067
1068 Pred <<predLiteral=mystrdup(LATEXT(1));
1069 save_line=action_line;
1070 save_file=action_file;
1071 >>
1072
1073 {
1074 predOrExpr>[predExpr] <<predExprPresent=1;>>
1075 }
1076
1077 <<if (predLiteral != NULL && name != NULL) {
1078
1079 /*
1080 * predExpr may be NULL due to syntax errors
1081 * or simply omitted by the user
1082 */
1083
1084 predEntry=newPredEntry(name);
1085 predEntry->file=save_file;
1086 predEntry->line=save_line;
1087 predExpr=MR_predFlatten(predExpr);
1088 predEntry->predLiteral=predLiteral;
1089 if (! predExprPresent || predExpr == NULL) {
1090 predExpr=new_pred();
1091 predExpr->expr=predLiteral;
1092 predExpr->source=newActionNode();
1093 predExpr->source->action=predExpr->expr;
1094 predExpr->source->rname=CurPredName;
1095 predExpr->source->line=action_line;
1096 predExpr->source->file=action_file;
1097 predExpr->source->is_predicate=1;
1098 predExpr->k=predicateLookaheadDepth(predExpr->source);
1099 };
1100 predEntry->pred=predExpr;
1101 hash_add(Pname,name,(Entry *)predEntry);
1102 predExpr=NULL;
1103 };
1104 predicate_free(predExpr);
1105 >>
1106
1107 |
1108 <<save_line=zzline; save_file=CurFile;>>
1109
1110 predOrExpr>[predExpr]
1111
1112 <<if (predExpr != NULL && name != NULL) {
1113 predEntry=newPredEntry(name);
1114 predEntry->file=CurFile;
1115 predEntry->line=zzline;
1116 predExpr=MR_predFlatten(predExpr);
1117 predEntry->pred=predExpr;
1118 hash_add(Pname,name,(Entry *)predEntry);
1119 predExpr=NULL;
1120 };
1121 predicate_free(predExpr);
1122 >>
1123 )
1124 {";"}
1125 ;
1126
1127 /* fail */
1128
1129 <<predicate_free(predExpr);
1130 >>
1131
1132 /* rule predOrExpr */
1133
1134 predOrExpr>[Predicate *result] :
1135 <<Predicate *ORnode;
1136 Predicate *predExpr;
1137 Predicate **tail=NULL;
1138 >>
1139 predAndExpr>[predExpr]
1140 <<
1141 ORnode=new_pred();
1142 ORnode->expr=PRED_OR_LIST;
1143 if (predExpr != NULL) {
1144 ORnode->down=predExpr;
1145 tail=&predExpr->right;
1146 };
1147 >>
1148 ( "\|\|" predAndExpr>[predExpr]
1149 <<
1150 if (predExpr != NULL) {
1151 *tail=predExpr;
1152 tail=&predExpr->right;
1153 };
1154 >>
1155 )*
1156 <<
1157 $result=ORnode;
1158 ORnode=NULL;
1159 >>
1160 ;
1161
1162 /* fail */
1163
1164 <<predicate_free(ORnode);>>
1165
1166 /* rule predAndExpr */
1167
1168 predAndExpr>[Predicate *result] :
1169 <<Predicate *ANDnode;
1170 Predicate *predExpr;
1171 Predicate **tail=NULL;
1172 >>
1173 predPrimary>[predExpr]
1174 <<
1175 ANDnode=new_pred();
1176 ANDnode->expr=PRED_AND_LIST;
1177 if (predExpr != NULL) {
1178 ANDnode->down=predExpr;
1179 tail=&predExpr->right;
1180 };
1181 >>
1182 ( "&&" predPrimary>[predExpr]
1183 <<
1184 if (predExpr != NULL) {
1185 *tail=predExpr;
1186 tail=&predExpr->right;
1187 };
1188 >>
1189 )*
1190 <<
1191 $result=ANDnode;
1192 ANDnode=NULL;
1193 >>
1194 ;
1195
1196 /* fail */
1197
1198 <<predicate_free(ANDnode);>>
1199
1200
1201 /* rule predPrimary */
1202
1203 predPrimary>[Predicate *result] :
1204 <<
1205 char *name=NULL;
1206 PredEntry *predEntry=NULL;
1207 Predicate *predExpr=NULL;
1208 >>
1209
1210 TokenTerm <<name=mystrdup(LATEXT(1));>>
1211
1212 <<
1213 predEntry=(PredEntry *) hash_get(Pname,name);
1214 if (predEntry == NULL) {
1215 warnFL(eMsg1("no previously defined #pred with name \"%s\"",name),
1216 FileStr[CurFile],zzline);
1217 name=NULL;
1218 $result=NULL;
1219 } else {
1220 predExpr=predicate_dup(predEntry->pred);
1221 predExpr->predEntry=predEntry;
1222 $result=predExpr;
1223 };
1224 >>
1225
1226 | "\(" predOrExpr>[predExpr] "\)"
1227 <<
1228 $result=predExpr;
1229 >>
1230
1231 | "!" predPrimary>[predExpr]
1232 <<
1233 predExpr->inverted=!predExpr->inverted;
1234 $result=predExpr;
1235 >>
1236 ;
1237
1238 /* fail */ <<
1239 predicate_free(predExpr);
1240 >>
1241
1242 /* rule aLexclass */
1243
1244 aLexclass: "{\\}#lexclass" TokenTerm <<lexclass(mystrdup(LATEXT(1)));>>
1245 ;
1246 <<CannotContinue=TRUE;>>
1247
1248 /* rule error */
1249
1250 error : <<char *t=NULL; ECnode *e; int go=1; TermEntry *p;>>
1251 "{\\}#errclass"
1252 (<<;>> TokenTerm <<t=mystrdup(LATEXT(1));>>
1253 | QuotedTerm <<t=mystrdup(LATEXT(1));>>
1254 )
1255 <<e = newECnode;
1256 require(e!=NULL, "cannot allocate error class node");
1257 e->lexclass = CurrentLexClass;
1258 if ( Tnum( (t=StripQuotes(t)) ) == 0 )
1259 {
1260 if ( hash_get(Texpr, t) != NULL )
1261 warn(eMsg1("errclass name conflicts with regular expression '%s'",t));
1262 e->tok = addTname( t );
1263 set_orel(e->tok, &imag_tokens);
1264 require((p=(TermEntry *)hash_get(Tname, t)) != NULL,
1265 "hash table mechanism is broken");
1266 p->classname = 1; /* entry is errclass name, not token */
1267 list_add(&eclasses, (char *)e);
1268 }
1269 else
1270 {
1271 warn(eMsg1("redefinition of errclass or conflict w/token or tokclass '%s'; ignored",t));
1272 free( (char *)e );
1273 go=0;
1274 }
1275 >>
1276 "\{"
1277 ( NonTerminal <<if ( go ) t=mystrdup(LATEXT(1));>>
1278 | TokenTerm <<if ( go ) t=mystrdup(LATEXT(1));>>
1279 | QuotedTerm <<if ( go ) t=mystrdup(LATEXT(1));>>
1280 )
1281 <<if ( go ) list_add(&(e->elist), t);>>
1282 (
1283 ( NonTerminal <<if ( go ) t=mystrdup(LATEXT(1));>>
1284 | TokenTerm <<if ( go ) t=mystrdup(LATEXT(1));>>
1285 | QuotedTerm <<if ( go ) t=mystrdup(LATEXT(1));>>
1286 )
1287 <<if ( go ) list_add(&(e->elist), t);>>
1288 )*
1289 "\}"
1290 ;
1291 <<CannotContinue=TRUE;>>
1292
1293 /* rule tclass */
1294
1295 tclass : <<char *t=NULL; TCnode *e; int go=1,tok,totok; TermEntry *p, *term, *toterm;>>
1296 <<char *akaString=NULL; int save_file; int save_line;>>
1297 <<char *totext=NULL; >>
1298 "{\\}#tokclass" TokenTerm <<t=mystrdup(LATEXT(1));>>
1299 <<e = newTCnode;
1300 require(e!=NULL, "cannot allocate token class node");
1301 e->lexclass = CurrentLexClass;
1302 if ( Tnum( t ) == 0 )
1303 {
1304 e->tok = addTname( t );
1305 set_orel(e->tok, &imag_tokens);
1306 set_orel(e->tok, &tokclasses);
1307 require((p=(TermEntry *)hash_get(Tname, t)) != NULL,
1308 "hash table mechanism is broken");
1309 p->classname = 1; /* entry is class name, not token */
1310 p->tclass = e; /* save ptr to this tclass def */
1311 list_add(&tclasses, (char *)e);
1312 }
1313 else
1314 {
1315 warn(eMsg1("redefinition of tokclass or conflict w/token '%s'; ignored",t));
1316 free( (char *)e );
1317 go=0;
1318 }
1319 >>
1320 /* MR23 */ {
1321 /* MR23 */ "\("
1322 /* MR23 */ QuotedTerm
1323 /* MR23 */ <<akaString=mystrdup(StripQuotes(LATEXT(1)));
1324 /* MR11 */ save_file=CurFile;save_line=zzline;
1325 /* MR23 */ >>
1326 /* MR23 */ "\)"
1327 /* MR23 */ }
1328 /* MR23 */
1329 /* MR23 */
1330 /* MR23 */ <<
1331 /* MR23 */ if (p!= NULL && akaString != NULL) {
1332 /* MR23 */ if (p->akaString != NULL) {
1333 /* MR23 */ if (strcmp(p->akaString,akaString) != 0) {
1334 /* MR23 */ warnFL(eMsg2("this #tokclass statement conflicts with a previous #tokclass %s(\"%s\") statement",
1335 /* MR23 */ t,p->akaString),
1336 /* MR23 */ FileStr[save_file],save_line);
1337 /* MR23 */ };
1338 /* MR23 */ } else {
1339 /* MR23 */ p->akaString=akaString;
1340 /* MR23 */ };
1341 /* MR23 */ };
1342 /* MR23 */ >>
1343
1344 "\{"
1345 (
1346 ( TokenTerm
1347 <<if ( go ) {
1348 term = (TermEntry *) hash_get(Tname, LATEXT(1));
1349 if ( term==NULL && UserDefdTokens ) {
1350 err("implicit token definition not allowed with #tokdefs");
1351 go = 0;
1352 }
1353 else {t=mystrdup(LATEXT(1)); tok=addTname(LATEXT(1));}
1354 }>>
1355
1356 {
1357 ".."
1358 TokenTerm
1359
1360 <<if ( go ) {
1361 toterm = (TermEntry *) hash_get(Tname, LATEXT(1));
1362 if ( toterm==NULL && UserDefdTokens ) {
1363 err("implicit token definition not allowed with #tokdefs");
1364 go = 0;
1365 } else {
1366 totext=mystrdup(LATEXT(1)); totok=addTname(LATEXT(1));
1367 }
1368 }
1369 >>
1370 }
1371
1372 | QuotedTerm
1373 <<if ( go ) {
1374 term = (TermEntry *) hash_get(Texpr, LATEXT(1));
1375 if ( term==NULL && UserDefdTokens ) {
1376 err("implicit token definition not allowed with #tokdefs");
1377 go = 0;
1378 }
1379 else {t=mystrdup(LATEXT(1)); tok=addTexpr(LATEXT(1));}
1380 }>>
1381 )
1382 <<if ( go ) {
1383 if (totext == NULL) {
1384 list_add(&(e->tlist), t);
1385 } else {
1386 list_add(&(e->tlist),"..");
1387 list_add(&(e->tlist),t);
1388 list_add(&(e->tlist),totext);
1389 }
1390 totext=NULL;
1391 }
1392 >>
1393 )+ // MR15 Manfred Kogler - forbid empty #tokclass sets (was "+")
1394 "\}"
1395 ;
1396 <<CannotContinue=TRUE;>>
1397
1398 /* rule token */
1399
1400 token : <<char *t=NULL, *e=NULL, *a=NULL; int tnum=0;>>
1401 <<char *akaString=NULL; TermEntry *te;int save_file=0,save_line=0;>> /* MR11 */
1402 "{\\}#token"
1403
1404 /* MR1 10-Apr-97 MR1 Allow shift right operator in DLG actions */
1405 /* MR1 Danger when parser feedback to lexer */
1406 /* MR1 */
1407
1408 <<tokenActionActive=1;>> /* MR1 */
1409 { TokenTerm <<t=mystrdup(LATEXT(1));>>
1410
1411 /* MR11 */ {
1412 /* MR11 */ "\("
1413 /* MR11 */ QuotedTerm
1414 /* MR11 */ <<akaString=mystrdup(StripQuotes(LATEXT(1)));
1415 /* MR11 */ save_file=CurFile;save_line=zzline;
1416 /* MR11 */ >>
1417 /* MR11 */ "\)"
1418 /* MR11 */ }
1419
1420 { "=" "[0-9]+" /* define the token type number */
1421 <<tnum = atoi(LATEXT(1));>>
1422 }
1423 }
1424 { QuotedTerm <<e=mystrdup(LATEXT(1));>> }
1425 { Action
1426 <<
1427 a = (char *) calloc(strlen(LATEXT(1))+1, sizeof(char));
1428 require(a!=NULL, "rule token: cannot allocate action");
1429 strcpy(a, LATEXT(1));
1430 >>
1431 }
1432
1433 { ";" } /* MR11 */
1434
1435 <<chkToken(t, e, a, tnum);>>
1436
1437 <<if (t != NULL) {
1438 te=(TermEntry *)hash_get(Tname,t);
1439 if (te != NULL && akaString != NULL) {
1440 if (te->akaString != NULL) {
1441 if (strcmp(te->akaString,akaString) != 0) {
1442 warnFL(eMsg2("this #token statement conflicts with a previous #token %s(\"%s\") statement",
1443 t,te->akaString),
1444 FileStr[save_file],save_line);
1445 };
1446 } else {
1447 te->akaString=akaString;
1448 };
1449 };
1450 };
1451 >>
1452 ;
1453 <<CannotContinue=TRUE;>>
1454
1455 /* rule block */
1456
1457 block[set *toksrefd, set *rulesrefd]
1458 : <<
1459 Graph g, b;
1460 set saveblah;
1461 int saveinalt = inAlt;
1462 ExceptionGroup *eg;
1463 *$toksrefd = empty;
1464 *$rulesrefd = empty;
1465 set_clr(AST_nodes_refd_in_actions);
1466 CurBlockID++;
1467 /* MR23 */ CurBlockID_array[BlkLevel] = CurBlockID;
1468 CurAltNum = 1;
1469 /* MR23 */ CurAltNum_array[BlkLevel] = CurAltNum;
1470 saveblah = attribsRefdFromAction;
1471 attribsRefdFromAction = empty;
1472 >>
1473
1474 alt[toksrefd,rulesrefd] <<b = g = $1;>>
1475
1476 <<
1477 if ( ((Junction *)g.left)->p1->ntype == nAction )
1478 {
1479 ActionNode *actionNode=(ActionNode *)
1480 ( ( (Junction *)g.left) ->p1);
1481 if (!actionNode->is_predicate )
1482 {
1483 actionNode->init_action = TRUE;
1484 /* MR12c */ if (actionNode->noHoist) {
1485 /* MR12c */ errFL("<<nohoist>> appears as init-action - use <<>> <<nohoist>>",
1486 /* MR12c */ FileStr[actionNode->file],actionNode->line);
1487 /* MR12c */ };
1488 }
1489 }
1490 ((Junction *)g.left)->blockid = CurBlockID;
1491 >>
1492
1493 ( exception_group > [eg]
1494 <<
1495 if ( eg!=NULL ) {
1496 /* MR7 ***** eg->altID = makeAltID(CurBlockID,CurAltNum); *****/
1497 /* MR7 ***** CurAltStart->exception_label = eg->altID; *****/
1498 list_add(&CurExGroups, (void *)eg);
1499 }
1500 >>
1501 )*
1502 <<CurAltNum++;
1503 /* MR23 */ CurAltNum_array[BlkLevel] = CurAltNum;
1504 >>
1505
1506 ( "\|" <<inAlt=1;>>
1507 alt[toksrefd,rulesrefd] <<g = Or(g, $2);>>
1508 <<
1509 ((Junction *)g.left)->blockid = CurBlockID;
1510 >>
1511
1512 ( exception_group > [eg]
1513 <<
1514 if ( eg!=NULL ) {
1515 /* MR7 ***** eg->altID = makeAltID(CurBlockID,CurAltNum); *****/
1516 /* MR7 ***** CurAltStart->exception_label = eg->altID; *****/
1517 list_add(&CurExGroups, (void *)eg);
1518 }
1519 >>
1520 )*
1521
1522 <<CurAltNum++;
1523 /* MR23 */ CurAltNum_array[BlkLevel] = CurAltNum;
1524 >>
1525
1526 )*
1527 <<$0 = b;>>
1528 <<attribsRefdFromAction = saveblah; inAlt = saveinalt;>>
1529 ;
1530 <<CannotContinue=TRUE;>>
1531
1532 /* rule alt */
1533
1534 alt[set *toksrefd, set *rulesrefd]
1535 : <<int n=0; Graph g; int e_num=0, old_not=0; Node *node; set elems, dif;
1536 int first_on_line = 1, use_def_MT_handler = 0;
1537 g.left=NULL; g.right=NULL;
1538
1539 CurAltStart = NULL;
1540 elems = empty;
1541 inAlt = 1;
1542 >>
1543 { "\@" /* handle MismatchedToken signals with default handler */
1544 <<use_def_MT_handler = 1;>>
1545 }
1546
1547 ( <<;>> /* MR9 Removed unreferenced variable "tok" */
1548 { <<old_not=0;>> "\~" <<old_not=1;>> }
1549 element[old_not, first_on_line, use_def_MT_handler] > [node]
1550 <<if ( node!=NULL && node->ntype!=nAction ) first_on_line = 0;>>
1551 <<
1552 if ( $2.left!=NULL ) {
1553 g = Cat(g, $2);
1554 n++;
1555 if ( node!=NULL ) {
1556 if ( node->ntype!=nAction ) e_num++;
1557 /* record record number of all rule and token refs */
1558 if ( node->ntype==nToken ) {
1559 TokNode *tk = (TokNode *)((Junction *)$2.left)->p1;
1560 tk->elnum = e_num;
1561 set_orel(e_num, &elems);
1562 }
1563 else if ( node->ntype==nRuleRef ) {
1564 RuleRefNode *rn = (RuleRefNode *)((Junction *)$2.left)->p1;
1565 rn->elnum = e_num;
1566 set_orel(e_num, $rulesrefd);
1567 }
1568 }
1569 }
1570 >>
1571 )*
1572 <<if ( n == 0 ) g = emptyAlt();
1573 $0 = g;
1574 /* We want to reduce number of LT(i) calls and the number of
1575 * local attribute variables in C++ mode (for moment, later we'll
1576 * do for C also). However, if trees are being built, they
1577 * require most of the attrib variables to create the tree nodes
1578 * with; therefore, we gen a token ptr for each token ref in C++
1579 */
1580 if ( GenCC && !GenAST )
1581 {
1582 /* This now free's the temp set -ATG 5/6/95 */
1583 set temp;
1584 temp = set_and(elems, attribsRefdFromAction);
1585 set_orin($toksrefd, temp);
1586 set_free(temp);
1587 }
1588 else set_orin($toksrefd, elems);
1589 if ( GenCC ) {
1590 dif = set_dif(attribsRefdFromAction, elems);
1591 if ( set_deg(dif)>0 )
1592 err("one or more $i in action(s) refer to non-token elements");
1593 set_free(dif);
1594 }
1595 set_free(elems);
1596 set_free(attribsRefdFromAction);
1597 inAlt = 0;
1598 >>
1599 ;
1600 <<CannotContinue=TRUE;>>
1601
1602 /* rule element_label */
1603
1604 element_label > [LabelEntry *label]
1605 : <<TermEntry *t=NULL; LabelEntry *l=NULL; RuleEntry *r=NULL; char *lab;>>
1606 LABEL <<lab = mystrdup(LATEXT(1));>>
1607 <<
1608 UsedNewStyleLabel = 1;
1609 if ( UsedOldStyleAttrib ) err("cannot mix with new-style labels with old-style $i");
1610 t = (TermEntry *) hash_get(Tname, lab);
1611 if ( t==NULL ) t = (TermEntry *) hash_get(Texpr, lab);
1612 if ( t==NULL ) r = (RuleEntry *) hash_get(Rname, lab);
1613 if ( t!=NULL ) {
1614 err(eMsg1("label definition clashes with token/tokclass definition: '%s'", lab));
1615 $label = NULL;
1616 }
1617 else if ( r!=NULL ) {
1618 err(eMsg1("label definition clashes with rule definition: '%s'", lab));
1619 $label = NULL;
1620 }
1621 else {
1622 /* we don't clash with anybody else */
1623 l = (LabelEntry *) hash_get(Elabel, lab);
1624 if ( l==NULL ) { /* ok to add new element label */
1625 l = (LabelEntry *)hash_add(Elabel,
1626 lab,
1627 (Entry *)newLabelEntry(lab));
1628 /* add to list of element labels for this rule */
1629 list_add(&CurElementLabels, (void *)lab);
1630 /* MR7 */ leAdd(l); /* list of labels waiting for exception group definitions */
1631 $label = l;
1632 }
1633 else {
1634 err(eMsg1("label definitions must be unique per rule: '%s'", lab));
1635 $label = NULL;
1636 }
1637 }
1638 >>
1639 ":"
1640 ;
1641
1642 /* rule element */
1643
1644 element[int old_not, int first_on_line, int use_def_MT_handler] > [Node *node]
1645 : <<
1646 Attrib blk;
1647 Predicate *pred = NULL;
1648 int local_use_def_MT_handler=0;
1649 ActionNode *act;
1650 RuleRefNode *rr;
1651 set toksrefd, rulesrefd;
1652 TermEntry *term;
1653 TokNode *p=NULL; RuleRefNode *q; int approx=0;
1654 LabelEntry *label=NULL;
1655 int predMsgDone=0;
1656 int semDepth=0;
1657 int ampersandStyle;
1658 int height; /* MR11 */
1659 int equal_height; /* MR11 */
1660
1661 char* pFirstSetSymbol = NULL; /* MR21 */
1662
1663 $node = NULL;
1664 >>
1665 {element_label>[label]}
1666 ( TokenTerm
1667 <<
1668 term = (TermEntry *) hash_get(Tname, LATEXT(1));
1669 if ( term==NULL && UserDefdTokens ) {
1670 err("implicit token definition not allowed with #tokdefs");
1671 $$.left = $$.right = NULL;
1672 }
1673 else {
1674 $$ = buildToken(LATEXT(1));
1675 p=((TokNode *)((Junction *)$$.left)->p1);
1676 term = (TermEntry *) hash_get(Tname, LATEXT(1));
1677 require( term!= NULL, "hash table mechanism is broken");
1678 p->tclass = term->tclass;
1679 p->complement = $old_not;
1680 if ( label!=NULL ) {
1681 p->el_label = label->str;
1682 label->elem = (Node *)p;
1683 }
1684 }
1685 >>
1686 { ".."
1687 ( QuotedTerm
1688 <<if ( p!=NULL ) setUpperRange(p, LATEXT(1));>>
1689 | TokenTerm
1690 <<if ( p!=NULL ) setUpperRange(p, LATEXT(1));>>
1691 )
1692 }
1693 <<
1694 if ( p!=NULL && (p->upper_range!=0 || p->tclass || $old_not) )
1695 list_add(&MetaTokenNodes, (void *)p);
1696 >>
1697 ( "^" <<if ( p!=NULL ) p->astnode=ASTroot;>>
1698 | <<if ( p!=NULL ) p->astnode=ASTchild;>>
1699 | "!" <<if ( p!=NULL ) p->astnode=ASTexclude;>>
1700 )
1701 { "\@" <<local_use_def_MT_handler = 1;>> }
1702 <<
1703 if ( p!=NULL && $first_on_line ) {
1704 CurAltStart = (Junction *)$$.left;
1705 altAdd(CurAltStart); /* MR7 */
1706 p->altstart = CurAltStart;
1707 }
1708 if ( p!=NULL )
1709 p->use_def_MT_handler = $use_def_MT_handler || local_use_def_MT_handler;
1710 $node = (Node *)p;
1711 >>
1712 | QuotedTerm
1713 <<
1714 term = (TermEntry *) hash_get(Texpr, LATEXT(1));
1715 if ( term==NULL && UserDefdTokens ) {
1716 err("implicit token definition not allowed with #tokdefs");
1717 $$.left = $$.right = NULL;
1718 }
1719 else {
1720 $$ = buildToken(LATEXT(1)); p=((TokNode *)((Junction *)$$.left)->p1);
1721 p->complement = $old_not;
1722 if ( label!=NULL ) {
1723 p->el_label = label->str;
1724 label->elem = (Node *)p;
1725 }
1726 }
1727 >>
1728 { ".."
1729 ( QuotedTerm
1730 <<if ( p!=NULL ) setUpperRange(p, LATEXT(1));>>
1731 | TokenTerm
1732 <<if ( p!=NULL ) setUpperRange(p, LATEXT(1));>>
1733 )
1734 }
1735 ( "^" <<if ( p!=NULL ) p->astnode=ASTroot;>>
1736 | <<if ( p!=NULL ) p->astnode=ASTchild;>>
1737 | "!" <<if ( p!=NULL ) p->astnode=ASTexclude;>>
1738 )
1739 { "\@" <<local_use_def_MT_handler = 1;>> }
1740 <<
1741 if ( p!=NULL && (p->upper_range!=0 || p->tclass || $old_not) )
1742 list_add(&MetaTokenNodes, (void *)p);
1743 >>
1744 <<
1745 if ( $first_on_line ) {
1746 CurAltStart = (Junction *)$$.left;
1747 altAdd(CurAltStart); /* MR7 */
1748 p->altstart = CurAltStart;
1749 }
1750 if ( p!=NULL )
1751 p->use_def_MT_handler = $use_def_MT_handler || local_use_def_MT_handler;
1752 $node = (Node *)p;
1753 >>
1754
1755 | <<if ( $old_not ) warn("~ WILDCARD is an undefined operation (implies 'nothing')");>>
1756 "."
1757 <<$$ = buildWildCard(LATEXT(1)); p=((TokNode *)((Junction *)$$.left)->p1);>>
1758 ( "^" <<p->astnode=ASTroot;>>
1759 | <<p->astnode=ASTchild;>>
1760 | "!" <<p->astnode=ASTexclude;>>
1761 )
1762 <<list_add(&MetaTokenNodes, (void *)p);>>
1763 <<
1764 if ( $first_on_line ) {
1765 CurAltStart = (Junction *)$$.left;
1766 altAdd(CurAltStart); /* MR7 */
1767 p->altstart = CurAltStart;
1768 if ( label!=NULL ) {
1769 p->el_label = label->str;
1770 label->elem = (Node *)p;
1771 }
1772 }
1773 $node = (Node *)p;
1774 >>
1775
1776 | <<if ( $old_not ) warn("~ NONTERMINAL is an undefined operation");>>
1777 NonTerminal
1778 <<$$ = buildRuleRef(LATEXT(1));>>
1779 { "!" <<q = (RuleRefNode *) ((Junction *)$$.left)->p1;
1780 q->astnode=ASTexclude;>>
1781 }
1782 { {"\<"}
1783 PassAction <<addParm(((Junction *)$$.left)->p1, LATEXT(1));>>
1784 }
1785 <<rr=(RuleRefNode *) ((Junction *)$$.left)->p1;>>
1786 { <<char *a;>>
1787 "\>"
1788 PassAction
1789 <<
1790 a = (char *) calloc(strlen(LATEXT(1))+1, sizeof(char));
1791 require(a!=NULL, "rule element: cannot allocate assignment");
1792 strcpy(a, LATEXT(1));
1793 rr->assign = a;
1794 >>
1795 }
1796 <<
1797 if ( label!=NULL ) {
1798 rr->el_label = label->str;
1799 label->elem = (Node *)rr;
1800 }
1801 if ( $first_on_line ) {
1802 CurAltStart = (Junction *)$$.left;
1803 altAdd(CurAltStart); /* MR7 */
1804 ((RuleRefNode *)((Junction *)$$.left)->p1)->altstart = CurAltStart;
1805 }
1806 $node = (Node *)rr;
1807 >>
1808 )
1809
1810 | <<if ( $old_not ) warn("~ ACTION is an undefined operation");>>
1811 Action <<$0 = buildAction(LATEXT(1),action_file,action_line, 0);>>
1812 <<if ( $first_on_line ) { /* MR7 */
1813 CurAltStart = (Junction *)$0.left; /* MR7 */
1814 altAdd(CurAltStart); /* MR7 */
1815 };>> /* MR7 */
1816 <<$node = (Node *) ((Junction *)$0.left)->p1;>>
1817
1818 | <<if ( $old_not ) warn("~ SEMANTIC-PREDICATE is an undefined operation");>>
1819 Pred <<$0 = buildAction(LATEXT(1),action_file,action_line, 1);>>
1820 <<act = (ActionNode *) ((Junction *)$0.left)->p1;>>
1821 <<if (numericActionLabel) { /* MR10 */
1822 list_add(&NumericPredLabels,act); /* MR10 */
1823 numericActionLabel=0; /* MR10 */
1824 }; /* MR10 */
1825 >>
1826 { <<char *a;>>
1827 PassAction
1828 <<
1829 a = (char *) calloc(strlen(LATEXT(1))+1, sizeof(char));
1830 require(a!=NULL, "rule element: cannot allocate predicate fail action");
1831 strcpy(a, LATEXT(1));
1832 act->pred_fail = a;
1833 >>
1834 }
1835 <<if ( $first_on_line ) { /* MR7 */
1836 CurAltStart = (Junction *)$0.left; /* MR7 */
1837 altAdd(CurAltStart); /* MR7 */
1838 };>> /* MR7 */
1839 <<$node = (Node *)act;>>
1840
1841 | <<if ( $old_not ) warn("~ BLOCK is an undefined operation");>>
1842 <<BlkLevel++;
1843 if (BlkLevel >= MAX_BLK_LEVEL) fatal("Blocks nested too deeply");
1844 /* MR23 */ CurBlockID_array[BlkLevel] = CurBlockID;
1845 /* MR23 */ CurAltNum_array[BlkLevel] = CurAltNum;
1846 >>
1847 { Pragma
1848 ( "approx" <<approx=LL_k;>>
1849 | "LL\(1\)" <<approx = 1;>> /* MR20 */
1850 | "LL\(2\)" <<approx = 2;>> /* MR20 */
1851 )
1852 }
1853
1854 /* MR21 */ { FirstSetSymbol
1855 /* MR21 */ "\("
1856 /* MR21 */ ( NonTerminal
1857 /* MR21 */ <<
1858 /* MR21 */ pFirstSetSymbol = (char *) calloc(strlen(LATEXT(1))+1,
1859 /* MR21 */ sizeof(char));
1860 /* MR21 */ require(pFirstSetSymbol!=NULL,
1861 /* MR21 */ "cannot allocate first set name");
1862 /* MR21 */ strcpy(pFirstSetSymbol, LATEXT(1));
1863 /* MR21 */ >>
1864 /* MR21 */ | TokenTerm
1865 /* MR21 */ <<
1866 /* MR21 */ pFirstSetSymbol = (char *) calloc(strlen(LATEXT(1))+1,
1867 /* MR21 */ sizeof(char));
1868 /* MR21 */ require(pFirstSetSymbol!=NULL,
1869 /* MR21 */ "cannot allocate first set name");
1870 /* MR21 */ strcpy(pFirstSetSymbol, LATEXT(1));
1871 /* MR21 */ >>
1872 /* MR21 */ )
1873 /* MR21 */ "\)"
1874 /* MR21 */ }
1875
1876 (
1877
1878 "\(" block[&toksrefd,&rulesrefd] "\)"
1879 <<blk = $$ = $2;
1880 /* MR23 */ CurBlockID_array[BlkLevel] = (-1);
1881 /* MR23 */ CurAltNum_array[BlkLevel] = (-1);
1882 --BlkLevel;
1883 >>
1884
1885 ( "\*" <<$$ = makeLoop($$,approx,pFirstSetSymbol);>>
1886 | "\+" <<$$ = makePlus($$,approx,pFirstSetSymbol);>>
1887 | "?"
1888 (
1889 ( "=>" <<ampersandStyle=0;>>
1890 | "&&" <<ampersandStyle=1;>> /* MR10 (g)? && <<p>>? */
1891 )
1892 Pred /* generalized predicate */
1893 /* first make into a predicate */
1894 <<$$ = buildAction(LATEXT(1),action_file,action_line,1);>>
1895 <<act = (ActionNode *) ((Junction *)$$.left)->p1;>>
1896 <<semDepth=predicateLookaheadDepth(act);>> /* MR10 */
1897 <<if (numericActionLabel) { /* MR10 */
1898 list_add(&NumericPredLabels,act); /* MR10 */
1899 numericActionLabel=0; /* MR10 */
1900 }; /* MR10 */
1901 >>
1902 { <<char *a;>>
1903 PassAction
1904 <<
1905 a = (char *)calloc(strlen(LATEXT(1))+1, sizeof(char));
1906 require(a!=NULL, "rule element: cannot allocate predicate fail action");
1907 strcpy(a, LATEXT(1));
1908 act->pred_fail = a;
1909 >>
1910 }
1911 <<if ($first_on_line) { /* MR7 */
1912 CurAltStart=(Junction *)$$.left; /* MR7 */
1913 altAdd(CurAltStart); /* MR7 */
1914 };>>
1915 <<$node = (Node *)act;>>
1916
1917 /* for now, just snag context */
1918 <<
1919 pred = computePredFromContextGuard(blk,&predMsgDone); /* MR10 */
1920 if ( pred==NULL) { /* MR10 */
1921 if ( !predMsgDone) err("invalid or missing context guard"); /* MR10 */
1922 predMsgDone=1; /* MR10 */
1923 } else { /* MR10 */
1924 act->guardNodes=(Junction *)blk.left; /* MR11 */
1925 pred->expr = act->action;
1926 pred->source = act;
1927 /* MR10 */ pred->ampersandStyle = ampersandStyle; /* 0 means (g)? => ... 1 means (g)? && ... */
1928 /* MR13 */ if (pred->tcontext != NULL) {
1929 /* MR13 */ height=MR_max_height_of_tree(pred->tcontext);
1930 /* MR13 */ equal_height=MR_all_leaves_same_height(pred->tcontext,height);
1931 /* MR13 */ if (! equal_height) {
1932 /* MR13 */ errFL("in guarded predicates all tokens in the guard must be at the same height",
1933 /* MR13 */ FileStr[act->file],act->line);
1934 /* MR13 */ };
1935 /* MR13 */ }
1936 /* MR10 */ if (ampersandStyle) {
1937 /* MR10 */ act->ampersandPred = pred;
1938 /* MR11 */ if (! HoistPredicateContext) {
1939 /* MR11 */ errFL("without \"-prc on\" (guard)? && <<pred>>? ... doesn't make sense",
1940 /* MR11 */ FileStr[act->file],act->line);
1941 /* MR11 */ };
1942 /* MR10 */ } else {
1943 /* MR10 */ act->guardpred = pred;
1944 /* MR10 */ };
1945 /* MR10 */ if (pred->k != semDepth) {
1946 /* MR10 */ warn(eMsgd2("length of guard (%d) does not match the length of semantic predicate (%d)",
1947 /* MR10 */ pred->k,semDepth));
1948 /* MR10 */ };
1949 }
1950 >>
1951 | <<$$ = makeBlk($$,approx,pFirstSetSymbol);
1952 FoundGuessBlk = 1;
1953 ((Junction *) ((Junction *)$$.left)->p1)->guess=1;
1954 if ( !$first_on_line ) {
1955 err("(...)? predicate must be first element of production");
1956 }
1957 >>
1958 )
1959 | <<$$ = makeBlk($$,approx,pFirstSetSymbol);>>
1960 )
1961 <<
1962 if ( pred==NULL && !predMsgDone) { /* MR10 */
1963 ((Junction *)((Junction *)$$.left)->p1)->blockid = CurBlockID;
1964 ((Junction *)((Junction *)$$.left)->p1)->tokrefs = toksrefd;
1965 ((Junction *)((Junction *)$$.left)->p1)->rulerefs = rulesrefd;
1966 if ( $first_on_line ) { /* MR7 */
1967 CurAltStart = (Junction *)((Junction *)((Junction *)$$.left)->p1); /* MR7 */
1968 altAdd(CurAltStart); /* MR7 */
1969 }; /* MR7 */
1970 $node = (Node *) ((Junction *)$$.left)->p1;
1971 }
1972 >>
1973
1974 | "\{" block[&toksrefd,&rulesrefd]
1975 <<$$ = makeOpt($2,approx,pFirstSetSymbol);
1976 /* MR23 */ CurBlockID_array[BlkLevel] = (-1);
1977 /* MR23 */ CurAltNum_array[BlkLevel] = (-1);
1978 --BlkLevel;
1979 >>
1980 "\}"
1981 <<
1982 ((Junction *)((Junction *)$$.left)->p1)->blockid = CurBlockID;
1983 ((Junction *)((Junction *)$$.left)->p1)->tokrefs = toksrefd;
1984 ((Junction *)((Junction *)$$.left)->p1)->rulerefs = rulesrefd;
1985 >>
1986 <<if ( $first_on_line ) { /* MR7 */
1987 CurAltStart = (Junction *) ((Junction *)((Junction *)$$.left)->p1); /* MR7 */
1988 altAdd(CurAltStart); /* MR7 */
1989 };
1990 >>
1991 <<$node = (Node *) ((Junction *)$$.left)->p1;>>
1992
1993 )
1994
1995 /* Error catching alternatives */
1996 | "\*" <<warn("don't you want a ')' with that '*'?"); CannotContinue=TRUE;>>
1997 | "\+" <<warn("don't you want a ')' with that '+'?"); CannotContinue=TRUE;>>
1998 | "\>" <<warn("'>' can only appear after a nonterminal"); CannotContinue=TRUE;>>
1999 | PassAction <<warn("[...] out of context 'rule > [...]'");
2000 CannotContinue=TRUE;>>
2001 ;
2002 <<CannotContinue=TRUE;>>
2003
2004 /* rule default_exception_handler */
2005
2006 default_exception_handler
2007 : exception_group > [DefaultExGroup]
2008 ;
2009
2010 /* rule exception_group */
2011
2012 exception_group > [ExceptionGroup *eg]
2013 : <<ExceptionHandler *h; LabelEntry *label=NULL; /* MR6 */
2014 FoundException = 1; FoundExceptionGroup = 1;>> /* MR6 */
2015
2016 "exception" <<$eg = (ExceptionGroup *)calloc(1, sizeof(ExceptionGroup));>>
2017 { <<char *p;>>
2018 PassAction /* did they attach a label? */
2019 <<
2020 p = LATEXT(1)+1;
2021 p[strlen(p)-1] = '\0'; /* kill trailing space */
2022 label = (LabelEntry *) hash_get(Elabel, LATEXT(1)+1);
2023 if ( label==NULL )
2024 {
2025 err(eMsg1("unknown label in exception handler: '%s'", LATEXT(1)+1));
2026 }
2027 >>
2028 }
2029 ( exception_handler > [h]
2030 <<list_add(&($eg->handlers), (void *)h);>>
2031 )*
2032 { "default" ":" Action
2033 <<{
2034 ExceptionHandler *eh = (ExceptionHandler *)
2035 calloc(1, sizeof(ExceptionHandler));
2036 char *a = (char *) calloc(strlen(LATEXT(1))+1, sizeof(char));
2037 require(eh!=NULL, "exception: cannot allocate handler");
2038 require(a!=NULL, "exception: cannot allocate action");
2039 strcpy(a, LATEXT(1));
2040 eh->action = a;
2041 eh->signalname = (char *) calloc(strlen("default")+1, sizeof(char));
2042 require(eh->signalname!=NULL, "exception: cannot allocate sig name");
2043 strcpy(eh->signalname, "default");
2044 list_add(&($eg->handlers), (void *)eh);
2045 }>>
2046 }
2047
2048 <<
2049 if ( label!=NULL ) {
2050 /* Record ex group in sym tab for this label */
2051 if ( label->ex_group!=NULL ) {
2052 err(eMsg1("duplicate exception handler for label '%s'",label->str));
2053 } else {
2054 label->ex_group = $eg;
2055 /* Label the exception group itself */
2056 $eg->label = label->str;
2057 /* Make the labelled element pt to the exception also */
2058 /* MR6 */ if (label->elem == NULL) {
2059 /* MR6 */ err(eMsg1("reference in exception handler to undefined label '%s'",label->str));
2060 /* MR6 */ } else {
2061 switch ( label->elem->ntype ) {
2062 case nRuleRef :
2063 {
2064 RuleRefNode *r = (RuleRefNode *)label->elem;
2065 r->ex_group = $eg;
2066 break;
2067 }
2068 case nToken :
2069 {
2070 TokNode *t = (TokNode *)label->elem;
2071 t->ex_group = $eg;
2072 break;
2073 }
2074 } /* end switch */
2075 /* MR6 */ }; /* end test on label->elem */
2076 } /* end test on label->ex_group */
2077
2078 } /* end test on exception label */
2079
2080 /* MR7 */
2081 /* MR7 */ if (BlkLevel == 1 && label == NULL) {
2082 /* MR7 */ $eg->forRule=1;
2083 /* MR7 */ } else if (label == NULL) {
2084 /* MR7 */ $eg->altID = makeAltID(CurBlockID_array[BlkLevel], CurAltNum_array[BlkLevel]);
2085 /* MR7 */ egAdd($eg);
2086 /* MR7 */ } else {
2087 /* MR7 */ $eg->labelEntry=label;
2088 /* MR7 */ };
2089 /* MR7 */
2090 /* MR7 */ /* You may want to remove this exc from the rule list */
2091 /* MR7 */ /* and handle at the labeled element site. */
2092 /* MR7 */
2093 /* MR7 */ if (label != NULL) {
2094 /* MR7 */ $eg = NULL;
2095 /* MR7 */ };
2096
2097 >>
2098 ;
2099 <<CannotContinue=TRUE;>>
2100
2101 /* rule exception_handler */
2102
2103 exception_handler > [ExceptionHandler *eh]
2104 : <<;>> /* MR9 Removed unreferenced variable "a" */
2105 "catch"
2106 <<
2107 $eh = (ExceptionHandler *)calloc(1, sizeof(ExceptionHandler));
2108 require($eh!=NULL, "exception: cannot allocate handler");
2109 >>
2110 ( NonTerminal
2111 <<
2112 $eh->signalname = (char *) calloc(strlen(LATEXT(1))+1, sizeof(char));
2113 require($eh->signalname!=NULL, "exception: cannot allocate sig name");
2114 strcpy($eh->signalname, LATEXT(1));
2115 >>
2116 | TokenTerm
2117 <<
2118 $eh->signalname = (char *) calloc(strlen(LATEXT(1))+1, sizeof(char));
2119 require($eh->signalname!=NULL, "exception: cannot allocate sig name");
2120 strcpy($eh->signalname, LATEXT(1));
2121 >>
2122 )
2123 ":"
2124 { <<$eh->action = NULL;>>
2125 Action
2126 <<
2127 $eh->action = (char *) calloc(strlen(LATEXT(1))+1, sizeof(char));
2128 require($eh->action!=NULL, "exception: cannot allocate action");
2129 strcpy($eh->action, LATEXT(1));
2130 >>
2131 }
2132 ;
2133 <<CannotContinue=TRUE;>>
2134
2135 #token NonTerminal "[a-z] [A-Za-z0-9_]*"
2136 <<
2137 while ( zzchar==' ' || zzchar=='\t' ) {
2138 zzadvance();
2139 }
2140 if ( zzchar == ':' && inAlt ) NLA = LABEL;
2141 >>
2142 #token TokenTerm "[A-Z] [A-Za-z0-9_]*"
2143 <<
2144 while ( zzchar==' ' || zzchar=='\t' ) {
2145 zzadvance();
2146 }
2147 if ( zzchar == ':' && inAlt ) NLA = LABEL;
2148 >>
2149 #token "{\\}#[A-Za-z0-9_]*" <<warn(eMsg1("unknown meta-op: %s",LATEXT(1))); zzskip(); >>
2150
2151 #lexclass PARSE_ENUM_FILE
2152
2153 #token "[\t\ ]+" << zzskip(); >> /* Ignore White */
2154 #token "\n|\r|\r\n" << zzline++; zzskip(); >> /* Track Line # */
2155 #token "//" << zzmode(TOK_DEF_CPP_COMMENTS); zzmore(); >>
2156 #token "/\*" << zzmode(TOK_DEF_COMMENTS); zzskip(); >>
2157 #token "#ifdef" << zzmode(TOK_DEF_CPP_COMMENTS); zzskip(); >>
2158 #token "#if" << zzmode(TOK_DEF_CPP_COMMENTS); zzskip(); >>
2159 #token "#ifndef" << ; >>
2160 #token "#else" << zzmode(TOK_DEF_CPP_COMMENTS); zzskip(); >>
2161 #token "#endif" << zzmode(TOK_DEF_CPP_COMMENTS); zzskip(); >>
2162 #token "#undef" << zzmode(TOK_DEF_CPP_COMMENTS); zzskip(); >>
2163 #token "#import" << zzmode(TOK_DEF_CPP_COMMENTS); zzskip(); >>
2164 #token "@" << ; >>
2165
2166 /* rule enum_file */
2167
2168 enum_file[char *fname]
2169 : { "#ifndef" ID
2170 { "#define" ID /* ignore if it smells like a gate */
2171 /* First #define after the first #ifndef (if any) is ignored */
2172 }
2173 }
2174 ( ( enum_def[$fname] )+
2175 | defines[$fname]
2176 )
2177 |
2178 ;
2179
2180 /* rule defines */
2181
2182 defines[char *fname]
2183 : <<int v; int maxt=(-1); char *t;>> /* MR3 */
2184 (
2185 "#define" ID
2186 <<t = mystrdup(LATEXT(1));>>
2187 INT
2188 <<
2189 v = atoi(LATEXT(1));
2190 /* fprintf(stderr, "#token %s=%d\n", t, v);*/
2191
2192 /* MR2 Andreas Magnusson (Andreas.Magnusson@mailbox.swipnet.se) */
2193 /* MR2 Fix to bug introduced by 1.33MR1 for #tokdefs */
2194 /* MR2 Don't let #tokdefs be confused by */
2195 /* MR2 DLGminToken and DLGmaxToken */
2196
2197 if ( ! isDLGmaxToken(t)) { /* MR2 */
2198 TokenNum = v;
2199 if ( v>maxt ) maxt=v;
2200 if ( Tnum( t ) == 0 ) {
2201 addForcedTname( t, v );
2202 } else {
2203 warnFL(eMsg1("redefinition of token %s; ignored",t),$fname,zzline);
2204 };
2205 };
2206 >>
2207 )+
2208 <<TokenNum = maxt + 1;>>
2209 ;
2210
2211 /* rule enum_def */
2212
2213 enum_def[char *fname]
2214 : <<int v= 0; int maxt=(-1); char *t;>> /* MR3 */
2215 "enum" ID
2216 "\{"
2217 ID
2218 <<t = mystrdup(LATEXT(1));>>
2219 ( "=" INT <<v=atoi(LATEXT(1));>>
2220 | <<v++;>>
2221 )
2222 <<
2223 /* fprintf(stderr, "#token %s=%d\n", t, v);*/
2224 TokenNum = v;
2225 if ( v>maxt ) maxt=v; /* MR3 */
2226 if ( Tnum( t ) == 0 ) addForcedTname( t, v );
2227 else {
2228 warnFL(eMsg1("redefinition of token %s; ignored",t),$fname,zzline);
2229 }
2230 >>
2231 ( ","
2232
2233 /* MR2 Andreas Magnusson (Andreas.Magnusson@mailbox.swipnet.se) */
2234 /* MR2 Fix to bug introduced by 1.33MR1 for #tokdefs */
2235 /* MR2 Don't let #tokdefs be confused by */
2236 /* MR2 DLGminToken and DLGmaxToken */
2237
2238 {
2239 <<isDLGmaxToken(LATEXT(1))>>? ID { "=" INT } /* MR2 */
2240 | ID /* MR2 */
2241 <<t = mystrdup(LATEXT(1));>>
2242 ( "=" INT <<v=atoi(LATEXT(1));>>
2243 | <<v++;>>
2244 )
2245 <<
2246 /* fprintf(stderr, "#token %s=%d\n", t, v);*/
2247 TokenNum = v;
2248 if ( v>maxt ) maxt=v; /* MR3 */
2249 if ( Tnum( t ) == 0 ) addForcedTname( t, v );
2250 else {
2251 warnFL(eMsg1("redefinition of token %s; ignored",t),$fname,zzline);
2252 }
2253 >>
2254 }
2255 )*
2256 "\}"
2257 ";"
2258 <<TokenNum = maxt + 1;>> /* MR3 */
2259 ;
2260
2261 #token INT "[0-9]+"
2262 #token ID "[a-zA-Z_][_a-zA-Z0-9]*"
2263
2264 #lexclass START
2265
2266 /* MR14 Arpad Beszedes 26-May-98
2267 Add support for #line directives when antlr source is pre-processed
2268 */
2269
2270 #lexaction
2271 <<
2272
2273 static char *
2274 #ifdef __USE_PROTOS
2275 getFileNameFromTheLineInfo(char *toStr, char *fromStr)
2276 #else
2277 getFileNameFromTheLineInfo(toStr, fromStr)
2278 char *toStr, *fromStr;
2279 #endif
2280 {
2281 int i, j, k;
2282
2283 if (!fromStr || !toStr) return toStr;
2284
2285 /* find the first " */
2286
2287 for (i=0;
2288 (i<MaxFileName) &&
2289 (fromStr[i] != '\n') &&
2290 (fromStr[i] != '\r') &&
2291 (fromStr[i] != '\"');
2292 i++) /* nothing */ ;
2293
2294 if ( (i == MaxFileName) ||
2295 (fromStr[i] == '\n') ||
2296 (fromStr[i] == '\r') ) {
2297 return toStr;
2298 }
2299
2300 /* find the second " */
2301
2302 for (j=i+1;
2303 (j<MaxFileName) &&
2304 (fromStr[j] != '\n') &&
2305 (fromStr[j] != '\r') &&
2306 (fromStr[j] != '\"');
2307 j++) /* nothing */ ;
2308
2309 if ((j == MaxFileName) ||
2310 (fromStr[j] == '\n') ||
2311 (fromStr[j] == '\r') ) {
2312 return toStr;
2313 }
2314
2315 /* go back until the last / or \ */
2316
2317 for (k=j-1;
2318 (fromStr[k] != '\"') &&
2319 (fromStr[k] != '/') &&
2320 (fromStr[k] != '\\');
2321 k--) /* nothing */ ;
2322
2323 /* copy the string after " / or \ into toStr */
2324
2325 for (i=k+1; fromStr[i] != '\"'; i++) {
2326 toStr[i-k-1] = fromStr[i];
2327 }
2328
2329 toStr[i-k-1] = '\0';
2330
2331 return toStr;
2332 }
2333
2334 /* MR14 end of a block to support #line in antlr source code */
2335
2336 >>
2337
2338 <<
2339
2340 /* MR2 Andreas Magnusson (Andreas.Magnusson@mailbox.swipnet.se) */
2341 /* MR2 Fix to bug introduced by 1.33MR1 for #tokdefs */
2342 /* MR2 Don't let #tokdefs be confused by */
2343 /* MR2 DLGminToken and DLGmaxToken */
2344
2345 /* semantic check on DLGminToken and DLGmaxmaxToken in #tokdefs */
2346
2347 #ifdef __USE_PROTOS
2348 static int isDLGmaxToken(char *Token)
2349 #else
2350 static int isDLGmaxToken(Token)
2351 char * Token;
2352 #endif
2353 {
2354 static char checkStr1[] = "DLGmaxToken";
2355 static char checkStr2[] = "DLGminToken";
2356
2357 if (strcmp(Token, checkStr1) == 0)
2358 return 1;
2359 else if (strcmp(Token, checkStr2) == 0)
2360 return 1;
2361 else
2362 return 0;
2363 }
2364
2365 /* semantics of #token */
2366 static void
2367 #ifdef __USE_PROTOS
2368 chkToken(char *t, char *e, char *a, int tnum)
2369 #else
2370 chkToken(t,e,a,tnum)
2371 char *t, *e, *a;
2372 int tnum;
2373 #endif
2374 {
2375 TermEntry *p;
2376
2377 /* check to see that they don't try to redefine a token as a token class */
2378 if ( t!=NULL ) {
2379 p = (TermEntry *) hash_get(Tname, t);
2380 if ( p!=NULL && p->classname ) {
2381 err(eMsg1("redefinition of #tokclass '%s' to #token not allowed; ignored",t));
2382 if ( a!=NULL ) free((char *)a);
2383 return;
2384 }
2385 }
2386
2387 if ( t==NULL && e==NULL ) { /* none found */
2388 err("#token requires at least token name or rexpr");
2389 }
2390 else if ( t!=NULL && e!=NULL ) { /* both found */
2391 if ( UserDefdTokens ) { /* if #tokdefs, must not define new */
2392 p = (TermEntry *) hash_get(Tname, t);
2393 if ( p == NULL) {
2394 err(eMsg1("new token definition '%s' not allowed - only #token with name already defined by #tokdefs file allowed",t));
2395 return;
2396 };
2397 }
2398 Tklink(t, e);
2399 if ( a!=NULL ) {
2400 if ( hasAction(e) ) {
2401 err(eMsg1("redefinition of action for %s; ignored",e));
2402 }
2403 else setHasAction(e, a);
2404 }
2405 }
2406 else if ( t!=NULL ) { /* only one found */
2407 if ( UserDefdTokens ) {
2408 p = (TermEntry *) hash_get(Tname, t);
2409 if (p == NULL) {
2410 err(eMsg1("new token definition '%s' not allowed - only #token with name already defined by #tokdefs file allowed",t));
2411 };
2412 return;
2413 }
2414 if ( Tnum( t ) == 0 ) addTname( t );
2415 else {
2416 err(eMsg1("redefinition of token %s; ignored",t));
2417 }
2418 if ( a!=NULL ) {
2419 err(eMsg1("action cannot be attached to a token name (%s); ignored",t));
2420 free((char *)a);
2421 }
2422 }
2423 else if ( e!=NULL ) {
2424 if ( Tnum( e ) == 0 ) addTexpr( e );
2425 else {
2426 if ( hasAction(e) ) {
2427 err(eMsg1("redefinition of action for expr %s; ignored",e));
2428 }
2429 else if ( a==NULL ) {
2430 err(eMsg1("redefinition of expr %s; ignored",e));
2431 }
2432 }
2433 if ( a!=NULL ) setHasAction(e, a);
2434 }
2435
2436 /* if a token type number was specified, then add the token ID and 'tnum'
2437 * pair to the ForcedTokens list. (only applies if an id was given)
2438 */
2439 if ( t!=NULL && tnum>0 )
2440 {
2441 if ( set_el(tnum, reserved_positions) )
2442 {
2443 err(eMsgd("a token has already been forced to token number %d; ignored", tnum));
2444 }
2445 else
2446 {
2447 list_add(&ForcedTokens, newForcedToken(t,tnum));
2448 set_orel(tnum, &reserved_positions);
2449 }
2450 }
2451 }
2452 >>
2453
2454 <<
2455 static int
2456 #ifdef __USE_PROTOS
2457 match_token(char *s, char **nxt)
2458 #else
2459 match_token(s,nxt)
2460 char *s;
2461 char **nxt;
2462 #endif
2463 {
2464 if ( !(*s>='A' && *s<='Z') ) return 0;
2465 s++;
2466 while ( (*s>='a' && *s<='z') ||
2467 (*s>='A' && *s<='Z') ||
2468 (*s>='0' && *s<='9') ||
2469 *s=='_' )
2470 {
2471 s++;
2472 }
2473 if ( *s!=' ' && *s!='}' ) return 0;
2474 *nxt = s;
2475 return 1;
2476 }
2477
2478 static int
2479 #ifdef __USE_PROTOS
2480 match_rexpr(char *s, char **nxt)
2481 #else
2482 match_rexpr(s,nxt)
2483 char *s;
2484 char **nxt;
2485 #endif
2486 {
2487 if ( *s!='"' ) return 0;
2488 s++;
2489 while ( *s!='"' )
2490 {
2491 if ( *s=='\n' || *s=='\r' ) /* MR13 */
2492 warn("eoln found in regular expression");
2493 if ( *s=='\\' ) s++;
2494 s++;
2495 }
2496 *nxt = s+1;
2497 return 1;
2498 }
2499
2500 /*
2501 * Walk a string "{ A .. Z }" where A..Z is a space separated list
2502 * of token references (either labels or reg exprs). Return a
2503 * string "inlineX_set" for some unique integer X. Basically,
2504 * we pretend as if we had seen "#tokclass inlineX { A .. Z }"
2505 * on the input stream outside of an action.
2506 */
2507 char *
2508 #ifdef __USE_PROTOS
2509 inline_set(char *s)
2510 #else
2511 inline_set(s)
2512 char *s;
2513 #endif
2514 {
2515 char *nxt;
2516 fprintf(stderr, "found consumeUntil( {...} )\n");
2517 while ( *s==' ' || *s=='\t' || *s=='\n' || *s=='\r' ) {s++;}
2518 if ( *s!='{' )
2519 {
2520 err("malformed consumeUntil( {...} ); missing '{'");
2521 return "bad_set";
2522 }
2523 s++;
2524 while ( *s==' ' || *s=='\t' || *s=='\n' || *s=='\r' ) {s++;}
2525 while ( *s!='}' )
2526 {
2527 if ( match_token(s,&nxt) ) fprintf(stderr, "found token %s\n", s);
2528 else if ( match_rexpr(s,&nxt) ) fprintf(stderr, "found rexpr %s\n", s);
2529 else {
2530 err("invalid element in consumeUntil( {...} )");
2531 return "bad_set";
2532 }
2533 s = nxt;
2534 while ( *s==' ' || *s=='\t' || *s=='\n' || *s=='\r' ) {s++;}
2535 }
2536 return "inlineX_set";
2537 }
2538 >>
2539
2540 <<
2541 /* ANTLR-specific syntax error message generator
2542 * (define USER_ZZSYN when compiling so don't get 2 definitions)
2543 */
2544 void
2545 #ifdef __USE_PROTOS
2546 zzsyn(char *text, int tok, char *egroup, SetWordType *eset, int etok,
2547 int k, char *bad_text)
2548 #else
2549 zzsyn(text, tok, egroup, eset, etok, k, bad_text)
2550 char *text, *egroup, *bad_text;
2551 int tok;
2552 int etok;
2553 int k;
2554 SetWordType *eset;
2555 #endif
2556 {
2557 fprintf(stderr, ErrHdr, FileStr[CurFile]!=NULL?FileStr[CurFile]:"stdin", zzline);
2558 fprintf(stderr, " syntax error at \"%s\"", (tok==zzEOF_TOKEN)?"EOF":text);
2559 if ( !etok && !eset ) {fprintf(stderr, "\n"); return;}
2560 if ( k==1 ) fprintf(stderr, " missing");
2561 else
2562 {
2563 fprintf(stderr, "; \"%s\" not", bad_text);
2564 if ( zzset_deg(eset)>1 ) fprintf(stderr, " in");
2565 }
2566 if ( zzset_deg(eset)>0 ) zzedecode(eset);
2567 else fprintf(stderr, " %s", zztokens[etok]);
2568 if ( strlen(egroup) > (size_t)0 ) fprintf(stderr, " in %s", egroup);
2569 fprintf(stderr, "\n");
2570 }
2571 >>
2572
2573 #lexaction <<
2574 #ifdef __USE_PROTOS
2575 void mark_label_used_in_sem_pred(LabelEntry *le) /* MR10 */
2576 #else
2577 void mark_label_used_in_sem_pred(le) /* MR10 */
2578 LabelEntry *le;
2579 #endif
2580 {
2581 TokNode *tn;
2582 require (le->elem->ntype == nToken,"mark_label_used... ntype != nToken");
2583 tn=(TokNode *)le->elem;
2584 require (tn->label != 0,"mark_label_used... TokNode has no label");
2585 tn->label_used_in_semantic_pred=1;
2586 }
2587 >>