Re: ASTs and Type Check Analysis

Hans-Peter Diettrich <DrDiettrich1@aol.com>
Sun, 24 Aug 2008 01:11:27 +0200

          From comp.compilers

Related articles
ASTs and Type Check Analysis crancran@gmail.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 crancran@gmail.com (CranCran77) (2008-08-25)
Re: ASTs and Type Check Analysis bc@freeuk.com (Bartc) (2008-08-25)
Re: ASTs and Type Check Analysis DrDiettrich1@aol.com (Hans-Peter Diettrich) (2008-08-26)
| List of all articles for this month |

From: Hans-Peter Diettrich <DrDiettrich1@aol.com>
Newsgroups: comp.compilers
Date: Sun, 24 Aug 2008 01:11:27 +0200
Organization: Compilers Central
References: 08-08-044
Keywords: analysis, AST
Posted-Date: 24 Aug 2008 14:42:40 EDT

CranCran77 schrieb:


> 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
> time?


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.
interpreted code.


DoDi


Post a followup to this message

Return to the comp.compilers page.
Search the comp.compilers archives again.