line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
1
|
|
|
1
|
|
365
|
use strict; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
38
|
|
2
|
1
|
|
|
1
|
|
6
|
use warnings FATAL => 'all'; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
38
|
|
3
|
|
|
|
|
|
|
|
4
|
|
|
|
|
|
|
package MarpaX::Languages::C::Scan::Actions; |
5
|
1
|
|
|
1
|
|
168
|
use XML::LibXML; |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
use Carp qw/croak/; |
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
# ABSTRACT: ISO ANSI C grammar actions in Scan mode |
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
our $VERSION = '0.47'; # VERSION |
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
sub new { |
14
|
|
|
|
|
|
|
my $class = shift; |
15
|
|
|
|
|
|
|
my $self = { |
16
|
|
|
|
|
|
|
dom => XML::LibXML::Document->new(), |
17
|
|
|
|
|
|
|
_ruleDescription => [] |
18
|
|
|
|
|
|
|
}; |
19
|
|
|
|
|
|
|
bless($self, $class); |
20
|
|
|
|
|
|
|
return $self |
21
|
|
|
|
|
|
|
} |
22
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
sub nonTerminalSemantic { |
24
|
|
|
|
|
|
|
my $self = shift; |
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
my ($lhs, @rhs) = $self->getRuleDescription(); |
27
|
|
|
|
|
|
|
my $maxRhs = $#rhs; |
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
my $node = XML::LibXML::Element->new($lhs); |
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
foreach (0..$#_) { |
32
|
|
|
|
|
|
|
my $child; |
33
|
|
|
|
|
|
|
if (ref($_[$_]) eq 'ARRAY') { |
34
|
|
|
|
|
|
|
# |
35
|
|
|
|
|
|
|
# This is a lexeme |
36
|
|
|
|
|
|
|
# |
37
|
|
|
|
|
|
|
my $name; |
38
|
|
|
|
|
|
|
if ($_ > $maxRhs) { |
39
|
|
|
|
|
|
|
if ($maxRhs == 0) { |
40
|
|
|
|
|
|
|
# |
41
|
|
|
|
|
|
|
# Ok only if $maxRhs is 0 : this is (probably) a sequence |
42
|
|
|
|
|
|
|
# |
43
|
|
|
|
|
|
|
$name = $rhs[0] |
44
|
|
|
|
|
|
|
} else { |
45
|
|
|
|
|
|
|
croak "Too many arguments on the stack. Rule was: $lhs ::= @rhs\n" |
46
|
|
|
|
|
|
|
} |
47
|
|
|
|
|
|
|
} else { |
48
|
|
|
|
|
|
|
$name = $rhs[$_] |
49
|
|
|
|
|
|
|
} |
50
|
|
|
|
|
|
|
$child = XML::LibXML::Element->new($name); |
51
|
|
|
|
|
|
|
$child->setAttribute('start', $_[$_]->[0]); |
52
|
|
|
|
|
|
|
$child->setAttribute('length', $_[$_]->[1]); |
53
|
|
|
|
|
|
|
$child->setAttribute('text', $_[$_]->[2]) |
54
|
|
|
|
|
|
|
} else { |
55
|
|
|
|
|
|
|
$child = $_[$_] |
56
|
|
|
|
|
|
|
} |
57
|
|
|
|
|
|
|
$node->addChild($child) |
58
|
|
|
|
|
|
|
} |
59
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
if ($lhs eq 'translationUnit') { |
61
|
|
|
|
|
|
|
$self->{dom}->setDocumentElement($node); |
62
|
|
|
|
|
|
|
return $self->{dom} |
63
|
|
|
|
|
|
|
} else { |
64
|
|
|
|
|
|
|
return $node |
65
|
|
|
|
|
|
|
} |
66
|
|
|
|
|
|
|
} |
67
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
sub getRuleDescription { |
69
|
|
|
|
|
|
|
my $rule_id = $Marpa::R2::Context::rule; |
70
|
|
|
|
|
|
|
my $_ruleDescription = $_[0]->{_ruleDescription}; |
71
|
|
|
|
|
|
|
my $rule_desc = $_ruleDescription->[$rule_id]; |
72
|
|
|
|
|
|
|
if (! $rule_desc) { |
73
|
|
|
|
|
|
|
my $slg = $Marpa::R2::Context::slg; |
74
|
|
|
|
|
|
|
$_ruleDescription->[$rule_id] = $rule_desc = [ map { $slg->symbol_display_form($_) } $slg->rule_expand($rule_id) ] |
75
|
|
|
|
|
|
|
} |
76
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
return @{$rule_desc} |
78
|
|
|
|
|
|
|
} |
79
|
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
1; |
81
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
__END__ |