[antlr-interest] Parsing Java: Missing parenthesis in AST for variable declaration?

Vidar Håkestad vidar at hawkis.com
Tue Jan 24 15:31:36 PST 2006


Hello.

I'm using one of the Java 1.5 parsers provided on the antlr home page.
In all of these grammars, there is a rule for handling declarations of 
variables specified like this:

variableDeclarator![AST mods, AST t]
	: id:IDENT
	  d:declaratorBrackets[t]
	  v:varInitializer
	  {
	    #variableDeclarator = 
#(#[VARIABLE_DEF,"VARIABLE_DEF"], mods,#(#[TYPE,"TYPE"],d), id, v);
	   System.err.println("Declaration: "+#variableDeclarator.toStringTree());
	   }
	;

(my formatting)
When this rule is applied to the following Java code (which is inside a 
method):

	String[] folders = path.list(new DirFilter()); // Find all folder entries

The output statement gives:

( VARIABLE_DEF
  MODIFIERS
  ( TYPE ( [ String ) ) folders 
( = ( EXPR ( ( ( . path list )
( ELIST ( EXPR ( new DirFilter ELIST ) ) ) ) ) ) )

which seems to be missing one closing parenthesis (11 and 10)? Is this 
intended behaviour, or is there some problem with the grammar?

Regards,
Hawkis


More information about the antlr-interest mailing list