[antlr-interest] Idea: semantic grammar
adam.rpconnelly at googlemail.com
Thu May 22 06:52:34 PDT 2008
I don't know if there is anything like this about at the moment, or even if
it's a good idea. What I've been thinking about is having a grammar that
defines the semantics of a language that parsers can then import. It would
basically be a list of the possible types of semantic error that could
occur, along with any information necessary to generate an error message,
and an action that creates the message.
>From this a number of exception classes would be generated, along with a
MessageCreator that would generate error messages based on the actions
supplied. Inside the parser grammar, when semantic predicates are declared,
the type of error would be indicated, and from this the correct exception
would be thrown. The parser would then ask its ErrorReporter to handle the
error, which would use the MessageCreator to create the error message, and
would then add it to a list / print to the console / whatever.
>From this, "catalogs" of pre-defined semantic errors could be provided along
with the correct messages to display for these errors. Obviously this
wouldn't define the actual semantics of the language (since you'd still need
to implement this in actions), but it would simplify the error reporting
part since users would just import the correct semantics, then indicate when
a certain semantic error should be thrown.
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the antlr-interest