Secd - App C D 7→ nil E f 7→ v 1 x 7→ v 2 e nil S E C D(8 where v 1 = fun f x is e E Function Return v S E nil S E C D 7→ v S E C D(9

Info iconThis preview shows page 1. Sign up to view the full content.

View Full Document Right Arrow Icon
CS 221 Programming Languages Handout 3 Fall 2005 Nov 23 , 2005 Landin’s SECD Machine States s ::= nil | ( S, E, C ) :: s Stacks S ::= nil | v :: S (value list) Control C ::= nil | ce :: C Control element ce ::= e | Prim ( op ) | App | If Initial State (for expression e ): ( nil, empty, e :: nil ) :: nil Final States : ( v :: nil, empty, nil ) :: nil , where v is the result value. Analyze ( S, E, op ( e 1 , e 2 ) :: C ) :: D 7→ ( S, E, e 1 :: e 2 :: Prim ( op ) :: C ) :: D (1) ( S, E, apply ( e 1 , e 2 ) :: C ) :: D 7→ ( S, E, e 1 :: e 2 :: App :: C ) :: D (2) ( S, E, if ( e, e 1 , e 2 ) :: C ) :: D 7→ ( S, E, e :: If :: e 1 :: e 2 :: C ) :: D (3) Value Expressions ( S, E, n :: C ) :: D 7→ ( n :: S, E, C ) :: D (4) ( S, E, b :: C ) :: D 7→ ( b :: S, E, C ) :: D (5) ( S, E, x :: C ) :: D 7→ ( E ( x ) :: S, E, C ) :: D (6) ( S, E, ( fun f ( x ) is e ) :: C ) :: D 7→ ([ fun f ( x ) is e ; E ] :: S, E, C ) :: D (7) Function Call ( v 2 :: v 1 :: S, E,
Background image of page 1
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: App :: C ) :: D 7→ ( nil, E [ f 7→ v 1 ][ x 7→ v 2 ] , e :: nil ) :: ( S, E, C ) :: D (8) where v 1 = [ fun f ( x ) is e ; E ] . Function Return ( v :: S, E, nil ) :: ( S , E , C ) :: D 7→ ( v :: S , E , C ) :: D (9) Consume values ( v 2 :: v 1 :: S, E, Prim ( op ) :: C ) :: D 7→ (( v 1 op v 2 ) :: S, E, C ) :: D (10) ( true :: S, E, If :: e 1 :: e 2 :: C ) :: D 7→ ( S, E, e 1 :: C ) :: D (11) ( false :: S, E, If :: e 1 :: e 2 :: C ) :: D 7→ ( S, E, e 2 :: C ) :: D (12) 1...
View Full Document

This note was uploaded on 10/10/2009 for the course CMSC 2210 taught by Professor Macqueen during the Fall '09 term at UChicago.

Ask a homework question - tutors are online