Syntax
- Expr ::= Number
- | Expr '+' Expr
- | Expr '-' Expr
- | Expr '*' Expr
- | '(' Expr ')'
Example
- 2+3*4
- (2+3) * 4
Semantics
Semantic domain: integer arithmetic
Value
Numbers evaluate to their value
Operations map to integer operations
Rules
Reduce
Deduction tree
Rules
Syntax
- Expr ::= Number
- | Expr '+' Expr
- | Expr '-' Expr
- | Expr '*' Expr
- | Ident
- | PrgSeq
- | '(' Expr ')'
- Ident ::= 'a' | 'b' | ... | 'z'
- PrgSeq ::= Prg | Prg ';' PrgSeq
- Prg ::= Ident ':=' Expr
Example
- a := 2+3;
- b := (a:=a+1)*4;
- a := b-5
Semantics
Look up variable value in store
Assignment: evaluate expression, then update state
Sequence: evaluate subexpressions, chain results
Syntax
- Expr ::= Number
- | Expr '+' Expr
- | Expr '-' Expr
- | Expr '*' Expr
- | Ident
- | Expr '>=' Expr
- | PrgSeq
- | '(' Expr ')'
- Ident ::= 'a' | 'b' | ... | 'z'
- PrgSeq ::= Prg | Prg ';' PrgSeq
- Prg ::= Ident ':=' Expr
- | 'if' Expr
- 'then' Expr
- 'else' Expr 'fi'
- | 'while' Expr 'do'
- Expr
- 'od'
Semantics
- i := -2;
- if i>=0
- then i := i
- else i := 0-i
- fi
- n := -5;
- if n>=0
- then i := n
- else i := 0-n
- fi;
- f := 1;
- while i do
- f := f*i;
- i := i-1
- od
Lemma