[antlr-interest] Bug with more than one parser

Jean-Claude Durand Jean-Claude.Durand at imag.fr
Thu Nov 24 09:18:53 PST 2005


Hi,
I got bugs when I try to have 2 parsers one calling the other with some 
types of rules. I use ANTLR for a large project
but I isolated the problem on a very simple example:
The example parses sequences of assignments as simple as:
x = a * bb * c;

The main grammar consists of 2 rules:

// an example:  "x = a * bb * c;"
assignments:	
	( IDF ASSIGN prod SEMI )+
	;

// this rule "calls" the grammar Expression which parses a simple 
product of terms like "a * bb * c":
prod:	
	{
		Expression exp(getInputState());
		exp.product();
	}
	;

The called grammar just parses the product, it can be done with:
// The iterative formulation is OK:
product:
	IDF
	(
		PROD IDF
	)*
	;

/* Although with these rules, I got a bug "unexpected token":
product:
	IDF
	remaining
	;

remaining:
		PROD IDF
		remaining
	|
		// empty
	;
*/

The same kind of pb arises if for instance you want to have tabs 
elements or variables, and the rule below does
not work:
product:
	IDF ( LB INTEGER RB )?
	(
		PROD IDF ( LB INTEGER RB )?
	)*
	;

I send you the files of the example:

-------------- next part --------------
A non-text attachment was scrubbed...
Name: Assignment.tar.gz
Type: application/x-gzip
Size: 1495 bytes
Desc: not available
Url : http://www.antlr.org/pipermail/antlr-interest/attachments/20051124/e8a57d85/Assignment.tar.gz
-------------- next part --------------


Thanks for your answer,

Jean-Claude Durand
GETA, CLIPS, IMAG-Campus, BP 53
385, rue de la Biblioth?que
38041 Grenoble Cedex 9
France

+33 (0)4 76 51 43 81
jean-claude.durand at imag.f// The iterative formulation is OK:


More information about the antlr-interest mailing list