Expression and Statements
Expression and Statements
Expressions
Statements
Exercises
Programming Language
Mai 02nd 2024, Dr.Thomas MESSI NGUELE Programming Languages – Expressions and Statem. 1 / 17
Chapter Goals
Expressions
Statements
Exercises
Chapter Goals
Mai 02nd 2024, Dr.Thomas MESSI NGUELE Programming Languages – Expressions and Statem. 2 / 17
Chapter Goals
Expressions
Statements
Exercises
Agenda
1 Chapter Goals
2 Expressions
3 Statements
4 Exercises
Mai 02nd 2024, Dr.Thomas MESSI NGUELE Programming Languages – Expressions and Statem. 3 / 17
Chapter Goals Generalities on Expressions
Expressions Tree structure
Statements Boolean expressions
Exercises Mixed - Mode expressions
Agenda
1 Chapter Goals
2 Expressions
Generalities on Expressions
Tree structure
Boolean expressions
Mixed - Mode expressions
3 Statements
4 Exercises
Mai 02nd 2024, Dr.Thomas MESSI NGUELE Programming Languages – Expressions and Statem. 4 / 17
Chapter Goals Generalities on Expressions
Expressions Tree structure
Statements Boolean expressions
Exercises Mixed - Mode expressions
Generalities on Expressions
1 An expression is a combinaison of one or more constants, variables,
operators and functions intended to be computed in order to produce a value.
2 In others words, an expression is composed of one or more operands whose
values may be combined by operators.
3 Example is "4.0 + a ∗ b" which evaluation is as follow :
First substitute values for variables a and b.
Multiply these values.
Add 4.0 to the previous result.
4 There are precedence rules in order to avoid non determinism. For example,
in java, the evaluation is as follow :
a - Evaluate any expression enclosed within brackets first, starting with the
innermost brackets.
b - Apply the following operator precedence :
! * / % + - > < >= <= == != && || =
c - If the opperators in (b-) have the same precedence, apply them in order from
left to right.
Mai 02nd 2024, Dr.Thomas MESSI NGUELE Programming Languages – Expressions and Statem. 5 / 17
Chapter Goals Generalities on Expressions
Expressions Tree structure
Statements Boolean expressions
Exercises Mixed - Mode expressions
1 The values of b and c are first multiplied together, the result is then divided
by d and finaly added to a value.
2 The evaluation of an expression should produce a value and nothing more ; it
should not change the state of a program.
3 Operators in expressions can be binary (dyadic) or unary (monadic).
Mai 02nd 2024, Dr.Thomas MESSI NGUELE Programming Languages – Expressions and Statem. 6 / 17
Chapter Goals Generalities on Expressions
Expressions Tree structure
Statements Boolean expressions
Exercises Mixed - Mode expressions
Boolean expressions
Mai 02nd 2024, Dr.Thomas MESSI NGUELE Programming Languages – Expressions and Statem. 7 / 17
Chapter Goals Generalities on Expressions
Expressions Tree structure
Statements Boolean expressions
Exercises Mixed - Mode expressions
1 An expression in which the two operands do not have the same type is called
a mixed-mode expression.
2 Three categories of languages can be identified :
Languages that forbit mixed-mode expressions (Ada).
Languages like Pascal and Java that allow ’sensible’ combinations such as
adding an intenger to floating-point value. The result of such an expression is,
as would be expected, a floating-point value.
Languages like C and C++ that allow ’unusual’ combinations such as the
ability to add an integer to a character. This can lead to unexpected results.
Mai 02nd 2024, Dr.Thomas MESSI NGUELE Programming Languages – Expressions and Statem. 8 / 17
Chapter Goals Generalities
Expressions Assignment Statements
Statements Compound Statements
Exercises Other statements
Agenda
1 Chapter Goals
2 Expressions
3 Statements
Generalities
Assignment Statements
Compound Statements
Other statements
4 Exercises
Mai 02nd 2024, Dr.Thomas MESSI NGUELE Programming Languages – Expressions and Statem. 9 / 17
Chapter Goals Generalities
Expressions Assignment Statements
Statements Compound Statements
Exercises Other statements
Generalities
Mai 02nd 2024, Dr.Thomas MESSI NGUELE Programming Languages – Expressions and Statem. 10 / 17
Chapter Goals Generalities
Expressions Assignment Statements
Statements Compound Statements
Exercises Other statements
Assignment Statements
1 The general form of the assignment is "el :=er".
el is the expression on the left-hand side of an assignement that gives a
reference as its results.
er is the expression on the right-hand side of an assignment that gives a value
as its result.
2 The value of the right-hand expression is assigned to the reference given by
the left-hand expression.
3 Assignment is an operation on reference-value pairs.
4 There are restriction on el :
It should be variable name, field of a record.
Compatibility between the type of el and the type of value given by er.
Assignment Operators
=, +=, -=, *=, /=, ++, –
*b++ ?, a = 1, Is there any difference between b=a++ and b=++a ?
Mai 02nd 2024, Dr.Thomas MESSI NGUELE Programming Languages – Expressions and Statem. 11 / 17
Chapter Goals Generalities
Expressions Assignment Statements
Statements Compound Statements
Exercises Other statements
Compound Statements
Mai 02nd 2024, Dr.Thomas MESSI NGUELE Programming Languages – Expressions and Statem. 12 / 17
Chapter Goals Generalities
Expressions Assignment Statements
Statements Compound Statements
Exercises Other statements
Other statements
1 Selection with if and switch case or case of "selector".
2 Iterative statements. Loops are terminated in one of two ways :
either by a condition being fulfilled,
or by completing a fixe number of iterations.
Example : for loop, while loop, repeat loop.
A mechanism for iterating over the elements of a data structure is known as
an iterator.
3 goto statement. Jumps
4 Exception handling.
During programming excution, "exceptional" evens may occur.
Such exceptional occurrences can arise as a result of errors,
such as attempted division by zero, erroneous user input,
an array subscript going out of bounds,
unexpectedly encoutering the end of the file.
Java : try { }catch(){ ... }
Mai 02nd 2024, Dr.Thomas MESSI NGUELE Programming Languages – Expressions and Statem. 13 / 17
Chapter Goals
Expressions
Statements
Exercises
Agenda
1 Chapter Goals
2 Expressions
3 Statements
4 Exercises
Mai 02nd 2024, Dr.Thomas MESSI NGUELE Programming Languages – Expressions and Statem. 14 / 17
Chapter Goals
Expressions
Statements
Exercises
Exercises
Mai 02nd 2024, Dr.Thomas MESSI NGUELE Programming Languages – Expressions and Statem. 15 / 17
Chapter Goals
Expressions
Statements
Exercises
Bibliography
Mai 02nd 2024, Dr.Thomas MESSI NGUELE Programming Languages – Expressions and Statem. 16 / 17
Chapter Goals
Expressions
Statements
Exercises
Mai 02nd 2024, Dr.Thomas MESSI NGUELE Programming Languages – Expressions and Statem. 17 / 17