[antlr-interest] Type discovery for operator overloading?

C. Mundi cmundi at gmail.com
Fri Jun 13 20:37:54 PDT 2008


On Fri, Jun 13, 2008 at 7:56 PM, Gavin Lambert <antlr at mirality.co.nz> wrote:

>
> Generally speaking, when writing a tree grammar rule you put the action to
> be executed at the end of the rule.  This means that it has already seen
> both terms in the AST, so there's no lookahead involved here.  You merely
> need some way to identify the type of each term (which is trivial in the
> above case, and only slightly more complicated in the cases where the terms
> can be sub-ASTs/expressions).
>
> Of course, this approach only works for a strongly typed language (ie. one
> where variables are typed, so that you can statically determine whether a
> given variable name contains a string or an integer).  If your language is
> dynamically typed then you'll have to have your runtime multiplication
> operation work out what types its arguments are and how to deal with them
> accordingly.
>


You're quite right: I entirely neglected to mention that my little language
is dynamically typed.  That was an important bit to leave out.  Dynamic
typing was one of my preliminary user requirements leading me down this
rabbit hole.  But as I begin to appreciate some of the implications, I
wonder if the runtime cleverness we originally sought is worth the added
complexity.  Of course, only my users can answer that.  Your reply has
helped greatly to sharpen my thinking on the subject.  Thank you.

cheers,
c. mundi
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.antlr.org/pipermail/antlr-interest/attachments/20080613/8906edf8/attachment.html 


More information about the antlr-interest mailing list