[antlr-interest] Off topic:Type handling
Anakreon
anakreonmejdi at yahoo.gr
Mon Oct 18 12:54:13 PDT 2004
Andrew Deren wrote:
> Just a few comments:
> Why are you doing type analysis in parser for dynamically typed language?
> I've never done anything in asp (or VB), but I've worked on other
> dynamically typed languages and it's almost impossible to do type-checking
> (analysis) at parse (or compile) time. For those language all type
> information is usually only available at runtime.
> For example:
> x = 3
> if (somecondition)
> {
> x = "some string";
> }
>
> // what type is x here?
> z = x;
>
> There is no way you can now type of x (or z after assignment), because it
> depends on some runtime condition. This is only one of many problems.
>
> Why are you doing type analysis for VB? Are you trying to compile it or
> translate to typed language?
>
> Andrew
ASP is translated to PHP which is typeless as well.
But I need the type of variables in certain cases which are demonstrated
in the URL of the mail.
Here is why:
Usefulness of type determination
=================================
1) Currently, if there are more then one method with the same name
which happens when a method receives variable count arguments,the appropriate
method is chosen based on the arguments count. This implies the limitation
that we can not define more then one method in the XML definition with the same
name and argument count, but with different argument types. This is very useful
when based on arguments type an other translation exists. We can end with
wrong translation because of this.
2) The AND, OR, XOR, NOT operators function as binary or logical operators
based on context. For example a = 12 OR 23 is a binary operator, but currently
is translated as a logical operator.
3) When functions return arrays, the translator is unaware of this fact. If the
code requests individual elements of the returned array, an error is produced
since the translator does not know that the variable holds an array, and an invalid
translation is generated.
4) When code which falls in the cases (2, 3) exists inside a user defined method
or sub, and refers to the methods arguments, the same problem appears.
This problem however is even more difficult to solve because when the method's
body is translated, the translator can not know the types of the arguments a priori.
The arguments can be determined only if:
a) The method is called. Then the types of the arguments passed to the method
can be used as the expected types of the arguments. This should be considered
as heuristic because a method can be called with different argument types each time.
b) An operation is performed on an argument which is valid only if the argument
belongs to a specific type. ASPA takes an optimistic approach on translation
and assumes that the source code to be translated is correct. Because of this
we can set the arguments type equal to the one the operation requires. This
assumption may not be valid in certain cases hence the translation might be
wrong.
Generally is not possible to determine the type of the variable.
There is no why to be always capable of finding the type.
In many cases however it is possible.
I hope someone has faced a similar problem and can make some suggestions on
how to solve the problem.
Anakreon
Yahoo! Groups Links
<*> To visit your group on the web, go to:
http://groups.yahoo.com/group/antlr-interest/
<*> To unsubscribe from this group, send an email to:
antlr-interest-unsubscribe at yahoogroups.com
<*> Your use of Yahoo! Groups is subject to:
http://docs.yahoo.com/info/terms/
More information about the antlr-interest
mailing list