[antlr-interest] Left recursion problem

HELLE Guillaume guillaume.helle at capgemini.com
Thu Jan 25 23:55:17 PST 2007


Hi!

I have a left recursion problem and i don't know how to solve it...
The problem is between "structure_controle" and "instruction"...
How i can solve it?
I am using antlr V3

Thanks for your advicean your help!

Best regards

Guillaume Helle


My grammar :

grammar lpr;

program : (commentaire|structure_controle|predicat_generation)* ;

predicat_generation
	:	'DEBUTBLOC(' site (',' site)* ')' instruction* 'FINBLOC';

site	:	'sit_' ('a'..'z'|'A'..'Z')+;

structure_controle
	:	'SI' condition 'ALORS' instruction ('SINON' instruction)*
'FINSI' |
		'TANTQUE' condition 'FAIRE' instruction 'FINFAIRE' |
		instruction |
		code_C;
		
commentaire
	:	'#' ( ~(newline) )* 
                 {_ttype = Token.SKIP;};
                 
code_C	:	'&' ( ~(newline) )*;

texte_libre
	:	(chaine_caractere*|' '|'\t')*;

condition
	:	'(' 
		(condition (('ET'|'OU') condition)* | 
		expression_arithmetique ('='|'<'|'>'|'<='|'>='|'<>')
expression_arithmetique)
		')';
	
instruction
	:	(
		condition |
		'REGLE' nom_regle |
		'APPEL' action_gascon |
		variable '=' expression_arithmetique |
		variable '=' expression_chaine |
		variable '=' condition |
		structure_controle
		) newline;		
	
expression_arithmetique
	:	'(' (
		terme_compose (('+'|'*'|'/'|'-') terme_compose)* |
		'-'* terme_compose |
		terme_compose '**' constante_entiere
		) ')';		

terme_compose
	:	expression_arithmetique | 
		'(' expression_arithmetique ')' |
		terme |
		'(' terme ')';
		
terme	:	(variable|constante|repere);

expression_chaine
	:	variable ('+' variable | chaine_caractere)* |
		chaine_caractere;

variable:	variable_locale | variable_globale;

variable_locale
	:	'lo' ('E'|'D'|'F'|'R'|'C'|'L'|'1'..'9' 'E'|'1'..'9' 'F')
chaine_caractere;
	
variable_globale
	:	'gl' ('a'..'z'|'A'..'Z')+ nom |
		'gl' nom |
		'GL' nom 'PANNE';
	
nom_regle
	:	nom;
		
action_gascon
	:	nom;
	
repere	:
('a'..'z'|'A'..'Z')('a'..'z'|'A'..'Z')('0'..'9')('0'..'9')('a'..'z'|'A'..'Z'
)+;	
			
nom	:	('a'..'z'|'A'..'Z'|'0'..'9')*;	

chaine_caractere:
	(nom|'_')*;
	
constante_entiere
	:	('+'|'-')* ('1'..'9')* ('0'..'9')+;
	
constante
	:	constante_entiere;
	
	
	
newline	:	'\r\n'|'\r'|'\n';
			
		
WS      : (' '|'\t'|'\n')+ {channel=99;}
;

;


This message contains information that may be privileged or confidential and is the property of the Capgemini Group. It is intended only for the person to whom it is addressed. If you are not the intended recipient,  you are not authorized to read, print, retain, copy, disseminate,  distribute, or use this message or any part thereof. If you receive this  message in error, please notify the sender immediately and delete all  copies of this message.



More information about the antlr-interest mailing list