| Refresh | Home EGTry.com

tree construction operators



rule of a sequence of token and child rules

delare: 'int' ID^ init ';'!

public MyParser.declare_return declare() {
  declare_return retval=new MyParser.declare_return();
  retval.start=input.LT(1); //LT(1) is the next token
  Object root=adapter.nil(); //null root object
  
  //create 'int' node
  Token intToken=(Token)match(input, INT);
  adaptor.addChild(root,adaptor.create(intToken));

  //create ID node, and make it as the root
  Token idToken=(Token)match(input, ID);
  root=adaptor.becomeRoot(adaptor.create(idToken,root);
  
  //create init node
  MyParser.init_return initRet=init();
  adaptor.addChild(root,initRet.getTree());


  //match ';' and throw away
  match(input,SEMI);

  retval.stop=input.LT(-1); 
  retval.tree=adaptor.rulePostProcessing(root);
  adaptor.setTokenBoundaries(retval.tree,retval.start,retval.stop);

}