Programming Languages: Design, Specification, and ImplementationAdministrativeReview: BNF, Concrete and Abstract Syntax TreesUse of typesTypesFortran ExampleFortran: Name SpacesFortran: Static and Runtime Naming; ScopeReferences: Invisible but SignificantControl flowEverything staticWhat can go wrongAlgol 60: Static and Runtime Naming; ScopeNew features in Algol 60Beyond: Algol 68; PL/I; CNew things that can go wrongProgramming Languages:Design, Specification, and ImplementationG22.2210-001Rob StromSeptember 14, 2006AdministrativeAlternative mailing address for me: [email protected]Everyone should subscribe to the class mailing list: http://www.cs.nyu.edu/mailman/listinfo/g22_2110_001_fa06Readings: Remainder of chapter 3 of Gelernter and Jagannathan; chapter 7; MIT Scheme documentationGelernter textbook: we will notify about availability of photocopied notesHomework due end of class 4 (Scheme):•Convert list of atoms to concrete tree according to the simple grammar•Convert concrete tree to abstract treeReview: BNF, Concrete and Abstract Syntax Trees( A + B * C ) * D A B C Dftfftettfeeft*+*expr ::= expr “+” term | expr “–” term | termterm ::= term “*” factor | term “/” factor | factorfactor ::= number | identifier | “(“ expr “)”Use of typesOperator overloadingPolymorphismConversionImplementation choicesError checkingDifferences: •What’s typed? The value, the container, or the name•If the name can refer to different containers must they all be the same type?TypesIntegerFloat(In COBOL: Decimal)Second-class: “Hollerith”Fortran ExampleFortran: Name SpacesGlobal•Procedures and Functions•Common BlocksStatically Scoped•VariablesName Spaces•One global name space•One per procedure/functionDynamically Scoped•NoneFortran: Static and Runtime Naming; ScopePROGRAM MAIN…COMMON/ FOO/A,B,I/ BAR/C, D/ BAZ/E, F, JDIMENSION Z(999)…CALL SWAP(W, Z(200))…SUBROUTINE SWAP(X,Y)COMMON/ FOO/OLDX /GORP/KTEMPX = XX = YY = TEMPXOLDX = TEMPX…FUNCTION N (I)COMMON/ BAZ/X/GORP/LNTEMP = I**2 – 3*I + 2N = NTEMP * L…References: Invisible but SignificantEQUIVALENCE COMMONBindingControl flow“Spaghetti” codeGOTO and assigned GOTOCan jump anywhere except:•To another procedure•Inside a DO loop from outside the loopIF tests and jumps, not blocksDO loops and jumpsEverything staticDimensions of arrays (although not necessarily visible to subroutines)Number of instances of storage blocksAll programs both static and global (except statement functions)All I/O devices static and globalWhat can go wrongSyntax problems•DO I = 1.3Passing a constant•CALL SWAP(2, 3)Unchecked BoundsUninitialized VariablesAlgol 60: Static and Runtime Naming; ScopePROCEDURE MAIN;…x := read();BEGIN INTEGER ARRAY FOO[1:X]; … j := 20; blat(j, FOO(j)); …PROCEDURE blat(x,y); BEGIN x := 1000; y:= 1000 END…INTEGER PROCEDURE random; BEGIN OWN INTEGER seed; random := seed := some new value … END…New features in Algol 60Call by nameDynamic array boundsRecursive creation of local stack variablesOwn variablesNested declarations, scopesInner proceduresBeyond: Algol 68; PL/I; CFully dynamic storage – e.g. PL/I’s storage classes:•STATIC – like FORTRAN (local & external)•AUTOMATIC – like Algol 60 non-own•CONTROLLED – dynamically allocated•X BASED(Y) – dynamically allocated with pointerNew things that can go wrongUnbounded memoryDangling references via pointersDangling
View Full Document