Presentation is loading. Please wait.

Presentation is loading. Please wait.

Pascal By: Liane Tom. Outline o Background o Data types and Syntax o Procedures and Functions o Advantages o Disadvantages.

Similar presentations


Presentation on theme: "Pascal By: Liane Tom. Outline o Background o Data types and Syntax o Procedures and Functions o Advantages o Disadvantages."— Presentation transcript:

1 Pascal By: Liane Tom

2 Outline o Background o Data types and Syntax o Procedures and Functions o Advantages o Disadvantages

3 Background o Named after mathematician and philosopher Blaise Pascal. o Developed by Niklaus Wirth o Based on ALGOL o Designed to be a block-structured language for general use o It is a compiled language o Developing and testing programs might take longer than other languages. o Designed for teaching programming to computer science, engineering, and science students o Used for undergraduate courses until the late 1990s

4 Data Types and Syntax o Reserved words o AND, ARRAY, BEGIN, CASE, CONST, DIV, DO, etc. o Predefined identifiers o Programmer can change meaning o boolean, char, integer, real, text, false, etc. o Ordinal Data Types o Integer, char, and boolean o Data are countable, each has a unique predecessor and successor, and they can be ordered and compared o User-Defined Types o Frequently referred to as enumerated types o TYPE Weekday = (Mon, Tues, Wed, Thur, Fri); VAR Day : Weekday;

5 Data Types and Syntax Cont’d o String constants o If a word of one or more characters is used. o Defined in the CONST portion of the declaration section. o Entire string must be enclosed in single quotation marks. o Ex. CONST Name = ‘Liane Tom’; Date = ‘May 1, 2006’; o Array o Two methods to declare o VAR List : ARRAY[1..5] OF integer; o TYPE Numbers = ARRAY[1..5] OF integer; VAR List : Numbers;

6 Data Types and Syntax Cont’d o Records o A collection of fields that may be treated as a whole or individually o Ex. VAR Customer : RECORD Name : Array [1..30] OF char; Age : integer; AnnualIncome : real; END;

7 Data Types and Syntax Cont’d o Sets o Structured data type consisting of a collection of distinct elements from an ordinal base type o TYPE type name = SET OF base type; VAR variable name = type name; o Ex. TYPE Alphabet = SET OF ‘A’.. ‘Z’; VAR Vowels, Consonants : Alphabet; o Once a set variable is declared, it is undefined until an assignment of values is made o Ex. Vowels := [‘A’,’E’,’I’,’O’,’U’];

8 Data Types and Syntax Cont’d o Program

9 Procedures and Functions o Procedures o Procedure heading instead of program heading. o PROCEDURE procedure name(parameter list); o END is followed by a semicolon instead of a period o Declared in the VAR section in the main program o Procedure heading is also an identifier, so variable identifiers cannot use the same names if they are on the same level. o Ex. PROGRAM Demo2 (output); VAR Prac : integer; PROCEDURE Prac (A : integer); o Functions o FUNCTION function name(parameter list) : return type; o Some value must be assigned to the function name in the executable section of the function o Cube := X*X*X; o Function name cannot be used on the right side of an assignment statement within the function. o Cube := Cube + 1; o In the calling program, the function name cannot be used on the left of an assignment statement.

10 Advantages o Simple and expressive o Program structure of the main program, procedures, and functions are all similar o Heading o Declaration section o Execution section o No restriction on the length of variable, function, or procedure names o Strongly-typed language so variables can only be assigned to the correct data type

11 Disadvantages o Compiled language – takes more time to develop and test small Pascal programs o Can overload variables names between main program and procedures o Not that much flexibility since it is strongly-typed o No static variables – no variable can be private to another routine and retain its value from one call of the routine to the next

12 Resources o Kernighan, Brian W., “Why Pascal is Not My Favorite Programming Language”. 2 Apr 1981. University of Virginia, Department of Computer Science. 11 Apr 2006.. o “Modula-2”. 8 Apr 2006. Wikipedia. 11 Apr 2006.. o Nance, Douglas W., Fundamentals of Pascal: Understanding Programming and Problem Solving. West Publishing Company, 1986. o “Pascal Programming Language”. 11 Apr 2006. Wikipedia. 11 Apr 2006.. o Sebesta, Robert W., Concepts of Programming Languages. 7th ed. Pearson Education, Inc., 2006.


Download ppt "Pascal By: Liane Tom. Outline o Background o Data types and Syntax o Procedures and Functions o Advantages o Disadvantages."

Similar presentations


Ads by Google