+ All Categories
Home > Documents > The CSE Machine

The CSE Machine

Date post: 03-Jan-2016
Category:
Upload: valdemar-astrid
View: 38 times
Download: 2 times
Share this document with a friend
Description:
The CSE Machine. Programming Language Principles Lecture 12. Prepared by Manuel E. Bermúdez, Ph.D. Associate Professor University of Florida. Mechanical Evaluation of RPAL Programs. Substitution mechanism (based on lambda-calculus) convenient for humans, but inconvenient for machines. - PowerPoint PPT Presentation
Popular Tags:
22
The CSE Machine Prepared by Manuel E. Bermúdez, Ph.D. Associate Professor University of Florida Programming Language Principles Lecture 12
Transcript
Page 1: The CSE Machine

The CSE Machine

Prepared by

Manuel E. Bermúdez, Ph.D.Associate ProfessorUniversity of Florida

Programming Language PrinciplesLecture 12

Page 2: The CSE Machine

Mechanical Evaluation of RPAL Programs

• Substitution mechanism (based on lambda-calculus) convenient for humans, but inconvenient for machines.

• Need an algorithm to complete the operational semantic specification of RPAL

Page 3: The CSE Machine

Introducing the CSE Machine

• C - Control • a sequence of operations

• S - Stack • operands

• E - Environment • Initially, PE (Primitive Environment)• Updated as evaluation proceeds

• PE: a mapping from names to objects and operations.

Page 4: The CSE Machine

CSE Machine programs: control structures

• Flatten the RPAL program's ST into a "control structure“ (vs. a lambda-expression).

• Done using a simple pre-order tree traversal.

Page 5: The CSE Machine

Example

• Evaluate -2 ** (a-b), in an environment in which (somehow) a=6 and b=1.

• Flattened control structure: neg ** 2 - a b.

• Place this control structure on the Control of the CSE Machine.

Page 6: The CSE Machine
Page 7: The CSE Machine

CSE Machine Operation (informally)

1. Remove right-most item from control.2. If a name, look it up in the CE (current

environment), push onto the stack.3. If , then

• rator = pop(stack)• rand = pop(stack)• push(apply(rator,rand), stack)

4. Stop if control is empty: value on the stack is the result.

Page 8: The CSE Machine

Notes

• Minus: function that subtracts its second argument from its first one.

• Minus6: a function that subtracts its argument from 6.

• Exp, likewise: the exponentiation function.

• Exp2: function that raises 2 to the power of its argument.

Page 9: The CSE Machine

Notes (cont’d)

• Notice difference between "neg" (a name), and "Neg" (the actual operator).

• Control contains gammas (and lambdas) and names. Stack contains "real" values.

Page 10: The CSE Machine

Generating Control Structures

• Begin with CS (control structure) 0:

• Perform a pre-order traversal of the standardized tree.

• For each node:a. If a name, add it to the current CS.b. If a , add it to the current CS.c. If a , add < k x> to the current CS.

• k: new index; x: 's left child. • Generate control structure k:

traverse the 's right child.

Page 11: The CSE Machine

Generating Control Structures

• We use a single symbol to represent a -expression, both on the control, and on the stack. The symbol is <i k x>.• i: environment,• k: CS of the function's body,• x: the function's bound variable.

• The -expression becomes a -closure when its environment is determined, when it is placed on the stack.

Page 12: The CSE Machine

Examples

• Three examples of generating control structures.

Page 13: The CSE Machine
Page 14: The CSE Machine
Page 15: The CSE Machine
Page 16: The CSE Machine

Operation of the CSE Machine

• Five rules• Process driven by TOP symbol on the

control.• Need environment markers, on the

Control and Stack.• Every environment is linked to a

previously created (but not necessarily currently active) environment.

• Thus, environment structure is a tree.

Page 17: The CSE Machine
Page 18: The CSE Machine

Examples of CSE Machine Operation

• Let’s run through the CSE machine, for our 3 examples.

Page 19: The CSE Machine
Page 20: The CSE Machine
Page 21: The CSE Machine
Page 22: The CSE Machine

The CSE Machine

Prepared by

Manuel E. Bermúdez, Ph.D.Associate ProfessorUniversity of Florida

Programming Language PrinciplesLecture 12


Recommended