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

Bharath S payasam79 at yahoo.com
Fri Apr 16 12:46:07 PDT 2004


Hi Jon,

If you look at line 329 and 330, both lines can occur
zero or more times and both of them COULD START with
JAVADOC_OPEN

329: (javaDocComment | import)*
330: ( (invariantCondition)* typeDefinition)*

Now, lets say the parser encounters JAVADOC_OPEN.
Should it consider it as a "javaDocComment" or
"invariantCondition"? You have a non-determinism right
there.

If you claim that "typeDefinition" follows
invariantCondition, it still wont help you
differentiate because a "javaDocComment" can always be
follwed by a "typeDefinition" as every rule in 329/330
is optional.

Try to add a "hash" symbol or any other symbol for
that case, in front of either javaDocComment or
invariantCondition and see if the error is resolved.

Note: I'm a newbie, so bear with me if my suggestion
isnt helpful.

-----------------------------------------------------
--- Jon Schewe <jpschewe at mtu.net> wrote:
> Apparently that's still non-deterministic.  
> 
> Line 329 is (javaDocComment | import)*
> ANTLR Parser Generator   Version 2.7.3   1989-2004
> jGuru.com
> java.g:329: warning:nondeterminism upon
> java.g:329:     k==1:JAVADOC_OPEN
> java.g:329:    
>
k==2:JAVADOC_CLOSE,POST_CONDITION,PRE_CONDITION,ASSERT_CONDITION,INVARIANT_CONDITION
> java.g:329:     between alt 1 and exit branch of
> block
> 
> On Thu, 2004-04-15 at 23:10, lgcraymer wrote:
> > Try something like
> > 
> > compilationUnit
> >     :
> >     (   ( (javaDocComment)* package )=>
> (javaDocComment)* package
> >     |
> >     )
> >     (javaDocComment | import)*
> >     ( (invariantCondition)* typeDefinition)*
> >     EOF
> >     ;
> >     
> > --Loring
> > 
> > 
> > --- In antlr-interest at yahoogroups.com, Jon Schewe
> <jpschewe at m...> wrote:
> > > I asked this question back in October of 2000
> and never got an answer. 
> > > I've worked on it on and off (mostly off) since
> then and have not come
> > > up with an answer.  I've updated to antlr 2.7.3
> hoping that it'd be
> > > better at this, but still haven't gotten it
> working.  
> > > 
> > > So here's the question again to see if anyone
> else can figure it out.
> > > 
> > > The structure of the file is as follows:
> > > 
> > > compilationUnit
> > >   :
> > > (javadocComment)*
> > > (package)?
> > > (javadocComment | import)*
> > > ( (invariantCondition)* typeDefinition)*
> > > EOF
> > > 
> > > /**
> > >    This is a javadoc comment that we're not
> looking for any conditions
> > > in.
> > > **/
> > > javadocComment
> > >   : JAVADOC_OPEN ( INVARIANT_CONDITION |
> PRE_CONDITION | POST_CONDITION
> > > | ASSERT_CONDITION )* JAVADOC_CLOSE
> > >   ;
> > > 
> > > /**
> > >    This is a javadoc comment that we're looking
> for invariants in.
> > > **/
> > > invariantCondition
> > >   : JAVADOC_OPEN ( iv:INVARIANT_CONDITION {
> addInvariant(iv); } |
> > > PRE_CONDITION | POST_CONDITION |
> ASSERT_CONDITION )* JAVADOC_CLOSE
> > >   ;
> > > 
> > > Basically it's a Java grammar, where the javadoc
> comments are
> > > important.  I've gotten past the lexer by using
> two lexers, one for
> > > inside comments and one for everything else. 
> That gives me a nice token
> > > stream, but I just can't seem to get past the
> top rule above.  If I
> > > don't allow comments anywhere above
> typeDefinition and require that
> > > typeDefiniation exists, it'll compile and go. 
> However I want to allow
> > > comments above typeDefinition and I want to
> allow a file that's
> > > commented out with single line comments (thus no
> type definition).
> > > 
> > > Thanks for any help you can provide.
> > > -- 
> > > 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
> > 
> > 
> > 
> >  
> > Yahoo! Groups Links
> > 
> > 
> > 
> >  
> -- 
> 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
> 

> ATTACHMENT part 2 application/pgp-signature
name=signature.asc



=====
Bharath Sundararaman
Graduate Assistant, CAHS.
(312)-5606532 (M)
http://www.cs.uic.edu/~bsundara


	
		
__________________________________
Do you Yahoo!?
Yahoo! Tax Center - File online by April 15th
http://taxes.yahoo.com/filing.html


 
Yahoo! Groups Links

<*> To visit your group on the web, go to:
     http://groups.yahoo.com/group/antlr-interest/

<*> To unsubscribe from this group, send an email to:
     antlr-interest-unsubscribe at yahoogroups.com

<*> Your use of Yahoo! Groups is subject to:
     http://docs.yahoo.com/info/terms/
 



More information about the antlr-interest mailing list