+## ----------------- ##
+## YYSTYPE typedef. ##
+## ----------------- ##
+
+AT_SETUP([YYSTYPE typedef])
+
+AT_DATA_GRAMMAR([input.y],
+[[%{
+void yyerror (char const *);
+int yylex (void);
+typedef union { char const *val; } YYSTYPE;
+%}
+
+%type <val> program
+
+%%
+
+program: { $$ = ""; };
+]])
+
+AT_CHECK([bison -o input.c input.y])
+AT_COMPILE([input.o], [-c input.c])
+
+AT_CLEANUP
+
+
+
## ------------------------------------- ##
## Early token definitions with --yacc. ##
## ------------------------------------- ##
input.y:6.1: invalid character: `%'
input.y:6.2: invalid character: `-'
input.y:7.1-8.0: missing `%}' at end of file
+input.y:7.1-8.0: syntax error, unexpected %{...%}
]])
AT_CLEANUP
void yyerror (const char *s);
int yylex (void);
%}
-[%%
+[%token QUOTES "\""
+%token TICK "'"
+%%
exp:
'\'' "\'"
| '\"' "\""
struct_stat: /* empty. */ | if else;
if: "if" "const" "then" statement;
else: "else" statement;
+%token IF "if";
+%token CONST "const";
+%token THEN "then";
+%token ELSE "else";
%%
]])
AT_DATA_GRAMMAR([input.y],
[[%{
#include <stdio.h>
-void yyerror (char const *msg);
-int yylex (void);
+static void yyerror (char const *msg);
+static int yylex (void);
%}
%error-verbose
%%
-void
+static void
yyerror (char const *msg)
{
fprintf (stderr, "%s\n", msg);
}
-int
+static int
yylex (void)
{
return 'a';
]])
AT_CLEANUP
+
+
+
+## --------------------------------- ##
+## String alias declared after use. ##
+## --------------------------------- ##
+
+AT_SETUP([String alias declared after use])
+
+# Bison once incorrectly asserted that the symbol number for either a token or
+# its alias was the highest symbol number so far at the point of the alias
+# declaration. That was true unless the declaration appeared after their first
+# uses.
+
+AT_DATA([input.y],
+[[%%
+start: 'a' "A" 'b';
+%token 'a' "A";
+]])
+
+AT_CHECK([bison -t -o input.c input.y])
+
+AT_CLEANUP
+
+
+
+## --------------------------- ##
+## Undeclared string literal. ##
+## --------------------------- ##
+
+AT_SETUP([Undeclared string literal])
+
+# Bison once allowed a string literal to be used in the grammar without any
+# declaration assigning it as an alias of another token.
+
+AT_DATA([input.y],
+[[%%
+start: "abc";
+]])
+
+AT_CHECK([bison -t -o input.c input.y], [1], [],
+[[input.y:2.8-12: "abc" undeclared
+]])
+
+AT_CLEANUP