[antlr-interest] 2.7.2a4 ANTLR/C# - build ok, panic shutdown

Ney, Richard richard.ney at aspect.com
Tue Dec 3 23:52:10 PST 2002


Daniel,

Why don't you just write an override method for the panic? In it you could
throw your own exception. Most of the error handlers for ANTLR C# are
console based and require an override method for customization.

-Richard

-----Original Message-----
From: Daniel Gackle [mailto:gackle at shaw.ca] 
Sent: Tuesday, December 03, 2002 11:14 PM
To: antlr-interest at yahoogroups.com
Subject: [antlr-interest] 2.7.2a4 ANTLR/C# - build ok, panic shutdown


Micheal,

First, thanks for the reply.  I followed your advice, went back to 2.7.2a4
for ANTLR/C#, and got it to build.  It turns out my mistake was in trying to
compile the C# codegen files by themselves, using commands like "javac
CSharp*.java".  A simple "javac *.java" works fine.

Second, I think I have a bug to report.  Once I got 2.7.2a4 to build, my
code that worked fine with 2.7.2a2 wouldn't even run.  It simply
disappeared, no exception, no crash, no nothing.  What changed between
versions?  Well, 2.7.2a2 used Activator.CreateInstance to create a custom
token type.  This required me to send in an assembly-qualified name for my
type, like this:

  myLexer.setTokenObjectClass("MyClass.CustomToken,MyAssembly")

2.7.2a4 switched to Assembly.CreateInstance.  That doesn't work with
assembly-qualified names.  As a result, the tokens weren't getting created,
and panic() was getting called instead.  By taking the assembly bit off the
type name, like this:

  myLexer.setTokenObjectClass("MyClass.CustomToken")

I got the code to run.  That, however, is not the bug.  The bug has to do
with the panic routine:

  public virtual void  panic(string s)
  {
     Console.Error.WriteLine("CharScanner; panic: " + s);
     Environment.Exit(1);
  }

The problem with this is that my program is a GUI app, not a console one. So
the error message never gets displayed and the call to Environment.Exit
shuts down the whole program without any warning.  This cost me several
hours of painstakingly stepping through code, trying to pinpoint exactly
where the runtime was (as I thought) crashing in some strange way.  This
code may work for console apps but is a very non-standard way to handle
errors in a GUI.  IMHO it would be much better to throw an exception.  If
the client doesn't catch it, at least the .NET runtime will throw up its
default exception handler, guaranteeing that the error will be displayed in
some form.  (Other ANTLR errors are dealt with in this way and my code
handles them fine.)

Third, I must apologize for misspelling your name for the past 6 months.  I
don't know why I didn't notice it before!

Regards,
Daniel


-----Original Message-----

Message: 3
   Date: Tue, 03 Dec 2002 13:29:24 -0000
   From: "micheal_jor" <open.zone at virgin.net>
Subject: Re: Can't build antlr-2.7.2a4-CSharp

>> What version of regular antlr is antlr-2.7.2a4 C#
>> supposed to go with?

>ANTLR 2.7.2a4. It proably would work for 2.7.2a5 and 2.7.2a6 as well 
>but I haven't tested either scenario [ nor do I intend to  ;-) ]. An 
>update to the latest ANTLR release is in the works....



 

Your use of Yahoo! Groups is subject to http://docs.yahoo.com/info/terms/ 


 

Your use of Yahoo! Groups is subject to http://docs.yahoo.com/info/terms/ 



More information about the antlr-interest mailing list