]> git.saurik.com Git - bison.git/blame - tests/input.at
Minor spelling, grammar, and white space fixes.
[bison.git] / tests / input.at
CommitLineData
9b2d0677 1# Checking the output filenames. -*- Autotest -*-
6c35d22c 2# Copyright (C) 2002 Free Software Foundation, Inc.
9b2d0677
AD
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
6c35d22c 23
9b2d0677
AD
24## ------------ ##
25## Invalid $n. ##
26## ------------ ##
27
9b2d0677
AD
28AT_SETUP([Invalid $n])
29
30AT_DATA([input.y],
31[[%%
bfcf1f3a 32exp: { $$ = $1 ; };
9b2d0677
AD
33]])
34
35AT_CHECK([bison input.y], [1], [],
56c47203 36[[input.y:2.6-14: invalid value: $1
9b2d0677
AD
37]])
38
39AT_CLEANUP
40
41
42## ------------ ##
43## Invalid @n. ##
44## ------------ ##
45
9b2d0677
AD
46AT_SETUP([Invalid @n])
47
48AT_DATA([input.y],
49[[%%
bfcf1f3a 50exp: { @$ = @1 ; };
9b2d0677
AD
51]])
52
53AT_CHECK([bison input.y], [1], [],
f25bfb75 54[[input.y:2.6-14: invalid value: @1
9b2d0677
AD
55]])
56
57AT_CLEANUP
9af3fbce
AD
58
59
60## -------------- ##
e776192e 61## Type Clashes. ##
9af3fbce
AD
62## -------------- ##
63
e776192e 64AT_SETUP([Type Clashes])
9af3fbce
AD
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], [],
e776192e
AD
77[[input.y:4.4-15: type clash (`bar' `') on default action
78input.y:5.4-8: type clash (`bar' `') on default action
79input.y:6.4: empty rule for typed nonterminal, and no action
9af3fbce
AD
80]])
81
82AT_CLEANUP
5a08f1ce
AD
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([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#include <stdio.h>
101%}
102/* %{ and %} can be here too. */
103
104%{
105/* Exercise pre-prologue dependency to %union. */
106typedef 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%{
120static YYSTYPE value_t_as_yystype (value_t val);
121
122/* Exercise quotes in declarations. */
123char quote[] = "@:>@@:>@,";
124%}
125
126%{
127static void yyerror (const char *s);
128static 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. */
138exp: '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
148static YYSTYPE
149value_t_as_yystype (value_t val)
150{
151 YYSTYPE res;
152 res.ival = val;
153 return res;
154}
155
156static int
157yylex (void)
158{
159 static const char *input = "1";
160 yylval = value_t_as_yystype (*input);
161 return *input++;
162}
163
164static void
165yyerror (const char *msg)
166{
167 fprintf (stderr, "%s\n", msg);
168}
169]])
170
171AT_DATA([main.c],
172[[typedef int value_t;
173#include "input.h"
174
175int yyparse (void);
176
177int
178main (void)
179{
180 return yyparse ();
181}
182]])
183
184AT_CHECK([bison input.y -d -v -o input.c])
1154cced
AD
185AT_COMPILE([input], [input.c main.c])
186AT_PARSER_CHECK([./input], 0,
5a08f1ce
AD
187[[[1],
188]])
189
190AT_CLEANUP