[antlr-interest] Re: How to make antlr parse this

Jon Schewe jpschewe at mtu.net
Tue Apr 27 20:15:45 PDT 2004


On Sat, 2004-04-17 at 15:12, Mark wrote:
> favor of matching the invariant.  Which leads us to:
> 
> unit: pre start middle end ;
> pre: fluff ;
> start : (package fluff)? ;
> middle : (import fluff)* ;
> end : ((invariant)? typedef)* ;
> fluff : 
>     (comment)=> ( (invariant typedef)=> empty | comment fluff )
>     | empty ;
> invariant : comment { some code here } ;
> empty : ;
> 
> So, fluff is a sequence of zero or more comments, but doesn't include the last comment 
> that could be an invariant if if is followed by a typedef.  Alas, this is tail recursive, but that 
> may or may not be a concern for you.  (Do you expect to parse things with thousands of 
> consecutive comment blocks?)
> 
No, I don't expect there to be throunds of consecutive comment blocks,
so I'm not worried about the tail recursion.  

Thank you so very much for this help!  I went back and implemented this
and it works perfectly.  I hadn't thought of pushing the comments up to
the previous rule like that.

-- 
Jon Schewe | http://mtu.net/~jpschewe
GPG signature at http://mtu.net/~jpschewe/gpg.sig.html
For I am convinced that neither death nor life, neither angels 
nor demons, neither the present nor the future, nor any 
powers, neither height nor depth, nor anything else in all 
creation, will be able to separate us from the love of God that 
is in Christ Jesus our Lord. - Romans 8:38-39
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 198 bytes
Desc: This is a digitally signed message part
Url : http://www.antlr.org/pipermail/antlr-interest/attachments/20040427/0b8eab52/attachment.bin


More information about the antlr-interest mailing list