1 / 12

Pascal

Pascal. By: Liane Tom. Outline. Background Data types and Syntax Procedures and Functions Advantages Disadvantages. Background. Named after mathematician and philosopher Blaise Pascal. Developed by Niklaus Wirth Based on ALGOL Designed to be a block-structured language for general use

Download Presentation

Pascal

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Pascal By: Liane Tom

  2. Outline • Background • Data types and Syntax • Procedures and Functions • Advantages • Disadvantages

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

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

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

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

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

  8. Data Types and Syntax Cont’d • Program

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

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

  11. Disadvantages • Compiled language – takes more time to develop and test small Pascal programs • Can overload variables names between main program and procedures • Not that much flexibility since it is strongly-typed • 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 • Kernighan, Brian W., “Why Pascal is Not My Favorite Programming Language”. 2 Apr 1981. University of Virginia, Department of Computer Science. 11 Apr 2006. <http://www.cs.virginia.edu/~evans/cs655-S00/readings/bwk-on-pascal.html>. • “Modula-2”. 8 Apr 2006. Wikipedia. 11 Apr 2006. <http://en.wikipedia.org/wiki/Modula-2>. • Nance, Douglas W., Fundamentals of Pascal: Understanding Programming and Problem Solving. West Publishing Company, 1986. • “Pascal Programming Language”. 11 Apr 2006. Wikipedia. 11 Apr 2006. <http://en.wikipedia.org/wiki/Pascal_programming_language>. • Sebesta, Robert W., Concepts of Programming Languages. 7th ed. Pearson Education, Inc., 2006.

More Related