[antlr-interest] [v2 to v3][C++/C] throw C++ exception from parser/tree parser.

Ruslan Zasukhin ruslan_zasukhin at valentina-db.com
Wed Sep 7 12:13:05 PDT 2011


On 9/7/11 7:36 PM, "Jim Idle" <jimi at temporal-wave.com> wrote:

Hi Jim,

> You remember that this is all open source, freely given right?

Of course I do :-)

And I have read sources of ANTLR 3.4, be sure.
Btw, my congratulations and respect. Very high quality code.

> Generally,
> don't try and mix C++ things in with the C. Exceptions are almost
> certainly not want you want for error reporting while parsing anyway.

> As I said earlier, copy the existing routine and adapt it. It does as many
> things as it can to show you how to access the information. I can't
> provide a universal error message handler as there is no way to know what
> information your particular parser will have available or how you want the
> messages to look and so on. All your customer error handler need do is
> call a C++ object that you provide and that object can collect the errors
> so that you can print them out at the end etc. The source code is right
> there and well commented :)

Ahhaa,  I hope I have to hear you ...
I will try say it now by own words to double check.

* so we must implement own dsiplayError() -- this is clear.

* we must NOT throw here any C++ exception.
    Instead, we must just build some Err String and put it
    e.g. Into our own Stack of such error strings

* then we do 

   AST         =  parser->entryRule()
   MyNodes = treePareser->entryRule()

Zero exceptions here
Then we just do

    if( errCount > 0 )
    {   
         stop  job
         somehow report errors to user
         for example

        point ZZZ:
         throw  myException(  ErrStack->getErrors() ;)
    }


Sounds right?
Thank you, Jim for points.

-----------------
Well, only one more question come to mind.  :-)

I have read that ANTLR3-C self build LIST OF exception objects.
Is this true?

If yes, then may be this is not needed? I mean override displayError()
method?

>> All your customer error handler need do is
>> call a C++ object that you provide and that object can collect the errors
>> so that you can print them out at the end etc.

And we can "convert" that list into exception at point ZZZ in the above
example?


-- 
Best regards,

Ruslan Zasukhin
VP Engineering and New Technology
Paradigma Software, Inc

Valentina - Joining Worlds of Information
http://www.paradigmasoft.com

[I feel the need: the need for speed]




More information about the antlr-interest mailing list