# Bison Reports. -*- Autotest -*-
# Copyright (C) 2018-2019 Free Software Foundation, Inc.
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see .
AT_BANNER([[Test reports.]])
## --------- ##
## Reports. ##
## --------- ##
AT_SETUP([Reports])
AT_KEYWORDS([report])
AT_BISON_OPTION_PUSHDEFS
AT_DATA([input.yy],
[[%token
END 0 "end of file"
ASSIGN ":="
INCR "incr"
;
%token IDENTIFIER "identifier"
%type id
%token NUMBER "number"
%type exp
%%
%start unit;
unit: assignments exp { driver.result = $2; };
assignments:
%empty {}
| assignments assignment {};
assignment:
id ":=" exp { driver.variables[$id] = $exp; };
id:
"identifier";
exp:
"incr" exp { $$ = 1; } { $$ = 10; } exp { $$ = $2 + $3 + $4 + $5; }
| "(" exp ")" { std::swap ($$, $2); }
| "identifier" { $$ = driver.variables[$1]; }
| "number" { std::swap ($$, $1); };
]])
AT_BISON_CHECK([-o input.cc -v --graph=input.gv --xml input.yy])
# Check the contents of the report.
AT_CHECK([cat input.output], [],
[[Grammar
0 $accept: unit "end of file"
1 unit: assignments exp
2 assignments: %empty
3 | assignments assignment
4 assignment: id ":=" exp
5 id: "identifier"
6 @1: %empty
7 @2: %empty
8 exp: "incr" exp @1 @2 exp
9 | "(" exp ")"
10 | "identifier"
11 | "number"
Terminals, with rules where they appear
"end of file" (0) 0
error (256)
":=" (258) 4
"incr" (259) 8
"identifier" (260) 5 10
"number" (261) 11
"(" (262) 9
")" (263) 9
Nonterminals, with rules where they appear
$accept (9)
on left: 0
unit (10)
on left: 1
on right: 0
assignments (11)
on left: 2 3
on right: 1 3
assignment (12)
on left: 4
on right: 3
id (13)
on left: 5
on right: 4
exp (14)
on left: 8 9 10 11
on right: 1 4 8 9
@1 (15)
on left: 6
on right: 8
@2 (16)
on left: 7
on right: 8
State 0
0 $accept: . unit "end of file"
$default reduce using rule 2 (assignments)
unit go to state 1
assignments go to state 2
State 1
0 $accept: unit . "end of file"
"end of file" shift, and go to state 3
State 2
1 unit: assignments . exp
3 assignments: assignments . assignment
"incr" shift, and go to state 4
"identifier" shift, and go to state 5
"number" shift, and go to state 6
"(" shift, and go to state 7
assignment go to state 8
id go to state 9
exp go to state 10
State 3
0 $accept: unit "end of file" .
$default accept
State 4
8 exp: "incr" . exp @1 @2 exp
"incr" shift, and go to state 4
"identifier" shift, and go to state 11
"number" shift, and go to state 6
"(" shift, and go to state 7
exp go to state 12
State 5
5 id: "identifier" .
10 exp: "identifier" .
"end of file" reduce using rule 10 (exp)
$default reduce using rule 5 (id)
State 6
11 exp: "number" .
$default reduce using rule 11 (exp)
State 7
9 exp: "(" . exp ")"
"incr" shift, and go to state 4
"identifier" shift, and go to state 11
"number" shift, and go to state 6
"(" shift, and go to state 7
exp go to state 13
State 8
3 assignments: assignments assignment .
$default reduce using rule 3 (assignments)
State 9
4 assignment: id . ":=" exp
":=" shift, and go to state 14
State 10
1 unit: assignments exp .
$default reduce using rule 1 (unit)
State 11
10 exp: "identifier" .
$default reduce using rule 10 (exp)
State 12
8 exp: "incr" exp . @1 @2 exp
$default reduce using rule 6 (@1)
@1 go to state 15
State 13
9 exp: "(" exp . ")"
")" shift, and go to state 16
State 14
4 assignment: id ":=" . exp
"incr" shift, and go to state 4
"identifier" shift, and go to state 11
"number" shift, and go to state 6
"(" shift, and go to state 7
exp go to state 17
State 15
8 exp: "incr" exp @1 . @2 exp
$default reduce using rule 7 (@2)
@2 go to state 18
State 16
9 exp: "(" exp ")" .
$default reduce using rule 9 (exp)
State 17
4 assignment: id ":=" exp .
$default reduce using rule 4 (assignment)
State 18
8 exp: "incr" exp @1 @2 . exp
"incr" shift, and go to state 4
"identifier" shift, and go to state 11
"number" shift, and go to state 6
"(" shift, and go to state 7
exp go to state 19
State 19
8 exp: "incr" exp @1 @2 exp .
$default reduce using rule 8 (exp)
]])
# Now generate verbose reports.
AT_BISON_CHECK([-o input.cc -rall --graph=input.gv --xml input.yy])
# Check the contents of the report.
AT_CHECK([cat input.output], [],
[[Grammar
0 $accept: unit "end of file"
1 unit: assignments exp
2 assignments: %empty
3 | assignments assignment
4 assignment: id ":=" exp
5 id: "identifier"
6 @1: %empty
7 @2: %empty
8 exp: "incr" exp @1 @2 exp
9 | "(" exp ")"
10 | "identifier"
11 | "number"
Terminals, with rules where they appear
"end of file" (0) 0
error (256)
":=" (258) 4
"incr" (259) 8
"identifier" (260) 5 10
"number" (261) 11
"(" (262) 9
")" (263) 9
Nonterminals, with rules where they appear
$accept (9)
on left: 0
unit (10)
on left: 1
on right: 0
assignments (11)
on left: 2 3
on right: 1 3
assignment (12)
on left: 4
on right: 3
id (13)
on left: 5
on right: 4
exp (14)
on left: 8 9 10 11
on right: 1 4 8 9
@1 (15)
on left: 6
on right: 8
@2 (16)
on left: 7
on right: 8
State 0
0 $accept: . unit "end of file"
1 unit: . assignments exp
2 assignments: . %empty
3 | . assignments assignment
$default reduce using rule 2 (assignments)
unit go to state 1
assignments go to state 2
State 1
0 $accept: unit . "end of file"
"end of file" shift, and go to state 3
State 2
1 unit: assignments . exp
3 assignments: assignments . assignment
4 assignment: . id ":=" exp
5 id: . "identifier"
8 exp: . "incr" exp @1 @2 exp
9 | . "(" exp ")"
10 | . "identifier"
11 | . "number"
"incr" shift, and go to state 4
"identifier" shift, and go to state 5
"number" shift, and go to state 6
"(" shift, and go to state 7
assignment go to state 8
id go to state 9
exp go to state 10
State 3
0 $accept: unit "end of file" .
$default accept
State 4
8 exp: . "incr" exp @1 @2 exp
8 | "incr" . exp @1 @2 exp
9 | . "(" exp ")"
10 | . "identifier"
11 | . "number"
"incr" shift, and go to state 4
"identifier" shift, and go to state 11
"number" shift, and go to state 6
"(" shift, and go to state 7
exp go to state 12
State 5
5 id: "identifier" . [":="]
10 exp: "identifier" . ["end of file"]
"end of file" reduce using rule 10 (exp)
$default reduce using rule 5 (id)
State 6
11 exp: "number" .
$default reduce using rule 11 (exp)
State 7
8 exp: . "incr" exp @1 @2 exp
9 | . "(" exp ")"
9 | "(" . exp ")"
10 | . "identifier"
11 | . "number"
"incr" shift, and go to state 4
"identifier" shift, and go to state 11
"number" shift, and go to state 6
"(" shift, and go to state 7
exp go to state 13
State 8
3 assignments: assignments assignment .
$default reduce using rule 3 (assignments)
State 9
4 assignment: id . ":=" exp
":=" shift, and go to state 14
State 10
1 unit: assignments exp .
$default reduce using rule 1 (unit)
State 11
10 exp: "identifier" .
$default reduce using rule 10 (exp)
State 12
6 @1: . %empty
8 exp: "incr" exp . @1 @2 exp
$default reduce using rule 6 (@1)
@1 go to state 15
State 13
9 exp: "(" exp . ")"
")" shift, and go to state 16
State 14
4 assignment: id ":=" . exp
8 exp: . "incr" exp @1 @2 exp
9 | . "(" exp ")"
10 | . "identifier"
11 | . "number"
"incr" shift, and go to state 4
"identifier" shift, and go to state 11
"number" shift, and go to state 6
"(" shift, and go to state 7
exp go to state 17
State 15
7 @2: . %empty
8 exp: "incr" exp @1 . @2 exp
$default reduce using rule 7 (@2)
@2 go to state 18
State 16
9 exp: "(" exp ")" .
$default reduce using rule 9 (exp)
State 17
4 assignment: id ":=" exp .
$default reduce using rule 4 (assignment)
State 18
8 exp: . "incr" exp @1 @2 exp
8 | "incr" exp @1 @2 . exp
9 | . "(" exp ")"
10 | . "identifier"
11 | . "number"
"incr" shift, and go to state 4
"identifier" shift, and go to state 11
"number" shift, and go to state 6
"(" shift, and go to state 7
exp go to state 19
State 19
8 exp: "incr" exp @1 @2 exp .
$default reduce using rule 8 (exp)
]])
AT_CHECK([sed -e '1s/GNU Bison .*\.$/GNU Bison VERSION./' input.gv], [],
[[// Generated by GNU Bison VERSION.
// Report bugs to .
// Home page: .
digraph "input.yy"
{
node [fontname = courier, shape = box, colorscheme = paired6]
edge [fontname = courier]
0 [label="State 0\n\l 0 $accept: . unit \"end of file\"\l 1 unit: . assignments exp\l 2 assignments: . %empty\l 3 | . assignments assignment\l"]
0 -> 1 [style=dashed label="unit"]
0 -> 2 [style=dashed label="assignments"]
0 -> "0R2" [style=solid]
"0R2" [label="R2", fillcolor=3, shape=diamond, style=filled]
1 [label="State 1\n\l 0 $accept: unit . \"end of file\"\l"]
1 -> 3 [style=solid label="\"end of file\""]
2 [label="State 2\n\l 1 unit: assignments . exp\l 3 assignments: assignments . assignment\l 4 assignment: . id \":=\" exp\l 5 id: . \"identifier\"\l 8 exp: . \"incr\" exp @1 @2 exp\l 9 | . \"(\" exp \")\"\l 10 | . \"identifier\"\l 11 | . \"number\"\l"]
2 -> 4 [style=solid label="\"incr\""]
2 -> 5 [style=solid label="\"identifier\""]
2 -> 6 [style=solid label="\"number\""]
2 -> 7 [style=solid label="\"(\""]
2 -> 8 [style=dashed label="assignment"]
2 -> 9 [style=dashed label="id"]
2 -> 10 [style=dashed label="exp"]
3 [label="State 3\n\l 0 $accept: unit \"end of file\" .\l"]
3 -> "3R0" [style=solid]
"3R0" [label="Acc", fillcolor=1, shape=diamond, style=filled]
4 [label="State 4\n\l 8 exp: . \"incr\" exp @1 @2 exp\l 8 | \"incr\" . exp @1 @2 exp\l 9 | . \"(\" exp \")\"\l 10 | . \"identifier\"\l 11 | . \"number\"\l"]
4 -> 4 [style=solid label="\"incr\""]
4 -> 11 [style=solid label="\"identifier\""]
4 -> 6 [style=solid label="\"number\""]
4 -> 7 [style=solid label="\"(\""]
4 -> 12 [style=dashed label="exp"]
5 [label="State 5\n\l 5 id: \"identifier\" . [\":=\"]\l 10 exp: \"identifier\" . [\"end of file\"]\l"]
5 -> "5R5" [style=solid]
"5R5" [label="R5", fillcolor=3, shape=diamond, style=filled]
5 -> "5R10" [label="[\"end of file\"]", style=solid]
"5R10" [label="R10", fillcolor=3, shape=diamond, style=filled]
6 [label="State 6\n\l 11 exp: \"number\" .\l"]
6 -> "6R11" [style=solid]
"6R11" [label="R11", fillcolor=3, shape=diamond, style=filled]
7 [label="State 7\n\l 8 exp: . \"incr\" exp @1 @2 exp\l 9 | . \"(\" exp \")\"\l 9 | \"(\" . exp \")\"\l 10 | . \"identifier\"\l 11 | . \"number\"\l"]
7 -> 4 [style=solid label="\"incr\""]
7 -> 11 [style=solid label="\"identifier\""]
7 -> 6 [style=solid label="\"number\""]
7 -> 7 [style=solid label="\"(\""]
7 -> 13 [style=dashed label="exp"]
8 [label="State 8\n\l 3 assignments: assignments assignment .\l"]
8 -> "8R3" [style=solid]
"8R3" [label="R3", fillcolor=3, shape=diamond, style=filled]
9 [label="State 9\n\l 4 assignment: id . \":=\" exp\l"]
9 -> 14 [style=solid label="\":=\""]
10 [label="State 10\n\l 1 unit: assignments exp .\l"]
10 -> "10R1" [style=solid]
"10R1" [label="R1", fillcolor=3, shape=diamond, style=filled]
11 [label="State 11\n\l 10 exp: \"identifier\" .\l"]
11 -> "11R10" [style=solid]
"11R10" [label="R10", fillcolor=3, shape=diamond, style=filled]
12 [label="State 12\n\l 6 @1: . %empty\l 8 exp: \"incr\" exp . @1 @2 exp\l"]
12 -> 15 [style=dashed label="@1"]
12 -> "12R6" [style=solid]
"12R6" [label="R6", fillcolor=3, shape=diamond, style=filled]
13 [label="State 13\n\l 9 exp: \"(\" exp . \")\"\l"]
13 -> 16 [style=solid label="\")\""]
14 [label="State 14\n\l 4 assignment: id \":=\" . exp\l 8 exp: . \"incr\" exp @1 @2 exp\l 9 | . \"(\" exp \")\"\l 10 | . \"identifier\"\l 11 | . \"number\"\l"]
14 -> 4 [style=solid label="\"incr\""]
14 -> 11 [style=solid label="\"identifier\""]
14 -> 6 [style=solid label="\"number\""]
14 -> 7 [style=solid label="\"(\""]
14 -> 17 [style=dashed label="exp"]
15 [label="State 15\n\l 7 @2: . %empty\l 8 exp: \"incr\" exp @1 . @2 exp\l"]
15 -> 18 [style=dashed label="@2"]
15 -> "15R7" [style=solid]
"15R7" [label="R7", fillcolor=3, shape=diamond, style=filled]
16 [label="State 16\n\l 9 exp: \"(\" exp \")\" .\l"]
16 -> "16R9" [style=solid]
"16R9" [label="R9", fillcolor=3, shape=diamond, style=filled]
17 [label="State 17\n\l 4 assignment: id \":=\" exp .\l"]
17 -> "17R4" [style=solid]
"17R4" [label="R4", fillcolor=3, shape=diamond, style=filled]
18 [label="State 18\n\l 8 exp: . \"incr\" exp @1 @2 exp\l 8 | \"incr\" exp @1 @2 . exp\l 9 | . \"(\" exp \")\"\l 10 | . \"identifier\"\l 11 | . \"number\"\l"]
18 -> 4 [style=solid label="\"incr\""]
18 -> 11 [style=solid label="\"identifier\""]
18 -> 6 [style=solid label="\"number\""]
18 -> 7 [style=solid label="\"(\""]
18 -> 19 [style=dashed label="exp"]
19 [label="State 19\n\l 8 exp: \"incr\" exp @1 @2 exp .\l"]
19 -> "19R8" [style=solid]
"19R8" [label="R8", fillcolor=3, shape=diamond, style=filled]
}
]])
AT_CHECK([[sed -e 's/bison-xml-report version="[^"]*"/bison-xml-report version="VERSION"/g' input.xml]], [],
[[
input.yy
$accept
unit
"end of file"
unit
assignments
exp
assignments
assignments
assignments
assignment
assignment
id
":="
exp
id
"identifier"
@1
@2
exp
"incr"
exp
@1
@2
exp
exp
"("
exp
")"
exp
"identifier"
exp
"number"
-
":="
-
"end of file"
]])
AT_BISON_OPTION_POPDEFS
AT_CLEANUP