> How could I store value in AS.g and how can AS.g and AStree.g communicate?
> Could you plz give me a small example?
>
Hi Annie
Just define variables in the members section of each grammar.
Here's a general example where parser grammar A.g needs to collect
data which will then be used in tree grammar Bwalker.g
In grammar A.g...
@members {
private List<MyClass> myList = new ArrayList<MyClass>();
public List<MyClass> getList() { return myList; }
}
Then one or more rules in A.g have actions to create MyClass objects
and add them to the list.
In grammar Bwalker.g...
@members {
private List<MyClass> aList;
public void setList( List<MyClass> list ) { aList = list };
}
Now the client code runs AParser and gets the AST and the list...
AParser parser = new AParser(...);
AParser.prog_return r = parser.prog();
CommonTree primaryAST = (CommonTree) r.getTree();
List<MyClass> listFromA = parser.getList();
Then it gives the AST and the list to Bwalker...
CommonTreeNodeStream nodes = new CommonTreeNodeStream(primaryAST);
nodes.setTokenStream(tokens);
BWalker bwalker = new BWalker(nodes);
bwalker.setList( listFromA );
BWalker.start_return r = bwalker.start();
Hope this helps
Michael
List: http://www.antlr.org/mailman/listinfo/antlr-interest
Unsubscribe:
http://www.antlr.org/mailman/options/antlr-interest/your-email-address
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---