[antlr-interest] Beginner's problem

Vaphel vaphel at op.pl
Fri Aug 19 01:12:57 PDT 2005


Hello,
 
I think I should do it in the TreeParser but I don't know how. I try 
to explain it in this way:
 
-----------------------------------------------------------
class MyLexer extends Lexer;
A: 'a';
B: 'b';
C: 'c';
D: 'd';
----------------------------------------------------------
class MyParser extends Parser;
options{buildAST = true;}
start: A^ end ;
end: B | C ;
-------------------------------------------------------
class MyTreeWalker extends TreeParser;
options{buildAST = true;}
start: #(A (B | C));
----------------------------------------------------
 
So my program accept expresion 'ab' or 'ac'.
Now I need in TreeParser to add a token D after every token A (so when an input of TreeParser is 'ab' I want an output 'adb' and when an input is 'ac' I want an output 'adc').
 
And the 2nd case (a little different Parser and TreeParser) - how to remove in TreeParser a token (e.g. when as an input I have 'adc' I want to have as an output 'ac' etc.).
 
Maybe it's very simple but I couldn't find a method to add or remove node while I traverse in TreeParser a tree built in Parser. 
And when I tried to write it by myself it didn't work.

Thank you for every advise.
 
Regards,
Vaphel


Tekst oryginalnej wiadomości:
Od: Bryan Ewbank <ewbank at gmail.com>
Do: ANTLR Interest <antlr-interest at antlr.org>
Temat: Re: [antlr-interest] Beginner's problem
Data: 2005-08-15 20:02:55

BE> I don't understand the question.  You talk about tree walker, but then
BE> ask a question (I think) about scanner/lex operations.

BE> If you are processing a tree of:

BE>    #(FUNC function a1 a2 ... )

BE> you can do something like this to add the intermediate node:

BE>    a: #(FUNC nm ( arg )* );
BE>    arg: old_arg { ## = #( #[QUOTE,"'"], ##); };

BE> ---------

BE> If you are attempting to change the sequence of tokens scanned from

BE>    NAME LEFTPAREN NAME COMMA NAME ... RIGHTPAREN

BE> into

BE>    NAME LEFTPAREN QUOTE NAME QUOTE COMMA ... QUOTE RIGHTPAREN

BE> Then I'll have to leave it for others, as I don't use an antlr lexer...

BE> On 8/14/05, vaphel at op.pl <vaphel at op.pl> wrote:
>> I'm writing a tree walker and I try my tree walker modify an expresion:
>> function(arg1, arg2, arg3) to function('arg1','arg2','arg3') but I don't
>> know, how I can do it.
>> 
>> I tried to add a node QUOT (='\'') after a current node equal "("and ","
>> and before ")" and "," but I can't find a method which can insert a node
>> between current and next node.

Wiadomość wysłana przez program DRACO ORGANIZER http://www.dshome.pl



More information about the antlr-interest mailing list