1 languages and compilers (sprog og oversættere) bent thomsen department of computer science...

13
1 Languages and Compilers (SProg og Oversættere) Bent Thomsen Department of Computer Science Aalborg University ledgement to Hanne Riis Nielson and Flemming Nielson whose book this lecture

Upload: jacoby-ingham

Post on 31-Mar-2015

216 views

Category:

Documents


1 download

TRANSCRIPT

Page 1: 1 Languages and Compilers (SProg og Oversættere) Bent Thomsen Department of Computer Science Aalborg University With acknowledgement to Hanne Riis Nielson

1

Languages and Compilers(SProg og Oversættere)

Bent Thomsen

Department of Computer Science

Aalborg University

With acknowledgement to Hanne Riis Nielson and Flemming Nielson whose book this lecture is based on.

Page 2: 1 Languages and Compilers (SProg og Oversættere) Bent Thomsen Department of Computer Science Aalborg University With acknowledgement to Hanne Riis Nielson

2

The missing link

The connectionBetween

Syntax and SemanticsAnd

Languages and Compilers

Page 3: 1 Languages and Compilers (SProg og Oversættere) Bent Thomsen Department of Computer Science Aalborg University With acknowledgement to Hanne Riis Nielson

3

The Language While

The Language While can be considered mini version of Mini-TriangleWhile is almost the same as the BIMS language

Page 4: 1 Languages and Compilers (SProg og Oversættere) Bent Thomsen Department of Computer Science Aalborg University With acknowledgement to Hanne Riis Nielson

4

Single step operational semantics for While

Page 5: 1 Languages and Compilers (SProg og Oversættere) Bent Thomsen Department of Computer Science Aalborg University With acknowledgement to Hanne Riis Nielson

5

A stack based virtual machine - AM

States:

Transitions:

Page 6: 1 Languages and Compilers (SProg og Oversættere) Bent Thomsen Department of Computer Science Aalborg University With acknowledgement to Hanne Riis Nielson

6

Operational semantics for AM

Page 7: 1 Languages and Compilers (SProg og Oversættere) Bent Thomsen Department of Computer Science Aalborg University With acknowledgement to Hanne Riis Nielson

7

Translation of While to AM

Note similarity with code generation templates for Mini-Triangle

Page 8: 1 Languages and Compilers (SProg og Oversættere) Bent Thomsen Department of Computer Science Aalborg University With acknowledgement to Hanne Riis Nielson

8

Example

Page 9: 1 Languages and Compilers (SProg og Oversættere) Bent Thomsen Department of Computer Science Aalborg University With acknowledgement to Hanne Riis Nielson

9

Correctness Proof

Page 10: 1 Languages and Compilers (SProg og Oversættere) Bent Thomsen Department of Computer Science Aalborg University With acknowledgement to Hanne Riis Nielson

10

Soundness and completeness

Page 11: 1 Languages and Compilers (SProg og Oversættere) Bent Thomsen Department of Computer Science Aalborg University With acknowledgement to Hanne Riis Nielson

11

Getting closer to TAM

Page 12: 1 Languages and Compilers (SProg og Oversættere) Bent Thomsen Department of Computer Science Aalborg University With acknowledgement to Hanne Riis Nielson

12

And closer

Page 13: 1 Languages and Compilers (SProg og Oversættere) Bent Thomsen Department of Computer Science Aalborg University With acknowledgement to Hanne Riis Nielson

13

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