]> git.saurik.com Git - bison.git/blame_incremental - tests/input.at
Regenerate.
[bison.git] / tests / input.at
... / ...
CommitLineData
1# Checking the Bison scanner. -*- Autotest -*-
2# Copyright (C) 2002, 2003 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
19AT_BANNER([[Input Processing.]])
20
21# Mostly test that we are robust to mistakes.
22
23
24## ------------ ##
25## Invalid $n. ##
26## ------------ ##
27
28AT_SETUP([Invalid $n])
29
30AT_DATA([input.y],
31[[%%
32exp: { $$ = $1 ; };
33]])
34
35AT_CHECK([bison input.y], [1], [],
36[[input.y:2.13-14: integer out of range: `$1'
37]])
38
39AT_CLEANUP
40
41
42## ------------ ##
43## Invalid @n. ##
44## ------------ ##
45
46AT_SETUP([Invalid @n])
47
48AT_DATA([input.y],
49[[%%
50exp: { @$ = @1 ; };
51]])
52
53AT_CHECK([bison input.y], [1], [],
54[[input.y:2.13-14: integer out of range: `@1'
55]])
56
57AT_CLEANUP
58
59
60## -------------- ##
61## Type Clashes. ##
62## -------------- ##
63
64AT_SETUP([Type Clashes])
65
66AT_DATA([input.y],
67[[%token foo
68%type <bar> exp
69%%
70exp: foo {} foo
71 | foo
72 | /* Empty. */
73 ;
74]])
75
76AT_CHECK([bison input.y], [], [],
77[[input.y:4.6-15: warning: type clash on default action: <bar> != <>
78input.y:5.6-8: warning: type clash on default action: <bar> != <>
79input.y:6.5: warning: empty rule for typed nonterminal, and no action
80]])
81
82AT_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
93AT_SETUP([Torturing the Scanner])
94
95
96AT_DATA([input.y], [])
97AT_CHECK([bison input.y], [1], [],
98[[input.y:1.1: syntax error, unexpected "end of file"
99]])
100
101
102AT_DATA_GRAMMAR([input.y],
103[[%{
104/* This is seen in GCC: a %{ and %} in middle of a comment. */
105const char *foo = "So %{ and %} can be here too.";
106
107#if 0
108/* These examples test Bison while not stressing C compilers too much.
109 Many C compilers mishandle backslash-newlines, so this part of the
110 test is inside "#if 0". The comment and string are written so that
111 the "#endif" will be seen regardless of the C compiler bugs that we
112 know about, namely:
113
114 HP C (as of late 2002) mishandles *\[newline]\[newline]/ within a
115 comment.
116
117 The Apple Darwin compiler (as of late 2002) mishandles
118 \\[newline]' within a character constant.
119
120 */
121
122/\
123* A comment with backslash-newlines in it. %} *\
124\
125/
126/* { Close the above comment, if the C compiler mishandled it. */
127
128char str[] = "\\
129" A string with backslash-newlines in it %{ %} \\
130\
131"";
132
133char apostrophe = '\'';
134#endif
135
136#include <stdio.h>
137%}
138/* %{ and %} can be here too. */
139
140%{
141/* Exercise pre-prologue dependency to %union. */
142typedef int value;
143%}
144
145/* Exercise M4 quoting: '@:>@@:>@', 0. */
146
147/* Also exercise %union. */
148%union
149{
150 value ival; /* A comment to exercise an old bug. */
151};
152
153
154/* Exercise post-prologue dependency to %union. */
155%{
156static YYSTYPE value_as_yystype (value val);
157
158/* Exercise quotes in declarations. */
159char quote[] = "@:>@@:>@,";
160%}
161
162%{
163static void yyerror (const char *s);
164static int yylex (void);
165%}
166
167%type <ival> '@<:@'
168
169/* Exercise quotes in strings. */
170%token FAKE "fake @<:@@:>@ \a\b\f\n\r\t\v\"\'\?\\\u005B\U0000005c ??!??'??(??)??-??/??<??=??> \x1\1"
171
172%%
173/* Exercise M4 quoting: '@:>@@:>@', @<:@, 1. */
174exp: '@<:@' '\1' two '$' '@' '{' oline output.or.oline.opt
175 {
176 /* Exercise quotes in braces. */
177 char tmp[] = "@<:@%c@:>@,\n";
178 printf (tmp, $1);
179 }
180;
181
182two: '\x000000000000000000000000000000000000000000000000000000000000000000002';
183oline: '@' 'o' 'l' 'i' 'n' 'e' '@' '_' '_' 'o' 'l' 'i' 'n' 'e' '_' '_';
184output.or.oline.opt: ;|oline;;|output;;;
185output: '#' 'o' 'u' 't' 'p' 'u' 't' ' ';
186%%
187/* Exercise M4 quoting: '@:>@@:>@', @<:@, 2. */
188
189static YYSTYPE
190value_as_yystype (value val)
191{
192 YYSTYPE res;
193 res.ival = val;
194 return res;
195}
196
197static int
198yylex (void)
199{
200 static const char *input = "@<:@\1\2$@{@oline@__@&t@oline__\
201#output "; /* "
202 */
203 yylval = value_as_yystype (*input);
204 return *input++;
205}
206
207static void
208yyerror (const char *msg)
209{
210 fprintf (stderr, "%s\n", msg);
211}
212]])
213
214# Pacify Emacs'font-lock-mode: "
215
216AT_DATA([main.c],
217[[typedef int value;
218#include "input.h"
219
220int yyparse (void);
221
222int
223main (void)
224{
225 return yyparse ();
226}
227]])
228
229AT_CHECK([bison -d -v -o input.c input.y])
230AT_COMPILE([input.o], [-c input.c])
231AT_COMPILE([main.o], [-c main.c])
232AT_COMPILE([input], [input.o main.o])
233AT_PARSER_CHECK([./input], 0,
234[[[@<:@],
235]])
236
237AT_CLEANUP