# Checking GLR Parsing: Regression Tests -*- Autotest -*-
-# Copyright (C) 2002-2003, 2005-2007, 2009-2012 Free Software
+# Copyright (C) 2002-2003, 2005-2007, 2009-2013 Free Software
# Foundation, Inc.
# This program is free software: you can redistribute it and/or modify
int
main (int argc, char **argv)
{
+ int res;
input = stdin;
if (argc == 2 && !(input = fopen (argv[1], "r")))
return 3;
- int res = yyparse ();
+ res = yyparse ();
if (argc == 2 && fclose (input))
return 4;
return res;
}
int
-main(int argc, char* argv[])
+main (int argc, char* argv[])
{
+ int res;
input = stdin;
if (argc == 2 && !(input = fopen (argv[1], "r")))
return 3;
- int res = yyparse ();
+ res = yyparse ();
if (argc == 2 && fclose (input))
return 4;
return res;
;
%%
-]AT_YYLEX_DEFINE(["a"])[
]AT_YYERROR_DEFINE[
-int
-main (void)
-{
- return yyparse () != 1;
-}
+]AT_YYLEX_DEFINE(["a"])[
+]AT_MAIN_DEFINE[
]])
AT_BISON_OPTION_POPDEFS
]])
AT_COMPILE([glr-regr5])
-AT_PARSER_CHECK([[./glr-regr5]], 0, [],
+AT_PARSER_CHECK([[./glr-regr5]], 1, [],
[syntax is ambiguous
])
%%
]AT_YYERROR_DEFINE[
]AT_YYLEX_DEFINE(["a"])[
-int
-main (void)
-{
- return yyparse () != 1;
-}
+]AT_MAIN_DEFINE[
]])
AT_BISON_OPTION_POPDEFS
]])
AT_COMPILE([glr-regr6])
-AT_PARSER_CHECK([[./glr-regr6]], 0,
+AT_PARSER_CHECK([[./glr-regr6]], 1,
[Destructor called.
],
[syntax is ambiguous
## ------------------------------------------------------------------------- ##
## Incorrect default location for empty right-hand sides. Adapted from bug ##
-## report by Claudia Hermann. ##
+## report by Claudia Hermann. ##
## See http://lists.gnu.org/archive/html/bug-bison/2005-10/msg00069.html and ##
## http://lists.gnu.org/archive/html/bug-bison/2005-10/msg00072.html ##
## ------------------------------------------------------------------------- ##
%%
-PortClause : T_PORT InterfaceDeclaration T_PORT
- { printf("%d/%d - %d/%d - %d/%d\n",
- @1.first_column, @1.last_column,
- @2.first_column, @2.last_column,
- @3.first_column, @3.last_column); }
- ;
+PortClause : T_PORT InterfaceDeclaration T_PORT
+ { printf("%d/%d - %d/%d - %d/%d\n",
+ @1.first_column, @1.last_column,
+ @2.first_column, @2.last_column,
+ @3.first_column, @3.last_column); }
+ ;
-InterfaceDeclaration : OptConstantWord %dprec 1
- | OptSignalWord %dprec 2
- ;
+InterfaceDeclaration : OptConstantWord %dprec 1
+ | OptSignalWord %dprec 2
+ ;
-OptConstantWord : /* empty */
- | T_CONSTANT
- ;
+OptConstantWord : /* empty */
+ | T_CONSTANT
+ ;
-OptSignalWord : /* empty */
- { printf("empty: %d/%d\n", @$.first_column, @$.last_column); }
- | T_SIGNAL
- ;
+OptSignalWord : /* empty */
+ { printf("empty: %d/%d\n", @$.first_column, @$.last_column); }
+ | T_SIGNAL
+ ;
%%
}
}
-int
-main (void)
-{
- yyparse();
- return 0;
-}
+]AT_MAIN_DEFINE[
]])
AT_BISON_OPTION_POPDEFS
int exit_status = yyparse ();
if (parent_rhs_before_value)
{
- fprintf (stderr, "`parent_rhs_before' destructor not called.\n");
+ fprintf (stderr, "'parent_rhs_before' destructor not called.\n");
exit_status = 1;
}
if (merged_value)
{
- fprintf (stderr, "`merged' destructor not called.\n");
+ fprintf (stderr, "'merged' destructor not called.\n");
exit_status = 1;
}
if (parent_rhs_after_value)
{
- fprintf (stderr, "`PARENT_RHS_AFTER' destructor not called.\n");
+ fprintf (stderr, "'PARENT_RHS_AFTER' destructor not called.\n");
exit_status = 1;
}
return exit_status;
## ------------------------------------------------------------------------- ##
-## Incorrect lookahead during deterministic GLR. See ##
+## Incorrect lookahead during deterministic GLR. See ##
## <http://lists.gnu.org/archive/html/help-bison/2005-07/msg00017.html> and ##
## <http://lists.gnu.org/archive/html/bison-patches/2006-01/msg00060.html>. ##
## ------------------------------------------------------------------------- ##
{
printf ("'%c', yylval='", yychar);
if (yylval.value > ' ')
- printf ("%c", yylval.value);
+ printf ("%c", yylval.value);
printf ("', yylloc=(%d,%d),(%d,%d)",
- yylloc.first_line, yylloc.first_column,
- yylloc.last_line, yylloc.last_column);
+ yylloc.first_line, yylloc.first_column,
+ yylloc.last_line, yylloc.last_column);
}
printf ("\n");
}
| conflict defstate_look 'a' nonconflict2 'b' defstate_shift %dprec 2 {
USE ($3); USE ($5);
print_lookahead ("merge <- conflict defstate_look 'a' nonconflict2 'b'"
- " defstate_shift");
+ " defstate_shift");
}
;
USE ($1);
if (yychar != 'd' && yychar != YYEOF)
{
- fprintf (stderr, "Incorrect lookahead during stack explosion.\n");
+ fprintf (stderr, "Incorrect lookahead during stack explosion.\n");
}
}
;
USE ($1);
if (yychar != 'd' && yychar != YYEOF)
{
- fprintf (stderr, "Incorrect lookahead during stack explosion.\n");
+ fprintf (stderr, "Incorrect lookahead during stack explosion.\n");
}
}
;
USE ($1);
if (yychar != 'd' && yychar != YYEOF)
{
- fprintf (stderr, "Incorrect lookahead during stack explosion.\n");
+ fprintf (stderr, "Incorrect lookahead during stack explosion.\n");
}
}
;
{
if (yychar != YYEMPTY)
{
- fprintf (stderr,
- "Found lookahead where shouldn't during stack explosion.\n");
+ fprintf (stderr,
+ "Found lookahead where shouldn't during stack explosion.\n");
}
}
;
{
printf ("'%c', yylval='", yychar);
if (yylval.value > ' ')
- printf ("%c", yylval.value);
+ printf ("%c", yylval.value);
printf ("', yylloc=(%d,%d),(%d,%d)",
- yylloc.first_line, yylloc.first_column,
- yylloc.last_line, yylloc.last_column);
+ yylloc.first_line, yylloc.first_column,
+ yylloc.last_line, yylloc.last_column);
}
printf ("\n");
}
int exit_status = yyparse () != 1;
if (parent_rhs_before_value)
{
- fprintf (stderr, "`parent_rhs_before' destructor not called.\n");
+ fprintf (stderr, "'parent_rhs_before' destructor not called.\n");
exit_status = 1;
}
return exit_status;
return input[toknum++];
}
-int
-main (void)
-{
- return yyparse () != 1;
-}
+]AT_MAIN_DEFINE[
]])
AT_BISON_OPTION_POPDEFS
]])
AT_COMPILE([glr-regr17])
-AT_PARSER_CHECK([[./glr-regr17]], 0, [],
+AT_PARSER_CHECK([[./glr-regr17]], 1, [],
[1.1-2.2: syntax is ambiguous
])
%%
]AT_YYERROR_DEFINE[
]AT_YYLEX_DEFINE[
-int
-main (void)
-{
- return yyparse ();
-}
+]AT_MAIN_DEFINE[
]])
AT_BISON_OPTION_POPDEFS
AT_BISON_CHECK([[-o glr-regr18.c glr-regr18.y]], 1, [],
-[[glr-regr18.y:26.18-24: error: result type clash on merge function 'merge': <type2> != <type1>
-glr-regr18.y:25.18-24: previous declaration
-glr-regr18.y:27.13-19: error: result type clash on merge function 'merge': <type3> != <type2>
-glr-regr18.y:26.18-24: previous declaration
+[[glr-regr18.y:28.18-24: error: result type clash on merge function 'merge': <type2> != <type1>
+glr-regr18.y:27.18-24: previous declaration
+glr-regr18.y:29.13-19: error: result type clash on merge function 'merge': <type3> != <type2>
+glr-regr18.y:28.18-24: previous declaration
]])
AT_CLEANUP
AT_SETUP([Ambiguity reports])
-AT_BISON_OPTION_PUSHDEFS
+AT_BISON_OPTION_PUSHDEFS([%debug])
AT_DATA_GRAMMAR([input.y],
[[
%{
b: 'b';
d: /* nada. */;
%%
-]AT_YYLEX_DEFINE(["abc"])[
]AT_YYERROR_DEFINE[
-int
-main (void)
-{
- yydebug = 1;
- return !!yyparse ();
-}
+]AT_YYLEX_DEFINE(["abc"])[
+]AT_MAIN_DEFINE[
]])
AT_BISON_OPTION_POPDEFS
]])
AT_COMPILE([input])
-AT_PARSER_CHECK([[./input]], 1, [],
+AT_PARSER_CHECK([[./input --debug]], 1, [],
[Starting parse
Entering state 0
Reading a token: Next token is token 'a' ()
Reading a token: Next token is token 'b' ()
Shifting token 'b' ()
Entering state 3
-Reducing stack 0 by rule 3 (line 25):
+Reducing stack 0 by rule 3 (line 27):
$1 = token 'b' ()
-> $$ = nterm b ()
Entering state 4
Reading a token: Next token is token 'c' ()
Shifting token 'c' ()
Entering state 6
-Reducing stack 0 by rule 4 (line 26):
+Reducing stack 0 by rule 4 (line 28):
-> $$ = nterm d ()
Entering state 7
Reading a token: Now at end of input.
])
AT_CLEANUP
+
+
+## ----------------------------------------------------------------- ##
+## Predicates. ##
+## ##
+## http://lists.gnu.org/archive/html/bug-bison/2013-10/msg00004.html ##
+## ----------------------------------------------------------------- ##
+
+AT_SETUP([Predicates])
+
+# FIXME: We need genuine test cases with uses of %?.
+
+AT_DATA_GRAMMAR([input.y],
+[[%glr-parser
+%expect-rr 1
+%%
+// Exercise "%?{...}" and "%? {...}".
+widget:
+ %? {new_syntax} "widget" id new_args { $$ = f($3, $4); }
+| %?{!new_syntax} "widget" id old_args { $$ = f($3, $4); }
+;
+id:;
+new_args:;
+old_args:;
+%%
+]])
+
+AT_BISON_CHECK([[input.y]])
+
+AT_CLEANUP