[antlr-interest] Rewrite rule in Habelitz Java grammar ignored?

Jason Veldicott jasonveldicott at gmail.com
Fri Jul 20 12:19:20 PDT 2012


Apologies, problem resolved, somewhat embarrassingly.

There was a simple mistake in the test rig in which compilationUnit() was
called on the parser rather than javaSource().

Jason


On Fri, Jul 20, 2012 at 12:04 PM, Jason Veldicott
<jasonveldicott at gmail.com>wrote:

> Hi,
>
> I'm trying to get Habelitz's (http://www.habelitz.com<http://www.habelitz.com/index.php?option=com_content&task=view&id=12&Itemid=8>) Java
> grammar running, java.g, and have encountered a problem in which the
> following top-level parser rule:
>
> javaSource
>     :   compilationUnit
>         ->  ^(JAVA_SOURCE compilationUnit)
>
>
> does not produce an AST rooted with JAVA_SOURCE, but instead with a node
> named ANNOTATION_LIST, which comes later in the grammar.  A longer listing
> of the produced AST appears at end of this post.
>
> It seems the rewrite part of this rule is ignored.  I need it not to be,
> otherwise the accompanying JavaTreeParser.g (by Habelitz) results in this
> error:
>
> JavaTreeParser.g: node from line 0:0 mismatched tree node: ANNOTATION_LIST
> expecting JAVA_SOURCE
>
>
> Any suggestion as to what my be going wrong here would be much appreciated.
>
> Thanks
>
> Jason
>
>
> tree=ANNOTATION_LIST (import (. (. java io) File)) (class (MODIFIER_LIST
> public) Test1 (CLASS_TOP_LEVEL_SCOPE (VOID_METHOD_DECL (MODIFIER_LIST
> public) test FORMAL_PARAM_LIST (BLOCK_SCOPE (EXPR (METHOD_CALL (. (. System
> out) println) (ARGUMENT_LIST (EXPR "testing"))))))))
>
null
>      ANNOTATION_LIST
>      import
>           .
>                .
>                     java
>                     io
>                File
>      class
>           MODIFIER_LIST
>


More information about the antlr-interest mailing list