[antlr-interest] Predicate Variable

Carleton Coffrin Carleton at Coffrin.com
Fri Jul 27 12:25:08 PDT 2007


Is there a way to write a predicate which takes another predicate as an
argument?

My inspiration for this question is as follows.  The language I am working
with supports different sets of statements depending on where the statements
appear.  This yields statement predicates like this,

programA
    : (stmtA SCOLON)*
;

stmtA
    : s=whileA
    | s=foo
;

whileA
    : "while" expr "do" programA "od"
;


programB
    : (stmtB SCOLON)*
;

stmtB
    : s=whileB
    | s=bar
;

whileB
    : "while" expr "do" programB "od"
;

I am looking for a way to factor out the while loop structure in "whileA"
and "whileB" with out breaking the required recursive "programA"/"programB"
reference.  I would like to write something like this,

while<pred>
    : "while" expr "do" pred "od"
;

How might I archive this sort of refactoring?

Cheers
-Carleton
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.antlr.org/pipermail/antlr-interest/attachments/20070727/bd9b5f05/attachment.html 


More information about the antlr-interest mailing list