[antlr-interest] repeating the parsing of a subtree

Claude Moulin claude.moulin at hds.utc.fr
Thu Nov 5 06:19:32 PST 2009


Hello,
First a remark: AntLRWorks doesn't display correctly the graph of a rule
containing the . meta-character.
I have found two solutions:
1) Create a tree based interpreter (see p 245 of Terence's last book -
very interesting book)
2) Create a specific walker and launch the rule able to parse the list
tree:

For the tree
^(REPEAT a = atom list = .)

I create the following code:
{
  for (int i = 0; i < $a.r ; i++) {
    CommonTreeNodeStream nodes = new CommonTreeNodeStream(liste);
    MyTreeWalker walker = new MyTreeWalker(nodes); // the same class as
the one generated.
    walker.list_instructions();
  }
}

I am not completely satisfied. 
Claude
------------------------------

Message: 11
Date: Sat, 24 Oct 2009 20:09:17 +0200
From: "Claude Moulin" <claude.moulin at hds.utc.fr>
Subject: [antlr-interest] repeating the parsing of a subtree
To: <antlr-interest at antlr.org>
Message-ID: <3402BD9F2C1434438EF1F319BE558FBB01258E7B at xena.ad.utc>
Content-Type: text/plain; charset="us-ascii"

I never had a good solution to the problem that I resolved before using
(or rendering public) the getNodeIndex method of the
CommonTreeNodeStream

class.

I have the following tree:

^(REPEAT a = atom list = .)

Where list can be parsed with a specific rule: list_instructions. 

atom returns an integer giving the number of times (maybe 0) the list of
instructions has to be executed.

The semantics of the instruction is then clear.

In the previous version of antlr I used the following interpreting Java
code:

{

 for (int i = 0; i < $a.r ; i++) {

   push(list);

   list_instructions();

   pop();

}

Where push and pop method are added to the tree parser:

private void push(CommonTree tree) {

 int n = ((CommonTreeNodeStream)input).getNodeIndex(tree);

 if (n >= 0)

   ((CommonTreeNodeStream)input).push(n);

}

private void pop() {

     ((CommonTreeNodeStream)input).pop();

  }

In version 3.2 CommonTreeNodeStream has been updated and I no longer
understand how to parse a subtree of the AST when it is needed and
possibly several times. The problem was to find the index of a Tree root
in the AST representation.

 

Can someone give the solution?

Thank you

Claude 

 

-------------- next part --------------
An HTML attachment was scrubbed...
URL:
http://www.antlr.org/pipermail/antlr-interest/attachments/20091024/01eb9
5ff/attachment-0001.html 

------------------------------

_______________________________________________
antlr-interest mailing list
antlr-interest at antlr.org
http://www.antlr.org/mailman/listinfo/antlr-interest

End of antlr-interest Digest, Vol 59, Issue 25
**********************************************


More information about the antlr-interest mailing list