[antlr-interest] A newbie question and is this mailing list ablack hole for
Foolish Ewe
foolishewe at hotmail.com
Mon Oct 23 10:24:06 PDT 2006
David:
Thanks for the reply, I appreciate it!
Regarding the keyword recognition, the language specifies what I call
"keyword completion",
so that if say "namespace" was a keyword and I wanted to recognize "names",
"namesp", ...,
"namespace", then in the lexer to recognize the token I do:
NAMESPACE: "names" ('p' ('a' ('c' ('e')?)?)?)?;
I suspect I may need to roll a comparison method to allow for completion
matching.
I hadn't really considered your approach, I guess I could push the keyword
recognition
back on the parser (although I wonder about the performance hit and how to
generate
meaningful error messages). Off the top of my head, I can't see a show
stopper in this
approach, but I want to think a bit before I try this transformation.
Thanks Again:
Bill M.
>From: David Holroyd <dave at badgers-in-foil.co.uk>
>To: antlr-interest at antlr.org
>Subject: Re: [antlr-interest] A newbie question and is this mailing list
>ablack hole for me?
>Date: Mon, 23 Oct 2006 16:06:27 +0000
>
>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/
_________________________________________________________________
Try the next generation of search with Windows Live Search today!
http://imagine-windowslive.com/minisites/searchlaunch/?locale=en-us&source=hmtagline
More information about the antlr-interest
mailing list