Hi,

I submitted this post before, but in a wrong discussion thread. Sorry for the 
mess. I am resubmitting this post in a new thread with additional information.


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

One of the tasks 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 this (the code may be not exact, but the 
idea should be clear)

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

In my version of AST the tree rewrite may look something like this.

tree grammar TSLrewriteArray;

options {
    tokenVocab = TSL;
    ASTLabelType = CommonTree;
    output = AST;
    filter = true;
    rewrite = true;
}

topdown

   :    ^(EXPRESSION_STATEMENT ^(ASSIGN ID INT)) ( ^(EXPRESSION_STATEMENT 
^(ASSIGN ^(INDEX ID ^(INC_AFTER ID)) e=. )) )+
        -> ... result tree here...
        ;

I was not able to make AST tree rewrites to work directly. I think that the 
reason is that tree rewrites are based on a tree visitor pattern. The pattern 
assumes that only one node at a time may be visited and changed, while here I 
need to change sequence of nodes with arbitrary length. The replacement is also 
a sequence of nodes and potentially of different length (it could always be 
presented as one node by adding an artificial root to a sequence, but I prefer 
sequence).

The generated recognizer is capable of properly doing pattern matching. Seems 
like I only need to create an appropriate visitor that understands that more 
than one node may be visited and replaced. I do not know yet if this could be 
done, if I will encounter other issues, for example with rollbacks.

Has anybody encountered such a problem? Am I following the right approach?

I have limited experience with ANTLR and any help would be appreciated.

Thanks in advance,
Viktor


--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---

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

Reply via email to