line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
2
|
|
|
2
|
|
10
|
use strict; |
|
2
|
|
|
|
|
2
|
|
|
2
|
|
|
|
|
71
|
|
2
|
2
|
|
|
2
|
|
7
|
use warnings FATAL => 'all'; |
|
2
|
|
|
|
|
3
|
|
|
2
|
|
|
|
|
74
|
|
3
|
|
|
|
|
|
|
|
4
|
|
|
|
|
|
|
package MarpaX::Languages::C::AST::Grammar::ISO_ANSI_C_2011; |
5
|
2
|
|
|
2
|
|
795
|
use MarpaX::Languages::C::AST::Grammar::ISO_ANSI_C_2011::Actions; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
55
|
|
6
|
2
|
|
|
2
|
|
9
|
use Carp qw/croak/; |
|
2
|
|
|
|
|
3
|
|
|
2
|
|
|
|
|
119
|
|
7
|
2
|
|
|
2
|
|
1066
|
use IO::String; |
|
2
|
|
|
|
|
6871
|
|
|
2
|
|
|
|
|
1454
|
|
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
# ABSTRACT: ISO ANSI C 2011 grammar written in Marpa BNF |
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
our $VERSION = '0.45'; # VERSION |
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
our %DEFAULT_PAUSE = ( |
15
|
|
|
|
|
|
|
TYPEDEF_NAME => 'before', |
16
|
|
|
|
|
|
|
ENUMERATION_CONSTANT => 'before', |
17
|
|
|
|
|
|
|
IDENTIFIER => 'before', |
18
|
|
|
|
|
|
|
SEMICOLON => 'after', |
19
|
|
|
|
|
|
|
LCURLY_SCOPE => 'after', |
20
|
|
|
|
|
|
|
LCURLY_REENTERSCOPE => 'after', |
21
|
|
|
|
|
|
|
RCURLY_SCOPE => 'after', |
22
|
|
|
|
|
|
|
COMMA => 'after', |
23
|
|
|
|
|
|
|
EQUAL => 'after', |
24
|
|
|
|
|
|
|
LPAREN_SCOPE => 'after', |
25
|
|
|
|
|
|
|
RPAREN_SCOPE => 'after', |
26
|
|
|
|
|
|
|
ANY_ASM => 'after', |
27
|
|
|
|
|
|
|
); |
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
our $DEFAULTACTIONOBJECT = sprintf('%s::%s', __PACKAGE__, 'Actions'); |
30
|
|
|
|
|
|
|
our $DEFAULTNONTERMINALSEMANTIC = ':default ::= action => [values] bless => ::lhs'; |
31
|
|
|
|
|
|
|
our $DEFAULTTERMINALSEMANTIC = 'lexeme default = action => [start,length,value,name] forgiving => 1'; |
32
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
our $DATA = do {local $/; }; |
34
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
sub new { |
36
|
1
|
|
|
1
|
1
|
4
|
my ($class, $pausep, $start, $actionObject, $nonTerminalSemantic, $terminalSemantic) = @_; |
37
|
|
|
|
|
|
|
|
38
|
1
|
|
33
|
|
|
6
|
$actionObject //= $DEFAULTACTIONOBJECT; |
39
|
|
|
|
|
|
|
|
40
|
1
|
|
|
|
|
7
|
my $self = { |
41
|
|
|
|
|
|
|
_grammar_option => {}, |
42
|
|
|
|
|
|
|
_recce_option => {semantics_package => $actionObject, ranking_method => 'high_rule_only'}, |
43
|
|
|
|
|
|
|
}; |
44
|
|
|
|
|
|
|
# |
45
|
|
|
|
|
|
|
# Rework the grammar to have the pauses: |
46
|
|
|
|
|
|
|
# Those in %DEFAULT_PAUSE cannot be altered. |
47
|
|
|
|
|
|
|
# The other lexemes given in argument will get a pause => after eventually |
48
|
|
|
|
|
|
|
# |
49
|
1
|
|
|
|
|
3
|
my %pause = (); |
50
|
1
|
50
|
|
|
|
3
|
if (defined($pausep)) { |
51
|
1
|
50
|
|
|
|
4
|
if (ref($pausep) ne 'HASH') { |
52
|
0
|
|
|
|
|
0
|
croak 'pausep must be a reference to HASH'; |
53
|
|
|
|
|
|
|
} |
54
|
1
|
|
|
|
|
1
|
map {$pause{$_} = 'after'} keys %{$pausep}; |
|
0
|
|
|
|
|
0
|
|
|
1
|
|
|
|
|
4
|
|
55
|
|
|
|
|
|
|
} |
56
|
1
|
|
|
|
|
6
|
map {$pause{$_} = $DEFAULT_PAUSE{$_}} keys %DEFAULT_PAUSE; |
|
12
|
|
|
|
|
23
|
|
57
|
|
|
|
|
|
|
|
58
|
1
|
|
|
|
|
3
|
$self->{_content} = ''; |
59
|
1
|
|
|
|
|
1
|
my $allb = exists($pause{__ALL__}); |
60
|
1
|
|
|
|
|
2
|
my $pragmas = ''; |
61
|
1
|
50
|
33
|
|
|
5
|
if (defined($start) && "$start") { |
62
|
|
|
|
|
|
|
# |
63
|
|
|
|
|
|
|
# User gave a custom start, we assume he will hit inaccessible symbols |
64
|
|
|
|
|
|
|
# |
65
|
0
|
|
|
|
|
0
|
$pragmas = "\ninaccessible is ok by default\n"; |
66
|
|
|
|
|
|
|
} else { |
67
|
1
|
|
|
|
|
3
|
$start = 'translationUnit'; |
68
|
|
|
|
|
|
|
} |
69
|
1
|
|
|
|
|
9
|
my $data = IO::String->new($DATA); |
70
|
1
|
|
|
|
|
70
|
while (defined($_ = <$data>)) { |
71
|
1885
|
|
|
|
|
24271
|
my $line = $_; |
72
|
1885
|
100
|
|
|
|
3264
|
if ($line =~ /^\s*:lexeme\s*~\s*<(\w+)>/) { |
73
|
127
|
|
|
|
|
264
|
my $lexeme = substr($line, $-[1], $+[1] - $-[1]); |
74
|
|
|
|
|
|
|
# |
75
|
|
|
|
|
|
|
# Doing this test first will make sure DEFAULT_PAUSE lexemes |
76
|
|
|
|
|
|
|
# will always get the correct 'pause' value (i.e. after or before) |
77
|
|
|
|
|
|
|
# |
78
|
127
|
100
|
|
|
|
339
|
if (exists($pause{$lexeme})) { |
|
|
50
|
|
|
|
|
|
79
|
12
|
50
|
|
|
|
21
|
if (! ($line =~ /\bpause\b/)) { |
80
|
12
|
|
|
|
|
25
|
substr($line, -1, 1) = " pause => $pause{$lexeme}\n"; |
81
|
|
|
|
|
|
|
} |
82
|
|
|
|
|
|
|
} elsif ($allb) { |
83
|
0
|
0
|
|
|
|
0
|
if (! ($line =~ /\bpause\b/)) { |
84
|
|
|
|
|
|
|
# |
85
|
|
|
|
|
|
|
# Hardcoded to 'after' |
86
|
|
|
|
|
|
|
# |
87
|
0
|
|
|
|
|
0
|
substr($line, -1, 1) = " pause => after\n"; |
88
|
|
|
|
|
|
|
} |
89
|
|
|
|
|
|
|
} |
90
|
|
|
|
|
|
|
} |
91
|
1885
|
|
|
|
|
3974
|
$self->{_content} .= $line; |
92
|
|
|
|
|
|
|
} |
93
|
1
|
|
33
|
|
|
21
|
$nonTerminalSemantic //= $DEFAULTNONTERMINALSEMANTIC; |
94
|
1
|
|
33
|
|
|
4
|
$terminalSemantic //= $DEFAULTTERMINALSEMANTIC; |
95
|
|
|
|
|
|
|
|
96
|
1
|
|
|
|
|
67
|
$self->{_content} =~ s/\$PRAGMAS\n/$pragmas/; |
97
|
1
|
|
|
|
|
55
|
$self->{_content} =~ s/\$START\n/$start/; |
98
|
1
|
|
|
|
|
65
|
$self->{_content} =~ s/\$NONTERMINALSEMANTIC\b/$nonTerminalSemantic/; |
99
|
1
|
|
|
|
|
104
|
$self->{_content} =~ s/\$TERMINALSEMANTIC\b/$terminalSemantic/; |
100
|
|
|
|
|
|
|
|
101
|
1
|
|
|
|
|
13
|
bless($self, $class); |
102
|
|
|
|
|
|
|
|
103
|
1
|
|
|
|
|
11
|
return $self; |
104
|
|
|
|
|
|
|
} |
105
|
|
|
|
|
|
|
|
106
|
|
|
|
|
|
|
|
107
|
|
|
|
|
|
|
sub content { |
108
|
1
|
|
|
1
|
1
|
2
|
my ($self) = @_; |
109
|
1
|
|
|
|
|
4
|
return $self->{_content}; |
110
|
|
|
|
|
|
|
} |
111
|
|
|
|
|
|
|
|
112
|
|
|
|
|
|
|
|
113
|
|
|
|
|
|
|
sub grammar_option { |
114
|
1
|
|
|
1
|
1
|
2
|
my ($self) = @_; |
115
|
1
|
|
|
|
|
5
|
return $self->{_grammar_option}; |
116
|
|
|
|
|
|
|
} |
117
|
|
|
|
|
|
|
|
118
|
|
|
|
|
|
|
|
119
|
|
|
|
|
|
|
sub recce_option { |
120
|
1
|
|
|
1
|
1
|
1
|
my ($self) = @_; |
121
|
1
|
|
|
|
|
4
|
return $self->{_recce_option}; |
122
|
|
|
|
|
|
|
} |
123
|
|
|
|
|
|
|
|
124
|
|
|
|
|
|
|
1; |
125
|
|
|
|
|
|
|
|
126
|
|
|
|
|
|
|
=pod |
127
|
|
|
|
|
|
|
|
128
|
|
|
|
|
|
|
=encoding UTF-8 |
129
|
|
|
|
|
|
|
|
130
|
|
|
|
|
|
|
=head1 NAME |
131
|
|
|
|
|
|
|
|
132
|
|
|
|
|
|
|
MarpaX::Languages::C::AST::Grammar::ISO_ANSI_C_2011 - ISO ANSI C 2011 grammar written in Marpa BNF |
133
|
|
|
|
|
|
|
|
134
|
|
|
|
|
|
|
=head1 VERSION |
135
|
|
|
|
|
|
|
|
136
|
|
|
|
|
|
|
version 0.45 |
137
|
|
|
|
|
|
|
|
138
|
|
|
|
|
|
|
=head1 SYNOPSIS |
139
|
|
|
|
|
|
|
|
140
|
|
|
|
|
|
|
use strict; |
141
|
|
|
|
|
|
|
use warnings FATAL => 'all'; |
142
|
|
|
|
|
|
|
use MarpaX::Languages::C::AST::Grammar::ISO_ANSI_C_2011; |
143
|
|
|
|
|
|
|
|
144
|
|
|
|
|
|
|
my $grammar = MarpaX::Languages::C::AST::Grammar::ISO_ANSI_C_2011->new(); |
145
|
|
|
|
|
|
|
|
146
|
|
|
|
|
|
|
my $grammar_content = $grammar->content(); |
147
|
|
|
|
|
|
|
my $grammar_option = $grammar->grammar_option(); |
148
|
|
|
|
|
|
|
my $recce_option = $grammar->recce_option(); |
149
|
|
|
|
|
|
|
|
150
|
|
|
|
|
|
|
=head1 DESCRIPTION |
151
|
|
|
|
|
|
|
|
152
|
|
|
|
|
|
|
This modules contains the ISO ANSI C 2011 C grammar written in Marpa BNF, as of L and L. |
153
|
|
|
|
|
|
|
|
154
|
|
|
|
|
|
|
=head1 SUBROUTINES/METHODS |
155
|
|
|
|
|
|
|
|
156
|
|
|
|
|
|
|
=head2 new([$pausep, $start, $actionObject, $nonTerminalSemantic, $terminalSemantic]) |
157
|
|
|
|
|
|
|
|
158
|
|
|
|
|
|
|
Instance a new object. Takes an eventual reference to a HASH for lexemes for which a pause after is requested, followed by an eventual start rule, an eventual action object, an eventual default non-terminal semantic action, a default terminal semantic action. Default paused lexemes is hardcoded to a list of lexeme that must always be paused, and this list cannot be altered. Default start rule is 'translationUnit'. Default action object is hardcoded to __PACKAGE__::Actions module. Default non-terminal semantic is hardcoded to ':default ::= action => [values] bless => ::lhs'. Default terminal semantic is hardcoded to :'lexeme default = action => [start,length,value] forgiving => 1'. |
159
|
|
|
|
|
|
|
|
160
|
|
|
|
|
|
|
=head2 content() |
161
|
|
|
|
|
|
|
|
162
|
|
|
|
|
|
|
Returns the content of the grammar. Takes no argument. |
163
|
|
|
|
|
|
|
|
164
|
|
|
|
|
|
|
=head2 grammar_option() |
165
|
|
|
|
|
|
|
|
166
|
|
|
|
|
|
|
Returns recommended option for Marpa::R2::Scanless::G->new(), returned as a reference to a hash. |
167
|
|
|
|
|
|
|
|
168
|
|
|
|
|
|
|
=head2 recce_option() |
169
|
|
|
|
|
|
|
|
170
|
|
|
|
|
|
|
Returns recommended option for Marpa::R2::Scanless::R->new(), returned as a reference to a hash. |
171
|
|
|
|
|
|
|
|
172
|
|
|
|
|
|
|
=head1 AUTHOR |
173
|
|
|
|
|
|
|
|
174
|
|
|
|
|
|
|
Jean-Damien Durand |
175
|
|
|
|
|
|
|
|
176
|
|
|
|
|
|
|
=head1 COPYRIGHT AND LICENSE |
177
|
|
|
|
|
|
|
|
178
|
|
|
|
|
|
|
This software is copyright (c) 2013 by Jean-Damien Durand. |
179
|
|
|
|
|
|
|
|
180
|
|
|
|
|
|
|
This is free software; you can redistribute it and/or modify it under |
181
|
|
|
|
|
|
|
the same terms as the Perl 5 programming language system itself. |
182
|
|
|
|
|
|
|
|
183
|
|
|
|
|
|
|
=cut |
184
|
|
|
|
|
|
|
|
185
|
|
|
|
|
|
|
__DATA__ |