[antlr-interest] A newbie question and is this mailing list a black hole for me?

David Holroyd dave at badgers-in-foil.co.uk
Mon Oct 23 09:06:27 PDT 2006


On Mon, Oct 23, 2006 at 03:46:19PM +0000, Foolish Ewe wrote:
> For my job, I am writing a tool to parse a language, that for
> historical reasons has what I'll call "undelimited strings", which are
> positional string parameters with white space delimiiters.  The
> problem becomes that if the undelimited string has a prefix that
> matches a keyword, then the scanner will call it a keyword and not a
> string (which is understandable but not the behavior I want).

I dunno if this helps you, but in the cases where I had the 'is it a
keyword or an IDENT?' problem, I just dropped the keyword def from the
lexer, and then had a parser rule with a predicate testing the IDENT
value.

e.g. 'namespace' is sometimes a keyword, and sometimes an identifier,
depending on context, so I drop the NAMESPACE definition in the lexer,
and then replace all references to NAMESPACE in the grammar to a
namespaceKeyword rule, defined like this:

namespaceKeyword
	:	{input.LT(1).getText().equals("namespace")}? IDENT
	;

(You could also change the type of the token with a rewrite, if that
were useful for your app.)


Any good?
dave

-- 
http://david.holroyd.me.uk/


More information about the antlr-interest mailing list