[antlr-interest] On to the next issue: error(211)
Hendrik Maryns
qwizv9b02 at sneakemail.com
Wed Nov 12 02:05:15 PST 2008
Gavin Lambert schreef:
> At 01:52 12/11/2008, Hendrik Maryns wrote:
> >The thing I am having trouble with is that, with the idea of
> >polymorphism etc., I'd like to have things dealt with at the
> >appropriate place.
> >
> >I have rules like
> >
> >atomic : atomicHead variable label ;
> >
> >atomicHead : EQUALITY | DOMINANCE | INCLUSION | … ;
> >
> >and depending on the value of atomicHead, I
> want a different Java
> >object to be created.
>
> If you have input AST fragments like this:
> ^(EQUALITY a b)
> ^(DOMINANCE a b)
> ^(INCLUSION a b)
> ^(INVERSE a)
>
> then they're trivial to parse with AST
> rules. The job of the parser is usually to
> translate the sequential token stream into a tree
> structure that conveys the intended meaning; the
> tree parser then goes through that tree and does
> whatever you want.
That is what I intended to do, but the problem remains. Indeed I will
have to come back from the generalization that I had in the atomic rule,
and indeed just list all possible subtypes separately, each of them
looking for their arguments. This is no problem, but I just thought it
was a nice generalization. For simple parsing, it works, but it makes
it difficult to generate the proper code, due to the dependencies on
subrules.
The tree grammar is usually
> very simple and you should almost never need to
> use any predicates in it.
I see. Since my grammar is so easy, I will do it in the parser directly
instead.
> (Though I'm not sure why you're calling this
> "atomic". It seems like an odd choice of name
> for something that seems to require neighbouring symbols as well.)
Lol, because they are atomic formulas in the problem domain, but of
course not viewn from a parser standpoint.
> >I cannot do
> >
> >atomic return [Formula result] : atomicHead[$variable.result,
> >$label.result] variable label { $result = $atomicHead.result; };
> >
> >since $variable.result and $label.result will not have been
> >evaluated at that point.
>
> atomic returns [Formula result]
> : ^(EQUALITY variable expr) { $result = new
> Equality($variable.result, $expr.result); }
> | ^(DOMINANCE ...
So indeed split up the rule which generalizes over the structure of the
several atomic formulas (head variable variable) into a rule for each
head. This is what I am doing now.
Thanks!
H.
--
Hendrik Maryns
http://tcl.sfs.uni-tuebingen.de/~hendrik/
==================
Ask smart questions, get good answers:
http://www.catb.org/~esr/faqs/smart-questions.html
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 257 bytes
Desc: OpenPGP digital signature
Url : http://www.antlr.org/pipermail/antlr-interest/attachments/20081112/031222f2/attachment.bin
More information about the antlr-interest
mailing list