Related articles |
---|
Java Comment-Preserving Grammar matthew-google@faredge.com.au (2004-05-24) |
Re: Java Comment-Preserving Grammar sreeni@viswanadha.net (Sreenivasa Viswanadha) (2004-05-30) |
Re: Java Comment-Preserving Grammar martin@cs.uu.nl (Martin Bravenboer) (2004-05-30) |
Re: Java Comment-Preserving Grammar cdodd@acm.org (Chris Dodd) (2004-05-30) |
Re: Java Comment-Preserving Grammar dobes@dobesland.com (Dobes Vandermeer) (2004-05-30) |
Re: Java Comment-Preserving Grammar tbauer@cadrc.calpoly.edu (Tim Bauer) (2004-05-30) |
Re: Java Comment-Preserving Grammar jens.troeger@light-speed.de (2004-06-06) |
Re: Java Comment-Preserving Grammar clint@0lsen.net (Clint Olsen) (2004-06-06) |
Re: Java Comment-Preserving Grammar gah@ugcs.caltech.edu (glen herrmannsfeldt) (2004-06-09) |
Re: Java Comment-Preserving Grammar cfc@shell01.TheWorld.com (Chris F Clark) (2004-06-11) |
Re: Java Comment-Preserving Grammar alexc@std.com (Alex Colvin) (2004-06-13) |
Re: Java Comment-Preserving Grammar gah@ugcs.caltech.edu (glen herrmannsfeldt) (2004-06-13) |
[1 later articles] |
From: | "Tim Bauer" <tbauer@cadrc.calpoly.edu> |
Newsgroups: | comp.compilers |
Date: | 30 May 2004 13:22:10 -0400 |
Organization: | Cal Poly, SLO |
References: | 04-05-075 |
Keywords: | Java, parse |
Posted-Date: | 30 May 2004 13:22:10 EDT |
>
> Is there an available Java grammar which preserves comments in an
> output AST tree? I know there are plenty of java grammars out there,
> but all ignore comments. I'm happy to use any tool providing I can
> gain access to the comments in the tree.
>
> My end goal is to parse commented-out extensions to the java language:
>
> class /*#immutable*/ Blah {
>
> public /*#input*/ int x;
> public /*#result*/ int y;
>
> }
The parser generator suite I am most familiar with is Lex (flex) /
YACC (bison). The way I usually see /* comments handled there is
having the lexer go into new new state and ignoring everything until
*/. There are regular expressions to match the sequence, but it is too
easy to just use this approch. I imagine that most scanner generators
should have some analogous construct.
After the state change you can scan only the tokens you are interested in.
#input or #result.
You will probably want to switch your error handling strategys for this
state too.
Another suggestion is to extend in the comment begin delimiter.
Much like the javadocs will ignore /* and expects /**, you
could invent something like /*# (that may be your intention, but I cannot
tell).
You could state change to ignore /* and state change to only try and parse
/*# comments.
This is a neat idea.
Good luck,
- Tim
Return to the
comp.compilers page.
Search the
comp.compilers archives again.