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