1 languages and compilers (sprog og oversættere) lecture 13 (2) bent thomsen department of computer...
TRANSCRIPT
1
Languages and Compilers(SProg og Oversættere)
Lecture 13 (2)
Bent Thomsen
Department of Computer Science
Aalborg University
With acknowledgement to Hanne Riis Nielson and Flemming Nielson whose book this lecture is based on.
2
The missing link
The connectionbetween
Syntax and Semanticsand
Languages and Compilers
3
The Language While
The Language While can be considered a mini version of Mini TriangleWhile is almost the same as the BIMS language
4
Single step operational semantics for While
5
Recursive Interpreter and Semantics
public Object visitBinaryExpression(BinaryExpression expr, Object arg){
Value val1 = (Value) expr.E1.visit(this, null);Value val2 = (Value) expr.E2.visit(this, null);
return applyBinary(expr.O, val1, val2);}
• Code for Recursive Interpreter can be derived from big step semantics
6
A stack based virtual machine - AM
States:
Transitions:
7
Operational semantics for AM
8
Translation of While to AM
Note similarity with code generation templates for Mini Triangle
9
Example
10
Correctness Proof
11
Soundness and completeness
12
Getting closer to TAM
13
And closer
14
Conclusion
• With a bit of hard work it is possible to connect – The high level operational semantics for a language
– With the low level implementation
– And prove correctness of the translation
• This is called:
Provably correct implementations
• For more information read– Semantics with applications,
– Hanne Riis Nielson and Flemming Nielson
– Wiley 1992, ISBN 0 471 92980 8