| 1 | # | ||||||||||||||||||||||||||||||||||||||||||
| 2 | # Module Parse::Yapp::Lalr | ||||||||||||||||||||||||||||||||||||||||||
| 3 | # | ||||||||||||||||||||||||||||||||||||||||||
| 4 | # Copyright © 1998, 1999, 2000, 2001, Francois Desarmenien. | ||||||||||||||||||||||||||||||||||||||||||
| 5 | # Copyright © 2017 William N. Braswell, Jr. | ||||||||||||||||||||||||||||||||||||||||||
| 6 | # (see the pod text in Parse::Yapp module for use and distribution rights) | ||||||||||||||||||||||||||||||||||||||||||
| 7 | # | ||||||||||||||||||||||||||||||||||||||||||
| 8 | package Parse::Yapp::Lalr; | ||||||||||||||||||||||||||||||||||||||||||
| 9 | 3 | @ISA=qw( Parse::Yapp::Grammar ); | |||||||||||||||||||||||||||||||||||||||||
| 10 | |||||||||||||||||||||||||||||||||||||||||||
| 11 | 3 | require 5.004; | |||||||||||||||||||||||||||||||||||||||||
| 12 | |||||||||||||||||||||||||||||||||||||||||||
| 13 | 3 | ▶ | use Parse::Yapp::Grammar; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 14 | |||||||||||||||||||||||||||||||||||||||||||
| 15 | =for nobody | ||||||||||||||||||||||||||||||||||||||||||
| 16 | |||||||||||||||||||||||||||||||||||||||||||
| 17 | Parse::Yapp::Compile Object Structure: | ||||||||||||||||||||||||||||||||||||||||||
| 18 | -------------------------------------- | ||||||||||||||||||||||||||||||||||||||||||
| 19 | { | ||||||||||||||||||||||||||||||||||||||||||
| 20 | GRAMMAR => Parse::Yapp::Grammar, | ||||||||||||||||||||||||||||||||||||||||||
| 21 | STATES => [ { CORE => [ items... ], | ||||||||||||||||||||||||||||||||||||||||||
| 22 | ACTIONS => { term => action } | ||||||||||||||||||||||||||||||||||||||||||
| 23 | GOTOS => { nterm => stateno } | ||||||||||||||||||||||||||||||||||||||||||
| 24 | }... ] | ||||||||||||||||||||||||||||||||||||||||||
| 25 | CONFLICTS=>{ SOLVED => { stateno => [ ruleno, token, solved ] }, | ||||||||||||||||||||||||||||||||||||||||||
| 26 | FORCED => { TOTAL => [ nbsr, nbrr ], | ||||||||||||||||||||||||||||||||||||||||||
| 27 | DETAIL => { stateno => { TOTAL => [ nbsr, nbrr ] } | ||||||||||||||||||||||||||||||||||||||||||
| 28 | LIST => [ ruleno, token ] | ||||||||||||||||||||||||||||||||||||||||||
| 29 | } | ||||||||||||||||||||||||||||||||||||||||||
| 30 | } | ||||||||||||||||||||||||||||||||||||||||||
| 31 | } | ||||||||||||||||||||||||||||||||||||||||||
| 32 | } | ||||||||||||||||||||||||||||||||||||||||||
| 33 | |||||||||||||||||||||||||||||||||||||||||||
| 34 | 'items' are of form: [ ruleno, dotpos ] | ||||||||||||||||||||||||||||||||||||||||||
| 35 | 'term' in ACTIONS is '' means default action | ||||||||||||||||||||||||||||||||||||||||||
| 36 | 'action' may be: | ||||||||||||||||||||||||||||||||||||||||||
| 37 | undef: explicit error (nonassociativity) | ||||||||||||||||||||||||||||||||||||||||||
| 38 | 0 : accept | ||||||||||||||||||||||||||||||||||||||||||
| 39 | >0 : shift and go to state 'action' | ||||||||||||||||||||||||||||||||||||||||||
| 40 | <0 : reduce using rule -'action' | ||||||||||||||||||||||||||||||||||||||||||
| 41 | 'solved' may have values of: | ||||||||||||||||||||||||||||||||||||||||||
| 42 | 'shift' if solved as Shift | ||||||||||||||||||||||||||||||||||||||||||
| 43 | 'reduce' if solved as Reduce | ||||||||||||||||||||||||||||||||||||||||||
| 44 | 'error' if solved by discarding both Shift and Reduce (nonassoc) | ||||||||||||||||||||||||||||||||||||||||||
| 45 | |||||||||||||||||||||||||||||||||||||||||||
| 46 | SOLVED is a set of states containing Solved conflicts | ||||||||||||||||||||||||||||||||||||||||||
| 47 | FORCED are forced conflict resolutions | ||||||||||||||||||||||||||||||||||||||||||
| 48 | |||||||||||||||||||||||||||||||||||||||||||
| 49 | nbsr and nbrr are number of shift/reduce and reduce/reduce conflicts | ||||||||||||||||||||||||||||||||||||||||||
| 50 | |||||||||||||||||||||||||||||||||||||||||||
| 51 | TOTAL is the total number of SR/RR conflicts for the parser | ||||||||||||||||||||||||||||||||||||||||||
| 52 | |||||||||||||||||||||||||||||||||||||||||||
| 53 | DETAIL is the detail of conflicts for each state | ||||||||||||||||||||||||||||||||||||||||||
| 54 | TOTAL is the total number of SR/RR conflicts for a state | ||||||||||||||||||||||||||||||||||||||||||
| 55 | LIST is the list of discarded reductions (for display purpose only) | ||||||||||||||||||||||||||||||||||||||||||
| 56 | |||||||||||||||||||||||||||||||||||||||||||
| 57 | |||||||||||||||||||||||||||||||||||||||||||
| 58 | =cut | ||||||||||||||||||||||||||||||||||||||||||
| 59 | |||||||||||||||||||||||||||||||||||||||||||
| 60 | 3 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 61 | |||||||||||||||||||||||||||||||||||||||||||
| 62 | 3 | ▶ | use Carp; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 63 | |||||||||||||||||||||||||||||||||||||||||||
| 64 | ############### | ||||||||||||||||||||||||||||||||||||||||||
| 65 | # Constructor # | ||||||||||||||||||||||||||||||||||||||||||
| 66 | ############### | ||||||||||||||||||||||||||||||||||||||||||
| 67 | 10 | ▶ | sub new { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
new: called CC=2 SCAR=7.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 68 | 10 | my($class)=shift; | |||||||||||||||||||||||||||||||||||||||||
| 69 | |||||||||||||||||||||||||||||||||||||||||||
| 70 | 10 | ▶ | ref($class) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 71 | and $class=ref($class); | ||||||||||||||||||||||||||||||||||||||||||
| 72 | |||||||||||||||||||||||||||||||||||||||||||
| 73 | 10 | my($self)=$class->SUPER::new(@_); | |||||||||||||||||||||||||||||||||||||||||
| 74 | 10 | $self->_Compile(); | |||||||||||||||||||||||||||||||||||||||||
| 75 | 10 | bless($self,$class); | |||||||||||||||||||||||||||||||||||||||||
| 76 | } | ||||||||||||||||||||||||||||||||||||||||||
| 77 | ########### | ||||||||||||||||||||||||||||||||||||||||||
| 78 | # Methods # | ||||||||||||||||||||||||||||||||||||||||||
| 79 | ########### | ||||||||||||||||||||||||||||||||||||||||||
| 80 | |||||||||||||||||||||||||||||||||||||||||||
| 81 | ########################### | ||||||||||||||||||||||||||||||||||||||||||
| 82 | # Method To View Warnings # | ||||||||||||||||||||||||||||||||||||||||||
| 83 | ########################### | ||||||||||||||||||||||||||||||||||||||||||
| 84 | 0 | ▶ | sub Warnings { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
Warnings: not called CC=8 SCAR=42.8
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 85 | 0 | my($self)=shift; | |||||||||||||||||||||||||||||||||||||||||
| 86 | 0 | my($text); | |||||||||||||||||||||||||||||||||||||||||
| 87 | 0 | my($nbsr,$nbrr)=@{$$self{CONFLICTS}{FORCED}{TOTAL}}; | |||||||||||||||||||||||||||||||||||||||||
| 88 | |||||||||||||||||||||||||||||||||||||||||||
| 89 | 0 | $text=$self->SUPER::Warnings(); | |||||||||||||||||||||||||||||||||||||||||
| 90 | |||||||||||||||||||||||||||||||||||||||||||
| 91 | $nbsr != $$self{GRAMMAR}{EXPECT} | ||||||||||||||||||||||||||||||||||||||||||
| 92 | 0 | ▶ | and $text.="$nbsr shift/reduce conflict".($nbsr > 1 ? "s" : ""); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 93 | |||||||||||||||||||||||||||||||||||||||||||
| 94 | $nbrr | ||||||||||||||||||||||||||||||||||||||||||
| 95 | 0 | ▶ | and do { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 96 | 0 | ▶ | $nbsr | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 97 | and $text.=" and "; | ||||||||||||||||||||||||||||||||||||||||||
| 98 | 0 | ▶ | $text.="$nbrr reduce/reduce conflict".($nbrr > 1 ? "s" : ""); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 99 | }; | ||||||||||||||||||||||||||||||||||||||||||
| 100 | |||||||||||||||||||||||||||||||||||||||||||
| 101 | ( $nbsr != $$self{GRAMMAR}{EXPECT} | ||||||||||||||||||||||||||||||||||||||||||
| 102 | 0 | ▶ | or $nbrr) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$nbsr != $self->{"GRAMMAR"}{"EXPECT"} or $nbrr
MC/DC0%0/2
$nbsr != $self->{"GRAMMAR"}{"EXPECT"} or $nbrr
$nbsr != $self->{"GRAMMAR"}{"EXPECT"}
$nbrr
Truth table0%0/3
A or B
A= $nbsr != $self->{"GRAMMAR"}{"EXPECT"}B= $nbrr
| |||||||||||||||||||||||||||||||||||||||||||
| 103 | and $text.="\n"; | ||||||||||||||||||||||||||||||||||||||||||
| 104 | |||||||||||||||||||||||||||||||||||||||||||
| 105 | 0 | $text; | |||||||||||||||||||||||||||||||||||||||||
| 106 | } | ||||||||||||||||||||||||||||||||||||||||||
| 107 | ############################# | ||||||||||||||||||||||||||||||||||||||||||
| 108 | # Method To View DFA States # | ||||||||||||||||||||||||||||||||||||||||||
| 109 | ############################# | ||||||||||||||||||||||||||||||||||||||||||
| 110 | 0 | ▶ | sub ShowDfa { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
ShowDfa: not called CC=25 SCAR=64.8
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 111 | 0 | my($self)=shift; | |||||||||||||||||||||||||||||||||||||||||
| 112 | 0 | my($text); | |||||||||||||||||||||||||||||||||||||||||
| 113 | 0 | my($grammar,$states)=($$self{GRAMMAR}, $$self{STATES}); | |||||||||||||||||||||||||||||||||||||||||
| 114 | |||||||||||||||||||||||||||||||||||||||||||
| 115 | 0 | for my $stateno (0..$#$states) { | |||||||||||||||||||||||||||||||||||||||||
| 116 | 0 | my(@shifts,@reduces,@errors,$default); | |||||||||||||||||||||||||||||||||||||||||
| 117 | |||||||||||||||||||||||||||||||||||||||||||
| 118 | 0 | $text.="State $stateno:\n\n"; | |||||||||||||||||||||||||||||||||||||||||
| 119 | |||||||||||||||||||||||||||||||||||||||||||
| 120 | #Dump Kernel Items | ||||||||||||||||||||||||||||||||||||||||||
| 121 | 0 | ▶ | for (sort { $$a[0] <=> $$b[0] | ||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/3
$Parse::Yapp::Lalr::a->[0] <=> $Parse::Yapp::Lalr::b->[0] || $Parse::Yapp::Lalr::a->[1] <=> $Parse::Yapp::Lalr::b->[1]
MC/DC0%0/2
$Parse::Yapp::Lalr::a->[0] <=> $Parse::Yapp::Lalr::b->[0] || $Parse::Yapp::Lalr::a->[1] <=> $Parse::Yapp::Lalr::b->[1]
$Parse::Yapp::Lalr::a->[0] <=> $Parse::Yapp::Lalr::b->[0]
$Parse::Yapp::Lalr::a->[1] <=> $Parse::Yapp::Lalr::b->[1]
Truth table0%0/3
A || B
A= $Parse::Yapp::Lalr::a->[0] <=> $Parse::Yapp::Lalr::b->[0]B= $Parse::Yapp::Lalr::a->[1] <=> $Parse::Yapp::Lalr::b->[1]
| |||||||||||||||||||||||||||||||||||||||||||
| 122 | 0 | or $$a[1] <=> $$b[1] } @{$$states[$stateno]{'CORE'}}) { | |||||||||||||||||||||||||||||||||||||||||
| 123 | 0 | my($ruleno,$pos)=@$_; | |||||||||||||||||||||||||||||||||||||||||
| 124 | 0 | my($lhs,$rhs)=@{$$grammar{RULES}[$ruleno]}[0,1]; | |||||||||||||||||||||||||||||||||||||||||
| 125 | 0 | my(@rhscopy)=@$rhs; | |||||||||||||||||||||||||||||||||||||||||
| 126 | |||||||||||||||||||||||||||||||||||||||||||
| 127 | 0 | ▶ | $ruleno | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 128 | or $rhscopy[-1] = '$end'; | ||||||||||||||||||||||||||||||||||||||||||
| 129 | |||||||||||||||||||||||||||||||||||||||||||
| 130 | 0 | splice(@rhscopy,$pos,0,'.'); | |||||||||||||||||||||||||||||||||||||||||
| 131 | 0 | $text.= "\t$lhs -> ".join(' ',@rhscopy)."\t(Rule $ruleno)\n"; | |||||||||||||||||||||||||||||||||||||||||
| 132 | } | ||||||||||||||||||||||||||||||||||||||||||
| 133 | |||||||||||||||||||||||||||||||||||||||||||
| 134 | #Prepare Actions | ||||||||||||||||||||||||||||||||||||||||||
| 135 | 0 | for (keys(%{$$states[$stateno]{ACTIONS}})) { | |||||||||||||||||||||||||||||||||||||||||
| 136 | 0 | my($term,$action)=($_,$$states[$stateno]{ACTIONS}{$_}); | |||||||||||||||||||||||||||||||||||||||||
| 137 | |||||||||||||||||||||||||||||||||||||||||||
| 138 | 0 | ▶ | $term eq chr(0) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 139 | and $term = '$end'; | ||||||||||||||||||||||||||||||||||||||||||
| 140 | |||||||||||||||||||||||||||||||||||||||||||
| 141 | not defined($action) | ||||||||||||||||||||||||||||||||||||||||||
| 142 | 0 | ▶ | and do { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 143 | 0 | push(@errors,$term); | |||||||||||||||||||||||||||||||||||||||||
| 144 | 0 | next; | |||||||||||||||||||||||||||||||||||||||||
| 145 | }; | ||||||||||||||||||||||||||||||||||||||||||
| 146 | |||||||||||||||||||||||||||||||||||||||||||
| 147 | $action > 0 | ||||||||||||||||||||||||||||||||||||||||||
| 148 | 0 | ▶ | and do { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 149 | 0 | push(@shifts,[ $term, $action ]); | |||||||||||||||||||||||||||||||||||||||||
| 150 | 0 | next; | |||||||||||||||||||||||||||||||||||||||||
| 151 | }; | ||||||||||||||||||||||||||||||||||||||||||
| 152 | |||||||||||||||||||||||||||||||||||||||||||
| 153 | 0 | $action = -$action; | |||||||||||||||||||||||||||||||||||||||||
| 154 | |||||||||||||||||||||||||||||||||||||||||||
| 155 | $term | ||||||||||||||||||||||||||||||||||||||||||
| 156 | 0 | ▶ | or do { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 157 | 0 | $default= [ '$default', $action ]; | |||||||||||||||||||||||||||||||||||||||||
| 158 | 0 | next; | |||||||||||||||||||||||||||||||||||||||||
| 159 | }; | ||||||||||||||||||||||||||||||||||||||||||
| 160 | |||||||||||||||||||||||||||||||||||||||||||
| 161 | 0 | push(@reduces,[ $term, $action ]); | |||||||||||||||||||||||||||||||||||||||||
| 162 | } | ||||||||||||||||||||||||||||||||||||||||||
| 163 | |||||||||||||||||||||||||||||||||||||||||||
| 164 | #Dump shifts | ||||||||||||||||||||||||||||||||||||||||||
| 165 | @shifts | ||||||||||||||||||||||||||||||||||||||||||
| 166 | 0 | ▶ | and do { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 167 | 0 | $text.="\n"; | |||||||||||||||||||||||||||||||||||||||||
| 168 | 0 | for (sort { $$a[0] cmp $$b[0] } @shifts) { | |||||||||||||||||||||||||||||||||||||||||
| 169 | 0 | my($term,$shift)=@$_; | |||||||||||||||||||||||||||||||||||||||||
| 170 | |||||||||||||||||||||||||||||||||||||||||||
| 171 | 0 | $text.="\t$term\tshift, and go to state $shift\n"; | |||||||||||||||||||||||||||||||||||||||||
| 172 | } | ||||||||||||||||||||||||||||||||||||||||||
| 173 | }; | ||||||||||||||||||||||||||||||||||||||||||
| 174 | |||||||||||||||||||||||||||||||||||||||||||
| 175 | #Dump errors | ||||||||||||||||||||||||||||||||||||||||||
| 176 | @errors | ||||||||||||||||||||||||||||||||||||||||||
| 177 | 0 | ▶ | and do { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 178 | 0 | $text.="\n"; | |||||||||||||||||||||||||||||||||||||||||
| 179 | 0 | for my $term (sort { $a cmp $b } @errors) { | |||||||||||||||||||||||||||||||||||||||||
| 180 | 0 | $text.="\t$term\terror (nonassociative)\n"; | |||||||||||||||||||||||||||||||||||||||||
| 181 | } | ||||||||||||||||||||||||||||||||||||||||||
| 182 | }; | ||||||||||||||||||||||||||||||||||||||||||
| 183 | |||||||||||||||||||||||||||||||||||||||||||
| 184 | #Prepare reduces | ||||||||||||||||||||||||||||||||||||||||||
| 185 | exists($$self{CONFLICTS}{FORCED}{DETAIL}{$stateno}) | ||||||||||||||||||||||||||||||||||||||||||
| 186 | 0 | ▶ | and push(@reduces,@{$$self{CONFLICTS}{FORCED}{DETAIL}{$stateno}{LIST}}); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 187 | |||||||||||||||||||||||||||||||||||||||||||
| 188 | 0 | ▶ | @reduces=sort { $$a[0] cmp $$b[0] or $$a[1] <=> $$b[1] } @reduces; | ||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/3
$Parse::Yapp::Lalr::a->[0] cmp $Parse::Yapp::Lalr::b->[0] || $Parse::Yapp::Lalr::a->[1] <=> $Parse::Yapp::Lalr::b->[1]
MC/DC0%0/2
$Parse::Yapp::Lalr::a->[0] cmp $Parse::Yapp::Lalr::b->[0] || $Parse::Yapp::Lalr::a->[1] <=> $Parse::Yapp::Lalr::b->[1]
$Parse::Yapp::Lalr::a->[0] cmp $Parse::Yapp::Lalr::b->[0]
$Parse::Yapp::Lalr::a->[1] <=> $Parse::Yapp::Lalr::b->[1]
Truth table0%0/3
A || B
A= $Parse::Yapp::Lalr::a->[0] cmp $Parse::Yapp::Lalr::b->[0]B= $Parse::Yapp::Lalr::a->[1] <=> $Parse::Yapp::Lalr::b->[1]
| |||||||||||||||||||||||||||||||||||||||||||
| 189 | |||||||||||||||||||||||||||||||||||||||||||
| 190 | 0 | ▶ | defined($default) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 191 | and push(@reduces,$default); | ||||||||||||||||||||||||||||||||||||||||||
| 192 | |||||||||||||||||||||||||||||||||||||||||||
| 193 | #Dump reduces | ||||||||||||||||||||||||||||||||||||||||||
| 194 | @reduces | ||||||||||||||||||||||||||||||||||||||||||
| 195 | 0 | ▶ | and do { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 196 | 0 | $text.="\n"; | |||||||||||||||||||||||||||||||||||||||||
| 197 | 0 | for (@reduces) { | |||||||||||||||||||||||||||||||||||||||||
| 198 | 0 | my($term,$ruleno)=@$_; | |||||||||||||||||||||||||||||||||||||||||
| 199 | 0 | my($discard); | |||||||||||||||||||||||||||||||||||||||||
| 200 | |||||||||||||||||||||||||||||||||||||||||||
| 201 | $ruleno < 0 | ||||||||||||||||||||||||||||||||||||||||||
| 202 | 0 | ▶ | and do { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 203 | 0 | ++$discard; | |||||||||||||||||||||||||||||||||||||||||
| 204 | 0 | $ruleno = -$ruleno; | |||||||||||||||||||||||||||||||||||||||||
| 205 | }; | ||||||||||||||||||||||||||||||||||||||||||
| 206 | |||||||||||||||||||||||||||||||||||||||||||
| 207 | 0 | ▶ | $text.= "\t$term\t".($discard ? "[" : ""); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 208 | 0 | ▶ | if($ruleno) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 209 | 0 | $text.= "reduce using rule $ruleno ". | |||||||||||||||||||||||||||||||||||||||||
| 210 | "($$grammar{RULES}[$ruleno][0])"; | ||||||||||||||||||||||||||||||||||||||||||
| 211 | } | ||||||||||||||||||||||||||||||||||||||||||
| 212 | else { | ||||||||||||||||||||||||||||||||||||||||||
| 213 | 0 | $text.='accept'; | |||||||||||||||||||||||||||||||||||||||||
| 214 | } | ||||||||||||||||||||||||||||||||||||||||||
| 215 | 0 | ▶ | $text.=($discard ? "]" : "")."\n"; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 216 | } | ||||||||||||||||||||||||||||||||||||||||||
| 217 | }; | ||||||||||||||||||||||||||||||||||||||||||
| 218 | |||||||||||||||||||||||||||||||||||||||||||
| 219 | #Dump gotos | ||||||||||||||||||||||||||||||||||||||||||
| 220 | exists($$states[$stateno]{GOTOS}) | ||||||||||||||||||||||||||||||||||||||||||
| 221 | 0 | ▶ | and do { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 222 | 0 | $text.= "\n"; | |||||||||||||||||||||||||||||||||||||||||
| 223 | 0 | for (keys(%{$$states[$stateno]{GOTOS}})) { | |||||||||||||||||||||||||||||||||||||||||
| 224 | 0 | $text.= "\t$_\tgo to state $$states[$stateno]{GOTOS}{$_}\n"; | |||||||||||||||||||||||||||||||||||||||||
| 225 | } | ||||||||||||||||||||||||||||||||||||||||||
| 226 | }; | ||||||||||||||||||||||||||||||||||||||||||
| 227 | |||||||||||||||||||||||||||||||||||||||||||
| 228 | 0 | $text.="\n"; | |||||||||||||||||||||||||||||||||||||||||
| 229 | } | ||||||||||||||||||||||||||||||||||||||||||
| 230 | 0 | $text; | |||||||||||||||||||||||||||||||||||||||||
| 231 | } | ||||||||||||||||||||||||||||||||||||||||||
| 232 | |||||||||||||||||||||||||||||||||||||||||||
| 233 | ###################################### | ||||||||||||||||||||||||||||||||||||||||||
| 234 | # Method to get summary about parser # | ||||||||||||||||||||||||||||||||||||||||||
| 235 | ###################################### | ||||||||||||||||||||||||||||||||||||||||||
| 236 | 0 | ▶ | sub Summary { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
Summary: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 237 | 0 | my($self)=shift; | |||||||||||||||||||||||||||||||||||||||||
| 238 | 0 | my($text); | |||||||||||||||||||||||||||||||||||||||||
| 239 | |||||||||||||||||||||||||||||||||||||||||||
| 240 | 0 | $text=$self->SUPER::Summary(); | |||||||||||||||||||||||||||||||||||||||||
| 241 | $text.="Number of states : ". | ||||||||||||||||||||||||||||||||||||||||||
| 242 | 0 | scalar(@{$$self{STATES}})."\n"; | |||||||||||||||||||||||||||||||||||||||||
| 243 | 0 | $text; | |||||||||||||||||||||||||||||||||||||||||
| 244 | } | ||||||||||||||||||||||||||||||||||||||||||
| 245 | |||||||||||||||||||||||||||||||||||||||||||
| 246 | ####################################### | ||||||||||||||||||||||||||||||||||||||||||
| 247 | # Method To Get Infos about conflicts # | ||||||||||||||||||||||||||||||||||||||||||
| 248 | ####################################### | ||||||||||||||||||||||||||||||||||||||||||
| 249 | 0 | ▶ | sub Conflicts { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
Conflicts: not called CC=10 SCAR=47.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 250 | 0 | my($self)=shift; | |||||||||||||||||||||||||||||||||||||||||
| 251 | 0 | my($states)=$$self{STATES}; | |||||||||||||||||||||||||||||||||||||||||
| 252 | 0 | my($conflicts)=$$self{CONFLICTS}; | |||||||||||||||||||||||||||||||||||||||||
| 253 | 0 | my($text); | |||||||||||||||||||||||||||||||||||||||||
| 254 | |||||||||||||||||||||||||||||||||||||||||||
| 255 | 0 | for my $stateno ( sort { $a <=> $b } keys(%{$$conflicts{SOLVED}})) { | |||||||||||||||||||||||||||||||||||||||||
| 256 | |||||||||||||||||||||||||||||||||||||||||||
| 257 | 0 | for (@{$$conflicts{SOLVED}{$stateno}}) { | |||||||||||||||||||||||||||||||||||||||||
| 258 | 0 | my($ruleno,$token,$how)=@$_; | |||||||||||||||||||||||||||||||||||||||||
| 259 | |||||||||||||||||||||||||||||||||||||||||||
| 260 | 0 | ▶ | $token eq chr(0) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 261 | and $token = '$end'; | ||||||||||||||||||||||||||||||||||||||||||
| 262 | |||||||||||||||||||||||||||||||||||||||||||
| 263 | 0 | $text.="Conflict in state $stateno between rule ". | |||||||||||||||||||||||||||||||||||||||||
| 264 | "$ruleno and token $token resolved as $how.\n"; | ||||||||||||||||||||||||||||||||||||||||||
| 265 | } | ||||||||||||||||||||||||||||||||||||||||||
| 266 | }; | ||||||||||||||||||||||||||||||||||||||||||
| 267 | |||||||||||||||||||||||||||||||||||||||||||
| 268 | 0 | for my $stateno ( sort { $a <=> $b } keys(%{$$conflicts{FORCED}{DETAIL}})) { | |||||||||||||||||||||||||||||||||||||||||
| 269 | 0 | my($nbsr,$nbrr)=@{$$conflicts{FORCED}{DETAIL}{$stateno}{TOTAL}}; | |||||||||||||||||||||||||||||||||||||||||
| 270 | |||||||||||||||||||||||||||||||||||||||||||
| 271 | 0 | $text.="State $stateno contains "; | |||||||||||||||||||||||||||||||||||||||||
| 272 | |||||||||||||||||||||||||||||||||||||||||||
| 273 | 0 | ▶ | $nbsr | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 274 | and $text.="$nbsr shift/reduce conflict". | ||||||||||||||||||||||||||||||||||||||||||
| 275 | ($nbsr > 1 ? "s" : ""); | ||||||||||||||||||||||||||||||||||||||||||
| 276 | |||||||||||||||||||||||||||||||||||||||||||
| 277 | $nbrr | ||||||||||||||||||||||||||||||||||||||||||
| 278 | 0 | ▶ | and do { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 279 | 0 | ▶ | $nbsr | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 280 | and $text.=" and "; | ||||||||||||||||||||||||||||||||||||||||||
| 281 | |||||||||||||||||||||||||||||||||||||||||||
| 282 | 0 | ▶ | $text.="$nbrr reduce/reduce conflict". | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 283 | ($nbrr > 1 ? "s" : ""); | ||||||||||||||||||||||||||||||||||||||||||
| 284 | }; | ||||||||||||||||||||||||||||||||||||||||||
| 285 | 0 | $text.="\n"; | |||||||||||||||||||||||||||||||||||||||||
| 286 | }; | ||||||||||||||||||||||||||||||||||||||||||
| 287 | |||||||||||||||||||||||||||||||||||||||||||
| 288 | 0 | $text; | |||||||||||||||||||||||||||||||||||||||||
| 289 | } | ||||||||||||||||||||||||||||||||||||||||||
| 290 | |||||||||||||||||||||||||||||||||||||||||||
| 291 | ################################# | ||||||||||||||||||||||||||||||||||||||||||
| 292 | # Method to dump parsing tables # | ||||||||||||||||||||||||||||||||||||||||||
| 293 | ################################# | ||||||||||||||||||||||||||||||||||||||||||
| 294 | 9 | ▶ | sub DfaTable { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
DfaTable: called CC=9 SCAR=22.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 295 | 9 | my($self)=shift; | |||||||||||||||||||||||||||||||||||||||||
| 296 | 9 | my($states)=$$self{STATES}; | |||||||||||||||||||||||||||||||||||||||||
| 297 | 9 | my($stateno); | |||||||||||||||||||||||||||||||||||||||||
| 298 | my($text); | ||||||||||||||||||||||||||||||||||||||||||
| 299 | |||||||||||||||||||||||||||||||||||||||||||
| 300 | 9 | $text="[\n\t{"; | |||||||||||||||||||||||||||||||||||||||||
| 301 | |||||||||||||||||||||||||||||||||||||||||||
| 302 | $text.=join("\n\t},\n\t{", | ||||||||||||||||||||||||||||||||||||||||||
| 303 | map { | ||||||||||||||||||||||||||||||||||||||||||
| 304 | 9 | my($state)=$_; | |||||||||||||||||||||||||||||||||||||||||
| 305 | 107 | my($text); | |||||||||||||||||||||||||||||||||||||||||
| 306 | |||||||||||||||||||||||||||||||||||||||||||
| 307 | 107 | $text="#State ".$stateno++."\n\t\t"; | |||||||||||||||||||||||||||||||||||||||||
| 308 | |||||||||||||||||||||||||||||||||||||||||||
| 309 | ( not exists($$state{ACTIONS}{''}) | ||||||||||||||||||||||||||||||||||||||||||
| 310 | 63 | or keys(%{$$state{ACTIONS}}) > 1) | |||||||||||||||||||||||||||||||||||||||||
| 311 | 107 | ▶ | and do { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
not exists $state->{"ACTIONS"}{""} or keys %{$$state{"ACTIONS"};} > 1
MC/DC100%2/2
not exists $state->{"ACTIONS"}{""} or keys %{$$state{"ACTIONS"};} > 1
not exists $state->{"ACTIONS"}{""}
keys %{$$state{"ACTIONS"};} > 1
Truth table100%3/3
not(A) or B
A= not exists $state->{"ACTIONS"}{""}B= keys %{$$state{"ACTIONS"};} > 1
| |||||||||||||||||||||||||||||||||||||||||||
| 312 | |||||||||||||||||||||||||||||||||||||||||||
| 313 | 57 | $text.="ACTIONS => {\n\t\t\t"; | |||||||||||||||||||||||||||||||||||||||||
| 314 | |||||||||||||||||||||||||||||||||||||||||||
| 315 | $text.=join(",\n\t\t\t", | ||||||||||||||||||||||||||||||||||||||||||
| 316 | map { | ||||||||||||||||||||||||||||||||||||||||||
| 317 | 126 | my($term,$action)=($_,$$state{ACTIONS}{$_}); | |||||||||||||||||||||||||||||||||||||||||
| 318 | 126 | my($text); | |||||||||||||||||||||||||||||||||||||||||
| 319 | |||||||||||||||||||||||||||||||||||||||||||
| 320 | 126 | ▶ | if(substr($term,0,1) eq "'") { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 321 | 96 | $term=~s/([\@\$\"])/\\$1/g; | |||||||||||||||||||||||||||||||||||||||||
| 322 | 96 | $term=~s/^'|'$/"/g; | |||||||||||||||||||||||||||||||||||||||||
| 323 | } | ||||||||||||||||||||||||||||||||||||||||||
| 324 | else { | ||||||||||||||||||||||||||||||||||||||||||
| 325 | 30 | ▶ | $term= $term eq chr(0) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 326 | ? "''" | ||||||||||||||||||||||||||||||||||||||||||
| 327 | : "'$term'"; | ||||||||||||||||||||||||||||||||||||||||||
| 328 | } | ||||||||||||||||||||||||||||||||||||||||||
| 329 | |||||||||||||||||||||||||||||||||||||||||||
| 330 | 126 | ▶ | if(defined($action)) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 331 | 125 | $action=int($action); | |||||||||||||||||||||||||||||||||||||||||
| 332 | } | ||||||||||||||||||||||||||||||||||||||||||
| 333 | else { | ||||||||||||||||||||||||||||||||||||||||||
| 334 | 1 | $action='undef'; | |||||||||||||||||||||||||||||||||||||||||
| 335 | } | ||||||||||||||||||||||||||||||||||||||||||
| 336 | |||||||||||||||||||||||||||||||||||||||||||
| 337 | 126 | "$term => $action"; | |||||||||||||||||||||||||||||||||||||||||
| 338 | |||||||||||||||||||||||||||||||||||||||||||
| 339 | 57 | } grep { $_ } keys(%{$$state{ACTIONS}})); | |||||||||||||||||||||||||||||||||||||||||
| 340 | |||||||||||||||||||||||||||||||||||||||||||
| 341 | 57 | $text.="\n\t\t}"; | |||||||||||||||||||||||||||||||||||||||||
| 342 | }; | ||||||||||||||||||||||||||||||||||||||||||
| 343 | |||||||||||||||||||||||||||||||||||||||||||
| 344 | exists($$state{ACTIONS}{''}) | ||||||||||||||||||||||||||||||||||||||||||
| 345 | 107 | ▶ | and do { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 346 | 63 | ▶ | keys(%{$$state{ACTIONS}}) > 1 | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 347 | and $text.=",\n\t\t"; | ||||||||||||||||||||||||||||||||||||||||||
| 348 | |||||||||||||||||||||||||||||||||||||||||||
| 349 | 63 | $text.="DEFAULT => $$state{ACTIONS}{''}"; | |||||||||||||||||||||||||||||||||||||||||
| 350 | }; | ||||||||||||||||||||||||||||||||||||||||||
| 351 | |||||||||||||||||||||||||||||||||||||||||||
| 352 | exists($$state{GOTOS}) | ||||||||||||||||||||||||||||||||||||||||||
| 353 | 107 | ▶ | and do { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 354 | 29 | $text.=",\n\t\tGOTOS => {\n\t\t\t"; | |||||||||||||||||||||||||||||||||||||||||
| 355 | $text.=join(",\n\t\t\t", | ||||||||||||||||||||||||||||||||||||||||||
| 356 | map { | ||||||||||||||||||||||||||||||||||||||||||
| 357 | 43 | my($nterm,$stateno)=($_,$$state{GOTOS}{$_}); | |||||||||||||||||||||||||||||||||||||||||
| 358 | 43 | my($text); | |||||||||||||||||||||||||||||||||||||||||
| 359 | |||||||||||||||||||||||||||||||||||||||||||
| 360 | 43 | "'$nterm' => $stateno"; | |||||||||||||||||||||||||||||||||||||||||
| 361 | |||||||||||||||||||||||||||||||||||||||||||
| 362 | 29 | } keys(%{$$state{GOTOS}})); | |||||||||||||||||||||||||||||||||||||||||
| 363 | 29 | $text.="\n\t\t}"; | |||||||||||||||||||||||||||||||||||||||||
| 364 | }; | ||||||||||||||||||||||||||||||||||||||||||
| 365 | |||||||||||||||||||||||||||||||||||||||||||
| 366 | 107 | $text; | |||||||||||||||||||||||||||||||||||||||||
| 367 | |||||||||||||||||||||||||||||||||||||||||||
| 368 | }@$states); | ||||||||||||||||||||||||||||||||||||||||||
| 369 | |||||||||||||||||||||||||||||||||||||||||||
| 370 | 9 | $text.="\n\t}\n]"; | |||||||||||||||||||||||||||||||||||||||||
| 371 | |||||||||||||||||||||||||||||||||||||||||||
| 372 | 9 | $text; | |||||||||||||||||||||||||||||||||||||||||
| 373 | |||||||||||||||||||||||||||||||||||||||||||
| 374 | } | ||||||||||||||||||||||||||||||||||||||||||
| 375 | |||||||||||||||||||||||||||||||||||||||||||
| 376 | |||||||||||||||||||||||||||||||||||||||||||
| 377 | #################################### | ||||||||||||||||||||||||||||||||||||||||||
| 378 | # Method to build Dfa from Grammar # | ||||||||||||||||||||||||||||||||||||||||||
| 379 | #################################### | ||||||||||||||||||||||||||||||||||||||||||
| 380 | 10 | ▶ | sub _Compile { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_Compile: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 381 | 10 | my($self)=shift; | |||||||||||||||||||||||||||||||||||||||||
| 382 | 10 | my($grammar,$states); | |||||||||||||||||||||||||||||||||||||||||
| 383 | |||||||||||||||||||||||||||||||||||||||||||
| 384 | 10 | $grammar=$self->{GRAMMAR}; | |||||||||||||||||||||||||||||||||||||||||
| 385 | |||||||||||||||||||||||||||||||||||||||||||
| 386 | 10 | $states = _LR0($grammar); | |||||||||||||||||||||||||||||||||||||||||
| 387 | |||||||||||||||||||||||||||||||||||||||||||
| 388 | 10 | $self->{CONFLICTS} = _LALR($grammar,$states); | |||||||||||||||||||||||||||||||||||||||||
| 389 | |||||||||||||||||||||||||||||||||||||||||||
| 390 | 10 | $self->{STATES}=$states; | |||||||||||||||||||||||||||||||||||||||||
| 391 | } | ||||||||||||||||||||||||||||||||||||||||||
| 392 | |||||||||||||||||||||||||||||||||||||||||||
| 393 | ######################### | ||||||||||||||||||||||||||||||||||||||||||
| 394 | # LR0 States Generation # | ||||||||||||||||||||||||||||||||||||||||||
| 395 | ######################### | ||||||||||||||||||||||||||||||||||||||||||
| 396 | # | ||||||||||||||||||||||||||||||||||||||||||
| 397 | ########################### | ||||||||||||||||||||||||||||||||||||||||||
| 398 | # General digraph routine # | ||||||||||||||||||||||||||||||||||||||||||
| 399 | ########################### | ||||||||||||||||||||||||||||||||||||||||||
| 400 | 30 | ▶ | sub _Digraph { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_Digraph: called CC=3 SCAR=11.0
| |||||||||||||||||||||||||||||||||||||||||||
| 401 | 30 | my($rel,$F)=@_; | |||||||||||||||||||||||||||||||||||||||||
| 402 | 30 | my(%N,@S); | |||||||||||||||||||||||||||||||||||||||||
| 403 | 30 | my($infinity)=(~(1<<31)); | |||||||||||||||||||||||||||||||||||||||||
| 404 | 30 | my($Traverse); | |||||||||||||||||||||||||||||||||||||||||
| 405 | |||||||||||||||||||||||||||||||||||||||||||
| 406 | 10659 | ▶ | $Traverse = sub { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=7 SCAR=19.5
| |||||||||||||||||||||||||||||||||||||||||||
| 407 | 10659 | my($x,$d)=@_; | |||||||||||||||||||||||||||||||||||||||||
| 408 | 10659 | my($y); | |||||||||||||||||||||||||||||||||||||||||
| 409 | |||||||||||||||||||||||||||||||||||||||||||
| 410 | 10659 | push(@S,$x); | |||||||||||||||||||||||||||||||||||||||||
| 411 | 10659 | $N{$x}=$d; | |||||||||||||||||||||||||||||||||||||||||
| 412 | |||||||||||||||||||||||||||||||||||||||||||
| 413 | exists($$rel{$x}) | ||||||||||||||||||||||||||||||||||||||||||
| 414 | 10659 | ▶ | and do { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 415 | 9183 | for $y (keys(%{$$rel{$x}})) { | |||||||||||||||||||||||||||||||||||||||||
| 416 | 42992 | ▶ | exists($N{$y}) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 417 | or &$Traverse($y,$d+1); | ||||||||||||||||||||||||||||||||||||||||||
| 418 | |||||||||||||||||||||||||||||||||||||||||||
| 419 | $N{$y} < $N{$x} | ||||||||||||||||||||||||||||||||||||||||||
| 420 | 42992 | ▶ | and $N{$x} = $N{$y}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 421 | |||||||||||||||||||||||||||||||||||||||||||
| 422 | 42992 | $$F{$x}|=$$F{$y}; | |||||||||||||||||||||||||||||||||||||||||
| 423 | } | ||||||||||||||||||||||||||||||||||||||||||
| 424 | }; | ||||||||||||||||||||||||||||||||||||||||||
| 425 | |||||||||||||||||||||||||||||||||||||||||||
| 426 | $N{$x} == $d | ||||||||||||||||||||||||||||||||||||||||||
| 427 | 10659 | ▶ | and do { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 428 | 10322 | for(;;) { | |||||||||||||||||||||||||||||||||||||||||
| 429 | 10659 | $y=pop(@S); | |||||||||||||||||||||||||||||||||||||||||
| 430 | 10659 | $N{$y}=$infinity; | |||||||||||||||||||||||||||||||||||||||||
| 431 | 10659 | ▶ | $y eq $x | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 432 | and last; | ||||||||||||||||||||||||||||||||||||||||||
| 433 | 337 | $$F{$y}=$$F{$x}; | |||||||||||||||||||||||||||||||||||||||||
| 434 | } | ||||||||||||||||||||||||||||||||||||||||||
| 435 | }; | ||||||||||||||||||||||||||||||||||||||||||
| 436 | 30 | }; | |||||||||||||||||||||||||||||||||||||||||
| 437 | |||||||||||||||||||||||||||||||||||||||||||
| 438 | 30 | for (keys(%$rel)) { | |||||||||||||||||||||||||||||||||||||||||
| 439 | 9183 | ▶ | exists($N{$_}) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 440 | or &$Traverse($_,1); | ||||||||||||||||||||||||||||||||||||||||||
| 441 | } | ||||||||||||||||||||||||||||||||||||||||||
| 442 | } | ||||||||||||||||||||||||||||||||||||||||||
| 443 | ####################### | ||||||||||||||||||||||||||||||||||||||||||
| 444 | # Generate LR0 states # | ||||||||||||||||||||||||||||||||||||||||||
| 445 | ####################### | ||||||||||||||||||||||||||||||||||||||||||
| 446 | =for nobody | ||||||||||||||||||||||||||||||||||||||||||
| 447 | Formula used for closures: | ||||||||||||||||||||||||||||||||||||||||||
| 448 | |||||||||||||||||||||||||||||||||||||||||||
| 449 | CLOSE(A) = DCLOSE(A) u U (CLOSE(B) | A close B) | ||||||||||||||||||||||||||||||||||||||||||
| 450 | |||||||||||||||||||||||||||||||||||||||||||
| 451 | where: | ||||||||||||||||||||||||||||||||||||||||||
| 452 | |||||||||||||||||||||||||||||||||||||||||||
| 453 | DCLOSE(A) = { [ A -> alpha ] in P } | ||||||||||||||||||||||||||||||||||||||||||
| 454 | |||||||||||||||||||||||||||||||||||||||||||
| 455 | A close B iff [ A -> B gamma ] in P | ||||||||||||||||||||||||||||||||||||||||||
| 456 | |||||||||||||||||||||||||||||||||||||||||||
| 457 | =cut | ||||||||||||||||||||||||||||||||||||||||||
| 458 | 10 | ▶ | sub _SetClosures { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_SetClosures: called CC=5 SCAR=16.1
| |||||||||||||||||||||||||||||||||||||||||||
| 459 | 10 | my($grammar)=@_; | |||||||||||||||||||||||||||||||||||||||||
| 460 | 10 | my($rel,$closures); | |||||||||||||||||||||||||||||||||||||||||
| 461 | |||||||||||||||||||||||||||||||||||||||||||
| 462 | 10 | for my $symbol (keys(%{$$grammar{NTERM}})) { | |||||||||||||||||||||||||||||||||||||||||
| 463 | 270 | $closures->{$symbol}=pack('b'.@{$$grammar{RULES}}); | |||||||||||||||||||||||||||||||||||||||||
| 464 | |||||||||||||||||||||||||||||||||||||||||||
| 465 | 270 | for my $ruleno (@{$$grammar{NTERM}{$symbol}}) { | |||||||||||||||||||||||||||||||||||||||||
| 466 | 888 | my($rhs)=$$grammar{RULES}[$ruleno][1]; | |||||||||||||||||||||||||||||||||||||||||
| 467 | |||||||||||||||||||||||||||||||||||||||||||
| 468 | 888 | vec($closures->{$symbol},$ruleno,1)=1; | |||||||||||||||||||||||||||||||||||||||||
| 469 | |||||||||||||||||||||||||||||||||||||||||||
| 470 | @$rhs > 0 | ||||||||||||||||||||||||||||||||||||||||||
| 471 | and exists($$grammar{NTERM}{$$rhs[0]}) | ||||||||||||||||||||||||||||||||||||||||||
| 472 | 888 | ▶ | and ++$rel->{$symbol}{$$rhs[0]}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
@$rhs > 0 and exists $grammar->{"NTERM"}{$rhs->[0]}
MC/DC100%2/2
@$rhs > 0 and exists $grammar->{"NTERM"}{$rhs->[0]}
@$rhs > 0
exists $grammar->{"NTERM"}{$rhs->[0]}
Truth table100%3/3
A and B
A= @$rhs > 0B= exists $grammar->{"NTERM"}{$rhs->[0]}
| |||||||||||||||||||||||||||||||||||||||||||
| 473 | } | ||||||||||||||||||||||||||||||||||||||||||
| 474 | } | ||||||||||||||||||||||||||||||||||||||||||
| 475 | 10 | _Digraph($rel,$closures); | |||||||||||||||||||||||||||||||||||||||||
| 476 | |||||||||||||||||||||||||||||||||||||||||||
| 477 | 10 | $closures | |||||||||||||||||||||||||||||||||||||||||
| 478 | } | ||||||||||||||||||||||||||||||||||||||||||
| 479 | |||||||||||||||||||||||||||||||||||||||||||
| 480 | 1718 | ▶ | sub _Closures { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_Closures: called CC=4 SCAR=13.9
| |||||||||||||||||||||||||||||||||||||||||||
| 481 | 1718 | my($grammar,$core,$closures)=@_; | |||||||||||||||||||||||||||||||||||||||||
| 482 | 1718 | my($ruleset)=pack('b'.@{$$grammar{RULES}}); | |||||||||||||||||||||||||||||||||||||||||
| 483 | |||||||||||||||||||||||||||||||||||||||||||
| 484 | 1718 | for (@$core) { | |||||||||||||||||||||||||||||||||||||||||
| 485 | 3895 | my($ruleno,$pos)=@$_; | |||||||||||||||||||||||||||||||||||||||||
| 486 | 3895 | my($rhs)=$$grammar{RULES}[$ruleno][1]; | |||||||||||||||||||||||||||||||||||||||||
| 487 | |||||||||||||||||||||||||||||||||||||||||||
| 488 | $pos < @$rhs | ||||||||||||||||||||||||||||||||||||||||||
| 489 | and exists($closures->{$$rhs[$pos]}) | ||||||||||||||||||||||||||||||||||||||||||
| 490 | 3895 | ▶ | and $ruleset|=$closures->{$$rhs[$pos]}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$pos < @$rhs and exists $$closures{$rhs->[$pos]}
MC/DC100%2/2
$pos < @$rhs and exists $$closures{$rhs->[$pos]}
$pos < @$rhs
exists $$closures{$rhs->[$pos]}
Truth table100%3/3
A and B
A= $pos < @$rhsB= exists $$closures{$rhs->[$pos]}
| |||||||||||||||||||||||||||||||||||||||||||
| 491 | } | ||||||||||||||||||||||||||||||||||||||||||
| 492 | 56069 | [ @$core, map { [ $_, 0 ] } | |||||||||||||||||||||||||||||||||||||||||
| 493 | 1330007 | grep { vec($ruleset,$_,1) } | |||||||||||||||||||||||||||||||||||||||||
| 494 | 1718 | 0..$#{$$grammar{RULES}} ]; | |||||||||||||||||||||||||||||||||||||||||
| 495 | } | ||||||||||||||||||||||||||||||||||||||||||
| 496 | |||||||||||||||||||||||||||||||||||||||||||
| 497 | 1718 | ▶ | sub _Transitions { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_Transitions: called CC=7 SCAR=19.5
| |||||||||||||||||||||||||||||||||||||||||||
| 498 | 1718 | my($grammar,$cores,$closures,$states,$stateno)=@_; | |||||||||||||||||||||||||||||||||||||||||
| 499 | 1718 | my($core)=$$states[$stateno]{'CORE'}; | |||||||||||||||||||||||||||||||||||||||||
| 500 | 1718 | my(%transitions); | |||||||||||||||||||||||||||||||||||||||||
| 501 | |||||||||||||||||||||||||||||||||||||||||||
| 502 | 1718 | for (@{_Closures($grammar,$core,$closures)}) { | |||||||||||||||||||||||||||||||||||||||||
| 503 | 59964 | my($ruleno,$pos)=@$_; | |||||||||||||||||||||||||||||||||||||||||
| 504 | 59964 | my($rhs)=$$grammar{RULES}[$ruleno][1]; | |||||||||||||||||||||||||||||||||||||||||
| 505 | |||||||||||||||||||||||||||||||||||||||||||
| 506 | $pos == @$rhs | ||||||||||||||||||||||||||||||||||||||||||
| 507 | 59964 | ▶ | and do { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 508 | 1187 | push(@{$$states[$stateno]{ACTIONS}{''}},$ruleno); | |||||||||||||||||||||||||||||||||||||||||
| 509 | 1187 | next; | |||||||||||||||||||||||||||||||||||||||||
| 510 | }; | ||||||||||||||||||||||||||||||||||||||||||
| 511 | 58777 | push(@{$transitions{$$rhs[$pos]}},[ $ruleno, $pos+1 ]); | |||||||||||||||||||||||||||||||||||||||||
| 512 | } | ||||||||||||||||||||||||||||||||||||||||||
| 513 | |||||||||||||||||||||||||||||||||||||||||||
| 514 | 1718 | for (keys(%transitions)) { | |||||||||||||||||||||||||||||||||||||||||
| 515 | 23159 | my($symbol,$core)=($_,$transitions{$_}); | |||||||||||||||||||||||||||||||||||||||||
| 516 | 58777 | my($corekey)=join(',',map { join('.',@$_) } | |||||||||||||||||||||||||||||||||||||||||
| 517 | 23159 | ▶ | sort { $$a[0] <=> $$b[0] | ||||||||||||||||||||||||||||||||||||||||
|
Condition66%2/3
$Parse::Yapp::Lalr::a->[0] <=> $Parse::Yapp::Lalr::b->[0] || $Parse::Yapp::Lalr::a->[1] <=> $Parse::Yapp::Lalr::b->[1]
MC/DC0%0/2
$Parse::Yapp::Lalr::a->[0] <=> $Parse::Yapp::Lalr::b->[0] || $Parse::Yapp::Lalr::a->[1] <=> $Parse::Yapp::Lalr::b->[1]
$Parse::Yapp::Lalr::a->[0] <=> $Parse::Yapp::Lalr::b->[0]
$Parse::Yapp::Lalr::a->[1] <=> $Parse::Yapp::Lalr::b->[1]
Truth table66%2/3
A || B
A= $Parse::Yapp::Lalr::a->[0] <=> $Parse::Yapp::Lalr::b->[0]B= $Parse::Yapp::Lalr::a->[1] <=> $Parse::Yapp::Lalr::b->[1]
| |||||||||||||||||||||||||||||||||||||||||||
| 518 | or $$a[1] <=> $$b[1] } | ||||||||||||||||||||||||||||||||||||||||||
| 519 | @$core); | ||||||||||||||||||||||||||||||||||||||||||
| 520 | 23159 | my($tostateno); | |||||||||||||||||||||||||||||||||||||||||
| 521 | |||||||||||||||||||||||||||||||||||||||||||
| 522 | exists($cores->{$corekey}) | ||||||||||||||||||||||||||||||||||||||||||
| 523 | 23159 | ▶ | or do { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 524 | 1708 | push(@$states,{ 'CORE' => $core }); | |||||||||||||||||||||||||||||||||||||||||
| 525 | 1708 | $cores->{$corekey}=$#$states; | |||||||||||||||||||||||||||||||||||||||||
| 526 | }; | ||||||||||||||||||||||||||||||||||||||||||
| 527 | |||||||||||||||||||||||||||||||||||||||||||
| 528 | 23159 | $tostateno=$cores->{$corekey}; | |||||||||||||||||||||||||||||||||||||||||
| 529 | 23159 | push(@{$$states[$tostateno]{FROM}},$stateno); | |||||||||||||||||||||||||||||||||||||||||
| 530 | |||||||||||||||||||||||||||||||||||||||||||
| 531 | exists($$grammar{TERM}{$_}) | ||||||||||||||||||||||||||||||||||||||||||
| 532 | 23159 | ▶ | and do { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 533 | 11824 | $$states[$stateno]{ACTIONS}{$_} = [ $tostateno ]; | |||||||||||||||||||||||||||||||||||||||||
| 534 | 11824 | next; | |||||||||||||||||||||||||||||||||||||||||
| 535 | }; | ||||||||||||||||||||||||||||||||||||||||||
| 536 | 11335 | $$states[$stateno]{GOTOS}{$_} = $tostateno; | |||||||||||||||||||||||||||||||||||||||||
| 537 | } | ||||||||||||||||||||||||||||||||||||||||||
| 538 | } | ||||||||||||||||||||||||||||||||||||||||||
| 539 | |||||||||||||||||||||||||||||||||||||||||||
| 540 | 10 | ▶ | sub _LR0 { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_LR0: called CC=2 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||
| 541 | 10 | my($grammar)=@_; | |||||||||||||||||||||||||||||||||||||||||
| 542 | 10 | my($states) = []; | |||||||||||||||||||||||||||||||||||||||||
| 543 | 10 | my($stateno); | |||||||||||||||||||||||||||||||||||||||||
| 544 | my($closures); #$closures={ nterm => ruleset,... } | ||||||||||||||||||||||||||||||||||||||||||
| 545 | 10 | my($cores)={}; # { "itemlist" => stateno, ... } | |||||||||||||||||||||||||||||||||||||||||
| 546 | # where "itemlist" has the form: | ||||||||||||||||||||||||||||||||||||||||||
| 547 | # "ruleno.pos,ruleno.pos" ordered by ruleno,pos | ||||||||||||||||||||||||||||||||||||||||||
| 548 | |||||||||||||||||||||||||||||||||||||||||||
| 549 | 10 | $closures = _SetClosures($grammar); | |||||||||||||||||||||||||||||||||||||||||
| 550 | 10 | push(@$states,{ 'CORE' => [ [ 0, 0 ] ] }); | |||||||||||||||||||||||||||||||||||||||||
| 551 | 10 | ▶ | for($stateno=0;$stateno<@$states;++$stateno) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 552 | 1718 | _Transitions($grammar,$cores,$closures,$states,$stateno); | |||||||||||||||||||||||||||||||||||||||||
| 553 | } | ||||||||||||||||||||||||||||||||||||||||||
| 554 | |||||||||||||||||||||||||||||||||||||||||||
| 555 | 10 | $states | |||||||||||||||||||||||||||||||||||||||||
| 556 | } | ||||||||||||||||||||||||||||||||||||||||||
| 557 | |||||||||||||||||||||||||||||||||||||||||||
| 558 | ######################################################### | ||||||||||||||||||||||||||||||||||||||||||
| 559 | # Add Lookahead tokens where needed to make LALR states # | ||||||||||||||||||||||||||||||||||||||||||
| 560 | ######################################################### | ||||||||||||||||||||||||||||||||||||||||||
| 561 | =for nobody | ||||||||||||||||||||||||||||||||||||||||||
| 562 | Compute First sets for non-terminal using the following formula: | ||||||||||||||||||||||||||||||||||||||||||
| 563 | |||||||||||||||||||||||||||||||||||||||||||
| 564 | FIRST(A) = { a in T u { epsilon } | A l a } | ||||||||||||||||||||||||||||||||||||||||||
| 565 | u | ||||||||||||||||||||||||||||||||||||||||||
| 566 | U { FIRST(B) | B in V and A l B } | ||||||||||||||||||||||||||||||||||||||||||
| 567 | |||||||||||||||||||||||||||||||||||||||||||
| 568 | where: | ||||||||||||||||||||||||||||||||||||||||||
| 569 | |||||||||||||||||||||||||||||||||||||||||||
| 570 | A l x iff [ A -> X1 X2 .. Xn x alpha ] in P and Xi =>* epsilon, 1 <= i <= n | ||||||||||||||||||||||||||||||||||||||||||
| 571 | =cut | ||||||||||||||||||||||||||||||||||||||||||
| 572 | 10 | ▶ | sub _SetFirst { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_SetFirst: called CC=6 SCAR=17.9
| |||||||||||||||||||||||||||||||||||||||||||
| 573 | 10 | my($grammar,$termlst,$terminx)=@_; | |||||||||||||||||||||||||||||||||||||||||
| 574 | 10 | my($rel,$first)=( {}, {} ); | |||||||||||||||||||||||||||||||||||||||||
| 575 | |||||||||||||||||||||||||||||||||||||||||||
| 576 | 10 | for my $symbol (keys(%{$$grammar{NTERM}})) { | |||||||||||||||||||||||||||||||||||||||||
| 577 | 270 | $first->{$symbol}=pack('b'.@$termlst); | |||||||||||||||||||||||||||||||||||||||||
| 578 | |||||||||||||||||||||||||||||||||||||||||||
| 579 | RULE: | ||||||||||||||||||||||||||||||||||||||||||
| 580 | 270 | for my $ruleno (@{$$grammar{NTERM}{$symbol}}) { | |||||||||||||||||||||||||||||||||||||||||
| 581 | 888 | my($rhs)=$$grammar{RULES}[$ruleno][1]; | |||||||||||||||||||||||||||||||||||||||||
| 582 | |||||||||||||||||||||||||||||||||||||||||||
| 583 | 888 | for (@$rhs) { | |||||||||||||||||||||||||||||||||||||||||
| 584 | exists($terminx->{$_}) | ||||||||||||||||||||||||||||||||||||||||||
| 585 | 868 | ▶ | and do { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 586 | 299 | vec($first->{$symbol},$terminx->{$_},1)=1; | |||||||||||||||||||||||||||||||||||||||||
| 587 | 299 | next RULE; | |||||||||||||||||||||||||||||||||||||||||
| 588 | }; | ||||||||||||||||||||||||||||||||||||||||||
| 589 | 569 | ++$rel->{$symbol}{$_}; | |||||||||||||||||||||||||||||||||||||||||
| 590 | 569 | ▶ | exists($$grammar{NULLABLE}{$_}) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 591 | or next RULE; | ||||||||||||||||||||||||||||||||||||||||||
| 592 | } | ||||||||||||||||||||||||||||||||||||||||||
| 593 | 47 | vec($first->{$symbol},0,1)=1; | |||||||||||||||||||||||||||||||||||||||||
| 594 | } | ||||||||||||||||||||||||||||||||||||||||||
| 595 | } | ||||||||||||||||||||||||||||||||||||||||||
| 596 | 10 | _Digraph($rel,$first); | |||||||||||||||||||||||||||||||||||||||||
| 597 | |||||||||||||||||||||||||||||||||||||||||||
| 598 | 10 | $first | |||||||||||||||||||||||||||||||||||||||||
| 599 | } | ||||||||||||||||||||||||||||||||||||||||||
| 600 | |||||||||||||||||||||||||||||||||||||||||||
| 601 | 8974 | ▶ | sub _Preds { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_Preds: called CC=4 SCAR=13.9
| |||||||||||||||||||||||||||||||||||||||||||
| 602 | 8974 | my($states,$stateno,$len)=@_; | |||||||||||||||||||||||||||||||||||||||||
| 603 | 8974 | my($queue, $preds); | |||||||||||||||||||||||||||||||||||||||||
| 604 | |||||||||||||||||||||||||||||||||||||||||||
| 605 | 8974 | ▶ | $len | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 606 | or return [ $stateno ]; | ||||||||||||||||||||||||||||||||||||||||||
| 607 | |||||||||||||||||||||||||||||||||||||||||||
| 608 | 1004 | $queue=[ [ $stateno, $len ] ]; | |||||||||||||||||||||||||||||||||||||||||
| 609 | 1004 | ▶ | while(@$queue) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 610 | 3862 | my($pred) = shift(@$queue); | |||||||||||||||||||||||||||||||||||||||||
| 611 | 3862 | my($stateno, $len) = @$pred; | |||||||||||||||||||||||||||||||||||||||||
| 612 | |||||||||||||||||||||||||||||||||||||||||||
| 613 | $len == 1 | ||||||||||||||||||||||||||||||||||||||||||
| 614 | 3862 | ▶ | and do { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 615 | 3169 | push(@$preds,@{$states->[$stateno]{FROM}}); | |||||||||||||||||||||||||||||||||||||||||
| 616 | 3169 | next; | |||||||||||||||||||||||||||||||||||||||||
| 617 | }; | ||||||||||||||||||||||||||||||||||||||||||
| 618 | |||||||||||||||||||||||||||||||||||||||||||
| 619 | 2858 | push(@$queue, map { [ $_, $len - 1 ] } | |||||||||||||||||||||||||||||||||||||||||
| 620 | 693 | @{$states->[$stateno]{FROM}}); | |||||||||||||||||||||||||||||||||||||||||
| 621 | } | ||||||||||||||||||||||||||||||||||||||||||
| 622 | |||||||||||||||||||||||||||||||||||||||||||
| 623 | # Pass @$preds through a hash to ensure unicity | ||||||||||||||||||||||||||||||||||||||||||
| 624 | 1004 | [ keys( %{ +{ map { ($_,1) } @$preds } } ) ]; | |||||||||||||||||||||||||||||||||||||||||
| 625 | } | ||||||||||||||||||||||||||||||||||||||||||
| 626 | |||||||||||||||||||||||||||||||||||||||||||
| 627 | 1235 | ▶ | sub _FirstSfx { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_FirstSfx: called CC=5 SCAR=16.1
| |||||||||||||||||||||||||||||||||||||||||||
| 628 | 1235 | my($grammar,$firstset,$termlst,$terminx,$ruleno,$pos,$key)=@_; | |||||||||||||||||||||||||||||||||||||||||
| 629 | 1235 | my($first)=pack('b'.@$termlst); | |||||||||||||||||||||||||||||||||||||||||
| 630 | 1235 | my($rhs)=$$grammar{RULES}[$ruleno][1]; | |||||||||||||||||||||||||||||||||||||||||
| 631 | |||||||||||||||||||||||||||||||||||||||||||
| 632 | 1235 | ▶ | for (;$pos < @$rhs;++$pos) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 633 | exists($terminx->{$$rhs[$pos]}) | ||||||||||||||||||||||||||||||||||||||||||
| 634 | 817 | ▶ | and do { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 635 | 395 | vec($first,$terminx->{$$rhs[$pos]},1)=1; | |||||||||||||||||||||||||||||||||||||||||
| 636 | 395 | return($first); | |||||||||||||||||||||||||||||||||||||||||
| 637 | }; | ||||||||||||||||||||||||||||||||||||||||||
| 638 | 422 | $first|=$firstset->{$$rhs[$pos]}; | |||||||||||||||||||||||||||||||||||||||||
| 639 | |||||||||||||||||||||||||||||||||||||||||||
| 640 | 422 | ▶ | vec($first,0,1) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 641 | and vec($first,0,1)=0; | ||||||||||||||||||||||||||||||||||||||||||
| 642 | |||||||||||||||||||||||||||||||||||||||||||
| 643 | 422 | ▶ | exists($$grammar{NULLABLE}{$$rhs[$pos]}) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 644 | or return($first); | ||||||||||||||||||||||||||||||||||||||||||
| 645 | |||||||||||||||||||||||||||||||||||||||||||
| 646 | } | ||||||||||||||||||||||||||||||||||||||||||
| 647 | 597 | vec($first,0,1)=1; | |||||||||||||||||||||||||||||||||||||||||
| 648 | 597 | $first; | |||||||||||||||||||||||||||||||||||||||||
| 649 | } | ||||||||||||||||||||||||||||||||||||||||||
| 650 | |||||||||||||||||||||||||||||||||||||||||||
| 651 | =for noboby | ||||||||||||||||||||||||||||||||||||||||||
| 652 | Compute Follow sets using following formula: | ||||||||||||||||||||||||||||||||||||||||||
| 653 | |||||||||||||||||||||||||||||||||||||||||||
| 654 | FOLLOW(p,A) = READ(p,A) | ||||||||||||||||||||||||||||||||||||||||||
| 655 | u | ||||||||||||||||||||||||||||||||||||||||||
| 656 | U { FOLLOW(q,B) | (p,A) include (q,B) | ||||||||||||||||||||||||||||||||||||||||||
| 657 | |||||||||||||||||||||||||||||||||||||||||||
| 658 | where: | ||||||||||||||||||||||||||||||||||||||||||
| 659 | |||||||||||||||||||||||||||||||||||||||||||
| 660 | READ(p,A) = U { FIRST(beta) | [ A -> alpha A . beta ] in KERNEL(GOTO(p,A)) | ||||||||||||||||||||||||||||||||||||||||||
| 661 | } - { epsilon } | ||||||||||||||||||||||||||||||||||||||||||
| 662 | |||||||||||||||||||||||||||||||||||||||||||
| 663 | (p,a) include (q,B) iff [ B -> alpha A . beta ] in KERNEL(GOTO(p,A), | ||||||||||||||||||||||||||||||||||||||||||
| 664 | epsilon in FIRST(beta) and | ||||||||||||||||||||||||||||||||||||||||||
| 665 | q in PRED(p,alpha) | ||||||||||||||||||||||||||||||||||||||||||
| 666 | =cut | ||||||||||||||||||||||||||||||||||||||||||
| 667 | 10 | ▶ | sub _ComputeFollows { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_ComputeFollows: called CC=13 SCAR=25.6
| |||||||||||||||||||||||||||||||||||||||||||
| 668 | 10 | my($grammar,$states,$termlst)=@_; | |||||||||||||||||||||||||||||||||||||||||
| 669 | 10 | my($firstset,$terminx); | |||||||||||||||||||||||||||||||||||||||||
| 670 | 10 | my($inconsistent, $rel, $follows, $sfx)= ( {}, {}, {}, {} ); | |||||||||||||||||||||||||||||||||||||||||
| 671 | |||||||||||||||||||||||||||||||||||||||||||
| 672 | 10 | %$terminx= map { ($termlst->[$_],$_) } 0..$#$termlst; | |||||||||||||||||||||||||||||||||||||||||
| 673 | |||||||||||||||||||||||||||||||||||||||||||
| 674 | 10 | $firstset=_SetFirst($grammar,$termlst,$terminx); | |||||||||||||||||||||||||||||||||||||||||
| 675 | |||||||||||||||||||||||||||||||||||||||||||
| 676 | 10 | for my $stateno (0..$#$states) { | |||||||||||||||||||||||||||||||||||||||||
| 677 | 1718 | my($state)=$$states[$stateno]; | |||||||||||||||||||||||||||||||||||||||||
| 678 | |||||||||||||||||||||||||||||||||||||||||||
| 679 | exists($$state{ACTIONS}{''}) | ||||||||||||||||||||||||||||||||||||||||||
| 680 | 1148 | and ( @{$$state{ACTIONS}{''}} > 1 | |||||||||||||||||||||||||||||||||||||||||
| 681 | 1111 | or keys(%{$$state{ACTIONS}}) > 1 ) | |||||||||||||||||||||||||||||||||||||||||
| 682 | 1718 | ▶ | and do { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%6/6
exists $state->{"ACTIONS"}{""} and @{$state->{"ACTIONS"}{""};} > 1 || keys %{$$state{"ACTIONS"};} > 1
@{$state->{"ACTIONS"}{""};} > 1 or keys %{$$state{"ACTIONS"};} > 1
MC/DC100%3/3
exists $state->{"ACTIONS"}{""} and @{$state->{"ACTIONS"}{""};} > 1 || keys %{$$state{"ACTIONS"};} > 1
exists $state->{"ACTIONS"}{""}
@{$state->{"ACTIONS"}{""};} > 1
keys %{$$state{"ACTIONS"};} > 1
Truth table100%4/4
A and B or C
A= exists $state->{"ACTIONS"}{""}B= @{$state->{"ACTIONS"}{""};} > 1C= keys %{$$state{"ACTIONS"};} > 1
| |||||||||||||||||||||||||||||||||||||||||||
| 683 | 397 | ++$inconsistent->{$stateno}; | |||||||||||||||||||||||||||||||||||||||||
| 684 | |||||||||||||||||||||||||||||||||||||||||||
| 685 | 397 | for my $ruleno (@{$$state{ACTIONS}{''}}) { | |||||||||||||||||||||||||||||||||||||||||
| 686 | 436 | my($lhs,$rhs)=@{$$grammar{RULES}[$ruleno]}[0,1]; | |||||||||||||||||||||||||||||||||||||||||
| 687 | |||||||||||||||||||||||||||||||||||||||||||
| 688 | 436 | for my $predno (@{_Preds($states,$stateno,scalar(@$rhs))}) { | |||||||||||||||||||||||||||||||||||||||||
| 689 | 11975 | ++$rel->{"$stateno.$ruleno"}{"$predno.$lhs"}; | |||||||||||||||||||||||||||||||||||||||||
| 690 | } | ||||||||||||||||||||||||||||||||||||||||||
| 691 | } | ||||||||||||||||||||||||||||||||||||||||||
| 692 | }; | ||||||||||||||||||||||||||||||||||||||||||
| 693 | |||||||||||||||||||||||||||||||||||||||||||
| 694 | exists($$state{GOTOS}) | ||||||||||||||||||||||||||||||||||||||||||
| 695 | 1718 | ▶ | or next; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 696 | |||||||||||||||||||||||||||||||||||||||||||
| 697 | 656 | for my $symbol (keys(%{$$state{GOTOS}})) { | |||||||||||||||||||||||||||||||||||||||||
| 698 | 11335 | my($tostate)=$$states[$$state{GOTOS}{$symbol}]; | |||||||||||||||||||||||||||||||||||||||||
| 699 | 11335 | my($goto)="$stateno.$symbol"; | |||||||||||||||||||||||||||||||||||||||||
| 700 | |||||||||||||||||||||||||||||||||||||||||||
| 701 | 11335 | $follows->{$goto}=pack('b'.@$termlst); | |||||||||||||||||||||||||||||||||||||||||
| 702 | |||||||||||||||||||||||||||||||||||||||||||
| 703 | 11335 | for my $item (@{$$tostate{'CORE'}}) { | |||||||||||||||||||||||||||||||||||||||||
| 704 | 39723 | my($ruleno,$pos)=@$item; | |||||||||||||||||||||||||||||||||||||||||
| 705 | 39723 | my($key)="$ruleno.$pos"; | |||||||||||||||||||||||||||||||||||||||||
| 706 | |||||||||||||||||||||||||||||||||||||||||||
| 707 | exists($sfx->{$key}) | ||||||||||||||||||||||||||||||||||||||||||
| 708 | 39723 | ▶ | or $sfx->{$key} = _FirstSfx($grammar,$firstset, | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 709 | $termlst,$terminx, | ||||||||||||||||||||||||||||||||||||||||||
| 710 | $ruleno,$pos,$key); | ||||||||||||||||||||||||||||||||||||||||||
| 711 | |||||||||||||||||||||||||||||||||||||||||||
| 712 | 39723 | $follows->{$goto}|=$sfx->{$key}; | |||||||||||||||||||||||||||||||||||||||||
| 713 | |||||||||||||||||||||||||||||||||||||||||||
| 714 | vec($follows->{$goto},0,1) | ||||||||||||||||||||||||||||||||||||||||||
| 715 | 39723 | ▶ | and do { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 716 | 8538 | my($lhs)=$$grammar{RULES}[$ruleno][0]; | |||||||||||||||||||||||||||||||||||||||||
| 717 | |||||||||||||||||||||||||||||||||||||||||||
| 718 | 8538 | vec($follows->{$goto},0,1)=0; | |||||||||||||||||||||||||||||||||||||||||
| 719 | |||||||||||||||||||||||||||||||||||||||||||
| 720 | 8538 | for my $predno (@{_Preds($states,$stateno,$pos-1)}) { | |||||||||||||||||||||||||||||||||||||||||
| 721 | 30297 | ++$rel->{$goto}{"$predno.$lhs"}; | |||||||||||||||||||||||||||||||||||||||||
| 722 | } | ||||||||||||||||||||||||||||||||||||||||||
| 723 | }; | ||||||||||||||||||||||||||||||||||||||||||
| 724 | } | ||||||||||||||||||||||||||||||||||||||||||
| 725 | } | ||||||||||||||||||||||||||||||||||||||||||
| 726 | } | ||||||||||||||||||||||||||||||||||||||||||
| 727 | 10 | _Digraph($rel,$follows); | |||||||||||||||||||||||||||||||||||||||||
| 728 | |||||||||||||||||||||||||||||||||||||||||||
| 729 | 10 | ($follows,$inconsistent) | |||||||||||||||||||||||||||||||||||||||||
| 730 | } | ||||||||||||||||||||||||||||||||||||||||||
| 731 | |||||||||||||||||||||||||||||||||||||||||||
| 732 | 10 | ▶ | sub _ComputeLA { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_ComputeLA: called CC=6 SCAR=17.9
| |||||||||||||||||||||||||||||||||||||||||||
| 733 | 10 | my($grammar,$states)=@_; | |||||||||||||||||||||||||||||||||||||||||
| 734 | 10 | my($termlst)= [ '',keys(%{$$grammar{TERM}}) ]; | |||||||||||||||||||||||||||||||||||||||||
| 735 | |||||||||||||||||||||||||||||||||||||||||||
| 736 | 10 | my($follows,$inconsistent) = _ComputeFollows($grammar,$states,$termlst); | |||||||||||||||||||||||||||||||||||||||||
| 737 | |||||||||||||||||||||||||||||||||||||||||||
| 738 | 10 | for my $stateno ( keys(%$inconsistent ) ) { | |||||||||||||||||||||||||||||||||||||||||
| 739 | 397 | my($state)=$$states[$stateno]; | |||||||||||||||||||||||||||||||||||||||||
| 740 | 397 | my($conflict); | |||||||||||||||||||||||||||||||||||||||||
| 741 | |||||||||||||||||||||||||||||||||||||||||||
| 742 | #NB the sort is VERY important for conflicts resolution order | ||||||||||||||||||||||||||||||||||||||||||
| 743 | 397 | for my $ruleno (sort { $a <=> $b } | |||||||||||||||||||||||||||||||||||||||||
| 744 | 397 | @{$$state{ACTIONS}{''}}) { | |||||||||||||||||||||||||||||||||||||||||
| 745 | 436 | for my $term ( map { $termlst->[$_] } grep { | |||||||||||||||||||||||||||||||||||||||||
| 746 | 46056 | vec($follows->{"$stateno.$ruleno"},$_,1) } | |||||||||||||||||||||||||||||||||||||||||
| 747 | 0..$#$termlst) { | ||||||||||||||||||||||||||||||||||||||||||
| 748 | 7755 | ▶ | exists($$state{ACTIONS}{$term}) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 749 | and ++$conflict; | ||||||||||||||||||||||||||||||||||||||||||
| 750 | 7755 | push(@{$$state{ACTIONS}{$term}},-$ruleno); | |||||||||||||||||||||||||||||||||||||||||
| 751 | } | ||||||||||||||||||||||||||||||||||||||||||
| 752 | } | ||||||||||||||||||||||||||||||||||||||||||
| 753 | 397 | delete($$state{ACTIONS}{''}); | |||||||||||||||||||||||||||||||||||||||||
| 754 | $conflict | ||||||||||||||||||||||||||||||||||||||||||
| 755 | 397 | ▶ | or delete($inconsistent->{$stateno}); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 756 | } | ||||||||||||||||||||||||||||||||||||||||||
| 757 | |||||||||||||||||||||||||||||||||||||||||||
| 758 | $inconsistent | ||||||||||||||||||||||||||||||||||||||||||
| 759 | 10 | } | |||||||||||||||||||||||||||||||||||||||||
| 760 | |||||||||||||||||||||||||||||||||||||||||||
| 761 | ############################# | ||||||||||||||||||||||||||||||||||||||||||
| 762 | # Solve remaining conflicts # | ||||||||||||||||||||||||||||||||||||||||||
| 763 | ############################# | ||||||||||||||||||||||||||||||||||||||||||
| 764 | |||||||||||||||||||||||||||||||||||||||||||
| 765 | 10 | ▶ | sub _SolveConflicts { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_SolveConflicts: called CC=20 SCAR=30.0
| |||||||||||||||||||||||||||||||||||||||||||
| 766 | 10 | my($grammar,$states,$inconsistent)=@_; | |||||||||||||||||||||||||||||||||||||||||
| 767 | 10 | my(%rulesprec,$RulePrec); | |||||||||||||||||||||||||||||||||||||||||
| 768 | 10 | my($conflicts)={ SOLVED => {}, | |||||||||||||||||||||||||||||||||||||||||
| 769 | FORCED => { TOTAL => [ 0, 0 ], | ||||||||||||||||||||||||||||||||||||||||||
| 770 | DETAIL => {} | ||||||||||||||||||||||||||||||||||||||||||
| 771 | } | ||||||||||||||||||||||||||||||||||||||||||
| 772 | }; | ||||||||||||||||||||||||||||||||||||||||||
| 773 | |||||||||||||||||||||||||||||||||||||||||||
| 774 | 845 | ▶ | $RulePrec = sub { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=5 SCAR=16.1
| |||||||||||||||||||||||||||||||||||||||||||
| 775 | 845 | my($ruleno)=@_; | |||||||||||||||||||||||||||||||||||||||||
| 776 | 845 | my($rhs,$rprec)=@{$$grammar{RULES}[$ruleno]}[1,2]; | |||||||||||||||||||||||||||||||||||||||||
| 777 | 845 | my($lastterm); | |||||||||||||||||||||||||||||||||||||||||
| 778 | |||||||||||||||||||||||||||||||||||||||||||
| 779 | 845 | ▶ | defined($rprec) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 780 | and return($rprec); | ||||||||||||||||||||||||||||||||||||||||||
| 781 | |||||||||||||||||||||||||||||||||||||||||||
| 782 | exists($rulesprec{$ruleno}) | ||||||||||||||||||||||||||||||||||||||||||
| 783 | 612 | ▶ | and return($rulesprec{$ruleno}); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 784 | |||||||||||||||||||||||||||||||||||||||||||
| 785 | 67 | $lastterm=(grep { exists($$grammar{TERM}{$_}) } @$rhs)[-1]; | |||||||||||||||||||||||||||||||||||||||||
| 786 | |||||||||||||||||||||||||||||||||||||||||||
| 787 | defined($lastterm) | ||||||||||||||||||||||||||||||||||||||||||
| 788 | and ref($$grammar{TERM}{$lastterm}) | ||||||||||||||||||||||||||||||||||||||||||
| 789 | 67 | ▶ | and do { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
defined $lastterm and ref $grammar->{"TERM"}{$lastterm}
MC/DC50%1/2
defined $lastterm and ref $grammar->{"TERM"}{$lastterm}
defined $lastterm
ref $grammar->{"TERM"}{$lastterm}
Truth table66%2/3
A and B
A= defined $lasttermB= ref $grammar->{"TERM"}{$lastterm}
| |||||||||||||||||||||||||||||||||||||||||||
| 790 | 48 | $rulesprec{$ruleno}=$$grammar{TERM}{$lastterm}[1]; | |||||||||||||||||||||||||||||||||||||||||
| 791 | 48 | return($rulesprec{$ruleno}); | |||||||||||||||||||||||||||||||||||||||||
| 792 | }; | ||||||||||||||||||||||||||||||||||||||||||
| 793 | |||||||||||||||||||||||||||||||||||||||||||
| 794 | 19 | undef; | |||||||||||||||||||||||||||||||||||||||||
| 795 | 10 | }; | |||||||||||||||||||||||||||||||||||||||||
| 796 | |||||||||||||||||||||||||||||||||||||||||||
| 797 | 10 | for my $stateno (keys(%$inconsistent)) { | |||||||||||||||||||||||||||||||||||||||||
| 798 | 155 | my($state)=$$states[$stateno]; | |||||||||||||||||||||||||||||||||||||||||
| 799 | 155 | my($actions)=$$state{ACTIONS}; | |||||||||||||||||||||||||||||||||||||||||
| 800 | 155 | my($nbsr,$nbrr); | |||||||||||||||||||||||||||||||||||||||||
| 801 | |||||||||||||||||||||||||||||||||||||||||||
| 802 | 155 | for my $term ( keys(%$actions) ) { | |||||||||||||||||||||||||||||||||||||||||
| 803 | 5702 | my($act)=$$actions{$term}; | |||||||||||||||||||||||||||||||||||||||||
| 804 | |||||||||||||||||||||||||||||||||||||||||||
| 805 | 5702 | ▶ | @$act > 1 | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 806 | or next; | ||||||||||||||||||||||||||||||||||||||||||
| 807 | |||||||||||||||||||||||||||||||||||||||||||
| 808 | $$act[0] > 0 | ||||||||||||||||||||||||||||||||||||||||||
| 809 | and ref($$grammar{TERM}{$term}) | ||||||||||||||||||||||||||||||||||||||||||
| 810 | 895 | ▶ | and do { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$act->[0] > 0 and ref $grammar->{"TERM"}{$term}
MC/DC100%2/2
$act->[0] > 0 and ref $grammar->{"TERM"}{$term}
$act->[0] > 0
ref $grammar->{"TERM"}{$term}
Truth table100%3/3
A and B
A= $act->[0] > 0B= ref $grammar->{"TERM"}{$term}
| |||||||||||||||||||||||||||||||||||||||||||
| 811 | 842 | my($assoc,$tprec)=@{$$grammar{TERM}{$term}}; | |||||||||||||||||||||||||||||||||||||||||
| 812 | 842 | my($k,$error); | |||||||||||||||||||||||||||||||||||||||||
| 813 | |||||||||||||||||||||||||||||||||||||||||||
| 814 | 842 | ▶ | for ($k=1;$k<@$act;++$k) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 815 | 845 | my($ruleno)=-$$act[$k]; | |||||||||||||||||||||||||||||||||||||||||
| 816 | 845 | my($rprec)=&$RulePrec($ruleno); | |||||||||||||||||||||||||||||||||||||||||
| 817 | |||||||||||||||||||||||||||||||||||||||||||
| 818 | 845 | ▶ | defined($rprec) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 819 | or next; | ||||||||||||||||||||||||||||||||||||||||||
| 820 | |||||||||||||||||||||||||||||||||||||||||||
| 821 | ( $tprec > $rprec | ||||||||||||||||||||||||||||||||||||||||||
| 822 | or ( $tprec == $rprec and $assoc eq 'RIGHT')) | ||||||||||||||||||||||||||||||||||||||||||
| 823 | 826 | ▶ | and do { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%6/6
$tprec > $rprec or $tprec == $rprec and $assoc eq "RIGHT"
$tprec == $rprec and $assoc eq "RIGHT"
MC/DC100%3/3
$tprec > $rprec or $tprec == $rprec and $assoc eq "RIGHT"
$tprec > $rprec
$tprec == $rprec
$assoc eq "RIGHT"
Truth table100%4/4
A or B and C
A= $tprec > $rprecB= $tprec == $rprecC= $assoc eq "RIGHT"
| |||||||||||||||||||||||||||||||||||||||||||
| 824 | 542 | push(@{$$conflicts{SOLVED}{$stateno}}, | |||||||||||||||||||||||||||||||||||||||||
| 825 | [ $ruleno, $term, 'shift' ]); | ||||||||||||||||||||||||||||||||||||||||||
| 826 | 542 | splice(@$act,$k--,1); | |||||||||||||||||||||||||||||||||||||||||
| 827 | 542 | next; | |||||||||||||||||||||||||||||||||||||||||
| 828 | }; | ||||||||||||||||||||||||||||||||||||||||||
| 829 | ( $tprec < $rprec | ||||||||||||||||||||||||||||||||||||||||||
| 830 | or $assoc eq 'LEFT') | ||||||||||||||||||||||||||||||||||||||||||
| 831 | 284 | ▶ | and do { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$tprec < $rprec or $assoc eq "LEFT"
MC/DC100%2/2
$tprec < $rprec or $assoc eq "LEFT"
$tprec < $rprec
$assoc eq "LEFT"
Truth table100%3/3
A or B
A= $tprec < $rprecB= $assoc eq "LEFT"
| |||||||||||||||||||||||||||||||||||||||||||
| 832 | 283 | push(@{$$conflicts{SOLVED}{$stateno}}, | |||||||||||||||||||||||||||||||||||||||||
| 833 | [ $ruleno, $term, 'reduce' ]); | ||||||||||||||||||||||||||||||||||||||||||
| 834 | $$act[0] > 0 | ||||||||||||||||||||||||||||||||||||||||||
| 835 | 283 | ▶ | and do { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 836 | 283 | splice(@$act,0,1); | |||||||||||||||||||||||||||||||||||||||||
| 837 | 283 | --$k; | |||||||||||||||||||||||||||||||||||||||||
| 838 | }; | ||||||||||||||||||||||||||||||||||||||||||
| 839 | 283 | next; | |||||||||||||||||||||||||||||||||||||||||
| 840 | }; | ||||||||||||||||||||||||||||||||||||||||||
| 841 | 1 | push(@{$$conflicts{SOLVED}{$stateno}}, | |||||||||||||||||||||||||||||||||||||||||
| 842 | [ $ruleno, $term, 'error' ]); | ||||||||||||||||||||||||||||||||||||||||||
| 843 | 1 | splice(@$act,$k--,1); | |||||||||||||||||||||||||||||||||||||||||
| 844 | $$act[0] > 0 | ||||||||||||||||||||||||||||||||||||||||||
| 845 | 1 | ▶ | and do { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 846 | 1 | splice(@$act,0,1); | |||||||||||||||||||||||||||||||||||||||||
| 847 | 1 | ++$error; | |||||||||||||||||||||||||||||||||||||||||
| 848 | 1 | --$k; | |||||||||||||||||||||||||||||||||||||||||
| 849 | }; | ||||||||||||||||||||||||||||||||||||||||||
| 850 | } | ||||||||||||||||||||||||||||||||||||||||||
| 851 | 842 | ▶ | $error | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 852 | and unshift(@$act,undef); | ||||||||||||||||||||||||||||||||||||||||||
| 853 | }; | ||||||||||||||||||||||||||||||||||||||||||
| 854 | |||||||||||||||||||||||||||||||||||||||||||
| 855 | @$act > 1 | ||||||||||||||||||||||||||||||||||||||||||
| 856 | 895 | ▶ | and do { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 857 | 72 | $nbrr += @$act - 2; | |||||||||||||||||||||||||||||||||||||||||
| 858 | 72 | ▶ | ($$act[0] > 0 ? $nbsr : $nbrr) += 1; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 859 | 72 | push(@{$$conflicts{FORCED}{DETAIL}{$stateno}{LIST}}, | |||||||||||||||||||||||||||||||||||||||||
| 860 | 72 | map { [ $term, $_ ] } splice(@$act,1)); | |||||||||||||||||||||||||||||||||||||||||
| 861 | }; | ||||||||||||||||||||||||||||||||||||||||||
| 862 | } | ||||||||||||||||||||||||||||||||||||||||||
| 863 | |||||||||||||||||||||||||||||||||||||||||||
| 864 | $nbsr | ||||||||||||||||||||||||||||||||||||||||||
| 865 | 155 | ▶ | and do { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 866 | 27 | $$conflicts{FORCED}{TOTAL}[0]+=$nbsr; | |||||||||||||||||||||||||||||||||||||||||
| 867 | 27 | $$conflicts{FORCED}{DETAIL}{$stateno}{TOTAL}[0]+=$nbsr; | |||||||||||||||||||||||||||||||||||||||||
| 868 | }; | ||||||||||||||||||||||||||||||||||||||||||
| 869 | |||||||||||||||||||||||||||||||||||||||||||
| 870 | $nbrr | ||||||||||||||||||||||||||||||||||||||||||
| 871 | 155 | ▶ | and do { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 872 | 11 | $$conflicts{FORCED}{TOTAL}[1]+=$nbrr; | |||||||||||||||||||||||||||||||||||||||||
| 873 | 11 | $$conflicts{FORCED}{DETAIL}{$stateno}{TOTAL}[1]+=$nbrr; | |||||||||||||||||||||||||||||||||||||||||
| 874 | }; | ||||||||||||||||||||||||||||||||||||||||||
| 875 | |||||||||||||||||||||||||||||||||||||||||||
| 876 | } | ||||||||||||||||||||||||||||||||||||||||||
| 877 | |||||||||||||||||||||||||||||||||||||||||||
| 878 | $conflicts | ||||||||||||||||||||||||||||||||||||||||||
| 879 | 10 | } | |||||||||||||||||||||||||||||||||||||||||
| 880 | |||||||||||||||||||||||||||||||||||||||||||
| 881 | ############################### | ||||||||||||||||||||||||||||||||||||||||||
| 882 | # Make default reduce actions # | ||||||||||||||||||||||||||||||||||||||||||
| 883 | ############################### | ||||||||||||||||||||||||||||||||||||||||||
| 884 | 10 | ▶ | sub _SetDefaults { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_SetDefaults: called CC=11 SCAR=24.0
| |||||||||||||||||||||||||||||||||||||||||||
| 885 | 10 | my($states)=@_; | |||||||||||||||||||||||||||||||||||||||||
| 886 | |||||||||||||||||||||||||||||||||||||||||||
| 887 | 10 | for my $state (@$states) { | |||||||||||||||||||||||||||||||||||||||||
| 888 | 1718 | my($actions)=$$state{ACTIONS}; | |||||||||||||||||||||||||||||||||||||||||
| 889 | 1718 | my(%reduces,$default,$nodefault); | |||||||||||||||||||||||||||||||||||||||||
| 890 | |||||||||||||||||||||||||||||||||||||||||||
| 891 | exists($$actions{''}) | ||||||||||||||||||||||||||||||||||||||||||
| 892 | 1718 | ▶ | and do { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 893 | 751 | $$actions{''}[0] = -$$actions{''}[0]; | |||||||||||||||||||||||||||||||||||||||||
| 894 | 751 | ++$nodefault; | |||||||||||||||||||||||||||||||||||||||||
| 895 | }; | ||||||||||||||||||||||||||||||||||||||||||
| 896 | |||||||||||||||||||||||||||||||||||||||||||
| 897 | #shift error token => no default | ||||||||||||||||||||||||||||||||||||||||||
| 898 | exists($$actions{error}) | ||||||||||||||||||||||||||||||||||||||||||
| 899 | 1718 | ▶ | and $$actions{error}[0] > 0 | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
exists $actions->{"error"} and $actions->{"error"}[0] > 0
MC/DC100%2/2
exists $actions->{"error"} and $actions->{"error"}[0] > 0
exists $actions->{"error"}
$actions->{"error"}[0] > 0
Truth table100%3/3
A and B
A= exists $actions->{"error"}B= $actions->{"error"}[0] > 0
| |||||||||||||||||||||||||||||||||||||||||||
| 900 | and ++$nodefault; | ||||||||||||||||||||||||||||||||||||||||||
| 901 | |||||||||||||||||||||||||||||||||||||||||||
| 902 | 1718 | for my $term (keys(%$actions)) { | |||||||||||||||||||||||||||||||||||||||||
| 903 | |||||||||||||||||||||||||||||||||||||||||||
| 904 | 19432 | $$actions{$term}=$$actions{$term}[0]; | |||||||||||||||||||||||||||||||||||||||||
| 905 | |||||||||||||||||||||||||||||||||||||||||||
| 906 | ( not defined($$actions{$term}) | ||||||||||||||||||||||||||||||||||||||||||
| 907 | 19432 | ▶ | or $$actions{$term} > 0 | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%6/6
not defined $actions->{$term} or $actions->{$term} > 0 or $nodefault
not defined $actions->{$term} or $actions->{$term} > 0
MC/DC100%3/3
not defined $actions->{$term} or $actions->{$term} > 0 or $nodefault
not defined $actions->{$term}
$actions->{$term} > 0
$nodefault
Truth table100%4/4
not(A) or B or C
A= not defined $actions->{$term}B= $actions->{$term} > 0C= $nodefault
| |||||||||||||||||||||||||||||||||||||||||||
| 908 | or $nodefault) | ||||||||||||||||||||||||||||||||||||||||||
| 909 | and next; | ||||||||||||||||||||||||||||||||||||||||||
| 910 | |||||||||||||||||||||||||||||||||||||||||||
| 911 | 7059 | push(@{$reduces{$$actions{$term}}},$term); | |||||||||||||||||||||||||||||||||||||||||
| 912 | } | ||||||||||||||||||||||||||||||||||||||||||
| 913 | |||||||||||||||||||||||||||||||||||||||||||
| 914 | 1718 | ▶ | keys(%reduces) > 0 | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 915 | or next; | ||||||||||||||||||||||||||||||||||||||||||
| 916 | |||||||||||||||||||||||||||||||||||||||||||
| 917 | 416 | $default=( map { $$_[0] } | |||||||||||||||||||||||||||||||||||||||||
| 918 | 40 | ▶ | sort { $$b[1] <=> $$a[1] or $$b[0] <=> $$a[0] } | ||||||||||||||||||||||||||||||||||||||||
|
Condition66%2/3
$Parse::Yapp::Lalr::b->[1] <=> $Parse::Yapp::Lalr::a->[1] || $Parse::Yapp::Lalr::b->[0] <=> $Parse::Yapp::Lalr::a->[0]
MC/DC0%0/2
$Parse::Yapp::Lalr::b->[1] <=> $Parse::Yapp::Lalr::a->[1] || $Parse::Yapp::Lalr::b->[0] <=> $Parse::Yapp::Lalr::a->[0]
$Parse::Yapp::Lalr::b->[1] <=> $Parse::Yapp::Lalr::a->[1]
$Parse::Yapp::Lalr::b->[0] <=> $Parse::Yapp::Lalr::a->[0]
Truth table66%2/3
A || B
A= $Parse::Yapp::Lalr::b->[1] <=> $Parse::Yapp::Lalr::a->[1]B= $Parse::Yapp::Lalr::b->[0] <=> $Parse::Yapp::Lalr::a->[0]
| |||||||||||||||||||||||||||||||||||||||||||
| 919 | 377 | map { [ $_, scalar(@{$reduces{$_}}) ] } | |||||||||||||||||||||||||||||||||||||||||
| 920 | keys(%reduces))[0]; | ||||||||||||||||||||||||||||||||||||||||||
| 921 | |||||||||||||||||||||||||||||||||||||||||||
| 922 | 377 | delete(@$actions{ @{$reduces{$default}} }); | |||||||||||||||||||||||||||||||||||||||||
| 923 | 377 | $$state{ACTIONS}{''}=$default; | |||||||||||||||||||||||||||||||||||||||||
| 924 | } | ||||||||||||||||||||||||||||||||||||||||||
| 925 | } | ||||||||||||||||||||||||||||||||||||||||||
| 926 | |||||||||||||||||||||||||||||||||||||||||||
| 927 | 10 | ▶ | sub _LALR { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_LALR: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 928 | 10 | my($grammar,$states) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 929 | 10 | my($conflicts,$inconsistent); | |||||||||||||||||||||||||||||||||||||||||
| 930 | |||||||||||||||||||||||||||||||||||||||||||
| 931 | 10 | $inconsistent = _ComputeLA($grammar,$states); | |||||||||||||||||||||||||||||||||||||||||
| 932 | |||||||||||||||||||||||||||||||||||||||||||
| 933 | 10 | $conflicts = _SolveConflicts($grammar,$states,$inconsistent); | |||||||||||||||||||||||||||||||||||||||||
| 934 | 10 | _SetDefaults($states); | |||||||||||||||||||||||||||||||||||||||||
| 935 | |||||||||||||||||||||||||||||||||||||||||||
| 936 | 10 | $conflicts | |||||||||||||||||||||||||||||||||||||||||
| 937 | } | ||||||||||||||||||||||||||||||||||||||||||
| 938 | |||||||||||||||||||||||||||||||||||||||||||
| 939 | |||||||||||||||||||||||||||||||||||||||||||
| 940 | 3 | 1; | |||||||||||||||||||||||||||||||||||||||||