/* $Id: ASN1-004.grammar,v 1.1.1.1 2001/02/24 04:58:50 raif Exp $ * * Copyright (C) 1997-2001 The Cryptix Foundation Limited. All rights reserved. * * Use, modification, copying and distribution of this software is subject * the terms and conditions of the Cryptix General Licence. You should have * received a copy of the Cryptix General Licence along with this library; * if not, you can download a copy from http://www.cryptix.org/ . */ /** * A SableCC input file for an ASN.1:1990 subset grammar.

* * Based on Christian Rinderknecht * work on Asno'90.

* * @version $Revision: 1.1.1.1 $ * @author Raif S. Naffah */ Package cryptix.asn1; //=========================================================================== Helpers all = [0..127]; cr = 13; lf = 10; tab = 9; letter = ['-' + [['a'..'z'] + ['A'..'Z']]]; digit = ['0'..'9']; esc = '\' 'n'|'\' 't'|'\' 'b'|'\' 'r'|'\' 'f'|'\' '\'|'\' '''|'\' '"'; c_char = [all - ['"' + ['\' + [cr + lf]]]] | esc; //=========================================================================== Tokens l_brace = '{'; r_brace = '}'; l_paren = '('; r_paren = ')'; l_bracket = '['; r_bracket = ']'; comma = ','; minus = '-'; less = '<'; colon = ':'; bar = '|'; dot = '.'; semi = ';'; dotdot = '..'; ellipsis = '...'; assign_op = '::='; by_kw = 'BY'; of_kw = 'OF'; any_kw = 'ANY'; bit_kw = 'BIT'; end_kw = 'END'; max_kw = 'MAX'; min_kw = 'MIN'; set_kw = 'SET'; from_kw = 'FROM'; null_kw = 'NULL'; real_kw = 'REAL'; size_kw = 'SIZE'; tags_kw = 'TAGS'; true_kw = 'TRUE'; with_kw = 'WITH'; begin_kw = 'BEGIN'; false_kw = 'FALSE'; octet_kw = 'OCTET'; absent_kw = 'ABSENT'; choice_kw = 'CHOICE'; object_kw = 'OBJECT'; string_kw = 'STRING'; boolean_kw = 'BOOLEAN'; default_kw = 'DEFAULT'; defined_kw = 'DEFINED'; exports_kw = 'EXPORTS'; imports_kw = 'IMPORTS'; integer_kw = 'INTEGER'; private_kw = 'PRIVATE'; present_kw = 'PRESENT'; utc_time_kw = 'UTCTime'; based_num_kw = 'BASEDNUM'; explicit_kw = 'EXPLICIT'; external_kw = 'EXTERNAL'; implicit_kw = 'IMPLICIT'; includes_kw = 'INCLUDES'; optional_kw = 'OPTIONAL'; sequence_kw = 'SEQUENCE'; bmp_string_kw = 'BMPString'; component_kw = 'COMPONENT'; ia5_string_kw = 'IA5String'; universal_kw = 'UNIVERSAL'; components_kw = 'COMPONENTS'; enumerated_kw = 'ENUMERATED'; identifier_kw = 'IDENTIFIER'; application_kw = 'APPLICATION'; definitions_kw = 'DEFINITIONS'; plus_infinity_kw = 'PLUSINFINITY'; numeric_string_kw = 'NumericString'; general_string_kw = 'GeneralString'; graphic_string_kw = 'GraphicString'; minus_infinity_kw = 'MINUSINFINITY'; teletex_string_kw = 'TeletexString'; visible_string_kw = 'VisibleString'; videotex_string_kw = 'VideotexString'; generalized_time_kw = 'GeneralizedTime'; printable_string_kw = 'PrintableString'; universal_string_kw = 'UniversalString'; object_descriptor_kw = 'ObjectDescriptor'; number = digit+; h_string = ''' (digit + ['a' .. 'f'] + ['A' .. 'F'])+ ''' 'H'; b_string = ''' ['0' .. '1']* ''' 'B'; c_string = ''' c_char+ '''; upper = ['A'..'Z'] (letter | digit)*; lower = ['a'..'z'] (letter | digit)*; blank = (' ' | tab | cr | lf)+; comment = '-' '-' [all - [cr + lf]]* (cr | lf | cr lf); //=========================================================================== Ignored Tokens blank, comment; //=========================================================================== Productions module_definition = module_identifier definitions_kw tagging? assign_op begin_kw module_body? end_kw ; module_identifier = upper obj_id_comp_lst? ; obj_id_comp_lst = l_brace [oids]:obj_id_component+ r_brace ; obj_id_component = {numeric} number | {upper} upper dot lower | {lower} lower class_attr? ; class_attr = l_paren class_number r_paren ; tagging = tag_default tags_kw ; tag_default = {explicit} explicit_kw | {implicit} implicit_kw ; module_body = {exports} exports imports? assignment+ | {imports} imports assignment+ | assignment+ ; exports = exports_kw symbol [symbols]:comma_symbol* semi ; imports = imports_kw [imports]:symbols_from_module* semi ; symbols_from_module = symbol [symbols]:comma_symbol* from_kw module_identifier ; comma_symbol = comma symbol ; symbol = {upper} upper | {lower} lower ; assignment = {type} upper assign_op type | {value} lower type assign_op value ; /*= TYPES ===================================================================*/ type = {lower} lower less type | {upper} upper access_type? [subtypes]:subtype_spec* | {null} null_kw [subtypes]:subtype_spec* | {aux_type} aux_type ; access_type = dot upper ; aux_type = {tagged} l_bracket clazz? class_number r_bracket tag_default? type | {built_in} built_in_type [subtypes]:subtype_spec* | {set_of} set_kw of_kw type | {set} set_kw type_suf? | {sequence_of} sequence_kw of_kw type | {sequence} sequence_kw type_suf? ; type_suf = {subtype} [subtypes]:subtype_spec+ | {struct} l_brace element_type [element_types]:comma_element_type* r_brace subtype_spec* | {size} size_kw subtype_spec of_kw type ; comma_element_type = comma element_type ; /*---------------------------------------------------------------------------*/ built_in_type = {boolean} boolean_kw | {integer} integer_kw named_num_lst? | {bit} bit_kw string_kw named_bit_lst? | {octet} octet_kw string_kw | {choice} choice_kw l_brace named_type_list_plus r_brace | {any} any_kw any_suf? | {oid} object_kw identifier_kw | {enum} enumerated_kw named_num_lst | {real} real_kw | {numeric} numeric_string_kw | {printable} printable_string_kw | {teletex} teletex_string_kw | {videotex} videotex_string_kw | {visible} visible_string_kw | {ia5} ia5_string_kw | {graphic} graphic_string_kw | {general} general_string_kw | {universal} universal_string_kw | {bmp} bmp_string_kw | {external} external_kw | {utc} utc_time_kw | {gmt} generalized_time_kw | {object} object_descriptor_kw ; named_num_lst = l_brace named_number [named_numbers]:comma_named_number* r_brace ; comma_named_number = comma named_number ; named_bit_lst = l_brace named_bit [named_bits]:comma_named_bit* r_brace ; comma_named_bit = comma named_bit ; named_type_list_plus = named_type [named_types]:comma_named_type* ; comma_named_type = comma named_type ; any_suf = defined_kw by_kw lower ; /*---------------------------------------------------------------------------*/ named_type = {lower} lower less? type | {upper} upper access_type? [subtypes]:subtype_spec* | {null} null_kw [subtypes]:subtype_spec* | {aux} aux_type ; /*---------------------------------------------------------------------------*/ named_number = lower l_paren aux_named_num r_paren ; aux_named_num = {positive} number | {negative} minus number | {lower} lower | {upper} upper dot lower ; /*---------------------------------------------------------------------------*/ named_bit = lower l_paren class_number r_paren ; /*---------------------------------------------------------------------------*/ element_type = {named} named_type element_type_suf? | {component} components_kw of_kw type ; element_type_suf = {optional} optional_kw | {default} default_kw value ; /*---------------------------------------------------------------------------*/ clazz = {universal} universal_kw | {app} application_kw | {private} private_kw ; class_number = {numeric} number | {lower} lower | {upper} upper dot lower ; /*= VALUES ==================================================================*/ value = {aux} aux_val0 | {upper} upper aux_val1 | {lower} lower aux_val2? | {positive} number | {negative} minus number ; aux_val0 = {built_in} built_in_value | {aux} aux_type colon value | {null} null_kw spec_val? ; aux_val1 = spec_val | {dot} dot aux_val11 ; aux_val2 = {colon} colon value | {less} less type colon value ; aux_val11 = {upper} upper spec_val | {lower} lower ; spec_val = {subtype} [subtypes]:subtype_spec+ colon value | {colon} colon value ; /*---------------------------------------------------------------------------*/ built_in_value = {true} true_kw | {false} false_kw | {max_value} plus_infinity_kw | {min_value} minus_infinity_kw | {based_num} based_num_kw | {string} string_kw | {l_brace} l_brace bet_braces? r_brace ; /*---------------------------------------------------------------------------*/ bet_braces = {aux} aux_val0 aux_named? | {negative} minus number aux_named? | {lower} lower aux_bet1? | {upper} upper aux_bet2 | {positive} number aux_bet3? ; aux_bet1 = {l_paren} l_paren class_number r_paren [oids]:obj_id_component* | {aux_named} aux_named | {aux_val2} aux_val2 aux_named? | {negative} minus number aux_named? | {aux_val0} aux_val0 aux_named? | {lower} lower aux_bet11? | {positive} number aux_bet3? | {upper} upper aux_bet2 ; aux_bet2 = {values} spec_val aux_named? | {dot} dot aux_bet21 ; aux_bet3 = {oid} obj_id_component+ | {aux_named} aux_named ; aux_bet11 = {l_paren} l_paren class_number r_paren [oids]:obj_id_component* | {oid} [oids]:obj_id_component+ | {aux_val2} aux_val2 aux_named? | {aux_named} aux_named ; aux_bet21 = {upper} upper spec_val aux_named? | {lower} lower aux_bet3? ; aux_named = [named_values]:comma_named_value+ ; comma_named_value = comma named_value ; named_value = {lower} lower named_val_suf? | {upper} upper aux_val1 | {positive} number | {negative} minus number | {aux} aux_val0 ; named_val_suf = {value} value | {aux} aux_val2 ; /*= SUBTYPES ================================================================*/ subtype_spec = l_paren subtype_value_set [subtype_value_sets]:bar_subtype_value_set* r_paren ; bar_subtype_value_set = bar subtype_value_set ; subtype_value_set = {include} includes_kw type | {min} min_kw sub_val_set_suf | {from} from_kw subtype_spec | {size} size_kw subtype_spec | {with} with_kw inner_type_suf | {aux} s_v_s_aux ; /*---------------------------------------------------------------------------*/ sub_val_set_suf = {dotdot} dotdot less? upper_end_value | {less} [l1]:less dotdot [l2]:less? upper_end_value ; upper_end_value = {value} value | {max} max_kw ; /*---------------------------------------------------------------------------*/ inner_type_suf = {single} component_kw subtype_spec | {multi} components_kw multiple_type_constraints ; multiple_type_constraints = l_brace ellipsis_comma? named_constraint_list? r_brace ; ellipsis_comma = ellipsis comma ; named_constraint_list = {named} named_constraint [named_constraints]:comma_named_constraint* | {comma} [named_constraints]:comma_named_constraint+ ; comma_named_constraint = comma named_constraint? ; named_constraint = {lower} lower subtype_spec? presence_constraint? | {subtype} subtype_spec presence_constraint? | {presence} presence_constraint ; presence_constraint = {present} present_kw | {absent} absent_kw | {optional} optional_kw ; /*---------------------------------------------------------------------------*/ s_v_s_aux = {built_in} built_in_value sub_val_set_suf? | {aux} aux_type colon s_v_s_aux | {null} null_kw s_v_s_aux3? | {upper} upper s_v_s_aux1 | {lower} lower s_v_s_aux2? | {positive} number sub_val_set_suf? | {negative} minus number sub_val_set_suf? ; s_v_s_aux1 = {subtype} [subtypes]:subtype_spec+ colon s_v_s_aux | {colon} colon s_v_s_aux | {dot} dot s_v_s_aux11 ; s_v_s_aux2 = {colon} colon s_v_s_aux | {dotdot} dotdot less? upper_end_value | {less} less s_v_s_aux21 ; s_v_s_aux3 = {subtype} [subtypes]:subtype_spec+ colon s_v_s_aux | {colon} colon s_v_s_aux | {set} sub_val_set_suf ; s_v_s_aux11 = {upper} upper [subtypes]:subtype_spec* colon s_v_s_aux | {lower} lower sub_val_set_suf? ; s_v_s_aux21 = {type} type colon s_v_s_aux | {dotdot} dotdot less? upper_end_value ; //===========================================================================