1 / 20

Pascal

Pascal. Jinbo Lin. Pascal. Structured and Strong type language program HelloWorld; uses crt; var x:string='Hello, World!'; begin writeln( x ); readkey; end. History. Pascal is a programming language that grew out from ALGOL. Published by Dr. Niklaus Wirth in 1971.

lovelessj
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 Jinbo Lin

  2. Pascal • Structured and Strong type language • program HelloWorld; • uses crt; • var x:string='Hello, World!'; • begin • writeln(x); • readkey; • end.

  3. History • Pascal is a programming language that grew out from ALGOL. • Published by Dr. Niklaus Wirth in 1971. • Designed as a teaching programming language. • Later, Dr. Ken Bowles in UCSD adapt the Pascal compiler to Apple II. • By early 1980's, U.S. Educational Testing Service decide to add a computer science AP Exam, Pascal was chosen. • In 1999, C++ replaced Pascal, and Java replaced C++ soon after that.

  4. Names, Binding, and Scopes • Pascal is case insensitive. • letters, digits, and _ are only characters allowed to make identifiers. • Different types of compiler has its own rules on the length of identifier name. • Static Binding • All ALGOL based language are static scoping, which includes Pascal.

  5. Data Types • Simple : • integer • real • character • boolean • user-defined type • Structured: • array • record • file • set • Pointer.

  6. Data Types (Integer) • Pascal has many ways to define those data types, and each type may be vary on the range and the memory size. • Ten types of Integer: • byte : 0 to 255, 1 byte • smallint: -(2^15) to (2^15) -1, 2 bytes • longint: -(2^31) to (2^31)-1 , 4 bytes • ingeter, shortint, word, cardinal, qword, longword, int64. • The most common way, integer, will be stored as either smallint or longint.

  7. Data Types (String) • String: • character array: a sequence of zero or more characters enclosed by single quotes. (e.g. myString: pack array [1..20] of char) • string: a sequence of characters with an optional size specification. (e.g. myString: string) • short string: a string type that with the specification of length (e.g. myString: string[20]) • null terminated string: use a null value at the end of actual string value to indicate the length (e.g. myString: pchar)

  8. Expressions and Assignment Statements • operator precedency rule is the same as other language • Strict type checking • Only two exception: • implicit data type conversion within same group • implicit data type conversion with int and real. • Pascal Support Operator Overloading

  9. Control Structure • Selection • if then • if then else • case • Iteration • for do • while do • repeat until • key word: break, continue.

  10. Control Structure Cont. program example; uses crt; label 1; var i : integer; begin i := 1; 1: repeat if( i = 7) then begin i := i + 1; goto 1; end; writeln('value of i: ', i); i:= i +1; until i = 10; readkey; end. • Goto: statement that provides an unconditional jump from the goto to a labeled statement in the same function. • value of i: 1 • value of i: 2 • value of i: 3 • value of i: 4 • value of i: 5 • value of i: 6 • value of i: 8 • value of i: 9

  11. SubProgram • Procedure vs Function • header, local declaration, body • pass by reference vs. pass by value function name(argument(s): type1; argument(s): type2; ...): function_type; local declarations; begin ... < statements > ... name:= expression; end;

  12. Support of Object-Oriented Programming • Object Pascal • Object vs. Class • Stack vs. Heap type object-identifier = object private field1 : field-type; field2 : field-type; ... public procedure proc1; function f1(): function-type; end;

  13. Concurrency • Concurrent Pascal, or Pascal FC • Constructs that are removed: • records • goto statement and labels • procedures as parameter • packed arrays • pointer types • file types.

  14. Exception Handling • Try • Except • Finally

  15. Readability • Pros: • Code is structured • Simplicity: not flexible • More English words than symbols • Cons: • Too many ways to define a data type like string and integer. • use begin .. end instead of { .. } • Conclusion: high readability.

  16. Writability • Pros: • Case Insensitive • Operator Overloading • Abstract data types • Cons: • More English words than symbols • Lack of flexibility • Relatively less API available • Conclusion: decent Writability

  17. Reliability • Pros: • Strongly typed • Support for exception handling • Rich data types set • Cons: • Aliasing: pointer and pass by reference mode • Conclusion: super reliable

  18. Cost • Software: two major IDE: Lazarus and Delphi, are free to download online. • Hardware: Lazarus is a cross-platform IDE that can run on Windows, Linux and Mac. • Overall: Pascal has high readability, decent writability, and it is super reliable. The price is, Pascal is not powerful.

More Related