Related articles |
---|
Semantical checks that involve flow of execution of the program lujoplujop@gmail.com (Lujop) (2004-10-17) |
Re: Semantical checks that involve flow of execution of the program skaller@nospam.com.au (John Max Skaller) (2004-10-21) |
Re: Semantical checks that involve flow of execution of the program choksheak@yahoo.com (ChokSheak Lau) (2004-10-21) |
From: | "John Max Skaller" <skaller@nospam.com.au> |
Newsgroups: | comp.compilers |
Date: | 21 Oct 2004 22:21:10 -0400 |
Organization: | Compilers Central |
References: | 04-10-122 |
Keywords: | semantics |
Posted-Date: | 21 Oct 2004 22:21:10 EDT |
On Sun, 17 Oct 2004 16:09:46 -0400, Lujop wrote:
> //var a is not inicialized
> ...
> if codition1 then
> a <- 1
> else if codition2 then
> b <-2
> else
> a <- 1
>
> With this example Java says that 'a' is possibly not initialized
> because branch 2 don't assign any value in a.
If your representation is a node
Cond (c,yes,no)
then you can just use
a_is_init (yes) and a_is_init (no)
For sequential statements:
Seq(first,next)
you can use
a_is_init(first) or a_is_init(next)
These are synthetic attributes -- you can calculate bottom up
directly in the parser, or using simple recursive descent.
In practice you would not use a function just checking for
one variable 'a'. Instead, you'd calculate *all* the variables
initialised at once, using a set. Then the rules would be like:
init (Cond (c, yes, no) ==> init(yes) intersect init (no)
Return to the
comp.compilers page.
Search the
comp.compilers archives again.