[antlr-interest] How to make antlr parse this

Jon Schewe jpschewe at mtu.net
Thu Apr 15 19:15:50 PDT 2004


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
-------------- 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/20040415/2cfcf25e/attachment.bin


More information about the antlr-interest mailing list