1 # Checking the Bison scanner. -*- Autotest -*-
2 # Copyright (C) 2002, 2003 Free Software Foundation, Inc.
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)
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.
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
19 AT_BANNER([[Input Processing.]])
21 # Mostly test that we are robust to mistakes.
28 AT_SETUP([Invalid $n])
35 AT_CHECK([bison input.y], [1], [],
36 [[input.y:2.13-14: integer out of range: `$1'
46 AT_SETUP([Invalid @n])
53 AT_CHECK([bison input.y], [1], [],
54 [[input.y:2.13-14: integer out of range: `@1'
64 AT_SETUP([Type Clashes])
76 AT_CHECK([bison input.y], [], [],
77 [[input.y:4.6-15: warning: type clash on default action: <bar> != <>
78 input.y:5.6-8: warning: type clash on default action: <bar> != <>
79 input.y:6.5: warning: empty rule for typed nonterminal, and no action
86 ## ----------------------- ##
87 ## Torturing the Scanner. ##
88 ## ----------------------- ##
90 # Be sure to compile and run, so that the C compiler checks what
93 AT_SETUP([Torturing the Scanner])
96 AT_DATA([input.y], [])
97 AT_CHECK([bison input.y], [1], [],
98 [[input.y:1.1: syntax error, unexpected "end of file"
102 AT_DATA_GRAMMAR([input.y],
104 /* This is seen in GCC: a %{ and %} in middle of a comment. */
105 const char *foo = "So %{ and %} can be here too.";
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
114 HP C (as of late 2002) mishandles *\[newline]\[newline]/ within a
117 The Apple Darwin compiler (as of late 2002) mishandles
118 \\[newline]' within a character constant.
123 * A comment with backslash-newlines in it. %} *\
126 /* { Close the above comment, if the C compiler mishandled it. */
129 " A string with backslash-newlines in it %{ %} \\
133 char apostrophe = '\'';
138 /* %{ and %} can be here too. */
141 /* Exercise pre-prologue dependency to %union. */
145 /* Exercise M4 quoting: '@:>@@:>@', 0. */
147 /* Also exercise %union. */
150 value ival; /* A comment to exercise an old bug. */
154 /* Exercise post-prologue dependency to %union. */
156 static YYSTYPE value_as_yystype (value val);
158 /* Exercise quotes in declarations. */
159 char quote[] = "@:>@@:>@,";
163 static void yyerror (const char *s);
164 static int yylex (void);
169 /* Exercise quotes in strings. */
170 %token FAKE "fake @<:@@:>@ \a\b\f\n\r\t\v\"\'\?\\\u005B\U0000005c ??!??'??(??)??-??/??<??=??> \x1\1"
173 /* Exercise M4 quoting: '@:>@@:>@', @<:@, 1. */
174 exp: '@<:@' '\1' two '$' '@' '{' oline output.or.oline.opt
176 /* Exercise quotes in braces. */
177 char tmp[] = "@<:@%c@:>@,\n";
182 two: '\x000000000000000000000000000000000000000000000000000000000000000000002';
183 oline: '@' 'o' 'l' 'i' 'n' 'e' '@' '_' '_' 'o' 'l' 'i' 'n' 'e' '_' '_';
184 output.or.oline.opt: ;|oline;;|output;;;
185 output: '#' 'o' 'u' 't' 'p' 'u' 't' ' ';
187 /* Exercise M4 quoting: '@:>@@:>@', @<:@, 2. */
190 value_as_yystype (value val)
200 static const char *input = "@<:@\1\2$@{@oline@__@&t@oline__\
203 yylval = value_as_yystype (*input);
208 yyerror (const char *msg)
210 fprintf (stderr, "%s\n", msg);
214 # Pacify Emacs'font-lock-mode: "
229 AT_CHECK([bison -d -v -o input.c input.y])
230 AT_COMPILE([input.o], [-c input.c])
231 AT_COMPILE([main.o], [-c main.c])
232 AT_COMPILE([input], [input.o main.o])
233 AT_PARSER_CHECK([./input], 0,