[antlr-interest] grammar for jdk1.5 parameterized types

Anthony W Youngman Anthony.Youngman at ECA-International.com
Fri Sep 19 02:38:45 PDT 2003


I'm going to hit this problem ...

But can't you get the lexer to create eg

">>" will return tokens GT NWGT while
"> >" will return GT GT

So the parser, where it wants >, will accept either GT or NWGT, but if
you actually want >>, then it looks for GT NWGT or possibly NWGT NWGT

Cheers,
Wol

-----Original Message-----
From: mzukowski at yci.com [mailto:mzukowski at yci.com] 
Sent: 18 September 2003 19:57
To: antlr-interest at yahoogroups.com
Subject: RE: [antlr-interest] grammar for jdk1.5 parameterized types


Yep, you're right!

Monty

-----Original Message-----
From: John P N Pybus [mailto:john-yahoo at pybus.org] 
Sent: Thursday, September 18, 2003 11:56 AM
To: antlr-interest at yahoogroups.com
Subject: Re: [antlr-interest] grammar for jdk1.5 parameterized types


mzukowski at yci.com wrote:
> You can't switch your lexer from the parser safely.  ANTLR doesn't 
> work that way (infinite lookahead and all that).  I suggest getting 
> rid of ">>" as a token and making the parser look for '>' '>' as GT.
> 
> Monty

Hmm, with the lexer ignoring Whitespace wouldn't the parser then allow 
"n > > 3" as well as "n >> 3"?

I'd suggest using lookahead in the lexer to define 3 tokens GT_GT, 
GT_EQ, and GT corresponding to a '>' directly followed by another '>'; 
'>' followed by '=' and all other '>' chars, respectively.

You can use ( GT | GT_GT ) in your parser rules for generics, and can 
define the various shift operators as GT_GT GT; GT_GT GT_EQ EQ etc...

I haven't done this with the antlr java grammar myself, but I believe 
I've seen this approach used in other java1.5 recognisers (sorry no 
reference handy).

Hope this makes some sense.

Yours,

John


 

Your use of Yahoo! Groups is subject to
http://docs.yahoo.com/info/terms/ 


 

Your use of Yahoo! Groups is subject to
http://docs.yahoo.com/info/terms/ 





***********************************************************************************

This transmission is intended for the named recipient only. It may contain private and confidential information. If this has come to you in error you must not act on anything disclosed in it, nor must you copy it, modify it, disseminate it in any way, or show it to anyone. Please e-mail the sender to inform us of the transmission error or telephone ECA International immediately and delete the e-mail from your information system.

Telephone numbers for ECA International offices are: Sydney +61 (0)2 9911 7799, Hong Kong + 852 2121 2388, London +44 (0)20 7351 5000 and New York +1 212 582 2333.

***********************************************************************************


 

Your use of Yahoo! Groups is subject to http://docs.yahoo.com/info/terms/ 




More information about the antlr-interest mailing list