[antlr-interest] Idea: semantic grammar

Johannes Luber JALuber at gmx.de
Thu May 22 10:08:54 PDT 2008


> Cheers for the replies.
> 
> Johannes, I probably didn't phrase it quite right.  I wasn't suggesting
> that
> you define the actual semantics of the language (I thought about that but
> temporarily moved it to the side).  What I was meaning is that for the
> purposes of simpler (from the user's point of view) error reporting, it
> should be possible to define the types of semantic errors that can occur
> (but not necessarily how to detect these errors).
> 
> Once these types were defined, when users create their semantic predicates
> they could then "attach" a type to a predicate which would alter the type
> of
> exception thrown by the predicate, and in turn the error message that was
> created.
> 
> Something like (ignoring the actual syntax)
> 
> {table.HasKey("myvar")}?[UndefinedIdentifier]
> 
> It may also be good to be able to pass argument to the types, but I
> haven't
> thought that quite through.
> 
> Does that make any more sense?
> Adam

It does. It's a nice idea, but things have to be extendable - not all semantic errors occur in a language.

Johannes

> 
> 2008/5/22 Johannes Luber <JALuber at gmx.de>:
> 
> > > Hi,
> > > 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.
> > >
> > > Any thoughts?
> > > Adam
> >
> > A nice idea but probably infeasible. There are too many semantic
> > differences for basically one thing - recently I read an article about
> "PHP
> > sucks" and saw that references were handled in 4.3, 4.4 and 5
> differently.
> > Granted, 4.3 was leaky and 4.4 made it too complicated, so restricting
> > options to sensible ones has a benefit, but if you want to be able to
> parse
> > even the most idiotic things, you have to able to define arbitrary
> > semantics. And then you can use the target language itself.
> >
> > Maybe Yggdrasil of Loring Craymer can do that in target independent
> manner,
> > but it would be basically still Turing equivalent. At least you can do
> far
> > more things target independent in Yggdrasil than in ANTLR - just a
> shame,
> > that he didn't got around to finish it yet.
> >
> > Johannes
> > --
> > Der GMX SmartSurfer hilft bis zu 70% Ihrer Onlinekosten zu sparen!
> > Ideal für Modem und ISDN: http://www.gmx.net/de/go/smartsurfer
> >

-- 
Desperate Housewives - das Spiel!
Pikante Skandale, schockierende Details unter: http://flat.games.gmx.de


More information about the antlr-interest mailing list