| 1 | package Parse::Eyapp::Lalr; | ||||||||||||||||||||||||||||||||||||||||||
| 2 | 61 | @ISA=qw( Parse::Eyapp::Grammar ); | |||||||||||||||||||||||||||||||||||||||||
| 3 | |||||||||||||||||||||||||||||||||||||||||||
| 4 | 61 | require 5.004; | |||||||||||||||||||||||||||||||||||||||||
| 5 | |||||||||||||||||||||||||||||||||||||||||||
| 6 | 61 | ▶ | use Parse::Eyapp::Grammar; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 7 | 61 | ▶ | use Data::Dumper; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 8 | |||||||||||||||||||||||||||||||||||||||||||
| 9 | # Parse::Eyapp::Compile Object Structure: | ||||||||||||||||||||||||||||||||||||||||||
| 10 | # -------------------------------------- | ||||||||||||||||||||||||||||||||||||||||||
| 11 | # { | ||||||||||||||||||||||||||||||||||||||||||
| 12 | # GRAMMAR => Parse::Eyapp::Grammar, | ||||||||||||||||||||||||||||||||||||||||||
| 13 | # STATES => [ { CORE => [ items... ], | ||||||||||||||||||||||||||||||||||||||||||
| 14 | # ACTIONS => { term => action } | ||||||||||||||||||||||||||||||||||||||||||
| 15 | # GOTOS => { nterm => stateno } | ||||||||||||||||||||||||||||||||||||||||||
| 16 | # }... ] | ||||||||||||||||||||||||||||||||||||||||||
| 17 | # CONFLICTS=>{ SOLVED => { stateno => [ ruleno, token, solved ] }, | ||||||||||||||||||||||||||||||||||||||||||
| 18 | # FORCED => { TOTAL => [ nbsr, nbrr ], | ||||||||||||||||||||||||||||||||||||||||||
| 19 | # DETAIL => { stateno => { TOTAL => [ nbsr, nbrr ] } | ||||||||||||||||||||||||||||||||||||||||||
| 20 | # LIST => [ ruleno, token ] | ||||||||||||||||||||||||||||||||||||||||||
| 21 | # } | ||||||||||||||||||||||||||||||||||||||||||
| 22 | # } | ||||||||||||||||||||||||||||||||||||||||||
| 23 | # } | ||||||||||||||||||||||||||||||||||||||||||
| 24 | # } | ||||||||||||||||||||||||||||||||||||||||||
| 25 | # | ||||||||||||||||||||||||||||||||||||||||||
| 26 | # 'items' are of form: [ ruleno, dotpos ] | ||||||||||||||||||||||||||||||||||||||||||
| 27 | # 'term' in ACTIONS is '' means default action | ||||||||||||||||||||||||||||||||||||||||||
| 28 | # 'action' may be: | ||||||||||||||||||||||||||||||||||||||||||
| 29 | # undef: explicit error (nonassociativity) | ||||||||||||||||||||||||||||||||||||||||||
| 30 | # 0 : accept | ||||||||||||||||||||||||||||||||||||||||||
| 31 | # >0 : shift and go to state 'action' | ||||||||||||||||||||||||||||||||||||||||||
| 32 | # <0 : reduce using rule -'action' | ||||||||||||||||||||||||||||||||||||||||||
| 33 | # 'solved' may have values of: | ||||||||||||||||||||||||||||||||||||||||||
| 34 | # 'shift' if solved as Shift | ||||||||||||||||||||||||||||||||||||||||||
| 35 | # 'reduce' if solved as Reduce | ||||||||||||||||||||||||||||||||||||||||||
| 36 | # 'error' if solved by discarding both Shift and Reduce (nonassoc) | ||||||||||||||||||||||||||||||||||||||||||
| 37 | # | ||||||||||||||||||||||||||||||||||||||||||
| 38 | # SOLVED is a set of states containing Solved conflicts | ||||||||||||||||||||||||||||||||||||||||||
| 39 | # FORCED are forced conflict resolutions | ||||||||||||||||||||||||||||||||||||||||||
| 40 | # | ||||||||||||||||||||||||||||||||||||||||||
| 41 | # nbsr and nbrr are number of shift/reduce and reduce/reduce conflicts | ||||||||||||||||||||||||||||||||||||||||||
| 42 | # | ||||||||||||||||||||||||||||||||||||||||||
| 43 | # TOTAL is the total number of SR/RR conflicts for the parser | ||||||||||||||||||||||||||||||||||||||||||
| 44 | # | ||||||||||||||||||||||||||||||||||||||||||
| 45 | # DETAIL is the detail of conflicts for each state | ||||||||||||||||||||||||||||||||||||||||||
| 46 | # TOTAL is the total number of SR/RR conflicts for a state | ||||||||||||||||||||||||||||||||||||||||||
| 47 | # LIST is the list of discarded reductions (for display purpose only) | ||||||||||||||||||||||||||||||||||||||||||
| 48 | |||||||||||||||||||||||||||||||||||||||||||
| 49 | |||||||||||||||||||||||||||||||||||||||||||
| 50 | 61 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 51 | |||||||||||||||||||||||||||||||||||||||||||
| 52 | 61 | ▶ | use Carp; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 53 | |||||||||||||||||||||||||||||||||||||||||||
| 54 | ############### | ||||||||||||||||||||||||||||||||||||||||||
| 55 | # Constructor # | ||||||||||||||||||||||||||||||||||||||||||
| 56 | ############### | ||||||||||||||||||||||||||||||||||||||||||
| 57 | 54 | ▶ | sub new { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
new: called CC=5 SCAR=20.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 58 | 54 | my($class)=shift; | |||||||||||||||||||||||||||||||||||||||||
| 59 | |||||||||||||||||||||||||||||||||||||||||||
| 60 | 54 | ▶ | ref($class) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 61 | and $class=ref($class); | ||||||||||||||||||||||||||||||||||||||||||
| 62 | |||||||||||||||||||||||||||||||||||||||||||
| 63 | 54 | my($self)=$class->SUPER::new(@_); | |||||||||||||||||||||||||||||||||||||||||
| 64 | 54 | $self->_Compile(); | |||||||||||||||||||||||||||||||||||||||||
| 65 | 54 | $self->_DynamicConflicts(); # call it only if dynamic conflict handlers | |||||||||||||||||||||||||||||||||||||||||
| 66 | |||||||||||||||||||||||||||||||||||||||||||
| 67 | 54 | ▶ | if ($self->Option('prefix')) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 68 | # weak accept for nested parsing !!!!!!!!!!!! | ||||||||||||||||||||||||||||||||||||||||||
| 69 | # substitute End Of Input by DEFAULT for each state | ||||||||||||||||||||||||||||||||||||||||||
| 70 | 0 | for (@{$self->{STATES}}) { | |||||||||||||||||||||||||||||||||||||||||
| 71 | 0 | ▶ | if (exists($_->{ACTIONS}{"\c@"})) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 72 | # what if DEFAULT action already exists ? | ||||||||||||||||||||||||||||||||||||||||||
| 73 | # Shall I have to use an option in eyapp???? | ||||||||||||||||||||||||||||||||||||||||||
| 74 | 0 | $_->{ACTIONS}{''} = $_->{ACTIONS}{"\c@"}; | |||||||||||||||||||||||||||||||||||||||||
| 75 | 0 | delete($_->{ACTIONS}{"\c@"}); | |||||||||||||||||||||||||||||||||||||||||
| 76 | } | ||||||||||||||||||||||||||||||||||||||||||
| 77 | } | ||||||||||||||||||||||||||||||||||||||||||
| 78 | } | ||||||||||||||||||||||||||||||||||||||||||
| 79 | |||||||||||||||||||||||||||||||||||||||||||
| 80 | 54 | bless($self,$class); | |||||||||||||||||||||||||||||||||||||||||
| 81 | } | ||||||||||||||||||||||||||||||||||||||||||
| 82 | ########### | ||||||||||||||||||||||||||||||||||||||||||
| 83 | # Methods # | ||||||||||||||||||||||||||||||||||||||||||
| 84 | ########### | ||||||||||||||||||||||||||||||||||||||||||
| 85 | |||||||||||||||||||||||||||||||||||||||||||
| 86 | ########################### | ||||||||||||||||||||||||||||||||||||||||||
| 87 | # Method To View Warnings # | ||||||||||||||||||||||||||||||||||||||||||
| 88 | ########################### | ||||||||||||||||||||||||||||||||||||||||||
| 89 | 4 | ▶ | sub Warnings { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
Warnings: called CC=9 SCAR=26.2
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 90 | 4 | my($self)=shift; | |||||||||||||||||||||||||||||||||||||||||
| 91 | 4 | my($text) = ''; | |||||||||||||||||||||||||||||||||||||||||
| 92 | |||||||||||||||||||||||||||||||||||||||||||
| 93 | # $nbsr = number of shift-reduce conflicts | ||||||||||||||||||||||||||||||||||||||||||
| 94 | # $nbrr = number of reduce-reduce conflicts | ||||||||||||||||||||||||||||||||||||||||||
| 95 | 4 | my($nbsr,$nbrr)=@{$$self{CONFLICTS}{FORCED}{TOTAL}}; | |||||||||||||||||||||||||||||||||||||||||
| 96 | |||||||||||||||||||||||||||||||||||||||||||
| 97 | 4 | $text=$self->SUPER::Warnings(); | |||||||||||||||||||||||||||||||||||||||||
| 98 | |||||||||||||||||||||||||||||||||||||||||||
| 99 | 4 | my $expected = $$self{GRAMMAR}{EXPECT}; | |||||||||||||||||||||||||||||||||||||||||
| 100 | 4 | ▶ | my ($sre, $rre) = ref($expected) ? @$expected : ($expected, 0); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 101 | |||||||||||||||||||||||||||||||||||||||||||
| 102 | 4 | ▶ | $nbsr != $sre and $nbsr > 0 and do { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$nbsr != $sre and $nbsr > 0
MC/DC50%1/2
$nbsr != $sre and $nbsr > 0
$nbsr != $sre
$nbsr > 0
Truth table66%2/3
A and B
A= $nbsr != $sreB= $nbsr > 0
| |||||||||||||||||||||||||||||||||||||||||||
| 103 | 1 | ▶ | $text.="$nbsr shift/reduce conflict".($nbsr > 1 ? "s " : " "); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 104 | }; # end of $nbsr != $sre There were shift-reduce conflicts | ||||||||||||||||||||||||||||||||||||||||||
| 105 | |||||||||||||||||||||||||||||||||||||||||||
| 106 | 4 | ▶ | $nbrr != $rre and $nbrr > 0 and do { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$nbrr != $rre and $nbrr > 0
MC/DC0%0/2
$nbrr != $rre and $nbrr > 0
$nbrr != $rre
$nbrr > 0
Truth table33%1/3
A and B
A= $nbrr != $rreB= $nbrr > 0
| |||||||||||||||||||||||||||||||||||||||||||
| 107 | 0 | ▶ | $nbsr != $sre and $text.="and "; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 108 | 0 | ▶ | $text.="$nbrr reduce/reduce conflict".($nbrr > 1 ? "s" : ""); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 109 | }; | ||||||||||||||||||||||||||||||||||||||||||
| 110 | |||||||||||||||||||||||||||||||||||||||||||
| 111 | 4 | $text; | |||||||||||||||||||||||||||||||||||||||||
| 112 | } | ||||||||||||||||||||||||||||||||||||||||||
| 113 | ############################# | ||||||||||||||||||||||||||||||||||||||||||
| 114 | # Method To View DFA States # | ||||||||||||||||||||||||||||||||||||||||||
| 115 | ############################# | ||||||||||||||||||||||||||||||||||||||||||
| 116 | 0 | ▶ | sub ShowDfa { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
ShowDfa: not called CC=26 SCAR=65.5
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 117 | 0 | my($self)=shift; | |||||||||||||||||||||||||||||||||||||||||
| 118 | 0 | my($text) = ''; | |||||||||||||||||||||||||||||||||||||||||
| 119 | 0 | my($grammar,$states)=($$self{GRAMMAR}, $$self{STATES}); | |||||||||||||||||||||||||||||||||||||||||
| 120 | |||||||||||||||||||||||||||||||||||||||||||
| 121 | 0 | for my $stateno (0..$#$states) { | |||||||||||||||||||||||||||||||||||||||||
| 122 | 0 | my(@shifts,@reduces,@errors,$default); | |||||||||||||||||||||||||||||||||||||||||
| 123 | |||||||||||||||||||||||||||||||||||||||||||
| 124 | 0 | $text.="State $stateno:\n\n"; | |||||||||||||||||||||||||||||||||||||||||
| 125 | |||||||||||||||||||||||||||||||||||||||||||
| 126 | #Dump Kernel Items | ||||||||||||||||||||||||||||||||||||||||||
| 127 | 0 | ▶ | for (sort { $$a[0] <=> $$b[0] | ||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/3
$Parse::Eyapp::Lalr::a->[0] <=> $Parse::Eyapp::Lalr::b->[0] || $Parse::Eyapp::Lalr::a->[1] <=> $Parse::Eyapp::Lalr::b->[1]
MC/DC0%0/2
$Parse::Eyapp::Lalr::a->[0] <=> $Parse::Eyapp::Lalr::b->[0] || $Parse::Eyapp::Lalr::a->[1] <=> $Parse::Eyapp::Lalr::b->[1]
$Parse::Eyapp::Lalr::a->[0] <=> $Parse::Eyapp::Lalr::b->[0]
$Parse::Eyapp::Lalr::a->[1] <=> $Parse::Eyapp::Lalr::b->[1]
Truth table0%0/3
A || B
A= $Parse::Eyapp::Lalr::a->[0] <=> $Parse::Eyapp::Lalr::b->[0]B= $Parse::Eyapp::Lalr::a->[1] <=> $Parse::Eyapp::Lalr::b->[1]
| |||||||||||||||||||||||||||||||||||||||||||
| 128 | 0 | or $$a[1] <=> $$b[1] } @{$$states[$stateno]{'CORE'}}) { | |||||||||||||||||||||||||||||||||||||||||
| 129 | 0 | my($ruleno,$pos)=@$_; | |||||||||||||||||||||||||||||||||||||||||
| 130 | 0 | my($lhs,$rhs)=@{$$grammar{RULES}[$ruleno]}[0,1]; | |||||||||||||||||||||||||||||||||||||||||
| 131 | 0 | my(@rhscopy)=@$rhs; | |||||||||||||||||||||||||||||||||||||||||
| 132 | |||||||||||||||||||||||||||||||||||||||||||
| 133 | 0 | ▶ | $ruleno | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 134 | or $rhscopy[-1] = '$end'; | ||||||||||||||||||||||||||||||||||||||||||
| 135 | |||||||||||||||||||||||||||||||||||||||||||
| 136 | 0 | splice(@rhscopy,$pos,0,'.'); | |||||||||||||||||||||||||||||||||||||||||
| 137 | 0 | $text.= "\t$lhs -> ".join(' ',@rhscopy)."\t(Rule $ruleno)\n"; | |||||||||||||||||||||||||||||||||||||||||
| 138 | } | ||||||||||||||||||||||||||||||||||||||||||
| 139 | |||||||||||||||||||||||||||||||||||||||||||
| 140 | #Prepare Actions | ||||||||||||||||||||||||||||||||||||||||||
| 141 | 0 | for (keys(%{$$states[$stateno]{ACTIONS}})) { | |||||||||||||||||||||||||||||||||||||||||
| 142 | 0 | my($term,$action)=($_,$$states[$stateno]{ACTIONS}{$_}); | |||||||||||||||||||||||||||||||||||||||||
| 143 | |||||||||||||||||||||||||||||||||||||||||||
| 144 | 0 | ▶ | $term eq chr(0) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 145 | and $term = '$end'; | ||||||||||||||||||||||||||||||||||||||||||
| 146 | |||||||||||||||||||||||||||||||||||||||||||
| 147 | not defined($action) | ||||||||||||||||||||||||||||||||||||||||||
| 148 | 0 | ▶ | and do { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 149 | 0 | push(@errors,$term); | |||||||||||||||||||||||||||||||||||||||||
| 150 | 0 | next; | |||||||||||||||||||||||||||||||||||||||||
| 151 | }; | ||||||||||||||||||||||||||||||||||||||||||
| 152 | |||||||||||||||||||||||||||||||||||||||||||
| 153 | $action > 0 | ||||||||||||||||||||||||||||||||||||||||||
| 154 | 0 | ▶ | and do { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 155 | 0 | push(@shifts,[ $term, $action ]); | |||||||||||||||||||||||||||||||||||||||||
| 156 | 0 | next; | |||||||||||||||||||||||||||||||||||||||||
| 157 | }; | ||||||||||||||||||||||||||||||||||||||||||
| 158 | |||||||||||||||||||||||||||||||||||||||||||
| 159 | 0 | $action = -$action; | |||||||||||||||||||||||||||||||||||||||||
| 160 | |||||||||||||||||||||||||||||||||||||||||||
| 161 | $term | ||||||||||||||||||||||||||||||||||||||||||
| 162 | 0 | ▶ | or do { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 163 | 0 | $default= [ '$default', $action ]; | |||||||||||||||||||||||||||||||||||||||||
| 164 | 0 | next; | |||||||||||||||||||||||||||||||||||||||||
| 165 | }; | ||||||||||||||||||||||||||||||||||||||||||
| 166 | |||||||||||||||||||||||||||||||||||||||||||
| 167 | 0 | push(@reduces,[ $term, $action ]); | |||||||||||||||||||||||||||||||||||||||||
| 168 | } | ||||||||||||||||||||||||||||||||||||||||||
| 169 | |||||||||||||||||||||||||||||||||||||||||||
| 170 | #Dump shifts | ||||||||||||||||||||||||||||||||||||||||||
| 171 | @shifts | ||||||||||||||||||||||||||||||||||||||||||
| 172 | 0 | ▶ | and do { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 173 | 0 | $text.="\n"; | |||||||||||||||||||||||||||||||||||||||||
| 174 | 0 | for (sort { $$a[0] cmp $$b[0] } @shifts) { | |||||||||||||||||||||||||||||||||||||||||
| 175 | 0 | my($term,$shift)=@$_; | |||||||||||||||||||||||||||||||||||||||||
| 176 | |||||||||||||||||||||||||||||||||||||||||||
| 177 | 0 | $text.="\t$term\tshift, and go to state $shift\n"; | |||||||||||||||||||||||||||||||||||||||||
| 178 | } | ||||||||||||||||||||||||||||||||||||||||||
| 179 | }; | ||||||||||||||||||||||||||||||||||||||||||
| 180 | |||||||||||||||||||||||||||||||||||||||||||
| 181 | #Dump errors | ||||||||||||||||||||||||||||||||||||||||||
| 182 | @errors | ||||||||||||||||||||||||||||||||||||||||||
| 183 | 0 | ▶ | and do { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 184 | 0 | $text.="\n"; | |||||||||||||||||||||||||||||||||||||||||
| 185 | 0 | for my $term (sort { $a cmp $b } @errors) { | |||||||||||||||||||||||||||||||||||||||||
| 186 | 0 | $text.="\t$term\terror (nonassociative)\n"; | |||||||||||||||||||||||||||||||||||||||||
| 187 | } | ||||||||||||||||||||||||||||||||||||||||||
| 188 | }; | ||||||||||||||||||||||||||||||||||||||||||
| 189 | |||||||||||||||||||||||||||||||||||||||||||
| 190 | #Prepare reduces | ||||||||||||||||||||||||||||||||||||||||||
| 191 | exists($$self{CONFLICTS}{FORCED}{DETAIL}{$stateno}) | ||||||||||||||||||||||||||||||||||||||||||
| 192 | 0 | ▶ | and push(@reduces,@{$$self{CONFLICTS}{FORCED}{DETAIL}{$stateno}{LIST}}); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 193 | |||||||||||||||||||||||||||||||||||||||||||
| 194 | 0 | ▶ | @reduces=sort { $$a[0] cmp $$b[0] or $$a[1] <=> $$b[1] } @reduces; | ||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/3
$Parse::Eyapp::Lalr::a->[0] cmp $Parse::Eyapp::Lalr::b->[0] || $Parse::Eyapp::Lalr::a->[1] <=> $Parse::Eyapp::Lalr::b->[1]
MC/DC0%0/2
$Parse::Eyapp::Lalr::a->[0] cmp $Parse::Eyapp::Lalr::b->[0] || $Parse::Eyapp::Lalr::a->[1] <=> $Parse::Eyapp::Lalr::b->[1]
$Parse::Eyapp::Lalr::a->[0] cmp $Parse::Eyapp::Lalr::b->[0]
$Parse::Eyapp::Lalr::a->[1] <=> $Parse::Eyapp::Lalr::b->[1]
Truth table0%0/3
A || B
A= $Parse::Eyapp::Lalr::a->[0] cmp $Parse::Eyapp::Lalr::b->[0]B= $Parse::Eyapp::Lalr::a->[1] <=> $Parse::Eyapp::Lalr::b->[1]
| |||||||||||||||||||||||||||||||||||||||||||
| 195 | |||||||||||||||||||||||||||||||||||||||||||
| 196 | 0 | ▶ | defined($default) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 197 | and push(@reduces,$default); | ||||||||||||||||||||||||||||||||||||||||||
| 198 | |||||||||||||||||||||||||||||||||||||||||||
| 199 | #Dump reduces | ||||||||||||||||||||||||||||||||||||||||||
| 200 | @reduces | ||||||||||||||||||||||||||||||||||||||||||
| 201 | 0 | ▶ | and do { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 202 | 0 | $text.="\n"; | |||||||||||||||||||||||||||||||||||||||||
| 203 | 0 | for (@reduces) { | |||||||||||||||||||||||||||||||||||||||||
| 204 | 0 | my($term,$ruleno)=@$_; | |||||||||||||||||||||||||||||||||||||||||
| 205 | 0 | my($discard); | |||||||||||||||||||||||||||||||||||||||||
| 206 | |||||||||||||||||||||||||||||||||||||||||||
| 207 | $ruleno < 0 | ||||||||||||||||||||||||||||||||||||||||||
| 208 | 0 | ▶ | and do { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 209 | 0 | ++$discard; | |||||||||||||||||||||||||||||||||||||||||
| 210 | 0 | $ruleno = -$ruleno; | |||||||||||||||||||||||||||||||||||||||||
| 211 | }; | ||||||||||||||||||||||||||||||||||||||||||
| 212 | |||||||||||||||||||||||||||||||||||||||||||
| 213 | 0 | ▶ | $term eq chr(0) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 214 | and $term = '$end'; | ||||||||||||||||||||||||||||||||||||||||||
| 215 | |||||||||||||||||||||||||||||||||||||||||||
| 216 | 0 | ▶ | $text.= "\t$term\t".($discard ? "[" : ""); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 217 | 0 | ▶ | if($ruleno) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 218 | 0 | $text.= "reduce using rule $ruleno ". | |||||||||||||||||||||||||||||||||||||||||
| 219 | "($$grammar{RULES}[$ruleno][0])"; | ||||||||||||||||||||||||||||||||||||||||||
| 220 | } | ||||||||||||||||||||||||||||||||||||||||||
| 221 | else { | ||||||||||||||||||||||||||||||||||||||||||
| 222 | 0 | $text.='accept'; | |||||||||||||||||||||||||||||||||||||||||
| 223 | } | ||||||||||||||||||||||||||||||||||||||||||
| 224 | 0 | ▶ | $text.=($discard ? "]" : "")."\n"; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 225 | } | ||||||||||||||||||||||||||||||||||||||||||
| 226 | }; | ||||||||||||||||||||||||||||||||||||||||||
| 227 | |||||||||||||||||||||||||||||||||||||||||||
| 228 | #Dump gotos | ||||||||||||||||||||||||||||||||||||||||||
| 229 | exists($$states[$stateno]{GOTOS}) | ||||||||||||||||||||||||||||||||||||||||||
| 230 | 0 | ▶ | and do { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 231 | 0 | $text.= "\n"; | |||||||||||||||||||||||||||||||||||||||||
| 232 | 0 | for (keys(%{$$states[$stateno]{GOTOS}})) { | |||||||||||||||||||||||||||||||||||||||||
| 233 | 0 | $text.= "\t$_\tgo to state $$states[$stateno]{GOTOS}{$_}\n"; | |||||||||||||||||||||||||||||||||||||||||
| 234 | } | ||||||||||||||||||||||||||||||||||||||||||
| 235 | }; | ||||||||||||||||||||||||||||||||||||||||||
| 236 | |||||||||||||||||||||||||||||||||||||||||||
| 237 | 0 | $text.="\n"; | |||||||||||||||||||||||||||||||||||||||||
| 238 | } | ||||||||||||||||||||||||||||||||||||||||||
| 239 | 0 | $text; | |||||||||||||||||||||||||||||||||||||||||
| 240 | } | ||||||||||||||||||||||||||||||||||||||||||
| 241 | |||||||||||||||||||||||||||||||||||||||||||
| 242 | #################################################################### | ||||||||||||||||||||||||||||||||||||||||||
| 243 | # Usage : $parser->outputtables($path, $base) | ||||||||||||||||||||||||||||||||||||||||||
| 244 | # Purpose : Gives support to eyapp option -v | ||||||||||||||||||||||||||||||||||||||||||
| 245 | # Parameters : The parser object plus the $path and $base names for the .output | ||||||||||||||||||||||||||||||||||||||||||
| 246 | # file | ||||||||||||||||||||||||||||||||||||||||||
| 247 | |||||||||||||||||||||||||||||||||||||||||||
| 248 | 0 | ▶ | sub outputtables { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
outputtables: not called CC=5 SCAR=34.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 249 | 0 | my ($parser, $path, $base) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 250 | |||||||||||||||||||||||||||||||||||||||||||
| 251 | 0 | ▶ | my($output)=$base?"$path$base.output":"STDOUT"; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 252 | 0 | my($tmp); | |||||||||||||||||||||||||||||||||||||||||
| 253 | |||||||||||||||||||||||||||||||||||||||||||
| 254 | 0 | ▶ | open(my $OUT,">$output") | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 255 | or die "Cannot create $base.output for writing.\n"; | ||||||||||||||||||||||||||||||||||||||||||
| 256 | |||||||||||||||||||||||||||||||||||||||||||
| 257 | 0 | ▶ | $tmp=$parser->Warnings() | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 258 | and print $OUT "Warnings:\n---------\n$tmp\n"; | ||||||||||||||||||||||||||||||||||||||||||
| 259 | 0 | ▶ | $tmp=$parser->Conflicts() | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 260 | and print $OUT "Conflicts:\n----------\n$tmp\n"; | ||||||||||||||||||||||||||||||||||||||||||
| 261 | 0 | print $OUT "Rules:\n------\n"; | |||||||||||||||||||||||||||||||||||||||||
| 262 | 0 | print $OUT $parser->ShowRules()."\n"; | |||||||||||||||||||||||||||||||||||||||||
| 263 | 0 | print $OUT "States:\n-------\n"; | |||||||||||||||||||||||||||||||||||||||||
| 264 | 0 | print $OUT $parser->ShowDfa()."\n"; | |||||||||||||||||||||||||||||||||||||||||
| 265 | 0 | print $OUT "Summary:\n--------\n"; | |||||||||||||||||||||||||||||||||||||||||
| 266 | 0 | print $OUT $parser->Summary(); | |||||||||||||||||||||||||||||||||||||||||
| 267 | |||||||||||||||||||||||||||||||||||||||||||
| 268 | 0 | close($OUT); | |||||||||||||||||||||||||||||||||||||||||
| 269 | } | ||||||||||||||||||||||||||||||||||||||||||
| 270 | |||||||||||||||||||||||||||||||||||||||||||
| 271 | 0 | ▶ | sub outputDot { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
outputDot: not called CC=14 SCAR=53.5
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 272 | 0 | my ($parser, $path, $base, $labelWithCore) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 273 | |||||||||||||||||||||||||||||||||||||||||||
| 274 | 0 | ▶ | my ($output)=$base?"$path$base.dot":"STDOUT"; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 275 | |||||||||||||||||||||||||||||||||||||||||||
| 276 | 0 | ▶ | open(my $OUT,">$output") | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 277 | or die "Cannot create $base.dot for writing.\n"; | ||||||||||||||||||||||||||||||||||||||||||
| 278 | |||||||||||||||||||||||||||||||||||||||||||
| 279 | 0 | my $graph = ''; | |||||||||||||||||||||||||||||||||||||||||
| 280 | |||||||||||||||||||||||||||||||||||||||||||
| 281 | 0 | my $dfa = $parser->ShowDfa(); | |||||||||||||||||||||||||||||||||||||||||
| 282 | |||||||||||||||||||||||||||||||||||||||||||
| 283 | #warn "$dfa\n"; | ||||||||||||||||||||||||||||||||||||||||||
| 284 | |||||||||||||||||||||||||||||||||||||||||||
| 285 | 0 | my $grammar = $parser->ShowRules()."\n"; | |||||||||||||||||||||||||||||||||||||||||
| 286 | |||||||||||||||||||||||||||||||||||||||||||
| 287 | #warn "$grammar\n"; | ||||||||||||||||||||||||||||||||||||||||||
| 288 | |||||||||||||||||||||||||||||||||||||||||||
| 289 | # make an array from the grammar | ||||||||||||||||||||||||||||||||||||||||||
| 290 | |||||||||||||||||||||||||||||||||||||||||||
| 291 | 0 | my %grammar = $grammar =~ m{(\d+):\s+(.*)}gx; | |||||||||||||||||||||||||||||||||||||||||
| 292 | |||||||||||||||||||||||||||||||||||||||||||
| 293 | # escape double quotes inside %grammar | ||||||||||||||||||||||||||||||||||||||||||
| 294 | 0 | $graph .= qq{ "g0" [label="0: $grammar{0}", shape = doubleoctagon, fontcolor=blue, color=blue ]\n}; | |||||||||||||||||||||||||||||||||||||||||
| 295 | 0 | for (1 .. (keys %grammar)-1) { | |||||||||||||||||||||||||||||||||||||||||
| 296 | 0 | $grammar{$_} =~ s/\\/\\\\/g; # escape escapes | |||||||||||||||||||||||||||||||||||||||||
| 297 | 0 | $grammar{$_} =~ s/"/\\"/g; # escape double quotes | |||||||||||||||||||||||||||||||||||||||||
| 298 | |||||||||||||||||||||||||||||||||||||||||||
| 299 | #warn "$_ => $grammar{$_}\n"; | ||||||||||||||||||||||||||||||||||||||||||
| 300 | |||||||||||||||||||||||||||||||||||||||||||
| 301 | 0 | $graph .= qq{ "g$_" [label="$_: $grammar{$_}", shape = box, fontcolor=blue, color=blue ]\n}; | |||||||||||||||||||||||||||||||||||||||||
| 302 | } | ||||||||||||||||||||||||||||||||||||||||||
| 303 | |||||||||||||||||||||||||||||||||||||||||||
| 304 | 0 | for (0 .. (keys %grammar)-2) { | |||||||||||||||||||||||||||||||||||||||||
| 305 | 0 | my $n = $_+1; | |||||||||||||||||||||||||||||||||||||||||
| 306 | 0 | $graph .= qq{ g$_ ->g$n [style=dotted];\n}; | |||||||||||||||||||||||||||||||||||||||||
| 307 | } | ||||||||||||||||||||||||||||||||||||||||||
| 308 | |||||||||||||||||||||||||||||||||||||||||||
| 309 | 0 | my $conflicts = $parser->Conflicts(); | |||||||||||||||||||||||||||||||||||||||||
| 310 | |||||||||||||||||||||||||||||||||||||||||||
| 311 | #warn $conflicts; | ||||||||||||||||||||||||||||||||||||||||||
| 312 | |||||||||||||||||||||||||||||||||||||||||||
| 313 | # State 13 contains 5 shift/reduce conflicts | ||||||||||||||||||||||||||||||||||||||||||
| 314 | # State 23 contains 5 shift/reduce conflicts | ||||||||||||||||||||||||||||||||||||||||||
| 315 | 0 | my @conflictstates = $conflicts =~ m{State\s+(\d+)\s+contains\s+\d+\s+(?:shift|reduce)/reduce\s+conflicts?\s*}gx; | |||||||||||||||||||||||||||||||||||||||||
| 316 | |||||||||||||||||||||||||||||||||||||||||||
| 317 | #warn "(@conflictstates)\n"; | ||||||||||||||||||||||||||||||||||||||||||
| 318 | |||||||||||||||||||||||||||||||||||||||||||
| 319 | 0 | $graph .= qq{$_ [shape = diamond, fontcolor=red, color=red]\n} for @conflictstates; | |||||||||||||||||||||||||||||||||||||||||
| 320 | |||||||||||||||||||||||||||||||||||||||||||
| 321 | 0 | my %states = ($dfa =~ m{State\s*(\d+)\s*:\n\s* | |||||||||||||||||||||||||||||||||||||||||
| 322 | ( | ||||||||||||||||||||||||||||||||||||||||||
| 323 | (?: | ||||||||||||||||||||||||||||||||||||||||||
| 324 | .*->.* | # a production line | ||||||||||||||||||||||||||||||||||||||||||
| 325 | .*go\s+to.* | # a shift or a goto line | ||||||||||||||||||||||||||||||||||||||||||
| 326 | .*reduce.* | # a reduce line | ||||||||||||||||||||||||||||||||||||||||||
| 327 | .*accept.* | # an accept line | ||||||||||||||||||||||||||||||||||||||||||
| 328 | \s+ | # white lines | ||||||||||||||||||||||||||||||||||||||||||
| 329 | )+ | ||||||||||||||||||||||||||||||||||||||||||
| 330 | ) | ||||||||||||||||||||||||||||||||||||||||||
| 331 | }gx); | ||||||||||||||||||||||||||||||||||||||||||
| 332 | |||||||||||||||||||||||||||||||||||||||||||
| 333 | 0 | for (sort { $a <=> $b } keys %states) { | |||||||||||||||||||||||||||||||||||||||||
| 334 | 0 | my $desc = $states{$_}; | |||||||||||||||||||||||||||||||||||||||||
| 335 | 0 | my @LRitems = $desc =~ m{(\S.*->.*[^\s.])\s+\(Rule\s+\d+\)}g; # remove productions | |||||||||||||||||||||||||||||||||||||||||
| 336 | |||||||||||||||||||||||||||||||||||||||||||
| 337 | # label states with core LR-0 items | ||||||||||||||||||||||||||||||||||||||||||
| 338 | 0 | ▶ | if ($labelWithCore) { # this is optional | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 339 | 0 | local $" = "\\n"; | |||||||||||||||||||||||||||||||||||||||||
| 340 | 0 | $graph .= qq{$_ [ label = "$_\\n@LRitems"}; #shape = plaintext, | |||||||||||||||||||||||||||||||||||||||||
| 341 | 0 | my $s = $_; | |||||||||||||||||||||||||||||||||||||||||
| 342 | 0 | ▶ | $graph .= qq{, shape = plaintext} unless (grep { $_ eq $s} @conflictstates); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 343 | 0 | $graph .= "]\n"; | |||||||||||||||||||||||||||||||||||||||||
| 344 | } | ||||||||||||||||||||||||||||||||||||||||||
| 345 | |||||||||||||||||||||||||||||||||||||||||||
| 346 | #warn "LRitems in $_:\n@LRitems\n"; | ||||||||||||||||||||||||||||||||||||||||||
| 347 | |||||||||||||||||||||||||||||||||||||||||||
| 348 | 0 | $desc =~ s/\n\s*\n/\n/g; # remove white lines | |||||||||||||||||||||||||||||||||||||||||
| 349 | |||||||||||||||||||||||||||||||||||||||||||
| 350 | # build digraph | ||||||||||||||||||||||||||||||||||||||||||
| 351 | # ID shift, and go to state 4 | ||||||||||||||||||||||||||||||||||||||||||
| 352 | 0 | ▶ | while ($desc =~ m{\t(.*)\s+shift,\s+and\s+go\s+to\s+state\s+(\d+)}gx) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 353 | 0 | my ($label, $state) = ($1, $2); | |||||||||||||||||||||||||||||||||||||||||
| 354 | 0 | $label =~ s/\\(?!")/\\\\/g; | |||||||||||||||||||||||||||||||||||||||||
| 355 | 0 | $graph .= qq{$_ -> $state [label = "$label"]\n}; | |||||||||||||||||||||||||||||||||||||||||
| 356 | } | ||||||||||||||||||||||||||||||||||||||||||
| 357 | |||||||||||||||||||||||||||||||||||||||||||
| 358 | # decl go to state 1 | ||||||||||||||||||||||||||||||||||||||||||
| 359 | 0 | ▶ | while ($desc =~ m{\t(\S+)\s+go\s+to\s+state\s+(\d+)}gx) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 360 | 0 | $graph .= qq{$_ -> $2 [label = "$1", arrowhead = odot, color = "red", fontcolor = "red"]\n}; | |||||||||||||||||||||||||||||||||||||||||
| 361 | } | ||||||||||||||||||||||||||||||||||||||||||
| 362 | |||||||||||||||||||||||||||||||||||||||||||
| 363 | # $default reduce using rule 1 (prog) | ||||||||||||||||||||||||||||||||||||||||||
| 364 | # ID reduce using rule 15 (decORexp_explorer) | ||||||||||||||||||||||||||||||||||||||||||
| 365 | 0 | ▶ | while ($desc =~ m{\t(\S+)\s+reduce\s+using\s+rule\s+(\d+)}gx) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 366 | 0 | $graph .= qq{$_ -> "g$2" [label = "$1", arrowhead=dot, color = "blue", fontcolor = "blue"]\n}; | |||||||||||||||||||||||||||||||||||||||||
| 367 | } | ||||||||||||||||||||||||||||||||||||||||||
| 368 | |||||||||||||||||||||||||||||||||||||||||||
| 369 | # shift-reduce conflicts | ||||||||||||||||||||||||||||||||||||||||||
| 370 | # ';' [reduce using rule 4 (ds)] | ||||||||||||||||||||||||||||||||||||||||||
| 371 | 0 | ▶ | while ($desc =~ m{\t(\S+)\s+\[\s*reduce\s+using\s+rule\s+(\d+)}gx) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 372 | 0 | $graph .= | |||||||||||||||||||||||||||||||||||||||||
| 373 | qq{$_ -> "g$2" [label = "$1", arrowhead=dot, style=dotted, color = "red", fontcolor = "red"]\n}; | ||||||||||||||||||||||||||||||||||||||||||
| 374 | } | ||||||||||||||||||||||||||||||||||||||||||
| 375 | |||||||||||||||||||||||||||||||||||||||||||
| 376 | # $default accept | ||||||||||||||||||||||||||||||||||||||||||
| 377 | 0 | ▶ | if ($desc =~ m{\t\$default\s+accept\s*}gx) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 378 | 0 | $graph .= qq{$_ [shape = doublecircle]\n}; | |||||||||||||||||||||||||||||||||||||||||
| 379 | 0 | $graph .= qq{$_ -> "g0" [arrowhead = dot, color = blue]\n}; | |||||||||||||||||||||||||||||||||||||||||
| 380 | } | ||||||||||||||||||||||||||||||||||||||||||
| 381 | |||||||||||||||||||||||||||||||||||||||||||
| 382 | #warn "$_ => $desc\n"; | ||||||||||||||||||||||||||||||||||||||||||
| 383 | |||||||||||||||||||||||||||||||||||||||||||
| 384 | } | ||||||||||||||||||||||||||||||||||||||||||
| 385 | 0 | print $OUT <<"EOGRAPH"; | |||||||||||||||||||||||||||||||||||||||||
| 386 | digraph G { | ||||||||||||||||||||||||||||||||||||||||||
| 387 | #concentrate = true | ||||||||||||||||||||||||||||||||||||||||||
| 388 | |||||||||||||||||||||||||||||||||||||||||||
| 389 | $graph | ||||||||||||||||||||||||||||||||||||||||||
| 390 | } | ||||||||||||||||||||||||||||||||||||||||||
| 391 | EOGRAPH | ||||||||||||||||||||||||||||||||||||||||||
| 392 | 0 | close $OUT; | |||||||||||||||||||||||||||||||||||||||||
| 393 | } | ||||||||||||||||||||||||||||||||||||||||||
| 394 | |||||||||||||||||||||||||||||||||||||||||||
| 395 | 0 | ▶ | sub qtables { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
qtables: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 396 | 0 | my ($parser) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 397 | |||||||||||||||||||||||||||||||||||||||||||
| 398 | 0 | my($tmp); | |||||||||||||||||||||||||||||||||||||||||
| 399 | |||||||||||||||||||||||||||||||||||||||||||
| 400 | 0 | my $warnings = $parser->Warnings(); | |||||||||||||||||||||||||||||||||||||||||
| 401 | 0 | my $conflicts = $parser->Conflicts(); | |||||||||||||||||||||||||||||||||||||||||
| 402 | 0 | my $rules = $parser->ShowRules(); | |||||||||||||||||||||||||||||||||||||||||
| 403 | 0 | my $states = $parser->ShowDfa(); | |||||||||||||||||||||||||||||||||||||||||
| 404 | 0 | my $summary = $parser->Summary(); | |||||||||||||||||||||||||||||||||||||||||
| 405 | |||||||||||||||||||||||||||||||||||||||||||
| 406 | 0 | my $tables =<<"ENDOFLALAR" | |||||||||||||||||||||||||||||||||||||||||
| 407 | Warnings: | ||||||||||||||||||||||||||||||||||||||||||
| 408 | --------- | ||||||||||||||||||||||||||||||||||||||||||
| 409 | $warnings | ||||||||||||||||||||||||||||||||||||||||||
| 410 | Conflicts: | ||||||||||||||||||||||||||||||||||||||||||
| 411 | ---------- | ||||||||||||||||||||||||||||||||||||||||||
| 412 | $conflicts | ||||||||||||||||||||||||||||||||||||||||||
| 413 | Rules: | ||||||||||||||||||||||||||||||||||||||||||
| 414 | ------ | ||||||||||||||||||||||||||||||||||||||||||
| 415 | $rules | ||||||||||||||||||||||||||||||||||||||||||
| 416 | States: | ||||||||||||||||||||||||||||||||||||||||||
| 417 | ------ | ||||||||||||||||||||||||||||||||||||||||||
| 418 | $states | ||||||||||||||||||||||||||||||||||||||||||
| 419 | $states | ||||||||||||||||||||||||||||||||||||||||||
| 420 | Summary: | ||||||||||||||||||||||||||||||||||||||||||
| 421 | -------- | ||||||||||||||||||||||||||||||||||||||||||
| 422 | $summary | ||||||||||||||||||||||||||||||||||||||||||
| 423 | ENDOFLALAR | ||||||||||||||||||||||||||||||||||||||||||
| 424 | } | ||||||||||||||||||||||||||||||||||||||||||
| 425 | |||||||||||||||||||||||||||||||||||||||||||
| 426 | ###################################### | ||||||||||||||||||||||||||||||||||||||||||
| 427 | # Method to get summary about parser # | ||||||||||||||||||||||||||||||||||||||||||
| 428 | ###################################### | ||||||||||||||||||||||||||||||||||||||||||
| 429 | 0 | ▶ | sub Summary { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
Summary: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 430 | 0 | my($self)=shift; | |||||||||||||||||||||||||||||||||||||||||
| 431 | 0 | my($text) = ''; | |||||||||||||||||||||||||||||||||||||||||
| 432 | |||||||||||||||||||||||||||||||||||||||||||
| 433 | 0 | $text=$self->SUPER::Summary(); | |||||||||||||||||||||||||||||||||||||||||
| 434 | $text.="Number of states : ". | ||||||||||||||||||||||||||||||||||||||||||
| 435 | 0 | scalar(@{$$self{STATES}})."\n"; | |||||||||||||||||||||||||||||||||||||||||
| 436 | 0 | $text; | |||||||||||||||||||||||||||||||||||||||||
| 437 | } | ||||||||||||||||||||||||||||||||||||||||||
| 438 | |||||||||||||||||||||||||||||||||||||||||||
| 439 | ####################################### | ||||||||||||||||||||||||||||||||||||||||||
| 440 | # Method To Get Infos about conflicts # | ||||||||||||||||||||||||||||||||||||||||||
| 441 | ####################################### | ||||||||||||||||||||||||||||||||||||||||||
| 442 | 0 | ▶ | sub Conflicts { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
Conflicts: not called CC=10 SCAR=47.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 443 | 0 | my($self)=shift; | |||||||||||||||||||||||||||||||||||||||||
| 444 | 0 | my($states)=$$self{STATES}; | |||||||||||||||||||||||||||||||||||||||||
| 445 | 0 | my($conflicts)=$$self{CONFLICTS}; | |||||||||||||||||||||||||||||||||||||||||
| 446 | 0 | my($text) = ''; | |||||||||||||||||||||||||||||||||||||||||
| 447 | |||||||||||||||||||||||||||||||||||||||||||
| 448 | 0 | for my $stateno ( sort { $a <=> $b } keys(%{$$conflicts{SOLVED}})) { | |||||||||||||||||||||||||||||||||||||||||
| 449 | |||||||||||||||||||||||||||||||||||||||||||
| 450 | 0 | for (@{$$conflicts{SOLVED}{$stateno}}) { | |||||||||||||||||||||||||||||||||||||||||
| 451 | 0 | my($ruleno,$token,$how)=@$_; | |||||||||||||||||||||||||||||||||||||||||
| 452 | |||||||||||||||||||||||||||||||||||||||||||
| 453 | 0 | ▶ | $token eq chr(0) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 454 | and $token = '$end'; | ||||||||||||||||||||||||||||||||||||||||||
| 455 | |||||||||||||||||||||||||||||||||||||||||||
| 456 | 0 | $text.="Conflict in state $stateno between rule ". | |||||||||||||||||||||||||||||||||||||||||
| 457 | "$ruleno and token $token resolved as $how.\n"; | ||||||||||||||||||||||||||||||||||||||||||
| 458 | } | ||||||||||||||||||||||||||||||||||||||||||
| 459 | }; | ||||||||||||||||||||||||||||||||||||||||||
| 460 | |||||||||||||||||||||||||||||||||||||||||||
| 461 | 0 | for my $stateno ( sort { $a <=> $b } keys(%{$$conflicts{FORCED}{DETAIL}})) { | |||||||||||||||||||||||||||||||||||||||||
| 462 | 0 | my($nbsr,$nbrr)=@{$$conflicts{FORCED}{DETAIL}{$stateno}{TOTAL}}; | |||||||||||||||||||||||||||||||||||||||||
| 463 | |||||||||||||||||||||||||||||||||||||||||||
| 464 | 0 | $text.="State $stateno contains "; | |||||||||||||||||||||||||||||||||||||||||
| 465 | |||||||||||||||||||||||||||||||||||||||||||
| 466 | 0 | ▶ | $nbsr | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 467 | and $text.="$nbsr shift/reduce conflict". | ||||||||||||||||||||||||||||||||||||||||||
| 468 | ($nbsr > 1 ? "s" : ""); | ||||||||||||||||||||||||||||||||||||||||||
| 469 | |||||||||||||||||||||||||||||||||||||||||||
| 470 | $nbrr | ||||||||||||||||||||||||||||||||||||||||||
| 471 | 0 | ▶ | and do { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 472 | 0 | ▶ | $nbsr | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 473 | and $text.=" and "; | ||||||||||||||||||||||||||||||||||||||||||
| 474 | |||||||||||||||||||||||||||||||||||||||||||
| 475 | 0 | ▶ | $text.="$nbrr reduce/reduce conflict". | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 476 | ($nbrr > 1 ? "s" : ""); | ||||||||||||||||||||||||||||||||||||||||||
| 477 | }; | ||||||||||||||||||||||||||||||||||||||||||
| 478 | 0 | $text.="\n"; | |||||||||||||||||||||||||||||||||||||||||
| 479 | }; | ||||||||||||||||||||||||||||||||||||||||||
| 480 | |||||||||||||||||||||||||||||||||||||||||||
| 481 | 0 | $text; | |||||||||||||||||||||||||||||||||||||||||
| 482 | } | ||||||||||||||||||||||||||||||||||||||||||
| 483 | |||||||||||||||||||||||||||||||||||||||||||
| 484 | ################################# | ||||||||||||||||||||||||||||||||||||||||||
| 485 | # Method to dump parsing tables # | ||||||||||||||||||||||||||||||||||||||||||
| 486 | ################################# | ||||||||||||||||||||||||||||||||||||||||||
| 487 | 54 | ▶ | sub DfaTable { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
DfaTable: called CC=9 SCAR=22.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 488 | 54 | my($self)=shift; | |||||||||||||||||||||||||||||||||||||||||
| 489 | 54 | my($states)=$$self{STATES}; | |||||||||||||||||||||||||||||||||||||||||
| 490 | 54 | my($stateno); | |||||||||||||||||||||||||||||||||||||||||
| 491 | my($text); | ||||||||||||||||||||||||||||||||||||||||||
| 492 | |||||||||||||||||||||||||||||||||||||||||||
| 493 | 54 | $text="[\n\t{"; | |||||||||||||||||||||||||||||||||||||||||
| 494 | |||||||||||||||||||||||||||||||||||||||||||
| 495 | $text.=join("\n\t},\n\t{", | ||||||||||||||||||||||||||||||||||||||||||
| 496 | map { | ||||||||||||||||||||||||||||||||||||||||||
| 497 | 54 | my($state)=$_; | |||||||||||||||||||||||||||||||||||||||||
| 498 | 1289 | my($text); | |||||||||||||||||||||||||||||||||||||||||
| 499 | |||||||||||||||||||||||||||||||||||||||||||
| 500 | 1289 | $text="#State ".$stateno++."\n\t\t"; | |||||||||||||||||||||||||||||||||||||||||
| 501 | |||||||||||||||||||||||||||||||||||||||||||
| 502 | ( not exists($$state{ACTIONS}{''}) | ||||||||||||||||||||||||||||||||||||||||||
| 503 | 694 | or keys(%{$$state{ACTIONS}}) > 1) | |||||||||||||||||||||||||||||||||||||||||
| 504 | 1289 | ▶ | 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
| |||||||||||||||||||||||||||||||||||||||||||
| 505 | |||||||||||||||||||||||||||||||||||||||||||
| 506 | 877 | $text.="ACTIONS => {\n\t\t\t"; | |||||||||||||||||||||||||||||||||||||||||
| 507 | |||||||||||||||||||||||||||||||||||||||||||
| 508 | $text.=join(",\n\t\t\t", | ||||||||||||||||||||||||||||||||||||||||||
| 509 | map { | ||||||||||||||||||||||||||||||||||||||||||
| 510 | 3101 | my($term,$action)=($_,$$state{ACTIONS}{$_}); | |||||||||||||||||||||||||||||||||||||||||
| 511 | 3101 | my($text); | |||||||||||||||||||||||||||||||||||||||||
| 512 | |||||||||||||||||||||||||||||||||||||||||||
| 513 | 3101 | ▶ | if(substr($term,0,1) eq "'") { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 514 | 2246 | $term=~s/([\@\$\"])/\\$1/g; | |||||||||||||||||||||||||||||||||||||||||
| 515 | 2246 | $term=~s/^'|'$/"/g; | |||||||||||||||||||||||||||||||||||||||||
| 516 | } | ||||||||||||||||||||||||||||||||||||||||||
| 517 | else { | ||||||||||||||||||||||||||||||||||||||||||
| 518 | 855 | ▶ | $term= $term eq chr(0) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 519 | ? "''" | ||||||||||||||||||||||||||||||||||||||||||
| 520 | : "'$term'"; | ||||||||||||||||||||||||||||||||||||||||||
| 521 | } | ||||||||||||||||||||||||||||||||||||||||||
| 522 | |||||||||||||||||||||||||||||||||||||||||||
| 523 | 3101 | ▶ | if(defined($action)) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 524 | 3101 | $action=int($action); | |||||||||||||||||||||||||||||||||||||||||
| 525 | } | ||||||||||||||||||||||||||||||||||||||||||
| 526 | else { | ||||||||||||||||||||||||||||||||||||||||||
| 527 | 0 | $action='undef'; | |||||||||||||||||||||||||||||||||||||||||
| 528 | } | ||||||||||||||||||||||||||||||||||||||||||
| 529 | |||||||||||||||||||||||||||||||||||||||||||
| 530 | 3101 | "$term => $action"; | |||||||||||||||||||||||||||||||||||||||||
| 531 | |||||||||||||||||||||||||||||||||||||||||||
| 532 | 877 | } grep { $_ } keys(%{$$state{ACTIONS}})); | |||||||||||||||||||||||||||||||||||||||||
| 533 | |||||||||||||||||||||||||||||||||||||||||||
| 534 | 877 | $text.="\n\t\t}"; | |||||||||||||||||||||||||||||||||||||||||
| 535 | }; | ||||||||||||||||||||||||||||||||||||||||||
| 536 | |||||||||||||||||||||||||||||||||||||||||||
| 537 | exists($$state{ACTIONS}{''}) | ||||||||||||||||||||||||||||||||||||||||||
| 538 | 1289 | ▶ | and do { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 539 | 694 | ▶ | keys(%{$$state{ACTIONS}}) > 1 | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 540 | and $text.=",\n\t\t"; | ||||||||||||||||||||||||||||||||||||||||||
| 541 | |||||||||||||||||||||||||||||||||||||||||||
| 542 | 694 | $text.="DEFAULT => $$state{ACTIONS}{''}"; | |||||||||||||||||||||||||||||||||||||||||
| 543 | }; | ||||||||||||||||||||||||||||||||||||||||||
| 544 | |||||||||||||||||||||||||||||||||||||||||||
| 545 | exists($$state{GOTOS}) | ||||||||||||||||||||||||||||||||||||||||||
| 546 | 1289 | ▶ | and do { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 547 | 481 | $text.=",\n\t\tGOTOS => {\n\t\t\t"; | |||||||||||||||||||||||||||||||||||||||||
| 548 | $text.=join(",\n\t\t\t", | ||||||||||||||||||||||||||||||||||||||||||
| 549 | map { | ||||||||||||||||||||||||||||||||||||||||||
| 550 | 909 | my($nterm,$stateno)=($_,$$state{GOTOS}{$_}); | |||||||||||||||||||||||||||||||||||||||||
| 551 | 909 | my($text); | |||||||||||||||||||||||||||||||||||||||||
| 552 | |||||||||||||||||||||||||||||||||||||||||||
| 553 | 909 | "'$nterm' => $stateno"; | |||||||||||||||||||||||||||||||||||||||||
| 554 | |||||||||||||||||||||||||||||||||||||||||||
| 555 | 481 | } keys(%{$$state{GOTOS}})); | |||||||||||||||||||||||||||||||||||||||||
| 556 | 481 | $text.="\n\t\t}"; | |||||||||||||||||||||||||||||||||||||||||
| 557 | }; | ||||||||||||||||||||||||||||||||||||||||||
| 558 | |||||||||||||||||||||||||||||||||||||||||||
| 559 | 1289 | $text; | |||||||||||||||||||||||||||||||||||||||||
| 560 | |||||||||||||||||||||||||||||||||||||||||||
| 561 | }@$states); | ||||||||||||||||||||||||||||||||||||||||||
| 562 | |||||||||||||||||||||||||||||||||||||||||||
| 563 | 54 | $text.="\n\t}\n]"; | |||||||||||||||||||||||||||||||||||||||||
| 564 | |||||||||||||||||||||||||||||||||||||||||||
| 565 | 54 | $text; | |||||||||||||||||||||||||||||||||||||||||
| 566 | |||||||||||||||||||||||||||||||||||||||||||
| 567 | } | ||||||||||||||||||||||||||||||||||||||||||
| 568 | |||||||||||||||||||||||||||||||||||||||||||
| 569 | 54 | ▶ | sub _DynamicConflicts { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_DynamicConflicts: called CC=7 SCAR=35.2
| |||||||||||||||||||||||||||||||||||||||||||
| 570 | 54 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 571 | 54 | my $ch = $self->{GRAMMAR}{CONFLICTHANDLERS}; | |||||||||||||||||||||||||||||||||||||||||
| 572 | |||||||||||||||||||||||||||||||||||||||||||
| 573 | 54 | ▶ | return unless %$ch; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 574 | |||||||||||||||||||||||||||||||||||||||||||
| 575 | 0 | my $co = $self->{CONFLICTS}{FORCED}{DETAIL}; | |||||||||||||||||||||||||||||||||||||||||
| 576 | |||||||||||||||||||||||||||||||||||||||||||
| 577 | 0 | my %C; # keys: | |||||||||||||||||||||||||||||||||||||||||
| 578 | # conflictive grammar productions. | ||||||||||||||||||||||||||||||||||||||||||
| 579 | # Values: | ||||||||||||||||||||||||||||||||||||||||||
| 580 | # tokens for which there is a conflict with this production | ||||||||||||||||||||||||||||||||||||||||||
| 581 | 0 | for my $state (keys %$co) { | |||||||||||||||||||||||||||||||||||||||||
| 582 | 0 | my @conList = @{$co->{$state}{LIST}}; | |||||||||||||||||||||||||||||||||||||||||
| 583 | |||||||||||||||||||||||||||||||||||||||||||
| 584 | 0 | for my $c (@conList) { | |||||||||||||||||||||||||||||||||||||||||
| 585 | 0 | my ($token, $production) = @$c; | |||||||||||||||||||||||||||||||||||||||||
| 586 | |||||||||||||||||||||||||||||||||||||||||||
| 587 | # the action chosen is in: $self->{STATES}[$state]{ACTIONS}{$token} | ||||||||||||||||||||||||||||||||||||||||||
| 588 | 0 | push @{$C{($production)}{$state}}, $token; | |||||||||||||||||||||||||||||||||||||||||
| 589 | } | ||||||||||||||||||||||||||||||||||||||||||
| 590 | } | ||||||||||||||||||||||||||||||||||||||||||
| 591 | |||||||||||||||||||||||||||||||||||||||||||
| 592 | 0 | for my $c (keys %$ch) { # for each conflict handler | |||||||||||||||||||||||||||||||||||||||||
| 593 | 0 | my $d = $ch->{$c}{production}; # hash ref of productions managed by this handler | |||||||||||||||||||||||||||||||||||||||||
| 594 | 0 | for my $p (keys %$d) { # for each production | |||||||||||||||||||||||||||||||||||||||||
| 595 | # # if $p reduce or shift? | ||||||||||||||||||||||||||||||||||||||||||
| 596 | # # find the conflictive states where $p appears | ||||||||||||||||||||||||||||||||||||||||||
| 597 | # # if $p is reduce and appears in state $s as -$p it is a state of conflict (the other is in the action table) | ||||||||||||||||||||||||||||||||||||||||||
| 598 | |||||||||||||||||||||||||||||||||||||||||||
| 599 | 0 | ▶ | if ($C{$p}) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 600 | 0 | push @{$ch->{$c}{states}}, $C{$p} | |||||||||||||||||||||||||||||||||||||||||
| 601 | } | ||||||||||||||||||||||||||||||||||||||||||
| 602 | else { | ||||||||||||||||||||||||||||||||||||||||||
| 603 | # check that it is a shift with this production. | ||||||||||||||||||||||||||||||||||||||||||
| 604 | } | ||||||||||||||||||||||||||||||||||||||||||
| 605 | } | ||||||||||||||||||||||||||||||||||||||||||
| 606 | } | ||||||||||||||||||||||||||||||||||||||||||
| 607 | } | ||||||||||||||||||||||||||||||||||||||||||
| 608 | |||||||||||||||||||||||||||||||||||||||||||
| 609 | #################################### | ||||||||||||||||||||||||||||||||||||||||||
| 610 | # Method to build Dfa from Grammar # | ||||||||||||||||||||||||||||||||||||||||||
| 611 | #################################### | ||||||||||||||||||||||||||||||||||||||||||
| 612 | 54 | ▶ | sub _Compile { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_Compile: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 613 | 54 | my($self)=shift; | |||||||||||||||||||||||||||||||||||||||||
| 614 | 54 | my($grammar,$states); | |||||||||||||||||||||||||||||||||||||||||
| 615 | |||||||||||||||||||||||||||||||||||||||||||
| 616 | 54 | $grammar=$self->{GRAMMAR}; | |||||||||||||||||||||||||||||||||||||||||
| 617 | |||||||||||||||||||||||||||||||||||||||||||
| 618 | 54 | $states = _LR0($grammar); | |||||||||||||||||||||||||||||||||||||||||
| 619 | |||||||||||||||||||||||||||||||||||||||||||
| 620 | 54 | $self->{CONFLICTS} = _LALR($grammar,$states); | |||||||||||||||||||||||||||||||||||||||||
| 621 | |||||||||||||||||||||||||||||||||||||||||||
| 622 | 54 | $self->{STATES}=$states; | |||||||||||||||||||||||||||||||||||||||||
| 623 | } | ||||||||||||||||||||||||||||||||||||||||||
| 624 | |||||||||||||||||||||||||||||||||||||||||||
| 625 | ######################### | ||||||||||||||||||||||||||||||||||||||||||
| 626 | # LR0 States Generation # | ||||||||||||||||||||||||||||||||||||||||||
| 627 | ######################### | ||||||||||||||||||||||||||||||||||||||||||
| 628 | # | ||||||||||||||||||||||||||||||||||||||||||
| 629 | ########################### | ||||||||||||||||||||||||||||||||||||||||||
| 630 | # General digraph routine # | ||||||||||||||||||||||||||||||||||||||||||
| 631 | ########################### | ||||||||||||||||||||||||||||||||||||||||||
| 632 | 162 | ▶ | sub _Digraph { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_Digraph: called CC=3 SCAR=11.0
| |||||||||||||||||||||||||||||||||||||||||||
| 633 | 162 | my($rel,$F)=@_; | |||||||||||||||||||||||||||||||||||||||||
| 634 | 162 | my(%N,@S); | |||||||||||||||||||||||||||||||||||||||||
| 635 | 162 | my($infinity)=(~(1<<31)); | |||||||||||||||||||||||||||||||||||||||||
| 636 | 162 | my($Traverse); | |||||||||||||||||||||||||||||||||||||||||
| 637 | |||||||||||||||||||||||||||||||||||||||||||
| 638 | 1747 | ▶ | $Traverse = sub { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=7 SCAR=19.5
| |||||||||||||||||||||||||||||||||||||||||||
| 639 | 1747 | my($x,$d)=@_; | |||||||||||||||||||||||||||||||||||||||||
| 640 | 1747 | my($y); | |||||||||||||||||||||||||||||||||||||||||
| 641 | |||||||||||||||||||||||||||||||||||||||||||
| 642 | 1747 | push(@S,$x); | |||||||||||||||||||||||||||||||||||||||||
| 643 | 1747 | $N{$x}=$d; | |||||||||||||||||||||||||||||||||||||||||
| 644 | |||||||||||||||||||||||||||||||||||||||||||
| 645 | exists($$rel{$x}) | ||||||||||||||||||||||||||||||||||||||||||
| 646 | 1747 | ▶ | and do { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 647 | 1487 | for $y (keys(%{$$rel{$x}})) { | |||||||||||||||||||||||||||||||||||||||||
| 648 | 7959 | ▶ | exists($N{$y}) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 649 | or &$Traverse($y,$d+1); | ||||||||||||||||||||||||||||||||||||||||||
| 650 | |||||||||||||||||||||||||||||||||||||||||||
| 651 | $N{$y} < $N{$x} | ||||||||||||||||||||||||||||||||||||||||||
| 652 | 7959 | ▶ | and $N{$x} = $N{$y}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 653 | |||||||||||||||||||||||||||||||||||||||||||
| 654 | 7959 | $$F{$x}|=$$F{$y}; | |||||||||||||||||||||||||||||||||||||||||
| 655 | } | ||||||||||||||||||||||||||||||||||||||||||
| 656 | }; | ||||||||||||||||||||||||||||||||||||||||||
| 657 | |||||||||||||||||||||||||||||||||||||||||||
| 658 | $N{$x} == $d | ||||||||||||||||||||||||||||||||||||||||||
| 659 | 1747 | ▶ | and do { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 660 | 1538 | for(;;) { | |||||||||||||||||||||||||||||||||||||||||
| 661 | 1747 | $y=pop(@S); | |||||||||||||||||||||||||||||||||||||||||
| 662 | 1747 | $N{$y}=$infinity; | |||||||||||||||||||||||||||||||||||||||||
| 663 | 1747 | ▶ | $y eq $x | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 664 | and last; | ||||||||||||||||||||||||||||||||||||||||||
| 665 | 209 | $$F{$y}=$$F{$x}; | |||||||||||||||||||||||||||||||||||||||||
| 666 | } | ||||||||||||||||||||||||||||||||||||||||||
| 667 | }; | ||||||||||||||||||||||||||||||||||||||||||
| 668 | 162 | }; | |||||||||||||||||||||||||||||||||||||||||
| 669 | |||||||||||||||||||||||||||||||||||||||||||
| 670 | 162 | for (keys(%$rel)) { | |||||||||||||||||||||||||||||||||||||||||
| 671 | 1487 | ▶ | exists($N{$_}) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 672 | or &$Traverse($_,1); | ||||||||||||||||||||||||||||||||||||||||||
| 673 | } | ||||||||||||||||||||||||||||||||||||||||||
| 674 | } | ||||||||||||||||||||||||||||||||||||||||||
| 675 | ####################### | ||||||||||||||||||||||||||||||||||||||||||
| 676 | # Generate LR0 states # | ||||||||||||||||||||||||||||||||||||||||||
| 677 | ####################### | ||||||||||||||||||||||||||||||||||||||||||
| 678 | # Formula used for closures: | ||||||||||||||||||||||||||||||||||||||||||
| 679 | # | ||||||||||||||||||||||||||||||||||||||||||
| 680 | # CLOSE(A) = DCLOSE(A) u U (CLOSE(B) | A close B) | ||||||||||||||||||||||||||||||||||||||||||
| 681 | # | ||||||||||||||||||||||||||||||||||||||||||
| 682 | # where: | ||||||||||||||||||||||||||||||||||||||||||
| 683 | # | ||||||||||||||||||||||||||||||||||||||||||
| 684 | # DCLOSE(A) = { [ A -> alpha ] in P } | ||||||||||||||||||||||||||||||||||||||||||
| 685 | # | ||||||||||||||||||||||||||||||||||||||||||
| 686 | # A close B iff [ A -> B gamma ] in P | ||||||||||||||||||||||||||||||||||||||||||
| 687 | |||||||||||||||||||||||||||||||||||||||||||
| 688 | 54 | ▶ | sub _SetClosures { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_SetClosures: called CC=5 SCAR=16.1
| |||||||||||||||||||||||||||||||||||||||||||
| 689 | 54 | my($grammar)=@_; | |||||||||||||||||||||||||||||||||||||||||
| 690 | 54 | my($rel,$closures); | |||||||||||||||||||||||||||||||||||||||||
| 691 | |||||||||||||||||||||||||||||||||||||||||||
| 692 | 54 | for my $symbol (keys(%{$$grammar{NTERM}})) { | |||||||||||||||||||||||||||||||||||||||||
| 693 | 277 | $closures->{$symbol}=pack('b'.@{$$grammar{RULES}}); | |||||||||||||||||||||||||||||||||||||||||
| 694 | |||||||||||||||||||||||||||||||||||||||||||
| 695 | 277 | for my $ruleno (@{$$grammar{NTERM}{$symbol}}) { | |||||||||||||||||||||||||||||||||||||||||
| 696 | 691 | my($rhs)=$$grammar{RULES}[$ruleno][1]; | |||||||||||||||||||||||||||||||||||||||||
| 697 | |||||||||||||||||||||||||||||||||||||||||||
| 698 | 691 | vec($closures->{$symbol},$ruleno,1)=1; | |||||||||||||||||||||||||||||||||||||||||
| 699 | |||||||||||||||||||||||||||||||||||||||||||
| 700 | @$rhs > 0 | ||||||||||||||||||||||||||||||||||||||||||
| 701 | and exists($$grammar{NTERM}{$$rhs[0]}) | ||||||||||||||||||||||||||||||||||||||||||
| 702 | 691 | ▶ | 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]}
| |||||||||||||||||||||||||||||||||||||||||||
| 703 | } | ||||||||||||||||||||||||||||||||||||||||||
| 704 | } | ||||||||||||||||||||||||||||||||||||||||||
| 705 | 54 | _Digraph($rel,$closures); | |||||||||||||||||||||||||||||||||||||||||
| 706 | |||||||||||||||||||||||||||||||||||||||||||
| 707 | 54 | $closures | |||||||||||||||||||||||||||||||||||||||||
| 708 | } | ||||||||||||||||||||||||||||||||||||||||||
| 709 | |||||||||||||||||||||||||||||||||||||||||||
| 710 | 1289 | ▶ | sub _Closures { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_Closures: called CC=4 SCAR=13.9
| |||||||||||||||||||||||||||||||||||||||||||
| 711 | 1289 | my($grammar,$core,$closures)=@_; | |||||||||||||||||||||||||||||||||||||||||
| 712 | 1289 | my($ruleset)=pack('b'.@{$$grammar{RULES}}); | |||||||||||||||||||||||||||||||||||||||||
| 713 | |||||||||||||||||||||||||||||||||||||||||||
| 714 | 1289 | for (@$core) { | |||||||||||||||||||||||||||||||||||||||||
| 715 | 3265 | my($ruleno,$pos)=@$_; | |||||||||||||||||||||||||||||||||||||||||
| 716 | 3265 | my($rhs)=$$grammar{RULES}[$ruleno][1]; | |||||||||||||||||||||||||||||||||||||||||
| 717 | |||||||||||||||||||||||||||||||||||||||||||
| 718 | $pos < @$rhs | ||||||||||||||||||||||||||||||||||||||||||
| 719 | and exists($closures->{$$rhs[$pos]}) | ||||||||||||||||||||||||||||||||||||||||||
| 720 | 3265 | ▶ | 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]}
| |||||||||||||||||||||||||||||||||||||||||||
| 721 | } | ||||||||||||||||||||||||||||||||||||||||||
| 722 | 5201 | [ @$core, map { [ $_, 0 ] } | |||||||||||||||||||||||||||||||||||||||||
| 723 | 34895 | grep { vec($ruleset,$_,1) } | |||||||||||||||||||||||||||||||||||||||||
| 724 | 1289 | 0..$#{$$grammar{RULES}} ]; | |||||||||||||||||||||||||||||||||||||||||
| 725 | } | ||||||||||||||||||||||||||||||||||||||||||
| 726 | |||||||||||||||||||||||||||||||||||||||||||
| 727 | 1289 | ▶ | sub _Transitions { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_Transitions: called CC=7 SCAR=19.5
| |||||||||||||||||||||||||||||||||||||||||||
| 728 | 1289 | my($grammar,$cores,$closures,$states,$stateno)=@_; | |||||||||||||||||||||||||||||||||||||||||
| 729 | 1289 | my($core)=$$states[$stateno]{'CORE'}; | |||||||||||||||||||||||||||||||||||||||||
| 730 | 1289 | my(%transitions); | |||||||||||||||||||||||||||||||||||||||||
| 731 | |||||||||||||||||||||||||||||||||||||||||||
| 732 | 1289 | for (@{_Closures($grammar,$core,$closures)}) { | |||||||||||||||||||||||||||||||||||||||||
| 733 | 8466 | my($ruleno,$pos)=@$_; | |||||||||||||||||||||||||||||||||||||||||
| 734 | 8466 | my($rhs)=$$grammar{RULES}[$ruleno][1]; | |||||||||||||||||||||||||||||||||||||||||
| 735 | |||||||||||||||||||||||||||||||||||||||||||
| 736 | $pos == @$rhs | ||||||||||||||||||||||||||||||||||||||||||
| 737 | 8466 | ▶ | and do { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 738 | 717 | push(@{$$states[$stateno]{ACTIONS}{''}},$ruleno); | |||||||||||||||||||||||||||||||||||||||||
| 739 | 717 | next; | |||||||||||||||||||||||||||||||||||||||||
| 740 | }; | ||||||||||||||||||||||||||||||||||||||||||
| 741 | 7749 | push(@{$transitions{$$rhs[$pos]}},[ $ruleno, $pos+1 ]); | |||||||||||||||||||||||||||||||||||||||||
| 742 | } | ||||||||||||||||||||||||||||||||||||||||||
| 743 | |||||||||||||||||||||||||||||||||||||||||||
| 744 | 1289 | for (keys(%transitions)) { | |||||||||||||||||||||||||||||||||||||||||
| 745 | 4777 | my($symbol,$core)=($_,$transitions{$_}); | |||||||||||||||||||||||||||||||||||||||||
| 746 | 7749 | my($corekey)=join(',',map { join('.',@$_) } | |||||||||||||||||||||||||||||||||||||||||
| 747 | 4777 | ▶ | sort { $$a[0] <=> $$b[0] | ||||||||||||||||||||||||||||||||||||||||
|
Condition66%2/3
$Parse::Eyapp::Lalr::a->[0] <=> $Parse::Eyapp::Lalr::b->[0] || $Parse::Eyapp::Lalr::a->[1] <=> $Parse::Eyapp::Lalr::b->[1]
MC/DC0%0/2
$Parse::Eyapp::Lalr::a->[0] <=> $Parse::Eyapp::Lalr::b->[0] || $Parse::Eyapp::Lalr::a->[1] <=> $Parse::Eyapp::Lalr::b->[1]
$Parse::Eyapp::Lalr::a->[0] <=> $Parse::Eyapp::Lalr::b->[0]
$Parse::Eyapp::Lalr::a->[1] <=> $Parse::Eyapp::Lalr::b->[1]
Truth table66%2/3
A || B
A= $Parse::Eyapp::Lalr::a->[0] <=> $Parse::Eyapp::Lalr::b->[0]B= $Parse::Eyapp::Lalr::a->[1] <=> $Parse::Eyapp::Lalr::b->[1]
| |||||||||||||||||||||||||||||||||||||||||||
| 748 | or $$a[1] <=> $$b[1] } | ||||||||||||||||||||||||||||||||||||||||||
| 749 | @$core); | ||||||||||||||||||||||||||||||||||||||||||
| 750 | 4777 | my($tostateno); | |||||||||||||||||||||||||||||||||||||||||
| 751 | |||||||||||||||||||||||||||||||||||||||||||
| 752 | exists($cores->{$corekey}) | ||||||||||||||||||||||||||||||||||||||||||
| 753 | 4777 | ▶ | or do { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 754 | 1235 | push(@$states,{ 'CORE' => $core }); | |||||||||||||||||||||||||||||||||||||||||
| 755 | 1235 | $cores->{$corekey}=$#$states; | |||||||||||||||||||||||||||||||||||||||||
| 756 | }; | ||||||||||||||||||||||||||||||||||||||||||
| 757 | |||||||||||||||||||||||||||||||||||||||||||
| 758 | 4777 | $tostateno=$cores->{$corekey}; | |||||||||||||||||||||||||||||||||||||||||
| 759 | 4777 | push(@{$$states[$tostateno]{FROM}},$stateno); | |||||||||||||||||||||||||||||||||||||||||
| 760 | |||||||||||||||||||||||||||||||||||||||||||
| 761 | exists($$grammar{TERM}{$_}) | ||||||||||||||||||||||||||||||||||||||||||
| 762 | 4777 | ▶ | and do { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 763 | 3868 | $$states[$stateno]{ACTIONS}{$_} = [ $tostateno ]; | |||||||||||||||||||||||||||||||||||||||||
| 764 | 3868 | next; | |||||||||||||||||||||||||||||||||||||||||
| 765 | }; | ||||||||||||||||||||||||||||||||||||||||||
| 766 | 909 | $$states[$stateno]{GOTOS}{$_} = $tostateno; | |||||||||||||||||||||||||||||||||||||||||
| 767 | } | ||||||||||||||||||||||||||||||||||||||||||
| 768 | } | ||||||||||||||||||||||||||||||||||||||||||
| 769 | |||||||||||||||||||||||||||||||||||||||||||
| 770 | 54 | ▶ | sub _LR0 { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_LR0: called CC=2 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||
| 771 | 54 | my($grammar)=@_; | |||||||||||||||||||||||||||||||||||||||||
| 772 | 54 | my($states) = []; | |||||||||||||||||||||||||||||||||||||||||
| 773 | 54 | my($stateno); | |||||||||||||||||||||||||||||||||||||||||
| 774 | my($closures); #$closures={ nterm => ruleset,... } | ||||||||||||||||||||||||||||||||||||||||||
| 775 | 54 | my($cores)={}; # { "itemlist" => stateno, ... } | |||||||||||||||||||||||||||||||||||||||||
| 776 | # where "itemlist" has the form: | ||||||||||||||||||||||||||||||||||||||||||
| 777 | # "ruleno.pos,ruleno.pos" ordered by ruleno,pos | ||||||||||||||||||||||||||||||||||||||||||
| 778 | |||||||||||||||||||||||||||||||||||||||||||
| 779 | 54 | $closures = _SetClosures($grammar); | |||||||||||||||||||||||||||||||||||||||||
| 780 | 54 | push(@$states,{ 'CORE' => [ [ 0, 0 ] ] }); | |||||||||||||||||||||||||||||||||||||||||
| 781 | 54 | ▶ | for($stateno=0;$stateno<@$states;++$stateno) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 782 | 1289 | _Transitions($grammar,$cores,$closures,$states,$stateno); | |||||||||||||||||||||||||||||||||||||||||
| 783 | } | ||||||||||||||||||||||||||||||||||||||||||
| 784 | |||||||||||||||||||||||||||||||||||||||||||
| 785 | 54 | $states | |||||||||||||||||||||||||||||||||||||||||
| 786 | } | ||||||||||||||||||||||||||||||||||||||||||
| 787 | |||||||||||||||||||||||||||||||||||||||||||
| 788 | ######################################################### | ||||||||||||||||||||||||||||||||||||||||||
| 789 | # Add Lookahead tokens where needed to make LALR states # | ||||||||||||||||||||||||||||||||||||||||||
| 790 | ######################################################### | ||||||||||||||||||||||||||||||||||||||||||
| 791 | # Compute First sets for non-terminal using the following formula: | ||||||||||||||||||||||||||||||||||||||||||
| 792 | # | ||||||||||||||||||||||||||||||||||||||||||
| 793 | # FIRST(A) = { a in T u { epsilon } | A l a } | ||||||||||||||||||||||||||||||||||||||||||
| 794 | # u | ||||||||||||||||||||||||||||||||||||||||||
| 795 | # U { FIRST(B) | B in V and A l B } | ||||||||||||||||||||||||||||||||||||||||||
| 796 | # | ||||||||||||||||||||||||||||||||||||||||||
| 797 | # where: | ||||||||||||||||||||||||||||||||||||||||||
| 798 | # | ||||||||||||||||||||||||||||||||||||||||||
| 799 | # A l x iff [ A -> X1 X2 .. Xn x alpha ] in P and Xi =>* epsilon, 1 <= i <= n | ||||||||||||||||||||||||||||||||||||||||||
| 800 | |||||||||||||||||||||||||||||||||||||||||||
| 801 | 54 | ▶ | sub _SetFirst { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_SetFirst: called CC=6 SCAR=17.9
| |||||||||||||||||||||||||||||||||||||||||||
| 802 | 54 | my($grammar,$termlst,$terminx)=@_; | |||||||||||||||||||||||||||||||||||||||||
| 803 | 54 | my($rel,$first)=( {}, {} ); | |||||||||||||||||||||||||||||||||||||||||
| 804 | |||||||||||||||||||||||||||||||||||||||||||
| 805 | 54 | for my $symbol (keys(%{$$grammar{NTERM}})) { | |||||||||||||||||||||||||||||||||||||||||
| 806 | 277 | $first->{$symbol}=pack('b'.@$termlst); | |||||||||||||||||||||||||||||||||||||||||
| 807 | |||||||||||||||||||||||||||||||||||||||||||
| 808 | RULE: | ||||||||||||||||||||||||||||||||||||||||||
| 809 | 277 | for my $ruleno (@{$$grammar{NTERM}{$symbol}}) { | |||||||||||||||||||||||||||||||||||||||||
| 810 | 691 | my($rhs)=$$grammar{RULES}[$ruleno][1]; | |||||||||||||||||||||||||||||||||||||||||
| 811 | |||||||||||||||||||||||||||||||||||||||||||
| 812 | 691 | for (@$rhs) { | |||||||||||||||||||||||||||||||||||||||||
| 813 | exists($terminx->{$_}) | ||||||||||||||||||||||||||||||||||||||||||
| 814 | 680 | ▶ | and do { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 815 | 269 | vec($first->{$symbol},$terminx->{$_},1)=1; | |||||||||||||||||||||||||||||||||||||||||
| 816 | 269 | next RULE; | |||||||||||||||||||||||||||||||||||||||||
| 817 | }; | ||||||||||||||||||||||||||||||||||||||||||
| 818 | 411 | ++$rel->{$symbol}{$_}; | |||||||||||||||||||||||||||||||||||||||||
| 819 | 411 | ▶ | exists($$grammar{NULLABLE}{$_}) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 820 | or next RULE; | ||||||||||||||||||||||||||||||||||||||||||
| 821 | } | ||||||||||||||||||||||||||||||||||||||||||
| 822 | 28 | vec($first->{$symbol},0,1)=1; | |||||||||||||||||||||||||||||||||||||||||
| 823 | } | ||||||||||||||||||||||||||||||||||||||||||
| 824 | } | ||||||||||||||||||||||||||||||||||||||||||
| 825 | 54 | _Digraph($rel,$first); | |||||||||||||||||||||||||||||||||||||||||
| 826 | |||||||||||||||||||||||||||||||||||||||||||
| 827 | 54 | $first | |||||||||||||||||||||||||||||||||||||||||
| 828 | } | ||||||||||||||||||||||||||||||||||||||||||
| 829 | |||||||||||||||||||||||||||||||||||||||||||
| 830 | 1073 | ▶ | sub _Preds { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_Preds: called CC=4 SCAR=13.9
| |||||||||||||||||||||||||||||||||||||||||||
| 831 | 1073 | my($states,$stateno,$len)=@_; | |||||||||||||||||||||||||||||||||||||||||
| 832 | 1073 | my($queue, $preds); | |||||||||||||||||||||||||||||||||||||||||
| 833 | |||||||||||||||||||||||||||||||||||||||||||
| 834 | 1073 | ▶ | $len | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 835 | or return [ $stateno ]; | ||||||||||||||||||||||||||||||||||||||||||
| 836 | |||||||||||||||||||||||||||||||||||||||||||
| 837 | 696 | $queue=[ [ $stateno, $len ] ]; | |||||||||||||||||||||||||||||||||||||||||
| 838 | 696 | ▶ | while(@$queue) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 839 | 4898 | my($pred) = shift(@$queue); | |||||||||||||||||||||||||||||||||||||||||
| 840 | 4898 | my($stateno, $len) = @$pred; | |||||||||||||||||||||||||||||||||||||||||
| 841 | |||||||||||||||||||||||||||||||||||||||||||
| 842 | $len == 1 | ||||||||||||||||||||||||||||||||||||||||||
| 843 | 4898 | ▶ | and do { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 844 | 4136 | push(@$preds,@{$states->[$stateno]{FROM}}); | |||||||||||||||||||||||||||||||||||||||||
| 845 | 4136 | next; | |||||||||||||||||||||||||||||||||||||||||
| 846 | }; | ||||||||||||||||||||||||||||||||||||||||||
| 847 | |||||||||||||||||||||||||||||||||||||||||||
| 848 | 4202 | push(@$queue, map { [ $_, $len - 1 ] } | |||||||||||||||||||||||||||||||||||||||||
| 849 | 762 | @{$states->[$stateno]{FROM}}); | |||||||||||||||||||||||||||||||||||||||||
| 850 | } | ||||||||||||||||||||||||||||||||||||||||||
| 851 | |||||||||||||||||||||||||||||||||||||||||||
| 852 | # Pass @$preds through a hash to ensure unicity | ||||||||||||||||||||||||||||||||||||||||||
| 853 | 696 | [ keys( %{ +{ map { ($_,1) } @$preds } } ) ]; | |||||||||||||||||||||||||||||||||||||||||
| 854 | } | ||||||||||||||||||||||||||||||||||||||||||
| 855 | |||||||||||||||||||||||||||||||||||||||||||
| 856 | 825 | ▶ | sub _FirstSfx { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_FirstSfx: called CC=5 SCAR=16.1
| |||||||||||||||||||||||||||||||||||||||||||
| 857 | 825 | my($grammar,$firstset,$termlst,$terminx,$ruleno,$pos,$key)=@_; | |||||||||||||||||||||||||||||||||||||||||
| 858 | 825 | my($first)=pack('b'.@$termlst); | |||||||||||||||||||||||||||||||||||||||||
| 859 | 825 | my($rhs)=$$grammar{RULES}[$ruleno][1]; | |||||||||||||||||||||||||||||||||||||||||
| 860 | |||||||||||||||||||||||||||||||||||||||||||
| 861 | 825 | ▶ | for (;$pos < @$rhs;++$pos) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 862 | exists($terminx->{$$rhs[$pos]}) | ||||||||||||||||||||||||||||||||||||||||||
| 863 | 414 | ▶ | and do { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 864 | 344 | vec($first,$terminx->{$$rhs[$pos]},1)=1; | |||||||||||||||||||||||||||||||||||||||||
| 865 | 344 | return($first); | |||||||||||||||||||||||||||||||||||||||||
| 866 | }; | ||||||||||||||||||||||||||||||||||||||||||
| 867 | 70 | $first|=$firstset->{$$rhs[$pos]}; | |||||||||||||||||||||||||||||||||||||||||
| 868 | |||||||||||||||||||||||||||||||||||||||||||
| 869 | 70 | ▶ | vec($first,0,1) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 870 | and vec($first,0,1)=0; | ||||||||||||||||||||||||||||||||||||||||||
| 871 | |||||||||||||||||||||||||||||||||||||||||||
| 872 | 70 | ▶ | exists($$grammar{NULLABLE}{$$rhs[$pos]}) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 873 | or return($first); | ||||||||||||||||||||||||||||||||||||||||||
| 874 | |||||||||||||||||||||||||||||||||||||||||||
| 875 | } | ||||||||||||||||||||||||||||||||||||||||||
| 876 | 417 | vec($first,0,1)=1; | |||||||||||||||||||||||||||||||||||||||||
| 877 | 417 | $first; | |||||||||||||||||||||||||||||||||||||||||
| 878 | } | ||||||||||||||||||||||||||||||||||||||||||
| 879 | |||||||||||||||||||||||||||||||||||||||||||
| 880 | # Compute Follow sets using following formula: | ||||||||||||||||||||||||||||||||||||||||||
| 881 | # | ||||||||||||||||||||||||||||||||||||||||||
| 882 | # FOLLOW(p,A) = READ(p,A) | ||||||||||||||||||||||||||||||||||||||||||
| 883 | # u | ||||||||||||||||||||||||||||||||||||||||||
| 884 | # U { FOLLOW(q,B) | (p,A) include (q,B) | ||||||||||||||||||||||||||||||||||||||||||
| 885 | # | ||||||||||||||||||||||||||||||||||||||||||
| 886 | # where: | ||||||||||||||||||||||||||||||||||||||||||
| 887 | # | ||||||||||||||||||||||||||||||||||||||||||
| 888 | # READ(p,A) = U { FIRST(beta) | [ A -> alpha A . beta ] in KERNEL(GOTO(p,A)) | ||||||||||||||||||||||||||||||||||||||||||
| 889 | # } - { epsilon } | ||||||||||||||||||||||||||||||||||||||||||
| 890 | # | ||||||||||||||||||||||||||||||||||||||||||
| 891 | # (p,a) include (q,B) iff [ B -> alpha A . beta ] in KERNEL(GOTO(p,A), | ||||||||||||||||||||||||||||||||||||||||||
| 892 | # epsilon in FIRST(beta) and | ||||||||||||||||||||||||||||||||||||||||||
| 893 | # q in PRED(p,alpha) | ||||||||||||||||||||||||||||||||||||||||||
| 894 | |||||||||||||||||||||||||||||||||||||||||||
| 895 | # >> x $firstset | ||||||||||||||||||||||||||||||||||||||||||
| 896 | # 0 HASH(0x1f7af60) | ||||||||||||||||||||||||||||||||||||||||||
| 897 | # '$start' => "\cG" | ||||||||||||||||||||||||||||||||||||||||||
| 898 | # 'a' => "\cB" | ||||||||||||||||||||||||||||||||||||||||||
| 899 | # 'b' => "\cH" | ||||||||||||||||||||||||||||||||||||||||||
| 900 | # 's' => "\cC" | ||||||||||||||||||||||||||||||||||||||||||
| 901 | # >> x $firstset->{'a'} # firstset es una string compactada de 0 y 1 que es trratada como un conjunto | ||||||||||||||||||||||||||||||||||||||||||
| 902 | # 0 "\cB" | ||||||||||||||||||||||||||||||||||||||||||
| 903 | # >> x unpack ("b*", $firstset->{'a'}) | ||||||||||||||||||||||||||||||||||||||||||
| 904 | # 0 01000000 | ||||||||||||||||||||||||||||||||||||||||||
| 905 | # >> x unpack ("b*", $firstset->{'b'}) | ||||||||||||||||||||||||||||||||||||||||||
| 906 | # 0 00010000 | ||||||||||||||||||||||||||||||||||||||||||
| 907 | # >> x unpack ("b*", $firstset->{'s'}) | ||||||||||||||||||||||||||||||||||||||||||
| 908 | # 0 11000000 | ||||||||||||||||||||||||||||||||||||||||||
| 909 | |||||||||||||||||||||||||||||||||||||||||||
| 910 | 54 | ▶ | sub _ComputeFollows { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_ComputeFollows: called CC=13 SCAR=25.6
| |||||||||||||||||||||||||||||||||||||||||||
| 911 | 54 | my($grammar,$states,$termlst)=@_; | |||||||||||||||||||||||||||||||||||||||||
| 912 | 54 | my($firstset,$terminx); | |||||||||||||||||||||||||||||||||||||||||
| 913 | 54 | my($inconsistent, $rel, $follows, $sfx)= ( {}, {}, {}, {} ); | |||||||||||||||||||||||||||||||||||||||||
| 914 | |||||||||||||||||||||||||||||||||||||||||||
| 915 | 54 | %$terminx= map { ($termlst->[$_],$_) } 0..$#$termlst; | |||||||||||||||||||||||||||||||||||||||||
| 916 | |||||||||||||||||||||||||||||||||||||||||||
| 917 | 54 | $firstset=_SetFirst($grammar,$termlst,$terminx); | |||||||||||||||||||||||||||||||||||||||||
| 918 | |||||||||||||||||||||||||||||||||||||||||||
| 919 | 54 | for my $stateno (0..$#$states) { | |||||||||||||||||||||||||||||||||||||||||
| 920 | 1289 | my($state)=$$states[$stateno]; | |||||||||||||||||||||||||||||||||||||||||
| 921 | |||||||||||||||||||||||||||||||||||||||||||
| 922 | exists($$state{ACTIONS}{''}) | ||||||||||||||||||||||||||||||||||||||||||
| 923 | 710 | and ( @{$$state{ACTIONS}{''}} > 1 | |||||||||||||||||||||||||||||||||||||||||
| 924 | 703 | or keys(%{$$state{ACTIONS}}) > 1 ) | |||||||||||||||||||||||||||||||||||||||||
| 925 | 1289 | ▶ | 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
| |||||||||||||||||||||||||||||||||||||||||||
| 926 | 393 | ++$inconsistent->{$stateno}; | |||||||||||||||||||||||||||||||||||||||||
| 927 | |||||||||||||||||||||||||||||||||||||||||||
| 928 | 393 | for my $ruleno (@{$$state{ACTIONS}{''}}) { | |||||||||||||||||||||||||||||||||||||||||
| 929 | 400 | my($lhs,$rhs)=@{$$grammar{RULES}[$ruleno]}[0,1]; | |||||||||||||||||||||||||||||||||||||||||
| 930 | |||||||||||||||||||||||||||||||||||||||||||
| 931 | 400 | for my $predno (@{_Preds($states,$stateno,scalar(@$rhs))}) { | |||||||||||||||||||||||||||||||||||||||||
| 932 | 3693 | ++$rel->{"$stateno.$ruleno"}{"$predno.$lhs"}; | |||||||||||||||||||||||||||||||||||||||||
| 933 | } | ||||||||||||||||||||||||||||||||||||||||||
| 934 | } | ||||||||||||||||||||||||||||||||||||||||||
| 935 | }; | ||||||||||||||||||||||||||||||||||||||||||
| 936 | |||||||||||||||||||||||||||||||||||||||||||
| 937 | exists($$state{GOTOS}) | ||||||||||||||||||||||||||||||||||||||||||
| 938 | 1289 | ▶ | or next; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 939 | |||||||||||||||||||||||||||||||||||||||||||
| 940 | 481 | for my $symbol (keys(%{$$state{GOTOS}})) { | |||||||||||||||||||||||||||||||||||||||||
| 941 | 909 | my($tostate)=$$states[$$state{GOTOS}{$symbol}]; | |||||||||||||||||||||||||||||||||||||||||
| 942 | 909 | my($goto)="$stateno.$symbol"; | |||||||||||||||||||||||||||||||||||||||||
| 943 | |||||||||||||||||||||||||||||||||||||||||||
| 944 | 909 | $follows->{$goto}=pack('b'.@$termlst); | |||||||||||||||||||||||||||||||||||||||||
| 945 | |||||||||||||||||||||||||||||||||||||||||||
| 946 | 909 | for my $item (@{$$tostate{'CORE'}}) { | |||||||||||||||||||||||||||||||||||||||||
| 947 | 3497 | my($ruleno,$pos)=@$item; | |||||||||||||||||||||||||||||||||||||||||
| 948 | 3497 | my($key)="$ruleno.$pos"; | |||||||||||||||||||||||||||||||||||||||||
| 949 | |||||||||||||||||||||||||||||||||||||||||||
| 950 | exists($sfx->{$key}) | ||||||||||||||||||||||||||||||||||||||||||
| 951 | 3497 | ▶ | or $sfx->{$key} = _FirstSfx($grammar,$firstset, | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 952 | $termlst,$terminx, | ||||||||||||||||||||||||||||||||||||||||||
| 953 | $ruleno,$pos,$key); | ||||||||||||||||||||||||||||||||||||||||||
| 954 | |||||||||||||||||||||||||||||||||||||||||||
| 955 | 3497 | $follows->{$goto}|=$sfx->{$key}; | |||||||||||||||||||||||||||||||||||||||||
| 956 | |||||||||||||||||||||||||||||||||||||||||||
| 957 | vec($follows->{$goto},0,1) | ||||||||||||||||||||||||||||||||||||||||||
| 958 | 3497 | ▶ | and do { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 959 | 673 | my($lhs)=$$grammar{RULES}[$ruleno][0]; | |||||||||||||||||||||||||||||||||||||||||
| 960 | |||||||||||||||||||||||||||||||||||||||||||
| 961 | 673 | vec($follows->{$goto},0,1)=0; | |||||||||||||||||||||||||||||||||||||||||
| 962 | |||||||||||||||||||||||||||||||||||||||||||
| 963 | 673 | for my $predno (@{_Preds($states,$stateno,$pos-1)}) { | |||||||||||||||||||||||||||||||||||||||||
| 964 | 3736 | ++$rel->{$goto}{"$predno.$lhs"}; | |||||||||||||||||||||||||||||||||||||||||
| 965 | } | ||||||||||||||||||||||||||||||||||||||||||
| 966 | }; | ||||||||||||||||||||||||||||||||||||||||||
| 967 | } | ||||||||||||||||||||||||||||||||||||||||||
| 968 | } | ||||||||||||||||||||||||||||||||||||||||||
| 969 | } | ||||||||||||||||||||||||||||||||||||||||||
| 970 | 54 | _Digraph($rel,$follows); | |||||||||||||||||||||||||||||||||||||||||
| 971 | |||||||||||||||||||||||||||||||||||||||||||
| 972 | 54 | ($follows,$inconsistent) | |||||||||||||||||||||||||||||||||||||||||
| 973 | } | ||||||||||||||||||||||||||||||||||||||||||
| 974 | |||||||||||||||||||||||||||||||||||||||||||
| 975 | 54 | ▶ | sub _ComputeLA { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_ComputeLA: called CC=6 SCAR=17.9
| |||||||||||||||||||||||||||||||||||||||||||
| 976 | 54 | my($grammar,$states)=@_; | |||||||||||||||||||||||||||||||||||||||||
| 977 | 54 | my($termlst)= [ '',keys(%{$$grammar{TERM}}) ]; | |||||||||||||||||||||||||||||||||||||||||
| 978 | |||||||||||||||||||||||||||||||||||||||||||
| 979 | 54 | my($follows,$inconsistent) = _ComputeFollows($grammar,$states,$termlst); | |||||||||||||||||||||||||||||||||||||||||
| 980 | |||||||||||||||||||||||||||||||||||||||||||
| 981 | 54 | for my $stateno ( keys(%$inconsistent ) ) { | |||||||||||||||||||||||||||||||||||||||||
| 982 | 393 | my($state)=$$states[$stateno]; | |||||||||||||||||||||||||||||||||||||||||
| 983 | 393 | my($conflict); | |||||||||||||||||||||||||||||||||||||||||
| 984 | |||||||||||||||||||||||||||||||||||||||||||
| 985 | #NB the sort is VERY important for conflicts resolution order | ||||||||||||||||||||||||||||||||||||||||||
| 986 | 393 | for my $ruleno (sort { $a <=> $b } | |||||||||||||||||||||||||||||||||||||||||
| 987 | 393 | @{$$state{ACTIONS}{''}}) { | |||||||||||||||||||||||||||||||||||||||||
| 988 | 400 | for my $term ( map { $termlst->[$_] } grep { | |||||||||||||||||||||||||||||||||||||||||
| 989 | 7450 | vec($follows->{"$stateno.$ruleno"},$_,1) } | |||||||||||||||||||||||||||||||||||||||||
| 990 | 0..$#$termlst) { | ||||||||||||||||||||||||||||||||||||||||||
| 991 | 2715 | ▶ | exists($$state{ACTIONS}{$term}) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 992 | and ++$conflict; | ||||||||||||||||||||||||||||||||||||||||||
| 993 | 2715 | push(@{$$state{ACTIONS}{$term}},-$ruleno); | |||||||||||||||||||||||||||||||||||||||||
| 994 | } | ||||||||||||||||||||||||||||||||||||||||||
| 995 | } | ||||||||||||||||||||||||||||||||||||||||||
| 996 | 393 | delete($$state{ACTIONS}{''}); | |||||||||||||||||||||||||||||||||||||||||
| 997 | $conflict | ||||||||||||||||||||||||||||||||||||||||||
| 998 | 393 | ▶ | or delete($inconsistent->{$stateno}); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 999 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1000 | |||||||||||||||||||||||||||||||||||||||||||
| 1001 | $inconsistent | ||||||||||||||||||||||||||||||||||||||||||
| 1002 | 54 | } | |||||||||||||||||||||||||||||||||||||||||
| 1003 | |||||||||||||||||||||||||||||||||||||||||||
| 1004 | ############################# | ||||||||||||||||||||||||||||||||||||||||||
| 1005 | # Solve remaining conflicts # | ||||||||||||||||||||||||||||||||||||||||||
| 1006 | ############################# | ||||||||||||||||||||||||||||||||||||||||||
| 1007 | |||||||||||||||||||||||||||||||||||||||||||
| 1008 | 54 | ▶ | sub _SolveConflicts { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_SolveConflicts: called CC=20 SCAR=30.9
| |||||||||||||||||||||||||||||||||||||||||||
| 1009 | 54 | my($grammar,$states,$inconsistent)=@_; | |||||||||||||||||||||||||||||||||||||||||
| 1010 | 54 | my(%rulesprec,$RulePrec); | |||||||||||||||||||||||||||||||||||||||||
| 1011 | 54 | my($conflicts)={ SOLVED => {}, | |||||||||||||||||||||||||||||||||||||||||
| 1012 | FORCED => { TOTAL => [ 0, 0 ], | ||||||||||||||||||||||||||||||||||||||||||
| 1013 | DETAIL => {} | ||||||||||||||||||||||||||||||||||||||||||
| 1014 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1015 | }; | ||||||||||||||||||||||||||||||||||||||||||
| 1016 | |||||||||||||||||||||||||||||||||||||||||||
| 1017 | 1377 | ▶ | $RulePrec = sub { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=5 SCAR=16.1
| |||||||||||||||||||||||||||||||||||||||||||
| 1018 | 1377 | my($ruleno)=@_; | |||||||||||||||||||||||||||||||||||||||||
| 1019 | 1377 | my($rhs,$rprec)=@{$$grammar{RULES}[$ruleno]}[1,2]; | |||||||||||||||||||||||||||||||||||||||||
| 1020 | 1377 | my($lastterm); | |||||||||||||||||||||||||||||||||||||||||
| 1021 | |||||||||||||||||||||||||||||||||||||||||||
| 1022 | 1377 | ▶ | defined($rprec) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 1023 | and return($rprec); | ||||||||||||||||||||||||||||||||||||||||||
| 1024 | |||||||||||||||||||||||||||||||||||||||||||
| 1025 | exists($rulesprec{$ruleno}) | ||||||||||||||||||||||||||||||||||||||||||
| 1026 | 1244 | ▶ | and return($rulesprec{$ruleno}); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 1027 | |||||||||||||||||||||||||||||||||||||||||||
| 1028 | 210 | $lastterm=(grep { exists($$grammar{TERM}{$_}) } @$rhs)[-1]; | |||||||||||||||||||||||||||||||||||||||||
| 1029 | |||||||||||||||||||||||||||||||||||||||||||
| 1030 | defined($lastterm) | ||||||||||||||||||||||||||||||||||||||||||
| 1031 | and ref($$grammar{TERM}{$lastterm}) | ||||||||||||||||||||||||||||||||||||||||||
| 1032 | 210 | ▶ | 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}
| |||||||||||||||||||||||||||||||||||||||||||
| 1033 | 209 | $rulesprec{$ruleno}=$$grammar{TERM}{$lastterm}[1]; | |||||||||||||||||||||||||||||||||||||||||
| 1034 | 209 | return($rulesprec{$ruleno}); | |||||||||||||||||||||||||||||||||||||||||
| 1035 | }; | ||||||||||||||||||||||||||||||||||||||||||
| 1036 | |||||||||||||||||||||||||||||||||||||||||||
| 1037 | 1 | undef; | |||||||||||||||||||||||||||||||||||||||||
| 1038 | 54 | }; | |||||||||||||||||||||||||||||||||||||||||
| 1039 | |||||||||||||||||||||||||||||||||||||||||||
| 1040 | 54 | for my $stateno (keys(%$inconsistent)) { | |||||||||||||||||||||||||||||||||||||||||
| 1041 | 263 | my($state)=$$states[$stateno]; | |||||||||||||||||||||||||||||||||||||||||
| 1042 | 263 | my($actions)=$$state{ACTIONS}; | |||||||||||||||||||||||||||||||||||||||||
| 1043 | 263 | my($nbsr,$nbrr); | |||||||||||||||||||||||||||||||||||||||||
| 1044 | |||||||||||||||||||||||||||||||||||||||||||
| 1045 | 263 | for my $term ( keys(%$actions) ) { | |||||||||||||||||||||||||||||||||||||||||
| 1046 | 2252 | my($act)=$$actions{$term}; | |||||||||||||||||||||||||||||||||||||||||
| 1047 | |||||||||||||||||||||||||||||||||||||||||||
| 1048 | 2252 | ▶ | @$act > 1 | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 1049 | or next; | ||||||||||||||||||||||||||||||||||||||||||
| 1050 | |||||||||||||||||||||||||||||||||||||||||||
| 1051 | $$act[0] > 0 | ||||||||||||||||||||||||||||||||||||||||||
| 1052 | and ref($$grammar{TERM}{$term}) | ||||||||||||||||||||||||||||||||||||||||||
| 1053 | 1393 | ▶ | and do { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$act->[0] > 0 and ref $grammar->{"TERM"}{$term}
MC/DC50%1/2
$act->[0] > 0 and ref $grammar->{"TERM"}{$term}
$act->[0] > 0
ref $grammar->{"TERM"}{$term}
Truth table66%2/3
A and B
A= $act->[0] > 0B= ref $grammar->{"TERM"}{$term}
| |||||||||||||||||||||||||||||||||||||||||||
| 1054 | 1377 | my($assoc,$tprec)=@{$$grammar{TERM}{$term}}; | |||||||||||||||||||||||||||||||||||||||||
| 1055 | 1377 | my($k,$error); | |||||||||||||||||||||||||||||||||||||||||
| 1056 | |||||||||||||||||||||||||||||||||||||||||||
| 1057 | 1377 | ▶ | for ($k=1;$k<@$act;++$k) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 1058 | 1377 | my($ruleno)=-$$act[$k]; | |||||||||||||||||||||||||||||||||||||||||
| 1059 | 1377 | my($rprec)=&$RulePrec($ruleno); | |||||||||||||||||||||||||||||||||||||||||
| 1060 | |||||||||||||||||||||||||||||||||||||||||||
| 1061 | 1377 | ▶ | defined($rprec) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 1062 | or next; | ||||||||||||||||||||||||||||||||||||||||||
| 1063 | |||||||||||||||||||||||||||||||||||||||||||
| 1064 | ( $tprec > $rprec | ||||||||||||||||||||||||||||||||||||||||||
| 1065 | or ( $tprec == $rprec and $assoc eq 'RIGHT')) | ||||||||||||||||||||||||||||||||||||||||||
| 1066 | 1376 | ▶ | 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"
| |||||||||||||||||||||||||||||||||||||||||||
| 1067 | 602 | push(@{$$conflicts{SOLVED}{$stateno}}, | |||||||||||||||||||||||||||||||||||||||||
| 1068 | [ $ruleno, $term, 'shift' ]); | ||||||||||||||||||||||||||||||||||||||||||
| 1069 | 602 | splice(@$act,$k--,1); | |||||||||||||||||||||||||||||||||||||||||
| 1070 | 602 | next; | |||||||||||||||||||||||||||||||||||||||||
| 1071 | }; | ||||||||||||||||||||||||||||||||||||||||||
| 1072 | ( $tprec < $rprec | ||||||||||||||||||||||||||||||||||||||||||
| 1073 | or $assoc eq 'LEFT') | ||||||||||||||||||||||||||||||||||||||||||
| 1074 | 774 | ▶ | and do { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$tprec < $rprec or $assoc eq "LEFT"
MC/DC0%0/2
$tprec < $rprec or $assoc eq "LEFT"
$tprec < $rprec
$assoc eq "LEFT"
Truth table66%2/3
A or B
A= $tprec < $rprecB= $assoc eq "LEFT"
| |||||||||||||||||||||||||||||||||||||||||||
| 1075 | 774 | push(@{$$conflicts{SOLVED}{$stateno}}, | |||||||||||||||||||||||||||||||||||||||||
| 1076 | [ $ruleno, $term, 'reduce' ]); | ||||||||||||||||||||||||||||||||||||||||||
| 1077 | $$act[0] > 0 | ||||||||||||||||||||||||||||||||||||||||||
| 1078 | 774 | ▶ | and do { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 1079 | 774 | splice(@$act,0,1); | |||||||||||||||||||||||||||||||||||||||||
| 1080 | 774 | --$k; | |||||||||||||||||||||||||||||||||||||||||
| 1081 | }; | ||||||||||||||||||||||||||||||||||||||||||
| 1082 | 774 | next; | |||||||||||||||||||||||||||||||||||||||||
| 1083 | }; | ||||||||||||||||||||||||||||||||||||||||||
| 1084 | 0 | push(@{$$conflicts{SOLVED}{$stateno}}, | |||||||||||||||||||||||||||||||||||||||||
| 1085 | [ $ruleno, $term, 'error' ]); | ||||||||||||||||||||||||||||||||||||||||||
| 1086 | 0 | splice(@$act,$k--,1); | |||||||||||||||||||||||||||||||||||||||||
| 1087 | $$act[0] > 0 | ||||||||||||||||||||||||||||||||||||||||||
| 1088 | 0 | ▶ | and do { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 1089 | 0 | splice(@$act,0,1); | |||||||||||||||||||||||||||||||||||||||||
| 1090 | 0 | ++$error; | |||||||||||||||||||||||||||||||||||||||||
| 1091 | 0 | --$k; | |||||||||||||||||||||||||||||||||||||||||
| 1092 | }; | ||||||||||||||||||||||||||||||||||||||||||
| 1093 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1094 | 1377 | ▶ | $error | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 1095 | and unshift(@$act,undef); | ||||||||||||||||||||||||||||||||||||||||||
| 1096 | }; | ||||||||||||||||||||||||||||||||||||||||||
| 1097 | |||||||||||||||||||||||||||||||||||||||||||
| 1098 | @$act > 1 | ||||||||||||||||||||||||||||||||||||||||||
| 1099 | 1393 | ▶ | and do { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 1100 | 17 | $nbrr += @$act - 2; | |||||||||||||||||||||||||||||||||||||||||
| 1101 | 17 | ▶ | ($$act[0] > 0 ? $nbsr : $nbrr) += 1; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 1102 | 17 | push(@{$$conflicts{FORCED}{DETAIL}{$stateno}{LIST}}, | |||||||||||||||||||||||||||||||||||||||||
| 1103 | 17 | map { [ $term, $_ ] } splice(@$act,1)); | |||||||||||||||||||||||||||||||||||||||||
| 1104 | }; | ||||||||||||||||||||||||||||||||||||||||||
| 1105 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1106 | |||||||||||||||||||||||||||||||||||||||||||
| 1107 | $nbsr | ||||||||||||||||||||||||||||||||||||||||||
| 1108 | 263 | ▶ | and do { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 1109 | 17 | $$conflicts{FORCED}{TOTAL}[0]+=$nbsr; | |||||||||||||||||||||||||||||||||||||||||
| 1110 | 17 | $$conflicts{FORCED}{DETAIL}{$stateno}{TOTAL}[0]+=$nbsr; | |||||||||||||||||||||||||||||||||||||||||
| 1111 | }; | ||||||||||||||||||||||||||||||||||||||||||
| 1112 | |||||||||||||||||||||||||||||||||||||||||||
| 1113 | $nbrr | ||||||||||||||||||||||||||||||||||||||||||
| 1114 | 263 | ▶ | and do { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 1115 | 0 | $$conflicts{FORCED}{TOTAL}[1]+=$nbrr; | |||||||||||||||||||||||||||||||||||||||||
| 1116 | 0 | $$conflicts{FORCED}{DETAIL}{$stateno}{TOTAL}[1]+=$nbrr; | |||||||||||||||||||||||||||||||||||||||||
| 1117 | }; | ||||||||||||||||||||||||||||||||||||||||||
| 1118 | |||||||||||||||||||||||||||||||||||||||||||
| 1119 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1120 | |||||||||||||||||||||||||||||||||||||||||||
| 1121 | $conflicts | ||||||||||||||||||||||||||||||||||||||||||
| 1122 | 54 | } | |||||||||||||||||||||||||||||||||||||||||
| 1123 | |||||||||||||||||||||||||||||||||||||||||||
| 1124 | ############################### | ||||||||||||||||||||||||||||||||||||||||||
| 1125 | # Make default reduce actions # | ||||||||||||||||||||||||||||||||||||||||||
| 1126 | ############################### | ||||||||||||||||||||||||||||||||||||||||||
| 1127 | 54 | ▶ | sub _SetDefaults { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_SetDefaults: called CC=12 SCAR=24.9
| |||||||||||||||||||||||||||||||||||||||||||
| 1128 | 54 | my($states)=@_; | |||||||||||||||||||||||||||||||||||||||||
| 1129 | |||||||||||||||||||||||||||||||||||||||||||
| 1130 | 54 | for my $state (@$states) { | |||||||||||||||||||||||||||||||||||||||||
| 1131 | 1289 | my($actions)=$$state{ACTIONS}; | |||||||||||||||||||||||||||||||||||||||||
| 1132 | |||||||||||||||||||||||||||||||||||||||||||
| 1133 | # %reduces: - rule number => array of tokens to reduce | ||||||||||||||||||||||||||||||||||||||||||
| 1134 | # $nodefault is true if no default can be derived | ||||||||||||||||||||||||||||||||||||||||||
| 1135 | 1289 | my(%reduces,$default,$nodefault); | |||||||||||||||||||||||||||||||||||||||||
| 1136 | |||||||||||||||||||||||||||||||||||||||||||
| 1137 | #If action with ''=> no default | ||||||||||||||||||||||||||||||||||||||||||
| 1138 | exists($$actions{''}) | ||||||||||||||||||||||||||||||||||||||||||
| 1139 | 1289 | ▶ | and do { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 1140 | 317 | $$actions{''}[0] = -$$actions{''}[0]; | |||||||||||||||||||||||||||||||||||||||||
| 1141 | 317 | ++$nodefault; | |||||||||||||||||||||||||||||||||||||||||
| 1142 | }; | ||||||||||||||||||||||||||||||||||||||||||
| 1143 | |||||||||||||||||||||||||||||||||||||||||||
| 1144 | #shift error token => no default | ||||||||||||||||||||||||||||||||||||||||||
| 1145 | exists($$actions{error}) | ||||||||||||||||||||||||||||||||||||||||||
| 1146 | 1289 | ▶ | and $$actions{error}[0] > 0 | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
exists $actions->{"error"} and $actions->{"error"}[0] > 0
MC/DC50%1/2
exists $actions->{"error"} and $actions->{"error"}[0] > 0
exists $actions->{"error"}
$actions->{"error"}[0] > 0
Truth table66%2/3
A and B
A= exists $actions->{"error"}B= $actions->{"error"}[0] > 0
| |||||||||||||||||||||||||||||||||||||||||||
| 1147 | and ++$nodefault; | ||||||||||||||||||||||||||||||||||||||||||
| 1148 | |||||||||||||||||||||||||||||||||||||||||||
| 1149 | 1289 | for my $term (keys(%$actions)) { | |||||||||||||||||||||||||||||||||||||||||
| 1150 | |||||||||||||||||||||||||||||||||||||||||||
| 1151 | 5507 | $$actions{$term}=$$actions{$term}[0]; | |||||||||||||||||||||||||||||||||||||||||
| 1152 | |||||||||||||||||||||||||||||||||||||||||||
| 1153 | 5507 | ▶ | (not defined($$actions{$term}) or $$actions{$term} > 0 or $nodefault) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition83%5/6
not defined $actions->{$term} or $actions->{$term} > 0 or $nodefault
not defined $actions->{$term} or $actions->{$term} > 0
MC/DC66%2/3
not defined $actions->{$term} or $actions->{$term} > 0 or $nodefault
not defined $actions->{$term}
$actions->{$term} > 0
$nodefault
Truth table75%3/4
not(A) or B or C
A= not defined $actions->{$term}B= $actions->{$term} > 0C= $nodefault
| |||||||||||||||||||||||||||||||||||||||||||
| 1154 | and next; | ||||||||||||||||||||||||||||||||||||||||||
| 1155 | |||||||||||||||||||||||||||||||||||||||||||
| 1156 | 2096 | push(@{$reduces{$$actions{$term}}},$term); | |||||||||||||||||||||||||||||||||||||||||
| 1157 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1158 | |||||||||||||||||||||||||||||||||||||||||||
| 1159 | 1289 | ▶ | keys(%reduces) > 0 or next; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 1160 | |||||||||||||||||||||||||||||||||||||||||||
| 1161 | # Find the production rule with the largest reduce set, i.e. | ||||||||||||||||||||||||||||||||||||||||||
| 1162 | # the largest number of tokens | ||||||||||||||||||||||||||||||||||||||||||
| 1163 | |||||||||||||||||||||||||||||||||||||||||||
| 1164 | # OLD CODE: | ||||||||||||||||||||||||||||||||||||||||||
| 1165 | # $default=( | ||||||||||||||||||||||||||||||||||||||||||
| 1166 | # # take the largest ... | ||||||||||||||||||||||||||||||||||||||||||
| 1167 | # map { $$_[0] } | ||||||||||||||||||||||||||||||||||||||||||
| 1168 | # # sort them by cardinal (in reverse) | ||||||||||||||||||||||||||||||||||||||||||
| 1169 | # sort { $$b[1] <=> $$a[1] or $$b[0] <=> $$a[0] } | ||||||||||||||||||||||||||||||||||||||||||
| 1170 | # # list of [ - rule number, number of tokens for that rule ] | ||||||||||||||||||||||||||||||||||||||||||
| 1171 | # map { [ $_, scalar(@{$reduces{$_}}) ] } | ||||||||||||||||||||||||||||||||||||||||||
| 1172 | # keys(%reduces) # list of - rule numbers | ||||||||||||||||||||||||||||||||||||||||||
| 1173 | # )[0]; | ||||||||||||||||||||||||||||||||||||||||||
| 1174 | |||||||||||||||||||||||||||||||||||||||||||
| 1175 | 377 | my $max = 0; | |||||||||||||||||||||||||||||||||||||||||
| 1176 | 377 | for (keys(%reduces)) { | |||||||||||||||||||||||||||||||||||||||||
| 1177 | 384 | my $t = @{$reduces{$_}}; | |||||||||||||||||||||||||||||||||||||||||
| 1178 | 384 | ▶ | ($max, $default) = ($t, $_) if $t > $max; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 1179 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1180 | |||||||||||||||||||||||||||||||||||||||||||
| 1181 | 377 | delete(@$actions{ @{$reduces{$default}} }); | |||||||||||||||||||||||||||||||||||||||||
| 1182 | 377 | $$state{ACTIONS}{''}=$default; | |||||||||||||||||||||||||||||||||||||||||
| 1183 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1184 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1185 | |||||||||||||||||||||||||||||||||||||||||||
| 1186 | 0 | ▶ | sub _dereference { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_dereference: not called CC=4 SCAR=30.0
| |||||||||||||||||||||||||||||||||||||||||||
| 1187 | 0 | my($states)=@_; | |||||||||||||||||||||||||||||||||||||||||
| 1188 | |||||||||||||||||||||||||||||||||||||||||||
| 1189 | 0 | for my $state (@$states) { | |||||||||||||||||||||||||||||||||||||||||
| 1190 | 0 | my($actions)=$$state{ACTIONS}; | |||||||||||||||||||||||||||||||||||||||||
| 1191 | |||||||||||||||||||||||||||||||||||||||||||
| 1192 | exists($$actions{''}) | ||||||||||||||||||||||||||||||||||||||||||
| 1193 | 0 | ▶ | and do { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 1194 | 0 | $$actions{''}[0] = -$$actions{''}[0]; | |||||||||||||||||||||||||||||||||||||||||
| 1195 | }; | ||||||||||||||||||||||||||||||||||||||||||
| 1196 | |||||||||||||||||||||||||||||||||||||||||||
| 1197 | 0 | for my $term (keys(%$actions)) { | |||||||||||||||||||||||||||||||||||||||||
| 1198 | 0 | $$actions{$term}=$$actions{$term}[0]; | |||||||||||||||||||||||||||||||||||||||||
| 1199 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1200 | |||||||||||||||||||||||||||||||||||||||||||
| 1201 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1202 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1203 | |||||||||||||||||||||||||||||||||||||||||||
| 1204 | 54 | ▶ | sub _LALR { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_LALR: called CC=2 SCAR=7.1
| |||||||||||||||||||||||||||||||||||||||||||
| 1205 | 54 | my($grammar,$states) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 1206 | 54 | my($conflicts,$inconsistent); | |||||||||||||||||||||||||||||||||||||||||
| 1207 | |||||||||||||||||||||||||||||||||||||||||||
| 1208 | 54 | $inconsistent = _ComputeLA($grammar,$states); | |||||||||||||||||||||||||||||||||||||||||
| 1209 | |||||||||||||||||||||||||||||||||||||||||||
| 1210 | 54 | $conflicts = _SolveConflicts($grammar,$states,$inconsistent); | |||||||||||||||||||||||||||||||||||||||||
| 1211 | |||||||||||||||||||||||||||||||||||||||||||
| 1212 | 54 | ▶ | if ($grammar->{NOCOMPACT}) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 1213 | 0 | _dereference($states); | |||||||||||||||||||||||||||||||||||||||||
| 1214 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1215 | else { | ||||||||||||||||||||||||||||||||||||||||||
| 1216 | 54 | _SetDefaults($states); | |||||||||||||||||||||||||||||||||||||||||
| 1217 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1218 | |||||||||||||||||||||||||||||||||||||||||||
| 1219 | 54 | $conflicts | |||||||||||||||||||||||||||||||||||||||||
| 1220 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1221 | |||||||||||||||||||||||||||||||||||||||||||
| 1222 | |||||||||||||||||||||||||||||||||||||||||||
| 1223 | 61 | 1; | |||||||||||||||||||||||||||||||||||||||||
| 1224 | |||||||||||||||||||||||||||||||||||||||||||