java parser generator
home
features
documentation
grammars
downloads
site originally designed by ninth ave
/* 
 * IDL to C++ sytax for SableCC(http://www.sable.mcgill.ca/SableCC/)
 *
 * Authors: Valentin Pavlov (fire@softhome.net)
 *          Ivan Dachev (ivandachev@yahoo.com)
 *
 * Copyright ProSyst GmbH 1999. (http://www.prosyst.com)
 * 
 * Please look at README.TXT for important changes and latest version
 * modifications. The BUGS.TXT contains list of known bugs.
 *
 * This software can be distributed under LGPL.
 * Please send all modifications (if) you made any to authors.
 *
 * Version 1.2
 */

Package com.prosyst.idl2cpp;

/*********************************
* Begin Helpers ******************
*********************************/
Helpers

  ascii_character     = [0..0xff];
  ascii_small         = ['a'..'z'];
  ascii_caps          = ['A'..'Z'];
  unicode_character   = [0..0xffff];

  ht  = 0x09;
  lf  = 0x0a;
  ff  = 0x0c;
  cr  = 0x0d;
  sp  = ' ';

  line_terminator     = lf | cr | cr lf; 
  input_character     = [ascii_character - [cr + lf]];
  uni_input_character = [unicode_character - [cr + lf]];

  not_star            = [input_character - '*'] | line_terminator;
  not_star_not_slash  = [input_character - ['*' + '/']] | line_terminator;

  
  digit               = ['0'..'9'];
  letter              = ascii_small | ascii_caps | '_';
  letter_or_digit     = letter | digit;

  non_zero_digit      = ['1'..'9'];
  hex_digit           = ['0'..'9'] | ['a'..'f'] | ['A'..'F'];
  octal_digit         = ['0'..'7'];
  
  decimal_numeral     = '0' | non_zero_digit digit*;
  hex_numeral         = '0' ('x' | 'X') hex_digit+;
  octal_numeral       = '0' octal_digit+;

  exponent_part       = ('e' | 'E') ('+' | '-')? digit+;

  fixed_type_suffix   = 'd' | 'D';

  single_character    = [input_character - [''' + '\']];
  wide_single_character = [uni_input_character - [''' + '\']];

  octal_escape        = '\' (octal_digit | octal_digit octal_digit | octal_digit octal_digit octal_digit);
  hex_escape          = '\' ('x' | 'X') (hex_digit | hex_digit hex_digit);
  unicode_escape      = '\' ('u' | 'U') (
                          hex_digit | 
                          hex_digit hex_digit |
                          hex_digit hex_digit hex_digit |
                          hex_digit hex_digit hex_digit hex_digit );

  escape_sequence     = '\n' | '\t' | '\v' | '\b' | '\r' | '\f' | '\a' | '\"' | '\' ''' | '\\' |
                          octal_escape | hex_escape | unicode_escape;

  string_character    = [input_character - ['"' + '\']] | escape_sequence;
  wide_string_character = [uni_input_character - ['"' + '\']] | escape_sequence;

  a = 'a' | 'A';
  b = 'b' | 'B';
  c = 'c' | 'C';
  d = 'd' | 'D';
  e = 'e' | 'E';
  f = 'f' | 'F';
  g = 'g' | 'G';
  h = 'h' | 'H';
  i = 'i' | 'I';
  j = 'j' | 'J';
  k = 'k' | 'K';
  l = 'l' | 'L';
  m = 'm' | 'M';
  n = 'n' | 'N';
  o = 'o' | 'O';
  p = 'p' | 'P';
  q = 'q' | 'Q';
  r = 'r' | 'R';
  s = 's' | 'S';
  t = 't' | 'T';
  u = 'u' | 'U';
  v = 'v' | 'V';
  w = 'w' | 'W';
  x = 'x' | 'X';
  y = 'y' | 'Y';
  z = 'z' | 'Z';

/*********************************
* Begin Tokens *******************
*********************************/
Tokens

  /*********************
  * Begin IDL Keywords *
  *********************/
  abstract = a b s t r a c t;
  any = a n y;
  attribute = a t t r i b u t e;
  boolean = b o o l e a n;
  case = c a s e;
  char = c h a r;
  const = c o n s t;
  context = c o n t e x t;
  custom = c u s t o m;
  default = d e f a u l t;
  double = d o u b l e;
  enum = e n u m;
  exception = e x c e p t i o n;
  factory = f a c t o r y;
  false = f a l s e;
  fixed  = f i x e d;
  float = f l o a t;
  in = i n;
  inout = i n o u t;
  interface = i n t e r f a c e;
  long = l o n g;
  module = m o d u l e;
  native = n a t i v e;
  octet = o c t e t;
  object = o b j e c t;
  oneway = o n e w a y;
  out = o u t;
  private = p r i v a t e;
  public = p u b l i c;
  raises = r a i s e s;
  readonly  = r e a d o n l y;
  sequence = s e q u e n c e;
  short = s h o r t;
  string = s t r i n g;
  struct = s t r u c t;
  supports = s u p p o r t s;
  switch = s w i t c h;
  true = t r u e;
  truncatable = t r u n c a t a b l e;
  typedef = t y p e d e f;
  union = u n i o n;
  unsigned = u n s i g n e d;
  valuebase = v a l u e b a s e;
  valuetype = v a l u e t y p e;
  void = v o i d;
  wchar = w c h a r;
  wstring = w s t r i n g;

  /*************************
  * Additional used tokens *
  *************************/
  l_parenthese = '(';
  r_parenthese = ')';
  l_brace = '{';
  r_brace = '}';
  l_bracket = '[';
  r_bracket = ']';
  semicolon = ';';
  comma = ',';
  colon = ':';
  doublecolon = '::';

  assign = '=';
  lt = '<';
  gt = '>';
  tilde = '~';
  plus = '+';
  minus = '-';
  star = '*';
  div = '/';
  bit_and = '&';
  bit_or = '|';
  bit_xor = '^';
  mod = '%';
  shift_left = '<<';
  shift_right = '>>';

  blank = (sp | ht | ff | line_terminator)*;

  traditional_comment = '/*' not_star+ '*'+ (not_star_not_slash not_star* '*'+)* '/';
  documentation_comment =    '/**' '*'* (not_star_not_slash not_star* '*'+)* '/';

  end_of_line_comment = '//' input_character* line_terminator?;

  integer_literal = decimal_numeral |
                          hex_numeral |
                          octal_numeral;

  fixed_pt_literal =
      digit+ '.' digit* fixed_type_suffix |
      '.' digit+ fixed_type_suffix |
      digit+ fixed_type_suffix;

  floating_pt_literal =
      digit+ '.' digit* exponent_part? |
      '.' digit+ exponent_part? |
      digit+ exponent_part;
  

  character_literal = ''' (single_character | escape_sequence) ''';
  wide_character_literal = 'L' ''' (wide_single_character | escape_sequence) ''';

  string_literal = '"' string_character* '"';
  wide_string_literal = 'L' '"' wide_string_character* '"';

  identifier = letter letter_or_digit*;

  directive = ('#pragma' | '#include' | '#ifndef' | '#define' | '#endif' ) input_character* line_terminator;

/*********************************
* Begin Ignored Tokens ***********
*********************************/
Ignored Tokens
  blank, 
  traditional_comment, 
  documentation_comment, 
  end_of_line_comment,
  directive;

/*********************************
* Begin Production ***************
*********************************/
Productions

  specification = definition+;

  definition = 
    {type_dcl}      type_dcl semicolon |
    {const_dcl}     const_dcl semicolon |
    {except_dcl}    except_dcl semicolon |
    {idl_interface} idl_interface semicolon |
    {idl_module}    idl_module semicolon |
    {value}         value semicolon;

  type_dcl = 
    {type_declarator}   type_declarator |
    {struct}            struct_type |
    {union}             union_type |
    {enum}              enum_type |
    {identifier}        native identifier;

  const_dcl = const const_type identifier assign or_expr;

  except_dcl = exception identifier l_brace member* r_brace;

  idl_interface = 
    {interface_dcl} interface_dcl |
    {forward_dcl}   forward_dcl;

  idl_module = module identifier l_brace definition+ r_brace;

  value = 
    {value_dcl}         value_dcl |
    {value_abs_dcl}     value_abs_dcl |
    {value_box_dcl}     value_box_dcl |
    {value_forward_dcl} value_forward_dcl;

  interface_dcl = interface_header l_brace export* r_brace;

  forward_dcl = abstract? interface identifier;

  interface_header = forward_dcl interface_inheritance_spec?;

  export =
    {type_dcl}      type_dcl semicolon |
    {const_dcl}     const_dcl semicolon |
    {except_dcl}    except_dcl semicolon |
    {attr_dcl}      attr_dcl semicolon |
    {op_dcl}        op_dcl semicolon;

  interface_inheritance_spec = colon scoped_name comma_scoped_name*;

  scoped_name =      
        {identifier} doublecolon? identifier |
        {scoped}     scoped_name doublecolon identifier;

  value_forward_dcl = abstract? valuetype identifier semicolon;

  value_box_dcl = valuetype identifier type_spec;

  value_abs_dcl = abstract valuetype identifier value_inheritance_spec? l_brace export* r_brace;
                                                                                                                
  value_dcl = value_header l_brace value_element* r_brace;

  value_header = custom? valuetype identifier value_inheritance_spec?;

  value_inheritance_spec = 
    {nosuport}  colon truncatable? scoped_name comma_scoped_name* |
    {suport}    supports scoped_name comma_scoped_name* |
    {msupport}  colon truncatable? scoped_name comma_scoped_name* supports [support_scoped]:scoped_name [support_comma_support]:comma_scoped_name*;

  value_element =
    {export}        export |
    {state_member}  state_member |
    {init_dcl}      init_dcl;

  state_member = 
        {public}    public type_spec declarators semicolon |
        {private}   private type_spec declarators semicolon;

  init_dcl = factory identifier l_parenthese init_param_decls? r_parenthese semicolon;

  init_param_decls = init_param_decl comma_init_param_decl*; // *; I'think in IDL spec. the star is missing

  init_param_decl = in param_type_spec identifier;

  const_type = 
    {long}              long |
    {short}             short |
    {longlong}          signed_longlong_int |
    {ulong}             unsigned_long_int |
    {ushort}            unsigned_short_int |
    {ulonglong}         unsigned_longlong_int |
    {char}              char |
    {wchar}             wchar |
    {boolean}           boolean |
    {floating_pt_type}  floating_pt_type |
    {string_type}       string_type |
    {wide_string_type}  wide_string_type |
    {fixed}             fixed |
    {scoped_name}       scoped_name |
    {octet}             octet;

  or_expr = 
    {xor_expr}  xor_expr |
    {or}        or_expr bit_or xor_expr;

  xor_expr = 
    {and_expr}  and_expr |
    {xor}       xor_expr bit_xor and_expr;

  and_expr = 
    {shift_expr}    shift_expr |
    {and}           and_expr bit_and shift_expr;

  shift_expr = 
    {add_expr}      add_expr |
    {shift_right}   shift_expr shift_right add_expr |
    {shift_left}    shift_expr shift_left add_expr;

  add_expr = 
    {mult_expr}     mult_expr |
    {plus}          add_expr plus mult_expr |
    {minus}         add_expr minus mult_expr;

  mult_expr =
    {unary_expr}    unary_expr |
    {multiply}      mult_expr star unary_expr |
    {divide}        mult_expr div unary_expr |
    {mod}           mult_expr mod unary_expr;


  unary_expr = 
    {unary_operator}    unary_operator primary_expr |
    {primary_expr}      primary_expr;

  primary_expr =
    {scoped_name}       scoped_name |
    {literal}           literal |
    {or_expr}           l_parenthese or_expr r_parenthese;

  literal =
    {integer}       integer_literal |
    {string}        string_literal |
    {char}          character_literal |
    {float}         floating_pt_literal |
    {boolean}       boolean_literal |
    {wstring}       wide_string_literal |
    {wchar}         wide_character_literal |
    {fixed}         fixed_pt_literal;

  type_spec = 
    {simple_type_spec}    simple_type_spec |
    {constr_type_spec}    constr_type_spec;

  simple_type_spec =
    {base_type_spec}      base_type_spec |
    {template_type_spec}  template_type_spec |
    {scoped_name}         scoped_name;

  base_type_spec =
    {float}         floating_pt_type |
    {long}          long |
    {short}         short |
    {longlong}      signed_longlong_int |
    {ulong}         unsigned_long_int |
    {ushort}        unsigned_short_int |
    {ulonglong}     unsigned_longlong_int |
    {char}          char |
    {wchar}         wchar |
    {boolean}       boolean |
    {octet}         octet |
    {any}           any |
    {object}        object |
    {valuebase}     valuebase;

  template_type_spec =
    {sequence}      sequence_type |
    {string}        string_type |
    {wstring}       wide_string_type |
    {fixed}         fixed_pt_type;

  constr_type_spec =
    {struct}    struct_type |
    {union}     union_type |
    {enum}      enum_type;

  declarators = declarator comma_declarator*;

  declarator = 
    {identifier}        identifier |
    {array_declarator}  array_declarator;

  struct_type = struct identifier l_brace member+ r_brace;

  member = type_spec declarators semicolon;

  union_type = union identifier switch
    l_parenthese switch_type_spec r_parenthese
    l_brace case_body+ r_brace;

  switch_type_spec = 
    {long}      long |
    {short}     short |
    {longlong}  signed_longlong_int |
    {ulong}     unsigned_long_int |
    {ushort}    unsigned_short_int |
    {ulonglong} unsigned_longlong_int |
    {char}      char |
    {boolean}   boolean |
    {enum}      enum_type |
    {scoped}    scoped_name;

  case_body = case_label+ type_spec declarator semicolon;

  case_label = 
    {or_expr} case or_expr colon |
    {default} default colon;

  enum_type = enum [name]:identifier l_brace identifier comma_identifier* r_brace;

  sequence_type = 
    {simple_positive} sequence lt simple_type_spec comma or_expr gt |
    {simple} sequence lt simple_type_spec gt;

  string_type = 
    {positive}    string lt or_expr gt |
    {simple}    string;

  wide_string_type =
    {positive} wstring lt or_expr gt |
    {simple} wstring;

  array_declarator = identifier fixed_array_size+;

  fixed_array_size = l_bracket or_expr r_bracket;

  attr_dcl = readonly? attribute param_type_spec identifier comma_identifier*;

  op_dcl = oneway? op_type_spec identifier parameter_dcls raises_expr? context_expr?;

  op_type_spec = 
    {param_type_spec} param_type_spec |
    {void} void;

  parameter_dcls = 
    {param_dcl} l_parenthese param_dcl comma_param_dcl* r_parenthese |
    {empty} l_parenthese r_parenthese;

  param_dcl = param_attribute param_type_spec identifier;

  raises_expr = raises l_parenthese scoped_name comma_scoped_name* r_parenthese;

  context_expr = context l_parenthese string_literal comma_string_literal* r_parenthese;

  param_type_spec = 
                    {base} base_type_spec |
                    {string} string_type |
                    {wide} wide_string_type |
                    {scoped} scoped_name;

  fixed_pt_type =   fixed lt [first]:or_expr comma [exponent]:or_expr gt;

  unary_operator =
    {minus}         minus |
    {plus}          plus |
    {tilde}         tilde;

  boolean_literal = 
    {true}          true |
    {false}         false;

  param_attribute = 
    {in}            in |
    {out}           out |
    {inout}         inout;

  floating_pt_type =
    {float}         float |
    {double}        double |
    {lond_double}   long double;

  unsigned_short_int = unsigned short;
  
  unsigned_long_int = unsigned long;
  
  unsigned_longlong_int = unsigned [left]:long [right]:long;

  signed_longlong_int = [left]:long [right]:long;

  comma_scoped_name = comma scoped_name;
  
  comma_identifier = comma identifier;

  comma_param_dcl = comma param_dcl;

  comma_declarator = comma declarator;

  comma_init_param_decl = comma init_param_decl;

  comma_string_literal = comma string_literal;

  type_declarator = typedef type_spec declarators;

This site has been last updated by the web master on 2007/6/24.