Subject: Re: contains statement

From: Zheng Gengbing <[email-masked]>
Date: Tue, 21 May 1996 09:28:24 +0800 (EAT)

On Mon, 20 May 1996, Guansong Zhang wrote:

> 
> I don't understand this. Or I did not make myself clear last time. Let's see an
> example:
> 
> ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
>       program test
>       real :: x,y
>       x = 3.14
>       call sub1 (x)
>       y = x * 2
>       stop
> 
>          contains
>          subroutine sub1(x)
>          real :: x
>          x = 1.0
>          return
>          end subroutine
> 
>       end program test
> ======================================
> 
> If dumpdep, we will find two x in symbol table. That is quite right, One's
> scope is 2-B, which is line 1: "program test"; the other's is 9-B, which is
> line 8: "subroutine sub1(x)".
> 
> Right now, the contains(8-B) and subroutine(9-B) are the right son of 2-B.
> 
> What I am saying above is that: why don't let 8-B be in the left son of 2-B
> while let 9-B be the left son of 8-B.
> 
> The second x's scope is still 9-B, instead of 8-B, the contains. And any
> further information is still retrevable through control parent feild.
> 
> (let the second x's scope be contains statement will be wrong. It is not a
> problem of easy or difficult. Since the contains statement may contain more
> than one subroutine.)
> 
> Please check this again to see if I am right.
>

	Then the control_parent of the subroutine  sub1 is contains statement,
right ? What I concern is what the sub1's scope is ,not x's .

	I can not figure out how this will affect our parser rigth now .
We have so long used to the current situation , and we have implemented 
this idea not only in main control but also other places in program 
unconsciously . So I don't know if we can adjust properly.

***************************************************************************
*     Zheng Gengbin                 *                                     *
*                                   *                                     *
*  Dept. of Computer Science        *  Phone:  86-10-2585088              *
*         & Technology              *  Email:                             *
*                                   *      [email-masked]   *
*  Peking University P.R.China      *  Mail:                              *
*                                   *      Room 1077 ,Building 47,        *
*                                   *      Peking University, P.R.China   *
***************************************************************************

---

From: Zheng Gengbing <[email-masked]>
Date: Wed, 22 May 1996 10:06:52 +0800 (EAT)

On Tue, 21 May 1996, Guansong Zhang wrote:

> On May 21,  9:28am, Zheng Gengbing wrote:
> > Subject: Re: contains statement
> On May 21,  5:49pm, Li Xinying wrote:
> >
> >    On this issue I agree with Zheng gengbin.( I have read his answering
> > letters.) To make subroutine_stmt be the left son of contain_stmt will
> > lead to some changes in functions about building symbol_table. Because
> > before building  a symbol-table node I must look  whether it has been
> > established before : first in the domain of local subroutine, then if it is
> > under contains ,it will look in the control-parents' domain. So I arrange
> > the relationship as that. Modifying it to the above situation of what you
> > said is possible, but it need some careful work.
> >
> >
> 
> Let's further discuss this, please don't make any change until we all agree.
> 
> First, I will comment on Li Xinying's algorithm for building symbol_table.
> 
> Suppose the contains is establish as I described, then when make a symbol
> entry, first looks the local scope, then its parent's scope. If its parents is
> a contains, look its parents' parents. We can obtain this chain through control
> parents feild. I don't see any difficulty. Please let me know if I omit
> something.
> 

	But when main program  refer to a procedure in contains block ,
the problem arise , for now the internal subroutine can not be seen to the 
main program .

> So all the thing need to be changed, to me, is the way of looking up table. Is
> that right?
> 
> Second. About Zheng Gengbin's question.
> 
> Yes, the contol parent's of sub1 is contains. But when looking up control
> parent you can always add one more if statement to lead it to one level up if
> meeting a contains statement. Please discuss this with others work on hpfsc to
> see if the changing is possible.
> 

	This is the one problem , the most serious problem is what I mentioned
above. And even though this change is possible , it is quite a trival 
matter .

> Finally, let me show you why this is a little problem for unparse. (suppose we
> don't care about the left and right son convention of sage now.)
> 
> Again, take the above program as an example.
> 
> Unparse do the work in this way currently.
> 
> At top level print "program..." unparse its left son, unparse it right son, and
> THEN print out "end program ..."
> 
> Here I emphasize that the end program is not printed out when control-end is
> met, but after unparsing the right son. So suppose this end statement is
> labeled, which will be recorded as the leftson's control end, unparse will lose
> this information.
> 
> (For a program unit without contains, program end was print out as control end
> is met, unparse can do this by if (the rightson == null) )
> 
> I talked about this just want to make us all clear about each other's problem.
> It doesn't necessaryly mean we have to change the current implementation of the
> contains.
> 
> Please make further comments on this.
>

	Can unparser  call recursively  to unparse right blob while
contains statements is encounted , while the control_end is left until
the call return ?

	Another way is to make procedures in contains block is also the left
blob of main program head , and follow the contains_statement ,
like :

	PROG_HEDR
           |
           ...
           |
        CONTIANS_STMT
           |
        PROC_HEDR
           |
           +-----+
           |     ...
        FUNC_HEDR
           |
        CONTROL_END

	these statement are all the left son of PROG_HEDR .
Then we only need to adjust the main control program of hpfsc.

> Guansong
> 
> P.S. I am also a little confused about when end can be labled. Please let me
> know where the handbook addressed this if you know. It also concerned with
> other kind of control end.
> 
>

	In my book , the branched target statement (which can be labeled ) is :
	1. action_stmt
	2. if_then_stmt
	3. end_if_stmt
	4. select_case_stmt
	5. end_select_stmt
	6. do_stmt
	7. end_do_stmt
	8. do_term_action_stmt
	9. do_term_shared_stmt
	10.where_construct_stmt

	constraints:
	1. branch to end_select_stmt can only from within select_case_construct 
	2. branch to end_do_stmt and do_term_stmt can only from within the
		do_construct .