[antlr-interest] Template Rule Help

Feriaman Ole feriaman at hotmail.com
Fri Aug 1 04:36:27 PDT 2008


Hi.



Let me introduce myself, i'm Feriaman, coding for a long time, but using AnTLR for a short time.
AnTLR is great and really easier to use than things like Spirit (which i'm familiar with).



Unfortunately, the documentation i could find is not as great as the tool himself.

That's why i try to get help here.
I really apologise if this isn't the right place to ask help.

My question is : is there a way to factorise thoses grammar rules (maybe some template rule) : 
---------------
singleA returns [A value]:
        TOKENA
        i1=ID {$value = Factory.CreateA($i1.text);}
    ;
singleB returns [B value]:

       TOKENB
        i1=ID {$value = Factory.CreateB($i1.text);}

    ;

objectAList returns [List<A> value]:
    first=singleA 
        {
            $value = new List<A>();
            $value.addValue($first.value);
        }
    (
        ','
        next=singleA {$value.addValue($next.value);}
    )*
    ;


objectBList returns [List<B> value]:

    first=singleB 

        {

            $value = new List<B>();

            $value.addValue($first.value);

        }

    (

        ','

        next=singleB {$value.addValue($next.value);}

    )*

    ;
---------------

Of course, generated function objectAList and objectBList should be different, because one returns a List<A> and the orther returnes a List<B>, so i understand i can't have a single rule (or am i wrong ?), but i suppose there is a way to write thoses two rules as a template rule, isn't it ?

Thanks alot ! 
_________________________________________________________________
Plus besoin de clé usb ! Stockez votre musique en ligne gratuitement !
http://www.windowslive.fr/skydrive/
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.antlr.org/pipermail/antlr-interest/attachments/20080801/486560af/attachment-0001.html 


More information about the antlr-interest mailing list