21 |
# Mostly test that we are robust to mistakes. |
# Mostly test that we are robust to mistakes. |
22 |
|
|
23 |
|
|
|
## ----------------------- ## |
|
|
## Torturing the Scanner. ## |
|
|
## ----------------------- ## |
|
|
|
|
|
AT_SETUP([Torturing the Scanner]) |
|
|
|
|
|
AT_DATA([input.y], |
|
|
[[%{ |
|
|
/* This is seen in GCC: a %{ and %} in middle of a comment. */ |
|
|
const char *foo = "So %{ and %} can be here."; |
|
|
%} |
|
|
/* %{ and %} can be here too. */ |
|
|
|
|
|
%% |
|
|
exp: 'a'; |
|
|
]]) |
|
|
|
|
|
AT_CHECK([bison input.y]) |
|
|
|
|
|
AT_CLEANUP |
|
|
|
|
|
|
|
|
|
|
|
|
|
24 |
## ------------ ## |
## ------------ ## |
25 |
## Invalid $n. ## |
## Invalid $n. ## |
26 |
## ------------ ## |
## ------------ ## |
80 |
]]) |
]]) |
81 |
|
|
82 |
AT_CLEANUP |
AT_CLEANUP |
83 |
|
|
84 |
|
|
85 |
|
|
86 |
|
## ----------------------- ## |
87 |
|
## Torturing the Scanner. ## |
88 |
|
## ----------------------- ## |
89 |
|
|
90 |
|
# Be sure to compile and run, so that the C compiler checks what |
91 |
|
# we do. |
92 |
|
|
93 |
|
AT_SETUP([Torturing the Scanner]) |
94 |
|
|
95 |
|
AT_DATA([input.y], |
96 |
|
[[%{ |
97 |
|
/* This is seen in GCC: a %{ and %} in middle of a comment. */ |
98 |
|
const char *foo = "So %{ and %} can be here too."; |
99 |
|
|
100 |
|
#include <stdio.h> |
101 |
|
%} |
102 |
|
/* %{ and %} can be here too. */ |
103 |
|
|
104 |
|
%{ |
105 |
|
/* Exercise pre-prologue dependency to %union. */ |
106 |
|
typedef int value_t; |
107 |
|
%} |
108 |
|
|
109 |
|
/* Exercise M4 quoting: '@:>@@:>@', 0. */ |
110 |
|
|
111 |
|
/* Also exercise %union. */ |
112 |
|
%union |
113 |
|
{ |
114 |
|
value_t ival; /* A comment to exercise an old bug. */ |
115 |
|
}; |
116 |
|
|
117 |
|
|
118 |
|
/* Exercise post-prologue dependency to %union. */ |
119 |
|
%{ |
120 |
|
static YYSTYPE value_t_as_yystype (value_t val); |
121 |
|
|
122 |
|
/* Exercise quotes in declarations. */ |
123 |
|
char quote[] = "@:>@@:>@,"; |
124 |
|
%} |
125 |
|
|
126 |
|
%{ |
127 |
|
static void yyerror (const char *s); |
128 |
|
static int yylex (void); |
129 |
|
%} |
130 |
|
|
131 |
|
%type <ival> '1' |
132 |
|
|
133 |
|
/* Exercise quotes in strings. */ |
134 |
|
%token FAKE "fake @<:@@:>@," |
135 |
|
|
136 |
|
%% |
137 |
|
/* Exercise M4 quoting: '@:>@@:>@', 1. */ |
138 |
|
exp: '1' |
139 |
|
{ |
140 |
|
/* Exercise quotes in braces. */ |
141 |
|
char tmp[] = "@<:@%c@:>@,\n"; |
142 |
|
printf (tmp, $1); |
143 |
|
} |
144 |
|
; |
145 |
|
%% |
146 |
|
/* Exercise M4 quoting: '@:>@@:>@', 2. */ |
147 |
|
|
148 |
|
static YYSTYPE |
149 |
|
value_t_as_yystype (value_t val) |
150 |
|
{ |
151 |
|
YYSTYPE res; |
152 |
|
res.ival = val; |
153 |
|
return res; |
154 |
|
} |
155 |
|
|
156 |
|
static int |
157 |
|
yylex (void) |
158 |
|
{ |
159 |
|
static const char *input = "1"; |
160 |
|
yylval = value_t_as_yystype (*input); |
161 |
|
return *input++; |
162 |
|
} |
163 |
|
|
164 |
|
static void |
165 |
|
yyerror (const char *msg) |
166 |
|
{ |
167 |
|
fprintf (stderr, "%s\n", msg); |
168 |
|
} |
169 |
|
]]) |
170 |
|
|
171 |
|
AT_DATA([main.c], |
172 |
|
[[typedef int value_t; |
173 |
|
#include "input.h" |
174 |
|
|
175 |
|
int yyparse (void); |
176 |
|
|
177 |
|
int |
178 |
|
main (void) |
179 |
|
{ |
180 |
|
return yyparse (); |
181 |
|
} |
182 |
|
]]) |
183 |
|
|
184 |
|
AT_CHECK([bison input.y -d -v -o input.c]) |
185 |
|
AT_CHECK([$CC $CFLAGS $CPPFLAGS main.c input.c -o input], 0, [], [ignore]) |
186 |
|
AT_CHECK([./input], 0, |
187 |
|
[[[1], |
188 |
|
]]) |
189 |
|
|
190 |
|
AT_CLEANUP |