[antlr-interest] a grammar problem

Jim Idle jimi at temporal-wave.com
Sun Dec 13 10:14:23 PST 2009


It might be better to lex just one token here and not worry about what characters are in it. Then check it semantically. You will then get errors like "#z is not a vlaid exactness sequence", instead of the lexer saying "Unexpected character 'z'". I see the original question was answered so I won't repeat the answer.
 
Jim
 
From: antlr-interest-bounces at antlr.org [mailto:antlr-interest-bounces at antlr.org] On Behalf Of Hans-Martin Adorf
Sent: Sunday, December 13, 2009 5:21 AM
To: antlr-interest at antlr.org
Subject: [antlr-interest] a grammar problem
 
Hi Folks,

here is an excerpt on a SchemeNumber grammar which is part of a Scheme grammar that I am toying with.

grammar SchemeNumber;
tokens {
    HASH = '#' ;
}
prefix2        : RADIX2 EXACTNESS?
        | EXACTNESS? RADIX2
        ;       
RADIX2        : HASH ('b'|'B');
EXACTNESS    : HASH ('i'|'I'|'e'|'E');

The problem is in rule 'prefix2' since token RADIX2 can be matched in two different ways. Scheme requires that I am able to state the following prefixes:

"#b", "#e#b" and "#b#e". 

The radix description is mandatory whereas the exactness is optional, and can come before ore after the radix description. 

Any idea how to change the grammar above so that ANTLR no longer complains and disables alternatives?

Thanks.
Hans-Martin


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


More information about the antlr-interest mailing list