[antlr-interest] Newbie Rule Rewrite

xkrebstarx xkrebstarx at gmail.com
Tue Apr 17 12:37:00 PDT 2007


>What do you want thhe output to look like?

I am using ANTLR v3 and I would like the rule to look like this...

rule      ( identifier | b | c | d ) ( '[' subscript ']' | f | g )*
        ;


and the input tokens a[i][j] would give me something like


sub
    sub
        a
        i
    j


The tough part is figuring out how the first set ( a,b,c,d ) and the
second set ( e,f,g ) would be represented in the rewrite. That sounds
a big vague, let me try to explain a little more.

If I do something this

      rule     ( a | b | c | d )
                       ( e  -> ^('sub' a e)
                         | f  -> rewrite
                         | g -> rewrite
                       }*


how do I know what a,b,c or d was used. I get an error.

Or conversely, if I use

rule     ( a | b | c | d ) ( e | f | g )* -> rewrite

how do I know what e,f,g, if any, were used. I have read the
Definitive reference over and over and cannot figure out how to put
this together properly.

Thanx

>>On Mon, Apr 16, 2007 at 11:11:39PM -0400, xkrebstarx wrote:
>> I am stuck on how to rewrite a rule like this. Can anyone help
>>
>> rule     ( a | b | c | d ) ( e | f | g }*


More information about the antlr-interest mailing list