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 2, or (at your option)
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, write to the Free Software
18 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
21 AT_BANNER([[Existing Grammars.]])
22 ## ----------------- ##
23 ## GNU AWK Grammar. ##
24 ## ----------------- ##
26 AT_SETUP([GNU AWK Grammar])
28 # We have been careful to strip all the actions excepts the
29 # mid-rule actions. We rely on %expect to check that there are
30 # indeed 65 SR conflicts.
32 # Bison was once wrong, due to an incorrect computation of nullable.
33 # It reported 485 SR conflicts!
38 %token FUNC_CALL NAME REGEXP
40 %token YNUMBER YSTRING
41 %token RELOP APPEND_OP
42 %token ASSIGNOP MATCHOP NEWLINE CONCAT_OP
43 %token LEX_BEGIN LEX_END LEX_IF LEX_ELSE LEX_RETURN LEX_DELETE
44 %token LEX_WHILE LEX_DO LEX_FOR LEX_BREAK LEX_CONTINUE
45 %token LEX_PRINT LEX_PRINTF LEX_NEXT LEX_EXIT LEX_FUNCTION
46 %token LEX_GETLINE LEX_NEXTFILE
48 %token LEX_AND LEX_OR INCREMENT DECREMENT
49 %token LEX_BUILTIN LEX_LENGTH
51 /* Lowest to highest */
58 %left FUNC_CALL LEX_BUILTIN LEX_LENGTH
61 %nonassoc RELOP '<' '>' '|' APPEND_OP TWOWAYIO
68 %left INCREMENT DECREMENT
74 : opt_nls program opt_nls
88 | LEX_BEGIN statement_term
89 | LEX_END statement_term
92 | pattern statement_term
93 | function_prologue function_body
108 : LEX_FUNCTION {} func_name '(' opt_param_list r_paren opt_nls
112 : l_brace statements r_brace opt_semi opt_nls
113 | l_brace r_brace opt_semi opt_nls
123 * In this rule, want_regexp tells yylex that the next thing
124 * is a regexp so it should read up to the closing slash.
130 : l_brace statements r_brace opt_semi opt_nls
131 | l_brace r_brace opt_semi opt_nls
136 | statements statement
149 | l_brace statements r_brace
151 | LEX_WHILE '(' exp r_paren opt_nls statement
152 | LEX_DO opt_nls statement LEX_WHILE '(' exp r_paren opt_nls
153 | LEX_FOR '(' NAME LEX_IN NAME r_paren opt_nls statement
154 | LEX_FOR '(' opt_exp semi opt_nls exp semi opt_nls opt_exp r_paren opt_nls statement
155 | LEX_FOR '(' opt_exp semi opt_nls semi opt_nls opt_exp r_paren opt_nls statement
156 | LEX_BREAK statement_term
157 | LEX_CONTINUE statement_term
158 | print '(' expression_list r_paren output_redir statement_term
159 | print opt_rexpression_list output_redir statement_term
160 | LEX_NEXT statement_term
161 | LEX_NEXTFILE statement_term
162 | LEX_EXIT opt_exp statement_term
163 | LEX_RETURN {} opt_exp statement_term
164 | LEX_DELETE NAME '[' expression_list ']' statement_term
165 | LEX_DELETE NAME statement_term
175 : LEX_IF '(' exp r_paren opt_nls statement
176 | LEX_IF '(' exp r_paren opt_nls statement
177 LEX_ELSE opt_nls statement
210 | param_list comma NAME
213 | param_list comma error
216 /* optional expression, as in for loop */
229 | rexpression_list comma rexp
231 | rexpression_list error
232 | rexpression_list error rexp
233 | rexpression_list comma error
243 | expression_list comma exp
245 | expression_list error
246 | expression_list error exp
247 | expression_list comma error
250 /* Expressions, not including the comma operator. */
251 exp : variable ASSIGNOP {} exp
252 | '(' expression_list r_paren LEX_IN NAME
253 | exp '|' LEX_GETLINE opt_variable
254 | exp TWOWAYIO LEX_GETLINE opt_variable
255 | LEX_GETLINE opt_variable input_redir
260 | '!' regexp %prec UNARY
265 | exp '?' exp ':' exp
267 | exp simp_exp %prec CONCAT_OP
271 : variable ASSIGNOP {} rexp
274 | LEX_GETLINE opt_variable input_redir
276 | '!' regexp %prec UNARY
280 | rexp '?' rexp ':' rexp
282 | rexp simp_exp %prec CONCAT_OP
287 /* Binary operators in order of decreasing precedence. */
288 | simp_exp '^' simp_exp
289 | simp_exp '*' simp_exp
290 | simp_exp '/' simp_exp
291 | simp_exp '%' simp_exp
292 | simp_exp '+' simp_exp
293 | simp_exp '-' simp_exp
299 : '!' simp_exp %prec UNARY
302 '(' opt_expression_list r_paren
303 | LEX_LENGTH '(' opt_expression_list r_paren
305 | FUNC_CALL '(' opt_expression_list r_paren
311 | '-' simp_exp %prec UNARY
312 | '+' simp_exp %prec UNARY
322 | NAME '[' expression_list ']'
323 | '$' non_post_simp_exp
353 # Pass plenty of options, to exercise plenty of code, even if we
354 # don't actually check the output. But SEGV is watching us, and
355 # so might do dmalloc.
356 AT_CHECK([[bison --verbose --defines input.y]])
360 ## ----------------- ##
361 ## GNU Cim Grammar. ##
362 ## ----------------- ##
364 AT_SETUP([GNU Cim Grammar])
366 # GNU Cim, the GNU Simula 87 Compiler.
368 # Bison was once wrong, due to an incorrect computation of the RR conflicts.
369 # It reported 80 SR && 99 RR conflicts instead of 78/10!!!
375 HACTIVATE HAFTER /*HAND*/ HARRAY HAT
376 HBEFORE HBEGIN HBOOLEAN
377 HCHARACTER HCLASS /*HCOMMENT*/ HCONC
379 HELSE HEND HEQ /*HEQV*/ HEXTERNAL
383 HIF /*HIMP*/ HIN HINNER HINSPECT HINTEGER HIS
385 HNAME HNE HNEW HNONE /*HNOT*/ HNOTEXT
387 HPRIOR HPROCEDURE HPROTECTED
389 HREACTIVATE HREAL HREF
391 HTEXT HTHEN HTHIS HTO
396 HASSIGNVALUE HASSIGNREF
397 /*HDOT*/ HPAREXPSEPARATOR HLABELSEPARATOR HSTATEMENTSEPARATOR
400 HADD HSUB HMUL HDIV HINTDIV HEXP
404 %token HBOOLEANKONST HINTEGERKONST HCHARACTERKONST
419 %left HVALRELOPERATOR HREFRELOPERATOR HOBJRELOPERATOR
425 %left HFACTOROPERATOR
426 %left HPRIMARYOPERATOR
434 /* GRAMATIKK FOR PROGRAM MODULES */
437 | error HSTATEMENTSEPARATOR MBEE_DECLSTMS
439 EXT_DECLARATION : HEXTERNAL
457 EXTERNAL_KIND_ITEM: EXT_IDENT
470 MBEE_REST_EXT_LIST: /* EMPTY
471 | HPAREXPSEPARATOR EXT_KIND_LIST
473 EXT_KIND_LIST : EXT_KIND_ITEM
474 | EXT_KIND_LIST HPAREXPSEPARATOR EXT_KIND_ITEM
476 EXT_KIND_ITEM : HIDENTIFIER
480 EMPTY_BLOCK : /*EMPT*/
484 | EXT_LIST HPAREXPSEPARATOR EXT_ITEM
486 EXT_ITEM : HIDENTIFIER
489 EXT_IDENT : /* EMPTY */
493 /* GRAMATIKK FOR TYPER */
512 /* GRAMATIKK FOR DEL AV SETNINGER */
513 MBEE_ELSE_PART : /*EMPT*/
523 FOR_LIST : FOR_LIST_ELEMENT
528 FOR_LIST_ELEMENT: EXPRESSION
531 MBEE_F_L_EL_R_PT: /*EMPT*/
543 CONN_STATE_R_PT : WHEN_CLAUSE_LIST
547 WHEN_CLAUSE_LIST: HWHEN
557 MBEE_OTWI_CLAUS : /*EMPT*/
562 ACTIVATOR : HACTIVATE
566 | ATDELAY EXPRESSION {}
574 BEFOREAFTER : HBEFORE
580 /* GRAMATIKK FOR SETNINGER OG DEKLARASJONER */
581 MODULSTATEMENT : HWHILE
615 | EXPRESSION_SIMP HBEGIN error HSTATEMENTSEPARATOR
617 | EXPRESSION_SIMP HBEGIN error HEND
619 | ACTIVATOR EXPRESSION SCHEDULE
624 | MBEE_TYPE HPROCEDURE
648 DECLSTATEMENT : MODULSTATEMENT
666 BLOCK : DECLSTATEMENT
667 | HBEGIN MBEE_DECLSTMS HEND
668 | HBEGIN error HSTATEMENTSEPARATOR MBEE_DECLSTMS HEND
671 MBEE_DECLSTMS : MBEE_DECLSTMSU
673 MBEE_DECLSTMSU : DECLSTATEMENT
678 MODULS : MODULSTATEMENT
679 | MODULS HSTATEMENTSEPARATOR MODULSTATEMENT
681 /* GRAMATIKK FOR DEL AV DEKLARASJONER */
682 ARR_SEGMENT_LIST: ARR_SEGMENT
687 ARR_SEGMENT : ARRAY_SEGMENT
689 BAUND_PAIR_LIST HENDPAR
691 ARRAY_SEGMENT : ARRAY_SEGMENT_EL {}
697 ARRAY_SEGMENT_EL: HIDENTIFIER
699 BAUND_PAIR_LIST : BAUND_PAIR
704 BAUND_PAIR : EXPRESSION
708 SWITCH_LIST : EXPRESSION
713 HEADING : MBEE_FMAL_PAR_P HSTATEMENTSEPARATOR {}
719 MBEE_FMAL_PAR_P : /*EMPT*/
722 FMAL_PAR_PART : HBEGPAR NO_TYPE
725 MBEE_LISTV : /*EMPT*/
729 | FPP_CATEG HDOTDOTDOT
731 HPAREXPSEPARATOR LISTV
734 HPAREXPSEPARATOR LISTV
736 FPP_HEADING : HBEGPAR NO_TYPE
737 FPP_MBEE_LISTV HENDPAR
739 FPP_MBEE_LISTV : /*EMPT*/
742 FPP_LISTV : FPP_CATEG HDOTDOTDOT
745 HPAREXPSEPARATOR LISTV
747 FPP_SPEC : FPP_CATEG SPECIFIER HIDENTIFIER
748 | FPP_CATEG FPP_PROC_DECL_IN_SPEC
750 FPP_CATEG : HNAME HLABELSEPARATOR
751 | HVALUE HLABELSEPARATOR
752 | HVAR HLABELSEPARATOR
755 FPP_PROC_DECL_IN_SPEC: MBEE_TYPE HPROCEDURE
758 FPP_HEADING {} { /* Yes, two "final" actions. */ }
760 IDENTIFIER_LISTV: HIDENTIFIER
763 HPAREXPSEPARATOR IDENTIFIER_LISTV
765 MBEE_MODE_PART : /*EMPT*/
768 MODE_PART : NAME_PART
771 | NAME_PART VALUE_PART
772 | VALUE_PART NAME_PART
775 | VALUE_PART VAR_PART
776 | VAR_PART VALUE_PART
777 | VAR_PART NAME_PART VALUE_PART
778 | NAME_PART VAR_PART VALUE_PART
779 | NAME_PART VALUE_PART VAR_PART
780 | VAR_PART VALUE_PART NAME_PART
781 | VALUE_PART VAR_PART NAME_PART
782 | VALUE_PART NAME_PART VAR_PART
792 VALUE_PART : HVALUE {}
793 IDENTIFIER_LISTV HSTATEMENTSEPARATOR
795 MBEE_SPEC_PART : /*EMPT*/
801 ONE_SPEC : SPECIFIER IDENTIFIER_LIST HSTATEMENTSEPARATOR
802 | NO_TYPE HPROCEDURE HIDENTIFIER HOBJRELOPERATOR
804 PROC_DECL_IN_SPEC HSTATEMENTSEPARATOR
805 | FPP_PROC_DECL_IN_SPEC HSTATEMENTSEPARATOR
806 | MBEE_TYPE HPROCEDURE HIDENTIFIER HSTATEMENTSEPARATOR
807 | MBEE_TYPE HPROCEDURE HIDENTIFIER HPAREXPSEPARATOR
808 IDENTIFIER_LIST HSTATEMENTSEPARATOR
816 PROC_DECL_IN_SPEC: MBEE_TYPE HPROCEDURE
823 MBEE_BEGIN_END : /* EMPTY */
826 MBEE_PROT_PART : /*EMPT*/
829 PROTECTION_PART : PROT_SPECIFIER IDENTIFIER_LIST
831 | PROTECTION_PART PROT_SPECIFIER
832 IDENTIFIER_LIST HSTATEMENTSEPARATOR
834 PROT_SPECIFIER : HHIDDEN
841 MBEE_VIRT_PART : /*EMPT*/
844 VIRTUAL_PART : HVIRTUAL
848 IDENTIFIER_LIST : HIDENTIFIER
849 | IDENTIFIER_LIST HPAREXPSEPARATOR
852 IDENTIFIER_LISTC: HIDENTIFIER
854 | IDENTIFIER_LISTC HPAREXPSEPARATOR
858 MBEE_CONSTANT : /* EMPTY */
864 /* GRAMATIKK FOR UTTRYKK */
865 EXPRESSION : EXPRESSION_SIMP
873 EXPRESSION_SIMP : EXPRESSION_SIMP
881 | EXPRESSION_SIMP HOR
885 | EXPRESSION_SIMP HAND
897 | HNOT EXPRESSION_SIMP
908 EXPRESSION_SIMP %prec UNEAR
941 ARGUMENT_LIST HENDPAR
943 MBEE_ARG_R_PT : /*EMPTY*/
945 ARGUMENT_LIST HENDPAR
947 ARGUMENT_LIST : EXPRESSION
955 # Pass plenty of options, to exercise plenty of code, even if we
956 # don't actually check the output. But SEGV is watching us, and
957 # so might do dmalloc.
958 AT_CHECK([[bison --verbose --defines input.y]], 0, [],
959 [[input.y: conflicts: 78 shift/reduce, 10 reduce/reduce
962 AT_CHECK([[grep '^State.*conflicts:' input.output]], 0,
963 [[State 64 conflicts: 14 shift/reduce
964 State 164 conflicts: 1 shift/reduce
965 State 201 conflicts: 33 shift/reduce, 4 reduce/reduce
966 State 206 conflicts: 1 shift/reduce
967 State 240 conflicts: 1 shift/reduce
968 State 335 conflicts: 9 shift/reduce, 2 reduce/reduce
969 State 356 conflicts: 1 shift/reduce
970 State 360 conflicts: 9 shift/reduce, 2 reduce/reduce
971 State 427 conflicts: 9 shift/reduce, 2 reduce/reduce
976 ## ----------------- ##
977 ## GNU pic Grammar. ##
978 ## ----------------- ##
980 AT_SETUP([GNU pic Grammar])
982 # GNU pic, part of groff.
984 # Bison once reported shift/reduce conflicts that it shouldn't have.
997 %token LEFT_ARROW_HEAD
998 %token RIGHT_ARROW_HEAD
999 %token DOUBLE_ARROW_HEAD
1109 /* this ensures that plot 17 "%g" parses as (plot 17 "%g") */
1113 /* give text adjustments higher precedence than TEXT, so that
1114 box "foo" above ljust == box ("foo" above ljust)
1117 %left LJUST RJUST ABOVE BELOW
1120 /* Give attributes that take an optional expression a higher
1121 precedence than left and right, so that eg `line chop left'
1123 %left CHOP SOLID DASHED DOTTED UP DOWN FILL COLORED OUTLINED
1126 %left VARIABLE NUMBER '(' SIN COS ATAN2 LOG EXP SQRT K_MAX K_MIN INT RAND SRAND LAST
1127 %left ORDINAL HERE '`'
1129 %left BOX CIRCLE ELLIPSE ARC LINE ARROW SPLINE '[' /* ] */
1131 /* these need to be lower than '-' */
1132 %left HEIGHT RADIUS WIDTH DIAMETER FROM TO AT THICKNESS
1134 /* these must have higher precedence than CHOP so that `label %prec CHOP'
1136 %left DOT_N DOT_E DOT_W DOT_S DOT_NE DOT_SE DOT_NW DOT_SW DOT_C
1137 %left DOT_START DOT_END TOP BOTTOM LEFT_CORNER RIGHT_CORNER
1138 %left UPPER LOWER NORTH SOUTH EAST WEST CENTER START END
1143 %left EQUALEQUAL NOTEQUAL
1144 %left '<' '>' LESSEQUAL GREATEREQUAL
1162 optional_separator middle_element_list optional_separator
1165 middle_element_list:
1167 | middle_element_list separator element
1181 VARIABLE '=' any_expr
1182 | VARIABLE ':' '=' any_expr
1188 | COMMAND print_args
1204 | FOR VARIABLE '=' expr TO expr optional_by DO
1217 | reset_variables VARIABLE
1218 | reset_variables ',' VARIABLE
1223 | print_args print_arg
1229 | position %prec ','
1249 text EQUALEQUAL text
1250 | text NOTEQUAL text
1251 | text_expr ANDAND text_expr
1252 | text_expr ANDAND expr
1253 | expr ANDAND text_expr
1254 | text_expr OROR text_expr
1255 | text_expr OROR expr
1256 | expr OROR text_expr
1268 | LABEL ':' optional_separator element
1269 | LABEL ':' optional_separator position_not_place
1270 | LABEL ':' optional_separator place
1297 | object_spec HEIGHT expr
1298 | object_spec RADIUS expr
1299 | object_spec WIDTH expr
1300 | object_spec DIAMETER expr
1301 | object_spec expr %prec HEIGHT
1303 | object_spec UP expr
1305 | object_spec DOWN expr
1307 | object_spec RIGHT expr
1309 | object_spec LEFT expr
1310 | object_spec FROM position
1311 | object_spec TO position
1312 | object_spec AT position
1313 | object_spec WITH path
1314 | object_spec WITH position %prec ','
1315 | object_spec BY expr_pair
1318 | object_spec DOTTED
1319 | object_spec DOTTED expr
1320 | object_spec DASHED
1321 | object_spec DASHED expr
1323 | object_spec FILL expr
1324 | object_spec SHADED text
1325 | object_spec COLORED text
1326 | object_spec OUTLINED text
1328 | object_spec CHOP expr
1330 | object_spec INVISIBLE
1331 | object_spec LEFT_ARROW_HEAD
1332 | object_spec RIGHT_ARROW_HEAD
1333 | object_spec DOUBLE_ARROW_HEAD
1336 | object_spec text %prec TEXT
1341 | object_spec THICKNESS expr
1342 | object_spec ALIGNED
1347 | SPRINTF '(' TEXT sprintf_args ')'
1352 | sprintf_args ',' expr
1362 | position '+' expr_pair
1363 | position '-' expr_pair
1364 | '(' position ',' position ')'
1365 | expr between position AND position
1366 | expr '<' position ',' position '>'
1371 | OF THE WAY BETWEEN
1380 /* line at A left == line (at A) left */
1399 optional_ordinal_last:
1406 | optional_ordinal_last object_type
1423 | label_path '.' LABEL
1428 /* give this a lower precedence than LEFT and RIGHT so that
1429 [A: box] with .A left == [A: box] with (.A left) */
1430 | label_path %prec TEXT
1436 | '(' relative_path ',' relative_path ')'
1438 /* The rest of these rules are a compatibility sop. */
1439 | ORDINAL LAST object_type relative_path
1440 | LAST object_type relative_path
1441 | ORDINAL object_type relative_path
1442 | LABEL relative_path
1469 | UPPER RIGHT_CORNER
1470 | LOWER RIGHT_CORNER
1494 | '-' expr %prec '!'
1496 | SIN '(' any_expr ')'
1497 | COS '(' any_expr ')'
1498 | ATAN2 '(' any_expr ',' any_expr ')'
1499 | LOG '(' any_expr ')'
1500 | EXP '(' any_expr ')'
1501 | SQRT '(' any_expr ')'
1502 | K_MAX '(' any_expr ',' any_expr ')'
1503 | K_MIN '(' any_expr ',' any_expr ')'
1504 | INT '(' any_expr ')'
1505 | RAND '(' any_expr ')'
1507 | SRAND '(' any_expr ')'
1509 | expr LESSEQUAL expr
1511 | expr GREATEREQUAL expr
1512 | expr EQUALEQUAL expr
1513 | expr NOTEQUAL expr
1520 # Pass plenty of options, to exercise plenty of code, even if we
1521 # don't actually check the output. But SEGV is watching us, and
1522 # so might do dmalloc.
1523 AT_CHECK([[bison --verbose --defines input.y]], 0, [],
1524 [[input.y:453.11-48: warning: rule never reduced because of conflicts: path: ORDINAL LAST object_type relative_path