[antlr-interest] a grammar problem

Hans-Martin Adorf dradorf at googlemail.com
Sun Dec 13 08:38:11 PST 2009


Hi,

thanks, the trick with leaving out one of the question marks does the job.

An no, blanks are not permitted between #b and #e, since these character
sequences are prefixes for binary numbers in Scheme (#b signifies a binary
number, #e an exact number).

How can I switch off spaces?

Regards
Hans-Martin

On Sun, Dec 13, 2009 at 3:16 PM, John B. Brodie <jbb at acm.org> wrote:

> Greetings!
> On Sun, 2009-12-13 at 14:20 +0100, Hans-Martin Adorf wrote:
> > 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?
>
> perhaps (untested)....
>
> prefix2 : RADIX2 EXACTNESS? | EXACTNESS RADIX2 ;
>
>
> (as an aside, are you sure you want to do this in the parser? does your
> lexer ignore whitespace? if so, does scheme permit whitespace between
> the radix and exactness tokens? because your lexer would accept that.)
>
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.antlr.org/pipermail/antlr-interest/attachments/20091213/4985f1d9/attachment.html 


More information about the antlr-interest mailing list