📄 asn1p_y.y
字号:
/* * X.680 does not permit ElementSetSpecs starting with ellipsis, * i.e. (..., A, B). This is very strange: the ElementSetSpecs is used * inside ValueSet, and ValueSets "in the wild" tend to have the first * ellipsis. */ValueSetBody: ValueSetElement { } | ValueSetBody ',' ValueSetElement { } ;ValueSetElement: TOK_ThreeDots { } | ElementSetSpec { } ;/* * Data Type Reference. * === EXAMPLE === * Type3 ::= CHOICE { a Type1, b Type 2 } * === EOF === */DataTypeReference: /* * Optionally tagged type definition. */ TypeRefName TOK_PPEQ optTag TOK_TYPE_IDENTIFIER { $$ = asn1p_expr_new(yylineno); checkmem($$); $$->Identifier = $1; $$->tag = $3; $$->expr_type = A1TC_TYPEID; $$->meta_type = AMT_TYPE; } | TypeRefName TOK_PPEQ Type { $$ = $3; $$->Identifier = $1; assert($$->expr_type); assert($$->meta_type); } | TypeRefName TOK_PPEQ ClassDeclaration { $$ = $3; $$->Identifier = $1; assert($$->expr_type == A1TC_CLASSDEF); assert($$->meta_type == AMT_OBJECT); } /* * Parametrized <Type> declaration: * === EXAMPLE === * SIGNED { ToBeSigned } ::= SEQUENCE { * toBeSigned ToBeSigned, * algorithm AlgorithmIdentifier, * signature BIT STRING * } * === EOF === */ | TypeRefName '{' ParameterArgumentList '}' TOK_PPEQ Type { $$ = $6; assert($$->Identifier == 0); $$->Identifier = $1; $$->params = $3; $$->meta_type = AMT_PARAMTYPE; } ;ParameterArgumentList: ParameterArgumentName { int ret; $$ = asn1p_paramlist_new(yylineno); checkmem($$); ret = asn1p_paramlist_add_param($$, $1.governor, $1.argument); checkmem(ret == 0); if($1.governor) asn1p_ref_free($1.governor); if($1.argument) free($1.argument); } | ParameterArgumentList ',' ParameterArgumentName { int ret; $$ = $1; ret = asn1p_paramlist_add_param($$, $3.governor, $3.argument); checkmem(ret == 0); if($3.governor) asn1p_ref_free($3.governor); if($3.argument) free($3.argument); } ; ParameterArgumentName: TypeRefName { $$.governor = NULL; $$.argument = $1; } | TypeRefName ':' Identifier { int ret; $$.governor = asn1p_ref_new(yylineno); ret = asn1p_ref_add_component($$.governor, $1, 0); checkmem(ret == 0); $$.argument = $3; } | TypeRefName ':' TypeRefName { int ret; $$.governor = asn1p_ref_new(yylineno); ret = asn1p_ref_add_component($$.governor, $1, 0); checkmem(ret == 0); $$.argument = $3; } | BasicTypeId ':' Identifier { int ret; $$.governor = asn1p_ref_new(yylineno); ret = asn1p_ref_add_component($$.governor, ASN_EXPR_TYPE2STR($1), 1); checkmem(ret == 0); $$.argument = $3; } ;ActualParameterList: ActualParameter { $$ = asn1p_expr_new(yylineno); checkmem($$); asn1p_expr_add($$, $1); } | ActualParameterList ',' ActualParameter { $$ = $1; asn1p_expr_add($$, $3); } ;ActualParameter: Type { $$ = $1; } | Identifier { $$ = asn1p_expr_new(yylineno); checkmem($$); $$->Identifier = $1; $$->expr_type = A1TC_REFERENCE; $$->meta_type = AMT_VALUE; } ;/* | '{' ActualParameter '}' { $$ = asn1p_expr_new(yylineno); checkmem($$); asn1p_expr_add($$, $2); $$->expr_type = A1TC_PARAMETRIZED; $$->meta_type = AMT_TYPE; } ;*//* * A collection of constructed data type members. */optComponentTypeLists: { $$ = asn1p_expr_new(yylineno); } | ComponentTypeLists { $$ = $1; };ComponentTypeLists: ComponentType { $$ = asn1p_expr_new(yylineno); checkmem($$); asn1p_expr_add($$, $1); } | ComponentTypeLists ',' ComponentType { $$ = $1; asn1p_expr_add($$, $3); } ;ComponentType: Identifier Type optMarker { $$ = $2; assert($$->Identifier == 0); $$->Identifier = $1; $$->marker = $3; } | TOK_COMPONENTS TOK_OF Type { $$ = asn1p_expr_new(yylineno); checkmem($$); $$->meta_type = $3->meta_type; $$->expr_type = A1TC_COMPONENTS_OF; asn1p_expr_add($$, $3); } | ExtensionAndException { $$ = $1; } ;AlternativeTypeLists: AlternativeType { $$ = asn1p_expr_new(yylineno); checkmem($$); asn1p_expr_add($$, $1); } | AlternativeTypeLists ',' AlternativeType { $$ = $1; asn1p_expr_add($$, $3); } ;AlternativeType: Identifier Type { $$ = $2; assert($$->Identifier == 0); $$->Identifier = $1; } | ExtensionAndException { $$ = $1; } ;ClassDeclaration: TOK_CLASS '{' ClassFieldList '}' optWithSyntax { $$ = $3; checkmem($$); $$->with_syntax = $5; assert($$->expr_type == A1TC_CLASSDEF); assert($$->meta_type == AMT_OBJECT); } ;optUnique: { $$ = 0; } | TOK_UNIQUE { $$ = 1; } ;ClassFieldList: ClassField { $$ = asn1p_expr_new(yylineno); checkmem($$); $$->expr_type = A1TC_CLASSDEF; $$->meta_type = AMT_OBJECT; asn1p_expr_add($$, $1); } | ClassFieldList ',' ClassField { $$ = $1; asn1p_expr_add($$, $3); } ;ClassField: ClassFieldIdentifier optMarker { $$ = asn1p_expr_new(yylineno); checkmem($$); $$->Identifier = $1.name; $$->expr_type = A1TC_CLASSFIELD; $$->meta_type = AMT_OBJECTFIELD; $$->marker = $2; } | ClassFieldIdentifier Type optUnique optMarker { $$ = $2; $$->Identifier = $1.name; $$->marker = $4; $$->unique = $3; } | ClassFieldIdentifier ClassFieldIdentifier optUnique optMarker { int ret; $$ = asn1p_expr_new(yylineno); checkmem($$); $$->Identifier = $1.name; $$->reference = asn1p_ref_new(yylineno); checkmem($$->reference); ret = asn1p_ref_add_component($$->reference, $2.name, $2.lex_type); checkmem(ret == 0); $$->expr_type = A1TC_CLASSFIELD; $$->meta_type = AMT_OBJECTFIELD; $$->marker = $4; $$->unique = $3; } ;optWithSyntax: { $$ = 0; } | WithSyntax { $$ = $1; } ;WithSyntax: TOK_WITH TOK_SYNTAX '{' { asn1p_lexer_hack_enable_with_syntax(); } WithSyntaxFormat '}' { $$ = $5; } ;WithSyntaxFormat: WithSyntaxFormatToken { $$ = asn1p_wsyntx_new(); TQ_ADD(&($$->chunks), $1, next); } | WithSyntaxFormat WithSyntaxFormatToken { $$ = $1; TQ_ADD(&($$->chunks), $2, next); } ;WithSyntaxFormatToken: TOK_opaque { $$ = asn1p_wsyntx_chunk_frombuf($1.buf, $1.len, 0); } | ClassFieldIdentifier { asn1p_ref_t *ref; int ret; ref = asn1p_ref_new(yylineno); checkmem(ref); ret = asn1p_ref_add_component(ref, $1.name, $1.lex_type); checkmem(ret == 0); $$ = asn1p_wsyntx_chunk_fromref(ref, 0); } ;ExtensionAndException: TOK_ThreeDots { $$ = asn1p_expr_new(yylineno); checkmem($$); $$->Identifier = strdup("..."); checkmem($$->Identifier); $$->expr_type = A1TC_EXTENSIBLE; $$->meta_type = AMT_TYPE; } | TOK_ThreeDots '!' DefinedValue { $$ = asn1p_expr_new(yylineno); checkmem($$); $$->Identifier = strdup("..."); checkmem($$->Identifier); $$->value = $3; $$->expr_type = A1TC_EXTENSIBLE; $$->meta_type = AMT_TYPE; } | TOK_ThreeDots '!' SignedNumber { $$ = asn1p_expr_new(yylineno); checkmem($$); $$->Identifier = strdup("..."); $$->value = $3; checkmem($$->Identifier); $$->expr_type = A1TC_EXTENSIBLE; $$->meta_type = AMT_TYPE; } ;Type: optTag TypeDeclaration optConstraints { $$ = $2; $$->tag = $1; /* * Outer constraint for SEQUENCE OF and SET OF applies * to the inner type. */ if($$->expr_type == ASN_CONSTR_SEQUENCE_OF || $$->expr_type == ASN_CONSTR_SET_OF) { assert(!TQ_FIRST(&($$->members))->constraints); TQ_FIRST(&($$->members))->constraints = $3; } else { if($$->constraints) { assert(!$2); } else { $$->constraints = $3; } } } ;TypeDeclaration: BasicType { $$ = $1; } | BasicString { $$ = asn1p_expr_new(yylineno); checkmem($$); $$->expr_type = $1; $$->meta_type = AMT_TYPE; } | TOK_CHOICE '{' AlternativeTypeLists '}' { $$ = $3; assert($$->expr_type == A1TC_INVALID); $$->expr_type = ASN_CONSTR_CHOICE; $$->meta_type = AMT_TYPE; } | TOK_SEQUENCE '{' optComponentTypeLists '}' { $$ = $3; assert($$->expr_type == A1TC_INVALID); $$->expr_type = ASN_CONSTR_SEQUENCE; $$->meta_type = AMT_TYPE; } | TOK_SET '{' optComponentTypeLists '}' { $$ = $3; assert($$->expr_type == A1TC_INVALID); $$->expr_type = ASN_CONSTR_SET; $$->meta_type = AMT_TYPE; } | TOK_SEQUENCE optConstraints TOK_OF optIdentifier optTag TypeDeclaration { $$ = asn1p_expr_new(yylineno); checkmem($$); $$->constraints = $2; $$->expr_type = ASN_CONSTR_SEQUENCE_OF; $$->meta_type = AMT_TYPE; $6->Identifier = $4; $6->tag = $5; asn1p_expr_add($$, $6); } | TOK_SET optConstraints TOK_OF optIdentifier optTag TypeDeclaration { $$ = asn1p_expr_new(yylineno); checkmem($$); $$->constraints = $2; $$->expr_type = ASN_CONSTR_SET_OF; $$->meta_type = AMT_TYPE; $6->Identifier = $4; $6->tag = $5; asn1p_expr_add($$, $6); } | TOK_ANY { $$ = asn1p_expr_new(yylineno); checkmem($$); $$->expr_type = ASN_TYPE_ANY; $$->meta_type = AMT_TYPE; } | TOK_ANY TOK_DEFINED TOK_BY Identifier { int ret; $$ = asn1p_expr_new(yylineno); checkmem($$); $$->reference = asn1p_ref_new(yylineno); ret = asn1p_ref_add_component($$->reference, $4, RLT_lowercase); checkmem(ret == 0); $$->expr_type = ASN_TYPE_ANY; $$->meta_type = AMT_TYPE; } /* * A parametrized assignment. */ | TypeRefName '{' ActualParameterList '}' { int ret; $$ = $3; assert($$->expr_type == 0); assert($$->meta_type == 0); assert($$->reference == 0); $$->reference = asn1p_ref_new(yylineno); checkmem($$->reference); ret = asn1p_ref_add_component($$->reference, $1, RLT_UNKNOWN); checkmem(ret == 0); free($1); $$->expr_type = A1TC_PARAMETRIZED; $$->meta_type = AMT_TYPE; } /* * A DefinedType reference. * "CLASS1.&id.&id2" * or * "Module.Type" * or * "Module.identifier" * or * "Type" */ | ComplexTypeReference { $$ = asn1p_expr_new(yylineno); checkmem($$); $$->reference = $1; $$->expr_type = A1TC_REFERENCE; $$->meta_type = AMT_TYPEREF; } | TOK_INSTANCE TOK_OF ComplexTypeReference { $$ = asn1p_expr_new(yylineno); checkmem($$); $$->reference = $3; $$->expr_type = A1TC_INSTANCE; $$->meta_type = AMT_TYPE; } ;/* * A type name consisting of several components. * === EXAMPLE === * === EOF === */ComplexTypeReference: TOK_typereference { int ret; $$ = asn1p_ref_new(yylineno); checkmem($$); ret = asn1p_ref_add_component($$, $1, RLT_UNKNOWN); checkmem(ret == 0); free($1); } | TOK_typereference '.' TypeRefName { int ret; $$ = asn1p_ref_new(yylineno); checkmem($$); ret = asn1p_ref_add_component($$, $1, RLT_UNKNOWN); checkmem(ret == 0); ret = asn1p_ref_add_component($$, $3, RLT_UNKNOWN); checkmem(ret == 0); free($1); } | ObjectClassReference '.' TypeRefName { int ret; $$ = asn1p_ref_new(yylineno); checkmem($$); ret = asn1p_ref_add_component($$, $1, RLT_UNKNOWN); checkmem(ret == 0); ret = asn1p_ref_add_component($$, $3, RLT_UNKNOWN); checkmem(ret == 0); free($1); } | TOK_typereference '.' Identifier { int ret; $$ = asn1p_ref_new(yylineno); checkmem($$); ret = asn1p_ref_add_component($$, $1, RLT_UNKNOWN); checkmem(ret == 0); ret = asn1p_ref_add_component($$, $3, RLT_lowercase); checkmem(ret == 0); free($1); } | ObjectClassReference { int ret; $$ = asn1p_ref_new(yylineno); checkmem($$); ret = asn1p_ref_add_component($$, $1, RLT_CAPITALS); free($1); checkmem(ret == 0); } | ObjectClassReference '.' ComplexTypeReferenceAmpList { int ret; $$ = $3; ret = asn1p_ref_add_component($$, $1, RLT_CAPITALS); free($1); checkmem(ret == 0); /* * Move the last element infront. */ { struct asn1p_ref_component_s tmp_comp; tmp_comp = $$->components[$$->comp_count-1]; memmove(&$$->components[1], &$$->components[0], sizeof($$->components[0]) * ($$->comp_count - 1)); $$->components[0] = tmp_comp; } } ;ComplexTypeReferenceAmpList: ComplexTypeReferenceElement { int ret; $$ = asn1p_ref_new(yylineno); checkmem($$); ret = asn1p_ref_add_component($$, $1.name, $1.lex_type); free($1.name); checkmem(ret == 0); } | ComplexTypeReferenceAmpList '.' ComplexTypeReferenceElement { int ret; $$ = $1; ret = asn1p_ref_add_component($$, $3.name, $3.lex_type); free($3.name); checkmem(ret == 0); } ;ComplexTypeReferenceElement: ClassFieldName;ClassFieldIdentifier: ClassFieldName;ClassFieldName: /* "&Type1" */ TOK_typefieldreference { $$.lex_type = RLT_AmpUppercase; $$.name = $1; } /* "&id" */ | TOK_valuefieldreference { $$.lex_type = RLT_Amplowercase; $$.name = $1; } ;/* * === EXAMPLE === * value INTEGER ::= 1 * === EOF === */ValueDefinition: Identifier DefinedTypeRef TOK_PPEQ Value { $$ = $2; assert($$->Identifier == NULL); $$->Identifier = $1; $$->meta_type = AMT_VALUE; $$->value = $4; } ;Value: Identifier ':' Value { $$ = asn1p_value_fromint(0); checkmem($$); $$->type = ATV_CHOICE_IDENTIFIER; $$->value.choice_identifier.identifier = $1; $$->value.choice_identifier.value = $3; } | '{' { asn1p_lexer_hack_push_opaque_state(); } Opaque /* '}' */ { $$ = asn1p_value_frombuf($3.buf, $3.len, 0); checkmem($$); $$->type = ATV_UNPARSED; } | TOK_NULL { $$ = asn1p_value_fromint(0); checkmem($$); $$->type = ATV_NULL; } | TOK_FALSE { $$ = asn1p_value_fromint(0); checkmem($$); $$->type = ATV_FALSE; } | TOK_TRUE { $$ = asn1p_value_fromint(0); checkmem($$); $$->type = ATV_TRUE; } | TOK_bstring { $$ = _convert_bitstring2binary($1, 'B'); checkmem($$); } | TOK_hstring { $$ = _convert_bitstring2binary($1, 'H'); checkmem($$); } | TOK_cstring { $$ = asn1p_value_frombuf($1.buf, $1.len, 0); checkmem($$); } | SignedNumber { $$ = $1; } | DefinedValue { $$ = $1; } ;DefinedValue: Identifier { asn1p_ref_t *ref; int ret; ref = asn1p_ref_new(yylineno); checkmem(ref); ret = asn1p_ref_add_component(ref, $1, RLT_lowercase); checkmem(ret == 0); $$ = asn1p_value_fromref(ref, 0); checkmem($$); free($1); } | TypeRefName '.' Identifier { asn1p_ref_t *ref; int ret; ref = asn1p_ref_new(yylineno); checkmem(ref); ret = asn1p_ref_add_component(ref, $1, RLT_UNKNOWN); checkmem(ret == 0); ret = asn1p_ref_add_component(ref, $3, RLT_lowercase); checkmem(ret == 0); $$ = asn1p_value_fromref(ref, 0); checkmem($$); free($1); free($3); } ;Opaque: TOK_opaque { $$.len = $1.len + 2; $$.buf = malloc($$.len + 1); checkmem($$.buf); $$.buf[0] = '{'; $$.buf[1] = ' '; memcpy($$.buf + 2, $1.buf, $1.len); $$.buf[$$.len] = '\0'; free($1.buf); } | Opaque TOK_opaque { int newsize = $1.len + $2.len; char *p = malloc(newsize + 1); checkmem(p); memcpy(p , $1.buf, $1.len); memcpy(p + $1.len, $2.buf, $2.len); p[newsize] = '\0'; free($1.buf); free($2.buf); $$.buf = p; $$.len = newsize; } ;BasicTypeId: TOK_BOOLEAN { $$ = ASN_BASIC_BOOLEAN; } | TOK_NULL { $$ = ASN_BASIC_NULL; } | TOK_REAL { $$ = ASN_BASIC_REAL; } | BasicTypeId_UniverationCompatible { $$ = $1; } | TOK_OCTET TOK_STRING { $$ = ASN_BASIC_OCTET_STRING; } | TOK_OBJECT TOK_IDENTIFIER { $$ = ASN_BASIC_OBJECT_IDENTIFIER; } | TOK_RELATIVE_OID { $$ = ASN_BASIC_RELATIVE_OID; } | TOK_EXTERNAL { $$ = ASN_BASIC_EXTERNAL; } | TOK_EMBEDDED TOK_PDV { $$ = ASN_BASIC_EMBEDDED_PDV; }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -