[antlr-interest] ANTLR C++ error?

marc_schellens m_schellens at hotmail.com
Tue Feb 26 21:56:50 PST 2002


I have the following tree parser:

label!
  : #(i:IDENTIFIER COLON)
	{ 
	  #label=#[LABEL,i->getText()];
	  comp.Label(#label); 
	}	
  ;

ANTLR generates:
	
label_AST=astFactory.create(LABEL,i->getText());
comp.Label(label_AST); 

ok.		
But for the following:

var!
  : #(VAR i:IDENTIFIER)
	{ 
	  #var=#[VAR,i->getText()];
	  comp.Var(#var);	
	}
  ;

ANTLR generates:
		 
var_AST=astFactory.create(static_cast<antlr::RefAST>(static_cast<antlr::RefAST>(tmp58_AST),i->getText()));
		  comp.Var(var_AST);	

What is the reason? For me both examples look
pretty much the same.
Thanks,
marc


both LABEL and VAR are defined in MyTreeParserTokenTypes.hpp.
The code genrated before the above two lines in the 2nd example is:
void MyTreeParser::var(RefDNode _t) {
	RefDNode var_AST_in = _t;
	returnAST = static_cast<RefDNode>(antlr::nullAST);
	antlr::ASTPair currentAST;
	RefDNode var_AST = static_cast<RefDNode>(antlr::nullAST);
	RefDNode i = static_cast<RefDNode>(antlr::nullAST);
	RefDNode i_AST = static_cast<RefDNode>(antlr::nullAST);
	
	RefDNode __t106 = _t;
	RefDNode tmp58_AST = static_cast<RefDNode>(antlr::nullAST);
	RefDNode tmp58_AST_in = static_cast<RefDNode>(antlr::nullAST);
	tmp58_AST = astFactory.create(static_cast<antlr::RefAST>(_t));
	tmp58_AST_in = _t;
	antlr::ASTPair __currentAST106 = currentAST;
	currentAST.root = currentAST.child;
	currentAST.child = static_cast<RefDNode>(antlr::nullAST);
	match(static_cast<antlr::RefAST>(_t),VAR);
	_t = _t->getFirstChild();
	i = _t;
	i_AST = astFactory.create(static_cast<antlr::RefAST>(i));
	match(static_cast<antlr::RefAST>(_t),IDENTIFIER);
	_t = _t->getNextSibling();
	currentAST = __currentAST106;
	_t = __t106;
	_t = _t->getNextSibling();
	var_AST = RefDNode(currentAST.root);



 

Your use of Yahoo! Groups is subject to http://docs.yahoo.com/info/terms/ 



More information about the antlr-interest mailing list