[antlr-interest] simple question on V2 grammar

Jim Idle jimi at temporal-wave.com
Tue Oct 9 14:29:14 PDT 2007


You want:

 

AND : ‘and’;

 

I believe. And your Letter rule matches lower case only, but the sample you
gave has upper case.

 

Hope this helps,

 

Jim

 

From: antlr-interest-bounces at antlr.org
[mailto:antlr-interest-bounces at antlr.org] On Behalf Of Nagesh, Harsha
Sent: Tuesday, October 09, 2007 2:21 PM
To: antlr-interest at antlr.org
Subject: [antlr-interest] simple question on V2 grammar

 

Hi - Can anybody please help me in this simple grammar ?

 

My language consists only of Letters (a..z) and a few tokens ("and", "or").
I am trying to match an expression "A and B" using the following

 

Parser

---------

myOp:

            atom (AND atom)*

       ;

 

atom: Letter

        ;

 

Lexer

-------

 

tokens { AND = "and";}

Letter: 'a'..'z'

 

 

When I feed the expression "A and B" to this, the parser fails. The second
token, Instead of matching with AND, matches with Letter and thus fails....I
am not sure how can I fix this ? I tried to use syntactic predicate 

 

myOp:

            (atom AND) => atom (AND atom)*

       ;

 

but antlr ignored it when generating the code saying that syntactic
predicate not required when only one alternative exists...

 

Can anybody please help

 

Thanks

Harsha

 

============================================================================
==
Please access the attached hyperlink for an important electronic
communications disclaimer: 
 
http://www.credit-suisse.com/legal/en/disclaimer_email_ib.html
============================================================================
==

 

No virus found in this incoming message.
Checked by AVG Free Edition.
Version: 7.5.488 / Virus Database: 269.14.5/1058 - Release Date: 10/8/2007
4:54 PM


No virus found in this outgoing message.
Checked by AVG Free Edition. 
Version: 7.5.488 / Virus Database: 269.14.5/1058 - Release Date: 10/8/2007
4:54 PM
 
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.antlr.org/pipermail/antlr-interest/attachments/20071009/7cf52537/attachment.html 


More information about the antlr-interest mailing list