|ASTs and Type Check Analysis email@example.com (CranCran77) (2008-08-20)|
|Re: ASTs and Type Check Analysis DrDiettrich1@aol.com (Hans-Peter Diettrich) (2008-08-24)|
|Re: ASTs and Type Check Analysis ArarghMail808@Arargh.com (2008-08-24)|
|Re: ASTs and Type Check Analysis firstname.lastname@example.org (CranCran77) (2008-08-25)|
|Re: ASTs and Type Check Analysis email@example.com (Bartc) (2008-08-25)|
|Re: ASTs and Type Check Analysis DrDiettrich1@aol.com (Hans-Peter Diettrich) (2008-08-26)|
|From:||Hans-Peter Diettrich <DrDiettrich1@aol.com>|
|Date:||Sun, 24 Aug 2008 01:11:27 +0200|
|Posted-Date:||24 Aug 2008 14:42:40 EDT|
> simple, I can see three passes required:
> - Pass #1 : Type Analysis
> - Pass #2 : Constant Folding
> - Pass #3 : Code Generation
> Am I off base here ?
> Where I am currently getting caught is in the first two phases. What
> is the ideal way to layer type information into the AST tree, followed
> by constant folding, followed by any other checks prior to compile
The efforts may depend on the actual brand of BASIC you're targeting.
When a variable can hold any type at any time, depending on the last
assignment, or depending on the last declaration passed in control
flow, a type analysis IMO will be quite fruitless.
Otherwise, when the type of a variable is known at compile time, you
have the usual choice of up-/downcasting to the next applicable type in
expression evaluation. That's easy when numerical and textual (string)
data cannot be mixed. Otherwise you'll have to specify what the result
of e.g. 1+"1" shall be - it might be "11", 2, or some even more weird
result. That's one of the common pitfalls also in Java :-(
Even Microsoft couldn't find *valid* optimizations for Visual Basic,
that would result in significantly faster execution of compiled vs.
Return to the
Search the comp.compilers archives again.