Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Class 32: Interpreters

David Evans
April 15, 2016

Class 32: Interpreters

cs1120: Introduction to Computing
Explorations in Language, Logic, and Machine
University of Virginia, Spring 2016

http://xplorecs.org/class32

Class 32:
Simulating a Turing Machine
Power of Turing Machine vs. Python
Interpreters
Primitives in Charme

David Evans

April 15, 2016
Tweet

More Decks by David Evans

Other Decks in Science

Transcript

  1. Class 32: Interpreters Introduction to Computing: Explorations in Language, Logic,

    and Machines cs1120 Spring 2016 David Evans University of Virginia
  2. Goal Recap Processing Input Output Program A computer is a

    machine that can execute a program. A universal computer is a machine that can execute any program.
  3. 7 0 0 A 1 0 4 w 0 #

    0 $ 1 4 w 0 # Recap: Turing Machine Symbols: a finite set of things you can write in a square States: a finite set of the “states of mind” of the machine Rules: a list of quintuples: (read symbol, state) è (write symbol, move, new state) Read symbol in current square Based on rule for current state and symbol read: Write a symbol into current square Move left or right one position Change state of mind
  4. Building a Language Design the grammar What strings are in

    the language? Use BNF to describe all the strings in the language Make up the evaluation rules Describe what every string in the language means Build an evaluator Implement a procedure that takes a string in the language as input and an environment and outputs its value: meval(String, Environment) returns Value
  5. Crash Course in Scheme (Charme) • All program elements are

    enclosed in parentheses • Programs built by composing functions • Application looks different from Python: (function input*) vs. function(input,*)
  6. 8 Program ::= ε | ProgramElement Program ProgramElement ::= Expression

    | Definition Definition ::= (define Name Expression) Expression ::= PrimitiveExpression | NameExpression | ApplicationExpression | ProcedureExpression | IfExpression PrimitiveExpression ::= Number | true | false | PrimitiveProcedure NameExpression ::= Name ApplicationExpression ::= (Expression MoreExpressions) MoreExpressions ::= ε | Expression MoreExpressions ProcedureExpression ::= (lambda (Parameters) Expression) Parameters ::= ε | Name Parameters IfExpression ::= (if ExpressionPred ExpressionConsequent ExpressionAlt )
  7. Is this an exaggeration? It is no exaggeration to regard

    this as the most fundamental idea in programming: The evaluator, which determines the meaning of expressions in the programming language, is just another program. To appreciate this point is to change our images of ourselves as programmers. We come to see ourselves as designers of languages, rather than only users of languages designed by others. Abelson and Sussman, Structure and Interpretation of Computer Programs (p. 360)
  8. Building an Evaluator To build an evaluator we need to:

    – Figure out how to represent data in programs What is a procedure, frame, environment, etc. – Implement the evaluation rules For each evaluation rule, define a procedure that follows the behavior of that rule. Next: we’ll look at a high-level how the application rule is implemented Chapter 11: detailed walk-through of the interpreter
  9. Charge • Make progress on Project 6: understand and experiment

    with the provided Charme interpreter, extended it for questions • Monday: how to implement constructed functions