Languages-beta : IMP-1.cbs | PRETTY | PDF
Language "IMP"
1 Arithmetic expressions
Semantics
eval-arith[[ _:aexp ]] : =>integers
Rule
eval-arith[[ N ]] = int-val[[ N ]]
Rule
eval-arith[[ I ]] = assigned(bound(id[[ I ]]))
Rule
eval-arith[[ AExp1 '+' AExp2 ]] =
integer-add(eval-arith[[ AExp1 ]], eval-arith[[ AExp2 ]])
Rule
eval-arith[[ AExp1 '/' AExp2 ]] =
checked integer-divide(eval-arith[[ AExp1 ]], eval-arith[[ AExp2 ]])
Rule
eval-arith[[ '(' AExp ')' ]] = eval-arith[[ AExp ]]
Syntax
N : num ::= '-'?_decimal
Lexis
D : decimal ::= ('0'-'9')+
Semantics
int-val[[ _:num ]] : integers
Rule
int-val[[ D ]] = decimal-natural(\"D\")
Rule
int-val[[ '-' D ]] = integer-negate(int-val[[ D ]])
Lexis
I : id ::= ('A'-'Z'|'a'-'z')+
Lexis
keyword ::= 'else' | 'false' | 'if' | 'true' | 'while'