Lectures 12 to 14

Lectures 12 to 14 - ----------------------------- 2-25-10

Info iconThis preview shows pages 1–3. Sign up to view the full content.

View Full Document Right Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: ----------------------------- 2-25-10 ------------------------------ PascalALGOLs like language, introduced by Niklaus Wirth (1971), but more reliable, efficient, and simpleforpedagogicpurposes (including for system programming). PASCAL introduced a much richer type systemthan ALGOL: A)type and Const declarations. B)Enumeration Types: To handle non-numeric data, eliminating the insecurity of overworking integers as such needed types. (exists in C, Pascal, and Ada) type month = (Jan, Feb, March, Apr, , Dec); Day = (Sun, Mon, Tue, , Sat); In C: enumStudentClass {Fresh, Soph, Junior, Senior} enumEmployeeGender {Male, Female} In Ada: type Days is ((Sun, Mon, Tue, , Sat); They are true ADTs, withuser defined data type, and systembuilt-in operators: :=, succ, pred, =, , <, >, , Advantages: 1-High level application oriented, allowing the language to cover wider area of applications. 2-Efficient use of memory to represent the type values. 3-Secure use of type elements, the compiler protects against any meaningless operations by the users on elements of the defined types. Pred(Jan) and succ (Sat) will produce compile time errors. Question: Can we still use the standard input/output commands for enumerated types? Problems? Yes: 1-No Input/output built in operations! (why?) 2-Overloaded enumerated literal constants when appearing in different definitions at the same environment. Ex:typefavoriteColors =(red, yellow, magenta, brown, aqua, blue, green);TrafficLightColors =(red, yellow, green);forcolor inred ..green do Noticethatcoloris implicitly typed with the specified discrete range by the compiler. The discrete range is ambiguous(!) since the compiler will not know to which type it belongs: favoriteColorsor TrafficLightColors? Hence, C and Pascal do not allowthe same element name to be used in more than one enumeration type in the same scope. Solution by Ada--Ada allows it but to resolve the name overloading:forcolor infavoriteColors (red) .. favoriteColors(green) do C)Subrange Types: Pascal (and other languages like Ada) allows the programmer to define subranges of only discrete types (enumerated, int, characters), where it inherits all of its parent defined set of operations. type uppercase = A..Z; index = 1..100; WeekDays = Mon..Fri; Advantages: 1-Enhances readability. 2-Security, errorsdue the assignment of out of range value will be detected at compile time,in case of literal constant value; or at run time,in case of expression/variable assignment. 3-Efficient memory representation of the type values. *Noticethat when the subrange inheritsits parents set of operations, it introduces security loophole. For example, dayOfMonth = 1..31, it is maybe ok to add/subtract the days of month, but what about dividing/multiplying them??!!...
View Full Document

This note was uploaded on 08/23/2011 for the course CSE 324 taught by Professor Soliman during the Spring '11 term at NMT.

Page1 / 9

Lectures 12 to 14 - ----------------------------- 2-25-10

This preview shows document pages 1 - 3. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online