]>
Commit | Line | Data |
---|---|---|
09903f30 PH |
1 | # Checking GLR Parsing: Regression Test -*- Autotest -*- |
2 | # Copyright (C) 2002 Free Software Foundation, Inc. | |
3 | ||
4 | # This program is free software; you can redistribute it and/or modify | |
5 | # it under the terms of the GNU General Public License as published by | |
6 | # the Free Software Foundation; either version 2, or (at your option) | |
7 | # any later version. | |
8 | ||
9 | # This program is distributed in the hope that it will be useful, | |
10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of | |
11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
12 | # GNU General Public License for more details. | |
13 | ||
14 | # You should have received a copy of the GNU General Public License | |
15 | # along with this program; if not, write to the Free Software | |
16 | # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA | |
17 | # 02111-1307, USA. | |
18 | ||
19 | AT_BANNER([[GLR Regression Test #1.]]) | |
20 | ||
21 | AT_SETUP([Badly Collapsed GLR States]) | |
22 | ||
9501dc6e | 23 | AT_DATA_GRAMMAR([glr-regr1.y], |
09903f30 PH |
24 | [[/* Regression Test: Improper state compression */ |
25 | /* Reported by Scott McPeak */ | |
26 | ||
27 | %{ | |
c240826c | 28 | #include <stdio.h> |
09903f30 PH |
29 | |
30 | #define YYSTYPE int | |
31 | static YYSTYPE exprMerge (YYSTYPE x0, YYSTYPE x1); | |
793a58bb AD |
32 | int yylex (void); |
33 | int yyerror (char const *msg); | |
09903f30 PH |
34 | %} |
35 | ||
36 | ||
37 | %glr-parser | |
38 | ||
39 | ||
40 | /* -------- productions ------ */ | |
41 | %% | |
42 | ||
43 | StartSymbol: E { $$=0; } %merge <exprMerge> | |
44 | ; | |
45 | ||
46 | E: E 'P' E { $$=1; printf("E -> E 'P' E\n"); } %merge <exprMerge> | |
47 | | 'B' { $$=2; printf("E -> 'B'\n"); } %merge <exprMerge> | |
48 | ; | |
49 | ||
50 | ||
51 | ||
52 | /* ---------- C code ----------- */ | |
53 | %% | |
54 | ||
55 | static YYSTYPE exprMerge (YYSTYPE x0, YYSTYPE x1) | |
56 | { | |
793a58bb AD |
57 | (void) x0; |
58 | (void) x1; | |
09903f30 PH |
59 | printf ("<OR>\n"); |
60 | return 0; | |
61 | } | |
62 | ||
793a58bb AD |
63 | int |
64 | main (void) | |
09903f30 | 65 | { |
c240826c | 66 | yyparse (); |
09903f30 PH |
67 | return 0; |
68 | } | |
69 | ||
793a58bb AD |
70 | int |
71 | yyerror (char const *msg) | |
09903f30 | 72 | { |
c240826c PE |
73 | fprintf (stderr, "%s\n", msg); |
74 | exit (4); | |
09903f30 PH |
75 | } |
76 | ||
77 | ||
793a58bb AD |
78 | int |
79 | yylex (void) | |
09903f30 | 80 | { |
c240826c PE |
81 | for (;;) |
82 | { | |
83 | int ch = getchar (); | |
84 | if (ch == EOF) | |
85 | return 0; | |
86 | else if (ch == 'B' || ch == 'P') | |
87 | return ch; | |
09903f30 | 88 | } |
09903f30 PH |
89 | } |
90 | ]]) | |
91 | ||
92 | AT_CHECK([[bison -o glr-regr1.c glr-regr1.y]], 0, [], | |
93 | [glr-regr1.y: warning: 1 shift/reduce conflict | |
94 | ]) | |
95 | AT_COMPILE([glr-regr1]) | |
793a58bb | 96 | AT_CHECK([[echo BPBPB | ./glr-regr1]], 0, |
09903f30 PH |
97 | [[E -> 'B' |
98 | E -> 'B' | |
99 | E -> E 'P' E | |
100 | E -> 'B' | |
101 | E -> E 'P' E | |
102 | E -> 'B' | |
103 | E -> E 'P' E | |
104 | E -> E 'P' E | |
105 | <OR> | |
106 | ]], []) | |
107 | ||
108 | AT_CLEANUP |