Re: Java Comment-Preserving Grammar

Martin Bravenboer <martin@cs.uu.nl>
30 May 2004 13:18:20 -0400

          From comp.compilers

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)
[4 later articles]
| List of all articles for this month |
From: Martin Bravenboer <martin@cs.uu.nl>
Newsgroups: comp.compilers
Date: 30 May 2004 13:18:20 -0400
Organization: Compilers Central
References: 04-05-075
Keywords: Java, parse
Posted-Date: 30 May 2004 13:18:20 EDT

Hi Matthew,


> 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.


The SGLR parser (Scannerless Generalized LR) produces an AsFix2ME parse
tree, which is a complete representation of the input. This includes
whitespace, comments, and even the productions of the syntax definition.
This representation is thus entirely self-contained, but as a result, it
is very verbose as well.


After imploding AsFix2ME to an abstract syntax tree, the comments and
whitespace are gone. It is not difficult the implement a tool that
annotates this AST with the comments from the parse tree.


I've put an example parse online:


Your input:
http://losser.st-lab.cs.uu.nl/~mbravenb/Foo.java


AsFix2ME parse tree
http://losser.st-lab.cs.uu.nl/~mbravenb/Foo.asfix


AST parse tree
http://losser.st-lab.cs.uu.nl/~mbravenb/Foo.asfix


De AST and parse tree are represented in the ATerm format. There are
ATerm libraries available for Java en C.


The Java syntax definition in SDF is part of the JavaFront package:
http://www.stratego-language.org/Stratego/JavaFront


Cheers,
Martin Bravenboer


Post a followup to this message

Return to the comp.compilers page.
Search the comp.compilers archives again.