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