Re: CFGs vs. "declare variable before use"

torbenm@diku.dk (=?iso-8859-1?q?Torben_=C6gidius_Mogensen?=)
28 May 2005 14:00:10 -0400

          From comp.compilers

Related articles
CFGs vs. "declare variable before use" devriese@cs.tcd.ie (Edsko de Vries) (2005-05-26)
Re: CFGs vs. "declare variable before use" wyrmwif@tsoft.org (SM Ryan) (2005-05-28)
Re: CFGs vs. "declare variable before use" mefrill@yandex.ru (mefrill) (2005-05-28)
Re: CFGs vs. "declare variable before use" torbenm@diku.dk (2005-05-28)
Re: CFGs vs. "declare variable before use" cfc@shell01.TheWorld.com (Chris F Clark) (2005-05-28)
Re: CFGs vs. "declare variable before use" torbenm@diku.dk (2005-05-31)
Re: CFGs vs. "declare variable before use" gah@ugcs.caltech.edu (glen herrmannsfeldt) (2005-05-31)
Re: CFGs vs. "declare variable before use" devriese@cs.tcd.ie (Edsko de Vries) (2005-06-02)
Re: CFGs vs. "declare variable before use" cfc@shell01.TheWorld.com (Chris F Clark) (2005-06-02)
Re: CFGs vs. "declare variable before use" gah@ugcs.caltech.edu (glen herrmannsfeldt) (2005-06-04)
[3 later articles]
| List of all articles for this month |
From: torbenm@diku.dk (=?iso-8859-1?q?Torben_=C6gidius_Mogensen?=)
Newsgroups: comp.compilers
Date: 28 May 2005 14:00:10 -0400
Organization: Department of Computer Science, University of Copenhagen
References: 05-05-216
Keywords: syntax, semantics, theory
Posted-Date: 28 May 2005 14:00:10 EDT

"Edsko de Vries" <devriese@cs.tcd.ie> writes:


> A common statement I read about the limitations of CFGs is that they
> cannot be used to express the requirement that "variables must be
> declared before they are used". However, I have been unable to find
> any formal justifications for this statement (e.g., in the style of
> the proof using the pumping lemma that a^n b^n c^n is not a context
> free language). Could anyone point me to some relevant literature?
> Also, are people aware of any other limitations of CFGs, esp. in the
> context of (the semantics of) programming languages, such as the one I
> mentioned, preferably with proofs?


CFG's can be used to guarantee that declarations precede use: If the
declaration dominates every use, then a variable is bound to be
declared before use. And you can also find cases where a use is
guaranteed to come before the declaration (if no path from the start
node to the use passes through the declaration). But there might be
cases where a control-flow analysis can't decide if there might be
uses preceeding the declaration.


Basically, the problem is that control-flow analysis (in most cases)
assumes that conditions are independent and that all branches are
valid. In a few cases, you can find conditions that are trivially
always true (or false) and you can find conditions that imply each
other (such as x<0 implies x<1), so you can see that some paths in the
CFG aren't valid. But (due to undecidability), no static analysis can
find all cases of dependent or constant conditions.


Hence, all static analyses are approximations, no matter if they are
based on CFG's, dataflow analysis, pre/post conditions or whatever.


                Torben


Post a followup to this message

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