[antlr-interest] syntactic predicates question

jbb at acm.org jbb at acm.org
Tue Apr 8 09:46:20 PDT 2003


Mr. O'Connor :-

Syntactic predicates are not necessary (nor is any look ahead greater
than 1) for the JCL examples you have asked about.

You simply need to "left factor" your grammar rules in order to put
them into LL(1) form. You should be able to read more about "left
factoring" in any good reference book on compilers. Aho, Sethi, and
Ullman's Compilers Principles, Techniques, and Tools - aka The Dragon
Book - is a good reference altho may be outdated now. 

Anyway, your first grammar can be re-written as:
/********************************************************************/
class fred extends Parser;

jclfile :
	(statement)+ 
    ;

statement :
	DSLASH (JCLNAME)? operation
    ;

operation :
	CNTL   
    |   PEND
    ;
/********************************************************************/

And your second grammar as:
/********************************************************************/
class fred extends Parser;

jclfile :
	(statement)+ 
    ;

statement :
	DSLASH (JCLNAME)? operation
    ;

operation :
	cntlStatement
    |   PEND
    ;

cntlStatement :
	CNTL
	statement
	DSLASH (JCLNAME)? ( ENDCNTL | operation )
    ;
/********************************************************************/

 

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




More information about the antlr-interest mailing list