CS 112
Arithmetic expressions
NOT fully parenthesized
(but correct)
1+2
1+3*4
(1+4)*5-2
Fully parenthesized expressions
expression := (expression operator expression)
expression := atom
Terminology
- operator. Examples:
- binary operators (+,-,*,/, AND, OR)
- unary operators: -, NOT.
- ternary operators: if x then a else b (In C, Java, etc.: x ? a
: b)
- operand: what the operator acts upon.
Examples
Atoms
1
2
(Binary) Operators
+, -, *, /
Expressions where the definition has been applied once:
(1 + 2)
(2 - 7)
(3 * 7)
(20 / 4)
(In class: what are the operators? the operands?)
Expressions where the recursive definition has been applied twice:
(1 + (3 * 4))
((1 + 3) * 2)
Expressions where the recursive definition has been applied several times
(How many?):
((1 + 3) * ( 2 - 3))
(((1 + 3) * (2 - (2 - 5))) * 2)
In class: make you own example quickly and figure out how many
times you have applied the RECURSIVE definition of what an
expression is.
Ileana Streinu