[antlr-interest] Clarification on documentation
Alexey Demakov
demakov at ispras.ru
Tue Aug 23 07:07:51 PDT 2005
Please note: when you 'Reply' to message from antlr list
it is sent to author, not in list. Use 'Reply all' and remove author :)
val:VALUE works only for tokens not for rules.
You have to return value from 'value' rule and use it such way: val = value
value returns [String res]
: t:THING_ID { res = t.getText(); }
| i:ID { res = i.getText(); }
;
assignment
{
String val = null;
}
: id:ID ASSIGN val = value
{ System.out.println("Assigned: '" + id.getText() + "' val = '" + val + "'" ); }
;
'value' rule also can be implemented as:
value returns [String res]
{
Token t = null;
}
:
{ t = LT(1); res = t.getText(); }
( THING_ID
| ID
)
;
LT(1) is the next token.
It is useful for long alternatives.
Regards,
Alexey
-----
Alexey Demakov
TreeDL: Tree Description Language: http://treedl.sourceforge.net
RedVerst Group: http://www.unitesk.com
----- Original Message -----
From: "Ciaran Treanor" <ciaran.treanor at gmail.com>
To: "Alexey Demakov" <demakov at ispras.ru>
Sent: Tuesday, August 23, 2005 5:49 PM
Subject: Re: [antlr-interest] Clarification on documentation
> Wow. Thanks for that Alexey. It's does seem like quite a lot of code
> to have to put in the grammar. That's fantastic though - you've really
> been a great help. I've got a lot to learn.
>
> I hope you don't mind, but I've got another question. For the
> 'assignment' rule I'd like to print out the 'value'. val:value doesn't
> work - can you show me how to get a handle on the 'value' token?
>
> assignment
> : id:ID ASSIGN value
> { System.out.println("Assigned: '" + id.getText() + "'"); }
> ;
>
> Cheers,
> Ciaran
>
> On 8/23/05, Alexey Demakov <demakov at ispras.ru> wrote:
> > Corrected version of your grammar is attached.
> >
> > Regards,
> > Alexey
> >
> > -----
> > Alexey Demakov
> > TreeDL: Tree Description Language: http://treedl.sourceforge.net
> > RedVerst Group: http://www.unitesk.com
> >
> >
> > ----- Original Message -----
> > From: "Ciaran Treanor" <ciaran.treanor at gmail.com>
> > To: "Alexey Demakov" <demakov at ispras.ru>
> > Sent: Tuesday, August 23, 2005 5:03 PM
> > Subject: Re: [antlr-interest] Clarification on documentation
> >
> >
> > Hi Alexey,
> >
> > > Do you want to qualify Thing456 as ID instead of THING_ID
> > > if Thing456 was not defined? You can check for it in code:
> >
> > I don't want to do this - but I didn't know you could do that so thanks!
> >
> > I've written up a test case and attached it to this mail. The current
> > error I'm getting is:
> > Exception in thread "main" line 9:8: unexpected char: 'D'
> > at com.ct.test.TestLexer.nextToken(TestLexer.java:113)
> > at antlr.TokenBuffer.fill(TokenBuffer.java:69)
> > at antlr.TokenBuffer.LA(TokenBuffer.java:80)
> > at antlr.LLkParser.LA(LLkParser.java:52)
> > at com.ct.test.TestParser.systemBlock(TestParser.java:102)
> > at com.ct.test.TestParser.testFile(TestParser.java:71)
> > at com.ct.test.TestParser.main(TestParser.java:27)
> >
> > Any ideas?
> >
> > Cheers,
> > ct
> >
> >
> >
>
More information about the antlr-interest
mailing list