6.001 Structure and Interpretation of Computer Programs. Copyright o 2004 by Massachusetts Institute of Technology Stages of an interpreter input to each stage Slide 15.1.10 Lexical a (average 4 (+ 55)) Now comes the heart of the interpreter. We want to take that tree structure and deduce its value. first. notice the form of tree (Parser structure. We will talk about this in detail later, but you can 回回 the parser has converted to a tree Evaluator Every time we see an"(", indicating the beginning of a new Environment we build up a tree where each horizontal slice through the tree Printer corresponds to some combination. Now what is the evaluator m supposed to do? It wants to take that tree structure, plus an environment,and interpret it. And what does that mean? Thin of the environment as a way of associating names with more primitive values. It acts much like a dictionary. The evaluator will use a set of rules to walk through this tree, looking up values associated with symbols from the environment, i.e. from that dictionary, and then using the rules to reduce complex expressions to simpler things culminating in some simple value that we will return 15.L.11 Stages of an interpreter input to each stage] value becomes input to the final stage. The printer simply Lexical analyzer) "(average 4(+55)) converts things back into the appropriate form for display on the monitor and then Parse 凹回回 Eva1uat⊙ symbol Environment avera symbol+5 7 Stages of an interpreter input to each stage Slide 15.1.12 Lexical analyzer m(average 4(+ 55)) that just gets displayed to the user average arser Eva1uat。r 口→[团 ment) Bera Printer 76.001 Structure and Interpretation of Computer Programs. Copyright © 2004 by Massachusetts Institute of Technology. Slide 15.1.10 Now comes the heart of the interpreter. We want to take that tree structure and deduce its value. First, notice the form of tree structure. We will talk about this in detail later, but you can already see how the parser has converted things into a tree. Every time we see an "(", indicating the beginning of a new combination, we have created a new list structure. If the parser is already inside a list structure, it drops down a level, so that we build up a tree where each horizontal slice through the tree corresponds to some combination. Now what is the evaluator supposed to do? It wants to take that tree structure, plus an environment, and interpret it. And what does that mean? Think of the environment as a way of associating names with more primitive values. It acts much like a dictionary. The evaluator will use a set of rules to walk through this tree, looking up values associated with symbols from the environment, i.e. from that dictionary, and then using the rules to reduce complex expressions to simpler things, culminating in some simple value that we will return. Slide 15.1.11 That value becomes input to the final stage. The printer simply converts things back into the appropriate form for display on the monitor, and then ... Slide 15.1.12 ... that just gets displayed to the user