Hi,
I need to embed actions in a tree parser for an old specific domain
language which
uses unconditional jumps like "GOTO" statements.

I've made two rules in my tree parser:
The first save the label node into a map called labels
The second rule should retrieve the index of that node in order to
jump on the node stream.
-------------------------
@members {
//global labels
public Map labels;
}

//goto labels
label   :       ^(LABEL li=labelItem lineTerminator)
                { //salvataggio nodo della label
                        CommonTree labelNode = null;
                        CommonTreeNodeStream stream = (CommonTreeNodeStream) 
input;
                        labelNode = (CommonTree) $label.start.getChild(0);
                        if (labelNode != null)
                        {
                                labels.put(new String($li.text),labelNode);
                        }
                }
        ;




        //unconditional jump
jump    :       ^(JUMP l=labelItem lineTerminator)
                {
                        CommonTree labelNode = null;
                        CommonTreeNodeStream stream = (CommonTreeNodeStream) 
input;
                        labelNode = (CommonTree) $jump.start.getChild(0);
                        if (labelNode != null)
                        {
                                String labelName = $l.text;
                                CommonTree jumpNode = (CommonTree) 
labels.get(labelName);
                                if (jumpNode != null)
                                {
                                stream.push(stream.getNodeIndex(jumpNode));
                                }
                        }
                }
        ;

//lineTerminator rule omitted
---------------
The problem I'had is about accessing "getNodeIndex" method of
CommonTreeNodeStream class.
That method is "protected" and code generated does not compile:
getNodeIndex(java.lang.Object) has protected access in
org.antlr.runtime.tree.CommonTreeNodeStream

How can I avoid this problem??

Are examples like this :
http://groups.google.it/group/il-antlr-interest/browse_thread/thread/b2a29d672b603e57/

still working?

I used antlr 3.1.1 and antlrWorks 1.2.2
Target language Java.

Thanks in advance.

Giovanni

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"il-antlr-interest" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/il-antlr-interest?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to