📄 asn1p_y.y
字号:
| TOK_CHARACTER TOK_STRING { $$ = ASN_BASIC_CHARACTER_STRING; } | TOK_UTCTime { $$ = ASN_BASIC_UTCTime; } | TOK_GeneralizedTime { $$ = ASN_BASIC_GeneralizedTime; } ;/* * A type identifier which may be used with "{ a(1), b(2) }" clause. */BasicTypeId_UniverationCompatible: TOK_INTEGER { $$ = ASN_BASIC_INTEGER; } | TOK_ENUMERATED { $$ = ASN_BASIC_ENUMERATED; } | TOK_BIT TOK_STRING { $$ = ASN_BASIC_BIT_STRING; } ;BasicType: BasicTypeId { $$ = asn1p_expr_new(yylineno); checkmem($$); $$->expr_type = $1; $$->meta_type = AMT_TYPE; } | BasicTypeId_UniverationCompatible UniverationDefinition { if($2) { $$ = $2; } else { $$ = asn1p_expr_new(yylineno); checkmem($$); } $$->expr_type = $1; $$->meta_type = AMT_TYPE; } ;BasicString: TOK_BMPString { $$ = ASN_STRING_BMPString; } | TOK_GeneralString { $$ = ASN_STRING_GeneralString; fprintf(stderr, "WARNING: GeneralString is not fully supported\n"); } | TOK_GraphicString { $$ = ASN_STRING_GraphicString; fprintf(stderr, "WARNING: GraphicString is not fully supported\n"); } | TOK_IA5String { $$ = ASN_STRING_IA5String; } | TOK_ISO646String { $$ = ASN_STRING_ISO646String; } | TOK_NumericString { $$ = ASN_STRING_NumericString; } | TOK_PrintableString { $$ = ASN_STRING_PrintableString; } | TOK_T61String { $$ = ASN_STRING_T61String; fprintf(stderr, "WARNING: T61String is not fully supported\n"); } | TOK_TeletexString { $$ = ASN_STRING_TeletexString; } | TOK_UniversalString { $$ = ASN_STRING_UniversalString; } | TOK_UTF8String { $$ = ASN_STRING_UTF8String; } | TOK_VideotexString { $$ = ASN_STRING_VideotexString; fprintf(stderr, "WARNING: VideotexString is not fully supported\n"); } | TOK_VisibleString { $$ = ASN_STRING_VisibleString; } | TOK_ObjectDescriptor { $$ = ASN_STRING_ObjectDescriptor; } ;/* * Data type constraints. */Union: '|' | TOK_UNION;Intersection: '^' | TOK_INTERSECTION;Except: TOK_EXCEPT;optConstraints: { $$ = 0; } | Constraints { $$ = $1; } ;Constraints: SetOfConstraints { CONSTRAINT_INSERT($$, ACT_CA_SET, $1, 0); } | TOK_SIZE '(' ElementSetSpecs ')' { /* * This is a special case, for compatibility purposes. * It goes without parentheses. */ CONSTRAINT_INSERT($$, ACT_CT_SIZE, $3, 0); } ;SetOfConstraints: '(' ElementSetSpecs ')' { $$ = $2; } | SetOfConstraints '(' ElementSetSpecs ')' { CONSTRAINT_INSERT($$, ACT_CA_SET, $1, $3); } ;ElementSetSpecs: ElementSetSpec { $$ = $1; } | ElementSetSpec ',' TOK_ThreeDots { asn1p_constraint_t *ct; ct = asn1p_constraint_new(yylineno); ct->type = ACT_EL_EXT; CONSTRAINT_INSERT($$, ACT_CA_CSV, $1, ct); } | ElementSetSpec ',' TOK_ThreeDots ',' ElementSetSpec { asn1p_constraint_t *ct; ct = asn1p_constraint_new(yylineno); ct->type = ACT_EL_EXT; CONSTRAINT_INSERT($$, ACT_CA_CSV, $1, ct); ct = $$; CONSTRAINT_INSERT($$, ACT_CA_CSV, ct, $5); } ;ElementSetSpec: ConstraintSubtypeElement { $$ = $1; } | ElementSetSpec Union ConstraintSubtypeElement { CONSTRAINT_INSERT($$, ACT_CA_UNI, $1, $3); } | ElementSetSpec Intersection ConstraintSubtypeElement { CONSTRAINT_INSERT($$, ACT_CA_INT, $1, $3); } | ConstraintSubtypeElement Except ConstraintSubtypeElement { CONSTRAINT_INSERT($$, ACT_CA_EXC, $1, $3); } ;ConstraintSubtypeElement: ConstraintSpec '(' ElementSetSpecs ')' { int ret; $$ = asn1p_constraint_new(yylineno); checkmem($$); $$->type = $1; ret = asn1p_constraint_insert($$, $3); checkmem(ret == 0); } | '(' ElementSetSpecs ')' { int ret; $$ = asn1p_constraint_new(yylineno); checkmem($$); $$->type = ACT_CA_SET; ret = asn1p_constraint_insert($$, $2); checkmem(ret == 0); } | ConstraintValue { $$ = asn1p_constraint_new(yylineno); checkmem($$); $$->type = ACT_EL_VALUE; $$->value = $1; } | ConstraintValue ConstraintRangeSpec ConstraintValue { $$ = asn1p_constraint_new(yylineno); checkmem($$); $$->type = $2; $$->range_start = $1; $$->range_stop = $3; } | TOK_MIN ConstraintRangeSpec ConstraintValue { $$ = asn1p_constraint_new(yylineno); checkmem($$); $$->type = $2; $$->range_start = asn1p_value_fromint(-123); $$->range_stop = $3; $$->range_start->type = ATV_MIN; } | ConstraintValue ConstraintRangeSpec TOK_MAX { $$ = asn1p_constraint_new(yylineno); checkmem($$); $$->type = $2; $$->range_start = $1; $$->range_stop = asn1p_value_fromint(321); $$->range_stop->type = ATV_MAX; } | TOK_MIN ConstraintRangeSpec TOK_MAX { $$ = asn1p_constraint_new(yylineno); checkmem($$); $$->type = $2; $$->range_start = asn1p_value_fromint(-123); $$->range_stop = asn1p_value_fromint(321); $$->range_start->type = ATV_MIN; $$->range_stop->type = ATV_MAX; } | TableConstraint { $$ = $1; } | WithComponents { $$ = $1; } ;ConstraintRangeSpec: TOK_TwoDots { $$ = ACT_EL_RANGE; } | TOK_TwoDots '<' { $$ = ACT_EL_RLRANGE; } | '<' TOK_TwoDots { $$ = ACT_EL_LLRANGE; } | '<' TOK_TwoDots '<' { $$ = ACT_EL_ULRANGE; } ;ConstraintSpec: TOK_SIZE { $$ = ACT_CT_SIZE; } | TOK_FROM { $$ = ACT_CT_FROM; } ;ConstraintValue: TOK_FALSE { $$ = asn1p_value_fromint(0); checkmem($$); $$->type = ATV_FALSE; } | TOK_TRUE { $$ = asn1p_value_fromint(1); checkmem($$); $$->type = ATV_TRUE; } | SignedNumber { $$ = $1; } | TOK_cstring { $$ = asn1p_value_frombuf($1.buf, $1.len, 0); checkmem($$); } | 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 { 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); $$ = asn1p_value_fromref(ref, 0); checkmem($$); free($1); } ;WithComponents: TOK_WITH TOK_COMPONENTS '{' WithComponentsList '}' { CONSTRAINT_INSERT($$, ACT_CT_WCOMPS, $4, 0); } ;WithComponentsList: WithComponentsElement { $$ = $1; } | WithComponentsList ',' WithComponentsElement { CONSTRAINT_INSERT($$, ACT_CT_WCOMPS, $1, $3); } ;WithComponentsElement: TOK_ThreeDots { $$ = asn1p_constraint_new(yylineno); checkmem($$); $$->type = ACT_EL_EXT; } | Identifier optConstraints optPresenceConstraint { $$ = asn1p_constraint_new(yylineno); checkmem($$); $$->type = ACT_EL_VALUE; $$->value = asn1p_value_frombuf($1, strlen($1), 0); $$->presence = $3; } ;/* * presence constraint for WithComponents */optPresenceConstraint: { $$ = ACPRES_DEFAULT; } | PresenceConstraint { $$ = $1; } ;PresenceConstraint: TOK_PRESENT { $$ = ACPRES_PRESENT; } | TOK_ABSENT { $$ = ACPRES_ABSENT; } | TOK_OPTIONAL { $$ = ACPRES_OPTIONAL; } ;TableConstraint: SimpleTableConstraint { $$ = $1; } | ComponentRelationConstraint { $$ = $1; } ;/* * "{ExtensionSet}" */SimpleTableConstraint: '{' TypeRefName '}' { asn1p_ref_t *ref = asn1p_ref_new(yylineno); asn1p_constraint_t *ct; int ret; ret = asn1p_ref_add_component(ref, $2, 0); checkmem(ret == 0); ct = asn1p_constraint_new(yylineno); checkmem($$); ct->type = ACT_EL_VALUE; ct->value = asn1p_value_fromref(ref, 0); CONSTRAINT_INSERT($$, ACT_CA_CRC, ct, 0); } ;ComponentRelationConstraint: SimpleTableConstraint '{' AtNotationList '}' { CONSTRAINT_INSERT($$, ACT_CA_CRC, $1, $3); } ;AtNotationList: AtNotationElement { $$ = asn1p_constraint_new(yylineno); checkmem($$); $$->type = ACT_EL_VALUE; $$->value = asn1p_value_fromref($1, 0); } | AtNotationList ',' AtNotationElement { asn1p_constraint_t *ct; ct = asn1p_constraint_new(yylineno); checkmem(ct); ct->type = ACT_EL_VALUE; ct->value = asn1p_value_fromref($3, 0); CONSTRAINT_INSERT($$, ACT_CA_CSV, $1, ct); } ;/* * @blah */AtNotationElement: '@' ComponentIdList { char *p = malloc(strlen($2) + 2); int ret; *p = '@'; strcpy(p + 1, $2); $$ = asn1p_ref_new(yylineno); ret = asn1p_ref_add_component($$, p, 0); checkmem(ret == 0); free(p); free($2); } | '@' '.' ComponentIdList { char *p = malloc(strlen($3) + 3); int ret; p[0] = '@'; p[1] = '.'; strcpy(p + 2, $3); $$ = asn1p_ref_new(yylineno); ret = asn1p_ref_add_component($$, p, 0); checkmem(ret == 0); free(p); free($3); } ;/* identifier "." ... */ComponentIdList: Identifier { $$ = $1; } | ComponentIdList '.' Identifier { int l1 = strlen($1); int l3 = strlen($3); $$ = malloc(l1 + 1 + l3 + 1); memcpy($$, $1, l1); $$[l1] = '.'; memcpy($$ + l1 + 1, $3, l3); $$[l1 + 1 + l3] = '\0'; } ;/* * MARKERS */optMarker: { $$.flags = EM_NOMARK; $$.default_value = 0; } | Marker { $$ = $1; } ;Marker: TOK_OPTIONAL { $$.flags = EM_OPTIONAL; $$.default_value = 0; } | TOK_DEFAULT Value { $$.flags = EM_DEFAULT; $$.default_value = $2; } ;/* * Universal enumeration definition to use in INTEGER and ENUMERATED. * === EXAMPLE === * Gender ::= ENUMERATED { unknown(0), male(1), female(2) } * Temperature ::= INTEGER { absolute-zero(-273), freezing(0), boiling(100) } * === EOF === *//*optUniverationDefinition: { $$ = 0; } | UniverationDefinition { $$ = $1; } ;*/UniverationDefinition: '{' '}' { $$ = asn1p_expr_new(yylineno); checkmem($$); } | '{' UniverationList '}' { $$ = $2; } ;UniverationList: UniverationElement { $$ = asn1p_expr_new(yylineno); checkmem($$); asn1p_expr_add($$, $1); } | UniverationList ',' UniverationElement { $$ = $1; asn1p_expr_add($$, $3); } ;UniverationElement: Identifier { $$ = asn1p_expr_new(yylineno); checkmem($$); $$->expr_type = A1TC_UNIVERVAL; $$->meta_type = AMT_VALUE; $$->Identifier = $1; } | Identifier '(' SignedNumber ')' { $$ = asn1p_expr_new(yylineno); checkmem($$); $$->expr_type = A1TC_UNIVERVAL; $$->meta_type = AMT_VALUE; $$->Identifier = $1; $$->value = $3; } | Identifier '(' DefinedValue ')' { $$ = asn1p_expr_new(yylineno); checkmem($$); $$->expr_type = A1TC_UNIVERVAL; $$->meta_type = AMT_VALUE; $$->Identifier = $1; $$->value = $3; } | SignedNumber { $$ = asn1p_expr_new(yylineno); checkmem($$); $$->expr_type = A1TC_UNIVERVAL; $$->meta_type = AMT_VALUE; $$->value = $1; } | TOK_ThreeDots { $$ = asn1p_expr_new(yylineno); checkmem($$); $$->Identifier = strdup("..."); checkmem($$->Identifier); $$->expr_type = A1TC_EXTENSIBLE; $$->meta_type = AMT_VALUE; } ;SignedNumber: TOK_number { $$ = asn1p_value_fromint($1); checkmem($$); } | TOK_number_negative { $$ = asn1p_value_fromint($1); checkmem($$); } ;/* * SEQUENCE definition. * === EXAMPLE === * Struct1 ::= SEQUENCE { * memb1 Struct2, * memb2 SEQUENCE OF { * memb2-1 Struct 3 * } * } * === EOF === *//* * SET definition. * === EXAMPLE === * Person ::= SET { * name [0] PrintableString (SIZE(1..20)), * country [1] PrintableString (SIZE(1..20)) DEFAULT default-country, * } * === EOF === */optTag: { memset(&$$, 0, sizeof($$)); } | Tag { $$ = $1; } ;Tag: TagTypeValue TagPlicit { $$ = $1; $$.tag_mode = $2.tag_mode; } ;TagTypeValue: '[' TagClass TOK_number ']' { $$ = $2; $$.tag_value = $3; };TagClass: { $$.tag_class = TC_CONTEXT_SPECIFIC; } | TOK_UNIVERSAL { $$.tag_class = TC_UNIVERSAL; } | TOK_APPLICATION { $$.tag_class = TC_APPLICATION; } | TOK_PRIVATE { $$.tag_class = TC_PRIVATE; } ;TagPlicit: { $$.tag_mode = TM_DEFAULT; } | TOK_IMPLICIT { $$.tag_mode = TM_IMPLICIT; } | TOK_EXPLICIT { $$.tag_mode = TM_EXPLICIT; } ;TypeRefName: TOK_typereference { checkmem($1); $$ = $1; } | TOK_capitalreference { checkmem($1); $$ = $1; } ;ObjectClassReference: TOK_capitalreference { checkmem($1); $$ = $1; } ;optIdentifier: { $$ = 0; } | Identifier { $$ = $1; }Identifier: TOK_identifier { checkmem($1); $$ = $1; } ;%%/* * Convert Xstring ('0101'B or '5'H) to the binary vector. */static asn1p_value_t *_convert_bitstring2binary(char *str, int base) { asn1p_value_t *val; int slen; int memlen; int baselen; int bits; uint8_t *binary_vector; uint8_t *bv_ptr; uint8_t cur_val; assert(str); assert(str[0] == '\''); switch(base) { case 'B': baselen = 1; break; case 'H': baselen = 4; break; default: assert(base == 'B' || base == 'H'); errno = EINVAL; return NULL; } slen = strlen(str); assert(str[slen - 1] == base); assert(str[slen - 2] == '\''); memlen = slen / (8 / baselen); /* Conservative estimate */ bv_ptr = binary_vector = malloc(memlen + 1); if(bv_ptr == NULL) /* ENOMEM */ return NULL; cur_val = 0; bits = 0; while(*(++str) != '\'') { switch(baselen) { case 1: switch(*str) { case '1': cur_val |= 1 << (7 - (bits % 8)); case '0': break; default: assert(!"_y UNREACH1"); case ' ': case '\r': case '\n': continue; } break; case 4: switch(*str) { case '0': case '1': case '2': case '3': case '4': case '5': case '6': case '7': case '8': case '9': cur_val |= (*str - '0') << (4 - (bits % 8)); break; case 'A': case 'B': case 'C': case 'D': case 'E': case 'F': cur_val |= ((*str - 'A') + 10) << (4 - (bits % 8)); break; default: assert(!"_y UNREACH2"); case ' ': case '\r': case '\n': continue; } break; } bits += baselen; if((bits % 8) == 0) { *bv_ptr++ = cur_val; cur_val = 0; } } *bv_ptr = cur_val; assert((bv_ptr - binary_vector) <= memlen); val = asn1p_value_frombits(binary_vector, bits, 0); if(val == NULL) { free(binary_vector); } return val;}extern char *asn1p_text;intyyerror(const char *msg) { fprintf(stderr, "ASN.1 grammar parse error " "near line %d (token \"%s\"): %s\n", yylineno, asn1p_text, msg); return -1;}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -