Usenet.com

www.Usenet.com

Group Index

Comp Thread Archive from Usenet.com

<-- __Chronological__ --> <-- __Thread__ -->

Re: grammar for corba/idl 2.3



[EMAIL PROTECTED] (dan kuwachi) wrote in message news:<[EMAIL PROTECTED]>...
> hi,
> 
> I was wondering if there is a corba 2.3 grammar for javacc.  It seems
> a little odd around a year has passed and there isn't one floating on
> the web.  There are quite a few changes from the corba 2.0 grammar to
> the 2.3 grammar, so any help would be greatly appreciated.
> 
> -dan

Below is part of our TermWare toolkit.
(http://www.gradsoft.com.ua/products/termware_eng.html)

You can strip term construction and receiving clear ILD-2.3 grammar.
(Or may-be just use termware tree representation).

Note, that for clear IDL processing you also need C preprocessor.
(we wrote own in java).

Don't hasinate call me directly with any questions.

Regards !
------------------------------------------------------
PARSER_BEGIN(IDLParser)

package ua.kiev.gradsoft.TermWare.parsers.idl;

import java.io.*;
import ua.kiev.gradsoft.TermWare.*;
import ua.kiev.gradsoft.TermWare.exceptions.*;

import ua.kiev.gradsoft.TermWare.parsers.utils.*;


public class IDLParser {

  public static IDLParser create(InputStream in, ITerm args)
  {
   // TODO: parse args.
   IDLParser retval = new IDLParser(in);
   return retval;
  }


  public static void main(String args[]) {
    IDLParser parser;
    if (args.length == 0) {
      parser = new IDLParser(System.in);
    } else if (args.length == 1) {
      try {
        parser = new IDLParser(new java.io.FileInputStream(args[0]));
      } catch (java.io.FileNotFoundException e) {
        System.out.println("IDL Parser:  File " + args[0] + " not
found.");
        return;
      }
    } else {
      System.out.println("TermWare IDL Parser usage:");
      System.out.println("java
ua.kiev.gradsoft.TermWare.parsers.IDL.IDLParser < inputfile");
      System.out.println("OR");
      System.out.println("java
ua.kiev.gradsoft.TermWare.parsers.IDL.IDLParser inputfile");
      return;
    }
    try {
      ITerm t=parser.specification();
      t.print(System.out);
    } catch (ParseException e) {
      System.out.println("TermWare IDL Parser: "+e.getMessage());
    } catch (TermWareException e){
      System.out.println("TermWare IDL Parser: "+e.getMessage());
    }
  }

  public ITerm readTerm() throws TermWareException
  {
   synchronized(globalLock_) {
   try {
     ITerm t=specification();
     eof_=true;  /* while eof = true: becouse in specifications() we
read all*/
     return t;
   }catch(ParseException ex){
     throw new TermWareParseException(ex.getMessage());
   }
   }
  }

  public boolean eof()
   { return eof_; }

  private static final ITerm cons(ITerm x, ITerm y) throws
TermWareException
  {
    return ITermFactory.createComplexTerm2("cons",x,y);
  }

  /*
   * cons(cons(x,y))->cons(x,cons(x,y));
   */
  private static final ITerm ncons(ITerm x) throws TermWareException
  {
   if (x.isComplexTerm() && x.getName().equals("cons")) {
     ITerm frs=x.getSubtermAt(0);
     ITerm snd=x.getSubtermAt(1);
     if (frs.isComplexTerm() && frs.getName().equals("cons")) {
       ITerm frs_frs=frs.getSubtermAt(0);
       ITerm frs_snd=frs.getSubtermAt(1);
       return ncons(frs_frs,cons(frs_snd,snd));
     }else{
       return x;
     }
   }else{
     return x;
   }
  }

  /*
   * cons(cons(x,y))->cons(x,cons(x,y));
   */
  private static final ITerm ncons(ITerm x, ITerm y) throws
TermWareException
  {
   if (x.isComplexTerm() && x.getName().equals("cons")) {
     ITerm frs=x.getSubtermAt(0);
     ITerm snd=x.getSubtermAt(1);
     return ncons(frs,cons(snd,y));
   }else{
     return cons(x,y);
   }
  }
  

  private boolean eof_=false;

  /**
   * global lock: current behaviour of IDLParser is near static,
   * becouse we have line number information in CPPP output, which is
   * readed by lexer which is not know about parser.
   * Sutuation will be changed afer open-source version of JavaCC.
   **/
  private static Object globalLock_=new Object();

}

PARSER_END(IDLParser)


/*
 * Tokens to ignore in the BNF follow.
 */

SKIP :
{
  < " " >
| < "\t" >
| < "\n" >
| < "\r" >
| < "//" (~["\n"])* "\n" >
| <"/*" (~["*"])* "*" (~["/"] (~["*"])* "*")* "/">
| < "#" ([" ","\t"])* (["0"-"9"])+
    (([" ","\t"])* "\"" (~["\""])+ "\""
           ([" ","\t"])* (["0"-"9"])* ([" ","\t"])* (["0"-"9"])*)?
"\n" >
| < "#" ([" ","\t"])* (["0"-"9"])+
    (([" ","\t"])* "\"" (~["\""])+ "\"") >
}

/* Production 1 */

ITerm specification() throws TermWareException :
{
ITerm specification=null;
ITerm definition=null;
}
{
  ( definition=definition() 
    { if (specification==null) { 
       specification=definition;
      }else{
       specification=cons(specification,definition);
      }
    }
  )+
  { return ncons(specification); }
}

/* Production 2 */

ITerm definition() throws TermWareException :
{
 ITerm retval;
}
{
  retval=type_dcl() ";"
   { return retval; }
|
  retval=const_dcl() ";"
    { return retval; }
|
  retval=except_dcl() ";"
    { return retval; }
|
 LOOKAHEAD(2)
  retval=interfacex() ";"
    { return retval; }
|
  retval=module() ";"
    { return retval; }
|
  retval=value() ";"
    { return retval; }
}

/* Production 3 */

ITerm module() throws TermWareException :
{
  ITerm definition = null;
  ITerm module=null;
  ITerm t=null;
  ITerm name=null;
}
{
  "module" name=identifier() "{" ( t=definition() 
                              { if (definition==null) {
                                    definition=t;
                                }else{
                                    definition=cons(definition,t);
                                }
                              }
                            )+ "}"
  { 
    if (definition==null) {
      definition=ITermFactory.createAtom("idl_empty_definition");
    }
    module=ITermFactory.createComplexTerm2("idl_module",name,ncons(definition));
    return module;
  }
}

/* Production 4 */

ITerm interfacex() throws TermWareException :
{
 ITerm retval;
}
{
  LOOKAHEAD(3)
  retval=interface_dcl()
   { return retval; }
|
  retval=forward_dcl()
   { return retval; }
}

/* Production 5 */

ITerm interface_dcl() throws TermWareException :
{
 ITerm body;
 ITerm header;
}
{
  header=interface_header() "{" body=interface_body() "}"
  {
   return ITermFactory.createComplexTerm2("idl_interface_dcl",header,body);
  }
}

/* Production 6 */

ITerm forward_dcl() throws TermWareException :
{
  ITerm name;
  boolean isAbstract=false;
  boolean isLocal=false;
}
{
  [ ("abstract" )
     {isAbstract=true;}
    | 
    ( "local" )
     {isLocal=true; } 
  ] "interface" name=identifier()
  {
   ITerm attributes;
   if (isAbstract==false && isLocal==false) {
    attributes=ITermFactory.createComplexTerm0("set");
   }else if (isAbstract==false && isLocal==true) {
    
attributes=ITermFactory.createComplexTerm1("set",ITermFactory.createAtom("idl_local"));
   }else if (isAbstract==true && isLocal==false) {
    
attributes=ITermFactory.createComplexTerm1("set",ITermFactory.createAtom("idl_abstract"));
   }else{
    attributes=ITermFactory.createComplexTerm2("set",
                                 
ITermFactory.createAtom("idl_abstract"),
                                  ITermFactory.createAtom("idl_local")
                                 );
   }   
   return ITermFactory.createComplexTerm2("idl_forward_dcl",attributes,name);
  }  
}

/* Production 7 */

ITerm interface_header() throws TermWareException :
{
 ITerm name=null;
 ITerm t=null;
 boolean isAbstract=false;
 boolean isLocal=false;
}
{
  [ "abstract"
    { isAbstract=true; }
    | "local" 
    { isLocal=true; }
  ] "interface" name=identifier() [ t=inheritance_spec() ]
  {
   ITerm attributes;
   if (isAbstract==false && isLocal==false) {
    attributes=ITermFactory.createComplexTerm0("set");
   }else if (isAbstract==false && isLocal==true) {
    
attributes=ITermFactory.createComplexTerm1("set",ITermFactory.createAtom("idl_local"));
   }else if (isAbstract==true && isLocal==false) {
    
attributes=ITermFactory.createComplexTerm1("set",ITermFactory.createAtom("idl_abstract"));
   }else{
    attributes=ITermFactory.createComplexTerm2("set",
                                 
ITermFactory.createAtom("idl_abstract"),
                                  ITermFactory.createAtom("idl_local")
                                 );
   }  
   ITerm inheritance_spec_term; 
   if (t==null) {
     inheritance_spec_term=ITermFactory.createComplexTerm0("set"); 
   }else{
     inheritance_spec_term=t;
   }
   return ITermFactory.createComplexTerm3("interface_header",
                                          name,
                                          attributes,
                                          inheritance_spec_term
                                         );
  }
}

/* Production 8 */

ITerm interface_body() throws TermWareException :
{
 ITerm t1=null;
 ITerm t2=null;
}
{
  ( t1=export() 
    { if (t2==null) t2=t1; 
      else t2=cons(t1,t2);
    }
  )*
  { return t2; }
}

/* Production 9 */

ITerm export() throws TermWareException :
{
  ITerm t;
}
{
  t=type_dcl() ";"
   { return t; }
|
  t=const_dcl() ";"
   { return t; }
|
  t=except_dcl() ";"
   { return t; }
|
  t=attr_dcl() ";"
   { return t; }
|
  t=op_dcl() ";"
   { return t; }
}

/* Production 10 */

/**
 * return set(x .. )
 **/
ITerm inheritance_spec() throws TermWareException :
{
  ITerm t1=null;
  ITerm t2=null;
  ITerm s=ITermFactory.createComplexTerm0("set");
}
{
  ":" t1=scoped_name() ( "," t2=scoped_name() 
                           { TermHelper.insert(s,t2); }
                       )*
  { TermHelper.insert(s,t1); return s; }

}

/* Production 11  in 2.6 */
ITerm interface_name() throws TermWareException :
{
 ITerm t;
}
{
 t=scoped_name()
  { return t; }
}


/* Production 11 in 2.0, 12 in 2.6 */

ITerm scoped_name() throws TermWareException :
{
 boolean scope=false;
 ITerm t1=null;
 ITerm t2=null;
 ITerm t3=null;
}
{
  [ "::" { scope=true; } ] t1=identifier() ( "::" t2=identifier() 
                                            { if (t3==null) t3=t2;
                                              else {
                                               
t3=ITermFactory.createComplexTerm2("cons",t2,t3);
                                              }
                                            }
                                           )*
  {
   ITerm retval;
   if (t2==null) {
     if (scope) {
       retval=ITermFactory.createComplexTerm2("cons",ITermFactory.createAtom("::"),t1);
     }else{
       retval=t1;
     }
   }else{
     t3=ITermFactory.createComplexTerm2("cons",t1,t3);
     if (scope) {
       retval=ITermFactory.createComplexTerm2("cons",ITermFactory.createAtom("::"),t3);
     }else{
       retval=t3;
     }     
   }
   return retval;
  }
}

/* Production 12 */

ITerm const_dcl() throws TermWareException :
{
  ITerm t1=null;
  ITerm t2=null;
  ITerm t3=null;
}
{
  "const" t1=const_type() t2=identifier() "=" t3=const_exp()
  { return ITermFactory.createComplexTerm3("idl_const_dcl",t2,t1,t3);
}
}

/* Production 13 in 2.6 */
ITerm value() throws TermWareException :
{
 ITerm t;
}
{
 LOOKAHEAD(3)
 t=value_dcl()
   { return t; }
 |
 LOOKAHEAD(3)
 t=value_abs_dcl()
   { return t; }
 |
 LOOKAHEAD(2)
 t=value_box_dcl()
   { return t; }
 |
 t=value_forward_dcl()
   { return t; }
}

/* Production 14 in 2.6 */

ITerm value_forward_dcl() throws TermWareException :
{
 boolean isAbstract=false; 
 ITerm idt;
}
{
 [ ( "abstract" ) { isAbstract=true; } ] "valuetype" idt=identifier()
 {
  return ITermFactory.createComplexTerm2("idl_value_forward_dcl",
                                     
ITermFactory.createBoolean(isAbstract),
                                      idt);
 }
}

/* Production 15 in 2.6 */

ITerm value_box_dcl() throws TermWareException :
{
 ITerm t1=null;
 ITerm t2=null;
}
{
 "valuetype" t1=identifier() t2=type_spec() 
  { return ITermFactory.createComplexTerm2("idl_value_box_dcl", t1,
t2); }
}

/* Production 16 in 2.6 */
ITerm value_abs_dcl() throws TermWareException :
{
 ITerm t1=null;
 ITerm t2=null;
 ITerm t4=null;
 ITerm export_seq=null;
}
{
 "abstract" "valuetype" t1=identifier() 
      t2=value_inheritance_spec()   
     "{" 
       ( (t4=export())*
         { if (export_seq==null) 
            export_seq=t4;
           else 
            export_seq=ITermFactory.createComplexTerm2("cons",export_seq,t4);
          }
        )
      "}"
 { 
   if (t2==null) t2=ITermFactory.createAtom("idl_empty_value_inherience_spec");
   if (export_seq==null) 
        export_seq=ITermFactory.createAtom("idl_empty_export");
   return ITermFactory.createComplexTerm3("idl_value_abs_dcl", t1, t2,
                                           export_seq); 
 }
}

/* Production 17 in 2.6 */
ITerm value_dcl() throws TermWareException :
{
 ITerm t1=null;
 ITerm t2=null;
 ITerm t3=null;
}
{
 t1=value_header() "{" 
             ( (t3=value_element())*
               { if (t2==null) t2=t3; else t2=cons(t3,t2); }
             )
                   "}"
 { return ITermFactory.createComplexTerm2("idl_value_dcl",t1,t2); }
}

/* Production 18 in 2.6 */
ITerm value_header() throws TermWareException :
{
 boolean isCustom=false;
 ITerm   t1=null;
 ITerm   t2=null;
}
{
 (
 [ ("custom") {isCustom=true;} ] "valuetype" t1=identifier()
   t2=value_inheritance_spec()
 )
 {
  if (t2==null) t2=ITermFactory.createAtom("idl_empty_inheritance_spec");
  return ITermFactory.createComplexTerm2("idl_value_header", t1,t2);
 } 
}

/* Production 19 in 2.6 */
ITerm value_inheritance_spec() throws TermWareException :
{
 ITerm t1=null;
 ITerm t2=null; // tmp;
 ITerm t3=null;
 ITerm t4=null;
 ITerm t5=null; // tmp
 ITerm t6=null;
 boolean isTrancatable=false;
}
{
 (
 [ ":" [( ("truncatable") { isTrancatable=true; } )]
        t1=value_name()
         ( "," t2=value_name() 
               { if (t3==null) t3=t2; else t3=cons(t3,t2); }
         ) * 
 ]
 [ "supports" t4=interface_name() ( "," t5=interface_name() 
                                    { if (t6==null) t6=t5; else
cons(t6,t5); }
                                  )*
 ] 
 )
 {
  ITerm tr=ITermFactory.createBoolean(isTrancatable);
  ITerm tt1=null;
  ITerm tt2=null;
  if (t1==null) tt1=ITermFactory.createAtom("empty");
  else if (t2==null) {
   tt1=ITermFactory.createComplexTerm2("idl_value_value_inheritance_spec",
                                        tr,t1);
  }else {
   tt1=ITermFactory.createComplexTerm2("idl_value_value_inheritance_spec",
                                        tr,cons(t1,ncons(t2)));
  }
  if (t4==null) tt2=ITermFactory.createAtom("empty");
  else if(t5==null) {
    tt2=t4;
  }else{
    tt2=cons(t4,ncons(t6));
  }
  return ITermFactory.createComplexTerm2("idl_value_inheritance_spec",tt1,tt2);
 }
}

/* Production 20 in 2.6 */
ITerm value_name() throws TermWareException :
{
 ITerm t;
}
{
 t=scoped_name()
  { return t; }
}

/* Production 21 in 2.6 */
ITerm value_element() throws TermWareException :
{
 ITerm t;
}
{
 t=export()
  { return t; }
 |
 t=state_member()
  { return t; }
 |
 t=init_dcl()
  { return t; }
}

/* Production 22 in 2.6 */
ITerm state_member() throws TermWareException :
{
 ITerm t1;
 ITerm t2;
 boolean isPublic=false;
}
{
  ( ("public") { isPublic=true; } | "private" )
     t1=type_spec() t2=declarators() ";" 
  {
   ITerm at=ITermFactory.createAtom(isPublic ? "public" : "private");
   ITerm retval=ITermFactory.createComplexTerm3("idl_state_member",at,t1,t2);
   return retval;
  }
}


/* Production 23 in 2.6 */
ITerm init_dcl() throws TermWareException :
{
 ITerm t1=null;
 ITerm t2=null;
}
{
 "factory" t1=identifier() "(" [ t2=init_param_decls() ] ")" ";"
 {
  if (t2==null) t2=ITermFactory.createAtom("idl_empty_init_param_decls");
  return ITermFactory.createComplexTerm2("idl_init_dcl",t1,t2);
 }
}

/* Production 24 in 2.6 */
ITerm init_param_decls() throws TermWareException :
{
 ITerm t1=null;
 ITerm t2=null;
 ITerm t3=null;
}
{
 t1=init_param_decl() ( "," t2=init_param_decl() 
                           { if (t3==null) t3=t2; else t3=cons(t3,t2);
}
                      )*
 {
  if (t3==null) return t1; else return cons(t1,t2);
 }
}

/* Production 25 in 2.6 */
ITerm init_param_decl() throws TermWareException :
{
 ITerm t1=null;
 ITerm t2=null;
 ITerm t3=null;
}
{
 t1=init_param_attribute() t2=param_type_spec() t3=simple_declarator()
 {
  return ITermFactory.createComplexTerm3("idl_init_param_decl",t1,t2,t3);
 }
}

ITerm init_param_attribute() throws TermWareException :
{
}
{
 "in"
 { return ITermFactory.createAtom("in"); }
}

/* Production 13 in 2.0 */

ITerm const_type() throws TermWareException :
{
 ITerm t;
}
{
(
  t=integer_type()
|
  t=char_type()
|
  t=wide_char_type()
|
  t=boolean_type()
|
  t=floating_pt_type()
|
  t=string_type()
|
  t=wide_string_type()
|
  t=fixed_pt_const_type()
|
  t=scoped_name()
)
 { return t; }
}

/* Production 14 */

ITerm  const_exp() throws TermWareException :
{
 ITerm t;
}
{
  t=or_expr()
   { return t; }
}

/* Production 15 */

ITerm or_expr() throws TermWareException :
{
 ITerm t1=null;
 ITerm t2=null;
 ITerm t3=null; 
}
{
  t1=xor_expr() ( "|" t2=xor_expr()
             {
              if (t3==null) t3=t2;
              else t3=ITermFactory.createComplexTerm2("idl_or_expr",t2,t3);
             }
             )*
 {
  if (t2==null) return t1;
  else{
   return t3=ITermFactory.createComplexTerm2("idl_or_expr",t1,t3);
  }
 }
}

/* Production 16 */

ITerm xor_expr() throws TermWareException :
{
 ITerm t1=null;
 ITerm t2=null;
 ITerm t3=null; 
}
{
  t1=and_expr() ( "^" t2=and_expr() 
             {
              if (t3==null) t3=t2;
              else t3=ITermFactory.createComplexTerm2("idl_xor_expr",t2,t3);
             }
  )*
 {
  if (t2==null) return t1;
  else{
   return ITermFactory.createComplexTerm2("idl_xor_expr",t1,t3);
  }
 }
}

/* Production 17 */

ITerm and_expr() throws TermWareException :
{
 ITerm t1=null;
 ITerm t2=null;
 ITerm t3=null; 
}
{
  shift_expr() ( "&" shift_expr() 
             {
              if (t3==null) t3=t2;
              else t3=ITermFactory.createComplexTerm2("idl_and_expr",t2,t3);
             }
               )*
 {
  if (t2==null) return t1;
  else{
   return ITermFactory.createComplexTerm2("idl_and_expr",t1,t3);
  }
 }

}

/* Production 18 */

ITerm shift_expr() throws TermWareException :
{
 String op=null;
 ITerm t1=null;
 ITerm t2=null;
 ITerm t3=null; 
}
{
  t1=add_expr() ( (
                   ( ">>" { op="idl_right_shift"; } | 
                    "<<" { op="idl_left_shift"; } 
                   ) t2=add_expr() )
             {
              if (t3==null) t3=ITermFactory.createComplexTerm1(op,t2);
              else {
                t3=ITermFactory.createComplexTerm2(t3.getName(),t2,t3.getSubtermAt(0));
                t3=ITermFactory.createComplexTerm1(op,t3);
              } 
             }
             )*
 {
  if (t2==null) {
    return t1;
  }else{
    return ITermFactory.createComplexTerm2(t3.getName(),t1,t3.getSubtermAt(0));
  }
 }
}

/* Production 19 */

ITerm add_expr() throws TermWareException :
{
 String op=null;
 ITerm t1=null;
 ITerm t2=null;
 ITerm t3=null; 
}
{
  t1=mult_expr() ( (( "+" { op="idl_plus"; } | "-" { op="idl_minus"; }
)
                   t2=mult_expr())
             {
              if (t3==null) t3=ITermFactory.createComplexTerm1(op,t2);
              else {
                t3=ITermFactory.createComplexTerm2(t3.getName(),t2,t3.getSubtermAt(0));
                t3=ITermFactory.createComplexTerm1(op,t3);
              } 
             }
               )*
 {
  if (t2==null) {
    return t1;
  }else{
    return ITermFactory.createComplexTerm2(t3.getName(),t1,t3.getSubtermAt(0));
  }
 }
}

/* Production 20 */

ITerm mult_expr() throws TermWareException :
{
 String op=null;
 ITerm t1=null;
 ITerm t2=null;
 ITerm t3=null; 
}
{
  t1=unary_expr() ( (( "*" { op="idl_multiply"; } | 
                    "/" { op="idl_divide"; } | 
                    "%" { op="idl_mod"; } ) t2=unary_expr()
                  )
             {
              if (t3==null) t3=ITermFactory.createComplexTerm1(op,t2);
              else {
                t3=ITermFactory.createComplexTerm2(t3.getName(),t2,t3.getSubtermAt(0));
                t3=ITermFactory.createComplexTerm1(op,t3);
              } 
             }
                )*
 {
  if (t2==null) {
    return t1;
  }else{
    return ITermFactory.createComplexTerm2(t3.getName(),t1,t3.getSubtermAt(0));
  }
 }
}

/* Production 21 */

ITerm unary_expr() throws TermWareException :
{
 String op=null;
 ITerm t=null;
}
{
  [ op=unary_operator() ] t=primary_expr()

  {
   if (op==null) return t;
   else {
     return ITermFactory.createComplexTerm1(op,t);
   }
  }

}

/* Production 22 */
String unary_operator() :
{}
{
  "-" { return "idl_minus"; }
|
  "+" { return "idl_plus"; }
|
  "~" { return "idl_negate"; }
}

/* Production 23 */

ITerm primary_expr() throws TermWareException :
{
 ITerm t;
}
{
  t=scoped_name()
   { return t; }
|
  t=literal()
   { return t; }
|
  "(" t=const_exp() ")"
   { return t; }
}

/* Production 24 */

ITerm literal() throws TermWareException :
{
 ITerm t;
}
{
  t=integer_literal()  { return t; }
|
  t=string_literal()   { return t; }
|
  t=character_literal() { return t; }
|
  t=floating_pt_literal() { return t; }
|
  t=boolean_literal() { return t; }
}

/* Production 25 */

ITerm boolean_literal() :
{
}
{
  "TRUE"
  { return ITermFactory.createBoolean(true); }
|
  "FALSE"
  { return ITermFactory.createBoolean(false); }
}

/* Production 26 */

ITerm positive_int_const() throws TermWareException :
{
 ITerm t;
}
{
  t=const_exp()
   { return t; }
}

/* Production 27 */

ITerm type_dcl() throws TermWareException :
{
 ITerm t;
}
{
  "typedef" t=type_declarator()
   { return t; }
|
 LOOKAHEAD(3)
  t=struct_type()
   { return t; }
|
 LOOKAHEAD(3)
  t=union_type()
   { return t; }
|
  t=enum_type()
   { return t; }
|
  "native" t=simple_declarator()
  { return ITermFactory.createComplexTerm1("native",t); }
|
  t=constr_forward_decl()
  { return t; }
}

/* Production 28 */

ITerm type_declarator() throws TermWareException :
{
 ITerm t1;
 ITerm t2;
}
{
  t1=type_spec() t2=declarators()
  { return ITermFactory.createComplexTerm2("idl_type_declarator",t1,t2);
}
}

/* Production 29 */

ITerm type_spec() throws TermWareException :
{
 ITerm t;
}
{
  t=simple_type_spec()
   { return t; }
|
  t=constr_type_spec()
   { return t; }
}

/* Production 30 */

ITerm simple_type_spec() throws TermWareException :
{
 ITerm t;
}
{
  t=base_type_spec()
   { return t; }
|
  t=template_type_spec()
   { return t; }
|
  t=scoped_name()
   { return t; }
}

/* Production 31 in 2.0, 46 in 2.6 */

ITerm base_type_spec() :
{
 ITerm t;
}
{
  t=floating_pt_type()
   { return t; }
|
  t=integer_type()
   { return t; }
|
  t=char_type()
   { return t; }
|
  t=wide_char_type()
   { return t; }
|
  t=boolean_type()
   { return t; }
|
  t=octet_type()
   { return t; }
|
  t=any_type()
   { return t; }
|
  t=object_type()
   { return t; }
|
  t=value_base_type()
   { return t; }
}

/* Production 32 */

ITerm template_type_spec() throws TermWareException :
{
 ITerm t;
}
{
  t=sequence_type()
   { return t; }
|
  t=string_type()
   { return t; }
|
  t=wide_string_type()
   { return t; }
}

/* Production 33 */

ITerm constr_type_spec() throws TermWareException :
{
 ITerm t;
}
{
  t=struct_type()
   { return t; }
|
  t=union_type()
   { return t; }
|
  t=enum_type()
   { return t; }
}

/* Production 34 */

ITerm declarators() throws TermWareException  :
{
 ITerm t1=null;
 ITerm t2=null;
 ITerm t3=null;
}
{
  t1=declarator() ( "," t2=declarator()
                {
                 if (t3==null) t3=t2;
                 else
t3=ITermFactory.createComplexTerm2("cons",t3,t2);
                } 
               )*
 {
  if (t2==null) {
    return ITermFactory.createComplexTerm1("idl_declarators",t1);
  } else {
    t3=ITermFactory.createComplexTerm2("cons",t1,t3);
    return ITermFactory.createComplexTerm1("idl_declarators",t3);    
  }
 }
}

/* Production 35 */

ITerm declarator() throws TermWareException :
{
 ITerm t;
}
{
  LOOKAHEAD(2)
  t=complex_declarator()
   { return t; }
 |
  t=simple_declarator()
   { return t; }
}

/* Production 36 */

ITerm simple_declarator() throws TermWareException :
{
 ITerm t;
}
{
  t=identifier()
   { return t; }
}

/* Production 37 */

ITerm complex_declarator() throws TermWareException :
{
 ITerm t;
}
{
  t=array_declarator()
   { return t; }
}

/* Production 38 */

ITerm floating_pt_type() :
{}
{
  "float"
  { return ITermFactory.createAtom("idl_float"); }
|
  "double"
  { return ITermFactory.createAtom("idl_double"); }
}

/* Production 39 */

ITerm integer_type() :
{
ITerm t;
}
{
  t=signed_int()
   { return t; }
|
  t=unsigned_int()
   { return t; }
}

/* Production 40 */

ITerm signed_int() :
{
 ITerm t;
}
{
  t=signed_long_int()
   { return t; }
|
  t=signed_short_int()
   { return t; }
}

/* Production 41 */

ITerm signed_long_int() :
{
}
{
  "long"
  { return ITermFactory.createAtom("idl_long"); }
}

/* Production 42 */

ITerm signed_short_int() :
{}
{
  "short"
  { return ITermFactory.createAtom("idl_short"); }
}

/* Production 43 */

ITerm unsigned_int() :
{
 ITerm t;
}
{
  LOOKAHEAD(2)
  t=unsigned_long_int()
   { return t; }
|
  t=unsigned_short_int()
   { return t; }
}

/* Production 44 */

ITerm unsigned_long_int() :
{}
{
  "unsigned" "long"
  { return ITermFactory.createAtom("idl_unsigned_long"); }
}

/* Production 45 */

ITerm unsigned_short_int() :
{}
{
  "unsigned" "short"
  { return ITermFactory.createAtom("idl_unsigned_short"); }
}

/* Production 46 */

ITerm char_type() :
{}
{
  "char"
  { return ITermFactory.createAtom("idl_char"); }
}

ITerm wide_char_type() :
{}
{
  "wchar"
  { return ITermFactory.createAtom("idl_wchar"); }
}


/* Production 47 */

ITerm boolean_type() :
{}
{
  "boolean"
  { return ITermFactory.createAtom("idl_boolean"); }
}

/* Production 48 */

ITerm octet_type() :
{}
{
  "octet"
  { return ITermFactory.createAtom("idl_octet"); }
}

/* Production 49 in 2.0, 68 in 2.6*/
ITerm any_type() :
{}
{
  "any"
 { return ITermFactory.createAtom("idl_any"); }
}

/* Production 69 in 2.6 */
ITerm object_type() :
{}
{
  "Object"
 { return ITermFactory.createAtom("idl_object"); }
}

/* Production 50 */

ITerm struct_type() throws TermWareException :
{
 ITerm t1=null;
 ITerm t2=null;
}
{
  "struct" t1=identifier() "{" t2=member_list() "}"
  { return ITermFactory.createComplexTerm2("idl_struct",t1,t2); }
}

/* Production 51 */

ITerm member_list() throws TermWareException :
{
 ITerm t1=null;
 ITerm t2=null; 
}
{
  ( t1=member() 
    { if (t2==null) t2=t1;
      else t2=ITermFactory.createComplexTerm2("cons",t1,t2);
    }
  )+
 {
  return t2;
 }
}

/* Production 52 */

ITerm member() throws TermWareException :
{
 ITerm t1=null;
 ITerm t2=null;
}
{
  t1=type_spec() t2=declarators() ";"
  { return ITermFactory.createComplexTerm2("idl_member",t1,t2); }
}

/* Production 53 */

ITerm union_type() throws TermWareException :
{
 ITerm t1=null;
 ITerm t2=null;
 ITerm t3=null;
}
{
  "union" t1=identifier() "switch" "(" t2=switch_type_spec() ")" "{"
t3=switch_body() "}"
  {
   return ITermFactory.createComplexTerm3("idl_union", t1, t2, t3);
  }
}

/* Production 54 */

ITerm switch_type_spec() throws TermWareException :
{
 ITerm t;
}
{
  t=integer_type()
   { return t; }
|
  t=char_type()
   { return t; }
|
  t=boolean_type()
   { return t; }
|
  t=enum_type()
   { return t; }
|
  t=scoped_name()
   { return t; }
}

/* Production 55 */

ITerm switch_body() throws TermWareException :
{
 ITerm t1=null;
 ITerm t2=null;
}
{
  ( t1=casex() 
    { if (t2==null) {
        t2=t1;
      }else{
        t2=ITermFactory.createComplexTerm2("cons",t1,t2);
      }
    }
  )+
  { return t2; }
}

/* Production 56 */

ITerm casex() throws TermWareException :
{
 ITerm t1=null;
 ITerm t2=null;
 ITerm t3=null;
}
{    
  ( t1=case_label() 
    { if (t3==null) t3=t2;
      else t3=cons(t1,t2);
    }
  )+ t2=element_spec() ";"
  { return ITermFactory.createComplexTerm2("idl_casex", t3,t2); }
}

/* Production 57 */

ITerm case_label() throws TermWareException :
{
 ITerm t1;
}
{
  "case" t1=const_exp() ":"
    { return ITermFactory.createComplexTerm1("idl_case_label",t1); }
|
  "default" ":"
   { return ITermFactory.createComplexTerm0("idl_default"); }
}

/* Production 58 */

ITerm element_spec() throws TermWareException :
{
 ITerm t1;
 ITerm t2;
}
{
  t1=type_spec() t2=declarator()
  { return ITermFactory.createComplexTerm2("idl_element_spec",t1,t2);
}
}

/* Production 59 */

ITerm enum_type() throws TermWareException :
{
 ITerm t1=null;
 ITerm t2=null;
 ITerm t3=null;
 ITerm t4=null;
 ITerm t5=null;
}
{
  "enum" t1=identifier() "{" (t2=enumerator() ( 
                                "," t3=enumerator() 
                                { if (t4==null) t4=t3;
                                  else t4=cons(t3,t4); }
                              )*
                             )
                             { 
                              if (t4==null) {
                               t5=t2;
                              }else{
                               t5=cons(t2,t4);
                              }
                             }
                         "}"
  { return ITermFactory.createComplexTerm2("idl_enum",t1,t5); }
}

/* Production 60 */

ITerm enumerator() throws TermWareException :
{
 ITerm t;
}
{
  t=identifier()
  { return t; }
}

/* Production 61 */

ITerm sequence_type() throws TermWareException  :
{
 ITerm n=null;
 ITerm t=null;
}
{
  "sequence" "<" t=simple_type_spec() [ "," n=positive_int_const() ]
">"
  { if (n==null) {
     return ITermFactory.createComplexTerm1("idl_sequence_type",t);
    }else{
     return ITermFactory.createComplexTerm2("idl_bounded_sequence_type",t,n);
    }
  }
}

/* Production 62 in 2.0, 81 in 2.6*/
ITerm string_type() throws TermWareException :
{
 ITerm n=null;
}
{
  "string" [ "<" n=positive_int_const() ">" ]
 {
  if (n==null) {
    return ITermFactory.createAtom("idl_string");
  }else{
    return ITermFactory.createComplexTerm1("idl_bounded_string",n);
  }
 }
}

/* Production 82 in 2.6*/
ITerm wide_string_type() throws TermWareException :
{
 ITerm n=null;
}
{
  "wstring" [ "<" n=positive_int_const() ">" ]
 {
  if (n==null) {
    return ITermFactory.createAtom("idl_wstring");
  }else{
    return ITermFactory.createComplexTerm1("idl_bounded_wstring",n);
  }
 }
}

/* Production 63 in 2.0, 83 in 2.6*/
ITerm array_declarator() throws TermWareException :
{
 ITerm t1;
 ITerm t2=null;
 ITerm t3=null;
}
{
  t1=identifier() ( t2=fixed_array_size() 
                    { if (t3==null) t3=t1; else t3=cons(t2,t3); }
                  )+
  { return ITermFactory.createComplexTerm2("idl_array_declarator",t1,t3);
}
  
}

/* Production 64 */

ITerm fixed_array_size() throws TermWareException  :
{
 ITerm t;
}
{
  "[" t=positive_int_const() "]"
    { return t; }
}

/* Production 65 */

ITerm attr_dcl() throws TermWareException :
{
 boolean rdonly=false;
 ITerm aat=null;
 ITerm ptst=null;
 ITerm sd1=null;
 ITerm sd2=null;
 ITerm sd3=null;
 ITerm sd=null;
}
{
  [ "readonly" {rdonly=true;}] "attribute" ptst=param_type_spec() 
                                           sd1=simple_declarator() 
      ( "," sd2=simple_declarator() 
        {
         if (sd3==null) {
          sd3=sd2;
         }else{
          sd3=cons(sd2,sd3);
         }
        }
      )*
  {
   aat=ITermFactory.createBoolean(rdonly);
   if (sd2==null) sd=sd1; else sd=cons(sd1,sd2);
   return ITermFactory.createComplexTerm3("idl_attr_dcl",sd,aat,ptst);
  }
}

/* Production 66 */

ITerm except_dcl() throws TermWareException  :
{
 ITerm t1=null;
 ITerm t2=null;
 ITerm t3=null;
}
{
  "exception" t1=identifier() "{" ( t2=member()
                                 { if (t3==null) t3=t2; else
t3=cons(t2,t3); }
                               )* "}"
  {
    if (t2==null) {
      return ITermFactory.createComplexTerm1("idl_except_dcl", t1);
    }else{
      return ITermFactory.createComplexTerm2("idl_except_dcl", t1,t3);
    }
  }
}

/* Production 67 */

ITerm op_dcl() throws TermWareException :
{
 ITerm t1=null;
 ITerm t2=null;
 ITerm t3=null;
 ITerm t4=null;
 ITerm t5=null;
 ITerm t6=null;       
}
{
  [ t1=op_attribute() ] t2=op_type_spec() t3=identifier()
t4=parameter_dcls() [ t5=raises_expr() ] [ t6=context_expr() ]
 {
  if (t1==null) {
    t1=ITermFactory.createComplexTerm0("set");
  }else{
    t1=ITermFactory.createComplexTerm1("set",t1);
  }
  if (t5==null) {
    t5=ITermFactory.createAtom("idl_emply_raises_expr");
  }  
  if (t6==null) {
    t6=ITermFactory.createAtom("idl_empty_context_expr");
  }
  return ITermFactory.createComplexTerm6("idl_op_dcl",t3,t1,t2,t4,t5,t6);
 }                  
}

/* Production 68 */

ITerm op_attribute() :
{}
{
  "oneway"
  { return ITermFactory.createAtom("idl_oneway"); }
}

/* Production 69 */

ITerm op_type_spec() throws TermWareException :
{
 ITerm t;
}
{
  t=param_type_spec()
  { return t; }
|
  "void"
  { return ITermFactory.createAtom("idl_void"); }
}

/* Production 70 */

ITerm parameter_dcls() throws TermWareException :
{
 ITerm t1=null;
 ITerm t2=null;
 ITerm t3=null;
}
{
  "(" [ t1=param_dcl() ( "," t2=param_dcl() 
                         {
                           if (t3==null) t3=t2;
                           else t3=cons(t2,t2);
                         }
                       )* ] ")"
 {
   if (t1==null) return
ITermFactory.createAtom("idl_empty_parameter_dcls");
   if (t2==null) return t1;
   else return ncons(t1,t3);
 }
}

/* Production 71 */

ITerm param_dcl() throws TermWareException :
{
 ITerm t1;
 ITerm t2;
 ITerm t3;
}
{
  (t1=param_attribute() t2=param_type_spec() t3=simple_declarator())
 { return ITermFactory.createComplexTerm3("idl_param_dcl",t1,t2,t3); }
}

/* Production 72 */

ITerm param_attribute() :
{}
{
  "in"
  { return ITermFactory.createAtom("idl_in"); }
|
  "out"
  { return ITermFactory.createAtom("idl_out"); }
|
  "inout"
  { return ITermFactory.createAtom("idl_inout"); }
}

/* Production 73 */

ITerm raises_expr() throws TermWareException :
{
 ITerm t1=null;
 ITerm t2=null;
 ITerm t3=null;
}
{
  "raises" "(" t1=scoped_name() ( "," t2=scoped_name() 
                                  { if (t3==null) {
                                      t3=t2;
                                    }else{
                                      t3=cons(t2,t3);
                                  } }
                                )* ")"
 {
  if (t2==null) {
    return t1;
  }else{
    return cons(t1,t3);
  }
 }
}

/* Production 74 */

ITerm context_expr() throws TermWareException :
{
 ITerm t1=null;
 ITerm t2=null;
 ITerm t3=null;
}
{
  "context" "(" t1=string_literal() ( "," t2=string_literal() 
                                        { if (t3==null) t3=t2;
                                          else t3=cons(t2,t3);
                                        }
                                    )* ")"
 {
  if (t2==null) {
    return t1;
  }else{
    return cons(t1,t3);
  }
 }
}

/* Production 75 */

ITerm param_type_spec() throws TermWareException :
{
 ITerm t;
}
{
  t=base_type_spec()
   { return t; }
|
  t=string_type()
   { return t; }
|
  t=wide_string_type()
|
  t=scoped_name()
   { return t; }
}

/* Definitions of complex regular expressions follow */

ITerm identifier() throws TermWareException:
{
 ITerm retval;
 Token token;
}
{
  token=<ID>
 {
  return ITermFactory.createComplexTerm1("idl_identifier",
                                  
ITermFactory.createString(token.image));
 }
}

ITerm integer_literal() throws ParseIntegerFormatException:
{
 Token tk;
 int x;
 int radix;
}
{
(
  tk=<OCTALINT>  { radix=8; }
|
  tk=<DECIMALINT>   { radix=10; }
|
  tk=<HEXADECIMALINT>  { radix=16; }
)
{
 try {
  x=Integer.parseInt(tk.image,radix);
 }catch(NumberFormatException ex){
  throw new ParseIntegerFormatException(ex.getMessage());
 }
 return ITermFactory.createInt(x);
}
}

ITerm  string_literal() :
{
 Token t;
}
{
  t=<STRING>
  { 
    return ITermFactory.createString(ParseUtils.token2String(t.image));
  } 
}

ITerm character_literal() :
{
 Token t;
}
{
  t=<CHARACTER>
  { 
    return ITermFactory.createString(ParseUtils.charToken2String(t.image));
  } 
}

ITerm floating_pt_literal() :
{
 Token t;
}
{
(
  t=<FLOATONE>
|
  t=<FLOATTWO>
)
 { double x=0.0;
   try {
     x=Double.parseDouble(t.image);
   }catch(NumberFormatException ex){
     System.err.println("Number format exception:"+ex.toString());
   }
   return ITermFactory.createDouble(x); 
 }
}

/* Production 97 in 2.6 */
ITerm fixed_pt_const_type() throws TermWareException :
{
}
{
 "fixed"
  { return ITermFactory.createAtom("idl_fixed_pt_const_type"); }
}


/* Production 98 in 2.6 */
ITerm value_base_type() :
{
}
{
 "ValueBase"
  { return ITermFactory.createAtom("idl_value_base_type"); }
}


/* Production 99 in 2.6 */
ITerm constr_forward_decl() throws TermWareException :
{
 ITerm t;
}
{
 "struct" t=identifier()
   { return ITermFactory.createComplexTerm2("idl_constr_forward_decl",
                                            
ITermFactory.createAtom("struct"),
                                             t);
   }
 |
 "union"  t=identifier()
   { return ITermFactory.createComplexTerm2("idl_constr_forward_decl",
                                            
ITermFactory.createAtom("union"),
                                             t);
   }
}

TOKEN :
{
  <  ID : ["a"-"z","A"-"Z", "_"] (["a"-"z","A"-"Z","0"-"9","_"])* >
| <  OCTALINT : "0" (["0"-"7"])* (["u","U","l","L"])? >
| <  DECIMALINT : ["1"-"9"] (["0"-"9"])* (["u","U","l","L"])? >
| <  HEXADECIMALINT : ("0x"|"0X") (["0"-"9","a"-"f","A"-"F"])+
(["u","U","l","L"])? >
| <  FLOATONE : ((["0"-"9"])+ "." (["0"-"9"])* | (["0"-"9"])* "."
(["0"-"9"])+)
   (["e","E"] (["-","+"])? (["0"-"9"])+)? (["f","F","l","L"])? >
| <  FLOATTWO : (["0"-"9"])+ ["e","E"] (["-","+"])?
   (["0"-"9"])+ (["f","F","l","L"])? >
| <  CHARACTER : "'"
   (   (~["'","\\","\n","\r"])
   | ("\\" (
             ["n","t","v","b","r","f","a","\\","?","'","\""]
            |
             "0" (["0"-"7"])*
            |
             ["1"-"9"] (["0"-"9"])*
            |
             ("0x" | "0X") (["0"-"9","a"-"f","A"-"F"])+
           )
     )
   )
   "'" >
| <  STRING : "\""
   ( ( ~["\"","\\","\n","\r"])
   | ("\\" (
             ["n","t","v","b","r","f","a","\\","?","'","\""]
            |
             "0" (["0"-"7"])*
            |
             ["1"-"9"] (["0"-"9"])*
            |
             ("0x" | "0X") (["0"-"9","a"-"f","A"-"F"])+
           )
     )
   )*
   "\"" >
}



<-- __Chronological__ --> <-- __Thread__ -->


Usenet.com



Please check out one of the premium Usenet Newsgroup Service Providers below for access to Usenet.