# Lecture: Mini Language Semantics

### Background Material

• Chapter 4 of the text (Semantic Analysis)
• Chapter 10 of the text (Functional Languages)
• Chapter 11 of the text (Logic Languages)

### Theme

This lecture provides semantics for the mini language using operational and denotational semantics. Interpreters are developed using scheme and prolog.

### Topics

1. Mini language
2. Operational semantics for mini language
• Syntax
1. < program > → < stmt-list>
2. < stmt-list> → < stmt > ; < stmt-list > | < stmt >
3. < stmt > → < assign-stmt > | < if-stmt > | < while-stmt >
4. < assign-stmt > → < identifier > := < expr >
5. < if-stmt > → if < expr > then < stmt-list > else < stmt-list > fi
6. < while-stmt > → while < expr > do < stmt-list > od
7. < expr > → < expr > + < term > | < expr > - < term > | < term >
8. < term > → < term > * < factor > | < factor >
9. < factor > → ( < expr > ) | < number > | < identifier >
10. < number > → < number > < digit > | < digit >
11. < digit > → 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9
12. < identifier > → < identifier > < letter > | < letter >
13. < letter > → a | b | c | ... | z
• Semantics
1. Env: Identifier &rarr Integer Union {undef}
2. (Env and {I = n})(J) = n if J=I, Env(J) otherwise
3. Env_0 = undef for all I
4. for if-stmt, if expr evaluates to value greater than 0, then evaluate stmt-list after then, else evaluate stmt-list after else
5. for while-stmt, as long as expr evaluates to a value greater than 0, stmt-list is repeatedly executed and expr evaluated.
• Example
1. n := 0 - 5;
2. if n then i := n else i := 0 - n fi;
3. fact := 1;
4. while i do fact := fact * i; i := i - 1 od
• scheme abstract syntax tree and interpreter
• Operational semantics using reduction machine and inference rules