[antlr-interest] problem with rules in tree parsers, is it a bug or is it normal ?

Ric Klaren klaren at cs.utwente.nl
Thu Feb 20 06:49:48 PST 2003


On Thu, Feb 20, 2003 at 03:30:34PM +0100, Anthony Brenelière wrote:
> In a tree parser,
> I have the following rules
> 
> entOrSet
> 	:	(entity)=> entity
> 	|	(set)=> set
> ;
> 
> entity
> 	:	#( R_ENT entityComponentList )
> ;
> 
> it compiles well, and there is no non-determinism
> but it is not able to recognize the token R_ENT whereas it should.

Could it be that the entity encountered looks more like
#( R_ENT <sumthin-else> ) Try building the treewalker with -traceTreeParser
and see what actually happens. (Or check in a debugger) 

During development with treewalkers I usually have in each rule a exception
handler that prints out the offending tree (look for print_tree code I
posted some while back) And add something like this to rules of interest:

rule:
	( sumthin ) *
	sumthin_else
;
exception
	catch [antlr::RecognitionException &ex]
	{
		print_tree<RefMyAST,MyTreeParser> pr(*this);
		pr.pr_tree(#rule_in);
	}

> When I change the entOrSet rule to:
> 
> entOrSet
> 	:	(entity)=> entity
> 	//	|	(set)=> set (this alternative is suppressed)
> ;
> 
> then everything works fine ! Then 'entity' rule is perfectly matched.
> ( but of course, i cannot have 'sets' sentences in my document )

This could maybe be induced by other rules. Another possibility might be
that something in your hierarchy of lexer/parser/treewalkers needs to be
rebuilt. Check the TokenTypes files of the parser to check if they have the
same idea about the numbering of the tokens.

If you're convinced that it's an antlr problem sent me as small as possible
piece of compiling code and input demonstrating the problem and I'll have a
look at it.

Cheers,

Ric
-- 
-----+++++*****************************************************+++++++++-------
    ---- Ric Klaren ----- j.klaren at utwente.nl ----- +31 53 4893722  ----
-----+++++*****************************************************+++++++++-------
  Xander: "Buffy, we need to do something *now*"
  Angel: "We need a distraction."
  Buffy: "Right."
  Angel: "What are you going to do?"
  Buffy: "I'm going to kill them all. That oughtta distract 'em..."


 

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



More information about the antlr-interest mailing list