[antlr-interest] Exception issues

Ric Klaren klaren at cs.utwente.nl
Tue Aug 24 09:13:49 PDT 2004


On Tue, Aug 24, 2004 at 03:48:04PM -0000, Eric Mahurin wrote:
> 1. SemanticException is constructed without any line, column, or
> filename.  Why?  It is not a very useful message - especially to the
> end-user that sees an expression with internal variables.

I'm don't know what the design behind it is/was. From a practical point of
view though the automatically generated code for a predicate that generates
a SemanticException has no token linked to it. So it's not possible to get
it from there. It would probably be possible to get this information from
the inputState (at the expense of it's precision it might not point at the
exact point where the predicate failed). Hmm come to think of it maybe it's
possible to grab it from LT(1) maybe with some extra code around it.

Work arounds I could think of:

1. Catch the exception directly in the alternative or the rule and rethrow
   it with line/column/file gobbled from another place (token in the
   vicinity) depends on context what's best.
2. Patch the codegenerator to grab data from LT(1). Should be a trivial
   patch to genSemPred methods in Java/CppCodegenerator. If you patch it
   and send me the patch I'll fix it in the repository.

As for the generated message. I guess it would be nicest if you specify a
fail message there. But that's a bit hairy would require some extra syntax
and stuff. Option 1. would allow you to fix up the message as well.

> 2. Ability to override the exception classes used for exception
> construction.  In my case, I have include files so that the filename
> is not constant.  I have another means of finding the filename (lookup
> table - ignores lexer/parser filename) and would like to use exception
> classes that use this method.

It depends on what you want but you most probably have to patch the runtime
lib and codegenerator. In general where applicable the exceptions should
take over line/column/file information from the tokens/ast's from which
they get generated. If some don't I guess that's a bug. To get
filename/line/column all set in tokens/ast's you may have to override a few
things. (makeToken in the lexer, custom AST with the right initialize stuff
there's examples for that around)

Cheers,

Ric
--
-----+++++*****************************************************+++++++++-------
    ---- Ric Klaren ----- j.klaren at utwente.nl ----- +31 53 4893755  ----
-----+++++*****************************************************+++++++++-------
  "I don't have anything against Java - it's the best damn implementation
              of UCSD Pascal ever released..." --- Larry Smith



 
Yahoo! Groups Links

<*> To visit your group on the web, go to:
    http://groups.yahoo.com/group/antlr-interest/

<*> To unsubscribe from this group, send an email to:
    antlr-interest-unsubscribe at yahoogroups.com

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



More information about the antlr-interest mailing list