[antlr-interest] Error on Defining a syntactic predicate

Hensley, Richard richard.hensley at mckesson.com
Thu Oct 3 11:49:38 PDT 2002


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/>  

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.antlr.org/pipermail/antlr-interest/attachments/20021003/f6c2fe20/attachment.html


More information about the antlr-interest mailing list