[antlr-interest] Question on tree parsers

Julian Santander jsantander at alcatel-lucent.com
Wed Jan 24 00:47:39 PST 2007


Folks,

  I hope you can help me with this one. I'm working with antlr v3
(currently the version directly from the source code repository, aka
pre-beta6) with Java output.

  I've got a grammar for an internal language working fairly well, but
now I'd like it to split the processing in two, one producing the AST,
and then a tree parser to process the AST and do more things.

  Among other things I've got in the Parser rules like this:

formal_parameter:
	ident_simple_type
	| ident_simple_type T_EQUAL expression   -> ^(ident_simple_type 
^(DEFAULT_VALUE expression))
	;

ident_simple_type:	
	memberName
	| T_IDENT simple_type -> ^(T_IDENT simple_type)


    This produces AST like:

(argument
  (REFTYPE
   (NAME typeName)))

or

(argument
  (REFTYPE
   (NAME typeValue))
  (DEFAULT_VALUE value))


    My question is how do I match this kind of AST production on the
TreeParser. So far the rules I've written is like:

formal_parameter:
        ident_simple_type
        | ^(ident_simple_type ^(DEFAULT_VALUE expression))
	;

ident_simple_type:	
	memberName
	| ^(T_IDENT simple_type)


    ... but they do not seem to work. My guess is that the  ^ seems to
carry different meaning, On tree rewrite it means "add this subtree one
level below", while on tree parsing is associated the UP and DOWN
tokens.....?¿?¿?

    Thanks very much in advance and best regards

       Julian




More information about the antlr-interest mailing list