[antlr-interest] imaginary node problem

Piper, Martin Martin.Piper at qg.com
Wed Sep 22 09:46:09 PDT 2010


Something seems to be missing in your rules, I assume ROOT_NODE and RULE_NODE are both imaginary nodes?
Also 
rule: appears somewhere in the filter rule?

But When you have in your rewrite rules
rule: SOME stuff IN here ->^(IMAGINARY_NODE_A IMAGINARY_NODE_B)

Two new imaginary nodes are created and inserted into the tree, You can't reference these imaginary nodes directly in the parent rule. The parent rule references the rule that creates these instead.

What I think you are trying to do though:

parent: (child)* EOF -> ^(ROOT_NODE child*);

child: SOME stuff IN here -> ^(RULE_NODE stuff)


on in particular in your case: (I'm cutting out the middle stuff that I don't know about)

input: (rule)* EOF ->^(ROOT_NODE rule*);

rule
  : L_SQ_B ANNT (ra=ON | ra=OFF) R_SQ_B COLON RULE L_SQ_B d=DIGITS* R_SQ_B
WS* curlyblock
  -> ^(RULE_NODE $ra)
  ;

This will create a tree of the form:

(ROOT_NODE(RULE_NODE $ra)(RULE_NODE $ra)(RULE_NODE $ra)...)


-----Original Message-----
From: antlr-interest-bounces at antlr.org [mailto:antlr-interest-bounces at antlr.org] On Behalf Of Damir Franusic
Sent: Tuesday, September 21, 2010 5:38 PM
To: antlr-interest at antlr.org
Subject: [antlr-interest] imaginary node problem

First of all Hi to everybody, This is my first email here, I have just
recently started using ANTLR. I'm working on some DSL and since i haven't
got any experience with antlr, i have stumbled across some issues.
I am trying to use "rewrite rules" to create a nice two dimensional AST. I
have declared couple of imaginary nodes but what happens is when i for
example do something like:

rule
  : L_SQ_B ANNT (ra=ON | ra=OFF) R_SQ_B COLON RULE L_SQ_B d=DIGITS* R_SQ_B
WS* curlyblock
  -> ^(RULE_NODE $ra)
  ;


This create an imaginary node and then on the outer rule(the one that gets
called last) i am trying to add a root node and assign this RULE_NODE to
that root node:

input
  : (filter)* EOF
  -> ^(ROOT_NODE RULE_NODE)
  ;


..and after this I end up with ROOT_NODE and just a new/blank RULE_NODE. How
do these nodes work? Do they oney work once and get rewritten when you use
them twice? You get my point I hope

Thanks,
Damir

List: http://www.antlr.org/mailman/listinfo/antlr-interest
Unsubscribe: http://www.antlr.org/mailman/options/antlr-interest/your-email-address


More information about the antlr-interest mailing list