YappParse.yp

filter: Statementstmt 82.6% 190 / 230 Branchbran 65.3% 68 / 104 Conditioncond 100% 3 / 3 MC/DCmcdc 100% 2 / 2 Subroutinesub 73.6% 28 / 38 Podpod 0.0% 0 / 2 totaltotal 76.7% 291 / 379 CC 59 SCAR 25.9
CC
59
Cov
77%
_Lexer
30.6
_SyntaxError
30.0
__ANON__
12.0
CRAP 13.4
« blib/lib/Parse/Yapp/Grammar.pm ↑ Summary blib/lib/Parse/Yapp/Options.pm »
1 %{
2 # Copyright © 1998, 1999, 2000, 2001, Francois Desarmenien.
3 # Copyright © 2017 William N. Braswell, Jr.
4 # All Rights Reserved.
5 # (see COPYRIGHT in Parse::Yapp.pm pod section for use and distribution rights)
6 #
7 # Parse/Yapp/Parser.yp: Parse::Yapp::Parser.pm source file
8 #
9 # Use: yapp -m 'Parse::Yapp::Parse' -o Parse/Yapp/Parse.pm YappParse.yp
10 #
11 # to generate the Parser module.
12 #
13 %}
14  
15 %{
16 require 5.004;
17  
18 3 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
19  
20 my($input,$lexlevel,@lineno,$nberr,$prec,$labelno);
21 my($syms,$head,$tail,$token,$term,$nterm,$rules,$precterm,$start,$nullable);
22 my($expect);
23  
24 %}
25  
26 10 ▶%%
Subroutine new: called CC=2 SCAR=7.3
Pod undocumented
27 10  
28 10 ▶# Main rule
Branch: 1 branch
BranchTrueFalseTotal
ref $class and $class = ref $class 0 10 10
29 yapp: head body tail ;
30  
31 #Common rules:
32  
33 523 ▶symbol: LITERAL {
Subroutine __ANON__: called CC=2 SCAR=6.9
34 exists($$syms{$_[1][0]})
35 523 ▶ or do {
Branch: 1 branch
BranchTrueFalseTotal
exists $$syms{$_[1][0]} or do { $$syms{$_[1][0]} = $_[1][1]; $$term{$_[1][0]} = undef } 457 66 523
36 66 $$syms{$_[1][0]} = $_[1][1];
37 66 $$term{$_[1][0]} = undef;
38 };
39 526 $_[1]
40 }
41 | ident #default action
42 ;
43  
44 1738 ▶ident: IDENT {
Subroutine __ANON__: called CC=2 SCAR=6.9
45 exists($$syms{$_[1][0]})
46 1741 ▶ or do {
Branch: 1 branch
BranchTrueFalseTotal
exists $$syms{$_[1][0]} or do { $$syms{$_[1][0]} = $_[1][1]; $$term{$_[1][0]} = undef } 1448 290 1738
47 293 $$syms{$_[1][0]} = $_[1][1];
48 293 $$term{$_[1][0]} = undef;
49 };
50 1741 $_[1]
51 }
52 ;
53  
54  
55 # Head section:
56 head: headsec '%%'
57 ;
58  
59 headsec: #empty #default action
60 | decls #default action
61 ;
62  
63 decls: decls decl #default action
64 | decl #default action
65 ;
66  
67 decl: '\n' #default action
68 | TOKEN typedecl symlist '\n'
69 27 ▶ {
Subroutine __ANON__: called CC=3 SCAR=11.6
70 27 for (@{$_[3]}) {
71 63 my($symbol,$lineno)=@$_;
72  
73 exists($$token{$symbol})
74 63 ▶ and do {
Branch: 1 branch
BranchTrueFalseTotal
exists $token->{$symbol} and do { _SyntaxError(0, "Token $symbol redefined: " . "Previously defined line $syms->{$symbol}", $lineno); next } 0 63 63
75 0 _SyntaxError(0,
76 "Token $symbol redefined: ".
77 "Previously defined line $$syms{$symbol}",
78 $lineno);
79 0 next;
80 };
81 63 $$token{$symbol}=$lineno;
82 63 $$term{$symbol} = [ ];
83 }
84 undef
85 27 }
86 | ASSOC typedecl symlist '\n'
87 37 ▶ {
Subroutine __ANON__: called CC=3 SCAR=11.4
88 37 for (@{$_[3]}) {
89 74 my($symbol,$lineno)=@$_;
90  
91 defined($$term{$symbol}[0])
92 74 ▶ and do {
Branch: 1 branch
BranchTrueFalseTotal
defined $term->{$symbol}[0] and do { _SyntaxError(1, "Precedence for symbol $symbol redefined: " . "Previously defined line $syms->{$symbol}", $lineno); next } 0 74 74
93 0 _SyntaxError(1,
94 "Precedence for symbol $symbol redefined: ".
95 "Previously defined line $$syms{$symbol}",
96 $lineno);
97 0 next;
98 };
99 74 $$token{$symbol}=$lineno;
100 74 $$term{$symbol} = [ $_[1][0], $prec ];
101 }
102 37 ++$prec;
103 undef
104 37 }
105 1 ▶ | START ident '\n' { $start=$_[2][0]; undef }
Subroutine __ANON__: called CC=1 SCAR=0.0
106 10 ▶ | HEADCODE '\n' { push(@$head,$_[1]); undef }
Subroutine __ANON__: called CC=1 SCAR=0.0
107 0 ▶ | UNION CODE '\n' { undef } #ignore
Subroutine __ANON__: not called CC=1 SCAR=6.9
108 | TYPE typedecl identlist '\n'
109 0 ▶ {
Subroutine __ANON__: not called CC=3 SCAR=24.8
110 0 for ( @{$_[3]} ) {
111 0 my($symbol,$lineno)=@$_;
112  
113 exists($$nterm{$symbol})
114 0 ▶ and do {
Branch: 1 branch
BranchTrueFalseTotal
exists $nterm->{$symbol} and do { _SyntaxError(0, "Non-terminal $symbol redefined: " . "Previously defined line $syms->{$symbol}", $lineno); next } 0 0 0
115 0 _SyntaxError(0,
116 "Non-terminal $symbol redefined: ".
117 "Previously defined line $$syms{$symbol}",
118 $lineno);
119 0 next;
120 };
121 0 delete($$term{$symbol}); #not a terminal
122 0 $$nterm{$symbol}=undef; #is a non-terminal
123 }
124 }
125 0 ▶ | EXPECT NUMBER '\n' { $expect=$_[2][0]; undef }
Subroutine __ANON__: not called CC=1 SCAR=6.9
126 0 ▶ | error '\n' { $_[0]->YYErrok }
Subroutine __ANON__: not called CC=1 SCAR=6.9
127 ;
128  
129 typedecl: #empty
130 | '<' IDENT '>'
131 ;
132  
133 73 ▶symlist: symlist symbol { push(@{$_[1]},$_[2]); $_[1] }
Subroutine __ANON__: called CC=1 SCAR=0.0
134 64 ▶ | symbol { [ $_[1] ] }
Subroutine __ANON__: called CC=1 SCAR=0.0
135 ;
136  
137 0 ▶identlist: identlist ident { push(@{$_[1]},$_[2]); $_[1] }
Subroutine __ANON__: not called CC=1 SCAR=6.9
138 0 ▶ | ident { [ $_[1] ] }
Subroutine __ANON__: not called CC=1 SCAR=6.9
139 ;
140  
141 # Rule section
142 body: rulesec '%%'
143 10 ▶ {
Subroutine __ANON__: called CC=3 SCAR=11.1
144 10 ▶ $start
Branch: 1 branch
BranchTrueFalseTotal
$start or $start = $rules->[1][0] 1 9 10
145 or $start=$$rules[1][0];
146  
147 10 ▶ ref($$nterm{$start})
Branch: 1 branch
BranchTrueFalseTotal
ref $nterm->{$start} or _SyntaxError(2, "Start symbol $start not found " . 'in rules section', $_[2][1]) 10 0 10
148 or _SyntaxError(2,"Start symbol $start not found ".
149 "in rules section",$_[2][1]);
150  
151 10 $$rules[0]=[ '$start', [ $start, chr(0) ], undef, undef ];
152 }
153 0 ▶ | '%%' { _SyntaxError(2,"No rules in input grammar",$_[1][1]); }
Subroutine __ANON__: not called CC=1 SCAR=6.9
154 ;
155  
156 rulesec: rulesec rules #default action
157 | rules #default action
158 ;
159  
160 257 ▶rules: IDENT ':' rhss ';' { _AddRules($_[1],$_[3]); undef }
Subroutine __ANON__: called CC=1 SCAR=0.0
161 0 ▶ | error ';' { $_[0]->YYErrok }
Subroutine __ANON__: not called CC=1 SCAR=6.9
162 ;
163  
164 618 ▶rhss: rhss '|' rule { push(@{$_[1]},$_[3]); $_[1] }
Subroutine __ANON__: called CC=1 SCAR=0.0
165 257 ▶ | rule { [ $_[1] ] }
Subroutine __ANON__: called CC=1 SCAR=0.0
166 ;
167  
168 117 ▶rule: rhs prec epscode { push(@{$_[1]}, $_[2], $_[3]); $_[1] }
Subroutine __ANON__: called CC=1 SCAR=0.0
169 758 ▶ | rhs {
Subroutine __ANON__: called CC=3 SCAR=11.0
170 758 my($code)=undef;
171  
172 defined($_[1])
173 and $_[1][-1][0] eq 'CODE'
174 758 ▶ and $code = ${pop(@{$_[1]})}[1];
Branch: 1 branch
BranchTrueFalseTotal
defined $_[1] and $_[1][-1][0] eq "CODE" and $code = do { pop @{$_[1];} }->[1] 32 726 758
Condition100%3/3
defined $_[1] and $_[1][-1][0] eq "CODE"
!ll&&!rl&&r
3369332
MC/DC100%2/2
defined $_[1] and $_[1][-1][0] eq "CODE"
defined $_[1] $_[1][-1][0] eq "CODE"
Truth table100%3/3
A and B
A= defined $_[1]B= $_[1][-1][0] eq "CODE"
ABresult
0X0
100
111
175  
176 758 push(@{$_[1]}, undef, $code);
177  
178 758 $_[1]
179 }
180 ;
181  
182 rhs: #empty #default action (will return undef)
183 | rhselts #default action
184 ;
185  
186 1207 ▶rhselts: rhselts rhselt { push(@{$_[1]},$_[2]); $_[1] }
Subroutine __ANON__: called CC=1 SCAR=0.0
187 834 ▶ | rhselt { [ $_[1] ] }
Subroutine __ANON__: called CC=1 SCAR=0.0
188 ;
189  
190 2006 ▶rhselt: symbol { [ 'SYMB', $_[1] ] }
Subroutine __ANON__: called CC=1 SCAR=0.0
191 35 ▶ | code { [ 'CODE', $_[1] ] }
Subroutine __ANON__: called CC=1 SCAR=0.0
192 ;
193  
194 prec: PREC symbol
195 117 ▶ {
Subroutine __ANON__: called CC=2 SCAR=8.4
196 defined($$term{$_[2][0]})
197 117 ▶ or do {
Branch: 1 branch
BranchTrueFalseTotal
defined $$term{$_[2][0]} or do { _SyntaxError(1, "No precedence for symbol $_[2][0]", $_[2][1]); return undef } 117 0 117
198 0 _SyntaxError(1,"No precedence for symbol $_[2][0]",
199 $_[2][1]);
200 0 return undef;
201 };
202  
203 117 ++$$precterm{$_[2][0]};
204 117 $$term{$_[2][0]}[1];
205 }
206 ;
207  
208 114 ▶epscode: { undef }
Subroutine __ANON__: called CC=1 SCAR=0.0
209 3 ▶ | code { $_[1] }
Subroutine __ANON__: called CC=1 SCAR=0.0
210 ;
211  
212 38 ▶code: CODE { $_[1] }
Subroutine __ANON__: called CC=1 SCAR=0.0
213 ;
214  
215 # Tail section:
216  
217 tail: /*empty*/
218 10 ▶ | TAILCODE { $tail=$_[1] }
Subroutine __ANON__: called CC=1 SCAR=0.0
219 10 ;
220  
221 %%
222 10 ▶sub _Error {
Subroutine _Error: not called CC=2 SCAR=14.6
223 0 my($value)=$_[0]->YYCurval;
224  
225 0 ▶ my($what)= $token ? "input: '$$value[0]'" : "end of input";
Branch: 1 branch
BranchTrueFalseTotal
$token ? : 0 0 0
226  
227 0 _SyntaxError(1,"Unexpected $what",$$value[1]);
228 }
229  
230 4048 ▶sub _Lexer {
Subroutine _Lexer: called CC=29 SCAR=34.2
231
232 #At EOF
233 4048 ▶ pos($$input) >= length($$input)
Branch: 1 branch
BranchTrueFalseTotal
pos $$input >= length $$input and return "", [undef, -1] 10 4038 4048
234 and return('',[ undef, -1 ]);
235  
236 #In TAIL section
237 $lexlevel > 1
238 4038 ▶ and do {
Branch: 1 branch
BranchTrueFalseTotal
$lexlevel > 1 and do { my($pos) = pos $$input; $lineno[0] = $lineno[1]; $lineno[1] = -1; pos $$input = length $$input; return "TAILCODE", [substr($$input, $pos), $lineno[0]] } 10 4028 4038
239 10 my($pos)=pos($$input);
240  
241 10 $lineno[0]=$lineno[1];
242 10 $lineno[1]=-1;
243 10 pos($$input)=length($$input);
244 10 return('TAILCODE',[ substr($$input,$pos), $lineno[0] ]);
245 };
246  
247 #Skip blanks
248 $lexlevel == 0
249 ? $$input=~m{\G((?:
250 [\t\ ]+ # Any white space char but \n
251 | \#[^\n]* # Perl like comments
252 | /\*.*?\*/ # C like comments
253 )+)}xsgc
254 : $$input=~m{\G((?:
255 \s+ # any white space char
256 | \#[^\n]* # Perl like comments
257 | /\*.*?\*/ # C like comments
258 )+)}xsgc
259 4028 ▶ and do {
Branch: 2 branches
BranchTrueFalseTotal
$lexlevel == 0 ? $$input =~ m[\G((?: [\t\ ]+ # Any white space char but \n | \#[^\n]* # Perl like comments | /\*.*?\*/ # C like comments )+)]cgsx : $$input =~ m[\G((?: \s+ # any white space char | \#[^\n]* # Perl like comments | /\*.*?\*/ # C like comments )+)]cgsx and do { my($blanks) = $1; pos $$input >= length $$input and return "", [undef, -1]; $lineno[1] += $blanks =~ tr/\n// } 3583 445 4028
$lexlevel == 0 ? : 351 3677 4028
260 3583 my($blanks)=$1;
261  
262 #Maybe At EOF
263 3583 ▶ pos($$input) >= length($$input)
Branch: 1 branch
BranchTrueFalseTotal
pos $$input >= length $$input and return "", [undef, -1] 0 3583 3583
264 and return('',[ undef, -1 ]);
265  
266 3583 $lineno[1]+= $blanks=~tr/\n//;
267 };
268  
269 4028 $lineno[0]=$lineno[1];
270  
271 4028 ▶ $$input=~/\G([A-Za-z_][A-Za-z0-9_]*)/gc
Branch: 1 branch
BranchTrueFalseTotal
$$input =~ /\G([A-Za-z_][A-Za-z0-9_]*)/cg and return "IDENT", [$1, $lineno[0]] 1995 2033 4028
272 and return('IDENT',[ $1, $lineno[0] ]);
273  
274 $$input=~/\G('(?:[^'\\]|\\\\|\\'|\\)+?')/gc
275 2033 ▶ and do {
Branch: 1 branch
BranchTrueFalseTotal
$$input =~ /\G('(?:[^'\\]|\\\\|\\'|\\)+?')/cg and do { $1 eq "'error'" and do { _SyntaxError(0, "Literal 'error' will be treated as error token", $lineno[0]); return "IDENT", ["error", $lineno[0]] }; return "LITERAL", [$1, $lineno[0]] } 523 1510 2033
276 $1 eq "'error'"
277 523 ▶ and do {
Branch: 1 branch
BranchTrueFalseTotal
$1 eq "'error'" and do { _SyntaxError(0, "Literal 'error' will be treated as error token", $lineno[0]); return "IDENT", ["error", $lineno[0]] } 0 523 523
278 0 _SyntaxError(0,"Literal 'error' ".
279 "will be treated as error token",$lineno[0]);
280 0 return('IDENT',[ 'error', $lineno[0] ]);
281 };
282 523 return('LITERAL',[ $1, $lineno[0] ]);
283 };
284  
285 $$input=~/\G(%%)/gc
286 1510 ▶ and do {
Branch: 1 branch
BranchTrueFalseTotal
$$input =~ /\G(%%)/cg and do { ++$lexlevel; return $1, [$1, $lineno[0]] } 20 1490 1510
287 20 ++$lexlevel;
288 20 return($1, [ $1, $lineno[0] ]);
289 };
290  
291 $$input=~/\G\{/gc
292 1490 ▶ and do {
Branch: 1 branch
BranchTrueFalseTotal
$$input =~ /\G\{/cg and do { my($level, $from, $code); $from = pos $$input; $level = 1; while ($$input =~ /([{}])/cg) { substr($$input, pos($$input) - 1, 1) eq "\\" and next; $level += $1 eq "{" ? 1 : -1 or last; } ; $level and _SyntaxError(2, "Unmatched { opened line $lineno[0]", -1); $code = substr($$input, $from, pos($$input) - $from - 1); $lineno[1] += $code =~ tr/\n//; return "CODE", [$code, $lineno[0]] } 38 1452 1490
293 38 my($level,$from,$code);
294  
295 38 $from=pos($$input);
296  
297 38 $level=1;
298 38 ▶ while($$input=~/([{}])/gc) {
Branch: 1 branch
BranchTrueFalseTotal
if ($$input =~ /([{}])/cg) 54 0 54
299 54 ▶ substr($$input,pos($$input)-1,1) eq '\\' #Quoted
Branch: 1 branch
BranchTrueFalseTotal
substr($$input, pos($$input) - 1, 1) eq "\\" and next 0 54 54
300 and next;
301 54 ▶ $level += ($1 eq '{' ? 1 : -1)
Branch: 2 branches
BranchTrueFalseTotal
$level += $1 eq "{" ? 1 : -1 or last 16 38 54
$1 eq '{' ? : 8 46 54
302 or last;
303 }
304 $level
305 38 ▶ and _SyntaxError(2,"Unmatched { opened line $lineno[0]",-1);
Branch: 1 branch
BranchTrueFalseTotal
$level and _SyntaxError(2, "Unmatched { opened line $lineno[0]", -1) 0 38 38
306 38 $code = substr($$input,$from,pos($$input)-$from-1);
307 38 $lineno[1]+= $code=~tr/\n//;
308 38 return('CODE',[ $code, $lineno[0] ]);
309 };
310  
311 1452 ▶ if($lexlevel == 0) {# In head section
Branch: 1 branch
BranchTrueFalseTotal
if ($lexlevel == 0) { } 203 1249 1452
312 203 ▶ $$input=~/\G%(left|right|nonassoc)/gc
Branch: 1 branch
BranchTrueFalseTotal
$$input =~ /\G%(left|right|nonassoc)/cg and return "ASSOC", [uc $1, $lineno[0]] 37 166 203
313 and return('ASSOC',[ uc($1), $lineno[0] ]);
314 166 ▶ $$input=~/\G%(start)/gc
Branch: 1 branch
BranchTrueFalseTotal
$$input =~ /\G%(start)/cg and return "START", [undef, $lineno[0]] 1 165 166
315 and return('START',[ undef, $lineno[0] ]);
316 165 ▶ $$input=~/\G%(expect)/gc
Branch: 1 branch
BranchTrueFalseTotal
$$input =~ /\G%(expect)/cg and return "EXPECT", [undef, $lineno[0]] 0 165 165
317 and return('EXPECT',[ undef, $lineno[0] ]);
318 $$input=~/\G%\{/gc
319 165 ▶ and do {
Branch: 1 branch
BranchTrueFalseTotal
$$input =~ /\G%\{/cg and do { my $code; $$input =~ /\G(.*?)%}/cgs or _SyntaxError(2, "Unmatched %{ opened line $lineno[0]", -1); $code = $1; $lineno[1] += $code =~ tr/\n//; return "HEADCODE", [$code, $lineno[0]] } 10 155 165
320 10 my($code);
321  
322 10 ▶ $$input=~/\G(.*?)%}/sgc
Branch: 1 branch
BranchTrueFalseTotal
$$input =~ /\G(.*?)%}/cgs or _SyntaxError(2, "Unmatched %{ opened line $lineno[0]", -1) 10 0 10
323 or _SyntaxError(2,"Unmatched %{ opened line $lineno[0]",-1);
324  
325 10 $code=$1;
326 10 $lineno[1]+= $code=~tr/\n//;
327 10 return('HEADCODE',[ $code, $lineno[0] ]);
328 };
329 155 ▶ $$input=~/\G%(token)/gc
Branch: 1 branch
BranchTrueFalseTotal
$$input =~ /\G%(token)/cg and return "TOKEN", [undef, $lineno[0]] 27 128 155
330 and return('TOKEN',[ undef, $lineno[0] ]);
331 128 ▶ $$input=~/\G%(type)/gc
Branch: 1 branch
BranchTrueFalseTotal
$$input =~ /\G%(type)/cg and return "TYPE", [undef, $lineno[0]] 0 128 128
332 and return('TYPE',[ undef, $lineno[0] ]);
333 128 ▶ $$input=~/\G%(union)/gc
Branch: 1 branch
BranchTrueFalseTotal
$$input =~ /\G%(union)/cg and return "UNION", [undef, $lineno[0]] 0 128 128
334 and return('UNION',[ undef, $lineno[0] ]);
335 128 ▶ $$input=~/\G([0-9]+)/gc
Branch: 1 branch
BranchTrueFalseTotal
$$input =~ /\G([0-9]+)/cg and return "NUMBER", [$1, $lineno[0]] 0 128 128
336 and return('NUMBER',[ $1, $lineno[0] ]);
337  
338 }
339 else {# In rule section
340 1249 ▶ $$input=~/\G%(prec)/gc
Branch: 1 branch
BranchTrueFalseTotal
$$input =~ /\G%(prec)/cg and return "PREC", [undef, $lineno[0]] 117 1132 1249
341 and return('PREC',[ undef, $lineno[0] ]);
342 }
343  
344 #Always return something
345 1260 ▶ $$input=~/\G(.)/sg
Branch: 1 branch
BranchTrueFalseTotal
$$input =~ /\G(.)/gs or die "Parse::Yapp::Grammar::Parse: Match (.) failed: report as a BUG" 1260 0 1260
346 or die "Parse::Yapp::Grammar::Parse: Match (.) failed: report as a BUG";
347  
348 1260 ▶ $1 eq "\n"
Branch: 1 branch
BranchTrueFalseTotal
$1 eq "\n" and ++$lineno[1] 128 1132 1260
349 and ++$lineno[1];
350  
351 1260 ( $1 ,[ $1, $lineno[0] ]);
352  
353 }
354  
355 0 ▶sub _SyntaxError {
Subroutine _SyntaxError: not called CC=5 SCAR=34.0
356 0 my($level,$message,$lineno)=@_;
357  
358 0 ▶ $message= "*".
Branch: 1 branch
BranchTrueFalseTotal
$lineno < 0 ? : 0 0 0
359 [ 'Warning', 'Error', 'Fatal' ]->[$level].
360 "* $message, at ".
361 ($lineno < 0 ? "eof" : "line $lineno").
362 ".\n";
363  
364 0 ▶ $level > 1
Branch: 1 branch
BranchTrueFalseTotal
$level > 1 and die $message 0 0 0
365 and die $message;
366  
367 0 warn $message;
368  
369 0 ▶ $level > 0
Branch: 1 branch
BranchTrueFalseTotal
$level > 0 and ++$nberr 0 0 0
370 and ++$nberr;
371  
372 0 ▶ $nberr == 20
Branch: 1 branch
BranchTrueFalseTotal
$nberr == 20 and die "*Fatal* Too many errors detected.\n" 0 0 0
373 and die "*Fatal* Too many errors detected.\n"
374 }
375  
376 257 ▶sub _AddRules {
Subroutine _AddRules: called CC=10 SCAR=24.1
377 257 my($lhs,$lineno)=@{$_[0]};
378 257 my($rhss)=$_[1];
379  
380 ref($$nterm{$lhs})
381 257 ▶ and do {
Branch: 1 branch
BranchTrueFalseTotal
ref $nterm->{$lhs} and do { _SyntaxError(1, "Non-terminal $lhs redefined: " . "Previously declared line $syms->{$lhs}", $lineno); return } 0 257 257
382 0 _SyntaxError(1,"Non-terminal $lhs redefined: ".
383 "Previously declared line $$syms{$lhs}",$lineno);
384 0 return;
385 };
386  
387 ref($$term{$lhs})
388 257 ▶ and do {
Branch: 1 branch
BranchTrueFalseTotal
ref $term->{$lhs} and do { my($where) = exists $token->{$lhs} ? $token->{$lhs} : $syms->{$lhs}; _SyntaxError(1, "Non-terminal $lhs previously " . "declared as token line $where", $lineno); return } 0 257 257
389 0 ▶ my($where) = exists($$token{$lhs}) ? $$token{$lhs} : $$syms{$lhs};
Branch: 1 branch
BranchTrueFalseTotal
exists $token->{$lhs} ? : 0 0 0
390 0 _SyntaxError(1,"Non-terminal $lhs previously ".
391 "declared as token line $where",$lineno);
392 0 return;
393 };
394  
395 ref($$nterm{$lhs}) #declared through %type
396 257 ▶ or do {
Branch: 1 branch
BranchTrueFalseTotal
ref $nterm->{$lhs} or do { $syms->{$lhs} = $lineno; delete $term->{$lhs} } 0 257 257
397 257 $$syms{$lhs}=$lineno; #Say it's declared here
398 257 delete($$term{$lhs}); #No more a terminal
399 };
400 257 $$nterm{$lhs}=[]; #It's a non-terminal now
401  
402 257 my($epsrules)=0; #To issue a warning if more than one epsilon rule
403  
404 257 for my $rhs (@$rhss) {
405 875 my($tmprule)=[ $lhs, [ ], splice(@$rhs,-2) ]; #Init rule
406  
407 @$rhs
408 875 ▶ or do {
Branch: 1 branch
BranchTrueFalseTotal
@$rhs or do { ++$nullable->{$lhs}; ++$epsrules } 834 41 875
409 41 ++$$nullable{$lhs};
410 41 ++$epsrules;
411 };
412  
413 875 for (0..$#$rhs) {
414 2009 my($what,$value)=@{$$rhs[$_]};
415  
416 $what eq 'CODE'
417 2009 ▶ and do {
Branch: 1 branch
BranchTrueFalseTotal
$what eq "CODE" and do { my($name) = '@' . ++$labelno . "-$_"; push @$rules, [$name, [], undef, $value]; push @{$$tmprule[1];}, $name; next } 3 2006 2009
418 3 my($name)='@'.++$labelno."-$_";
419 3 push(@$rules,[ $name, [], undef, $value ]);
420 3 push(@{$$tmprule[1]},$name);
421 3 next;
422 };
423 2006 push(@{$$tmprule[1]},$$value[0]);
424 }
425 875 push(@$rules,$tmprule);
426 875 push(@{$$nterm{$lhs}},$#$rules);
427 }
428  
429 257 ▶ $epsrules > 1
Branch: 1 branch
BranchTrueFalseTotal
$epsrules > 1 and _SyntaxError(0, "More than one empty rule for symbol $lhs", $lineno) 0 257 257
430 and _SyntaxError(0,"More than one empty rule for symbol $lhs",$lineno);
431 }
432  
433 10 ▶sub Parse {
Subroutine Parse: called CC=3 SCAR=11.0
Pod undocumented
434 10 my($self)=shift;
435  
436 10 ▶ @_ > 0
Branch: 1 branch
BranchTrueFalseTotal
@_ > 0 or croak("No input grammar\n") 10 0 10
437 or croak("No input grammar\n");
438  
439 10 my($parsed)={};
440  
441 10 $input=\$_[0];
442  
443 10 $lexlevel=0;
444 10 @lineno=(1,1);
445 10 $nberr=0;
446 10 $prec=0;
447 10 $labelno=0;
448  
449 10 $head=();
450 10 $tail="";
451  
452 10 $syms={};
453 10 $token={};
454 10 $term={};
455 10 $nterm={};
456 10 $rules=[ undef ]; #reserve slot 0 for start rule
457 10 $precterm={};
458  
459 10 $start="";
460 10 $nullable={};
461 10 $expect=0;
462  
463 10 pos($$input)=0;
464  
465  
466 10 $self->YYParse(yylex => \&_Lexer, yyerror => \&_Error);
467  
468 10 ▶ $nberr
Branch: 1 branch
BranchTrueFalseTotal
$nberr and _SyntaxError(2, "Errors detected: No output", -1) 0 10 10
469 and _SyntaxError(2,"Errors detected: No output",-1);
470  
471 10 @$parsed{ 'HEAD', 'TAIL', 'RULES', 'NTERM', 'TERM',
472 'NULL', 'PREC', 'SYMS', 'START', 'EXPECT' }
473 = ( $head, $tail, $rules, $nterm, $term,
474 $nullable, $precterm, $syms, $start, $expect);
475  
476 10 undef($input);
477 10 undef($lexlevel);
478 10 undef(@lineno);
479 10 undef($nberr);
480 10 undef($prec);
481 10 undef($labelno);
482  
483 10 undef($head);
484 10 undef($tail);
485  
486 10 undef($syms);
487 10 undef($token);
488 10 undef($term);
489 10 undef($nterm);
490 10 undef($rules);
491 10 undef($precterm);
492  
493 10 undef($start);
494 10 undef($nullable);
495 10 undef($expect);
496  
497 10 $parsed
498 }
499  
« blib/lib/Parse/Yapp/Grammar.pm ↑ Summary blib/lib/Parse/Yapp/Options.pm »