Mercurial > ~dholland > hg > ag > index.cgi
comparison tests/agcl/oldagsrc/pgg24-2.syn @ 0:13d2b8934445
Import AnaGram (near-)release tree into Mercurial.
author | David A. Holland |
---|---|
date | Sat, 22 Dec 2007 17:52:45 -0500 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:13d2b8934445 |
---|---|
1 {/* | |
2 AnaGram Syntax Analyzer. | |
3 Copyright (c) Jerome T. Holland, 1989, 1990, 1991, 1992 | |
4 All Rights Reserved. | |
5 */ | |
6 | |
7 //#define INCLUDE_LOGGING | |
8 | |
9 #include "assert.h" //ASSERT | |
10 #include "config.h" | |
11 #include "csexp.h" | |
12 #include "data.h" //DATA | |
13 #include "error.h" | |
14 #include "log.hpp" | |
15 #include "myalloc.h" | |
16 #include "rproc.h" | |
17 #include "rule.h" | |
18 #include "stk.h" //STK | |
19 #include "symbol.h" | |
20 #include "token.h" | |
21 #include "tree.h" | |
22 #include "tsd.h" | |
23 #include "ut.h" //UT | |
24 #include <ctype.h> //CTYPE | |
25 #include <stdio.h> //STDIO | |
26 #include <stdlib.h> //STDLIB | |
27 #include <string.h> //STRING | |
28 | |
29 #include "pgg24.h" //PGG | |
30 | |
31 #undef MODULE | |
32 #define MODULE 3 | |
33 | |
34 } | |
35 | |
36 [ | |
37 auto resynch | |
38 context type = cint | |
39 default reductions | |
40 ~declare pcb | |
41 diagnose errors | |
42 lines and columns | |
43 error frame | |
44 line numbers | |
45 //~allow macros | |
46 nest comments | |
47 parser stack size = 128 | |
48 pointer input | |
49 ~test range | |
50 token names | |
51 parser name = pgg | |
52 test file mask = "*.syn" | |
53 //rule coverage | |
54 distinguish keywords {'.'} | |
55 parser file name = "#.cpp" | |
56 ] | |
57 | |
58 any digit = digit + hex letter | |
59 anything = ~eof | |
60 backslash = '\\' | |
61 blank char = ' ' + tab | |
62 c literal elem = ~(single quote + double quote + eol chars + backslash + eof) | |
63 digit = '0-9' | |
64 double quote = '"' | |
65 eof = 0 + 26 | |
66 eol chars = carriage return + newline | |
67 hex letter = 'a-f' + 'A-F' | |
68 letter = 'a-z' + 'A-Z' + '_' | |
69 newline = '\n' | |
70 nonoctal digit = any digit - octal digit | |
71 octal digit = '0-7' | |
72 carriage return= '\r' | |
73 simple c char = ~('{' + '}' + single quote + double quote + eof) | |
74 simple string char = ~eof - (any digit + double quote + backslash + eol chars) | |
75 single quote = '\'' | |
76 tab = '\t' | |
77 vertical space = '\f' + '\v' | |
78 | |
79 arrow | |
80 -> "->", blank?... | |
81 | |
82 comma | |
83 -> ',', space? | |
84 | |
85 ellipsis | |
86 -> "...", blank?... | |
87 | |
88 equals | |
89 -> '=', space? | |
90 | |
91 bang | |
92 -> '!', space? | |
93 | |
94 left brace | |
95 -> '{', space? | |
96 | |
97 left bracket | |
98 -> '[', space? | |
99 | |
100 left parenthesis | |
101 -> '(', space? | |
102 | |
103 minus | |
104 -> '-', space? | |
105 | |
106 plus | |
107 -> '+', space? | |
108 | |
109 right bracket | |
110 -> ']', blank?... | |
111 | |
112 right brace | |
113 -> '}', blank?... | |
114 | |
115 right parenthesis | |
116 -> ')', blank?... | |
117 | |
118 right quote | |
119 -> single quote, blank?... | |
120 | |
121 tilde | |
122 -> '~', space? | |
123 | |
124 vertical bar | |
125 -> '|', space? | |
126 | |
127 (void) syntax definition $ | |
128 -> blank?..., end of line?, statement list, statement?, eof | |
129 | |
130 statement list | |
131 -> production:t, end of line =production(t); | |
132 -> definition, end of line | |
133 -> embedded c, end of line =nPrologueSegments = 1; | |
134 -> configuration section, end of line | |
135 // -> statement list, complete statement | |
136 -> statement list, production:t, end of line =production(t); | |
137 -> statement list, simple statement, end of line | |
138 /* | |
139 (void) complete statement | |
140 -> production:t, end of line =production(t); | |
141 -> simple statement, end of line | |
142 */ | |
143 | |
144 (void) statement | |
145 -> production:t =production(t); | |
146 -> simple statement | |
147 | |
148 (int) production | |
149 -> left hand side:type =iws(),type; | |
150 -> left hand side, right hand side | |
151 -> production:type, end of line, right hand side =concat_list(),type; | |
152 -> production, end of line, additional rule spec... | |
153 | |
154 (void) right hand side | |
155 -> arrow, rule specs | |
156 | |
157 (void) simple statement | |
158 -> definition | |
159 -> embedded c | |
160 -> configuration section | |
161 | |
162 (int) left hand side | |
163 -> token name list =0; | |
164 -> type definition:d, token name list =head_list_3(d); | |
165 | |
166 (void) token name list //left hand side of productions | |
167 -> token name:x =sws(head_list_2(x)); | |
168 -> token name list, comma, token name:x =aws(head_list_2(x)); | |
169 | |
170 (int) token name | |
171 -> symbol name =0; | |
172 -> symbol name, '$', blank?... =1; | |
173 | |
174 (int) type definition | |
175 -> left parenthesis, data type, ')', space? =Cast::create(); | |
176 | |
177 (void) wrapper type | |
178 -> data type =Cast::create().requireWrapper(); | |
179 | |
180 (void) wrapper list | |
181 -> wrapper type | |
182 -> wrapper list, comma, wrapper type | |
183 | |
184 (void) proper vp rule specs | |
185 -> vp rule spec:n =sws(n); | |
186 -> proper vp rule specs, additional vp rule spec | |
187 | |
188 (void) additional vp rule spec | |
189 -> vertical bar, vp rule spec:n =aws(n); | |
190 | |
191 (void) vp rule specs | |
192 -> reduction procedure:pn =sws((iws(),vp_form3(pn))); | |
193 -> vp rule specs, additional vp rule spec | |
194 | |
195 (void) vp rules | |
196 -> vp rule specs | proper vp rule specs | |
197 | |
198 (int) vp rule spec | |
199 -> grammar rule, reduction procedure:s =vp_form3(s); | |
200 | |
201 (void) rule specs | |
202 -> reduction procedure:n =sws(form_spec_2(form1(),n)); | |
203 -> rule spec:n =sws(n); | |
204 -> rule specs, additional rule spec | |
205 | |
206 (void) additional rule spec | |
207 -> vertical bar, rule spec:n =aws(n); | |
208 | |
209 (int) rule spec | |
210 -> grammar rule, reduction procedure:s =form_spec_2(makeRule(ruleElementStack.pop()),s); | |
211 | |
212 (void) grammar rule | |
213 -> init grammar rule, rule element:e, parameter name:p =ruleElementStack.top().push(RuleElement(e,p)); | |
214 -> grammar rule, comma, | |
215 rule element:e, parameter name:p =ruleElementStack.top().push(RuleElement(e,p)); | |
216 | |
217 init grammar rule | |
218 -> =ruleElementStack.push(AgStack<RuleElement>()); | |
219 | |
220 (int) reduction procedure | |
221 -> =0; | |
222 -> equals, embedded c =proc_spec_4(0); | |
223 -> equals, c expression, ';', blank?... =proc_spec_4(1); | |
224 | |
225 (void) data type | |
226 -> type name | |
227 -> type name, template field | |
228 -> type name, template field?, abstract declarator =concat_string(); | |
229 | |
230 (void) type name | |
231 -> symbol name | |
232 -> "::", !sss("::");, blank?..., symbol name =concat_string(); | |
233 -> type name, "::", !ass("::");, blank?..., symbol name =concat_string(); | |
234 | |
235 (void) abstract declarator | |
236 -> indirect data type | |
237 -> direct abstract declarator | |
238 -> indirect data type, direct abstract declarator =concat_string(); | |
239 | |
240 (void) template field | |
241 -> template field head, data type, '>', blank?... =acs('>'), concat_string(); | |
242 | |
243 template field head | |
244 -> '<', blank?... = acs('<'); | |
245 -> template field head, data type, ',', blank?... =acs(','), concat_string(); | |
246 | |
247 (void) direct abstract declarator | |
248 -> {left parenthesis =scs('(');}, abstract declarator, | |
249 right parenthesis =concat_string(), acs(')'); | |
250 | |
251 (void) star | |
252 -> '*', blank?... =sss(" *"); | |
253 | |
254 (void) pointer | |
255 -> star | |
256 -> star, symbol name =concat_string(); | |
257 | |
258 (void) indirect data type | |
259 -> pointer | |
260 -> indirect data type, pointer =concat_string(); | |
261 | |
262 (void) name string | |
263 -> letter:c =scs(c); | |
264 -> name string, letter + digit :c =acs(c); | |
265 -> name string, blank..., letter + digit :c =acs(' '), acs(c); | |
266 | |
267 (void) enum fix | |
268 -> "enum", blank..., letter + digit : c =sss("enum "), acs(c); | |
269 -> enum fix, letter + digit:c =acs(c); | |
270 -> enum fix, blank..., letter + digit:c =acs(' '), acs(c); | |
271 | |
272 (void) symbol name | |
273 -> name string, blank?... | |
274 | |
275 (void) blank | |
276 -> blank char | |
277 -> c comment | |
278 | |
279 (void) space | |
280 -> blank... | |
281 -> blank..., continuation | |
282 -> continuation | |
283 | |
284 (void) continuation | |
285 -> comment, next line | |
286 -> next line | |
287 | |
288 (void) next line | |
289 -> carriage return?, newline | |
290 -> carriage return?, newline, blank... | |
291 | |
292 (void) white | |
293 -> blank | |
294 -> carriage return?, newline | |
295 -> comment, carriage return?, newline | |
296 | |
297 (void) end of line | |
298 -> comment, carriage return?, newline | |
299 -> carriage return?, newline | |
300 -> end of line, white | |
301 -> end of line, vertical space //form feed | |
302 | |
303 (void) comment | |
304 -> "//", ~eol chars & ~eof?... | |
305 | |
306 (int) character | |
307 -> signed number | |
308 -> '^', 33..126:x, blank?... =x & 0x1f; | |
309 | |
310 (int) quoted character | |
311 -> single quote, char const:c, right quote =(character_seen=1),c; | |
312 | |
313 (int) signed number | |
314 -> sign:s, simple number:n, blank?... =s*n; | |
315 | |
316 (int) sign | |
317 -> plus? =1; | |
318 -> minus =-1; | |
319 | |
320 (int) simple number | |
321 -> decimal number | |
322 -> octal number:n =n; | |
323 -> {"0x" | "0X"}, hex number:n =n; | |
324 | |
325 (int) decimal number | |
326 -> '1-9':d =d - '0'; | |
327 -> decimal number:n, '0-9':d =10*n + d - '0'; | |
328 | |
329 (int) octal number | |
330 -> '0' =0; | |
331 -> octal number:n, '0-7':d =8*n + d - '0'; | |
332 | |
333 (int) hex number | |
334 -> hex digit:d =d; | |
335 -> hex number:n, hex digit:d =16*n + d; | |
336 | |
337 (int) hex digit | |
338 -> '0-9':d =d-'0'; | |
339 -> 'a-f' + 'A-F':d =(d&7)+9; | |
340 | |
341 (int) rule element | |
342 -> token | |
343 // -> mid rule action:p =vp_8a(p); | |
344 -> immediate action:p =vp_8a(mid_line(p)); | |
345 | |
346 (int) token | |
347 -> set union:n =form_element_1(n); | |
348 -> virtual production | |
349 | |
350 (CharSetExpression *) set union | |
351 -> set intersection | |
352 -> set union:u, plus, set intersection:i =new CharSetUnion(u,i); | |
353 -> set difference | |
354 | |
355 (CharSetExpression *) set difference | |
356 -> set union:u, minus, set intersection:i =new CharSetDifference(u,i); | |
357 | |
358 (CharSetExpression *) set intersection | |
359 -> set complement | |
360 -> set intersection:i, '&', space?, set complement:n =new CharSetIntersection(i,n); | |
361 | |
362 (CharSetExpression *) set complement | |
363 -> character set | |
364 -> tilde, set complement:n =new CharSetComplement(n); | |
365 | |
366 (int) char const | |
367 // -> anything -(single quote + backslash + eol chars):c = | |
368 // case_sensitive ? (c) : agToUpper((char) c); | |
369 -> anything -(single quote + backslash + eol chars) | |
370 -> escape sequence | |
371 -> octal escape | |
372 -> three octal | |
373 -> hex escape | |
374 | |
375 (CharSetExpression *) character set | |
376 -> character range | |
377 -> character:c =new IndividualCode(c); | |
378 -> quoted character:c =new IndividualChar(c); | |
379 -> symbol name =ss2(); | |
380 -> left parenthesis, set union:x, | |
381 right parenthesis =x; | |
382 | |
383 (CharSetExpression *) character range | |
384 -> single quote, char const:l, '-', | |
385 char const:r, right quote =(character_seen=1),new CharRange(l,r); | |
386 -> character:l, "..", space?, character:r =new CodeRange(l,r); | |
387 | |
388 (void) definition | |
389 -> symbol name, equals, set union:n =definition_1(n); | |
390 -> symbol name, equals, virtual production:p =definition_2(p); | |
391 // -> symbol name, equals, mid rule action:p =definition_2(vp_8a(p)); | |
392 -> symbol name, equals, proc def:p =defineImmediateProc(Procedure(p)); | |
393 | |
394 (void) enum definition | |
395 -> symbol name =definition_3(enum_base++); | |
396 -> symbol name, equals, character:n =definition_3(enum_base = n), enum_base++; | |
397 -> symbol name, equals, quoted character:n =definition_3(enum_base = n), enum_base++; | |
398 | |
399 (void) enum statement | |
400 -> "enum", space, left brace, enum definition | |
401 -> enum statement, comma, enum definition | |
402 | |
403 (void) keyword string | |
404 -> keyword string head, string, double quote, blank?... | |
405 | |
406 (void) string | |
407 -> string A | string B | string C | |
408 | |
409 (void) keyword string head | |
410 -> double quote =ics(); | |
411 | |
412 (int) string char | |
413 -> simple string char | |
414 -> escape sequence | |
415 -> three octal:n =null_warning(n); | |
416 | |
417 (int) escape sequence | |
418 -> "\\a" ='\a'; | |
419 -> "\\b" ='\b'; | |
420 -> "\\f" ='\f'; | |
421 -> "\\n" ='\n'; | |
422 -> "\\r" ='\r'; | |
423 -> "\\t" ='\t'; | |
424 -> "\\v" ='\v'; | |
425 -> "\\\\" ='\\'; | |
426 -> "\\?" = '\?'; | |
427 -> "\\'" ='\''; | |
428 -> "\\\"" ='"'; | |
429 | |
430 { | |
431 int null_warning(int n) { | |
432 extern void warning_here(const char *,...); | |
433 if (n == 0) log_error("Null character in string"); | |
434 return n; | |
435 } | |
436 } | |
437 | |
438 (int) one octal | |
439 -> backslash, '0-7':n =n&7; | |
440 | |
441 (int) two octal | |
442 -> one octal:n, '0-7':d =n*8 + (d&7); | |
443 | |
444 (int) three octal | |
445 -> two octal:n, '0-7':d =n*8 + (d&7); | |
446 | |
447 (int) octal escape | |
448 -> one octal | two octal | |
449 | |
450 (int) hex escape | |
451 -> "\\x", hex number:x =x; | |
452 | |
453 (void) string A | |
454 -> string char:c =acs(c); | |
455 -> any digit:c =acs(c); | |
456 -> string, string char:c =acs(c); | |
457 -> string A, any digit:c =acs(c); | |
458 -> string B, nonoctal digit:c =acs(c); | |
459 | |
460 (void) string B | |
461 -> octal escape:c =acs(null_warning(c)); | |
462 -> string, octal escape:c =acs(null_warning(c)); | |
463 | |
464 (void) string C | |
465 -> hex escape:c =acs(null_warning(c)); | |
466 -> string, hex escape:c =acs(null_warning(c)); | |
467 | |
468 (int) parameter name | |
469 -> =0; | |
470 -> ':', space?, c name =cVariableList << buildAgString(); | |
471 | |
472 (void) simple name | |
473 -> letter:c =scs(c); | |
474 -> simple name, letter + digit:c =acs(c); | |
475 | |
476 (void) c name | |
477 -> simple name, blank?... | |
478 | |
479 (void) configuration section | |
480 -> '[', configuration parameters, right bracket | |
481 | |
482 (void) configuration parameters | |
483 -> blank?..., end of line?, [configuration parameter list, end of line?] | |
484 | |
485 (void) configuration parameter list | |
486 -> configuration parameter | |
487 -> configuration parameter list, end of line, configuration parameter | |
488 | |
489 | |
490 (void) configuration parameter | |
491 -> symbol name =ConfigParam::set(1, pggErrorHandler); //gp4(1); | |
492 -> tilde, symbol name =ConfigParam::set(0, pggErrorHandler); //gp4(0); | |
493 -> symbol name, equals, data type =ConfigParam::set(pggErrorHandler); //gp2(); | |
494 -> symbol name, equals, keyword string =ConfigParam::set(pggErrorHandler); //gp3(); | |
495 -> enum fix, blank?..., equals, keyword string =ConfigParam::set(pggErrorHandler); //gp3(); | |
496 -> symbol name, equals, signed number:n =ConfigParam::set(n, pggErrorHandler); //gp5(n); | |
497 -> attribute statement | |
498 -> keyword kluge, symbol name =concat_string(), ConfigParam::set(1, pggErrorHandler); //gp4(1); | |
499 | |
500 keyword kluge | |
501 -> "distinguish", blank... =sss("distinguish "); | |
502 | |
503 (void) attribute statement | |
504 -> "left", token list =set_prec(1,0); | |
505 -> "right", token list =set_prec(0,1); | |
506 -> "nonassoc", token list =set_prec(0,0); | |
507 -> "sticky", token list =set_sticky(); | |
508 -> "subgrammar", token list =set_subgrammar(); | |
509 -> "hidden", token list =set_hidden(); | |
510 -> new reserve statement, list end //=new_reserve(); | |
511 -> enum statement, list end | |
512 -> "disregard", blank..., token:t =disregard(t); | |
513 -> "extend", blank..., "pcb", blank?..., embedded c =extensionStack.push(cSegmentStack.pop()); | |
514 -> "lexeme", token list =set_lexeme(); | |
515 -> "reserve", blank..., "keywords", token list =set_reserved_words(); | |
516 -> "rename", blank..., "macro", blank..., | |
517 macro name:oldName, blank..., macro name:newName =at(rename_macro_list,oldName,newName); | |
518 -> "wrapper", blank?..., left brace, wrapper list, right brace | |
519 | |
520 (int) macro name | |
521 -> letter =(PCB).pointer-input_base-1; | |
522 -> macro name, letter + digit | |
523 | |
524 list end | |
525 -> [comma | continuation], right brace | |
526 | |
527 (void) new reserve statement | |
528 -> "distinguish", blank..., "keywords", blank..., left brace, | |
529 set union:n =distinguishSets.push(ParseTree(n)); | |
530 -> new reserve statement, comma, set union:n =distinguishSets.push(ParseTree(n)); | |
531 | |
532 (void) token list | |
533 -> blank..., left brace, tokens, list end | |
534 | |
535 (void) tokens | |
536 -> token:t =sws(t); | |
537 -> tokens, comma, token:t =aws(t); | |
538 | |
539 (int) virtual production | |
540 -> keyword string =vp_s(); | |
541 -> keyword string, '?', blank?... =vp_5(vp_s()); | |
542 -> left brace, vp rules, right brace =vp_1(); | |
543 -> left brace, vp rules, "}...", blank?... =vp_2(); | |
544 -> left bracket, proper vp rule specs, right bracket =vp_3(); | |
545 -> left bracket, proper vp rule specs, "]...", blank?... =vp_4(); | |
546 -> set union:n, '?', blank?... =vp_5(form_element_1(n)); | |
547 -> set union:n, "?...", blank?... =vp_6(form_element_1(n)); | |
548 -> set union:n, ellipsis =vp_7(form_element_1(n)); | |
549 -> left brace, proper vp rule specs, "}/...", blank?... =vp_9(); | |
550 -> left bracket, proper vp rule specs, "]/...", blank?... =vp_10(); | |
551 | |
552 /* | |
553 (int) mid rule action | |
554 -> bang, embedded c =mid_line(proc_spec_4(0)); | |
555 -> bang, c expression, ';', blank?... =mid_line(proc_spec_4(1)); | |
556 */ | |
557 | |
558 (int) proc def | |
559 -> bang, embedded c =proc_spec_4(0); | |
560 -> bang, c expression, ';', blank?... =proc_spec_4(1); | |
561 | |
562 (int) immediate action | |
563 -> bang, embedded c =proc_spec_4(0); | |
564 -> bang, c expression, ';', blank?... =proc_spec_4(1); | |
565 | |
566 (void) embedded c | |
567 -> embedded c head, c code:y, right brace =cSegmentStack.top().end = y; | |
568 | |
569 (void) embedded c head | |
570 -> '{', [carriage return?, newline]... =cSegmentStack.push(CSegment()); // =copyon(); | |
571 | |
572 (unsigned char *) c code | |
573 -> =PCB.pointer; | |
574 -> c code first, c text =PCB.pointer; | |
575 | |
576 (void) c code first | |
577 -> simple c char - eol chars | |
578 -> c comment | |
579 -> comment, carriage return?, newline | |
580 -> c character constant, single quote | |
581 -> c string constant, double quote | |
582 | |
583 (void) c text | |
584 -> | |
585 -> c text, c char | |
586 | |
587 (void) c char //c char represents the content of embedded c | |
588 -> simple c char | |
589 -> '{', c text, '}' | |
590 -> c comment | |
591 -> comment, carriage return?, newline | |
592 -> c character constant, single quote | |
593 -> c string constant, double quote | |
594 | |
595 (void) c expression head | |
596 -> =cSegmentStack.push(CSegment()); | |
597 | |
598 (void) c expression | |
599 -> c expression head, c chars =cSegmentStack.top().end = PCB.pointer; | |
600 | |
601 (void) c chars | |
602 -> c expression char | |
603 -> c chars, c expression char | |
604 -> c chars, blank | |
605 | |
606 (void) c expression char //c char represents the content of embedded C | |
607 -> simple c char - ';' - eol chars - blank char | |
608 -> "\\\n" | |
609 -> c character constant, single quote | |
610 -> c string constant, double quote | |
611 | |
612 (void) c comment | |
613 -> c comment head, "*/" | |
614 | |
615 (void) c comment head | |
616 -> "/*" | |
617 -> c comment head, ~eof | |
618 | |
619 (void) c comment, c comment head | |
620 -> c comment head, c comment = | |
621 {if (nest_comments) PCB.reduction_token = pgg_c_comment_head_token;} | |
622 | |
623 (void) c string constant | |
624 -> double quote, [c literal elem | single quote | backslash, anything]... | |
625 | |
626 (void) c character constant | |
627 -> single quote, [c literal elem | double quote | backslash, anything]... | |
628 | |
629 [ | |
630 hidden { | |
631 arrow, comma, ellipsis, equals, left brace, | |
632 left bracket, left parenthesis, minus, plus, right bracket, | |
633 list end, | |
634 right brace, right parenthesis, right quote, star, tilde, | |
635 vertical bar, simple statement, token name, | |
636 rule spec, pointer, indirect data type, name string, | |
637 blank, space, next line, white, end of line, sign, simple number, | |
638 one octal, two octal, three octal, | |
639 string A, string B, string C, | |
640 simple name, c text, c char, c chars, c expression char, | |
641 c expression head, | |
642 c comment head, | |
643 c code, c name, | |
644 bang, // complete statement, | |
645 rule specs, vp rule specs, additional rule spec, | |
646 data type, template field, abstract declarator, | |
647 direct abstract declarator, pointer, | |
648 name string, proper vp rule specs, additional vp rule spec, | |
649 new reserve statement, anything, //set union, //set intersection, //set complement, | |
650 enum fix | |
651 } | |
652 ] | |
653 | |
654 { | |
655 pgg_pcb_type pgcb; | |
656 #define PCB pgcb | |
657 | |
658 #define PARSER_STACK_OVERFLOW parse_stack_overflow() | |
659 #define SYNTAX_ERROR log_syntax_error() | |
660 #define GET_CONTEXT CONTEXT.y = PCB.line, CONTEXT.x = PCB.column; | |
661 | |
662 #define REDUCTION_TOKEN_ERROR reduction_token_error() | |
663 | |
664 extern AgStack< AgStack<RuleElement> > ruleElementStack; | |
665 | |
666 AgStack<CSegment> extensionStack; | |
667 AgStack<CSegment> cSegmentStack; | |
668 int nPrologueSegments; | |
669 | |
670 CSegment::CSegment() | |
671 : begin(PCB.pointer), end(PCB.pointer), line(PCB.line) | |
672 { | |
673 LOGSECTION("CSegment::CSegment"); | |
674 // Nothing to do | |
675 } | |
676 | |
677 static class PggErrorHandler : public ConfigParam::ErrorHandler { | |
678 void badParam(const char *s){log_error(s);} | |
679 } pggErrorHandler; | |
680 | |
681 | |
682 void reduction_token_error(void) { | |
683 #ifdef INCLUDE_LOGGING | |
684 LOGSECTION("reduction_token_error"); | |
685 LOGV(PCB.sn) LCV(PCB.ssx) LCV(PCB.reduction_token); | |
686 for (int i = 0; i < PCB.ssx; i++) LOGV(i) LCV(PCB.ss[i]); | |
687 #endif | |
688 assert(0); | |
689 } | |
690 | |
691 extern AgString infile_name; | |
692 extern AgString errorReportFile; | |
693 | |
694 Error::Error(AgString msg, int contextFlag) | |
695 : file(errorReportFile), | |
696 line(contextFlag? ERROR_CONTEXT.y : PCB.line), | |
697 column(contextFlag? ERROR_CONTEXT.x : PCB.column), | |
698 key(warn), | |
699 message(msg) | |
700 { | |
701 LOGSECTION("Error::Error(AgString, int)"); | |
702 LOGV(PCB.line) LCV(PCB.column) LCV(contextFlag) LCV(msg.pointer()); | |
703 LOGV(ERROR_CONTEXT.x) LCV(ERROR_CONTEXT.y); | |
704 // Nothing here | |
705 } | |
706 | |
707 Error::Error(int l, int c, AgString msg) | |
708 : file(errorReportFile), | |
709 line(l), | |
710 column(c), | |
711 key(warn), | |
712 message(msg) | |
713 { | |
714 LOGSECTION("Error::Error(int, int, AgString)"); | |
715 // Nothing here | |
716 } | |
717 | |
718 extern tsd *rename_macro_list; | |
719 extern int parse_abort_flag; | |
720 | |
721 void parse_stack_overflow(void) { | |
722 reset_stk(); | |
723 log_error("Nesting too deep. Analysis aborted."); | |
724 errorList.top().setFatal(); | |
725 parse_abort_flag = 1; | |
726 PCB.exit_flag = AG_SEMANTIC_ERROR_CODE; | |
727 } | |
728 | |
729 extern int character_seen; | |
730 extern int enum_base; | |
731 extern unsigned char *input_base; | |
732 extern int precedence_level; | |
733 extern int syntax_error_flag; | |
734 | |
735 CharSetExpression *ss2(void); | |
736 | |
737 void acs(int); | |
738 void aws(int); | |
739 void atkn(Token); | |
740 void defineImmediateProc(Procedure p); | |
741 void definition_1(CharSetExpression *); | |
742 void definition_2(int); | |
743 void definition_3(int); | |
744 int form_element_1(CharSetExpression *); | |
745 int form_spec_2(int, int); | |
746 int form1(void); | |
747 int form2(void); | |
748 int head_list_1(int); | |
749 int head_list_2(int); | |
750 static int head_list_3(int); | |
751 void ics(void); | |
752 int identify_node(CharSetExpression *); | |
753 void iws(void); | |
754 int makeRule(const AgIndexedContainer<RuleElement> &); | |
755 int mid_line(int); | |
756 int null_warning(int); | |
757 int proc_spec_4(int); | |
758 void production(int); | |
759 void range(int, int); | |
760 void scs(int); | |
761 static void set_prec(int,int); | |
762 void sws(int); | |
763 int vp_form3(int); | |
764 int vp_s(void); | |
765 int vp_1(void); | |
766 int vp_2(void); | |
767 int vp_3(void); | |
768 int vp_4(void); | |
769 int vp_5(int); | |
770 int vp_6(int); | |
771 int vp_7(int); | |
772 int vp_8(int); | |
773 int vp_8a(int); | |
774 int vp_9(void); | |
775 int vp_10(void); | |
776 | |
777 int *disregard_list = NULL; | |
778 int n_disregard_list = 0; | |
779 | |
780 static void disregard(int tn) { | |
781 LOGSECTION("disregard"); | |
782 iws(); | |
783 if (n_disregard_list) { | |
784 int *p = disregard_list; | |
785 while (n_disregard_list--) aws(*p++); | |
786 DEALLOCATE(disregard_list); | |
787 } | |
788 xws(tn); | |
789 disregard_list = build_list(); | |
790 n_disregard_list = fis(); | |
791 } | |
792 | |
793 static void log_syntax_error(void) { | |
794 LOGSECTION("log_syntax_error"); | |
795 | |
796 #ifdef INCLUDE_LOGGING | |
797 { | |
798 LOGV(PCB.sn) LCV(PCB.ssx) LCV(PCB.token_number); | |
799 for (int i = 0; i < PCB.ssx; i++) LOGV(i) LCV(PCB.ss[i]); | |
800 } | |
801 #endif | |
802 int flag = PCB.error_frame_token == pgg_c_comment_token || | |
803 PCB.error_frame_token == pgg_embedded_c_token; | |
804 LOGV(flag); | |
805 reset_stk(); | |
806 | |
807 #ifdef INCLUDE_LOGGING | |
808 { | |
809 LOGV(PCB.sn) LCV(PCB.ssx) LCV(PCB.token_number); | |
810 for (int i = 0; i < PCB.ssx; i++) LOGV(i) LCV(PCB.ss[i]); | |
811 } | |
812 #endif | |
813 ssprintf("%s in %s", PCB.error_message, pgg_token_names[PCB.error_frame_token]); | |
814 LOGS(string_base); | |
815 errorList.push(Error(string_base, flag && PCB.token_number == pgg_eof_token)); | |
816 rcs(); | |
817 #ifdef INCLUDE_LOGGING | |
818 { | |
819 LOGV(PCB.sn) LCV(PCB.ssx) LCV(PCB.token_number); | |
820 for (int i = 0; i < PCB.ssx; i++) LOGV(i) LCV(PCB.ss[i]); | |
821 } | |
822 #endif | |
823 LOGS("error logged"); | |
824 errorList.top().setFatal(); | |
825 LOGS("fatal flag set"); | |
826 syntax_error_flag++; | |
827 #ifdef INCLUDE_LOGGING | |
828 { | |
829 LOGV(PCB.sn) LCV(PCB.ssx) LCV(PCB.token_number); | |
830 for (int i = 0; i < PCB.ssx; i++) LOGV(i) LCV(PCB.ss[i]); | |
831 } | |
832 #endif | |
833 if (errorList.size() < 50) return; | |
834 log_error("Too many errors. Parse aborted."); | |
835 errorList.top().setFatal(); | |
836 PCB.exit_flag = AG_SYNTAX_ERROR_CODE; | |
837 } | |
838 | |
839 static int head_list_3(int type) { | |
840 LOGSECTION("head_list_3"); | |
841 LOGV(type); | |
842 int i, n = tis(); | |
843 for (i = 0; i < n; i ++) { | |
844 Token token(list_base[i]); | |
845 int ptt = token->value_type; | |
846 LOGV(ptt) LCV(type); | |
847 if (ptt && ptt != type) { | |
848 ssprintf("Type Redefinition of T%03d: ", (int) token); | |
849 atkn(token); | |
850 log_error(); | |
851 } | |
852 token->value_type = type; | |
853 /* | |
854 if (ptt == 0 && token->rp_arg && type == void_token_type) { | |
855 //ssprintf("Void token, %s, used as parameter", dict_str(tkn_dict,token->token_name)); | |
856 ssprintf("Void token, %s, used as parameter", token->token_name->string.pointer()); | |
857 log_error(); | |
858 } | |
859 */ | |
860 } | |
861 return type; | |
862 } | |
863 | |
864 static void set_prec(int left, int right){ | |
865 LOGSECTION("set_prec"); | |
866 int n = tis(); | |
867 precedence_level++; | |
868 while (n--) { | |
869 Token token(list_base[n]); | |
870 token->left_associative = left; | |
871 token->right_associative = right; | |
872 token->precedence_level = precedence_level; | |
873 token->operatorCandidate = 1; | |
874 } | |
875 rws(); | |
876 } | |
877 | |
878 static void set_sticky(void){ | |
879 LOGSECTION("set_sticky"); | |
880 int n = tis(); | |
881 while (n--) { | |
882 Token token(list_base[n]); | |
883 token->sticky = 1; | |
884 } | |
885 rws(); | |
886 } | |
887 | |
888 static void set_subgrammar(void){ | |
889 LOGSECTION("set_subgrammar"); | |
890 int n = tis(); | |
891 while (n--) { | |
892 Token token = list_base[n]; | |
893 token->subgrammar = 1; | |
894 } | |
895 rws(); | |
896 } | |
897 | |
898 void set_hidden(void) { | |
899 LOGSECTION("set_hidden"); | |
900 int *lb = list_base; | |
901 int n = tis(); | |
902 //while (n--) map_token_number[*lb++].fine_structure = 1; | |
903 while (n--) Token(*lb++)->fine_structure = 1; | |
904 rws(); | |
905 } | |
906 | |
907 void set_lexeme(void) { | |
908 LOGSECTION("set_lexeme"); | |
909 int n = tis(); | |
910 while (n--) { | |
911 Token token = list_base[n]; | |
912 token->lexeme = 1; | |
913 } | |
914 rws(); | |
915 } | |
916 | |
917 void set_reserved_words(void) { | |
918 LOGSECTION("set_reserved_words"); | |
919 int n = tis(); | |
920 while (n--) { | |
921 Token token(list_base[n]); | |
922 token->reserved_word = 1; | |
923 } | |
924 rws(); | |
925 } | |
926 | |
927 void parse(void) { | |
928 pgcb.pointer = input_base; | |
929 pgg(); | |
930 } | |
931 } | |
932 |