[antlr-interest] syntactic predicates question
Jim O'Connor
Jim.OConnor at microfocus.com
Tue Apr 8 08:53:18 PDT 2003
Hi all,
I'll try to keep this as simple as possible. In JCL the statements are of
the form
//(optional name) keyword
//ZERO CNTL
//ONE PEND
// PEND
// CNTL
//FOUR PEND
/************************** valid "g" file
*****************************************************************/
class fred extends Parser;
options {
k=4; // Trying reasonable values of k 1-5 shows a difficulty with the
pattern DSLASH-JCLNAME-(DSLASH,EOF)-(EOF, CNTL, PEND, DSLASH, JCLNAME)
}
jclfile : (statement)+
;
statement : start CNTL
| start PEND
;
start : DSLASH (JCLNAME) ? ;
/***************************************************************************
****************/
Changing statement to
statement : (start CNTL) => start CNTL
| start PEND
;
works for this limited example. K can be set to 1.
There are about fifteen other statement keywords. Do I need a predicate for
all but one of the keywords?
The next step is a getting more in depth.
I would like the parser to understand nesting. The CNTL statement has a
matching ENDCNTL statement
/************************** valid "g" file
*****************************************/
class fred extends Parser;
options {
k=3;
}
jclfile : (statement)+
;
statement : (start CNTL) => cntlStatement
| start PEND
;
pendStatement : start PEND ;
cntlStatement : start CNTL (statement)+ endCntlStatement ;
endCntlStatement: start ENDCNTL;
start : DSLASH (JCLNAME) ?
/************************************************************************/
I get back to the original warning of nondeterminisms. The lame attempts at
resolving the non determinism leads to "single alternative" warnings.
Where should I concentrate effort? The original predicate solution for the
statement rule or the construct of the cntlStatement?
"valid g file" means it can be copied and "tooled" to get some idea of what
I'm talking about.
I have read the parts of the documentation explaining the rules
a: A (P)?
| A
;
That doesn't mean I fully understand the implications, though.
Your use of Yahoo! Groups is subject to http://docs.yahoo.com/info/terms/
More information about the antlr-interest
mailing list