[antlr-interest] AST transformation for sequence of statements

Viktor Lioutyi Viktor_Lioutyi at i2.com
Mon Jun 15 09:05:08 PDT 2009


Hi,

I am writing a prototype of converter from one language (TSL of WinRunner) to another (VB script of QTP).

One of the task includes identification of statement sequence similar to one below

int i = 0;
A[i++] = e1;
A[i++] = e2;
...
A[i++] = eN;

and rewriting it to something like that (the code may be not exact, but the idea should be clear)

Dim A(20)
A(0) = e1
A(1) = e2
...
A(20) = e20

I am trying to solve this task by using AST rewrites.

I tried to use pattern matching (with options output = AST; filter = true; rewrite=true;), but was not able to make pattern matching to recognize sequence of nodes. Option greedy=true on the rule did not help. My conclusion was that pattern matching could only works with a tree, not sequence of trees. Please let me know if I am mistaken here. Will it work with syntactic predicate?

I did not try AST rewrite option without filter yet. Is it the right way?

Could somebody give me some hints how to come to resolution of this task using ANTLR? 

I have limited experience with ANTLR and any help would be appreciated.
 
Thanks in advance,
Viktor


More information about the antlr-interest mailing list