Interpreters
The Structure of an Interpreter
有两个function:
Eval求表达式的值(Evaluate a Calculator expression.)Apply当eval找到一个表达式,用apply来求出其具体的值(Apply the named operator to a list of args.)EvalBase cases
原始值(数字)
查询与符号绑定的值
Recursive calls:
Eval(operator(操作符), operands(操作数))of call expressionsApply(procedure, arguments)Eval(sub-expressions)of special forms
ApplyBase cases
Built-in primitive procedures
Recursive calls:
Eval(body)(用户定义程序)
Special Forms
scheme_eval函数根据表达式选择行为symbols在当前环境中绑定为valuesself-evaluating表达式作为值返回所有其他合法表达式都以
Scheme lists的形式表示,称为combinations
Logical Special Forms
ifandorcond
Quotation
quote特殊形式evaluates被引用的表达式(which is not evaluated)expression本身就是被求出的值
Lambda expressions
Lambda 表达式对用户定义的过程进行求值
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>))
Last updated
Was this helpful?