Concepts of Programming Languages (750321)

Size: px
Start display at page:

Download "Concepts of Programming Languages (750321)"

Transcription

1 (750321) A-PDF MERGER DEMO A module For students in Departments CS, CIS, SE, ACS Faculty of IT / Philadelphia University Second Semester 2006/2007 1

2 (750321) Lecturer: Dr. Nadia Y. Yousif Room: IT 332 2

3 Course Outline Aims Objectives Assessment and Passing the Subject Lectures and Tutorial classes Lecturer and consultation Recommended reading 3

4 Aims of this module To provide students with a framework for thinking about programming languages. To learn different concepts of programming languages. To be able to learn new programming languages. To be able to select which programming language is most appropriate for a particular problem. 4

5 Course Objectives Understand different programming paradigms. Understand the syntax and semantics of programming languages. The ability of designing new programming language. The ability to develop different projects using different programming languages. 5

6 Assessment and Passing There are three assessment components: - Two midterm exams worth 15% of the marks each - Course work worth 20% of the marks - Final exam worth 50% You need to achieve an overall mark of 50% to pass the course. 6

7 Lectures and Practice Classes Lectures will be held at: 14:10 15:10 pm on Sunday, Tuesday, and Thursday in Room 7408 From the third week, tutorials will be given to be discussed in some of the class hours Students are expected to work on practice problems, or on their assignments on free labs 7

8 Lecturer and Consultation Lecturer: Dr. Nadia Y. Yousif Faulty of IT, Room 332, Phone Ext: Consultation The primary time for consultation is during the tutorial classes Other consultation at the office hours (in room 332) on: (Sun, Tue, Thu) 12:00 13:00 (Mon, Wed) 13:45 15:15 8

9 Recommended Reading The text book is: R. Sebesta,, Addison Wesley, 5 th Edition, 2002 The following is other good reference: Terrence W. Pratt, Programming : Design and Implementation, Prentice-Hall, 2002 Note: Most of the slides presented in the lectures are from Sebesta reference 9

10 Chapter One Preliminaries, including Why study PL concepts? Programming domains PL evaluation criteria What influences PL design? Tradeoffs faced by programming languages Implementation methods Programming environments 10

11 Why study Programming Language Concepts? Increased capacity to express programming concepts Improved background for choosing appropriate languages Increased ability to learn new languages Understanding the significance of implementation Increased ability to design new languages Overall advancement of computing 11

12 Programming Domains Scientific applications: (using Fortran, Algol 60) Business applications: (using COBOL) Artificial intelligence: (using LISP) Systems programming: (using C in programming the UNIX operating system) Scripting languages: (using Perl, Javascript) Special purpose languages 12

13 Language Evaluation Criteria Readability Writability Reliability Cost Etc 13

14 Evaluation Criteria: Readability How is it for one to read and understand programs written in the PL? Arguably the most important criterion! Factors effecting readability include - Overall simplicity Too many features is bad Orthogonality Makes the language easy to learn and read Meaning is context independent - Control statements - Data type and structures - Syntax considerations 14

15 Evaluation Criteria: Writability How easy is it to write programs in the language? Factors affecting writability: Simplicity and orthogonality Support for abstraction Expressivity Fit for the domain and problem 15

16 Evaluation Criteria: Reliability Factors: - Type checking - Exception handling - Aliasing - Readability and writability 16

17 Evaluation Criteria: Cost Categories: Programmer training Software creation Compilation Execution Compiler cost Poor reliability Maintenance 17

18 Evaluation Criteria: others Portability Generality Well-definedness Etc 18

19 Language Design Influences Computer Architecture -We use imperative languages, at least in part, because we use von Neumann machines - John von Neumann is generally considered to be the inventor of the "stored program" digital computer - the class to which most of today's computers belong. - CPU+memory which contains both program and data -Focus on moving data and program instructions between registers in CPU to memory locations 19

20 Language Design Influences: Programming Methodologies 1950s and early 1960s: Simple applications; worry about machine efficiency Late 60s: People efficiency became important; readability, better control structures. maintainability Late 70s: Data abstraction Middle 80s: Object-oriented programming 95-today: distributed programs, the Web 20

21 Language Categories The big four: Imperative or procedural (e.g. Fortran, C) Functional (e.g. Lisp, ML) Rule-based (e.g. Prolog) Object-oriented (e.g. Smalltalk, Java) Others: Scripting (e.g. Perl, Tcl/Tk) Constraint (e.g. Eclipse) 21

22 Language Design Trade-offs Reliability versus cost of execution Ada, unlike C, checks all array indices to ensure proper range. Writability versus readability (2 = 0 +.= T o. T) / T <- in is an APL one liner that produces a list of the prime numbers from 1 to N inclusive. Flexibility versus safety C, unlike Java, allows one to do arithmetic on pointers. 22

23 Implementation methods Direct execution by hardware ( e.g., machine language) Compilation to another language ( e.g., C) Interpretation Direct execution by software (e.g., csh, Lisp (traditionally)) Hybrid Compilation to another language (aka bytecode) which is then interpreted (e.g., Java, Perl) 23

24 Implementation issues Complexity of compiler/interpreter Speed of translation Speed of execution Portability of translated code Compactness of translated code Debugging ease compile hybrid interpret 24

25 Programming Environments The collection of tools used in software development, often including an integrated editor, debugger, compiler, collaboration tool, etc. Examples: UNIX -- Operating system with tool collection EMACS a highly programmable text editor Borland C++ -- A PC environment for C and C++ Smalltalk -- A language processor/environment Microsoft Visual C++ -- A large, complex visual environment Your favorite Java environment: Jbuilder, J++, 25

26 Chapter Two Topics to cover here: Introduction Variables (Names) The Concept of Binding Type Checking 1

27 Introduction Imperative Programming are abstractions of the underlying Von Neumann computer architecture. The two primary components of this architecture are memory and processor. The abstractions in a language for the memory cells of the machine are variables. A variable has attributes: name, address, value, type, lifetime, scope. The design of data types in a language requires many issues to be considered: - scope and lifetime of variables, - type checking and initialization. 2

28 Variable Attributes 1) Names (or identifiers) They are the main attribute of variables. The primary design issues for names are: - What is the maximum length of a name? - Can connector characters be used in names? - Are names case sensitive? - Are the special words reserved word or keywords? 3

29 Name Form A name is a string of characters used to identify some entity in a program. Some name forms in PLs: - In early PL, single-character names are used (as in mathematics) - In Fortran I, Fortran 77, names are restricted to be of length up to 6 characters - In Fortran 90, C, names can be up to 31 characters - In Java, Ada and C++, names have no limits on their length; but implementers of these languages put some limit on names to simplify the maintenance of the symbol table during compilation. 4

30 Name Form.. Cont. In some languages, e.g. Java, C, C++, names are case sensitive. For example, the following 3 names are distinct: Length, LENGTH, length This can be a problem of writability rather than readability. 5

31 Special Words Special words in PLs are used to make programs more readable. 1) A Keyword: It is a word of a PL that is special only in certain context. Example: the word REAL in Fortran language - It is considered as a keyword as in a declarative statement (e.g. REAL salary) - It is considered as variable (name) as in an assignment (e.g. REAL = 3.5) The program reader must recognize the difference between names and special words by context. Redefining keywords can lead to readability problem. 6

32 Special Words.. Cont. 2) A Reserved word It is a special name that cannot be used as a name. Reserved words are better than keywords. 3) Predefined names They are between reserved words and user-defined names. They have predefined meaning but can be redefined by the user. Example: the built-in data type names in Ada, such as INTEGER and FLOAT, are predefined. The definitions of the predefined names in Pascal and Ada must be visible to the compilers of those language because of their compile-time type checking. 7

33 Address The address of a variable is the memory address with which it is associated. In many PLs, it is possible for the name to be associated with different addresses at different places and at different times in the program. Example: A program can have two subprograms, sub1 and sub2, each of which defines a variable named sum. The reference to sum in sub1 is unrelated to the reference to sum in sub2. 8

34 Address.. Cont. The address of a variable is sometimes called its l- value, because that is what is required when a variable appears in the left hand side of an assignment statement. When more than one variable name can be used to access a single memory location, the names are called aliases. For example, if variables A and B are aliases, any change to A also changes B and vice versa. Aliasing makes program verification more difficult. 9

35 Type The type of a variable determines the range of values the variable can have and the set of operations that are defined for values of the type. Example In Fortran, the type INTEGER specifies - a value range of -32,768 to 32,767 - arithmetic operations: +, -, *, / - with some library functions such as function for absolute value. 10

36 Value The value of a variable is the contents of the memory cell or cells associated with the variable. It is convenient to think of computer memory in term of abstract cells rather than physical cells. For example, a floating-point value may occupy 4 physical bytes in a particular language, we think of a floating-point value as occupying a single abstract memory cell. A variable s value is sometimes called r-value because it is what is required when the variable is used on the right side of an assignment statement. 11

37 The Concept of Binding A binding is an association, such as between an attribute and an entity or between an operation and a symbol. A Binding time is the time at which binding takes place. Bindings can take place at: - language design time - language implementation time - compile time - link time - load time - run time 12

38 The Concept of Binding.. Cont. Example Consider the following piece of C++ program: int count; count = count + 5; Some of the bindings and their binding times for this assignment statement are as follows: 13

39 The Concept of Binding.. Cont. Set of possible types for count: bound at language design time. Type of count: bound at compile time. Set of possible values of count: bound at compiler design time. Value of count: bound at execution time with this statement. Set of possible meanings for the operator symbol +: bound at language definition time. Meaning of the operator symbol + in this statement: bound at compile time. Internal representation of the literal 5: bound at compiler design time. 14

40 Binding of Attributes to Variables Bindings made before run time are called static. Bindings made during run time are called dynamic. Note that many bindings are made before compile time. For example, while is bound by the language definition. 15

41 Type Binding A variable must be bound to a data type before referencing it in a program. Types can be specified statically through explicit or implicit declarations. Variable declarations 16 -An explicit declaration declares names and specifies types for them. -An implicit declaration is a means of associating variables with types through default conventions. In this case, the first appearance of a variable name in a program constitutes its implicit declaration (as in Fortran: identifiers begin with one of the letters I, J, K, L, M, or N are implicitly of type INTEGER; otherwise, they are implicitly real. - Both explicit and implicit declarations create static bindings to types.

42 Type Binding.. Cont. Note that x and y have no ``meaning'' in the statement: y = 5*x; Meaning may be provided by placing the statement in an appropriate context as follows: int y; int x; x=6; y = 5 * x; The declaration ``int x;'' binds x. We say that x is bound by that declaration (and likewise y for its declaration). Such statements are called name binding statements, or simply binders. In many imperative languages, name binders are considered separate statements, but this is not true in general. 17

43 Free and Bound Variable Occurrences Notions of free and bound variable occurrences depend upon the surrounding context, which may include binders. A free occurrence of an identifier is a use which has no matching binding: y = 5 * x; // Free occurrences of x and y A declaration occurrence of an identifier is one which declares it: int y; // declaration occurrence of y A bound occurrence of an identifier is a use which has a matching declaration: int y; // Declaration occurrence of y int x; // Declaration occurrence of x x=6; // Bound occurrence of x y = 5 * x; // Bound occurrences of x and y 18

44 Dynamic Type Binding In Dynamic binding, the type is not specified by a declaration statement. The variable is bound to a type when it is assigned a value in an assignment statement. When the assignment statement is executed, the variable on the left side of the assignment is bound to the type of the value, variable, or, expression on the right side of the assignment. APL, NOBOL4, and JavaScript use dynamic binding of variables to types 19

45 Dynamic Type Binding.. Cont. The advantage of dynamic binding of variables to types is that it provides a great deal of programming flexibility. The disadvantages of dynamic type binding are: 1- The errors cannot be detected at compile time. 2- The cost of implementing dynamic attribute binding is considerable, particularly in execution time. - Type checking must be done at run time; - Every variable must have a descriptor associated with it to maintain the current type. - The storage used for the value of a variable must be of varying size. 20

46 21 Type Checking Type checking is the activity of ensuring that the operands of an operator are of compatible types. A Compatible type is one that is either legal for the operator or is allowed under language rules to be implicitly converted by compiler-generated code to a legal type. This automatic conversion is called a coercion. A type error is the application of an operator to an operand of an inappropriate type. Type checking could be: - Static type checking where variables are bound to types statically (at compile-time). - Dynamic type checking where type binding is done at run-time.

47 Strong Typing A strongly typed language is one in which each name in a program in the language has a single type associated with it, and that type is known at compile time. The weakness of this definition is that it ignores the possibility that, although a variable s type may be known, the storage location to which it is bound may store values of different types at different times. Hence, a PL to be strongly typed, the type error should always be detected. The importance of strong typing is to detect all misuses of variables that result in type errors. 22

48 Strong Typing.. Cont. Fortran is not strongly types because the relationship between actual and formal parameter is not type checked. Pascal is nearly strongly typed, but it fails in it design of variant records because it allows omission of the tag that stores the current type of a variable, which provides the means of checking for the correct value types. C and C++ are not strongly typed because they allow functions for which parameter are not type checked. Java is strongly typed. Types can be explicitly cast, which could result in a type error. 23

49 Chapter Three Topics to cover here: Scope - Static Scope -Blocks - Dynamic Scope Scope and Lifetime Referencing Environments Named Constants Variable Initialization 1

50 Scope The scope of program variable is the range of statements in which the variable is visible. A variable is visible in a statement if it can be referenced in that statement. The scope rules of a language determine how a particular occurrence of a name is associated with a variable. A variable is local in a program unit or block if it is declared there. The non-local variables of a program unit or block are those that are visible within the program unit or block but are not declared there. 2

51 Static Scope ALGOL 60 language introduced the method of binding names to non-local variables, called static scoping, which has been copied by most subsequent imperative languages and many non-imperative languages as well. Static scopes in imperative languages are associated with program unit definition. To connect a name reference to a variable, you (or the compiler) must find the declaration Search process: search declarations, first locally, then in increasingly larger enclosing scopes, until one is found for the given name Enclosing static scopes (to a specific scope) are called its static ancestors; the nearest static ancestor is called a static parent In most languages, subprograms create their own scopes. In Pascal, Ada, and JavaScript, subprograms can be nested inside subprograms which can create a hierarchy of scope in a 3 program.

52 4 Static Scope Consider the following Pascal procedure: procedure big; var x : integer; procedure sub1; begin { sub1 } x end; { sub1 } procedure sub2; var x : integer ; begin { sub2 } end; { sub2 } begin { big } end; { big }

53 Static Scope Under static scoping, the reference to the variable x in sub1 is to the x declared in the procedure big. The search for x begins in the procedure in which the reference occurs, sub1. The search continues in the static parent of sub1, big, where the declaration of x is found. In languages that use static scoping, some variable declarations can be hidden from some subprograms. 5

54 Static Scope Consider the following Pascal program: program main; var x : integer; procedure sub1; var x : integer; begin { sub1 } x end { sub1 } begin { main } end. { main } 6

55 Static Scope In the previous example, the reference to x in sub1 is to sub1 s declared x. The x of the main program is hidden from the code of sub1. In general, a declaration for a variable hides any declaration of a variable with the same name in a larger enclosing scope. C and C++ do not allow subprograms to be nested inside other subprogram definitions, but they have global variables, which are declared outside any subprogram definition. Local variables can hide global variables as in Pascal. In C++, a global variable can be accessed using the scope operator (::). For example, if x is a global that is hidden in a subprogram by a local named x, the global could be referenced as ::x 7

56 8 Blocks In ALGOL 60, the concept of block was introduced. A Block is a method of creating static scopes inside program units Inside a block, it is allowed to declare local variables whose scope is minimized. These variables have their storage allocated when the block is entered and deallocated when the block is exited. Examples: C and C++: for (...) { int index;... } In Ada, blocks are specified with declare clauses, as in declare TEMP : integer; begin end ;

57 9 Blocks Pascal and Modula-2 are block-structured languages but do not include nonprocedural blocks. C, C++, and Java allow any compound statements to have declarations and define a new scope. Such compound statements are blocks. Scopes created by blocks are treated like those created by subprograms. References to variables in a block that are not declared there are connected to declarations by searching enclosing scopes in order of increasing size.

58 Blocks C++ and Java allow variable definitions to appear anywhere in functions. The scope of the variable is from its definition statement to the end of the function. The for statements of C++ and Java allow variable definitions in their initialization expressions. The scope is restricted to the for construct. The class and method definitions in object-oriented languages also create nested static scope. 10

59 Evaluation of Static Scoping Consider the example: Assume MAIN calls A and B A calls C and D B calls A and E MAIN A C D MAIN A B B E C D E MAIN MAIN A B A B 11 C D E C D E

60 Evaluation of Static Scoping Suppose the specification is changed so that D must now access some data in B Solutions: 1. Put D in B (but then C can no longer call it and D cannot access A's variables) 2. Move the data from B that D needs to MAIN (but then all procedures can access them) Same problem for procedure access! Overall: static scoping often encourages many globals 12

61 Dynamic Scope Dynamic scope is based on calling sequences of program units, not their textual layout (temporal versus spatial) References to variables are connected to declarations by searching back through the chain of subprogram calls that forced execution to this point 13

62 Example: MAIN - declaration of x SUB1 - declaration of x -... call SUB2... SUB reference to x call SUB1... MAIN calls SUB1 SUB1 calls SUB2 SUB2 uses x Dynamic Scope Static scoping - reference to x is to MAIN's x Dynamic scoping - reference to x is to SUB1's x 14

63 - Advantage: convenience - Disadvantage: poor readability Scope and Lifetime Scope and lifetime are sometimes closely related, but are different concepts!! Consider a static variable in a C or C++ function Evaluation of Dynamic Scoping 15

64 Scope and Lifetime Example Consider the following C++ functions: void printheader ( ) { } // end of printheader void compute ( ) { int sum ; printheader ( ); } // end of compute The scope of the variable sum - is completely contained within compute function; - it does not extend to the body of the function printheader, although printheader execute in the midst of the execution of compute. The lifetime of sum - extends over the time during which printheader executes - Whatever storage location sum is bound to before the call to printheader, that binding will continue during and after the execution of printheader 16

65 Referencing Environments Def: The referencing environment of a statement is the collection of all names that are visible in the statement -In a static scoped language, the referencing environment is the local variables plus all of the visible variables in all of the enclosing scopes - A subprogram is active if its execution has begun but has not yet terminated -In a dynamic-scoped language, the referencing environment is the local variables plus all visible variables in all active subprograms 17

66 Referencing Environments in a Static Scoped Language In Pascal, scopes are created only by procedure definitions (It is a static scoped language). The referencing environment of a statement in Pascal includes: - local variables - all of the variables declared in the procedures in which the statement is nested - variables declared in the main program 18

67 19 Referencing Environments: An Example Program example ; var a, b : integer ; procedure sub1; var x, y : integer ; begin { sub1 } end; { sub1 } procedure sub2 ; var x : integer ; procedure sub3 ; var x : integer ; begin { sub3 } -2 end; { sub3 } begin { sub2 } -3 end; { sub2 } begin { example } -4 end. { example }

68 Referencing Environments: An Example The referencing environment of the indicated points are a follows: Point Referencing Environment 1 x and y of sub1, a and b of example 2 x of sub3, (x of sub2 is hidden), a and b of example 3 x of sub2, a and b of example 4 a and b of example 20

69 Referencing Environments in a Dynamic Scoped Language: An Example Assume that main calls sub2 and sub2 calls sub1 in this example: void sub1( ) { int a, b ; -1 } // end of sub1 void sub2 ( ) { int b, c ; -2 sub1 ( ); } // end of sub2 void main ( ) { int c, d ; -3 sub2 ( ); } // end of main 21

70 Referencing Environments in a Dynamic Scoped Language: An Example The referencing environment of the indicated point are as follows: Point Referencing Environment 1 a and b of sub1, c of sub2, d of main, (c of main and b of ub2 are hidden) 2 b and c of sub2, d of main, (c of main is hidden) 3 c and d of main 22

71 Named Constant and Variable Initialization Def: A named constant is a variable that is bound to a value only when it is bound to storage - Advantages: readability and modifiability The binding of values to named constants can be either static (called manifest constants) or dynamic : Pascal: literals only Modula-2 and FORTRAN 90: constant-valued expressions Ada, C++, and Java: expressions of any kind 23 Def: The binding of a variable to a value at the time it is bound to storage is called initialization Initialization is often done on the declaration statement e.g., Ada SUM : FLOAT := 0.0;

72 Named Constant: An Example Consider the following Java program segment: void example ( ) { int [ ] intlist = new int [100] ; String [ ] strlist = new String[100] ; for ( index = 0 ; index < 100 ; index ++ ) { } for ( index = 0 ; index < 100 ; index ++ ) { } average = sum / 100 ; } 24

73 Named Constant: An Example When the previous program is modified to deal with different number of data values, all occurrences of 100 must be changed. This can be tedious and error-prone The program can be modified to have named constant: 25 void example ( ) { final int len = 100 ; int [ ] intlist = new int [len] ; String [ ] strlist = new String [len] ; for ( index = 0 ; index < len ; index ++ ) { } for ( index = 0 ; index < len ; index ++ ) { } average = sum / len ; }

74 Chapter Four Topics to cover here: Primitive Data Types Character String Types User-Defined Ordinal Types Array Types 1

75 Data Types: An Introduction Evolution of Data Types: FORTRAN I (1956) - INTEGER, REAL, arrays Ada (1983) - User can create a unique type for every category of variables in the problem space and have the system enforce the types All data types need descriptors. Def: A descriptor is the collection of the attributes of a variable Design Issues for All Data Types: 1. What is the syntax of references to variables? 2. What operations are defined and how are they specified? 2

76 Primitive Data Types Primitive Data Types are those not defined in terms of other data types 1- Integer - Almost always an exact reflection of the hardware, so the mapping is trivial - There may be as many as eight different integer types in a language. 2- Floating Point - Model real numbers, but only as approximations - for scientific use support at least two floating-point types; sometimes more - Usually exactly like the hardware, but not always; some languages allow accuracy specs in code e.g. (Ada) type SPEED is digits 7 range ; type VOLTAGE is delta 0.1 range ; 3

77 Primitive Data Types.. Cont. The floating point formats (a) Single precision 8 bits 23 bits Exponent Fraction sign bit (b) Double precision 11 bits 52 bits Exponent Fraction sign bit 4

78 Primitive Data Types.. Cont. Decimal - For business applications (money) - Store a fixed number of decimal digits (coded) - Advantage: accuracy - Disadvantages: limited range, wastes memory 3- Boolean - Could be implemented as bits, but often as bytes - Advantage: readability 5

79 Character String Types - Values are sequences of characters Design issues: 1. Is it a primitive type or just a special kind of array? 2. Is the length of objects static or dynamic? Operations: - Assignment - Comparison (=, >, etc.) - Concatenation - Substring reference - Pattern matching 6

80 Character String Types.. Cont. Examples: - Pascal - Not primitive; assignment and comparison only (of packed arrays) - Ada, FORTRAN 77, FORTRAN 90 and BASIC - Somewhat primitive - Assignment, comparison, concatenation, substring reference - FORTRAN has an intrinsic for pattern matching 7

81 Character String Types.. Cont. Example of String operations: 1- In Ada: N := N1 & N2 (concatenation) N (2..4) (substring reference) 2- In C and C++ - Not primitive - Use char arrays and a library of functions that provide operations (e.g. string.h) 3- SNOBOL4 (a string manipulation language) - Primitive - Many operations, including elaborate pattern matching 4- Perl - Patterns are defined in terms of regular expressions - A very powerful facility! 5- Java - String class (not arrays of char) 8

82 String Length Options 1. Static as in FORTRAN 77, Ada, COBOL e.g. (FORTRAN 90) CHARACTER (LEN = 15) NAME; 2. Limited Dynamic Length as in C and C++ actual length is indicated by a null character 3. Dynamic as in SNOBOL4, Perl 9

83 Evaluation of Character String Types Aid to writability - As a primitive type with static length, they are inexpensive to provide--why not have them? - Dynamic length is nice, but is it worth the expense? 10

84 Implementation of Strings - For Static length strings, a compile-time descriptor is needed such as: Static string Length Address - For Limited Dynamic length strings, a run-time descriptor for length may be needed (but not in C and C++) Limited dynamic string Maximum length Current length Address 11

85 12 Implementation of Strings - The limited dynamic strings of C and C++ do not require runtime descriptor because the end of a string is marked with the null character. - For Dynamic length strings, a run-time descriptor is needed. In this case, - allocation/deallocation is the biggest - implementation problem - the dynamic allocation can be in two ways: 1- Strings can be stored in a linked list 2- Strings are stored in adjacent storage cells. - The allocation and deallocation processes are simple in the linked list implementation (but string operations are slowed by the required pointer chasing). - Using adjacent cells requires less storage and faster string operations.

86 User Defined Ordinal Types An ordinal type is one in which the range of possible values can be easily associated with the set of positive integers. In Pascal and Ada, the primitive ordinal types are: integer, char, Boolean. In many languages, users can define two kinds of ordinal types: enumeration and subrange. 1- Enumeration Type - one in which the user enumerates all of the possible values, which are symbolic constants. e.g. in Ada, enumeration type is declared as follows: type DAYS is (Mon, Tue, Wed, Thu, Fri, Sat, Sun); Design Issue: Should a symbolic constant be allowed to be in more than one type definition? 13

87 1- Enumeration Types Examples: - Pascal - cannot reuse constants; they can be used for array subscripts, for variables, case selectors; NO input or output; can be compared. For example, type colortype = (red, blue, green, yellow); var color : colortype; color := blue; if color > red The Boolean expression of the if will evaluate to true. - Ada - constants can be reused (overloaded literals); disambiguate with context or type_name (one of them); can be used as in Pascal; CAN be input and output. - C and C++ - like Pascal, except they can be input and output as integers. - Java- the enumeration types are classes that implement the Enumeration interface. 14

88 Evaluation of Enumeration Types Aid to readability. - Named values are easily recognized. - e.g. no need to code a color as a number Aid to reliability. - e.g. compiler can check operations and ranges of values 15

89 2. Subrange Type Subrange type is an ordered contiguous subsequence of an ordinal type. For example, is a subrange of integer type Design Issue: How can they be used? Examples: - Pascal Subrange types behave as their parent types; can be used as for variables and array indices e.g. type pos = 0.. MAXINT; index = ; 16

90 2. Subrange Type.. Cont. -Ada - Subranges are not new types just constrained existing types (so they are compatible). - They are included in the class of types called subrange. - They can be used as in Pascal, plus case constants - e.g. subtype WEEKDAYS is DAYS range Mon.. Fri ; subtype INDEX is INTEGER range ; Evaluation of Subrange Types Aid to readability Aid to reliability - restricted ranges add error detection 17

91 Implementation of user-defined ordinal types - Enumeration types are implemented as integers - Subrange types are the parent types with code inserted (by the compiler) to restrict assignments to subrange variables 18

92 Array Types An array is an aggregate of homogeneous data elements in which an individual element is identified by its position in the aggregate, relative to the first element. Design Issues: 1. What types are legal for subscripts? 2. Are subscripting expressions in element references range checked? 3. When are subscript ranges bound? 4. When does allocation take place? 5. What is the maximum number of subscripts? 6. Can array objects be initialized? 7. Are any kind of slices allowed? 19

93 Array and Indexes Indexing is a mapping from indices to elements: array_name (index_value_list) an element Syntax of array references: - FORTRAN, PL/I, Ada use parentheses - Most others use brackets Subscript Types: - FORTRAN, C: int only - Pascal: any ordinal type (int, boolean, char, enum) - Ada: int or enum (includes boolean and char) - Java: integer types only 20

94 Subscript Bindings and Array Categories Four Categories of Arrays (based on subscript binding and binding to storage) 1. Static: range of subscripts and storage bindings are static e.g. FORTRAN 77, some arrays in Ada Advantage: execution efficiency (no allocation or deallocation) 2. Fixed stack dynamic: range of subscripts is statically bound, but storage is bound at elaboration time e.g. Pascal locals and, C locals that are not static Advantage: space efficiency 21

95 Subscript Bindings and Array Categories 3. Stack-dynamic: range and storage are dynamic, but fixed from then on for the variable s lifetime e.g. Ada declare blocks: declare STUFF : array (1..N) of FLOAT; begin... end; Advantage: flexibility - size need not be known until the array is about to be used 22

96 Subscript Bindings and Array Categories 4. Heap-dynamic: subscript range and storage bindings are dynamic and not fixed e.g. In FORTRAN 90, - INTEGER, ALLOCATABLE, ARRAY (:,:) :: MAT (Declares MAT to be a dynamic 2-dim array) - ALLOCATE (MAT (10, NUMBER_OF_COLS)) (Allocates MAT to have 10 rows and NUMBER_OF_COLS columns) - DEALLOCATE MAT (Deallocates MAT s storage) - In APL & Perl, arrays grow and shrink as needed - In Java, all arrays are objects (heap-dynamic) 23

97 Number of Subscripts in Arrays and Array Initialization - FORTRAN I allowed up to three subscripts - FORTRAN 77 allows up to seven - C, C++, and Java allow just one, but elements can be arrays - Others - no limit Arrays are initialized by a list of values that are put in the array in the order in which the array elements are stored in memory Examples: 1. FORTRAN - uses the DATA statement, or put the values in /... / on the declaration 2. C and C++ - put the values in braces; can let the compiler count them e.g. int stuff [ ] = {2, 4, 6, 8}; 3. Ada - positions for the values can be specified e.g. SCORE : array (1..5) of INTEGER := (1 => 3, 2 => 7, 24 3 => 12, others => 0);

98 25 Array Operations An array operation is one that operates on an array as a unit. 1- FORTRAN 77 provides no array operation. 2. Ada has array operations such as: - assignment; RHS can be an aggregate constant or an array name - catenation (specified by & ); for all single-dimensioned arrays - relational operators (= and /= only) 3. FORTRAN 90 has array operations called elemental because they are operations between pairs of array elements: - e.g. + between two arrays - intrinsic (subprograms) for a wide variety of array operations (e.g., matrix multiplication, vector dot product)

99 Evaluation and Implementation of Arrays Evaluation - Arrays are simple and have well developed. - The significance of using dynamic arrays and arrays of subscripts that are of ordinal types Implementation - Access function maps subscript expressions to an address in the array - Row major (by rows) or column major order (by columns) 26

100 Implementation of Arrays - The access function for one-dimensional array Suppose that list is an array of lower bound 1, and we want to access the element indexed by k. The access function is: address (list [k]) = address (list [1]) + (k-1)*element_size Or address (list [k]) = (address (list [1])- element_size) + ( k * element_size ) - The first operand of the + operation is the constant part (can be computed before run time, if the element type is statically bound) - The second operand is the variable part (can be computed at run-time) 27

101 Implementation of Arrays The access function for two-dimensional array To access an element in an array of two dimensions of size n x m, say a[i, j], stored in row major, we have: location(a[i, j]) = address(a[1, 1]) + ((((number of rows above the ith row) * (size of a row)) + (number of rows left of the jth column)) * element size) That is: location (a[i, j]) = address(a[1, 1]) + (((i - 1) * n) + (j - 1)) * element_size 28

102 Chapter Five Topics to cover here: Record Types Union Types Set Types Pointer Types 1

103 Records A record is a possibly heterogeneous aggregate of data elements in which the individual elements are identified by names Design Issues: 1. What is the form of references? 2. What unit operations are defined? Record Definition Syntax - COBOL uses level numbers to show nested records; - others use recursive definitions 2

104 Record Examples In COBOL 01 EMPLOYEE-RECORD. 02 EMPLOYEE-NAME. 05 FIRST PICTURE IS X(20). 05 MIDDLE PICTURE IS X(10). 05 LAST PICTURE IS X(20). 02 HOURLY-RATE PICTURE IS 99V99. 3

105 Record Examples.. Cont. In Ada EMPLOYEE_RECORD : record EMPLOYEE_NAME : record FIRST : STRING (1..20); MIDDLE : STRING (1..10); LAST : STRING (1..20) ; end record ; HOURLY_RATE : FLOAT ; end record ; In C++ struct employee { int id ; string name ; char gender ; float rate ; }; 4

106 Record Field References 1. COBOL field_name OF record_name_1 OF... OF record_name_n e.g. MIDDLE OF EMPLOYEE-NAME OF EMPLOYEE-RECORD 2. Others (dot notation) record_name_1.record_name_2. record_name_n.field_name e.g. EMPLOYEE-RECORD.EMPLOYEE-NAME. MIDDLE Fully qualified references must include all record names (as in COBOL, Ada) Elliptical references allow leaving out record names as long as the reference is unambiguous (as in COBOL, PL/I) 5

107 Record Field References Pascal and Modula-2 provide a with clause to abbreviate references. e.g. Code without with clause Code uses with clause employee.name := Ali ; with employee do employee.age := 42 ; begin employee.sex := M ; name := Ali ; employee.salary := ; age := 42 ; sex := M ; salary := ; end ; { end of with } 6

108 Record Operations 1. Assignment - Pascal, Ada, and C allow it if the types are identical - In Ada, the RHS can be an aggregate constant 2. Initialization - Allowed in Ada, using an aggregate constant 3. Comparison - In Ada, = and /=; one operand can be an aggregate constant 4. MOVE CORRESPONDING - In COBOL - it moves all fields in the source record to fields with the same names in the destination record 7

109 Comparing Records and Arrays 1. Access to array elements is much slower than access to record fields, because subscripts are dynamic (field names are static) 2. Dynamic subscripts could be used with record field access, but it would disallow type checking and it would be much slower 8

110 Implementation of Record Types The compile-time descriptor is as follows: (Note that the descriptor contains the offset address relative to the beginning of the record. This used for field accesses). Field 1 Field 2 Record Name Type Offset... Name Type Offset Address 9

111 Unions A union is a type whose variables are allowed to store different type values at different times during execution Design Issues for unions: 1. What kind of type checking, if any, must be done? 2. Should unions be integrated with records? 10

112 Union Examples 1. FORTRAN - with EQUIVALENCE statement 2. C, C++ : there is the union construct The union in these languages is called free union: the programmer is allowed complete freedom from type checking in their use. 3. Pascal Union Types Type checking of unions requires that each union construct includes a type indicator called tag or discriminant. Pascal has both discriminated and nondiscriminated unions The discriminated union is called a record variant 11

113 Union Examples e.g. type shape = (circle, triangle, rectangle) ; colors = (red, green, blue); figure = record filled : boolean ; color : colors ; case form : shape of circle : (diameter : real ) ; triangle : (leftside : integer ; rightside : integer ; angle : real ) ; rectangle : (side1 : integer; side2 : integer ; ) end; var f1 : figure; 12

114 Union Examples You can access any field by the dot notation such as: case f1.form of circle : writeln ( Circle; diameter =, f1.diameter); rectangle :writeln ( rectangle; sides are:, f1.side1, f1.side2); end Problem with Pascal s design: type checking is ineffective Reasons: a) User can create inconsistent unions (because the tag can be individually assigned) b) The tag is optional! That is, Union could be a free union. Consider the following: 13

115 Union Examples type figure = record case shape of circle : (diameter : real ) ; triangle : (leftside : integer ; rightside : integer ; angle : real ) ; rectangle : (side1 : integer; side2 : integer ; ) end ; - The user and the system cannot determine the current variant type. If f1.diameter := 2.73, then there is no way to guard against incorrect references such as side := f1.leftside; That is, both f1.diameter and f1.leftside can be assigned and referenced at any time. 14

116 Union Examples 4. Ada - discriminated unions - Reasons they are safer than Pascal & Modula-2: a. Tag must be present b. It is impossible for the user to create an inconsistent union (because tag cannot be assigned by itself--all assignments to the union must include the tag value) 5. Java has neither records nor unions Evaluation - potentially unsafe in most languages (not Ada) 15

117 Union Implementation Discriminated unions are implemented by simply using the same address for every possible variant. In case of constrained variants in Ada language, a complete descriptor can be stored at compile time, because there I no variation. e.g. type NODE (TAG : BOOLEAN ) is record case TAG is when true => COUNT : INTEGER ; when false => SUM : FLOAT ; end case; end record; The descriptor of this type is as follows: 16

118 Union Implementation TAG Discriminated Union BOOLEAN Offset Address Case table true false COUNT INTEGER SUM FLOAT Name Type Name Type 17

119 Sets A set is a type whose variables can store unordered collections of distinct values from some ordinal type Design Issue: - What is the maximum number of elements in any set base type? Examples: 1. Pascal - No maximum size in the language definition (not portable, poor writability if max is too small) - Operations: union (+), intersection (*), difference (-), =, <>, superset (>=), subset (<=), in 18

120 Sets.. Cont. 2. Modula-2 and Modula-3 - Additional operations: INCL, EXCL, / (symmetric set difference (elements in one but not both operands)) 3. Ada - does not include sets, but defines in as set membership operator for all enumeration types 4. Java includes a class for set operations 19

121 Set Example type colors = (red, blue, green, yellow, orange, white, black); colorset = set of colors; var set1, set2 : colorset ; set1 := [red, blue, white]; set2 := [black, blue]; 20

122 Sets.. Cont. Evaluation - If a language does not have sets, they must be simulated, either with enumerated types or with arrays - Arrays are more flexible than sets, but have much slower operations Implementation - Usually stored as bit strings and use logical operations for the set operations. 21

123 Pointers A pointer type is a type in which the range of values consists of memory addresses and a special value, nil (or null) Uses: 1. Addressing flexibility 2. Dynamic storage management Design Issues: 1. What is the scope and lifetime of pointer variables? 2. What is the lifetime of heap-dynamic variables? 3. Are pointers restricted to pointing at a particular type? 4. Are pointers used for dynamic storage management, indirect addressing, or both? 5. Should a language support pointer types, reference types, or both? Fundamental Pointer Operations: 1. Assignment of an address to a pointer 2. References (explicit versus implicit dereferencing) 22

124 Problems with Pointers 1. Dangling pointers (dangerous) - A pointer points to a heap-dynamic variable that has been deallocated - Creating one: a. Allocate a heap-dynamic variable and set a pointer to point at it b. Set a second pointer to the value of the first pointer c. Deallocate the heap-dynamic variable, using the first pointer 23

125 Problems with Pointers 2. Lost Heap-Dynamic Variables (wasteful) - A heap-dynamic variable that is no longer referenced by any program pointer - Creating one: a. Pointer p1 is set to point to a newly created heap-dynamic variable b. p1 is later set to point to another newly created heap-dynamic variable - The process of losing heap-dynamic variables is called memory leakage 24

126 Examples of Pointers 1. Pascal: used for dynamic storage management only - Explicit dereferencing - Dangling pointers are possible (dispose) - Dangling objects are also possible 2. Ada: a little better than Pascal and Modula-2 - Some dangling pointers are disallowed because dynamic objects can be automatically deallocated at the end of pointer's scope - All pointers are initialized to null - Similar dangling object problem (but rarely happens) 25

127 Examples of Pointers 3. C and C++ - Used for dynamic storage management and addressing - Explicit dereferencing and address-of operator - Can do address arithmetic in restricted forms - Domain type need not be fixed (void * ) e.g. float stuff[100]; float *p; p = stuff; *(p+5) is equivalent to stuff[5] and p[5] *(p+i) is equivalent to stuff[i] and p[i] - void * - can point to any type and can be type checked (cannot be dereferenced) 26

128 Examples of Pointers 4. FORTRAN 90 Pointers - Can point to heap and non-heap variables - Implicit dereferencing - Special assignment operator for non-dereferenced references e.g. REAL, POINTER :: ptr (POINTER is an attribute) ptr => target (where target is either a pointer or a non-pointer with the TARGET attribute)) - The TARGET attribute is assigned in the declaration, as in: INTEGER, TARGET :: NODE 27

129 Examples of Pointers 5. C++ Reference Types - Reference type variable is a constant pointer that is implicitly dereferenced - Used for parameters - Advantages of both pass-by-reference and pass-by-value - e.g. int result = 0; int &ref = result; // ref is a reference to result 6. Java - Only references - No pointer arithmetic - Can only point at objects (which are all on the heap) - No explicit deallocator (garbage collection is used) - Means there can be no dangling references - Dereferencing is always implicit 28

130 Evaluation of pointers 1. Dangling pointers and dangling objects are problems, as is heap management 2. Pointers are like goto's--they widen the range of cells that can be accessed by a variable 3. Pointers are necessary--so we can't design a language without them 29

131 Memory Management Memory management: identify unused, dynamically allocated memory cells and return them to the heap. Approaches Manual: explicit allocation and deallocation (C, C++) ( by new and delete procedures) - Automatic: Reference counters (modula2, Adobe Photoshop) Garbage collection (Lisp, Java) Problems with manual approach: Requires programmer effort Programmer s failures leads to space leaks and dangling references/sharing Proper explicit memory management is difficult and has been estimated to account for up to 40% of development time! 30

132 31 Solutions to Dangling Pointer Problem (1) Reference Counting Idea: - keep track how many references there are to a cell in memory. - If this number drops to 0, the cell is garbage. - Store garbage in free list; allocate from this list Advantages immediacy resources can be freed directly immediate reuse of memory possible Disadvantages Can t handle cyclic data structures Bad locality properties Large overhead for pointer manipulation

133 Solutions to Dangling Pointer Problem (2) Garbage Collection (GC) GC is a process by which dynamically allocated storage is reclaimed during the execution of a program. Usually refers to automatic periodic storage reclamation by the garbage collector (part of the run-time system), as opposed to explicit code to free specific blocks of memory. Usually triggered during memory allocation when available free memory falls below a threshold. Normal execution is suspended and GC is run. Major GC algorithms: Mark and sweep Copying Incremental garbage collection algorithms 32

134 Mark and Sweep Oldest and simplest algorithm Has two phases: mark and sweep Collection algorithms: When program runs out of memory, stop program, do garbage collection and resume program. Here: Keep free memory in free pool. When allocation encounters empty free pool, do garbage collection. Mark: Go through live memory and mark all live cells. Sweep: Go through whole memory and put a reference to all non-live cells into free pool. 33

135 Mark Algorithm Mark algorithm uses recursion as follows: for every pointer r do mark ( r ) end for procedure mark ( ptr ) begin if ( ptr null ) then if ptr^.tag is not marked then set ptr^.tag mark ( ptr^.llink ) mark ( ptr^.rlink ) end if end if 34

136 Problems with Garbage Collection (GC) The marking algorithm uses a great deal of storage (for stack space to use recursion). If your program need GC most (the program needs most of the cells in the heap), then the GC will work the worst (i.e. most of the cells must be traced and marked as being useful). The cost of additional space of the cell marks. The extra execution time required to execute the collection process. 35

Introduction Primitive Data Types Character String Types User-Defined Ordinal Types Array Types. Record Types. Pointer and Reference Types

Introduction Primitive Data Types Character String Types User-Defined Ordinal Types Array Types. Record Types. Pointer and Reference Types Chapter 6 Topics WEEK E FOUR Data Types Introduction Primitive Data Types Character String Types User-Defined Ordinal Types Array Types Associative Arrays Record Types Union Types Pointer and Reference

More information

Chapter 6. Data Types ISBN

Chapter 6. Data Types ISBN Chapter 6 Data Types ISBN 0-321 49362-1 Chapter 6 Topics Introduction Primitive Data Types Character String Types User-Defined Ordinal Types Array Types Associative Arrays Record Types Union Types Pointer

More information

Chapter 6. Data Types ISBN

Chapter 6. Data Types ISBN Chapter 6 Data Types ISBN 0-321 49362-1 Chapter 6 Topics Introduction Primitive Data Types Character String Types User-Defined Ordinal Types Array Types Associative Arrays Record Types Union Types Pointer

More information

Data Types. Outline. In Text: Chapter 6. What is a type? Primitives Strings Ordinals Arrays Records Sets Pointers 5-1. Chapter 6: Data Types 2

Data Types. Outline. In Text: Chapter 6. What is a type? Primitives Strings Ordinals Arrays Records Sets Pointers 5-1. Chapter 6: Data Types 2 Data Types In Text: Chapter 6 1 Outline What is a type? Primitives Strings Ordinals Arrays Records Sets Pointers Chapter 6: Data Types 2 5-1 Data Types Two components: Set of objects in the type (domain

More information

Chapter 6. Data Types

Chapter 6. Data Types Chapter 6 Data Types Introduction A data type defines a collection of data objects and a set of predefined operations on those objects A descriptor is the collection of the attributes of a variable Copyright

More information

Why study Programming Language Concepts? Chapter One. Language Evaluation Criteria. Programming Domains. Readability Writability Reliability Cost

Why study Programming Language Concepts? Chapter One. Language Evaluation Criteria. Programming Domains. Readability Writability Reliability Cost Chapter One Preliminaries, including Why study PL concepts? Programming domains PL evaluation criteria What influences PL design? Tradeoffs faced by programming languages Implementation methods Programming

More information

Data Types In Text: Ch C apter 6 1

Data Types In Text: Ch C apter 6 1 Data Types In Text: Chapter 6 1 Outline What is a type? Primitives Strings Ordinals Arrays Records Sets Pointers 2 Data Types Two components: Set of objects in the type (domain of values) Set of applicable

More information

Chapter 6. Structured Data Types. Topics. Structured Data Types. Vectors and Arrays. Vectors. Vectors: subscripts

Chapter 6. Structured Data Types. Topics. Structured Data Types. Vectors and Arrays. Vectors. Vectors: subscripts Topics Chapter 6 Structured Data Types Vectors Arrays Slices Associative Arrays Records Unions Lists Sets 2 Structured Data Types Virtually all languages have included some mechanisms for creating complex

More information

Chapter 6 part 1. Data Types. (updated based on 11th edition) ISBN

Chapter 6 part 1. Data Types. (updated based on 11th edition) ISBN Chapter 6 part 1 Data Types (updated based on 11th edition) ISBN 0-321 49362-1 Chapter 6 Topics Introduction Primitive Data Types Character String Types User-Defined Ordinal Types Array Types Associative

More information

CSE 452: Programming Languages. Where are we? Types: Intuitive Perspective. Data Types. High-level Programming Languages.

CSE 452: Programming Languages. Where are we? Types: Intuitive Perspective. Data Types. High-level Programming Languages. CSE 452: Programming Languages Data Types Where are we? Machine Language High-level Programming Languages Assembly Language Logic Object Oriented Imperative Functional You are here Concepts specification

More information

Introduction. Primitive Data Types: Integer. Primitive Data Types. ICOM 4036 Programming Languages

Introduction. Primitive Data Types: Integer. Primitive Data Types. ICOM 4036 Programming Languages ICOM 4036 Programming Languages Primitive Data Types Character String Types User-Defined Ordinal Types Array Types Associative Arrays Record Types Union Types Pointer and Reference Types Data Types This

More information

NOTE: Answer ANY FOUR of the following 6 sections:

NOTE: Answer ANY FOUR of the following 6 sections: A-PDF MERGER DEMO Philadelphia University Lecturer: Dr. Nadia Y. Yousif Coordinator: Dr. Nadia Y. Yousif Internal Examiner: Dr. Raad Fadhel Examination Paper... Programming Languages Paradigms (750321)

More information

Organization of Programming Languages CS3200 / 5200N. Lecture 06

Organization of Programming Languages CS3200 / 5200N. Lecture 06 Organization of Programming Languages CS3200 / 5200N Razvan C. Bunescu School of Electrical Engineering and Computer Science bunescu@ohio.edu Data Types A data type defines a collection of data objects

More information

Chapter 5 Names, Binding, Type Checking and Scopes

Chapter 5 Names, Binding, Type Checking and Scopes Chapter 5 Names, Binding, Type Checking and Scopes Names - We discuss all user-defined names here - Design issues for names: -Maximum length? - Are connector characters allowed? - Are names case sensitive?

More information

COSC252: Programming Languages: Basic Semantics: Data Types. Jeremy Bolton, PhD Asst Teaching Professor

COSC252: Programming Languages: Basic Semantics: Data Types. Jeremy Bolton, PhD Asst Teaching Professor COSC252: Programming Languages: Basic Semantics: Data Types Jeremy Bolton, PhD Asst Teaching Professor Copyright 2015 Pearson. All rights reserved. Common Types and Design Concerns Primitive Data Types

More information

A data type defines a collection of data objects and a set of predefined operations on those objects

A data type defines a collection of data objects and a set of predefined operations on those objects Data Types Introduction A data type defines a collection of data objects and a set of predefined operations on those objects Language selection criterion who well does supported data types match problem

More information

Organization of Programming Languages CS320/520N. Lecture 06. Razvan C. Bunescu School of Electrical Engineering and Computer Science

Organization of Programming Languages CS320/520N. Lecture 06. Razvan C. Bunescu School of Electrical Engineering and Computer Science Organization of Programming Languages CS320/520N Razvan C. Bunescu School of Electrical Engineering and Computer Science bunescu@ohio.edu Data Types A data type defines a collection of data objects and

More information

Chapter 5 Names, Bindings, Type Checking, and Scopes

Chapter 5 Names, Bindings, Type Checking, and Scopes Chapter 5 Names, Bindings, Type Checking, and Scopes 長庚大學資訊工程學系 陳仁暉 助理教授 Tel: (03) 211-8800 Ext: 5990 E-mail: jhchen@mail.cgu.edu.tw URL: http://www.csie.cgu.edu.tw/jhchen All rights reserved. No part

More information

Software II: Principles of Programming Languages

Software II: Principles of Programming Languages Software II: Principles of Programming Languages Lecture 6 Data Types Some Basic Definitions A data type defines a collection of data objects and a set of predefined operations on those objects A descriptor

More information

Chapter 5. Names, Bindings, and Scopes

Chapter 5. Names, Bindings, and Scopes Chapter 5 Names, Bindings, and Scopes Chapter 5 Topics Introduction Names Variables The Concept of Binding Scope Scope and Lifetime Referencing Environments Named Constants 1-2 Introduction Imperative

More information

For each of the following variables named x, specify whether they are static, stack-dynamic, or heapdynamic:

For each of the following variables named x, specify whether they are static, stack-dynamic, or heapdynamic: For each of the following variables named x, specify whether they are static, stack-dynamic, or heapdynamic: a) in C++: int* x = new(int); b) in Java: class book { protected string title; book(string x)

More information

What is a programming language?

What is a programming language? Overview Introduction Motivation Why study programming languages? Some key concepts What is a programming language? What is a programming language?...there is no agreement on what a programming language

More information

CPSC 3740 Programming Languages University of Lethbridge. Data Types

CPSC 3740 Programming Languages University of Lethbridge. Data Types Data Types A data type defines a collection of data values and a set of predefined operations on those values Some languages allow user to define additional types Useful for error detection through type

More information

Programming Languages, Summary CSC419; Odelia Schwartz

Programming Languages, Summary CSC419; Odelia Schwartz Programming Languages, Summary CSC419; Odelia Schwartz Chapter 1 Topics Reasons for Studying Concepts of Programming Languages Programming Domains Language Evaluation Criteria Influences on Language Design

More information

Array Initialization. Rectangular and Jagged Arrays. Arrays Operations. ICOM 4036 Programming Languages. Data Types

Array Initialization. Rectangular and Jagged Arrays. Arrays Operations. ICOM 4036 Programming Languages. Data Types ICOM 4036 Programming Languages Primitive Data Types Character String Types User-Defined Ordinal Types Array Types Associative Arrays Record Types Union Types Pointer and Reference Types Data Types This

More information

SE352b: Roadmap. SE352b Software Engineering Design Tools. W3: Programming Paradigms

SE352b: Roadmap. SE352b Software Engineering Design Tools. W3: Programming Paradigms SE352b Software Engineering Design Tools W3: Programming Paradigms Feb. 3, 2005 SE352b, ECE,UWO, Hamada Ghenniwa SE352b: Roadmap CASE Tools: Introduction System Programming Tools Programming Paradigms

More information

Chapter 6. Data Types. *modified by Stephanie Schwartz ISBN

Chapter 6. Data Types. *modified by Stephanie Schwartz ISBN Chapter 6 Data Types *modified by Stephanie Schwartz ISBN 0-321 49362-1 Chapter 6 Topics Introduction Primitive Data Types Character String Types Enumeration Types Array Types Associative Arrays Record

More information

Chapter 6. Data Types ISBN

Chapter 6. Data Types ISBN Chapter 6 Data Types ISBN 0-321 49362-1 Chapter 6 Topics Introduction Primitive Data Types Character String Types Enumeration Types Array Types Associative Arrays Record Types Tuple Types List Types Union

More information

Record Types. A record is a possibly heterogeneous aggregate of data elements in which the individual elements are identified by names Design issues:

Record Types. A record is a possibly heterogeneous aggregate of data elements in which the individual elements are identified by names Design issues: Record Types A record is a possibly heterogeneous aggregate of data elements in which the individual elements are identified by names Design issues: o What is the syntactic form of references to the field?

More information

Types. What is a type?

Types. What is a type? Types What is a type? Type checking Type conversion Aggregates: strings, arrays, structures Enumeration types Subtypes Types, CS314 Fall 01 BGRyder 1 What is a type? A set of values and the valid operations

More information

Programming Languages Third Edition. Chapter 7 Basic Semantics

Programming Languages Third Edition. Chapter 7 Basic Semantics Programming Languages Third Edition Chapter 7 Basic Semantics Objectives Understand attributes, binding, and semantic functions Understand declarations, blocks, and scope Learn how to construct a symbol

More information

CS 430 Spring Mike Lam, Professor. Data Types and Type Checking

CS 430 Spring Mike Lam, Professor. Data Types and Type Checking CS 430 Spring 2015 Mike Lam, Professor Data Types and Type Checking Type Systems Type system Rules about valid types, type compatibility, and how data values can be used Benefits of a robust type system

More information

Type Bindings. Static Type Binding

Type Bindings. Static Type Binding Type Bindings Two key issues in binding (or associating) a type to an identifier: How is type binding specified? When does the type binding take place? N. Meng, S. Arthur 1 Static Type Binding An explicit

More information

Principles of Programming Languages. Lecture Outline

Principles of Programming Languages. Lecture Outline Principles of Programming Languages CS 492 Lecture 1 Based on Notes by William Albritton 1 Lecture Outline Reasons for studying concepts of programming languages Programming domains Language evaluation

More information

TYPES, VALUES AND DECLARATIONS

TYPES, VALUES AND DECLARATIONS COSC 2P90 TYPES, VALUES AND DECLARATIONS (c) S. Thompson, M. Winters 1 Names, References, Values & Types data items have a value and a type type determines set of operations variables Have an identifier

More information

Chapter 1. Preliminaries

Chapter 1. Preliminaries Chapter 1 Preliminaries Chapter 1 Topics Reasons for Studying Concepts of Programming Languages Programming Domains Language Evaluation Criteria Influences on Language Design Language Categories Language

More information

Chapter 1. Preliminaries

Chapter 1. Preliminaries Chapter 1 Preliminaries Chapter 1 Topics Reasons for Studying Concepts of Programming Languages Programming Domains Language Evaluation Criteria Influences on Language Design Language Categories Language

More information

CSC 533: Organization of Programming Languages. Spring 2005

CSC 533: Organization of Programming Languages. Spring 2005 CSC 533: Organization of Programming Languages Spring 2005 Language features and issues variables & bindings data types primitive complex/structured expressions & assignments control structures subprograms

More information

Question No: 1 ( Marks: 1 ) - Please choose one One difference LISP and PROLOG is. AI Puzzle Game All f the given

Question No: 1 ( Marks: 1 ) - Please choose one One difference LISP and PROLOG is. AI Puzzle Game All f the given MUHAMMAD FAISAL MIT 4 th Semester Al-Barq Campus (VGJW01) Gujranwala faisalgrw123@gmail.com MEGA File Solved MCQ s For Final TERM EXAMS CS508- Modern Programming Languages Question No: 1 ( Marks: 1 ) -

More information

Data Types. Data Types. Introduction. Data Types. Data Types. Data Types. Introduction

Data Types. Data Types. Introduction. Data Types. Data Types. Data Types. Introduction Introduction Primitive Composite Structured Abstract Introduction Introduction Data Type is a Collection of Data Objects Possible r-values for a memory cell Set of operations on those objects Descriptor

More information

CS 230 Programming Languages

CS 230 Programming Languages CS 230 Programming Languages 11 / 20 / 2015 Instructor: Michael Eckmann Questions/comments? Chapter 6 Arrays Pointers Today s Topics We all know what arrays are. Design issues Legal types for subscripts

More information

Chapter 1 Preliminaries

Chapter 1 Preliminaries Chapter 1 Preliminaries Chapter 1 Topics Reasons for Studying Concepts of Programming Languages Programming Domains Language Evaluation Criteria Influences on Language Design Language Categories Language

More information

G Programming Languages - Fall 2012

G Programming Languages - Fall 2012 G22.2110-003 Programming Languages - Fall 2012 Lecture 2 Thomas Wies New York University Review Last week Programming Languages Overview Syntax and Semantics Grammars and Regular Expressions High-level

More information

Data Types. Every program uses data, either explicitly or implicitly to arrive at a result.

Data Types. Every program uses data, either explicitly or implicitly to arrive at a result. Every program uses data, either explicitly or implicitly to arrive at a result. Data in a program is collected into data structures, and is manipulated by algorithms. Algorithms + Data Structures = Programs

More information

COS 140: Foundations of Computer Science

COS 140: Foundations of Computer Science COS 140: Foundations of Computer Science Variables and Primitive Data Types Fall 2017 Introduction 3 What is a variable?......................................................... 3 Variable attributes..........................................................

More information

Answer: Early binding generally leads to greater efficiency (compilation approach) Late binding general leads to greater flexibility

Answer: Early binding generally leads to greater efficiency (compilation approach) Late binding general leads to greater flexibility Quiz Review Q1. What is the advantage of binding things as early as possible? Is there any advantage to delaying binding? Answer: Early binding generally leads to greater efficiency (compilation approach)

More information

9/7/17. Outline. Name, Scope and Binding. Names. Introduction. Names (continued) Names (continued) In Text: Chapter 5

9/7/17. Outline. Name, Scope and Binding. Names. Introduction. Names (continued) Names (continued) In Text: Chapter 5 Outline Name, Scope and Binding In Text: Chapter 5 Names Variable Binding Type bindings, type conversion Storage bindings and lifetime Scope Lifetime vs. Scope Referencing Environments N. Meng, S. Arthur

More information

Concepts of Programming Languages

Concepts of Programming Languages Concepts of Programming Languages COMP322 Fall 2012/2013 1-1 Textbook ISBN 0-321-49362-1 Chapter 1 Preliminaries ISBN 0-321-49362-1 Chapter 1 Topics Reasons for Studying Concepts of Programming Languages

More information

Organization of Programming Languages (CSE452) Why are there so many programming languages? What makes a language successful?

Organization of Programming Languages (CSE452) Why are there so many programming languages? What makes a language successful? Organization of Programming Languages (CSE452) Instructor: Dr. B. Cheng Fall 2004 1 Why are there so many programming languages? Evolution -- we've learned better ways of doing things over time Socio-economic

More information

22c:111 Programming Language Concepts. Fall Types I

22c:111 Programming Language Concepts. Fall Types I 22c:111 Programming Language Concepts Fall 2008 Types I Copyright 2007-08, The McGraw-Hill Company and Cesare Tinelli. These notes were originally developed by Allen Tucker, Robert Noonan and modified

More information

CS 330 Lecture 18. Symbol table. C scope rules. Declarations. Chapter 5 Louden Outline

CS 330 Lecture 18. Symbol table. C scope rules. Declarations. Chapter 5 Louden Outline CS 0 Lecture 8 Chapter 5 Louden Outline The symbol table Static scoping vs dynamic scoping Symbol table Dictionary associates names to attributes In general: hash tables, tree and lists (assignment ) can

More information

Fundamentals of Programming Languages

Fundamentals of Programming Languages Fundamentals of Programming Languages 1. DEFINITIONS... 2 2. BUILT-IN TYPES AND PRIMITIVE TYPES... 3 TYPE COMPATIBILITY... 9 GENERIC TYPES... 14 MONOMORPHIC VERSUS POLYMORPHIC... 16 TYPE IMPLEMENTATION

More information

Introduction. A. Bellaachia Page: 1

Introduction. A. Bellaachia Page: 1 Introduction 1. Objectives... 2 2. Why are there so many programming languages?... 2 3. What makes a language successful?... 2 4. Programming Domains... 3 5. Language and Computer Architecture... 4 6.

More information

Names, Bindings, Scopes

Names, Bindings, Scopes Names, Bindings, Scopes Variables In imperative l Language: abstractions of von Neumann machine Variables: abstraction of memory cell or cells Sometimes close to machine (e.g., integers), sometimes not

More information

Lecture Notes on Programming Languages

Lecture Notes on Programming Languages Lecture Notes on Programming Languages 37 Lecture 04: Data Types and Variables All programming languages provide data types. A data type describes a set of data values and a set of predefined operations

More information

Chapter 8 :: Composite Types

Chapter 8 :: Composite Types Chapter 8 :: Composite Types Programming Language Pragmatics, Fourth Edition Michael L. Scott Copyright 2016 Elsevier 1 Chapter08_Composite_Types_4e - Tue November 21, 2017 Records (Structures) and Variants

More information

COS 140: Foundations of Computer Science

COS 140: Foundations of Computer Science COS 140: Foundations of Variables and Primitive Data Types Fall 2017 Copyright c 2002 2017 UMaine School of Computing and Information S 1 / 29 Homework Reading: Chapter 16 Homework: Exercises at end of

More information

Imperative Programming

Imperative Programming Naming, scoping, binding, etc. Instructor: Dr. B. Cheng Fall 2004 1 Imperative Programming The central feature of imperative languages are variables Variables are abstractions for memory cells in a Von

More information

CPS 506 Comparative Programming Languages. Programming Language

CPS 506 Comparative Programming Languages. Programming Language CPS 506 Comparative Programming Languages Object-Oriented Oriented Programming Language Paradigm Introduction Topics Object-Oriented Programming Design Issues for Object-Oriented Oriented Languages Support

More information

Programming Languages Third Edition. Chapter 10 Control II Procedures and Environments

Programming Languages Third Edition. Chapter 10 Control II Procedures and Environments Programming Languages Third Edition Chapter 10 Control II Procedures and Environments Objectives Understand the nature of procedure definition and activation Understand procedure semantics Learn parameter-passing

More information

CS508-Modern Programming Solved MCQ(S) From Midterm Papers (1 TO 22 Lectures) BY Arslan

CS508-Modern Programming Solved MCQ(S) From Midterm Papers (1 TO 22 Lectures) BY Arslan CS508-Modern Programming Solved MCQ(S) From Midterm Papers (1 TO 22 Lectures) BY Arslan April 18,2017 V-U For Updated Files Visit Our Site : Www.VirtualUstaad.blogspot.com Updated. MidTerm Papers Solved

More information

G Programming Languages Spring 2010 Lecture 6. Robert Grimm, New York University

G Programming Languages Spring 2010 Lecture 6. Robert Grimm, New York University G22.2110-001 Programming Languages Spring 2010 Lecture 6 Robert Grimm, New York University 1 Review Last week Function Languages Lambda Calculus SCHEME review 2 Outline Promises, promises, promises Types,

More information

Chapter 5. Variables. Topics. Imperative Paradigm. Von Neumann Architecture

Chapter 5. Variables. Topics. Imperative Paradigm. Von Neumann Architecture Topics Chapter 5 Variables Imperative Paradigm Variables Names Address Types Assignment Binding Lifetime Scope Constants 2 Imperative Paradigm The most widely used and well-developed programming paradigm.

More information

Chapter 7. - FORTRAN I control statements were based directly on IBM 704 hardware

Chapter 7. - FORTRAN I control statements were based directly on IBM 704 hardware Levels of Control Flow: 1. Within expressions 2. Among program units 3. Among program statements Evolution: - FORTRAN I control statements were based directly on IBM 704 hardware - Much research and argument

More information

Compiler Construction

Compiler Construction Compiler Construction Lecture 18: Code Generation V (Implementation of Dynamic Data Structures) Thomas Noll Lehrstuhl für Informatik 2 (Software Modeling and Verification) noll@cs.rwth-aachen.de http://moves.rwth-aachen.de/teaching/ss-14/cc14/

More information

HANDLING NONLOCAL REFERENCES

HANDLING NONLOCAL REFERENCES SYMBOL TABLE A symbol table is a data structure kept by a translator that allows it to keep track of each declared name and its binding. Assume for now that each name is unique within its local scope.

More information

Structure of Programming Languages Lecture 10

Structure of Programming Languages Lecture 10 Structure of Programming Languages Lecture 10 CS 6636 4536 Spring 2017 CS 6636 4536 Lecture 10: Classes... 1/23 Spring 2017 1 / 23 Outline 1 1. Types Type Coercion and Conversion Type Classes, Generics,

More information

Compiler Construction

Compiler Construction Compiler Construction Thomas Noll Software Modeling and Verification Group RWTH Aachen University https://moves.rwth-aachen.de/teaching/ss-16/cc/ Recap: Static Data Structures Outline of Lecture 18 Recap:

More information

Concepts of Programming Languages

Concepts of Programming Languages Concepts of Programming Languages Lecture 1 - Introduction Patrick Donnelly Montana State University Spring 2014 Patrick Donnelly (Montana State University) Concepts of Programming Languages Spring 2014

More information

CS 3360 Design and Implementation of Programming Languages. Exam 1

CS 3360 Design and Implementation of Programming Languages. Exam 1 1 Spring 2016 (Monday, March 21) Name: CS 3360 Design and Implementation of Programming Languages Exam 1 This test has 18 questions and pages numbered 1 through 6. Reminders This test is closed-notes and

More information

Lecture 13: Object orientation. Object oriented programming. Introduction. Object oriented programming. OO and ADT:s. Introduction

Lecture 13: Object orientation. Object oriented programming. Introduction. Object oriented programming. OO and ADT:s. Introduction Lecture 13: Object orientation Object oriented programming Introduction, types of OO languages Key concepts: Encapsulation, Inheritance, Dynamic binding & polymorphism Other design issues Smalltalk OO

More information

Lecture 4 Memory Management

Lecture 4 Memory Management Lecture 4 Memory Management Dr. Wilson Rivera ICOM 4036: Programming Languages Electrical and Computer Engineering Department University of Puerto Rico Some slides adapted from Sebesta s textbook Lecture

More information

Types II. Hwansoo Han

Types II. Hwansoo Han Types II Hwansoo Han Arrays Most common and important composite data types Homogeneous elements, unlike records Fortran77 requires element type be scalar Elements can be any type (Fortran90, etc.) A mapping

More information

Programmiersprachen (Programming Languages)

Programmiersprachen (Programming Languages) 2016-05-13 Preface Programmiersprachen (Programming Languages) coordinates: lecturer: web: usable for: requirements: No. 185.208, VU, 3 ECTS Franz Puntigam http://www.complang.tuwien.ac.at/franz/ps.html

More information

Review of the C Programming Language

Review of the C Programming Language Review of the C Programming Language Prof. James L. Frankel Harvard University Version of 11:55 AM 22-Apr-2018 Copyright 2018, 2016, 2015 James L. Frankel. All rights reserved. Reference Manual for the

More information

Informatica 3 Syntax and Semantics

Informatica 3 Syntax and Semantics Informatica 3 Syntax and Semantics Marcello Restelli 9/15/07 Laurea in Ingegneria Informatica Politecnico di Milano Introduction Introduction to the concepts of syntax and semantics Binding Variables Routines

More information

Subprograms. Copyright 2015 Pearson. All rights reserved. 1-1

Subprograms. Copyright 2015 Pearson. All rights reserved. 1-1 Subprograms Introduction Fundamentals of Subprograms Design Issues for Subprograms Local Referencing Environments Parameter-Passing Methods Parameters That Are Subprograms Calling Subprograms Indirectly

More information

Storage. Outline. Variables and updating. Copy vs. Ref semantics Lifetime. Dangling References Garbage collection

Storage. Outline. Variables and updating. Copy vs. Ref semantics Lifetime. Dangling References Garbage collection Storage 1 Variables and updating Outline Copy vs. Ref semantics Lifetime Local and global variables Heap variables Persistent variables Dangling References Garbage collection 2 Variables and Updating Variable:

More information

CSCI312 Principles of Programming Languages!

CSCI312 Principles of Programming Languages! CSCI312 Principles of Programming Languages! Chapter 5 Types Xu Liu! ! 5.1!Type Errors! 5.2!Static and Dynamic Typing! 5.3!Basic Types! 5.4!NonBasic Types! 5.5!Recursive Data Types! 5.6!Functions as Types!

More information

The SPL Programming Language Reference Manual

The SPL Programming Language Reference Manual The SPL Programming Language Reference Manual Leonidas Fegaras University of Texas at Arlington Arlington, TX 76019 fegaras@cse.uta.edu February 27, 2018 1 Introduction The SPL language is a Small Programming

More information

CS558 Programming Languages

CS558 Programming Languages CS558 Programming Languages Fall 2016 Lecture 3a Andrew Tolmach Portland State University 1994-2016 Formal Semantics Goal: rigorous and unambiguous definition in terms of a wellunderstood formalism (e.g.

More information

Programming Languages

Programming Languages Programming Languages Tevfik Koşar Lecture - XVIII March 23 rd, 2006 1 Roadmap Arrays Pointers Lists Files and I/O 2 1 Arrays Two layout strategies for arrays Contiguous elements Row pointers Row pointers

More information

Programming Languages

Programming Languages Programming Languages Types CSCI-GA.2110-001 Summer 2011 What is a type? A type consists of a set of values The compiler/interpreter defines a mapping of these values onto the underlying hardware. 2 /

More information

Review of the C Programming Language for Principles of Operating Systems

Review of the C Programming Language for Principles of Operating Systems Review of the C Programming Language for Principles of Operating Systems Prof. James L. Frankel Harvard University Version of 7:26 PM 4-Sep-2018 Copyright 2018, 2016, 2015 James L. Frankel. All rights

More information

Programming Languages: Lecture 11

Programming Languages: Lecture 11 1 Programming Languages: Lecture 11 Chapter 9: Subprograms Jinwoo Kim jwkim@jjay.cuny.edu Chapter 9 Topics 2 Introduction Fundamentals of Subprograms Design Issues for Subprograms Local Referencing Environments

More information

Data Types (cont.) Subset. subtype in Ada. Powerset. set of in Pascal. implementations. CSE 3302 Programming Languages 10/1/2007

Data Types (cont.) Subset. subtype in Ada. Powerset. set of in Pascal. implementations. CSE 3302 Programming Languages 10/1/2007 CSE 3302 Programming Languages Data Types (cont.) Chengkai Li Fall 2007 Subset U = { v v satisfies certain conditions and v V} Ada subtype Example 1 type Digit_Type is range 0..9; subtype IntDigit_Type

More information

Subprograms. Bilkent University. CS315 Programming Languages Pinar Duygulu

Subprograms. Bilkent University. CS315 Programming Languages Pinar Duygulu 1 Subprograms CS 315 Programming Languages Pinar Duygulu Bilkent University Introduction 2 Two fundamental abstraction facilities Process abstraction Emphasized from early days Data abstraction Emphasized

More information

Chapter 9 Subprograms

Chapter 9 Subprograms Chapter 9 Subprograms We now explore the design of subprograms, including parameter-passing methods, local referencing environment, overloaded subprograms, generic subprograms, and the aliasing and problematic

More information

Topic IV. Parameters. Chapter 5 of Programming languages: Concepts & constructs by R. Sethi (2ND EDITION). Addison-Wesley, 1996.

Topic IV. Parameters. Chapter 5 of Programming languages: Concepts & constructs by R. Sethi (2ND EDITION). Addison-Wesley, 1996. References: Topic IV Block-structured procedural languages Algol and Pascal Chapters 5 and 7, of Concepts in programming languages by J. C. Mitchell. CUP, 2003. Chapter 5 of Programming languages: Concepts

More information

Lecture 12: Data Types (and Some Leftover ML)

Lecture 12: Data Types (and Some Leftover ML) Lecture 12: Data Types (and Some Leftover ML) COMP 524 Programming Language Concepts Stephen Olivier March 3, 2009 Based on slides by A. Block, notes by N. Fisher, F. Hernandez-Campos, and D. Stotts Goals

More information

6. Names, Scopes, and Bindings

6. Names, Scopes, and Bindings Copyright (C) R.A. van Engelen, FSU Department of Computer Science, 2000-2004 6. Names, Scopes, and Bindings Overview Names Binding time Object lifetime Object storage management Static allocation Stack

More information

Data Types. (with Examples In Haskell) COMP 524: Programming Languages Srinivas Krishnan March 22, 2011

Data Types. (with Examples In Haskell) COMP 524: Programming Languages Srinivas Krishnan March 22, 2011 Data Types (with Examples In Haskell) COMP 524: Programming Languages Srinivas Krishnan March 22, 2011 Based in part on slides and notes by Bjoern 1 Brandenburg, S. Olivier and A. Block. 1 Data Types Hardware-level:

More information

CS 536 Introduction to Programming Languages and Compilers Charles N. Fischer Lecture 11

CS 536 Introduction to Programming Languages and Compilers Charles N. Fischer Lecture 11 CS 536 Introduction to Programming Languages and Compilers Charles N. Fischer Lecture 11 CS 536 Spring 2015 1 Handling Overloaded Declarations Two approaches are popular: 1. Create a single symbol table

More information

Attributes, Bindings, and Semantic Functions Declarations, Blocks, Scope, and the Symbol Table Name Resolution and Overloading Allocation, Lifetimes,

Attributes, Bindings, and Semantic Functions Declarations, Blocks, Scope, and the Symbol Table Name Resolution and Overloading Allocation, Lifetimes, Chapter 5 Basic Semantics Attributes, Bindings, and Semantic Functions Declarations, Blocks, Scope, and the Symbol Table Name Resolution and Overloading Allocation, Lifetimes, and the Environment Variables

More information

Binding and Variables

Binding and Variables Binding and Variables 1. DEFINITIONS... 2 2. VARIABLES... 3 3. TYPE... 4 4. SCOPE... 4 5. REFERENCES... 7 6. ROUTINES... 9 7. ALIASING AND OVERLOADING... 10 8. GENERICS AND TEMPLATES... 12 A. Bellaachia

More information

Topic IV. Block-structured procedural languages Algol and Pascal. References:

Topic IV. Block-structured procedural languages Algol and Pascal. References: References: Topic IV Block-structured procedural languages Algol and Pascal Chapters 5 and 7, of Concepts in programming languages by J. C. Mitchell. CUP, 2003. Chapters 10( 2) and 11( 1) of Programming

More information

The PCAT Programming Language Reference Manual

The PCAT Programming Language Reference Manual The PCAT Programming Language Reference Manual Andrew Tolmach and Jingke Li Dept. of Computer Science Portland State University September 27, 1995 (revised October 15, 2002) 1 Introduction The PCAT language

More information

Storage. Outline. Variables and Updating. Composite Variables. Storables Lifetime : Programming Languages. Course slides - Storage

Storage. Outline. Variables and Updating. Composite Variables. Storables Lifetime : Programming Languages. Course slides - Storage Storage 1 Variables and Updating Outline Composite Variables Total and selective updating Array variables Storables Lifetime Local and global variables Heap variables Persistent variables Garbage collection

More information

Fundamentals of Programming Languages. Data Types Lecture 07 sl. dr. ing. Ciprian-Bogdan Chirila

Fundamentals of Programming Languages. Data Types Lecture 07 sl. dr. ing. Ciprian-Bogdan Chirila Fundamentals of Programming Languages Data Types Lecture 07 sl. dr. ing. Ciprian-Bogdan Chirila Predefined types Programmer defined types Scalar types Structured data types Cartesian product Finite projection

More information

Programming Languages 2nd edition Tucker and Noonan"

Programming Languages 2nd edition Tucker and Noonan Programming Languages 2nd edition Tucker and Noonan" " Chapter 1" Overview" " A good programming language is a conceptual universe for thinking about programming. " " " " " " " " " " " " "A. Perlis" "

More information