Sorry, I did not see that list thing, but I was trying to get you on the
right track.

First, don't use literals
Put the tokens in subrules
Change the token type in subrule (I usually just set the type field in the
token, but that is a bit of a cheat)
I don't have time to test every code snippet that I post here


x: t1+=void (t2+=star)* -> ^(LIST $t1 $t2*) ;

void: t=VOID -> TYPE[$t];
stat: t=STAR -> TYPE[$t];

VOID: 'void';
STAR: '*';

Jim



> -----Original Message-----
> From: antlr-interest-boun...@antlr.org [mailto:antlr-interest-
> boun...@antlr.org] On Behalf Of Christian
> Sent: Wednesday, October 19, 2011 2:24 PM
> To: antlr-interest@antlr.org
> Subject: Re: [antlr-interest] Rewriting a list of tokens to a list of
> custom tokens
>
> No, your solution still generates invalid java code for me. Did you
> test your solution? The TYPE token does not accept a list as parameter.
> It is a simple token defined within the token block at the top of the
> grammar.
> It seems that the construction of an implicit list is only possible for
> rules and read token within the rule, but not for imaginary tokens. I
> hope I am wrong.
>
> Please make more solution suggestions.
>
> Am 19.10.2011 17:40, schrieb Jim Idle:
> > t1+='void' (t2+='*')* -> ^(LIST TYPE[$t1]+ TYPE[$t2]+)
> >
> > By interpolating from your question. At least, that should get you on
> > the right track.
> >
> >
> > Jim
> >
> >> -----Original Message-----
> >> From: antlr-interest-boun...@antlr.org [mailto:antlr-interest-
> >> boun...@antlr.org] On Behalf Of Christian
> >> Sent: Wednesday, October 19, 2011 5:40 AM
> >> To: antlr-interest@antlr.org
> >> Subject: [antlr-interest] Rewriting a list of tokens to a list of
> >> custom tokens
> >>
> >> Hello ANTLR community,
> >>
> >> I want to get
> >>
> >>     t+='void' (t+='*')*
> >>
> >> to a list of a custom token type, say TYPE. That is, each
> >> element/token of the list should change its original type to the
> type TYPE.
> >> The following approach does not work because invalid java code is
> >> generated:
> >>
> >>     t+='void' (t+='*')* -> ^(TYPE[$t]+)
> >>
> >> The following implicit list generation works fine, however each
> >> element retains its original type:
> >>
> >>     t+='void' (t+='*')* -> ^($t+)
> >>
> >> Can anyone tell me, whether and how this could be done?
> >>
> >> Thanks in advance,
> >> Christian
> >>
> >> List: http://www.antlr.org/mailman/listinfo/antlr-interest
> >> Unsubscribe:
> >> http://www.antlr.org/mailman/options/antlr-interest/your-
> >> email-address
> > List: http://www.antlr.org/mailman/listinfo/antlr-interest
> > Unsubscribe:
> > http://www.antlr.org/mailman/options/antlr-interest/your-email-
> address
> >
>
>
> List: http://www.antlr.org/mailman/listinfo/antlr-interest
> Unsubscribe: http://www.antlr.org/mailman/options/antlr-interest/your-
> email-address

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

-- 
You received this message because you are subscribed to the Google Groups 
"il-antlr-interest" group.
To post to this group, send email to il-antlr-inter...@googlegroups.com.
To unsubscribe from this group, send email to 
il-antlr-interest+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/il-antlr-interest?hl=en.

Reply via email to