[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Mapping lists during AST transformation
On Sun 2006-10-29 at 12:13h, Etienne Gagnon wrote on sablecc-user:
:
> I see. So, to answer your original question: no, it is not possible to
> build distinct id* and expr* lists depending on the context because
> CST->AST transformation happens during the parsing phase. SableCC
> doesn't currently have post-parsing automatic CST->AST. That would be
> an interesting M.Sc. project... Just send me an interested student to
> work on it. ;-)
Well, I finished my thesis this year, so it's too late now. ;)
:
> One thing you could do, though, is to approach the problem from a
> different angle. You could allow for a wider parsing language and then
> weed the AST of illegal constructs. This would lead to some interesting
> consequences:
> 1- You can report more meaningful messages to users.
> 2- It is quite easy to do the pruning.
> 3- The post-parsing "manual" AST transformations is simple to do, as
> there is a single case to deal with (transform exp* into id*).
>
> I have attached a fully functional example illustrating this solution.
> Note how it can tell the user that the Nth parameter is invalid. This
> is much clearer than a parse error about an unexpected '->'. :-)
Thanks. I discarded this solution earlier on, mostly because it
creates a discrepancy between the intended syntax and the one
specified by the grammer, but maybe it's simpler to take this route
after all.
One thing that is not so nice about it is that something like
((((a)), +b)) -> a + b
would become valid, because parentheses and unary plus are discarded
by the CST->AST transformation. I have to think about that.
-- Niklas Matthies