Hi Niklas,
Niklas Matthies wrote:
> I always wondered why the square brackets are needed in something like
>
> {-> New x.y([list.element])}
What if you have more elements?
e.g.
Productions
x =
{y} [e1] e* z [e2]:e* z [e3]:e* {-> New x.y(e1.e, e2.e, e3.e) } //???
...
Abstract Syntax Tree
x =
{y} [e1]:e* [e2]:e* // Note: only 2 lists!
...
How are the lists grouped? Is AST(e1) == CST(e1+e2) or is it grouped
differently?
Also, the [] syntax is meant as a "user visible" indication that we are
dealing with a list. Even though it might be possible to get rid of
"[]", it might make the resulting code less intuitive to new users and
maybe even older ones like me. ;-)
The same reasoning applies to new. Of course, in this case, the
presence or not of arguments () is probably sufficient to distinguish,
at parse time, between the creation of a new node and a reference to a
sub-AST. Yet, the explicit New makes it more obvious to the human
eye... Maybe you could convince me otherwise, on this one.
What do others think? Do you prefer:
x =
{y} a b c {-> New x.y(a, b, c) } | // new node
{z} w {-> w.u }; // reference
or
x =
{y} a b c {-> x.y(a, b, c) } | // new node
{z} w {-> w.u }; // reference
For me, at least, the first version seems clearer, at the cost of being
just a little more verbose. Your opinion is welcome. [It's still time
to update SableCC 4's syntax...]
Etienne
--
Etienne M. Gagnon, Ph.D. http://www.info2.uqam.ca/~egagnon/
SableVM: http://www.sablevm.org/
SableCC: http://www.sablecc.org/
Attachment:
signature.asc
Description: OpenPGP digital signature