📂
CS-NoteBook
  • Introduction
  • CS144
    • concise introduction to Internet
      • 1.1 Networked Applications
      • 1.2 The 4 Layer Internet
      • 1.3 IP
      • 1.4 A Day in the Life of a Packet
      • 1.5 Principle: Packet Switching
      • 1.6 Principle:Layering
      • 1.7 Principle: Encapsulation
      • 1.8 Byte order and packet formats
      • 1.9 name and addresses:IPv4
      • 1.10 Longest Prefix Match for Link Layer
      • 1.11 Address Resolution Protocol(ARP)
      • 1.12 Summary
    • Transport Layer
      • 2.1 The TCP Service Model
      • 2.2 UDP service model
      • 2.3 ICMP(Internet Control Message Protocol 互联网报文控制协议)
      • 2.4 The End-to-End Principle
      • 2.5 Error Detection:3 schemes (Checksum,CRC and MAC)
      • 2.6 Finite State Machines(有限状态机)
      • 2.7 Flow Control
      • 2.8 Sliding window
      • 2.9 Retransmission Strategies
      • 2.10 TCP Header
      • 2.11 TCP Setup and Teardown
      • 2.12 Recap
    • Package Switching
      • 3.1 The history of Internet
      • 3.2 What is packet switching
      • [3.3 End-to-end delay and Queueing delay
      • 3.4 Playback Buffer(回放缓存区)
  • CS 61C
    • 1.4 C Memory Mangement, Usage
    • 1.5 Intro to Assembly Language, MIPS Intro
    • 1.5 extra bits operation
  • CS 61B
  • CS 61A
    • Function
    • Names
    • The Art of the Function
    • Control
    • Higher-Order Function
    • Recursive Function
    • List
    • Non-Local Assignment
    • Iterators
    • Objects
    • Data Abstraction
    • OOP
    • Inheritance
    • Representations
    • Decomposition
    • Scheme
    • Exceptions
    • Calculator
    • Interpreters
    • Declarative_Programming
    • Table
    • Aggregation
      • More_recursion
    • Databases
    • Distributed_Data
    • Tail Recursion
    • Exercises
      • lab00
      • lab01
      • hw01
      • tree Recursion example -- give Change
  • The Web DevelopMent Bootcamp
    • html5
    • css
    • bootstrap3
    • bootstrap4
    • javascript expression
    • javascript function
Powered by GitBook
On this page
  • The Structure of an Interpreter
  • Special Forms
  • Logical Special Forms
  • Quotation
  • Lambda expressions
  • Frame
  • Define

Was this helpful?

  1. CS 61A

Interpreters

The Structure of an Interpreter

有两个function:

  • Eval 求表达式的值(Evaluate a Calculator expression.)

  • Apply 当 eval 找到一个表达式,用 apply 来求出其具体的值(Apply the named operator to a list of args.)

  • Eval

    • Base cases

      • 原始值(数字)

      • 查询与符号绑定的值

    • Recursive calls:

      • Eval(operator(操作符), operands(操作数)) of call expressions

      • Apply(procedure, arguments)

      • Eval(sub-expressions) of special forms

  • Apply

    • Base cases

      • Built-in primitive procedures

    • Recursive calls:

      • Eval(body) (用户定义程序)

Special Forms

  • scheme_eval 函数根据表达式选择行为

    • symbols 在当前环境中绑定为 values

    • self-evaluating 表达式作为值返回

    • 所有其他合法表达式都以 Scheme lists 的形式表示,称为 combinations

Logical Special Forms

  • if

  • and or

  • cond

Quotation

  • quote特殊形式 evaluates 被引用的表达式(which is not evaluated)

  • expression 本身就是被求出的值

Lambda expressions

  • Lambda 表达式对用户定义的过程进行求值

class LambdaProcedure:
    def __init__(self, formals, body, env):
        self.formals = formals  # A scheme list of symbols
        self.body = body        # A scheme list of expressions
        self.env = env          # A Frame instance

Frame

  • 一个 frame 通过有一个parent frame来代表一个环境

  • Frames 是 Python 实例,有方法 lookup 和 define 。

Define

  • Define 将一个 symbol 绑定到 current environment 的 first frame 中的值。

  • Procedure definition(过程定义)是带有 lambda 表达式的定义的简写。

    (define (<name> <formal parameters>) <body>)

    (define <name> (lambda (<formal parameters>) <body>))

PreviousCalculatorNextDeclarative_Programming

Last updated 4 years ago

Was this helpful?