]>
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 | ||
23 | AT_DATA([glr-regr1.y], | |
24 | [[/* Regression Test: Improper state compression */ | |
25 | /* Reported by Scott McPeak */ | |
26 | ||
27 | %{ | |
28 | #include <stdio.h> // fgetc, printf | |
29 | ||
30 | #define YYSTYPE int | |
31 | static YYSTYPE exprMerge (YYSTYPE x0, YYSTYPE x1); | |
32 | %} | |
33 | ||
34 | ||
35 | %glr-parser | |
36 | ||
37 | ||
38 | /* -------- productions ------ */ | |
39 | %% | |
40 | ||
41 | StartSymbol: E { $$=0; } %merge <exprMerge> | |
42 | ; | |
43 | ||
44 | E: E 'P' E { $$=1; printf("E -> E 'P' E\n"); } %merge <exprMerge> | |
45 | | 'B' { $$=2; printf("E -> 'B'\n"); } %merge <exprMerge> | |
46 | ; | |
47 | ||
48 | ||
49 | ||
50 | /* ---------- C code ----------- */ | |
51 | %% | |
52 | ||
53 | static YYSTYPE exprMerge (YYSTYPE x0, YYSTYPE x1) | |
54 | { | |
55 | printf ("<OR>\n"); | |
56 | return 0; | |
57 | } | |
58 | ||
59 | int main() | |
60 | { | |
61 | yyparse(); | |
62 | return 0; | |
63 | } | |
64 | ||
65 | int yyerror(char const *msg) | |
66 | { | |
67 | printf("%s\n", msg); | |
68 | exit(4); | |
69 | } | |
70 | ||
71 | ||
72 | int yylex() | |
73 | { | |
74 | while (1) { | |
75 | int ch = fgetc(stdin); | |
76 | if (ch == EOF) { | |
77 | return 0; // bison's EOF | |
78 | } else if (ch == 'B' || ch == 'P') { | |
79 | return ch; | |
80 | } | |
81 | } | |
82 | } | |
83 | ]]) | |
84 | ||
85 | AT_CHECK([[bison -o glr-regr1.c glr-regr1.y]], 0, [], | |
86 | [glr-regr1.y: warning: 1 shift/reduce conflict | |
87 | ]) | |
88 | AT_COMPILE([glr-regr1]) | |
89 | AT_CHECK([[echo BPBPB | ./glr-regr1]], 0, | |
90 | [[E -> 'B' | |
91 | E -> 'B' | |
92 | E -> E 'P' E | |
93 | E -> 'B' | |
94 | E -> E 'P' E | |
95 | E -> 'B' | |
96 | E -> E 'P' E | |
97 | E -> E 'P' E | |
98 | <OR> | |
99 | ]], []) | |
100 | ||
101 | AT_CLEANUP |