Path: utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!ames!oliveb!pyramid!nsc!icldata!altnet!altos86!elxsi!beatnix!corbett From: corbett@beatnix.UUCP (Bob Corbett) Newsgroups: comp.lang.pascal Subject: Re: An ISO Pascal question... Message-ID: <2560@elxsi.UUCP> Date: 22 Mar 89 22:42:13 GMT References: <18654@adm.BRL.MIL> <2824@kalliope.rice.edu> <216@m2xenix.UUCP> <2158@virginia.acc.virginia.edu> Sender: news@elxsi.UUCP Reply-To: uunet!elxsi!corbett (Bob Corbett) Organization: ELXSI, San Jose Lines: 76 Distribution: In article <2158@virginia.acc.virginia.edu> scl@virginia.acc.Virginia.EDU (Steve Losen) writes: >>mootaz@titan.rice.edu (Elmootazbellah Nabil Elnozahy) asks if the >>following is legal Pascal: >> >> T = real; >> 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. So far, so good. But... >For some real fun, lets change the field orderings around and see what >happens. > > 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). } > This construction is not legal. The following statements are from ISO 7185: 6.2.2.5 When an identifier or label has a defining-point for region A and another identifier or label having the same spelling has a defining point for some region B enclosed by A, then region B and all regions enclosed by B shall be excluded from the scope of the defining-point for region A. Note the phrase "and all regions enclosed by B." In the example above, the inner record-type is a region enclosed by the region that is the outer record-type. From Section 6.4.3.3: The occurrence of an identifier in the identifier-list of a record-section of a fixed-part of a field-list shall constitute its defining-point as a field-identifier for the region that is the record-type closest-containing the field-list, and shall associate the field-identifier with a distinct component, which shall be designated a field, of the record-type and of the field-list. The region associated with the defining-point of the field-identifier T is the outer record-type and all regions enclosed by the outer record-type, which includes the inner record-type. Therefore, the inner record-type is excluded from the scope of the defining-point of the type-identifier T. Therefore, the use of T as a type-identifier in the inner record-type is illegal. >If you don't believe me, did you just finish writing an ISO Standard >Pascal compiler? No, I just started. >-- >Steve Losen scl@virginia.edu >University of Virginia Academic Computing Center Yours truly, Bob Corbett uunet!elxsi!corbett ucbvax!sun!elxsi!corbett