[antlr-interest] Re: Newbie Question
Praveen Ray
pray at eagleinvsys.com
Mon Oct 1 14:35:00 PDT 2001
Do u have a corresponding Lexer rule to identify the keywords?
Simply defining tokens in the Parser is not enough until there is
a Lexer rule to recognize the keywords in input stream. Also, the
corresponsing Lexer must have 'testLiteral' option set to true.
Try in Lexer (assuming your keywords begin with $ and Uppercase
Letter ):
KEYWORDS
options
{
testLiterals = true;
}
: '$' ('A'..'Z' | 'a'..'z')+ ;
and in Parser (wherever u need keywords accessed):
my_rule : "$Begin" (..other production elements etc)
Any literal in Parser is automatically a Lexer Keyword so you dont
need 'tokens' section.
Hope this helps.
--- In antlr-interest at y..., harshadpatel at t... wrote:
> Hi All !
> Im new to antlr and I am struggling to get my simple parser working
> my question is How do I write a grammer
> to parse keywords beginning with the dollor character
> e.g
> $BeginA
> $BeginB
> $EndB
> $EndA
>
>
> I've tried to define tokens such as this -->
> tokens
> {
> BEGIN="$Begin";
> END="$End";
> }
>
> But I get
> exception: antlr.TokenStreamRecognitionException: unexpected char: $
>
> When I run the Parser ???
>
> Any suggestions anyone
> Thanks in advance
> Harshad
Your use of Yahoo! Groups is subject to http://docs.yahoo.com/info/terms/
More information about the antlr-interest
mailing list