Louden’s Simple Language for Describing Formal Semantics program → stmt-list stmt-list → stmt ‘;’ stmt-list | stmt stmt → assign-stmt | if-stmt | while-stmt assign-stmt →identifier ‘:=’ expr if-stmt → ‘if’ expr ‘then’ stmt-list ‘else’ stmt-list ‘fi’ while-stmt → ‘while’ expr ‘do’ stmt-list ‘od’ identifier → ‘a’ | ‘b’ | ‘c’ |... | ‘z’ expr → expr ‘+’ term | expr ‘-’ term | term term → term ‘*’ factor | factor factor → ‘(‘ expr ‘)’ | number | identifier number → number digit | digit digit → ‘0’ | ’1’ | ’2’ | ’3’ | ’4’ | ’5’ | ’6’ | ’7’ | ’8’ | ’9’ One oddity about Louden’s little language: In if-stmt (resp. while- stmt) the expr is evaluated in the current environment. If it is greater than 0, the then (resp. do) is executed otherwise the else is executed (resp. while is terminated).
A variety of notations For our language, the semantic domain Environment, the set of all environments, is the collection of all (partial) functions mapping identifiers into Integer values. That is Environment = Identifier → Integer. We might express an element of this set by a name such as Env or σ. The empty environment would be an empty map, one that doesn’t map any identifier into any Integer value. A function can be modified by changing its map at exactly one element of its domain I, to have value n. This can be expressed variously as Env[n/I]σ[n/I](relatively standard) [n/i]Env[n/I]σ(somewhat standard) [I n]Env[I n]σ(somewhat nonstandard) Env&{I=n}(very nonstandard)
Logical Inference Rules Inference rules are all of the following form: This inference rule embodies the transitive property:
Structural Operational Semantics Meaning is assigned to a program by reducing it (and its input) to the value it yields. A reduction rule has either a syntactic component (or a mixture of sentactic components and semantic values) on the left side and a semantic value on the right side. Consider the rules for digits: ‘0’ => 0 ‘1’ => 1 ‘2’ => 2... ‘9’ => 9 and the rules for numbers: V ‘0’ => 10*V V ‘1’ => 10*V + 1 V ‘2’ => 10*V V ‘9’ => 10*V + 9 V 1 ‘+’ V 2 => V 1 + V 2 V 1 ‘-’ V 2 => V 1 - V 2’ V 1 ‘*’ V 2 => V 1 * V 2 ‘(‘ V ’)’ => V... etc. ‘2’ ‘+’ ‘1’ => 2 ‘+’ ‘1’ => 2 ‘+’ 1 => => 3
Adding Assignment Changes Things Slightly => => Env 0 &{a = 5} => => {a = 5} => => { a = 15, b = 20}
Control Flow is Not Much Harder