ch. 5 ch. 51 jcmt cse 3302 cse@uta programming languages cse3302 programming languages (more notes)...

21
CSE 3302 CSE@UTA Programming Languages Ch. 5 Ch. 5 1 jcmt CSE3302 CSE3302 Programming Languages Programming Languages (more notes) (more notes) Dr. Carter Tiernan

Upload: ann-cain

Post on 04-Jan-2016

229 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Ch. 5 Ch. 51 jcmt CSE 3302 CSE@UTA Programming Languages CSE3302 Programming Languages (more notes) Dr. Carter Tiernan

CSE 3302 CSE@UTA Programming Languages Ch. 5Ch. 5 1 jcmt

CSE3302CSE3302Programming LanguagesProgramming Languages

(more notes)(more notes)

Dr. Carter Tiernan

Page 2: Ch. 5 Ch. 51 jcmt CSE 3302 CSE@UTA Programming Languages CSE3302 Programming Languages (more notes) Dr. Carter Tiernan

CSE 3302 CSE@UTA Programming Languages Ch. 5Ch. 5 2 jcmt

Return to SimplicityReturn to Simplicity

• Attempts to extend Algol included:– PL /I

• very large• intersection of FORTRAN, COBOL, and

Algol• “Swiss army knife” approach

– Extensible languages• Kernal: application independent• Ex: operator extensions & syntax macros• Inefficient; hard to debug

Page 3: Ch. 5 Ch. 51 jcmt CSE 3302 CSE@UTA Programming Languages CSE3302 Programming Languages (more notes) Dr. Carter Tiernan

CSE 3302 CSE@UTA Programming Languages Ch. 5Ch. 5 3 jcmt

PascalPascal

• Niklaus Wirth designed successor languages to Algol

• Goal was to compete with FORTRAN and keep the benefits of Algol

• Explicit goals– Suitable for teaching programming– Reliable, efficient implementation

Page 4: Ch. 5 Ch. 51 jcmt CSE 3302 CSE@UTA Programming Languages CSE3302 Programming Languages (more notes) Dr. Carter Tiernan

CSE 3302 CSE@UTA Programming Languages Ch. 5Ch. 5 4 jcmt

Pascal StructurePascal Structure

• Syntax is Algol-like• Uses reserved words• New structures added

– Name– Data– Control

Page 5: Ch. 5 Ch. 51 jcmt CSE 3302 CSE@UTA Programming Languages CSE3302 Programming Languages (more notes) Dr. Carter Tiernan

CSE 3302 CSE@UTA Programming Languages Ch. 5Ch. 5 5 jcmt

Data StructuresData Structures

• Primitives– Real, integer, boolean from Algol– Characters : type char

• Enumeration types– Replaces integer codes to represent lists– Limits range of values explicitly– Keeps types unique and separate – Defined as a binding construct– Only allows meaningful operations– Efficient implementation

Page 6: Ch. 5 Ch. 51 jcmt CSE 3302 CSE@UTA Programming Languages CSE3302 Programming Languages (more notes) Dr. Carter Tiernan

CSE 3302 CSE@UTA Programming Languages Ch. 5Ch. 5 6 jcmt

Data Structures, continuedData Structures, continued

• Subrange types– Security and efficiency

• Set types– Mathematical application– Efficient– Set operations defined - implemented

with bit operations

Page 7: Ch. 5 Ch. 51 jcmt CSE 3302 CSE@UTA Programming Languages CSE3302 Programming Languages (more notes) Dr. Carter Tiernan

CSE 3302 CSE@UTA Programming Languages Ch. 5Ch. 5 7 jcmt

ArraysArrays• Generalized index types (integer

subranges)• Allowable element types - any other Pascal

base type including other arrays, etc.• No multi dimensional arrays BUT can have

an array whose element type is array and “syntactic sugar” allows appearance of multi-dim arrays

• Restrictions on Pascal arrays– Static bounds : determinable at compile time– Dimensions are part of array type– Feature interaction problem with bounds

Page 8: Ch. 5 Ch. 51 jcmt CSE 3302 CSE@UTA Programming Languages CSE3302 Programming Languages (more notes) Dr. Carter Tiernan

CSE 3302 CSE@UTA Programming Languages Ch. 5Ch. 5 8 jcmt

RecordsRecords

• Aggregate heterogeneous data– Components can be primitive types or

complex data types including records and arrays

– Component selection within a record is done with dot notation

– with statement opens a record for accessing multiple fields within the block of the with

Page 9: Ch. 5 Ch. 51 jcmt CSE 3302 CSE@UTA Programming Languages CSE3302 Programming Languages (more notes) Dr. Carter Tiernan

CSE 3302 CSE@UTA Programming Languages Ch. 5Ch. 5 9 jcmt

Arrays vs. RecordsArrays vs. Records

Structure Element types

Selectors

Array Homogeneous

Dynamic (computable)

Record Heterogeneous

Static

Page 10: Ch. 5 Ch. 51 jcmt CSE 3302 CSE@UTA Programming Languages CSE3302 Programming Languages (more notes) Dr. Carter Tiernan

CSE 3302 CSE@UTA Programming Languages Ch. 5Ch. 5 10 jcmt

Variant RecordsVariant Records

• Groups different fields according to a status value

• The status value is called the tag field• Creates a loophole related to type

because variant fields do not have to be initialized and previous values of different type may be accessible

Page 11: Ch. 5 Ch. 51 jcmt CSE 3302 CSE@UTA Programming Languages CSE3302 Programming Languages (more notes) Dr. Carter Tiernan

CSE 3302 CSE@UTA Programming Languages Ch. 5Ch. 5 11 jcmt

Data types (cont.)Data types (cont.)

• Pascal structures allow efficient information storage

• Pascal has pointers– Pointers have data types to support strong

typing in Pascal– Pointer base types can be any other type

• Initially type equivalence was not clearly defined– Structural, Name (simpler and safer)– Subrange equivalence within Name eq

Page 12: Ch. 5 Ch. 51 jcmt CSE 3302 CSE@UTA Programming Languages CSE3302 Programming Languages (more notes) Dr. Carter Tiernan

CSE 3302 CSE@UTA Programming Languages Ch. 5Ch. 5 12 jcmt

Name StructuresName Structures

• Bindings– Constant– Type– Variable– Procedure and function– Implicit enumeration– Label

Page 13: Ch. 5 Ch. 51 jcmt CSE 3302 CSE@UTA Programming Languages CSE3302 Programming Languages (more notes) Dr. Carter Tiernan

CSE 3302 CSE@UTA Programming Languages Ch. 5Ch. 5 13 jcmt

Name StructuresName Structures

• Constants abstract out dependencies

• Constants cannot be described by an expression

• Expressions cannot be used in variable or type declarations

Page 14: Ch. 5 Ch. 51 jcmt CSE 3302 CSE@UTA Programming Languages CSE3302 Programming Languages (more notes) Dr. Carter Tiernan

CSE 3302 CSE@UTA Programming Languages Ch. 5Ch. 5 14 jcmt

Name Struct ConstructorsName Struct Constructors• Records• Procedures

– Much like Algol in format and scope– Order of declarations was important

for one-pass compilation• Reverses top-down order• No way to define mutually recursive procs

– forward declaration (like C prototype decl)

• Group order important also

Page 15: Ch. 5 Ch. 51 jcmt CSE 3302 CSE@UTA Programming Languages CSE3302 Programming Languages (more notes) Dr. Carter Tiernan

CSE 3302 CSE@UTA Programming Languages Ch. 5Ch. 5 15 jcmt

Control StructuresControl Structures

• More structures than Algol but simpler

• I/O routines provided• Structured control is supported

– One entry, one exit

• Supports recursion• Has a goto to facilitate adoption

Page 16: Ch. 5 Ch. 51 jcmt CSE 3302 CSE@UTA Programming Languages CSE3302 Programming Languages (more notes) Dr. Carter Tiernan

CSE 3302 CSE@UTA Programming Languages Ch. 5Ch. 5 16 jcmt

StructuresStructures• for

– Austere & even simpler than FORTRAN DO

• while / do– Condition at beginning

• repeat / until– Condition at end

• case– Labeled cases

Page 17: Ch. 5 Ch. 51 jcmt CSE 3302 CSE@UTA Programming Languages CSE3302 Programming Languages (more notes) Dr. Carter Tiernan

CSE 3302 CSE@UTA Programming Languages Ch. 5Ch. 5 17 jcmt

ParametersParameters

• Pass by reference• Pass by value• Pass by constant

– Input parameter treated as a constant inside called routine

– Compiler can either copy or pass address of parameter

– Left loophole similar to aliasing problem

Page 18: Ch. 5 Ch. 51 jcmt CSE 3302 CSE@UTA Programming Languages CSE3302 Programming Languages (more notes) Dr. Carter Tiernan

CSE 3302 CSE@UTA Programming Languages Ch. 5Ch. 5 18 jcmt

Procedural parametersProcedural parameters

• Can pass procedures and functions as parameters

• Originally, formal specification gave procedure name and return type but not parameters of procedure being passed

• Standard required parameters to be specified also

Page 19: Ch. 5 Ch. 51 jcmt CSE 3302 CSE@UTA Programming Languages CSE3302 Programming Languages (more notes) Dr. Carter Tiernan

CSE 3302 CSE@UTA Programming Languages Ch. 5Ch. 5 19 jcmt

PascalPascal

• Excellent teaching language• Suitable for “real” programming• Usage goes beyond original intent

Page 20: Ch. 5 Ch. 51 jcmt CSE 3302 CSE@UTA Programming Languages CSE3302 Programming Languages (more notes) Dr. Carter Tiernan

CSE 3302 CSE@UTA Programming Languages Ch. 5Ch. 5 20 jcmt

Other LanguagesOther Languages

• PL /I extensions• BCPL - Cambridge Plus London• B - BCPL based & used in 1st Unix (8k

PDP-7)• C - successor of ‘B’ by Dennis Ritchie

– Used to rewrite Unix kernel– Characteristics of 1st, 2nd, and 3rd gen

languages

• PL /I extensions• BCPL - Cambridge Plus London• B - BCPL based & used in 1st Unix (8k

PDP-7)• C - successor of ‘B’ by Dennis Ritchie

– Used to rewrite Unix kernel– Characteristics of 1st, 2nd, and 3rd gen

languages

Page 21: Ch. 5 Ch. 51 jcmt CSE 3302 CSE@UTA Programming Languages CSE3302 Programming Languages (more notes) Dr. Carter Tiernan

CSE 3302 CSE@UTA Programming Languages Ch. 5Ch. 5 21 jcmt

Third Generation LanguagesThird Generation Languages

• Simplicity and efficiency• Data structures support applications

– Support nesting– User definition– Pointers

• Name structures have bindings for new types• Control structures are simplified and efficient

– Case