[antlr-interest] Error on Defining a syntactic predicate
Terence Parr
parrt at jguru.com
Thu Oct 3 13:09:55 PDT 2002
I think i have this all cleaned up in my dev branch...gotta find time
to pull that all in.
Ter
On Thursday, October 3, 2002, at 12:54 PM, tracey meng wrote:
> Richard,
>
> Thanks a lot. I'll fix it.
>
> Tracey
>
> --- "Hensley, Richard" <richard.hensley at mckesson.com>
> wrote:
>> Tracey,
>>
>> Trying putting
>>
>> tokens {
>> AND = "and";
>> OR = "or";
>> }
>>
>> at the top of your parser
>>
>> and removing the AND and OR rules from the lexer.
>>
>> put
>>
>> options {
>> testLiterals=false;
>> }
>>
>> at the top of your lexer
>>
>> change the VARIABLE rule to
>>
>> VARIABLE
>> options {
>> testLiterals=true;
>> }
>> : ('a'..'z'|'A'..'Z'|'_')
>> ('a'..'z'|'A'..'Z'|'_'|'0'..'9')*
>> ;
>>
>> This should treat AND and OR as literals, not
>> variable names.
>>
>> Richard
>> -----Original Message-----
>> From: txm3124 [ mailto:tracey_meng at yahoo.com
>> <mailto:tracey_meng at yahoo.com> ]
>> Sent: Thursday, October 03, 2002 11:34 AM
>> To: antlr-interest at yahoogroups.com
>> Subject: [antlr-interest] Error on Defining a
>> syntactic predicate
>>
>>
>> Can someone help me to fix the definition of Lexer
>> rules of AND and
>> OR? Thanks.
>>
>> I got an error as follows when I compiled the
>> attached ruleParser.g
>> file:
>>
>> C:\Tools\antlr-2.7.1\examples\java\ruleParser>java
>> antlr.Tool
>> ruleParser.g
>> ANTLR Parser Generator Version 2.7.1 1989-2000
>> jGuru.com
>> warning: lexical nondeterminism between rules
>> VARIABLE and AND upon
>> ruleParser.g:0: k==1:'A'..'Z','_','a'..'z'
>> warning: lexical nondeterminism between rules
>> VARIABLE and OR upon
>> ruleParser.g:0: k==1:'A'..'Z','_','a'..'z'
>> warning: lexical nondeterminism between rules AND
>> and OR upon
>> ruleParser.g:0:
>> k==1:<end-of-token>,'A'..'Z','_','a'..'z'
>> warning: found optional path in nextToken()
>> warning: found optional path in nextToken()
>>
>> ---------------------------------------------------
>>
>> class RuleParser extends Parser;
>> options {
>> buildAST = true;
>> }
>>
>> expr
>> : mexpr (OR^ mexpr)* SEMI!
>> ;
>>
>> mexpr
>> : atom (AND^ atom)*
>> ;
>>
>> atom: INT | WORDS
>> ;
>>
>> class RuleLexer extends Lexer;
>>
>> WS : (' '
>> | '\t'
>> | '\n'
>> | '\r')
>> {_ttType = Token.SKIP; }
>> ;
>>
>> LPAREN: '('
>> ;
>>
>> RPAREN: ')'
>> ;
>>
>> SEMI: ';'
>> ;
>>
>> protected
>> DIGIT
>> : '0'..'9'
>> ;
>>
>> INT : (DIGIT)+
>> ;
>>
>> VARIABLE
>> : ('a'..'z'|'A'..'Z'|'_')
>> ('a'..'z'|'A'..'Z'|'_'|'0'..'9')*
>> ;
>>
>> AND
>> : ('A''N''D') =>
>> {$setType(AND);}
>> | VARIABLE
>> {$setType(VARIABLE);}
>> ;
>>
>> OR
>> : ('O''R') =>
>> {$setType(OR);}
>> | VARIABLE
>> {$setType(VARIABLE);}
>> ;
>>
>>
>>
>>
>> Your use of Yahoo! Groups is subject to
>> http://docs.yahoo.com/info/terms/
>> <http://docs.yahoo.com/info/terms/>
>>
>>
>
>
> __________________________________________________
> Do you Yahoo!?
> New DSL Internet Access from SBC & Yahoo!
> http://sbc.yahoo.com
>
>
>
> Your use of Yahoo! Groups is subject to
> http://docs.yahoo.com/info/terms/
>
>
--
Co-founder, http://www.jguru.com
Creator, ANTLR Parser Generator: http://www.antlr.org
Lecturer in Comp. Sci., University of San Francisco
Your use of Yahoo! Groups is subject to http://docs.yahoo.com/info/terms/
More information about the antlr-interest
mailing list