[antlr-interest] syntactic predicates question
Jim O'Connor
Jim.OConnor at microfocus.com
Tue Apr 8 10:57:29 PDT 2003
Thanks for your assistance and advice. The dragon book is a favorite. The
left-factoring section hasn't quite sunk in, but I see where I should be
heading. The cntlStatement is giving me some problems, still.
Your suggestion is clear. Trying to modify it to match the grammar gets me
into difficulties
ORIGNAL
cntlStatement :
CNTL
statement
DSLASH (JCLNAME)? ( ENDCNTL | operation )
;
DESIRED - ENDCNTL ends a block of statements
cntlStatement :
CNTL
(statement)+
DSLASH (JCLNAME)? ( ENDCNTL )
;
Thanks again. Worst case, I have learned where to focus attention.
Jim
-----Original Message-----
From: jbb at acm.org [mailto:jbb at acm.org]
Sent: Tuesday, April 08, 2003 12:46 PM
To: antlr-interest at yahoogroups.com
Subject: Re: [antlr-interest] syntactic predicates question
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/
Your use of Yahoo! Groups is subject to http://docs.yahoo.com/info/terms/
More information about the antlr-interest
mailing list