[antlr-interest] Resolving ambiguities between rules

togol machillan togolmach2 at lycos.com
Mon Mar 7 03:39:08 PST 2005


Hello,

How do I resolve ambiguities between rules when a certain starting part of the rules are the same, like the following two rules.

p_singleline_list { std::string k = "";}  
		    : (k = keyword) {std::cout << "With single line list --- Keyword is " << k << std::endl;} 
		     (VALUE SLASH)+ (VALUE NEWLINE|AMPERSAND NEWLINE (VALUE (SLASH)?)+ NEWLINE)  ;


p_with_sentences { std::string k = "";}  
	     :(k = keyword) {std::cout << "Single line para  with sentences--- Keyword is " << k << std::endl;}
	     (VALUE|FIGURE|VALUE EQUAL (VALUE|FIGURE))+ NEWLINE (sentence)*;

Here the parser always tries to match with the first rule and throws in an unexpected token error when the structure should match the second rule. Is there any way to prioritise rule matching? Is it possible to use syntactic perdicates to differentiate two rules rather two alternatives of the same rule? 

Regards,

Togol Mach 
-- 
_______________________________________________
NEW! Lycos Dating Search. The only place to search multiple dating sites at once.
http://datingsearch.lycos.com



More information about the antlr-interest mailing list