1 # Exercising Bison on actual grammars. -*- Autotest -*-
3 # Copyright (C) 1989, 1990, 1991, 1992, 2000, 2001, 2002, 2003, 2004, 2005,
4 # 2007 Free Software Foundation, Inc.
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.
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.
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/>.
19 AT_BANNER([[Existing Grammars.]])
20 ## ----------------- ##
21 ## GNU AWK Grammar. ##
22 ## ----------------- ##
24 AT_SETUP([GNU AWK Grammar])
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.
30 # Bison was once wrong, due to an incorrect computation of nullable.
31 # It reported 485 SR conflicts!
36 %token FUNC_CALL NAME REGEXP
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
46 %token LEX_AND LEX_OR INCREMENT DECREMENT
47 %token LEX_BUILTIN LEX_LENGTH
49 /* Lowest to highest */
56 %left FUNC_CALL LEX_BUILTIN LEX_LENGTH
59 %nonassoc RELOP '<' '>' '|' APPEND_OP TWOWAYIO
66 %left INCREMENT DECREMENT
72 : opt_nls program opt_nls
86 | LEX_BEGIN statement_term
87 | LEX_END statement_term
90 | pattern statement_term
91 | function_prologue function_body
106 : LEX_FUNCTION {} func_name '(' opt_param_list r_paren opt_nls
110 : l_brace statements r_brace opt_semi opt_nls
111 | l_brace r_brace opt_semi opt_nls
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.
128 : l_brace statements r_brace opt_semi opt_nls
129 | l_brace r_brace opt_semi opt_nls
134 | statements statement
147 | l_brace statements r_brace
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
173 : LEX_IF '(' exp r_paren opt_nls statement
174 | LEX_IF '(' exp r_paren opt_nls statement
175 LEX_ELSE opt_nls statement
208 | param_list comma NAME
211 | param_list comma error
214 /* optional expression, as in for loop */
227 | rexpression_list comma rexp
229 | rexpression_list error
230 | rexpression_list error rexp
231 | rexpression_list comma error
241 | expression_list comma exp
243 | expression_list error
244 | expression_list error exp
245 | expression_list comma error
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
258 | '!' regexp %prec UNARY
263 | exp '?' exp ':' exp
265 | exp simp_exp %prec CONCAT_OP
269 : variable ASSIGNOP {} rexp
272 | LEX_GETLINE opt_variable input_redir
274 | '!' regexp %prec UNARY
278 | rexp '?' rexp ':' rexp
280 | rexp simp_exp %prec CONCAT_OP
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
297 : '!' simp_exp %prec UNARY
300 '(' opt_expression_list r_paren
301 | LEX_LENGTH '(' opt_expression_list r_paren
303 | FUNC_CALL '(' opt_expression_list r_paren
309 | '-' simp_exp %prec UNARY
310 | '+' simp_exp %prec UNARY
320 | NAME '[' expression_list ']'
321 | '$' non_post_simp_exp
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]])
358 ## ----------------- ##
359 ## GNU Cim Grammar. ##
360 ## ----------------- ##
362 AT_SETUP([GNU Cim Grammar])
364 # GNU Cim, the GNU Simula 87 Compiler.
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!!!
373 HACTIVATE HAFTER /*HAND*/ HARRAY HAT
374 HBEFORE HBEGIN HBOOLEAN
375 HCHARACTER HCLASS /*HCOMMENT*/ HCONC
377 HELSE HEND HEQ /*HEQV*/ HEXTERNAL
381 HIF /*HIMP*/ HIN HINNER HINSPECT HINTEGER HIS
383 HNAME HNE HNEW HNONE /*HNOT*/ HNOTEXT
385 HPRIOR HPROCEDURE HPROTECTED
387 HREACTIVATE HREAL HREF
389 HTEXT HTHEN HTHIS HTO
394 HASSIGNVALUE HASSIGNREF
395 /*HDOT*/ HPAREXPSEPARATOR HLABELSEPARATOR HSTATEMENTSEPARATOR
398 HADD HSUB HMUL HDIV HINTDIV HEXP
402 %token HBOOLEANKONST HINTEGERKONST HCHARACTERKONST
417 %left HVALRELOPERATOR HREFRELOPERATOR HOBJRELOPERATOR
423 %left HFACTOROPERATOR
424 %left HPRIMARYOPERATOR
432 /* GRAMATIKK FOR PROGRAM MODULES */
435 | error HSTATEMENTSEPARATOR MBEE_DECLSTMS
437 EXT_DECLARATION : HEXTERNAL
455 EXTERNAL_KIND_ITEM: EXT_IDENT
468 MBEE_REST_EXT_LIST: /* EMPTY
469 | HPAREXPSEPARATOR EXT_KIND_LIST
471 EXT_KIND_LIST : EXT_KIND_ITEM
472 | EXT_KIND_LIST HPAREXPSEPARATOR EXT_KIND_ITEM
474 EXT_KIND_ITEM : HIDENTIFIER
478 EMPTY_BLOCK : /*EMPT*/
482 | EXT_LIST HPAREXPSEPARATOR EXT_ITEM
484 EXT_ITEM : HIDENTIFIER
487 EXT_IDENT : /* EMPTY */
491 /* GRAMATIKK FOR TYPER */
510 /* GRAMATIKK FOR DEL AV SETNINGER */
511 MBEE_ELSE_PART : /*EMPT*/
521 FOR_LIST : FOR_LIST_ELEMENT
526 FOR_LIST_ELEMENT: EXPRESSION
529 MBEE_F_L_EL_R_PT: /*EMPT*/
541 CONN_STATE_R_PT : WHEN_CLAUSE_LIST
545 WHEN_CLAUSE_LIST: HWHEN
555 MBEE_OTWI_CLAUS : /*EMPT*/
560 ACTIVATOR : HACTIVATE
564 | ATDELAY EXPRESSION {}
572 BEFOREAFTER : HBEFORE
578 /* GRAMATIKK FOR SETNINGER OG DEKLARASJONER */
579 MODULSTATEMENT : HWHILE
613 | EXPRESSION_SIMP HBEGIN error HSTATEMENTSEPARATOR
615 | EXPRESSION_SIMP HBEGIN error HEND
617 | ACTIVATOR EXPRESSION SCHEDULE
622 | MBEE_TYPE HPROCEDURE
646 DECLSTATEMENT : MODULSTATEMENT
664 BLOCK : DECLSTATEMENT
665 | HBEGIN MBEE_DECLSTMS HEND
666 | HBEGIN error HSTATEMENTSEPARATOR MBEE_DECLSTMS HEND
669 MBEE_DECLSTMS : MBEE_DECLSTMSU
671 MBEE_DECLSTMSU : DECLSTATEMENT
676 MODULS : MODULSTATEMENT
677 | MODULS HSTATEMENTSEPARATOR MODULSTATEMENT
679 /* GRAMATIKK FOR DEL AV DEKLARASJONER */
680 ARR_SEGMENT_LIST: ARR_SEGMENT
685 ARR_SEGMENT : ARRAY_SEGMENT
687 BAUND_PAIR_LIST HENDPAR
689 ARRAY_SEGMENT : ARRAY_SEGMENT_EL {}
695 ARRAY_SEGMENT_EL: HIDENTIFIER
697 BAUND_PAIR_LIST : BAUND_PAIR
702 BAUND_PAIR : EXPRESSION
706 SWITCH_LIST : EXPRESSION
711 HEADING : MBEE_FMAL_PAR_P HSTATEMENTSEPARATOR {}
717 MBEE_FMAL_PAR_P : /*EMPT*/
720 FMAL_PAR_PART : HBEGPAR NO_TYPE
723 MBEE_LISTV : /*EMPT*/
727 | FPP_CATEG HDOTDOTDOT
729 HPAREXPSEPARATOR LISTV
732 HPAREXPSEPARATOR LISTV
734 FPP_HEADING : HBEGPAR NO_TYPE
735 FPP_MBEE_LISTV HENDPAR
737 FPP_MBEE_LISTV : /*EMPT*/
740 FPP_LISTV : FPP_CATEG HDOTDOTDOT
743 HPAREXPSEPARATOR LISTV
745 FPP_SPEC : FPP_CATEG SPECIFIER HIDENTIFIER
746 | FPP_CATEG FPP_PROC_DECL_IN_SPEC
748 FPP_CATEG : HNAME HLABELSEPARATOR
749 | HVALUE HLABELSEPARATOR
750 | HVAR HLABELSEPARATOR
753 FPP_PROC_DECL_IN_SPEC: MBEE_TYPE HPROCEDURE
756 FPP_HEADING {} { /* Yes, two "final" actions. */ }
758 IDENTIFIER_LISTV: HIDENTIFIER
761 HPAREXPSEPARATOR IDENTIFIER_LISTV
763 MBEE_MODE_PART : /*EMPT*/
766 MODE_PART : NAME_PART
769 | NAME_PART VALUE_PART
770 | VALUE_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
790 VALUE_PART : HVALUE {}
791 IDENTIFIER_LISTV HSTATEMENTSEPARATOR
793 MBEE_SPEC_PART : /*EMPT*/
799 ONE_SPEC : SPECIFIER IDENTIFIER_LIST HSTATEMENTSEPARATOR
800 | NO_TYPE HPROCEDURE HIDENTIFIER HOBJRELOPERATOR
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
814 PROC_DECL_IN_SPEC: MBEE_TYPE HPROCEDURE
821 MBEE_BEGIN_END : /* EMPTY */
824 MBEE_PROT_PART : /*EMPT*/
827 PROTECTION_PART : PROT_SPECIFIER IDENTIFIER_LIST
829 | PROTECTION_PART PROT_SPECIFIER
830 IDENTIFIER_LIST HSTATEMENTSEPARATOR
832 PROT_SPECIFIER : HHIDDEN
839 MBEE_VIRT_PART : /*EMPT*/
842 VIRTUAL_PART : HVIRTUAL
846 IDENTIFIER_LIST : HIDENTIFIER
847 | IDENTIFIER_LIST HPAREXPSEPARATOR
850 IDENTIFIER_LISTC: HIDENTIFIER
852 | IDENTIFIER_LISTC HPAREXPSEPARATOR
856 MBEE_CONSTANT : /* EMPTY */
862 /* GRAMATIKK FOR UTTRYKK */
863 EXPRESSION : EXPRESSION_SIMP
871 EXPRESSION_SIMP : EXPRESSION_SIMP
879 | EXPRESSION_SIMP HOR
883 | EXPRESSION_SIMP HAND
895 | HNOT EXPRESSION_SIMP
906 EXPRESSION_SIMP %prec UNEAR
939 ARGUMENT_LIST HENDPAR
941 MBEE_ARG_R_PT : /*EMPTY*/
943 ARGUMENT_LIST HENDPAR
945 ARGUMENT_LIST : EXPRESSION
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
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
974 ## ----------------- ##
975 ## GNU pic Grammar. ##
976 ## ----------------- ##
978 AT_SETUP([GNU pic Grammar])
980 # GNU pic, part of groff.
982 # Bison once reported shift/reduce conflicts that it shouldn't have.
995 %token LEFT_ARROW_HEAD
996 %token RIGHT_ARROW_HEAD
997 %token DOUBLE_ARROW_HEAD
1107 /* this ensures that plot 17 "%g" parses as (plot 17 "%g") */
1111 /* give text adjustments higher precedence than TEXT, so that
1112 box "foo" above ljust == box ("foo" above ljust)
1115 %left LJUST RJUST ABOVE BELOW
1118 /* Give attributes that take an optional expression a higher
1119 precedence than left and right, so that eg `line chop left'
1121 %left CHOP SOLID DASHED DOTTED UP DOWN FILL COLORED OUTLINED
1124 %left VARIABLE NUMBER '(' SIN COS ATAN2 LOG EXP SQRT K_MAX K_MIN INT RAND SRAND LAST
1125 %left ORDINAL HERE '`'
1127 %left BOX CIRCLE ELLIPSE ARC LINE ARROW SPLINE '[' /* ] */
1129 /* these need to be lower than '-' */
1130 %left HEIGHT RADIUS WIDTH DIAMETER FROM TO AT THICKNESS
1132 /* these must have higher precedence than CHOP so that `label %prec CHOP'
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
1141 %left EQUALEQUAL NOTEQUAL
1142 %left '<' '>' LESSEQUAL GREATEREQUAL
1160 optional_separator middle_element_list optional_separator
1163 middle_element_list:
1165 | middle_element_list separator element
1179 VARIABLE '=' any_expr
1180 | VARIABLE ':' '=' any_expr
1186 | COMMAND print_args
1202 | FOR VARIABLE '=' expr TO expr optional_by DO
1215 | reset_variables VARIABLE
1216 | reset_variables ',' VARIABLE
1221 | print_args print_arg
1227 | position %prec ','
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
1266 | LABEL ':' optional_separator element
1267 | LABEL ':' optional_separator position_not_place
1268 | LABEL ':' optional_separator place
1269 | '{' {} 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
1301 | object_spec UP expr
1303 | object_spec DOWN expr
1305 | object_spec RIGHT expr
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
1316 | object_spec DOTTED
1317 | object_spec DOTTED expr
1318 | object_spec DASHED
1319 | object_spec DASHED expr
1321 | object_spec FILL expr
1322 | object_spec SHADED text
1323 | object_spec COLORED text
1324 | object_spec OUTLINED text
1326 | object_spec CHOP expr
1328 | object_spec INVISIBLE
1329 | object_spec LEFT_ARROW_HEAD
1330 | object_spec RIGHT_ARROW_HEAD
1331 | object_spec DOUBLE_ARROW_HEAD
1334 | object_spec text %prec TEXT
1339 | object_spec THICKNESS expr
1340 | object_spec ALIGNED
1345 | SPRINTF '(' TEXT sprintf_args ')'
1350 | sprintf_args ',' expr
1360 | position '+' expr_pair
1361 | position '-' expr_pair
1362 | '(' position ',' position ')'
1363 | expr between position AND position
1364 | expr '<' position ',' position '>'
1369 | OF THE WAY BETWEEN
1378 /* line at A left == line (at A) left */
1397 optional_ordinal_last:
1404 | optional_ordinal_last object_type
1421 | label_path '.' LABEL
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
1434 | '(' relative_path ',' relative_path ')'
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
1467 | UPPER RIGHT_CORNER
1468 | LOWER RIGHT_CORNER
1492 | '-' expr %prec '!'
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 ')'
1505 | SRAND '(' any_expr ')'
1507 | expr LESSEQUAL expr
1509 | expr GREATEREQUAL expr
1510 | expr EQUALEQUAL expr
1511 | expr NOTEQUAL expr
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