CSADPRG_f2f_expressions_assignment_statements

original file
this is unedited

Arithmetic Expressions

Operators

Types of operators

Unary Binary Ternary
require one operand for operation first operand on the left of the operator and second operator on the right requires three operands. in js: one operator follows this -> conditional operator
providing two or more would have a syntax error x = x+10 used to summarize or shorten code using conditionals
increment x++ ++x 3*x int a = 10, b = 20, max;
decrement +-- 10+20
typeof "hello" delete array[2]+"200" 80<20
const number = 20

Design Issues

Operator Precedence

Operator Associativity

Symbol Table

Symbol Precedence Association
+- 1 R->L
*/ 2 L->R
^ 3 R->L
% 4 L->R

1+2*3-4
parenthesis method -> makes it single operand
for this class: keep writing the full thing but use parenthesis method

  1. (3-4) = -1
  2. (1+2) = 3
  3. (-1*3)

A+B*C-D^E/F%G-H+1

  1. A+B*C-D^E/F%G-(H+1) first level precedence R->L
  2. A+B*C-D^E/F%(G-(H+1))
  3. A+B*(C-D)^E/F%(G-(H+1))
  4. (A+B)*(C-D)^E/F%(G-(H+1))
  5. (A+B)*(C-D)^E/F%(G-(H+1))
  6. ((A+B)*(C-D))^E/F%(G-(H+1)) second level precedence L->R
  7. ((A+B)*(C-D))^(E/F)%(G-(H+1))
  8. ((A+B)*((C-D))^(E/F))%(G-(H+1)) third level precedence but there's only one ^ so it doesn't matter and we dont need associativity
  9. (((A+B)*((C-D))^(E/F)))%((G-(H+1))) fourth level precedence

Typical Precedence Levels

Ruby C Based
** postfix++, --
unary+, - prefix++, --, unary+, -
-
-

left

Operand Evaluation Order

Functional Side Effect

  1. disallow functional side effects
  1. or you can write a language definition to state the order of evaluating operands and demand that implementors guarantee that order
    disadvantage

Overloading/Operator overloading

Narrowing Conversion

Widening Conversion

Mixed mode expressions

int a;
float b, c, d;

d = b * a; //type casting or type coercion
// there's more floats in the line + being assigned to a float value d