[antlr-interest] Goto instead of exceptions for normal parsing in C#

Mark Pollack Mark.Pollack at codestreet.com
Fri May 5 11:56:17 PDT 2006


Hi,

I'm attaching a reply from my college Aleks Seovic who is most involved
in using Antlr.  The email was mistakenly send directly to Martin.
Anyway, here is a link to a previous discussion on the mailing list that
raised pretty much the same points.
http://www.antlr.org/pipermail/antlr-interest/2005-November/014300.
html  

- Mark

--- <snip> ---

Hi Martin,

As you guessed, it's the latter -- parser itself is not thread-safe
because of the static instancePool_ field within ASTPair class. It is a
pretty big problem for us, because we use Antlr to parse our expression
language, and expression language is used within Spring.NET in many
places: for property names within core IoC framework, for validation
framework, for data binding framework, etc.

We have a static factory method (Expression.Parse), that receives string
expression as a parameter, creates instance of the lexer and parser, and
parses the expression into an AST tree that we use to evaluate
expression. I thought originally this should be thread-safe, as each
call to Expression.Parse creates new instance of both lexer and parser,
but then I found out that *all* instances of ASTPair share the state
because static field is used. This leads to all kinds of collisions and
threading issues within web applications, when multiple request threads
parse data binding expressions for the page, for example.

Right now I solved the problem on our end, by placing a lock on the
whole Expression.Parse method, effectively serializing all expression
parsing, but this is far from the ideal solution because of its
performance and scalability implications. If you can figure out how to
get rid of the shared state and make at least calls to *different*
instances of the parser thread-safe, it would really help us a lot.

On another topic, it would be nice to change parser generator so it
doesn't use exceptions for flow control. Right now, we are getting a lot
of exceptions during parsing as parser tests each alternative in a
grammar, which both affects performance and displays annoying error
messages within Visual Studio debug window.

Finally, not sure if Mark mentioned it or not, it would be nice if
released Antlr binaries were signed ("strongly named"), because right
now we have to sign them ourselves in order to be able to use them from
our code, which is itself in signed assemblies.

Please let us know if these two issues can be fixed in a forseeable
future, or should we even hope that they will be fixed eventually, so we
know where we stand.

Regards,

	Aleks

 

> -----Original Message-----
> From: Martin Probst [mailto:mail at martin-probst.com] 
> Sent: Thursday, May 04, 2006 2:31 AM
> To: Mark Pollack
> Cc: Frank Hileman; antlr-interest at antlr.org
> Subject: Re: [antlr-interest] Goto instead of exceptions for 
> normal parsing in C#
> 
> Hi,
> 
> do you mean you can't run stuff multi threaded *after* 
> parsing or that the generated parser is non-reentrant (e.g. 
> non-threadable)? The latter is a well known fact, the first 
> would be new to me.
> 
> Martin
> 
> Am 04.05.2006 um 06:45 schrieb Mark Pollack:
> 
> > Hi,
> >
> > I'm also keenly interested in that.  There was a thread a while ago 
> > that V3 would improve in this area of C# code generation.  
> How is that 
> > progressing?  Also related is the need we have found (in
> > Spring.NET) to lock at the highest level in order to perform 
> > expression evaluation in a multithreaded environment (i.e. ASP.NET) 
> > due to the use of static variables in the code.  There were 
> some other 
> > reasons leading us in that direction, I'd have to dig up 
> the details.
> >
> > Cheers,
> > Mark
> >
> >
> > ________________________________
> >
> > From: antlr-interest-bounces at antlr.org on behalf of Frank Hileman
> > Sent: Wed 5/3/2006 7:55 PM
> > To: antlr-interest at antlr.org
> > Subject: [antlr-interest] Goto instead of exceptions for normal 
> > parsing in C#
> >
> >
> >
> > Antlr is wonderful!
> >
> > Is there a trick to get Antlr to generate code that uses 
> goto instead 
> > of throwing exceptions for normal parsing (not parse errors), using 
> > the C# generator?
> > The exceptions make it harder to debug.
> >
> > Also is there any C# generator and non-java binary builds 
> for antlr 3 
> > that can be downloaded?
> >
> > Thanks,
> > Frank Hileman
> >
> > __________________________________________________
> > Do You Yahoo!?
> > Tired of spam?  Yahoo! Mail has the best spam protection around 
> > http://mail.yahoo.com
> >
> >
> >
> >
> >
> 
> 
> 



More information about the antlr-interest mailing list