[antlr-interest] Re: another nondeterminism question
Adrian Sandor
aditsu at yahoo.com
Wed Jul 16 12:29:57 PDT 2003
wow, this really worked! thanks a lot! I had tried many things but I
didn't try to parse B and setType for it in the S rule, till I read
your message
if you say the example is very abstract, then how about this sample:
protected NLCHAR0: '\r'|'\n';
protected NLCHAR: NLCHAR0 | ("//")=>COMM | '/' {$setType(SLASH);};
protected NNLWSCHAR: ' ' | '\t';
protected WSCHAR: NNLWSCHAR | NLCHAR;
NNLWS: (NNLWSCHAR)+;
NLWS: NLCHAR (WSCHAR)*;
protected COMM: "//" (~('\r'|'\n'))* NLCHAR0;
(NL=newline, NNL = non-newline; WS=whitespace)
now it works, thanks to you :)
Adrian
--- In antlr-interest at yahoogroups.com, mzukowski at y... wrote:
> In fact you may need a syntactic predicate because of the linear
> approximation issue:
>
>
> S: ('a'|"bb")=>('a' | "bb")+
> | 'b' {$setType(B);}
> ;
>
> Let me know, I don't have time to try it out right now.
>
> Monty
> -----Original Message-----
> From: mzukowski at y... [mailto:mzukowski at y...]
> Sent: Wednesday, July 16, 2003 11:46 AM
> To: antlr-interest at yahoogroups.com
> Subject: RE: [antlr-interest] Re: another nondeterminism question
>
>
> OK, this is an linear approximation issue. If you had A:"aa"
| "bb" things
> would work. This example is very abstract. I would code it like
this:
>
> S: ('a' | "bb")+
> | 'b' {$setType(B);}
> ;
>
> Look up linear approximation in the FAQ & archives.
>
> Monty
> -----Original Message-----
> From: Adrian Sandor [mailto:aditsu at y...]
> Sent: Wednesday, July 16, 2003 11:26 AM
> To: antlr-interest at yahoogroups.com
> Subject: [antlr-interest] Re: another nondeterminism question
>
>
> ok, I tried with the following grammar:
>
> class l1 extends Lexer;
> options{k=2;}
> protected A: 'a' | "bb";
> B: 'b';
> S: (A)=>(A)+;
>
> and I got:
>
> ANTLR Parser Generator Version 2.7.2 1989-2003 jGuru.com
> t1.g: warning:lexical nondeterminism between rules B and S upon
> t1.g: k==1:'b'
> t1.g: k==2:<end-of-token>
> t1.g:5: warning:Syntactic predicate ignored for single alternative
>
>
> Adrian
>
> --- In antlr-interest at yahoogroups.com, mzukowski at y... wrote:
> > That's a weird bug you ran into, I think. It should give warnings
> in both
> > cases. You could solve this with a syntactic predicate:
> >
> > S: (A)=>(A)+;
> >
> > -----Original Message-----
> > From: Adrian Sandor [mailto:aditsu at y...]
> > Sent: Friday, July 11, 2003 9:54 AM
> > To: antlr-interest at yahoogroups.com
> > Subject: [antlr-interest] another nondeterminism question
> >
> >
> > why do I get a nondeterminism warning for this grammar:
> >
> > class l1 extends Lexer;
> > options{k=2;}
> > protected A: 'a' | "bb";
> > B: 'b';
> > S: (A)+;
> >
> > but I don't get any warning when I change S to:
> >
> > S: A (A)+;
> >
> > and how can I solve it for the first case?
> > I tried many things but to no avail...
> >
> > thanks
> > Adrian
Your use of Yahoo! Groups is subject to http://docs.yahoo.com/info/terms/
More information about the antlr-interest
mailing list