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

mzukowski at yci.com mzukowski at yci.com
Thu Sep 18 11:22:15 PDT 2003


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

-----Original Message-----
From: Ernest Pasour [mailto:sasecp at wnt.sas.com] 
Sent: Thursday, September 18, 2003 7:16 AM
To: antlr-interest at yahoogroups.com
Subject: [antlr-interest] grammar for jdk1.5 parameterized types


I'm trying to expand an existing java grammar to handle the parameterized
types supported in jdk1.5.  The problem is that a parameterized type like
the following:
	"class Seq<Pair<String>>"
introduces an ambiguity in the grammar.  The natural way to write the parser
uses ">" to match the closing angle brackets.  However, in this case, SR
(">>") is matched by the lexer instead of two GT (">").  What I would like
to be able to do is to detect *from the parser* that I need to change to a
special parameter lexer when I see the first '<' (LT) symbol.  The examples
I've found all seem to switch lexers in the lexer, based on lexer
information.  If I use the parser, then I have to push lookahead tokens back
onto the token stream so that the parameter lexer can process them (I
assume).

	Is token stream multiplexing an appropriate solution to my problem?
There appears to be a way I can rewrite the grammar to avoid this issue, but
it's pretty disgusting.

Thanks for any suggestions,
Ernest

 

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/ 




More information about the antlr-interest mailing list