Skip to Content
Concepts and Semantics of Programming Languages 1
book

Concepts and Semantics of Programming Languages 1

by Therese Hardin, Mathieu Jaume, Francois Pessaux, Veronique Viguie Donzeau-Gouge
August 2021
Intermediate to advanced
336 pages
7h 18m
English
Wiley-ISTE
Content preview from Concepts and Semantics of Programming Languages 1

6Data Types

6.1. Basic types

The languages Exp2 , . . . , Lang3 that we used to describe the notions of semantics and typing only consider two data types: integers and booleans. However, most programming languages include many more basic types. In this section, we shall present the most widespread data types, along with the ways in which they differ between languages.

6.1.1. Booleans

For certain languages, such as OCaml, Java, Ada and Pascal, the boolean type bool is a constructor of the type algebra and has two possible values: true and false. Other languages, such as C and C++, encode boolean values as integers, with a value of 0 conventionally used to mean “false” and any other value corresponding to “true”. Some of these languages, such as C++, include a type bool and predefined identifiers false and true but these values are fully compatible with integer values. Any integer expression may be used as the condition for a loop or an if-then-else. Any boolean expression may be used as an index in an array, or as an operand in an arithmetic operation. This makes the source text harder to understand and may lead to errors, which are difficult to detect.

Python behaves somewhat differently. It supplies two values, True and False,but allows integers and booleans to be mixed. It is thus possible to test whether or not an integer value is equal or different to a boolean value, or to use an integer value as the test for a condition. These practices are not recommended, see the examples ...

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Programming Languages: Concepts and Implementation

Programming Languages: Concepts and Implementation

Saverio Perugini

Publisher Resources

ISBN: 9781786305305Purchase Link