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

Jon Schewe jpschewe at mtu.net
Fri Apr 16 19:44:27 PDT 2004


On Fri, 2004-04-16 at 10:09, Mark wrote:
> First: recognize that, for the parser, javadocComment and invariantCondition are identical 
> parses - there is no way to tell them apart with any lookahead or syntatic predicates.
> 
Agreed.

> u : (c)* (p)? (c|i)* ((c)* t)* ;
> 
> Consider this sequence: c c c t
> 
> How many of those comments (c) should be used to match (c|i)*?  how many should be 
> used to match ((c)* t)*?
> 
> The grammar is non-deterministic because your specification is.  Once you decide hoe you 
> want to resolve the above ambiguity, then you can write a non-deterministic grammar for 
> it,

Ah yes, now I see the error of my ways.  In the case you show I want
just the last c to match typeDefinition.  So my grammar is more like
this:
compilationUnit
  :
 ( (javadocComment)* packageDefinition ) => (javadocComment)*
packageDefinition // Thanks Loring that took care of the ones above
packages
 | /* nothing */
 )
(javadocComment | import)*
( (invariantCondition)? typeDefinition)*
EOF

Of course antlr still informs me that this is non-deterministic, likely
due to k being 2 and javadocComment being longer than 2 tokens.  Am I
right on that one?

-- 
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/20040416/2366884a/attachment.bin


More information about the antlr-interest mailing list