📄 asn_grammar.y
字号:
ExternalType : EXTERNAL { $$ = new ExternalType; } ;AnyType : ANY { $$ = new AnyType(NULL); } | ANY DEFINED BY IDENTIFIER { $$ = new AnyType($4); } ;InstanceOfType : INSTANCE OF_t DefinedObjectClass ;IntegerType : INTEGER_t { $$ = new IntegerType; } | INTEGER_t '{' NamedNumberList '}' { $$ = new IntegerType($3); } ;NullType : NULL_TYPE { $$ = new NullType; } ;ObjectClassFieldType : DefinedObjectClass '.' FieldName { $$ = new ObjectClassFieldType($1, $3); } ;ObjectIdentifierType : OBJECT IDENTIFIER_t { $$ = new ObjectIdentifierType; } ;OctetStringType : OCTET STRING { $$ = new OctetStringType; } ;RealType : REAL { $$ = new RealType; } ;SequenceType : SEQUENCE '{' ComponentTypeLists '}' { $$ = $3; } | SEQUENCE '{' '}' { $$ = new SequenceType(NULL, FALSE, NULL); } | SEQUENCE '{' ExtensionAndException '}' { $$ = new SequenceType(NULL, TRUE, NULL); } ;ComponentTypeLists : ComponentTypeList { $$ = new SequenceType($1, FALSE, NULL); } | ComponentTypeList ',' ExtensionAndException { $$ = new SequenceType($1, TRUE, NULL); } | ComponentTypeList ',' ExtensionAndException ',' ComponentTypeList { $$ = new SequenceType($1, TRUE, $5); } | ExtensionAndException ',' ComponentTypeList { $$ = new SequenceType(NULL, TRUE, $3); } ;ComponentTypeList : ComponentType { $$ = new TypesList; $$->Append($1); } | ComponentTypeList ',' ComponentType { $1->Append($3); } ;ComponentType : NamedType | NamedType OPTIONAL_t { $1->SetOptional(); } | NamedType DEFAULT { IdentifierTokenContext = $1->GetIdentifierTokenContext(); } Value { IdentifierTokenContext = IDENTIFIER; $1->SetDefaultValue($4); } | COMPONENTS OF_t Type { $$ = $3; } ;SequenceOfType : SEQUENCE OF_t Type { $$ = new SequenceOfType($3, NULL); } ;SetType : SET '{' ComponentTypeLists '}' { $$ = new SetType((SequenceType*)$3); } | SET '{' '}' { $$ = new SetType; } ;SetOfType : SET OF_t Type { $$ = new SetOfType($3, NULL); } ;TaggedType : Tag Type { $2->SetTag($1.tagClass, $1.tagNumber, Module->GetDefaultTagMode()); $$ = $2; } | Tag IMPLICIT Type { $3->SetTag($1.tagClass, $1.tagNumber, Tag::Implicit); $$ = $3; } | Tag EXPLICIT Type { $3->SetTag($1.tagClass, $1.tagNumber, Tag::Explicit); $$ = $3; } ;Tag : '[' Class ClassNumber ']' { $$.tagClass = (Tag::Type)$2; $$.tagNumber = (int)$3; } ;ClassNumber : INTEGER | DefinedValue { if ($1->IsDescendant(IntegerValue::Class())) $$ = *(IntegerValue*)$1; else PError << StdError(Fatal) << "incorrect value type." << endl; } ;Class : UNIVERSAL { $$ = Tag::Universal; } | APPLICATION { $$ = Tag::Application; } | PRIVATE { $$ = Tag::Private; } | /* empty */ { $$ = Tag::ContextSpecific; } ;SelectionType : IDENTIFIER '<' Type { $$ = new SelectionType($1, $3); } ;UsefulType : GeneralizedTime { $$ = new GeneralizedTimeType; } | UTCTime { $$ = new UTCTimeType; } | ObjectDescriptor_t { $$ = new ObjectDescriptorType; } ;TypeFromObject : ReferencedObjects '.' FieldName { } ;/*!!!ValueSetFromObjects : ReferencedObjects '.' FieldName ;*/ReferencedObjects : DefinedObject | ParameterizedObject | DefinedObjectSet { } | ParameterizedObjectSet { } ;ParameterizedObject : DefinedObject ActualParameterList ;/********/ConstrainedType : Type Constraint { $1->AddConstraint($2); } | TypeWithConstraint ;TypeWithConstraint : SET Constraint OF_t Type { $$ = new SetOfType($4, $2); } | SET SizeConstraint OF_t Type { $$ = new SetOfType($4, new Constraint($2)); } | SEQUENCE Constraint OF_t Type { $$ = new SequenceOfType($4, $2); } | SEQUENCE SizeConstraint OF_t Type { $$ = new SequenceOfType($4, new Constraint($2)); } ;Constraint : '(' ConstraintSpec ExceptionSpec ')' { $$ = $2; } ;ConstraintSpec : ElementSetSpecs | GeneralConstraint ;ExceptionSpec : '!' ExceptionIdentification { $$ = $2; } | /* empty */ { $$ = NULL; } ;ExceptionIdentification : SignedNumber { $$ = new IntegerValue($1); } | DefinedValue | Type ':' Value { delete $1; PError << StdError(Warning) << "Typed exception unsupported" << endl; $$ = $3; } ;ElementSetSpecs : ElementSetSpec { $$ = new Constraint($1, FALSE, NULL); } | ElementSetSpec ',' '.' '.' '.' { $$ = new Constraint($1, TRUE, NULL); } | '.' '.' '.' ',' ElementSetSpec { $$ = new Constraint(NULL, TRUE, $5); } | ElementSetSpec ',' '.' '.' '.' ElementSetSpec { $$ = new Constraint($1, TRUE, $6); } ;ElementSetSpec : Unions | ALL Exclusions { $$ = new ConstraintElementList; $$->Append(new ConstrainAllConstraintElement($2)); } ;Unions : Intersections { $$ = new ConstraintElementList; $$->Append(new ElementListConstraintElement($1)); } | Unions UnionMark Intersections { $1->Append(new ElementListConstraintElement($3)); } ;Intersections : IntersectionElements { $$ = new ConstraintElementList; $$->Append($1); } | Intersections IntersectionMark IntersectionElements { $1->Append($3); } ;IntersectionElements : Elements | Elements Exclusions { $1->SetExclusions($2); } ;Exclusions : EXCEPT Elements { $$ = $2; } ;UnionMark : '|' | UNION ;IntersectionMark : '^' | INTERSECTION ;Elements : SubtypeElements | ObjectSetElements | '(' ElementSetSpec ')' { $$ = new ElementListConstraintElement($2); } ;SubtypeElements : Value { $$ = new SingleValueConstraintElement($1); } | ContainedSubtype { $$ = new SubTypeConstraintElement($1); } | ValueRange | PermittedAlphabet | SizeConstraint/*| TypeConstraint This is really Type and causes ambiguity with ContainedSubtype */ | InnerTypeConstraints ;ValueRange : LowerEndpoint '.' '.' UpperEndpoint { $$ = new ValueRangeConstraintElement($1, $4); } ;LowerEndpoint : LowerEndValue | LowerEndValue '<' ;UpperEndpoint : UpperEndValue | '<' UpperEndValue { $$ = $2; } ;LowerEndValue : Value | MIN { $$ = new MinValue; } ;UpperEndValue : Value | MAX { $$ = new MaxValue; } ;PermittedAlphabet : FROM Constraint { $$ = new FromConstraintElement($2); } ;ContainedSubtype : INCLUDES Type { $$ = $2; }/*| Type Actual grammar has INCLUDES keyword optional but this is horribly ambiguous, so only support a few specific Type definitions */ | ConstrainedType | BuiltinType | DefinedType | UsefulType ;SizeConstraint : SIZE_t Constraint { $$ = new SizeConstraintElement($2); } ;InnerTypeConstraints : WITH COMPONENT Constraint { $$ = new WithComponentConstraintElement(NULL, $3, WithComponentConstraintElement::Default); } | WITH COMPONENTS MultipleTypeConstraints { $$ = $3; } ;MultipleTypeConstraints : '{' TypeConstraints '}' /* FullSpecification */ { $$ = new InnerTypeConstraintElement($2, FALSE); } | '{' '.' '.' '.' ',' TypeConstraints '}' /* PartialSpecification */ { $$ = new InnerTypeConstraintElement($6, TRUE); } ;TypeConstraints : NamedConstraint { $$ = new ConstraintElementList; $$->Append($1); } | NamedConstraint ',' TypeConstraints { $3->Append($1); $$ = $3; } ;NamedConstraint : IDENTIFIER PresenceConstraint { $$ = new WithComponentConstraintElement($1, NULL, (int)$2); } | IDENTIFIER Constraint PresenceConstraint { $$ = new WithComponentConstraintElement($1, $2, (int)$3); } ;PresenceConstraint : PRESENT { $$ = WithComponentConstraintElement::Present; } | ABSENT { $$ = WithComponentConstraintElement::Absent; } | OPTIONAL_t { $$ = WithComponentConstraintElement::Optional; } | /* empty */ { $$ = WithComponentConstraintElement::Default; } ;GeneralConstraint : UserDefinedConstraint | TableConstraint ;UserDefinedConstraint : CONSTRAINED BY '{' UserDefinedConstraintParameterList '}' { $$ = new Constraint($4); } ;UserDefinedConstraintParameterList : /* empty */ { $$ = new UserDefinedConstraintElement(NULL); } | UserDefinedConstraintParameters { $$ = new UserDefinedConstraintElement($1); } ; UserDefinedConstraintParameters : UserDefinedConstraintParameter ',' UserDefinedConstraintParameters { $3->Append($1); $$ = $3; } | UserDefinedConstraintParameter { $$ = new TypesList; $$->Append($1); } ;UserDefinedConstraintParameter : Governor ':' ActualParameter { $$ = $3; } | ActualParameter ;TableConstraint : ObjectSet /* SimpleTableConstraint */ | ComponentRelationConstraint ;ComponentRelationConstraint : '{' DefinedObjectSet '}' '{' AtNotations '}' { $$ = NULL; } ;AtNotations : AtNotations ',' AtNotation | AtNotation ;AtNotation : '@' ComponentIdList | '@' '.' ComponentIdList ;ComponentIdList : ComponentIdList '.' IDENTIFIER | IDENTIFIER ;/********/ObjectClassAssignment : OBJECTCLASSREFERENCE ASSIGNMENT ObjectClass { } ;ObjectAssignment : OBJECTREFERENCE DefinedObjectClass ASSIGNMENT Object { } ;ObjectSetAssignment : OBJECTSETREFERENCE DefinedObjectClass ASSIGNMENT ObjectSet { } ;ObjectClass : DefinedObjectClass { } | ObjectClassDefn | ParameterizedObjectClass ;DefinedObjectClass : ExternalObjectClassReference | OBJECTCLASSREFERENCE | UsefulObjectClassReference ;ExternalObjectClassReference : MODULEREFERENCE '.' OBJECTCLASSREFERENCE { $$ = ConcatNames($1, '.', $3); } ;UsefulObjectClassReference : TYPE_IDENTIFIER { $$ = new PString("TYPE-IDENTIFIER"); } | ABSTRACT_SYNTAX { $$ = new PString("ABSTRACT-SYNTAX"); } ;ObjectClassDefn : CLASS '{' FieldSpecs '}' WithSyntaxSpec ;FieldSpecs : FieldSpecs ',' FieldSpec | FieldSpec ;FieldSpec : TypeFieldSpec | FixedTypeValueFieldSpec | VariableTypeValueFieldSpec | FixedTypeValueSetFieldSpec | VariableTypeValueSetFieldSpec | ObjectFieldSpec | ObjectSetFieldSpec ;TypeFieldSpec : TYPEFIELDREFERENCE TypeOptionalitySpec { } ;TypeOptionalitySpec : OPTIONAL_t | DEFAULT Type | /* empty */ ;FixedTypeValueFieldSpec : VALUEFIELDREFERENCE Type Unique ValueOptionalitySpec { } ;Unique : UNIQUE | /* empty */ ;ValueOptionalitySpec : OPTIONAL_t | DEFAULT Value | /* empty */ ;VariableTypeValueFieldSpec : VALUEFIELDREFERENCE FieldName ValueOptionalitySpec { } ;FixedTypeValueSetFieldSpec : VALUESETFIELDREFERENCE Type ValueSetOptionalitySpec { } ;ValueSetOptionalitySpec : OPTIONAL_t | DEFAULT ValueSet | /* empty */ ;VariableTypeValueSetFieldSpec : VALUESETFIELDREFERENCE FieldName ValueSetOptionalitySpec { } ;ObjectFieldSpec : OBJECTFIELDREFERENCE DefinedObjectClass ObjectOptionalitySpec { } ;ObjectOptionalitySpec : OPTIONAL_t | DEFAULT Object | /* empty */ ;ObjectSetFieldSpec : OBJECTSETFIELDREFERENCE DefinedObjectClass ObjectSetOptionalitySpec { } ;ObjectSetOptionalitySpec : OPTIONAL_t | DEFAULT ObjectSet | /* empty */ ;WithSyntaxSpec : WITH SYNTAX SyntaxList | /* empty */ ;SyntaxList : '{' TokenOrGroupSpecs '}' | '{' '}' ;TokenOrGroupSpecs : TokenOrGroupSpecs TokenOrGroupSpec | TokenOrGroupSpec ;TokenOrGroupSpec : RequiredToken | OptionalGroup ;OptionalGroup : '[' TokenOrGroupSpecs ']' ;RequiredToken : Literal | PrimitiveFieldName { } ;Literal : BIT | BOOLEAN_t | CHARACTER | CHOICE | EMBEDDED | END | ENUMERATED | EXTERNAL | FALSE_t | INSTANCE | INTEGER { } | INTERSECTION | MINUS_INFINITY | NULL_TYPE | OBJECT | OCTET | PLUS_INFINITY | REAL | SEQUENCE | SET | TRUE_t | UNION | ',' ;DefinedObject : ExternalObjectReference | OBJECTREFERENCE { } ;ExternalObjectReference : MODULEREFERENCE '.' OBJECTREFERENCE { } ;ParameterizedObjectClass : DefinedObjectClass ActualParameterList { } ;DefinedObjectSet : ExternalObjectSetReference { } | OBJECTSETREFERENCE { } ;ExternalObjectSetReference : MODULEREFERENCE '.' OBJECTSETREFERENCE { } ;ParameterizedObjectSet : DefinedObjectSet ActualParameterList ;FieldName : FieldName '.' PrimitiveFieldName { $$ = ConcatNames($1, '.', $3); } | PrimitiveFieldName ;PrimitiveFieldName : TYPEFIELDREFERENCE | VALUEFIELDREFERENCE | VALUESETFIELDREFERENCE | OBJECTFIELDREFERENCE | OBJECTSETFIELDREFERENCE ;Object : DefinedObject { }/*!!! | ObjectDefn { }*/ | ObjectFromObject { } | ParameterizedObject { } ;/*!!!!ObjectDefn : DefaultSyntax | DefinedSyntax ;DefaultSyntax : '{' FieldSettings '} : '{' '} ;FieldSettings : FieldSettings ',' FieldSetting | FieldSetting ;FieldSetting : PrimitiveFieldName Setting ;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -