[antlr-interest] ANTLR translation - e.g. Java->tree->Java

paul taney paultaney at yahoo.com
Sun Jun 22 06:50:47 PDT 2003


--- Tim Tyler <tt2333 at yahoo.co.uk> wrote:most of the
Java > ...parsers I can see
> strip out comments and white space.  I'm likely to
> be wanting to preserve these as much as possible -
> and maybe have them in the parse tree.
> 

I was attempting something similar and adapted
code from

    antlr-2.7.2/examples/java/preserveWhiteSpace

in the following way

public static void main(String[] args) {
  JavaLexer lexer = new JavaLexer(new
DataInputStream(System.in));
 
lexer.setTokenObjectClass("antlr.CommonHiddenStreamToken");
  filter = new TokenStreamHiddenTokenFilter(lexer);
  filter.hide(JavaRecognizer.WS);
  filter.hide(JavaRecognizer.SL_COMMENT);
  JavaRecognizer parser = new JavaRecognizer(filter);
 
parser.setASTNodeClass("antlr.CommonASTWithHiddenTokens");
  try {
      //rewire the next line for java's root node
      parser.compilationUnit(); 
  }

I'm still working it out, as this is my first antlr
project.  But I think this is on the right track...

Feedback would be appreciated.

paul taney


__________________________________
Do you Yahoo!?
SBC Yahoo! DSL - Now only $29.95 per month!
http://sbc.yahoo.com

 

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




More information about the antlr-interest mailing list