[antlr-interest] Problem with mutually left recursion

Nicolai Mainiero nicolai at mainiero.de
Wed Nov 29 00:34:05 PST 2006


Hi,

I am new to ANTLR and parser grammars and have with the following  
grammar a mutual left recusrion problem. Perhapes anybody can guide  
me throug the necessary rewriting of the rules.

I already used ANTLRWorks to detect the affectet rules. Here is the  
console output from it.

[09:19:55] Checking Grammar...
[09:19:55] Aborting because the following rules are mutually left- 
recursive:
     [var, functioncall, prefixexp]
     [fieldset, exp, tableconstructor, field]

Any help would be great.
Nicolai

PS: Here is the grammar I'm using:

chunk	:	(stat SEMI)* (laststat SEMI)?
	 	;
	
block	:	chunk
		;
		
stat	:	varlist1 EQUALS explist1
		|	functioncall
		|	DO block END
		|	WHILE exp DO block END
		|	REPEAT block UNTIL exp
		|	IF exp THEN block (ELSEIF exp THEN block)* (ELSE block)? END
		|	FOR NAME EQUALS exp COMMA exp (COMMA exp)? DO block END
		|	FOR namelist IN explist1 DO block END
		|	FUNCTION^ funcname funcbody
		| 	LOCAL FUNCTION NAME funcbody
		|	LOCAL namelist (EQUALS explist1)?
		;
	
laststat: 	RETURN explist1
		|		BREAK
		;
		
funcname:	NAME (DOT NAME)* (COLON NAME)?
		;


varlist1:	var (COMMA var)*
		;

var	:	NAME
		|	prefixexp LLARGEBRACKET exp RLARGEBRACKET
		|	prefixexp  DOT NAME
		;


namelist:	NAME (COMMA NAME)*
		;
		
explist1:	(exp COMMA)* exp
		;

exp		:	(NIL | FALSE | TRUE | NUMBER | STRING | THREEDOTS | function |  
prefixexp | tableconstructor | unop exp) (binop exp)*
		;

prefixexp:	var
		 |	functioncall
		 |	LBRACKET exp RBRACKET
		 ;
		 	
functioncall: prefixexp  args
			| prefixexp COLON NAME args
			;
			
	
			
args	:	LBRACKET (explist1)? RBRACKET
		|	tableconstructor
		| 	STRING
		;

function:	FUNCTION funcbody
		;

funcbody:	LBRACKET (parlist1)? RBRACKET block END
		;
		
parlist1:	namelist (COMMA THREEDOTS)?
		|	THREEDOTS
		;
		
tableconstructor:	(fieldset)*
				;
				
fieldset:	field (fieldsep field)* (fieldsep)?
		;

field	:	LLARGEBRACKET exp RLARGEBRACKET EQUALS exp
		|	NAME EQUALS exp
		|	exp
		;
		
fieldsep:	COMMA
		|	SEMI
		;
		
binop	:	PLUS
		|	MINUS
		|	STAR
		|	SLASH
		|	HAT
		|	PERCENT
		|	TWODOTS
		|	SMALLER
		|	SMALLEREQ
		|	LARGER
		|	LARGEREQ
		|	DOUBLEEQ
		|	NEGATEEQ
		|	AND
		|	OR
		;
		
unop	:	MINUS
		|	NOT
		|	HASH
		;
-------------- next part --------------
A non-text attachment was scrubbed...
Name: smime.p7s
Type: application/pkcs7-signature
Size: 2421 bytes
Desc: not available
Url : http://www.antlr.org/pipermail/antlr-interest/attachments/20061129/3969d7c8/attachment.bin 


More information about the antlr-interest mailing list