Path: utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!purdue!haven!uvaarpa!virginia!scl From: scl@virginia.acc.virginia.edu (Steve Losen) Newsgroups: comp.lang.pascal Subject: Re: An ISO Pascal question... Message-ID: <2158@virginia.acc.virginia.edu> Date: 22 Mar 89 00:25:49 GMT References: <18654@adm.BRL.MIL> <2824@kalliope.rice.edu> <216@m2xenix.UUCP> Reply-To: scl@virginia.acc.Virginia.EDU (Steve Losen) Organization: University of Va., Charlottesville, VA Lines: 68 >mootaz@titan.rice.edu (Elmootazbellah Nabil Elnozahy) asks if the >following is legal Pascal: > > T = real; > R = Record > T: integer; > D: T; > end; > B = Record > T: integer; > C: Record > D: T; > end; > end; The above is not legal ISO standard Pascal. While it is legal to redefine an identifier used in an enclosing scope, under no circumstances is it legal for an identifier to have two "meanings" in the same scope. All "namable" objects in Pascal share the same name space. Thus you may refer to a type X and then define a variable called X in the same scope. Looking at the example: T = real; { At first the scope of type T is the whole block } { and everything it encloses }. R = Record T: integer; { By defining a field named T, we have removed record R } { from the scope of type T } D: T; { illegal. T refers to the previous field. } end; B = Record T: integer; { By defining a field T we have removed record B and } { everything it encloses from the scope of type T } C: Record D: T; { illegal. Refers to field T in record B } end; end; For some real fun, lets change the field orderings around and see what happens. T = real; R = Record D: T; { By referencing type T, we have irrevocably kept } { record R within the scope of type T } T: integer; { illegal. We cannot redefine T because the Standard } { insists that within the scope of an identifier all } { occurrences of the identifier shall refer to the same } { thing. } end; B = Record C: Record D: T; { This reference to type T irrevocably keeps this } { anonymous record within the scope of type T. Record B } { (excluding this anonymous record) can still be } { removed from the scope of type T as we shall see.} end; T: integer; { This is perfectly legal. The scope of field T is } { now record B (excluding the anonymous record, which } { is within the scope of type T). } If you don't believe me, did you just finish writing an ISO Standard Pascal compiler? -- Steve Losen scl@virginia.edu University of Virginia Academic Computing Center