1
########################
2
# ASN.1 Parse::Yapp parser
3
# Copyright (C) Stefan (metze) Metzmacher <metze@samba.org>
4
# released under the GNU GPL version 3 or later
8
# the precedence actually doesn't matter at all for this grammer, but
9
# by providing a precedence we reduce the number of conflicts
11
%left '-' '+' '&' '|' '*' '>' '.' '/' '(' ')' '[' ']' ':' ',' ';'
19
identifier asn1_definitions asn1_delimitter asn1_begin asn1_decls asn1_end
21
"OBJECT" => "ASN1_DEFINITION",
22
"IDENTIFIER" => $_[1],
47
{ push(@{$_[1]}, $_[2]); $_[1] }
53
asn1_target asn1_delimitter asn1_application asn1_type
55
"OBJECT" => "ASN1_DEF",
56
"IDENTIFIER" => $_[1],
57
"APPLICATION" => $_[3],
68
| '[' 'APPLICATION' constant ']'
78
| asn1_object_identifier
99
| 'INTEGER' '(' constant '.' '.' constant ')'
103
"RANGE_LOW" => $_[3],
104
"RENAGE_HIGH" => $_[6]
111
"TYPE" => "BIT STRING",
119
"TYPE" => "OCTET STRING",
132
asn1_object_identifier:
133
'OBJECT' 'IDENTIFIER'
135
"TYPE" => "OBJECT IDENTIFIER",
151
"TYPE" => "ENUMERATED",
157
'SEQUENCE' '{' asn1_var_dec_list '}'
159
"TYPE" => "SEQUENCE",
168
| asn1_var_dec_list ',' asn1_var_dec
169
{ push(@{$_[1]}, $_[3]); $_[1] }
180
anytext: #empty { "" }
181
| identifier | constant | text
182
| anytext '-' anytext { "$_[1]$_[2]$_[3]" }
183
| anytext '.' anytext { "$_[1]$_[2]$_[3]" }
184
| anytext '*' anytext { "$_[1]$_[2]$_[3]" }
185
| anytext '>' anytext { "$_[1]$_[2]$_[3]" }
186
| anytext '|' anytext { "$_[1]$_[2]$_[3]" }
187
| anytext '&' anytext { "$_[1]$_[2]$_[3]" }
188
| anytext '/' anytext { "$_[1]$_[2]$_[3]" }
189
| anytext '+' anytext { "$_[1]$_[2]$_[3]" }
190
| anytext '(' anytext ')' anytext { "$_[1]$_[2]$_[3]$_[4]$_[5]" }
193
delimitter: DELIMITTER
196
identifier: IDENTIFIER
202
text: TEXT { "\"$_[1]\"" }
205
#####################################
212
if (exists $_[0]->YYData->{ERRMSG}) {
213
print $_[0]->YYData->{ERRMSG};
214
delete $_[0]->YYData->{ERRMSG};
217
my $line = $_[0]->YYData->{LINE};
218
my $last_token = $_[0]->YYData->{LAST_TOKEN};
219
my $file = $_[0]->YYData->{INPUT_FILENAME};
221
print "$file:$line: Syntax error near '$last_token'\n";
228
$parser->YYData->{INPUT}
232
$parser->YYData->{INPUT} =~ s/^[ \t]*//;
234
for ($parser->YYData->{INPUT}) {
236
if (s/^\# (\d+) \"(.*?)\"( \d+|)//) {
237
$parser->YYData->{LINE} = $1-1;
238
$parser->YYData->{INPUT_FILENAME} = $2;
241
if (s/^\#line (\d+) \"(.*?)\"( \d+|)//) {
242
$parser->YYData->{LINE} = $1-1;
243
$parser->YYData->{INPUT_FILENAME} = $2;
251
$parser->YYData->{LINE}++;
255
$parser->YYData->{LINE}++;
259
$parser->YYData->{LAST_TOKEN} = $1;
260
return('DELIMITTER',$1);
262
if (s/^\"(.*?)\"//) {
263
$parser->YYData->{LAST_TOKEN} = $1;
266
if (s/^(\d+)(\W|$)/$2/) {
267
$parser->YYData->{LAST_TOKEN} = $1;
268
return('CONSTANT',$1);
270
if (s/^([\w_-]+)//) {
271
$parser->YYData->{LAST_TOKEN} = $1;
273
/^(SEQUENCE|INTEGER|OCTET|STRING|
274
APPLICATION|OPTIONAL|NULL|COMPONENTS|OF|
275
BOOLEAN|ENUMERATED|CHOISE|REAL|BIT|OBJECT|IDENTIFIER|
276
DEFAULT|FALSE|TRUE|SET|DEFINITIONS|BEGIN|END)$/x) {
279
return('IDENTIFIER',$1);
282
$parser->YYData->{LAST_TOKEN} = $1;
291
my $filename = shift;
293
my $saved_delim = $/;
296
if (! defined $cpp) {
299
my $data = `$cpp -xc $filename`;
302
$self->YYData->{INPUT} = $data;
303
$self->YYData->{LINE} = 0;
304
$self->YYData->{LAST_TOKEN} = "NONE";
305
return $self->YYParse( yylex => \&_ASN1_Lexer, yyerror => \&_ASN1_Error );