[antlr-interest] my grammar was wrong, but my error rose a sy ntactic predicate problem in tree parsers

mzukowski at yci.com mzukowski at yci.com
Thu Feb 20 08:26:42 PST 2003


I avoid syntactic predicates in my tree parser by rearranging my tree and
using imaginary node types when appropriate.  You should not need a rule
like this:
entOrSet
	:	( R_ENT )=> entity
	|	( R_SET )=> set
;

This should work fine:

entOrSet
	:	entity
	|	set
;

Monty

-----Original Message-----
From: Anthony Brenelière [mailto:abreneliere at telys.com]
Sent: Thursday, February 20, 2003 7:33 AM
To: antlr-interest at yahoogroups.com; klaren at cs.utwente.nl
Subject: [antlr-interest] my grammar was wrong, but my error rose a
syntactic predicate problem in tree parsers




I did a mistake, i replaced:

( modif 1 )
set
	:	#( R_ENT setComponentList )
;

to 

set
	:	#( R_SEC setComponentList )
;

( modif 2 )
In the syntactic predicate, i did not need to check the entire rule.
I also  replaced..

entOrSet
	:	( entity )=> entity
	|	( set )=> set
;

by.. 

entOrSet
	:	( R_ENT )=> entity
	|	( R_SET )=> set
;

and now everything works.

BUT the rule..
entOrSet
	:	( entity )=> entity
;
..did work because the sintactic predicate was supressed (because it is
obsolete)

and HOWEVER..
entOrSet
	:	( entity )=> entity
	:	( set )=> set
;
..should work.

The syntactic predicate ( entity )=>  returns false whereas it should
return true. When there is no syntactic predicate, the rule is matched.

Important : Before ( modif 1 ), the syntax could have been validated by
both syntactic predicates ( entity )=>, ( set )=>, in that case, the
alternative 1 is chosen, because it is the first alternative. In the
parser i have rules that can be matched by more than one syntactic
predicate, in which case the first matched alternative is selected.

My conclusion is:
"When the syntax is OK, The syntactic predicate does not 'allways'
validate the rule, in tree parsers."

I join the C++ tree parser generated file, that contains the wrong
syntactic predicate (the on that rise the problem).

Here is a sample of my tree parser with mistakes (that rise the
syntactic predicate problem)...

entOrSet
	:	( entity )=> entity	// replaced by ( R_ENT )=>
entity
	|	( set )=> set		// replaced by ( R_SET )=> set; 

entity
	:	#( R_ENT entityComponentList )
;

set
	:	#( R_ENT setComponentList ) 	// replaced by #( R_SET
setComponentList )
;

entityComponentList
	:	( entityComponent )+
;

setComponentList
	:	( entityComponent | setComponent )+
;

entityComponent
	:	#( R_ENC component )
;

setComponent
	:	#( R_SEC component )  // Ric Klaren : Here is the
difference that would premit
                                  // the syntactic predicate of the rule
entOrSet 
;

component
	:	i:IDENTIFIER ("WHERE" entAttSetList)?
	{ cout << i->getText() << endl; }
; 

CHEERS,
Anthony

 

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


 

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



More information about the antlr-interest mailing list