]> git.saurik.com Git - bison.git/blob - tests/existing.at
Pass the token type to yysyntax_error.
[bison.git] / tests / existing.at
1 # Exercising Bison on actual grammars. -*- Autotest -*-
2
3 # Copyright (C) 1989, 1990, 1991, 1992, 2000, 2001, 2002, 2003, 2004, 2005,
4 # 2007 Free Software Foundation, Inc.
5
6 # This program is free software: you can redistribute it and/or modify
7 # it under the terms of the GNU General Public License as published by
8 # the Free Software Foundation, either version 3 of the License, or
9 # (at your option) any later version.
10 #
11 # This program is distributed in the hope that it will be useful,
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 # GNU General Public License for more details.
15 #
16 # You should have received a copy of the GNU General Public License
17 # along with this program. If not, see <http://www.gnu.org/licenses/>.
18
19 AT_BANNER([[Existing Grammars.]])
20 ## ----------------- ##
21 ## GNU AWK Grammar. ##
22 ## ----------------- ##
23
24 AT_SETUP([GNU AWK Grammar])
25
26 # We have been careful to strip all the actions excepts the
27 # mid-rule actions. We rely on %expect to check that there are
28 # indeed 65 SR conflicts.
29 #
30 # Bison was once wrong, due to an incorrect computation of nullable.
31 # It reported 485 SR conflicts!
32
33 AT_DATA([[input.y]],
34 [[%expect 65
35
36 %token FUNC_CALL NAME REGEXP
37 %token ERROR
38 %token YNUMBER YSTRING
39 %token RELOP APPEND_OP
40 %token ASSIGNOP MATCHOP NEWLINE CONCAT_OP
41 %token LEX_BEGIN LEX_END LEX_IF LEX_ELSE LEX_RETURN LEX_DELETE
42 %token LEX_WHILE LEX_DO LEX_FOR LEX_BREAK LEX_CONTINUE
43 %token LEX_PRINT LEX_PRINTF LEX_NEXT LEX_EXIT LEX_FUNCTION
44 %token LEX_GETLINE LEX_NEXTFILE
45 %token LEX_IN
46 %token LEX_AND LEX_OR INCREMENT DECREMENT
47 %token LEX_BUILTIN LEX_LENGTH
48
49 /* Lowest to highest */
50 %right ASSIGNOP
51 %right '?' ':'
52 %left LEX_OR
53 %left LEX_AND
54 %left LEX_GETLINE
55 %nonassoc LEX_IN
56 %left FUNC_CALL LEX_BUILTIN LEX_LENGTH
57 %nonassoc ','
58 %nonassoc MATCHOP
59 %nonassoc RELOP '<' '>' '|' APPEND_OP TWOWAYIO
60 %left CONCAT_OP
61 %left YSTRING YNUMBER
62 %left '+' '-'
63 %left '*' '/' '%'
64 %right '!' UNARY
65 %right '^'
66 %left INCREMENT DECREMENT
67 %left '$'
68 %left '(' ')'
69 %%
70
71 start
72 : opt_nls program opt_nls
73 ;
74
75 program
76 : rule
77 | program rule
78 | error
79 | program error
80 | /* empty */
81 ;
82
83 rule
84 : LEX_BEGIN {} action
85 | LEX_END {} action
86 | LEX_BEGIN statement_term
87 | LEX_END statement_term
88 | pattern action
89 | action
90 | pattern statement_term
91 | function_prologue function_body
92 ;
93
94 func_name
95 : NAME
96 | FUNC_CALL
97 | lex_builtin
98 ;
99
100 lex_builtin
101 : LEX_BUILTIN
102 | LEX_LENGTH
103 ;
104
105 function_prologue
106 : LEX_FUNCTION {} func_name '(' opt_param_list r_paren opt_nls
107 ;
108
109 function_body
110 : l_brace statements r_brace opt_semi opt_nls
111 | l_brace r_brace opt_semi opt_nls
112 ;
113
114 pattern
115 : exp
116 | exp ',' exp
117 ;
118
119 regexp
120 /*
121 * In this rule, want_regexp tells yylex that the next thing
122 * is a regexp so it should read up to the closing slash.
123 */
124 : '/' {} REGEXP '/'
125 ;
126
127 action
128 : l_brace statements r_brace opt_semi opt_nls
129 | l_brace r_brace opt_semi opt_nls
130 ;
131
132 statements
133 : statement
134 | statements statement
135 | error
136 | statements error
137 ;
138
139 statement_term
140 : nls
141 | semi opt_nls
142 ;
143
144 statement
145 : semi opt_nls
146 | l_brace r_brace
147 | l_brace statements r_brace
148 | if_statement
149 | LEX_WHILE '(' exp r_paren opt_nls statement
150 | LEX_DO opt_nls statement LEX_WHILE '(' exp r_paren opt_nls
151 | LEX_FOR '(' NAME LEX_IN NAME r_paren opt_nls statement
152 | LEX_FOR '(' opt_exp semi opt_nls exp semi opt_nls opt_exp r_paren opt_nls statement
153 | LEX_FOR '(' opt_exp semi opt_nls semi opt_nls opt_exp r_paren opt_nls statement
154 | LEX_BREAK statement_term
155 | LEX_CONTINUE statement_term
156 | print '(' expression_list r_paren output_redir statement_term
157 | print opt_rexpression_list output_redir statement_term
158 | LEX_NEXT statement_term
159 | LEX_NEXTFILE statement_term
160 | LEX_EXIT opt_exp statement_term
161 | LEX_RETURN {} opt_exp statement_term
162 | LEX_DELETE NAME '[' expression_list ']' statement_term
163 | LEX_DELETE NAME statement_term
164 | exp statement_term
165 ;
166
167 print
168 : LEX_PRINT
169 | LEX_PRINTF
170 ;
171
172 if_statement
173 : LEX_IF '(' exp r_paren opt_nls statement
174 | LEX_IF '(' exp r_paren opt_nls statement
175 LEX_ELSE opt_nls statement
176 ;
177
178 nls
179 : NEWLINE
180 | nls NEWLINE
181 ;
182
183 opt_nls
184 : /* empty */
185 | nls
186 ;
187
188 input_redir
189 : /* empty */
190 | '<' simp_exp
191 ;
192
193 output_redir
194 : /* empty */
195 | '>' exp
196 | APPEND_OP exp
197 | '|' exp
198 | TWOWAYIO exp
199 ;
200
201 opt_param_list
202 : /* empty */
203 | param_list
204 ;
205
206 param_list
207 : NAME
208 | param_list comma NAME
209 | error
210 | param_list error
211 | param_list comma error
212 ;
213
214 /* optional expression, as in for loop */
215 opt_exp
216 : /* empty */
217 | exp
218 ;
219
220 opt_rexpression_list
221 : /* empty */
222 | rexpression_list
223 ;
224
225 rexpression_list
226 : rexp
227 | rexpression_list comma rexp
228 | error
229 | rexpression_list error
230 | rexpression_list error rexp
231 | rexpression_list comma error
232 ;
233
234 opt_expression_list
235 : /* empty */
236 | expression_list
237 ;
238
239 expression_list
240 : exp
241 | expression_list comma exp
242 | error
243 | expression_list error
244 | expression_list error exp
245 | expression_list comma error
246 ;
247
248 /* Expressions, not including the comma operator. */
249 exp : variable ASSIGNOP {} exp
250 | '(' expression_list r_paren LEX_IN NAME
251 | exp '|' LEX_GETLINE opt_variable
252 | exp TWOWAYIO LEX_GETLINE opt_variable
253 | LEX_GETLINE opt_variable input_redir
254 | exp LEX_AND exp
255 | exp LEX_OR exp
256 | exp MATCHOP exp
257 | regexp
258 | '!' regexp %prec UNARY
259 | exp LEX_IN NAME
260 | exp RELOP exp
261 | exp '<' exp
262 | exp '>' exp
263 | exp '?' exp ':' exp
264 | simp_exp
265 | exp simp_exp %prec CONCAT_OP
266 ;
267
268 rexp
269 : variable ASSIGNOP {} rexp
270 | rexp LEX_AND rexp
271 | rexp LEX_OR rexp
272 | LEX_GETLINE opt_variable input_redir
273 | regexp
274 | '!' regexp %prec UNARY
275 | rexp MATCHOP rexp
276 | rexp LEX_IN NAME
277 | rexp RELOP rexp
278 | rexp '?' rexp ':' rexp
279 | simp_exp
280 | rexp simp_exp %prec CONCAT_OP
281 ;
282
283 simp_exp
284 : non_post_simp_exp
285 /* Binary operators in order of decreasing precedence. */
286 | simp_exp '^' simp_exp
287 | simp_exp '*' simp_exp
288 | simp_exp '/' simp_exp
289 | simp_exp '%' simp_exp
290 | simp_exp '+' simp_exp
291 | simp_exp '-' simp_exp
292 | variable INCREMENT
293 | variable DECREMENT
294 ;
295
296 non_post_simp_exp
297 : '!' simp_exp %prec UNARY
298 | '(' exp r_paren
299 | LEX_BUILTIN
300 '(' opt_expression_list r_paren
301 | LEX_LENGTH '(' opt_expression_list r_paren
302 | LEX_LENGTH
303 | FUNC_CALL '(' opt_expression_list r_paren
304 | variable
305 | INCREMENT variable
306 | DECREMENT variable
307 | YNUMBER
308 | YSTRING
309 | '-' simp_exp %prec UNARY
310 | '+' simp_exp %prec UNARY
311 ;
312
313 opt_variable
314 : /* empty */
315 | variable
316 ;
317
318 variable
319 : NAME
320 | NAME '[' expression_list ']'
321 | '$' non_post_simp_exp
322 ;
323
324 l_brace
325 : '{' opt_nls
326 ;
327
328 r_brace
329 : '}' opt_nls
330 ;
331
332 r_paren
333 : ')'
334 ;
335
336 opt_semi
337 : /* empty */
338 | semi
339 ;
340
341 semi
342 : ';'
343 ;
344
345 comma : ',' opt_nls
346 ;
347
348 %%
349 ]])
350
351 # Pass plenty of options, to exercise plenty of code, even if we
352 # don't actually check the output. But SEGV is watching us, and
353 # so might do dmalloc.
354 AT_BISON_CHECK([[--verbose --defines input.y]])
355
356 AT_CLEANUP
357
358 ## ----------------- ##
359 ## GNU Cim Grammar. ##
360 ## ----------------- ##
361
362 AT_SETUP([GNU Cim Grammar])
363
364 # GNU Cim, the GNU Simula 87 Compiler.
365
366 # Bison was once wrong, due to an incorrect computation of the RR conflicts.
367 # It reported 80 SR && 99 RR conflicts instead of 78/10!!!
368
369 AT_DATA([[input.y]],
370 [[%union {}
371
372 %token
373 HACTIVATE HAFTER /*HAND*/ HARRAY HAT
374 HBEFORE HBEGIN HBOOLEAN
375 HCHARACTER HCLASS /*HCOMMENT*/ HCONC
376 HDELAY HDO
377 HELSE HEND HEQ /*HEQV*/ HEXTERNAL
378 HFOR
379 HGE HGO HGOTO HGT
380 HHIDDEN
381 HIF /*HIMP*/ HIN HINNER HINSPECT HINTEGER HIS
382 HLABEL HLE HLONG HLT
383 HNAME HNE HNEW HNONE /*HNOT*/ HNOTEXT
384 /*HOR*/ HOTHERWISE
385 HPRIOR HPROCEDURE HPROTECTED
386 HQUA
387 HREACTIVATE HREAL HREF
388 HSHORT HSTEP HSWITCH
389 HTEXT HTHEN HTHIS HTO
390 HUNTIL
391 HVALUE HVAR HVIRTUAL
392 HWHEN HWHILE
393
394 HASSIGNVALUE HASSIGNREF
395 /*HDOT*/ HPAREXPSEPARATOR HLABELSEPARATOR HSTATEMENTSEPARATOR
396 HBEGPAR HENDPAR
397 HEQR HNER
398 HADD HSUB HMUL HDIV HINTDIV HEXP
399 HDOTDOTDOT
400
401 %token HIDENTIFIER
402 %token HBOOLEANKONST HINTEGERKONST HCHARACTERKONST
403 %token HREALKONST
404 %token HTEXTKONST
405
406
407 %right HASSIGN
408 %left HORELSE
409 %left HANDTHEN
410 %left HEQV
411 %left HIMP
412 %left HOR
413 %left HAND
414
415 %left HNOT
416
417 %left HVALRELOPERATOR HREFRELOPERATOR HOBJRELOPERATOR
418
419 %left HCONC
420
421 %left HTERMOPERATOR
422 %left UNEAR
423 %left HFACTOROPERATOR
424 %left HPRIMARYOPERATOR
425
426 %left HQUA
427
428 %left HDOT
429
430 %start MAIN_MODULE
431 %%
432 /* GRAMATIKK FOR PROGRAM MODULES */
433 MAIN_MODULE : {}
434 MODULS
435 | error HSTATEMENTSEPARATOR MBEE_DECLSTMS
436 ;
437 EXT_DECLARATION : HEXTERNAL
438 MBEE_TYPE
439 HPROCEDURE
440 {}
441 EXT_LIST
442 |
443 HEXTERNAL
444 HIDENTIFIER
445 HPROCEDURE
446 {}
447 HIDENTIFIER {}
448 EXTERNAL_KIND_ITEM
449 | HEXTERNAL
450 HCLASS
451 {}
452 EXT_LIST
453
454 ;
455 EXTERNAL_KIND_ITEM: EXT_IDENT
456 HOBJRELOPERATOR
457 {}
458 MBEE_TYPE HPROCEDURE
459 HIDENTIFIER
460 {}
461 HEADING EMPTY_BLOCK
462 {}
463 /* |
464 EXT_IDENT
465 {}
466 MBEE_REST_EXT_LIST
467 ;
468 MBEE_REST_EXT_LIST: /* EMPTY
469 | HPAREXPSEPARATOR EXT_KIND_LIST
470 ;
471 EXT_KIND_LIST : EXT_KIND_ITEM
472 | EXT_KIND_LIST HPAREXPSEPARATOR EXT_KIND_ITEM
473 ;
474 EXT_KIND_ITEM : HIDENTIFIER
475 EXT_IDENT
476 {}*/
477 ;
478 EMPTY_BLOCK : /*EMPT*/
479 | HBEGIN HEND
480 ;
481 EXT_LIST : EXT_ITEM
482 | EXT_LIST HPAREXPSEPARATOR EXT_ITEM
483 ;
484 EXT_ITEM : HIDENTIFIER
485 EXT_IDENT
486 ;
487 EXT_IDENT : /* EMPTY */
488 | HVALRELOPERATOR {}
489 HTEXTKONST
490 ;
491 /* GRAMATIKK FOR TYPER */
492 NO_TYPE : /*EMPT*/
493 ;
494 MBEE_TYPE : NO_TYPE
495 | TYPE
496 ;
497 TYPE : HREF HBEGPAR
498 HIDENTIFIER
499 {}
500 HENDPAR
501 | HTEXT
502 | HBOOLEAN
503 | HCHARACTER
504 | HSHORT HINTEGER
505 | HINTEGER
506 | HREAL
507 | HLONG HREAL
508 ;
509
510 /* GRAMATIKK FOR DEL AV SETNINGER */
511 MBEE_ELSE_PART : /*EMPT*/
512 /* | HELSE
513 HIF
514 EXPRESSION
515 HTHEN {}
516 BLOCK {}
517 MBEE_ELSE_PART {}*/
518 | HELSE {}
519 BLOCK
520 ;
521 FOR_LIST : FOR_LIST_ELEMENT
522 | FOR_LIST_ELEMENT
523 HPAREXPSEPARATOR
524 FOR_LIST
525 ;
526 FOR_LIST_ELEMENT: EXPRESSION
527 MBEE_F_L_EL_R_PT
528 ;
529 MBEE_F_L_EL_R_PT: /*EMPT*/
530 | HWHILE
531 EXPRESSION
532 | HSTEP
533 EXPRESSION
534 HUNTIL
535 EXPRESSION
536 ;
537 GOTO : HGO
538 HTO
539 | HGOTO
540 ;
541 CONN_STATE_R_PT : WHEN_CLAUSE_LIST
542 | HDO {}
543 BLOCK
544 ;
545 WHEN_CLAUSE_LIST: HWHEN
546 HIDENTIFIER
547 HDO {}
548 BLOCK
549 | WHEN_CLAUSE_LIST
550 HWHEN
551 HIDENTIFIER
552 HDO {}
553 BLOCK
554 ;
555 MBEE_OTWI_CLAUS : /*EMPT*/
556 | HOTHERWISE {}
557
558 BLOCK
559 ;
560 ACTIVATOR : HACTIVATE
561 | HREACTIVATE
562 ;
563 SCHEDULE : /*EMPT*/
564 | ATDELAY EXPRESSION {}
565 PRIOR
566 | BEFOREAFTER {}
567 EXPRESSION
568 ;
569 ATDELAY : HAT
570 | HDELAY
571 ;
572 BEFOREAFTER : HBEFORE
573 | HAFTER
574 ;
575 PRIOR : /*EMPT*/
576 | HPRIOR
577 ;
578 /* GRAMATIKK FOR SETNINGER OG DEKLARASJONER */
579 MODULSTATEMENT : HWHILE
580 EXPRESSION
581 HDO {}
582 BLOCK
583 | HIF
584 EXPRESSION
585 HTHEN {}
586 BLOCK {}
587 MBEE_ELSE_PART
588 | HFOR
589 HIDENTIFIER
590 HASSIGN {}
591 FOR_LIST
592 HDO {}
593 BLOCK
594 | GOTO
595 EXPRESSION
596 | HINSPECT
597 EXPRESSION {}
598 CONN_STATE_R_PT
599 {}
600 MBEE_OTWI_CLAUS
601 | HINNER
602 | HIDENTIFIER
603 HLABELSEPARATOR
604 {}
605 DECLSTATEMENT
606 | EXPRESSION_SIMP
607 HBEGIN
608 {}
609 IMPORT_SPEC_MODULE
610 {}
611 MBEE_DECLSTMS
612 HEND
613 | EXPRESSION_SIMP HBEGIN error HSTATEMENTSEPARATOR
614 MBEE_DECLSTMS HEND
615 | EXPRESSION_SIMP HBEGIN error HEND
616 | EXPRESSION_SIMP
617 | ACTIVATOR EXPRESSION SCHEDULE
618 | HBEGIN
619 {}
620 MBEE_DECLSTMS
621 HEND
622 | MBEE_TYPE HPROCEDURE
623 HIDENTIFIER
624 {}
625 HEADING BLOCK
626 | HIDENTIFIER
627 HCLASS
628 NO_TYPE
629 {}
630 IMPORT_SPEC_MODULE
631 HIDENTIFIER
632 {}
633 HEADING
634 BLOCK
635 | HCLASS
636 NO_TYPE
637 HIDENTIFIER
638 {}
639 HEADING
640 BLOCK
641 | EXT_DECLARATION
642 | /*EMPT*/
643 ;
644 IMPORT_SPEC_MODULE:
645 ;
646 DECLSTATEMENT : MODULSTATEMENT
647 | TYPE
648 HIDENTIFIER
649 MBEE_CONSTANT
650 HPAREXPSEPARATOR
651 {}
652 IDENTIFIER_LISTC
653 | TYPE
654 HIDENTIFIER
655 MBEE_CONSTANT
656 | MBEE_TYPE
657 HARRAY {}
658 ARR_SEGMENT_LIST
659 | HSWITCH
660 HIDENTIFIER
661 HASSIGN {}
662 SWITCH_LIST
663 ;
664 BLOCK : DECLSTATEMENT
665 | HBEGIN MBEE_DECLSTMS HEND
666 | HBEGIN error HSTATEMENTSEPARATOR MBEE_DECLSTMS HEND
667 | HBEGIN error HEND
668 ;
669 MBEE_DECLSTMS : MBEE_DECLSTMSU
670 ;
671 MBEE_DECLSTMSU : DECLSTATEMENT
672 | MBEE_DECLSTMSU
673 HSTATEMENTSEPARATOR
674 DECLSTATEMENT
675 ;
676 MODULS : MODULSTATEMENT
677 | MODULS HSTATEMENTSEPARATOR MODULSTATEMENT
678 ;
679 /* GRAMATIKK FOR DEL AV DEKLARASJONER */
680 ARR_SEGMENT_LIST: ARR_SEGMENT
681 | ARR_SEGMENT_LIST
682 HPAREXPSEPARATOR
683 ARR_SEGMENT
684 ;
685 ARR_SEGMENT : ARRAY_SEGMENT
686 HBEGPAR
687 BAUND_PAIR_LIST HENDPAR
688 ;
689 ARRAY_SEGMENT : ARRAY_SEGMENT_EL {}
690
691 | ARRAY_SEGMENT_EL
692 HPAREXPSEPARATOR
693 ARRAY_SEGMENT
694 ;
695 ARRAY_SEGMENT_EL: HIDENTIFIER
696 ;
697 BAUND_PAIR_LIST : BAUND_PAIR
698 | BAUND_PAIR
699 HPAREXPSEPARATOR
700 BAUND_PAIR_LIST
701 ;
702 BAUND_PAIR : EXPRESSION
703 HLABELSEPARATOR
704 EXPRESSION
705 ;
706 SWITCH_LIST : EXPRESSION
707 | EXPRESSION
708 HPAREXPSEPARATOR
709 SWITCH_LIST
710 ;
711 HEADING : MBEE_FMAL_PAR_P HSTATEMENTSEPARATOR {}
712 MBEE_MODE_PART {}
713 MBEE_SPEC_PART {}
714 MBEE_PROT_PART {}
715 MBEE_VIRT_PART
716 ;
717 MBEE_FMAL_PAR_P : /*EMPT*/
718 | FMAL_PAR_PART
719 ;
720 FMAL_PAR_PART : HBEGPAR NO_TYPE
721 MBEE_LISTV HENDPAR
722 ;
723 MBEE_LISTV : /*EMPT*/
724 | LISTV
725 ;
726 LISTV : HIDENTIFIER
727 | FPP_CATEG HDOTDOTDOT
728 | HIDENTIFIER {}
729 HPAREXPSEPARATOR LISTV
730 | FPP_SPEC
731 | FPP_SPEC
732 HPAREXPSEPARATOR LISTV
733 ;
734 FPP_HEADING : HBEGPAR NO_TYPE
735 FPP_MBEE_LISTV HENDPAR
736 ;
737 FPP_MBEE_LISTV : /*EMPT*/
738 | FPP_LISTV
739 ;
740 FPP_LISTV : FPP_CATEG HDOTDOTDOT
741 | FPP_SPEC
742 | FPP_SPEC
743 HPAREXPSEPARATOR LISTV
744 ;
745 FPP_SPEC : FPP_CATEG SPECIFIER HIDENTIFIER
746 | FPP_CATEG FPP_PROC_DECL_IN_SPEC
747 ;
748 FPP_CATEG : HNAME HLABELSEPARATOR
749 | HVALUE HLABELSEPARATOR
750 | HVAR HLABELSEPARATOR
751 | /*EMPT*/
752 ;
753 FPP_PROC_DECL_IN_SPEC: MBEE_TYPE HPROCEDURE
754 HIDENTIFIER
755 {}
756 FPP_HEADING {} { /* Yes, two "final" actions. */ }
757 ;
758 IDENTIFIER_LISTV: HIDENTIFIER
759 | HDOTDOTDOT
760 | HIDENTIFIER {}
761 HPAREXPSEPARATOR IDENTIFIER_LISTV
762 ;
763 MBEE_MODE_PART : /*EMPT*/
764 | MODE_PART
765 ;
766 MODE_PART : NAME_PART
767 | VALUE_PART
768 | VAR_PART
769 | NAME_PART VALUE_PART
770 | VALUE_PART NAME_PART
771 | NAME_PART VAR_PART
772 | VAR_PART NAME_PART
773 | VALUE_PART VAR_PART
774 | VAR_PART VALUE_PART
775 | VAR_PART NAME_PART VALUE_PART
776 | NAME_PART VAR_PART VALUE_PART
777 | NAME_PART VALUE_PART VAR_PART
778 | VAR_PART VALUE_PART NAME_PART
779 | VALUE_PART VAR_PART NAME_PART
780 | VALUE_PART NAME_PART VAR_PART
781 ;
782 NAME_PART : HNAME {}
783 IDENTIFIER_LISTV
784 HSTATEMENTSEPARATOR
785 ;
786 VAR_PART : HVAR {}
787 IDENTIFIER_LISTV
788 HSTATEMENTSEPARATOR
789 ;
790 VALUE_PART : HVALUE {}
791 IDENTIFIER_LISTV HSTATEMENTSEPARATOR
792 ;
793 MBEE_SPEC_PART : /*EMPT*/
794 | SPEC_PART
795 ;
796 SPEC_PART : ONE_SPEC
797 | SPEC_PART ONE_SPEC
798 ;
799 ONE_SPEC : SPECIFIER IDENTIFIER_LIST HSTATEMENTSEPARATOR
800 | NO_TYPE HPROCEDURE HIDENTIFIER HOBJRELOPERATOR
801 {}
802 PROC_DECL_IN_SPEC HSTATEMENTSEPARATOR
803 | FPP_PROC_DECL_IN_SPEC HSTATEMENTSEPARATOR
804 | MBEE_TYPE HPROCEDURE HIDENTIFIER HSTATEMENTSEPARATOR
805 | MBEE_TYPE HPROCEDURE HIDENTIFIER HPAREXPSEPARATOR
806 IDENTIFIER_LIST HSTATEMENTSEPARATOR
807 ;
808 SPECIFIER : TYPE
809 | MBEE_TYPE
810 HARRAY
811 | HLABEL
812 | HSWITCH
813 ;
814 PROC_DECL_IN_SPEC: MBEE_TYPE HPROCEDURE
815 HIDENTIFIER
816 {}
817 HEADING
818 {}
819 MBEE_BEGIN_END
820 ;
821 MBEE_BEGIN_END : /* EMPTY */
822 | HBEGIN HEND
823 ;
824 MBEE_PROT_PART : /*EMPT*/
825 | PROTECTION_PART
826 ;
827 PROTECTION_PART : PROT_SPECIFIER IDENTIFIER_LIST
828 HSTATEMENTSEPARATOR
829 | PROTECTION_PART PROT_SPECIFIER
830 IDENTIFIER_LIST HSTATEMENTSEPARATOR
831 ;
832 PROT_SPECIFIER : HHIDDEN
833 | HPROTECTED
834 | HHIDDEN
835 HPROTECTED
836 | HPROTECTED
837 HHIDDEN
838 ;
839 MBEE_VIRT_PART : /*EMPT*/
840 | VIRTUAL_PART
841 ;
842 VIRTUAL_PART : HVIRTUAL
843 HLABELSEPARATOR
844 MBEE_SPEC_PART
845 ;
846 IDENTIFIER_LIST : HIDENTIFIER
847 | IDENTIFIER_LIST HPAREXPSEPARATOR
848 HIDENTIFIER
849 ;
850 IDENTIFIER_LISTC: HIDENTIFIER
851 MBEE_CONSTANT
852 | IDENTIFIER_LISTC HPAREXPSEPARATOR
853 HIDENTIFIER
854 MBEE_CONSTANT
855 ;
856 MBEE_CONSTANT : /* EMPTY */
857 | HVALRELOPERATOR
858 {}
859 EXPRESSION
860 ;
861
862 /* GRAMATIKK FOR UTTRYKK */
863 EXPRESSION : EXPRESSION_SIMP
864 | HIF
865 EXPRESSION
866 HTHEN
867 EXPRESSION
868 HELSE
869 EXPRESSION
870 ;
871 EXPRESSION_SIMP : EXPRESSION_SIMP
872 HASSIGN
873 EXPRESSION
874 |
875
876 EXPRESSION_SIMP
877 HCONC
878 EXPRESSION_SIMP
879 | EXPRESSION_SIMP HOR
880 HELSE
881 EXPRESSION_SIMP
882 %prec HORELSE
883 | EXPRESSION_SIMP HAND
884 HTHEN
885 EXPRESSION_SIMP
886 %prec HANDTHEN
887 | EXPRESSION_SIMP
888 HEQV EXPRESSION_SIMP
889 | EXPRESSION_SIMP
890 HIMP EXPRESSION_SIMP
891 | EXPRESSION_SIMP
892 HOR EXPRESSION_SIMP
893 | EXPRESSION_SIMP
894 HAND EXPRESSION_SIMP
895 | HNOT EXPRESSION_SIMP
896 | EXPRESSION_SIMP
897 HVALRELOPERATOR
898 EXPRESSION_SIMP
899 | EXPRESSION_SIMP
900 HREFRELOPERATOR
901 EXPRESSION_SIMP
902 | EXPRESSION_SIMP
903 HOBJRELOPERATOR
904 EXPRESSION_SIMP
905 | HTERMOPERATOR
906 EXPRESSION_SIMP %prec UNEAR
907 | EXPRESSION_SIMP
908 HTERMOPERATOR
909 EXPRESSION_SIMP
910 | EXPRESSION_SIMP
911 HFACTOROPERATOR
912 EXPRESSION_SIMP
913 | EXPRESSION_SIMP
914 HPRIMARYOPERATOR
915 EXPRESSION_SIMP
916 | HBEGPAR
917 EXPRESSION HENDPAR
918 | HTEXTKONST
919 | HCHARACTERKONST
920 | HREALKONST
921 | HINTEGERKONST
922 | HBOOLEANKONST
923 | HNONE
924 | HIDENTIFIER
925 {}
926 MBEE_ARG_R_PT
927 | HTHIS HIDENTIFIER
928 | HNEW
929 HIDENTIFIER
930 ARG_R_PT
931 | EXPRESSION_SIMP
932 HDOT
933 EXPRESSION_SIMP
934 | EXPRESSION_SIMP
935 HQUA HIDENTIFIER
936 ;
937 ARG_R_PT : /*EMPTY*/
938 | HBEGPAR
939 ARGUMENT_LIST HENDPAR
940 ;
941 MBEE_ARG_R_PT : /*EMPTY*/
942 | HBEGPAR
943 ARGUMENT_LIST HENDPAR
944 ;
945 ARGUMENT_LIST : EXPRESSION
946 | EXPRESSION
947 HPAREXPSEPARATOR
948 ARGUMENT_LIST
949 ;
950 %%
951 ]])
952
953 # Pass plenty of options, to exercise plenty of code, even if we
954 # don't actually check the output. But SEGV is watching us, and
955 # so might do dmalloc.
956 AT_BISON_CHECK([[--verbose --defines input.y]], 0, [],
957 [[input.y: conflicts: 78 shift/reduce, 10 reduce/reduce
958 ]])
959
960 AT_CHECK([[grep '^State.*conflicts:' input.output]], 0,
961 [[State 64 conflicts: 14 shift/reduce
962 State 164 conflicts: 1 shift/reduce
963 State 201 conflicts: 33 shift/reduce, 4 reduce/reduce
964 State 206 conflicts: 1 shift/reduce
965 State 240 conflicts: 1 shift/reduce
966 State 335 conflicts: 9 shift/reduce, 2 reduce/reduce
967 State 356 conflicts: 1 shift/reduce
968 State 360 conflicts: 9 shift/reduce, 2 reduce/reduce
969 State 427 conflicts: 9 shift/reduce, 2 reduce/reduce
970 ]])
971
972 AT_CLEANUP
973
974 ## ----------------- ##
975 ## GNU pic Grammar. ##
976 ## ----------------- ##
977
978 AT_SETUP([GNU pic Grammar])
979
980 # GNU pic, part of groff.
981
982 # Bison once reported shift/reduce conflicts that it shouldn't have.
983
984 AT_DATA([[input.y]],
985 [[%union {}
986
987 %token LABEL
988 %token VARIABLE
989 %token NUMBER
990 %token TEXT
991 %token COMMAND_LINE
992 %token DELIMITED
993 %token ORDINAL
994 %token TH
995 %token LEFT_ARROW_HEAD
996 %token RIGHT_ARROW_HEAD
997 %token DOUBLE_ARROW_HEAD
998 %token LAST
999 %token UP
1000 %token DOWN
1001 %token LEFT
1002 %token RIGHT
1003 %token BOX
1004 %token CIRCLE
1005 %token ELLIPSE
1006 %token ARC
1007 %token LINE
1008 %token ARROW
1009 %token MOVE
1010 %token SPLINE
1011 %token HEIGHT
1012 %token RADIUS
1013 %token WIDTH
1014 %token DIAMETER
1015 %token FROM
1016 %token TO
1017 %token AT
1018 %token WITH
1019 %token BY
1020 %token THEN
1021 %token SOLID
1022 %token DOTTED
1023 %token DASHED
1024 %token CHOP
1025 %token SAME
1026 %token INVISIBLE
1027 %token LJUST
1028 %token RJUST
1029 %token ABOVE
1030 %token BELOW
1031 %token OF
1032 %token THE
1033 %token WAY
1034 %token BETWEEN
1035 %token AND
1036 %token HERE
1037 %token DOT_N
1038 %token DOT_E
1039 %token DOT_W
1040 %token DOT_S
1041 %token DOT_NE
1042 %token DOT_SE
1043 %token DOT_NW
1044 %token DOT_SW
1045 %token DOT_C
1046 %token DOT_START
1047 %token DOT_END
1048 %token DOT_X
1049 %token DOT_Y
1050 %token DOT_HT
1051 %token DOT_WID
1052 %token DOT_RAD
1053 %token SIN
1054 %token COS
1055 %token ATAN2
1056 %token LOG
1057 %token EXP
1058 %token SQRT
1059 %token K_MAX
1060 %token K_MIN
1061 %token INT
1062 %token RAND
1063 %token SRAND
1064 %token COPY
1065 %token THRU
1066 %token TOP
1067 %token BOTTOM
1068 %token UPPER
1069 %token LOWER
1070 %token SH
1071 %token PRINT
1072 %token CW
1073 %token CCW
1074 %token FOR
1075 %token DO
1076 %token IF
1077 %token ELSE
1078 %token ANDAND
1079 %token OROR
1080 %token NOTEQUAL
1081 %token EQUALEQUAL
1082 %token LESSEQUAL
1083 %token GREATEREQUAL
1084 %token LEFT_CORNER
1085 %token RIGHT_CORNER
1086 %token NORTH
1087 %token SOUTH
1088 %token EAST
1089 %token WEST
1090 %token CENTER
1091 %token END
1092 %token START
1093 %token RESET
1094 %token UNTIL
1095 %token PLOT
1096 %token THICKNESS
1097 %token FILL
1098 %token COLORED
1099 %token OUTLINED
1100 %token SHADED
1101 %token ALIGNED
1102 %token SPRINTF
1103 %token COMMAND
1104
1105 %left '.'
1106
1107 /* this ensures that plot 17 "%g" parses as (plot 17 "%g") */
1108 %left PLOT
1109 %left TEXT SPRINTF
1110
1111 /* give text adjustments higher precedence than TEXT, so that
1112 box "foo" above ljust == box ("foo" above ljust)
1113 */
1114
1115 %left LJUST RJUST ABOVE BELOW
1116
1117 %left LEFT RIGHT
1118 /* Give attributes that take an optional expression a higher
1119 precedence than left and right, so that eg `line chop left'
1120 parses properly. */
1121 %left CHOP SOLID DASHED DOTTED UP DOWN FILL COLORED OUTLINED
1122 %left LABEL
1123
1124 %left VARIABLE NUMBER '(' SIN COS ATAN2 LOG EXP SQRT K_MAX K_MIN INT RAND SRAND LAST
1125 %left ORDINAL HERE '`'
1126
1127 %left BOX CIRCLE ELLIPSE ARC LINE ARROW SPLINE '[' /* ] */
1128
1129 /* these need to be lower than '-' */
1130 %left HEIGHT RADIUS WIDTH DIAMETER FROM TO AT THICKNESS
1131
1132 /* these must have higher precedence than CHOP so that `label %prec CHOP'
1133 works */
1134 %left DOT_N DOT_E DOT_W DOT_S DOT_NE DOT_SE DOT_NW DOT_SW DOT_C
1135 %left DOT_START DOT_END TOP BOTTOM LEFT_CORNER RIGHT_CORNER
1136 %left UPPER LOWER NORTH SOUTH EAST WEST CENTER START END
1137
1138 %left ','
1139 %left OROR
1140 %left ANDAND
1141 %left EQUALEQUAL NOTEQUAL
1142 %left '<' '>' LESSEQUAL GREATEREQUAL
1143
1144 %left BETWEEN OF
1145 %left AND
1146
1147 %left '+' '-'
1148 %left '*' '/' '%'
1149 %right '!'
1150 %right '^'
1151
1152 %%
1153
1154 top:
1155 optional_separator
1156 | element_list
1157 ;
1158
1159 element_list:
1160 optional_separator middle_element_list optional_separator
1161 ;
1162
1163 middle_element_list:
1164 element
1165 | middle_element_list separator element
1166 ;
1167
1168 optional_separator:
1169 /* empty */
1170 | separator
1171 ;
1172
1173 separator:
1174 ';'
1175 | separator ';'
1176 ;
1177
1178 placeless_element:
1179 VARIABLE '=' any_expr
1180 | VARIABLE ':' '=' any_expr
1181 | UP
1182 | DOWN
1183 | LEFT
1184 | RIGHT
1185 | COMMAND_LINE
1186 | COMMAND print_args
1187 | PRINT print_args
1188 | SH
1189 {}
1190 DELIMITED
1191 | COPY TEXT
1192 | COPY TEXT THRU
1193 {}
1194 DELIMITED
1195 {}
1196 until
1197 | COPY THRU
1198 {}
1199 DELIMITED
1200 {}
1201 until
1202 | FOR VARIABLE '=' expr TO expr optional_by DO
1203 {}
1204 DELIMITED
1205 | simple_if
1206 | simple_if ELSE
1207 {}
1208 DELIMITED
1209 | reset_variables
1210 | RESET
1211 ;
1212
1213 reset_variables:
1214 RESET VARIABLE
1215 | reset_variables VARIABLE
1216 | reset_variables ',' VARIABLE
1217 ;
1218
1219 print_args:
1220 print_arg
1221 | print_args print_arg
1222 ;
1223
1224 print_arg:
1225 expr %prec ','
1226 | text
1227 | position %prec ','
1228 ;
1229
1230 simple_if:
1231 IF any_expr THEN
1232 {}
1233 DELIMITED
1234 ;
1235
1236 until:
1237 /* empty */
1238 | UNTIL TEXT
1239 ;
1240
1241 any_expr:
1242 expr
1243 | text_expr
1244 ;
1245
1246 text_expr:
1247 text EQUALEQUAL text
1248 | text NOTEQUAL text
1249 | text_expr ANDAND text_expr
1250 | text_expr ANDAND expr
1251 | expr ANDAND text_expr
1252 | text_expr OROR text_expr
1253 | text_expr OROR expr
1254 | expr OROR text_expr
1255 | '!' text_expr
1256 ;
1257
1258 optional_by:
1259 /* empty */
1260 | BY expr
1261 | BY '*' expr
1262 ;
1263
1264 element:
1265 object_spec
1266 | LABEL ':' optional_separator element
1267 | LABEL ':' optional_separator position_not_place
1268 | LABEL ':' optional_separator place
1269 | '{' {} element_list '}'
1270 {}
1271 optional_element
1272 | placeless_element
1273 ;
1274
1275 optional_element:
1276 /* empty */
1277 | element
1278 ;
1279
1280 object_spec:
1281 BOX
1282 | CIRCLE
1283 | ELLIPSE
1284 | ARC
1285 | LINE
1286 | ARROW
1287 | MOVE
1288 | SPLINE
1289 | text %prec TEXT
1290 | PLOT expr
1291 | PLOT expr text
1292 | '['
1293 {}
1294 element_list ']'
1295 | object_spec HEIGHT expr
1296 | object_spec RADIUS expr
1297 | object_spec WIDTH expr
1298 | object_spec DIAMETER expr
1299 | object_spec expr %prec HEIGHT
1300 | object_spec UP
1301 | object_spec UP expr
1302 | object_spec DOWN
1303 | object_spec DOWN expr
1304 | object_spec RIGHT
1305 | object_spec RIGHT expr
1306 | object_spec LEFT
1307 | object_spec LEFT expr
1308 | object_spec FROM position
1309 | object_spec TO position
1310 | object_spec AT position
1311 | object_spec WITH path
1312 | object_spec WITH position %prec ','
1313 | object_spec BY expr_pair
1314 | object_spec THEN
1315 | object_spec SOLID
1316 | object_spec DOTTED
1317 | object_spec DOTTED expr
1318 | object_spec DASHED
1319 | object_spec DASHED expr
1320 | object_spec FILL
1321 | object_spec FILL expr
1322 | object_spec SHADED text
1323 | object_spec COLORED text
1324 | object_spec OUTLINED text
1325 | object_spec CHOP
1326 | object_spec CHOP expr
1327 | object_spec SAME
1328 | object_spec INVISIBLE
1329 | object_spec LEFT_ARROW_HEAD
1330 | object_spec RIGHT_ARROW_HEAD
1331 | object_spec DOUBLE_ARROW_HEAD
1332 | object_spec CW
1333 | object_spec CCW
1334 | object_spec text %prec TEXT
1335 | object_spec LJUST
1336 | object_spec RJUST
1337 | object_spec ABOVE
1338 | object_spec BELOW
1339 | object_spec THICKNESS expr
1340 | object_spec ALIGNED
1341 ;
1342
1343 text:
1344 TEXT
1345 | SPRINTF '(' TEXT sprintf_args ')'
1346 ;
1347
1348 sprintf_args:
1349 /* empty */
1350 | sprintf_args ',' expr
1351 ;
1352
1353 position:
1354 position_not_place
1355 | place
1356 ;
1357
1358 position_not_place:
1359 expr_pair
1360 | position '+' expr_pair
1361 | position '-' expr_pair
1362 | '(' position ',' position ')'
1363 | expr between position AND position
1364 | expr '<' position ',' position '>'
1365 ;
1366
1367 between:
1368 BETWEEN
1369 | OF THE WAY BETWEEN
1370 ;
1371
1372 expr_pair:
1373 expr ',' expr
1374 | '(' expr_pair ')'
1375 ;
1376
1377 place:
1378 /* line at A left == line (at A) left */
1379 label %prec CHOP
1380 | label corner
1381 | corner label
1382 | corner OF label
1383 | HERE
1384 ;
1385
1386 label:
1387 LABEL
1388 | nth_primitive
1389 | label '.' LABEL
1390 ;
1391
1392 ordinal:
1393 ORDINAL
1394 | '`' any_expr TH
1395 ;
1396
1397 optional_ordinal_last:
1398 LAST
1399 | ordinal LAST
1400 ;
1401
1402 nth_primitive:
1403 ordinal object_type
1404 | optional_ordinal_last object_type
1405 ;
1406
1407 object_type:
1408 BOX
1409 | CIRCLE
1410 | ELLIPSE
1411 | ARC
1412 | LINE
1413 | ARROW
1414 | SPLINE
1415 | '[' ']'
1416 | TEXT
1417 ;
1418
1419 label_path:
1420 '.' LABEL
1421 | label_path '.' LABEL
1422 ;
1423
1424 relative_path:
1425 corner %prec CHOP
1426 /* give this a lower precedence than LEFT and RIGHT so that
1427 [A: box] with .A left == [A: box] with (.A left) */
1428 | label_path %prec TEXT
1429 | label_path corner
1430 ;
1431
1432 path:
1433 relative_path
1434 | '(' relative_path ',' relative_path ')'
1435 {}
1436 /* The rest of these rules are a compatibility sop. */
1437 | ORDINAL LAST object_type relative_path
1438 | LAST object_type relative_path
1439 | ORDINAL object_type relative_path
1440 | LABEL relative_path
1441 ;
1442
1443 corner:
1444 DOT_N
1445 | DOT_E
1446 | DOT_W
1447 | DOT_S
1448 | DOT_NE
1449 | DOT_SE
1450 | DOT_NW
1451 | DOT_SW
1452 | DOT_C
1453 | DOT_START
1454 | DOT_END
1455 | TOP
1456 | BOTTOM
1457 | LEFT
1458 | RIGHT
1459 | UPPER LEFT
1460 | LOWER LEFT
1461 | UPPER RIGHT
1462 | LOWER RIGHT
1463 | LEFT_CORNER
1464 | RIGHT_CORNER
1465 | UPPER LEFT_CORNER
1466 | LOWER LEFT_CORNER
1467 | UPPER RIGHT_CORNER
1468 | LOWER RIGHT_CORNER
1469 | NORTH
1470 | SOUTH
1471 | EAST
1472 | WEST
1473 | CENTER
1474 | START
1475 | END
1476 ;
1477
1478 expr:
1479 VARIABLE
1480 | NUMBER
1481 | place DOT_X
1482 | place DOT_Y
1483 | place DOT_HT
1484 | place DOT_WID
1485 | place DOT_RAD
1486 | expr '+' expr
1487 | expr '-' expr
1488 | expr '*' expr
1489 | expr '/' expr
1490 | expr '%' expr
1491 | expr '^' expr
1492 | '-' expr %prec '!'
1493 | '(' any_expr ')'
1494 | SIN '(' any_expr ')'
1495 | COS '(' any_expr ')'
1496 | ATAN2 '(' any_expr ',' any_expr ')'
1497 | LOG '(' any_expr ')'
1498 | EXP '(' any_expr ')'
1499 | SQRT '(' any_expr ')'
1500 | K_MAX '(' any_expr ',' any_expr ')'
1501 | K_MIN '(' any_expr ',' any_expr ')'
1502 | INT '(' any_expr ')'
1503 | RAND '(' any_expr ')'
1504 | RAND '(' ')'
1505 | SRAND '(' any_expr ')'
1506 | expr '<' expr
1507 | expr LESSEQUAL expr
1508 | expr '>' expr
1509 | expr GREATEREQUAL expr
1510 | expr EQUALEQUAL expr
1511 | expr NOTEQUAL expr
1512 | expr ANDAND expr
1513 | expr OROR expr
1514 | '!' expr
1515 ;
1516 ]])
1517
1518 # Pass plenty of options, to exercise plenty of code, even if we
1519 # don't actually check the output. But SEGV is watching us, and
1520 # so might do dmalloc.
1521 AT_BISON_CHECK([[--verbose --defines input.y]], 0, [],
1522 [[input.y:453.11-48: warning: rule useless in parser due to conflicts: path: ORDINAL LAST object_type relative_path
1523 ]])
1524
1525 AT_CLEANUP