📄 asn_grammar.y
字号:
%expect 14%{/* * asn_grammar.y * * ASN grammar file * * ASN.1 compiler to produce C++ classes. * * Copyright (c) 1997-1999 Equivalence Pty. Ltd. * * The contents of this file are subject to the Mozilla Public License * Version 1.0 (the "License"); you may not use this file except in * compliance with the License. You may obtain a copy of the License at * http://www.mozilla.org/MPL/ * * Software distributed under the License is distributed on an "AS IS" * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See * the License for the specific language governing rights and limitations * under the License. * * The Original Code is ASN Parser. * * The Initial Developer of the Original Code is Equivalence Pty. Ltd. * * Portions of this code were written with the assisance of funding from * Vovida Networks, Inc. http://www.vovida.com. * * Portions are Copyright (C) 1993 Free Software Foundation, Inc. * All Rights Reserved. * * Contributor(s): ______________________________________. * * $Log: asn_grammar.y,v $ * Revision 1.13 2004/04/03 08:22:23 csoutheren * Remove pseudo-RTTI and replaced with real RTTI * * Revision 1.12 2001/10/02 00:56:04 robertj * Fixed problem with autonumering enumerated types. * * Revision 1.11 2001/01/16 14:00:17 craigs * Changed MIN and MAX tokens to avoid namespace conflicts under BeOS * * Revision 1.10 2000/05/08 08:55:44 robertj * Fixed production error for ValueSet, thanks Huang-Ming Huang * * Revision 1.9 2000/01/19 12:33:07 robertj * Fixed parsing of OID's in IMPORTS section. * * Revision 1.8 2000/01/19 03:38:12 robertj * Fixed support for parsing multiple IMPORTS * * Revision 1.7 1999/07/22 06:48:54 robertj * Added comparison operation to base ASN classes and compiled ASN code. * Added support for ANY type in ASN parser. * * Revision 1.6 1999/06/09 06:58:08 robertj * Adjusted heading comments. * * Revision 1.5 1999/06/07 01:56:25 robertj * Added header comment on license. * * Revision 1.4 1999/06/06 05:30:28 robertj * Support for parameterised types and type-dentifier types. * Added ability to output multiple .cxx files. * * Revision 1.3 1998/12/14 06:47:55 robertj * New memory check code support. * * Revision 1.2 1998/05/21 04:21:46 robertj * Implementing more of the ASN spec. * * Revision 1.1 1997/12/13 09:17:47 robertj * Initial revision * */#include <ptlib.h>#undef malloc#undef calloc#undef realloc#undef free#include "main.h"extern int yylex();extern int ReferenceTokenContext;extern int IdentifierTokenContext;extern int BraceTokenContext;extern int NullTokenContext;extern int InMacroContext;extern int HasObjectTypeMacro;extern int InMIBContext;extern TypesList * CurrentImportList;static int UnnamedFieldCount = 1;static PStringList * DummyParameters;static PString * ConcatNames(PString * s1, char c, PString * s2){ *s1 += c; *s1 += *s2; delete s2; return s1;}#ifdef _MSC_VER#pragma warning(disable:4701)#endif%}%token IDENTIFIER%token BIT_IDENTIFIER%token OID_IDENTIFIER%token IMPORT_IDENTIFIER%token MODULEREFERENCE%token TYPEREFERENCE%token OBJECTCLASSREFERENCE%token TYPEFIELDREFERENCE%token VALUEFIELDREFERENCE%token VALUESETFIELDREFERENCE%token OBJECTFIELDREFERENCE%token OBJECTSETFIELDREFERENCE%token OBJECTREFERENCE%token OBJECTSETREFERENCE%token INTEGER%token CSTRING%token OS_BSTRING%token BS_BSTRING%token OS_HSTRING%token BS_HSTRING%token STRING_BRACE%token BITSTRING_BRACE%token OID_BRACE%token ABSENT %token ABSTRACT_SYNTAX %token ALL %token ANY%token APPLICATION %token ASSIGNMENT%token AUTOMATIC %token BEGIN_t%token BIT %token BMPString%token BOOLEAN_t%token BY%token CHARACTER %token CHOICE %token CLASS %token COMPONENT %token COMPONENTS %token CONSTRAINED %token DEFAULT %token DEFINED%token DEFINITIONS %token EMBEDDED %token END%token ENUMERATED %token EXCEPT %token EXPLICIT %token EXPORTS %token EXTERNAL %token FALSE_t %token FROM %token GeneralString %token GraphicString %token IA5String %token TYPE_IDENTIFIER %token IDENTIFIER_t%token IMPLICIT %token IMPORTS %token INCLUDES %token INSTANCE %token INTEGER_t %token INTERSECTION %token ISO646String%token MACRO%token MAX_t%token MIN_t%token MINUS_INFINITY%token NOTATION%token NULL_VALUE%token NULL_TYPE%token NumericString %token OBJECT %token OCTET %token OF_t %token OPTIONAL_t%token PDV %token PLUS_INFINITY %token PRESENT %token PrintableString %token PRIVATE %token REAL %token SEQUENCE %token SET %token SIZE_t %token STRING %token SYNTAX %token T61String %token TAGS %token TeletexString %token TRUE_t%token TYPE_t%token UNION %token UNIQUE %token UNIVERSAL %token UniversalString %token VideotexString %token VisibleString %token GeneralizedTime%token UTCTime%token VALUE%token WITH%token string_t%token identifier_t%token number_t%token empty_t%token type_t%token value_t%token OBJECT_TYPE%token TRAP_TYPE%token ACCESS%token STATUS%token read_only_t%token read_write_t%token write_only_t%token not_accessible_t%token mandatory_t%token optional_t%token obsolete_t%token deprecated_t%token DESCRIPTION_t%token REFERENCE_t%token INDEX_t%token DEFVAL_t%token ENTERPRISE%token VARIABLES%token ObjectDescriptor_t%type <ival> INTEGER%type <ival> TagDefault%type <ival> SignedNumber%type <ival> ObjectTypeAccess ObjectTypeStatus%type <ival> Class ClassNumber%type <ival> PresenceConstraint%type <sval> CSTRING%type <sval> BS_BSTRING%type <sval> OS_BSTRING%type <sval> BS_HSTRING%type <sval> OS_HSTRING%type <sval> IDENTIFIER%type <sval> BIT_IDENTIFIER%type <sval> OID_IDENTIFIER%type <sval> IMPORT_IDENTIFIER%type <sval> TYPEREFERENCE%type <sval> MODULEREFERENCE%type <sval> OBJECTCLASSREFERENCE%type <sval> TYPEFIELDREFERENCE%type <sval> VALUEFIELDREFERENCE%type <sval> VALUESETFIELDREFERENCE%type <sval> OBJECTFIELDREFERENCE%type <sval> OBJECTSETFIELDREFERENCE%type <sval> OBJECTREFERENCE%type <sval> OBJECTSETREFERENCE%type <sval> DefinitiveObjIdComponent%type <sval> DefinitiveNameAndNumberForm%type <sval> GlobalModuleReference%type <sval> Reference%type <sval> ExternalTypeReference ExternalValueReference%type <sval> ObjIdComponent%type <sval> NumberForm%type <sval> SimpleDefinedType%type <sval> ComponentIdList%type <sval> CharsDefn%type <sval> SimpleDefinedValue%type <sval> FieldName PrimitiveFieldName%type <sval> DefinedObjectClass%type <sval> ExternalObjectClassReference%type <sval> UsefulObjectClassReference%type <sval> Parameter%type <sval> MibIndexType MibDescrPart MibReferPart%type <slst> DefinitiveIdentifier%type <slst> DefinitiveObjIdComponentList%type <slst> ObjIdComponentList%type <slst> BitIdentifierList%type <slst> CharSyms%type <slst> ParameterList Parameters%type <slst> MibIndexTypes MibIndexPart%type <tval> Type BuiltinType ReferencedType NamedType%type <tval> DefinedType%type <tval> ConstrainedType%type <tval> TypeWithConstraint%type <tval> BitStringType%type <tval> BooleanType%type <tval> CharacterStringType %type <tval> RestrictedCharacterStringType%type <tval> UnrestrictedCharacterStringType%type <tval> ChoiceType AlternativeTypeLists%type <tval> EmbeddedPDVType%type <tval> EnumeratedType Enumerations%type <tval> ExternalType%type <tval> AnyType%type <tval> IntegerType%type <tval> NullType%type <tval> ObjectClassFieldType%type <tval> ObjectIdentifierType%type <tval> OctetStringType %type <tval> RealType%type <tval> SequenceType ComponentType ComponentTypeLists%type <tval> SequenceOfType%type <tval> SetType%type <tval> SetOfType%type <tval> TaggedType%type <tval> ParameterizedType%type <tval> SelectionType%type <tval> UsefulType%type <tval> TypeFromObject%type <tval> ContainedSubtype%type <tval> ActualParameter%type <tval> UserDefinedConstraintParameter%type <tval> Symbol%type <tval> ParameterizedReference%type <tlst> AlternativeTypeList%type <tlst> ComponentTypeList%type <tlst> ActualParameterList ActualParameters%type <tlst> UserDefinedConstraintParameters%type <tlst> SymbolList%type <vval> Value BuiltinValue%type <vval> AssignedIdentifier%type <vval> DefinedValue DefinedValue_Import%type <vval> ObjectIdentifierValue%type <vval> OctetStringValue%type <vval> BitStringValue%type <vval> ExceptionSpec%type <vval> ExceptionIdentification%type <vval> MibDefValPart%type <vval> LowerEndpoint LowerEndValue UpperEndpoint UpperEndValue%type <vval> ReferencedValue%type <vval> BooleanValue%type <vval> CharacterStringValue RestrictedCharacterStringValue%type <vval> CharacterStringList Quadruple Tuple%type <vval> ChoiceValue%type <vval> NullValue%type <vval> RealValue NumericRealValue SpecialRealValue %type <vval> SequenceValue NamedValue/*!!!! %type <vval> SequenceOfValue */%type <vval> ParameterizedValue%type <vlst> ComponentValueList%type <vlst> MibVarPart MibVarTypes%type <nval> NamedBit%type <nval> EnumerationItem%type <nval> NamedNumber%type <nlst> NamedBitList%type <nlst> Enumeration%type <nlst> NamedNumberList%type <elmt> IntersectionElements%type <elmt> Elements%type <elmt> Exclusions%type <elmt> SubtypeElements%type <elmt> ObjectSetElements%type <elmt> ValueRange%type <elmt> PermittedAlphabet%type <elmt> InnerTypeConstraints%type <elmt> MultipleTypeConstraints%type <elmt> SizeConstraint%type <elmt> UserDefinedConstraintParameterList%type <elmt> NamedConstraint%type <elst> ElementSetSpec Unions Intersections TypeConstraints%type <cons> Constraint%type <cons> ConstraintSpec%type <cons> ElementSetSpecs %type <cons> GeneralConstraint%type <cons> UserDefinedConstraint%type <cons> TableConstraint%type <cons> ComponentRelationConstraint%type <cons> ObjectSet%type <tagv> Tag%union { PInt64 ival; PString * sval; PStringList * slst; TypeBase * tval; TypesList * tlst; ValueBase * vval; ValuesList * vlst; NamedNumber * nval; NamedNumberList * nlst; Constraint * cons; ConstraintElementList * elst; ConstraintElementBase * elmt; struct { Tag::Type tagClass; unsigned tagNumber; } tagv;}%%ModuleDefinition : MODULEREFERENCE DefinitiveIdentifier DEFINITIONS TagDefault ASSIGNMENT BEGIN_t { Module = new ModuleDefinition($1, $2, (Tag::Mode)$4); ReferenceTokenContext = TYPEREFERENCE; } ModuleBody END ;DefinitiveIdentifier : '{' DefinitiveObjIdComponentList '}' { $$ = $2; } | /* empty */ { $$ = new PStringList; } ;DefinitiveObjIdComponentList : DefinitiveObjIdComponent { $$ = new PStringList; $$->Append($1); } | DefinitiveObjIdComponent DefinitiveObjIdComponentList { $2->InsertAt(0, $1); $$ = $2; } ;DefinitiveObjIdComponent : IDENTIFIER | INTEGER { $$ = new PString(PString::Unsigned, (int)$1); } | DefinitiveNameAndNumberForm ;DefinitiveNameAndNumberForm : IDENTIFIER '(' INTEGER ')' { delete $1; $$ = new PString(PString::Unsigned, (int)$3); } ;TagDefault : EXPLICIT TAGS { $$ = Tag::Explicit; } | IMPLICIT TAGS { $$ = Tag::Implicit; } | AUTOMATIC TAGS { $$ = Tag::Automatic; } | /* empty */ { $$ = Tag::Explicit; } ;/*************************************/ModuleBody : Exports Imports AssignmentList | /* empty */ ;Exports : EXPORTS SymbolsExported ';' | /* empty */ ;SymbolsExported : SymbolList { Module->SetExports($1); } | /* empty */ { Module->SetExportAll(); } ;Imports : IMPORTS SymbolsImported ';' | /* empty */ ;SymbolsImported : SymbolsFromModuleList | /* empty */ ;SymbolsFromModuleList : SymbolsFromModule | SymbolsFromModuleList SymbolsFromModule ;SymbolsFromModule : SymbolList FROM { CurrentImportList = $1; ReferenceTokenContext = MODULEREFERENCE; } GlobalModuleReference { if (!HasObjectTypeMacro) { HasObjectTypeMacro = $1->GetValuesIndex(SearchType("OBJECT-TYPE")) != P_MAX_INDEX; if (HasObjectTypeMacro) PError << "Info: including OBJECT-TYPE macro" << endl; } Module->AddImport(new ImportModule($4, $1)); ReferenceTokenContext = TYPEREFERENCE; CurrentImportList = NULL; } ;GlobalModuleReference : MODULEREFERENCE { ReferenceTokenContext = TYPEREFERENCE; BraceTokenContext = OID_BRACE; } AssignedIdentifier { BraceTokenContext = '{'; delete $3; } ;AssignedIdentifier : DefinedValue_Import | ObjectIdentifierValue | /* empty */ { $$ = NULL; } ;DefinedValue_Import : ExternalValueReference { $$ = new DefinedValue($1); } | IMPORT_IDENTIFIER { $$ = new DefinedValue($1); } ;SymbolList : Symbol { $$ = new TypesList; $$->Append($1); } | Symbol ',' SymbolList { $3->Append($1); $$ = $3; } ;Symbol : Reference { $$ = new ImportedType($1, FALSE); } | ParameterizedReference /* only required for X.683 */ ;/*************************************/AssignmentList: Assignment | AssignmentList Assignment ;Assignment : TypeAssignment | ValueAssignment | ValueSetTypeAssignment | ObjectClassAssignment | ObjectAssignment | ObjectSetAssignment | ParameterizedAssignment /* We do not have "real" macros, so fake MIB ones */ | MacroDefinition | ObjectTypeDefinition | TrapTypeDefinition ;ValueSetTypeAssignment : TYPEREFERENCE Type { $2->SetName($1); Module->AddType($2); IdentifierTokenContext = $2->GetIdentifierTokenContext(); BraceTokenContext = $2->GetBraceTokenContext(); } ASSIGNMENT ValueSet { IdentifierTokenContext = IDENTIFIER; BraceTokenContext = '{'; } ;/********/TypeAssignment : TYPEREFERENCE ASSIGNMENT Type { $3->SetName($1); Module->AddType($3); } ;Type : ConstrainedType | ReferencedType | BuiltinType ;BuiltinType : BitStringType | BooleanType | CharacterStringType | ChoiceType | EmbeddedPDVType | EnumeratedType | ExternalType | AnyType | InstanceOfType { } | IntegerType | NullType | ObjectClassFieldType | ObjectIdentifierType | OctetStringType | RealType | SequenceType | SequenceOfType | SetType | SetOfType | TaggedType ;ReferencedType : DefinedType | UsefulType | SelectionType | TypeFromObject/*!!! syntactically identical to TypeFromObject | ValueSetFromObjects*/ ;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -