]> git.saurik.com Git - bison.git/blame_incremental - tests/input.at
Really remove it.
[bison.git] / tests / input.at
... / ...
CommitLineData
1# Checking the output filenames. -*- 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
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.6-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.6-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], [1], [],
77[[input.y:4.4-15: type clash on default action: <bar> != <>
78input.y:5.4-8: type clash on default action: <bar> != <>
79input.y:6.4: 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
95AT_DATA_GRAMMAR([input.y],
96[[%{
97/* This is seen in GCC: a %{ and %} in middle of a comment. */
98const char *foo = "So %{ and %} can be here too.";
99
100#if 0
101/* These examples test Bison while not stressing C compilers too much.
102 Many C compilers mishandle backslash-newlines, so this part of the
103 test is inside "#if 0". The comment and string are written so that
104 the "#endif" will be seen regardless of the C compiler bugs that we
105 know about, namely:
106
107 HP C (as of late 2002) mishandles *\[newline]\[newline]/ within a
108 comment.
109
110 The Apple Darwin compiler (as of late 2002) mishandles
111 \\[newline]' within a character constant.
112
113 */
114
115/\
116* A comment with backslash-newlines in it. %} *\
117\
118/
119/* { Close the above comment, if the C compiler mishandled it. */
120
121char str[] = "\\
122" A string with backslash-newlines in it %{ %} \\
123\
124"";
125
126char apostrophe = '\'';
127#endif
128
129#include <stdio.h>
130%}
131/* %{ and %} can be here too. */
132
133%{
134/* Exercise pre-prologue dependency to %union. */
135typedef int value_t;
136%}
137
138/* Exercise M4 quoting: '@:>@@:>@', 0. */
139
140/* Also exercise %union. */
141%union
142{
143 value_t ival; /* A comment to exercise an old bug. */
144};
145
146
147/* Exercise post-prologue dependency to %union. */
148%{
149static YYSTYPE value_t_as_yystype (value_t val);
150
151/* Exercise quotes in declarations. */
152char quote[] = "@:>@@:>@,";
153%}
154
155%{
156static void yyerror (const char *s);
157static int yylex (void);
158%}
159
160%type <ival> '@<:@'
161
162/* Exercise quotes in strings. */
163%token FAKE "fake @<:@@:>@ \a\b\f\n\r\t\v\"\'\?\\\u005B\U0000005c ??!??'??(??)??-??/??<??=??> \x0\0"
164
165%%
166/* Exercise M4 quoting: '@:>@@:>@', @<:@, 1. */
167exp: '@<:@' '\1' two '$' '@' '{' oline output
168 {
169 /* Exercise quotes in braces. */
170 char tmp[] = "@<:@%c@:>@,\n";
171 printf (tmp, $1);
172 }
173;
174
175two: '\x000000000000000000000000000000000000000000000000000000000000000000002';
176oline: '@' 'o' 'l' 'i' 'n' 'e' '@' '_' '_' 'o' 'l' 'i' 'n' 'e' '_' '_';
177output: '#' 'o' 'u' 't' 'p' 'u' 't' ' ';
178%%
179/* Exercise M4 quoting: '@:>@@:>@', @<:@, 2. */
180
181static YYSTYPE
182value_t_as_yystype (value_t val)
183{
184 YYSTYPE res;
185 res.ival = val;
186 return res;
187}
188
189static int
190yylex (void)
191{
192 static const char *input = "@<:@\1\2$@{@oline@__@&t@oline__\
193#output "; /* "
194 */
195 yylval = value_t_as_yystype (*input);
196 return *input++;
197}
198
199static void
200yyerror (const char *msg)
201{
202 fprintf (stderr, "%s\n", msg);
203}
204]])
205
206# Pacify Emacs'font-lock-mode: "
207
208AT_DATA([main.c],
209[[typedef int value_t;
210#include "input.h"
211
212int yyparse (void);
213
214int
215main (void)
216{
217 return yyparse ();
218}
219]])
220
221AT_CHECK([bison -d -v -o input.c input.y])
222AT_COMPILE([input.o], [-c input.c])
223AT_COMPILE([main.o], [-c main.c])
224AT_COMPILE([input], [input.o main.o])
225AT_PARSER_CHECK([./input], 0,
226[[[@<:@],
227]])
228
229AT_CLEANUP