%}
-/* Exercise M4 quoting: '@:>@@:>@', 0. */
-
-/* Also exercise %union. */
+/* Exercise %union. */
%union
{
- value_t ival; /* A comment to exercise an old bug. */
+ value_t ival;
};
-/* Exercise post-prologue dependency to %union. */
-%{
-static void id (YYSTYPE *lval);
-
-/* Exercise quotes in declarations. */
-char quote[] = "@:>@@:>@,";
-%}
-
/* Bison Declarations */
%token CALC_EOF 0 "end of file"
%token <ival> NUM "number"
%type <ival> exp
-/* Exercise quotes in strings. */
-%token FAKE "fake @>:@@>:@,"
-
%nonassoc '=' /* comparison */
%left '-' '+'
%left '*' '/'
;
line:
- '\n'
-| exp '\n'
- {
- /* Exercise quotes in braces. */
- char tmp[] = "@>:@@:>@,";
- }
+ '\n' {}
+| exp '\n' {}
;
-/* Exercise M4 quoting: '@:>@@:>@', 1. */
exp:
NUM { $$ = $1; }
| exp '=' exp
/* The input. */
FILE *yyin;
-/* Exercise M4 quoting: '@:>@@:>@', 2. */
static void
yyerror (const char *s)
{
return res;
}
-void
-id (YYSTYPE* lval)
-{
-}
-
int
main (int argc, const char **argv)
{
[AT_DATA([[input]],
[[$2
]])
-AT_CHECK([./calc input], 0, [], [stderr])dnl
+AT_PARSER_CHECK([./calc input], 0, [], [stderr])dnl
AT_CHECK([wc -l <stderr | sed 's/[[^0-9]]//g'], 0,
[m4_bmatch([$1], [--debug],
[$3], [0])
# of expected lines on stderr.
m4_define([_AT_CHECK_CALC_ERROR],
[m4_bmatch([$2], [^/],
- [AT_CHECK([./calc $2], 0, [], [stderr])],
+ [AT_PARSER_CHECK([./calc $2], 0, [], [stderr])],
[AT_DATA([[input]],
[[$2
]])
-AT_CHECK([./calc input], 0, [], [stderr])])
+AT_PARSER_CHECK([./calc input], 0, [], [stderr])])
m4_bmatch([$1], [--debug],
[AT_CHECK([wc -l <stderr | sed 's/[[^0-9]]//g'], 0, [$3
# Normalize the observed and expected error messages, depending upon the
# options.
# 1. Remove the traces from observed.
-egrep -v '^((Start|Enter|Read|Reduc|Shift)ing|state|Error:|Next|Discarding) ' stderr >at-stderr
+sed '/^Starting/d
+/^Entering/d
+/^Reading/d
+/^Reducing/d
+/^Shifting/d
+/^state/d
+/^Error:/d
+/^Next/d
+/^Discarding/d
+/^yydestructor:/d' stderr >at-stderr
mv at-stderr stderr
# 2. Create the reference error message.
AT_DATA([[expout]],
AT_CHECK([bison calc.y -o calc.c m4_bpatsubst([$1], [--yyerror-verbose])],
[0], [], [])
-AT_CHECK([$CC $CFLAGS $CPPFLAGS calc.c -o calc], 0, [], [ignore])
+AT_COMPILE([calc])
# Test the priorities.
_AT_CHECK_CALC([$1],
_AT_CHECK_CALC_ERROR([$1], [1//2], [15],
[1.3-1.4: parse error, unexpected '/', expecting "number" or '-' or '('])
_AT_CHECK_CALC_ERROR([$1], [error], [4],
- [1.1-1.2: parse error, unexpected $undefined., expecting "number" or '-' or '\n' or '('])
+ [1.1-1.2: parse error, unexpected $undefined, expecting "number" or '-' or '\n' or '('])
_AT_CHECK_CALC_ERROR([$1], [1 = 2 = 3], [22],
[1.7-1.8: parse error, unexpected '='])
_AT_CHECK_CALC_ERROR([$1],
[14],
[2.1-2.2: parse error, unexpected '+'])
# Exercise error messages with EOF: work on an empty file.
-_AT_CHECK_CALC_ERROR([$1],
- [/dev/null],
- [4],
+_AT_CHECK_CALC_ERROR([$1], [/dev/null], [4],
[1.1-1.2: parse error, unexpected "end of file", expecting "number" or '-' or '\n' or '('])
# Exercise the error token: without it, we die at the first error,
# hence be sure i. to have several errors, ii. to test the action
# associated to `error'.
-_AT_CHECK_CALC_ERROR([$1],
- [(1 ++ 2) + (0 0) = 1],
- [82],
+_AT_CHECK_CALC_ERROR([$1], [(1 ++ 2) + (0 0) = 1], [82],
[1.5-1.6: parse error, unexpected '+', expecting "number" or '-' or '('
1.15-1.16: parse error, unexpected "number"
calc: error: 0 != 1])
# Add a studid example demonstrating that Bison can further improve the
# error message. FIXME: Fix this ridiculous message.
-_AT_CHECK_CALC_ERROR([$1],
- [()],
- [21],
-[1.2-1.3: parse error, unexpected ')', expecting error or "number" or '-' or '('])
+_AT_CHECK_CALC_ERROR([$1], [()], [21],
+[1.2-1.3: parse error, unexpected ')', expecting "number" or '-' or '('])
AT_CLEANUP
])# AT_CHECK_CALC