[antlr-interest] Re: Bug in c# case-insensitive lexer
tdjastrzebski
tdjastrzebski at yahoo.com
Wed Jul 2 17:09:10 PDT 2003
Since you mentioned forthcoming service release
I am sure you realize this by now, but just in case
Exceptions in .Net Framework are really meant to be used only in
exceptional situations. In another words, although just having an
exception handler costs virtually nothing, handling exceptions is a
HUGE performance hit.
I mentioned that because browsing Antlr generated code as well as the
runtime I notice exceptions often being used more for convenience and
form, but not necessary for efficiency.
Good example is CharScanner.testLiteralsTable() method. Using
exception handler instead of testing if hashtable contains particular
key makes code run about twice faster but ONLY if the key IS found.
If the key is not found handling the exception slows down release
code execution about 25 times compared to a version checking first if
the key exists and if so pulling the appropriate object. 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;
}
}
Also throwing MismatchedTokenException in Parser.match() (to
initialize backtracking, I guess) while performing syntactic
predicate does not seem to be the best possible approach. In
development debug environment it slows down parse time of a short
text from a fraction of a second to several seconds. 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.
Regards,
Tom Jastrzebski
> Thanks for the report Tom,
>
> This issue has already been fixed. I'll arrange a service release
for
> the C# bits as soon as schedule permits.
>
> Cheers,
>
> Micheal
> ANTLR/C# codegen
>
> > So appropriate line in lexer should read:
> >
> > literals = new Hashtable( new
> > System.Collections.CaseInsensitiveHashCodeProvider(), new
> > System.Collections.CaseInsensitiveComparer());
> >
> > instead of:
> >
> > literals = new Hashtable( new
> > System.Collections.CaseInsensitiveHashCodeProvider(), null);
> >
> > Which should be corrected in line 1252 of
CSharpCodeGenerator.java
> > file.
> >
> > Regards,
> > Tom Jastrzebski
Your use of Yahoo! Groups is subject to http://docs.yahoo.com/info/terms/
More information about the antlr-interest
mailing list