mirror of
https://git.savannah.gnu.org/git/bison.git
synced 2026-03-09 12:23:04 +00:00
glr: tests: add support for the YYDEBUG envvar
When debugging these parsers, we really need debug traces. Enable them, and bind them to $YYDEBUG. * tests/glr-regression.at: Support the YYDEBUG envvar. As a consequence, now that syntactic ambiguities are reported, adjust the expected output. (No users destructors if stack 0 deleted): Don't return 0 on memory exhaustion, really return the parser's status, and adust expectations.
This commit is contained in:
@@ -62,6 +62,7 @@ static YYSTYPE exprMerge (YYSTYPE x0, YYSTYPE x1);
|
||||
}
|
||||
|
||||
%define parse.assert
|
||||
%define parse.trace
|
||||
%glr-parser
|
||||
%expect 1
|
||||
]$1[
|
||||
@@ -105,6 +106,8 @@ main (int argc, const char* argv[])
|
||||
{
|
||||
assert (argc == 2); (void) argc;
|
||||
input = argv[1];
|
||||
if (getenv ("YYDEBUG"))
|
||||
yydebug = 1;
|
||||
return yyparse ();
|
||||
}
|
||||
]])
|
||||
@@ -159,6 +162,7 @@ AT_DATA_GRAMMAR([glr-regr2a.y],
|
||||
}
|
||||
|
||||
%define parse.assert
|
||||
%define parse.trace
|
||||
%glr-parser
|
||||
%expect 2
|
||||
]$1[
|
||||
@@ -237,6 +241,8 @@ main (int argc, char **argv)
|
||||
input = stdin;
|
||||
if (argc == 2 && !(input = fopen (argv[1], "r")))
|
||||
return 3;
|
||||
if (getenv ("YYDEBUG"))
|
||||
yydebug = 1;
|
||||
res = yyparse ();
|
||||
if (argc == 2 && fclose (input))
|
||||
return 4;
|
||||
@@ -305,6 +311,7 @@ static int MergeRule (int x0, int x1);
|
||||
}
|
||||
|
||||
%define parse.assert
|
||||
%define parse.trace
|
||||
%glr-parser
|
||||
%expect 1
|
||||
%expect-rr 2
|
||||
@@ -381,6 +388,8 @@ main (int argc, char* argv[])
|
||||
input = stdin;
|
||||
if (argc == 2 && !(input = fopen (argv[1], "r")))
|
||||
return 3;
|
||||
if (getenv ("YYDEBUG"))
|
||||
yydebug = 1;
|
||||
res = yyparse ();
|
||||
if (argc == 2 && fclose (input))
|
||||
return 4;
|
||||
@@ -422,6 +431,7 @@ AT_BISON_OPTION_PUSHDEFS([%glr-parser $1])
|
||||
AT_DATA_GRAMMAR([glr-regr4.y],
|
||||
[[
|
||||
%define parse.assert
|
||||
%define parse.trace
|
||||
%union { char *ptr; }
|
||||
%type <ptr> S A A1 A2 B
|
||||
%glr-parser
|
||||
@@ -464,7 +474,10 @@ B: 'a' { $$ = make_value ("B", "'a'"); } ;
|
||||
int
|
||||
main (void)
|
||||
{
|
||||
int status = yyparse ();
|
||||
int status = -1;
|
||||
if (getenv ("YYDEBUG"))
|
||||
yydebug = 1;
|
||||
status = yyparse ();
|
||||
while (ptrs_next != ptrs)
|
||||
free (*--ptrs_next);
|
||||
return status;
|
||||
@@ -526,6 +539,7 @@ AT_DATA_GRAMMAR([glr-regr5.y],
|
||||
}
|
||||
|
||||
%define parse.assert
|
||||
%define parse.trace
|
||||
%glr-parser
|
||||
%expect 0
|
||||
%expect-rr 1
|
||||
@@ -558,7 +572,16 @@ start:
|
||||
AT_FULL_COMPILE([glr-regr5],,,, [-rall])
|
||||
|
||||
AT_PARSER_CHECK([[glr-regr5]], 1, [],
|
||||
[syntax is ambiguous
|
||||
[Ambiguity detected.
|
||||
Option 1,
|
||||
start -> <Rule 1, tokens 1 .. 1>
|
||||
'a' <tokens 1 .. 1>
|
||||
|
||||
Option 2,
|
||||
start -> <Rule 2, tokens 1 .. 1>
|
||||
'a' <tokens 1 .. 1>
|
||||
|
||||
syntax is ambiguous
|
||||
])
|
||||
|
||||
AT_BISON_OPTION_POPDEFS
|
||||
@@ -590,6 +613,7 @@ AT_DATA_GRAMMAR([glr-regr6.y],
|
||||
}
|
||||
|
||||
%define parse.assert
|
||||
%define parse.trace
|
||||
%glr-parser
|
||||
%expect-rr 1
|
||||
]$1[
|
||||
@@ -616,7 +640,16 @@ AT_FULL_COMPILE([glr-regr6],,,, [-rall])
|
||||
AT_PARSER_CHECK([[glr-regr6]], 1,
|
||||
[Destructor called.
|
||||
],
|
||||
[syntax is ambiguous
|
||||
[Ambiguity detected.
|
||||
Option 1,
|
||||
start -> <Rule 1, tokens 1 .. 1>
|
||||
'a' <tokens 1 .. 1>
|
||||
|
||||
Option 2,
|
||||
start -> <Rule 2, tokens 1 .. 1>
|
||||
'a' <tokens 1 .. 1>
|
||||
|
||||
syntax is ambiguous
|
||||
])
|
||||
|
||||
AT_BISON_OPTION_POPDEFS
|
||||
@@ -658,6 +691,7 @@ AT_DATA_GRAMMAR([glr-regr7.y],
|
||||
}
|
||||
|
||||
%define parse.assert
|
||||
%define parse.trace
|
||||
%glr-parser
|
||||
%expect-rr 2
|
||||
]$1[
|
||||
@@ -703,7 +737,10 @@ stack2: 'a' ;
|
||||
int
|
||||
main (void)
|
||||
{
|
||||
int status = yyparse ();
|
||||
int status;
|
||||
if (getenv ("YYDEBUG"))
|
||||
yydebug = 1;
|
||||
status = yyparse ();
|
||||
while (tail)
|
||||
{
|
||||
count_node *prev = tail->prev;
|
||||
@@ -752,6 +789,7 @@ AT_DATA_GRAMMAR([glr-regr8.y],
|
||||
}
|
||||
|
||||
%define parse.assert
|
||||
%define parse.trace
|
||||
%glr-parser
|
||||
%expect-rr 1
|
||||
]$1[
|
||||
@@ -853,6 +891,7 @@ AT_DATA_GRAMMAR([glr-regr9.y],
|
||||
}
|
||||
|
||||
%define parse.assert
|
||||
%define parse.trace
|
||||
%glr-parser
|
||||
%expect-rr 2
|
||||
]$1[
|
||||
@@ -891,20 +930,23 @@ ambig2: 'a' ;
|
||||
int
|
||||
main (void)
|
||||
{
|
||||
int exit_status;
|
||||
exit_status = yyparse ();
|
||||
int status;
|
||||
if (getenv ("YYDEBUG"))
|
||||
yydebug = 1;
|
||||
status = yyparse ();
|
||||
if (tokens != destructors)
|
||||
{
|
||||
fprintf (stderr, "Tokens = %d, Destructors = %d\n", tokens, destructors);
|
||||
return 1;
|
||||
return 10;
|
||||
}
|
||||
return !exit_status;
|
||||
return status;
|
||||
}
|
||||
]])
|
||||
|
||||
AT_FULL_COMPILE([glr-regr9],,,, [-rall])
|
||||
|
||||
AT_PARSER_CHECK([[glr-regr9]], 0, [],
|
||||
# Exit 2: memory exhausted.
|
||||
AT_PARSER_CHECK([[glr-regr9]], 2, [],
|
||||
[memory exhausted
|
||||
])
|
||||
|
||||
@@ -938,6 +980,7 @@ AT_DATA_GRAMMAR([glr-regr10.y],
|
||||
}
|
||||
|
||||
%define parse.assert
|
||||
%define parse.trace
|
||||
%glr-parser
|
||||
%expect-rr 1
|
||||
]$1[
|
||||
@@ -963,6 +1006,8 @@ main (void)
|
||||
int i;
|
||||
for (i = 0; i < GARBAGE_SIZE; i+=1)
|
||||
garbage[i] = 108;
|
||||
if (getenv ("YYDEBUG"))
|
||||
yydebug = 1;
|
||||
return yyparse ();
|
||||
}
|
||||
]])
|
||||
@@ -1001,6 +1046,7 @@ AT_DATA_GRAMMAR([glr-regr11.y],
|
||||
}
|
||||
|
||||
%define parse.assert
|
||||
%define parse.trace
|
||||
%glr-parser
|
||||
%expect-rr 1
|
||||
]$1[
|
||||
@@ -1025,13 +1071,16 @@ start:
|
||||
int
|
||||
main (void)
|
||||
{
|
||||
int exit_status = yyparse ();
|
||||
int status;
|
||||
if (getenv ("YYDEBUG"))
|
||||
yydebug = 1;
|
||||
status = yyparse ();
|
||||
if (destructors != 1)
|
||||
{
|
||||
fprintf (stderr, "Destructor calls: %d\n", destructors);
|
||||
return 1;
|
||||
}
|
||||
return exit_status;
|
||||
return status;
|
||||
}
|
||||
]])
|
||||
|
||||
@@ -1062,6 +1111,7 @@ AT_BISON_OPTION_PUSHDEFS([%glr-parser $1])
|
||||
AT_DATA_GRAMMAR([glr-regr12.y],
|
||||
[[
|
||||
%define parse.assert
|
||||
%define parse.trace
|
||||
%glr-parser
|
||||
%expect 1
|
||||
%expect-rr 1
|
||||
@@ -1146,23 +1196,26 @@ merge (YYSTYPE s1, YYSTYPE s2)
|
||||
int
|
||||
main (void)
|
||||
{
|
||||
int exit_status = yyparse ();
|
||||
int status;
|
||||
if (getenv ("YYDEBUG"))
|
||||
yydebug = 1;
|
||||
status = yyparse ();
|
||||
if (parent_rhs_before_value)
|
||||
{
|
||||
fprintf (stderr, "'parent_rhs_before' destructor not called.\n");
|
||||
exit_status = 1;
|
||||
status = 1;
|
||||
}
|
||||
if (merged_value)
|
||||
{
|
||||
fprintf (stderr, "'merged' destructor not called.\n");
|
||||
exit_status = 1;
|
||||
status = 1;
|
||||
}
|
||||
if (parent_rhs_after_value)
|
||||
{
|
||||
fprintf (stderr, "'PARENT_RHS_AFTER' destructor not called.\n");
|
||||
exit_status = 1;
|
||||
status = 1;
|
||||
}
|
||||
return exit_status;
|
||||
return status;
|
||||
}
|
||||
]])
|
||||
|
||||
@@ -1212,6 +1265,7 @@ AT_DATA_GRAMMAR([glr-regr13.y],
|
||||
}
|
||||
|
||||
%define parse.assert
|
||||
%define parse.trace
|
||||
%locations
|
||||
%glr-parser
|
||||
]$1[
|
||||
@@ -1293,6 +1347,8 @@ main (void)
|
||||
yychar = '#'; /* Not a token in the grammar. */
|
||||
yylval.value = '!';
|
||||
]])[
|
||||
if (getenv ("YYDEBUG"))
|
||||
yydebug = 1;
|
||||
return yyparse ();
|
||||
}
|
||||
]])
|
||||
@@ -1356,6 +1412,7 @@ AT_DATA_GRAMMAR([glr-regr14.y],
|
||||
nondeterministic operation does not start. */
|
||||
|
||||
%define parse.assert
|
||||
%define parse.trace
|
||||
%type <value> 'a' 'b' 'c' 'd' stack_explosion
|
||||
%glr-parser
|
||||
%expect 0
|
||||
@@ -1524,6 +1581,8 @@ main (void)
|
||||
yychar = '#'; /* Not a token in the grammar. */
|
||||
yylval.value = '!';
|
||||
]])[
|
||||
if (getenv ("YYDEBUG"))
|
||||
yydebug = 1;
|
||||
return yyparse ();
|
||||
}
|
||||
]])
|
||||
@@ -1569,6 +1628,7 @@ AT_BISON_OPTION_PUSHDEFS([%glr-parser $1])
|
||||
AT_DATA_GRAMMAR([glr-regr15.y],
|
||||
[[
|
||||
%define parse.assert
|
||||
%define parse.trace
|
||||
%glr-parser
|
||||
%expect 0
|
||||
%expect-rr 2
|
||||
@@ -1623,20 +1683,32 @@ ambiguity2: ;
|
||||
int
|
||||
main (void)
|
||||
{
|
||||
int exit_status = yyparse () != 1;
|
||||
int status;
|
||||
if (getenv ("YYDEBUG"))
|
||||
yydebug = 1;
|
||||
status = yyparse () != 1;
|
||||
if (parent_rhs_before_value)
|
||||
{
|
||||
fprintf (stderr, "'parent_rhs_before' destructor not called.\n");
|
||||
exit_status = 1;
|
||||
status = 1;
|
||||
}
|
||||
return exit_status;
|
||||
return status;
|
||||
}
|
||||
]])
|
||||
|
||||
AT_FULL_COMPILE([glr-regr15],,,, [-rall])
|
||||
|
||||
AT_PARSER_CHECK([[glr-regr15]], 0, [],
|
||||
[syntax is ambiguous
|
||||
[Ambiguity detected.
|
||||
Option 1,
|
||||
ambiguity -> <Rule 6, empty>
|
||||
ambiguity1 -> <Rule 8, empty>
|
||||
|
||||
Option 2,
|
||||
ambiguity -> <Rule 7, empty>
|
||||
ambiguity2 -> <Rule 9, empty>
|
||||
|
||||
syntax is ambiguous
|
||||
])
|
||||
|
||||
AT_BISON_OPTION_POPDEFS
|
||||
@@ -1662,6 +1734,7 @@ AT_BISON_OPTION_PUSHDEFS([%glr-parser $1])
|
||||
AT_DATA_GRAMMAR([glr-regr16.y],
|
||||
[[
|
||||
%define parse.assert
|
||||
%define parse.trace
|
||||
%glr-parser
|
||||
%expect 0
|
||||
%expect-rr 1
|
||||
@@ -1694,13 +1767,16 @@ alt2: ;
|
||||
int
|
||||
main (void)
|
||||
{
|
||||
int exit_status = yyparse () != 1;
|
||||
int status;
|
||||
if (getenv ("YYDEBUG"))
|
||||
yydebug = 1;
|
||||
status = yyparse () != 1;
|
||||
if (lookahead_value)
|
||||
{
|
||||
fprintf (stderr, "Lookahead destructor not called.\n");
|
||||
exit_status = 1;
|
||||
status = 1;
|
||||
}
|
||||
return exit_status;
|
||||
return status;
|
||||
}
|
||||
]])
|
||||
|
||||
@@ -1734,6 +1810,7 @@ AT_BISON_OPTION_PUSHDEFS([%glr-parser %locations $1])
|
||||
AT_DATA_GRAMMAR([glr-regr17.y],
|
||||
[[
|
||||
%define parse.assert
|
||||
%define parse.trace
|
||||
%glr-parser
|
||||
%expect 0
|
||||
%expect-rr 3
|
||||
@@ -1791,7 +1868,26 @@ empty2: ;
|
||||
AT_FULL_COMPILE([glr-regr17],,,, [-rall])
|
||||
|
||||
AT_PARSER_CHECK([[glr-regr17]], 1, [],
|
||||
[1.1-2.2: syntax is ambiguous
|
||||
[Ambiguity detected.
|
||||
Option 1,
|
||||
start -> <Rule 1, tokens 1 .. 2>
|
||||
ambig1 -> <Rule 4, tokens 1 .. 2>
|
||||
sub_ambig2 -> <Rule 8, tokens 1 .. 2>
|
||||
empty2 -> <Rule 10, empty>
|
||||
'a' <tokens 1 .. 1>
|
||||
'b' <tokens 2 .. 2>
|
||||
empty1 -> <Rule 9, empty>
|
||||
|
||||
Option 2,
|
||||
start -> <Rule 2, tokens 1 .. 2>
|
||||
ambig2 -> <Rule 6, tokens 1 .. 2>
|
||||
sub_ambig2 -> <Rule 8, tokens 1 .. 2>
|
||||
empty2 -> <Rule 10, empty>
|
||||
'a' <tokens 1 .. 1>
|
||||
'b' <tokens 2 .. 2>
|
||||
empty2 -> <Rule 10, empty>
|
||||
|
||||
1.1-2.2: syntax is ambiguous
|
||||
])
|
||||
|
||||
AT_BISON_OPTION_POPDEFS
|
||||
@@ -1816,6 +1912,7 @@ m4_pushdef([AT_TEST],
|
||||
AT_BISON_OPTION_PUSHDEFS([%glr-parser $1])
|
||||
AT_DATA_GRAMMAR([glr-regr18.y],
|
||||
[[%define parse.assert
|
||||
%define parse.trace
|
||||
%glr-parser
|
||||
]$1[
|
||||
|
||||
@@ -1849,10 +1946,10 @@ sym3: %merge<merge> { $$ = 0; } ;
|
||||
]])
|
||||
|
||||
AT_BISON_CHECK([[-o glr-regr18.c -rall glr-regr18.y]], 1, [],
|
||||
[[glr-regr18.y:29.18-24: error: result type clash on merge function 'merge': <type2> != <type1>
|
||||
glr-regr18.y:28.18-24: note: previous declaration
|
||||
glr-regr18.y:30.13-19: error: result type clash on merge function 'merge': <type3> != <type2>
|
||||
[[glr-regr18.y:30.18-24: error: result type clash on merge function 'merge': <type2> != <type1>
|
||||
glr-regr18.y:29.18-24: note: previous declaration
|
||||
glr-regr18.y:31.13-19: error: result type clash on merge function 'merge': <type3> != <type2>
|
||||
glr-regr18.y:30.18-24: note: previous declaration
|
||||
]])
|
||||
|
||||
AT_BISON_OPTION_POPDEFS
|
||||
@@ -1882,6 +1979,7 @@ AT_DATA_GRAMMAR([input.y],
|
||||
}
|
||||
|
||||
%define parse.assert
|
||||
%define parse.trace
|
||||
%debug
|
||||
%glr-parser
|
||||
%expect 0
|
||||
@@ -1917,7 +2015,7 @@ Reading a token
|
||||
Next token is token 'b' ()
|
||||
Shifting token 'b' ()
|
||||
Entering state 3
|
||||
Reducing stack 0 by rule 3 (line 29):
|
||||
Reducing stack 0 by rule 3 (line 30):
|
||||
$][1 = token 'b' ()
|
||||
-> $][$ = nterm b ()
|
||||
Entering state 4
|
||||
@@ -1925,7 +2023,7 @@ Reading a token
|
||||
Next token is token 'c' ()
|
||||
Shifting token 'c' ()
|
||||
Entering state 6
|
||||
Reducing stack 0 by rule 4 (line 30):
|
||||
Reducing stack 0 by rule 4 (line 31):
|
||||
-> $][$ = nterm d ()
|
||||
Entering state 7
|
||||
Reading a token
|
||||
@@ -1933,10 +2031,10 @@ Now at end of input.
|
||||
Stack 0 Entering state 7
|
||||
Now at end of input.
|
||||
Splitting off stack 1 from 0.
|
||||
Reduced stack 1 by rule 2 (line 27); action deferred. Now in state 2.
|
||||
Reduced stack 1 by rule 2 (line 28); action deferred. Now in state 2.
|
||||
Stack 1 Entering state 2
|
||||
Now at end of input.
|
||||
Reduced stack 0 by rule 1 (line 26); action deferred. Now in state 2.
|
||||
Reduced stack 0 by rule 1 (line 27); action deferred. Now in state 2.
|
||||
Merging stack 0 into stack 1.
|
||||
Stack 1 Entering state 2
|
||||
Now at end of input.
|
||||
@@ -1993,6 +2091,7 @@ m4_pushdef([AT_TEST],
|
||||
AT_BISON_OPTION_PUSHDEFS([%glr-parser $1])
|
||||
AT_DATA_GRAMMAR([input.y],
|
||||
[[%define parse.assert
|
||||
%define parse.trace
|
||||
%glr-parser
|
||||
%define parse.error verbose
|
||||
%expect-rr 1
|
||||
@@ -2033,6 +2132,8 @@ main (int argc, const char* argv[])
|
||||
// Then the input.
|
||||
new_syntax = argv[1][0] == 'N';
|
||||
input = argv[1] + 1;
|
||||
if (getenv ("YYDEBUG"))
|
||||
yydebug = 1;
|
||||
return yyparse ();
|
||||
}
|
||||
]])
|
||||
|
||||
Reference in New Issue
Block a user