[antlr-interest] Re: Bug in c# case-insensitive lexer
micheal_jor
open.zone at virgin.net
Wed Jul 2 18:12:27 PDT 2003
> Since you mentioned forthcoming service release
> I am sure you realize this by now, but just in case
> Good example is CharScanner.testLiteralsTable() method.
<SNIP>
> Sample solution:
>
> public virtual int testLiteralsTable(int ttype)
> {
> string key = text.ToString();
>
> if (literals.ContainsKey(key)) {
> return (int) literals[key];
> } else {
> return ttype;
> }
> }
>
> public virtual int testLiteralsTable(string someText, int ttype)
> {
> if (literals.ContainsKey(someText)) {
> return (int) literals[someText];
> } else {
> return ttype;
> }
> }
Thanks again Tom for you comments. This is what those functions look
like at the moment:
public virtual int testLiteralsTable(int ttype)
{
string tokenText = text.ToString();
if ( (tokenText == null) || (tokenText == string.Empty) )
return ttype;
else
{
object typeAsObject = literals[tokenText];
return (typeAsObject == null) ? ttype : ((int) typeAsObject);
}
}
public virtual int testLiteralsTable(string someText, int ttype)
{
if ( (someText == null) || (someText == string.Empty) )
return ttype;
else
{
object typeAsObject = literals[someText];
return (typeAsObject == null) ? ttype : ((int) typeAsObject);
}
}
> Also throwing MismatchedTokenException in Parser.match() (to
> initialize backtracking, I guess) while performing syntactic
> predicate does not seem to be the best possible approach.
I'm not sure there is an issue here but either way this is one for
ANTLR v3 I'm afraid. Unless I receive a good patch for an alternate
design... ;-)
> But I am too new to Antlr to dare to suggest anything.
>
> Besides that I am really looking forward for future versions
> of this truly good tool.
;-)
Cheers,
Micheal
ANTLR/C#
Your use of Yahoo! Groups is subject to http://docs.yahoo.com/info/terms/
More information about the antlr-interest
mailing list