6.001 Structure and Interpretation of Computer Programs. Copyright o 2004 by Massachusetts Institute of Technology Slide 15.1.6 Stages of an interpreter Linput to each stage To do that, let's talk about the input and output characteristics Lexical analyzer of each of them By focusing on the input to each successive stage in the interpretation, we can get a sense of what should happen at each stage, and thus get a sense of how to build an interpreter Eva1uat。r Environmen p⊥nte Slide 15.1.7 Stages of an interpreter input to each stage The initial input is a string of characters, which represents the Lexical analyzer) "(average 4(+55)) typewritten version of the expression we want to evaluate. Th is exactly the thing that we would type in at a terminal if we Parser wanted to have an expression evaluated So the initial input is a tring of characters Evaluato Printer Stages of an interpreter input to each stage Slide 15.1. 8 Lexical analy: r(average 4(+ 55))" The first step is to use a lexical analyzer to convert that string of characters into units or words This is shown here. where the average Parser string gets converted into a set of words or isolated characters like"("and")"and+and numbers. Thus the input to the next Evaluator stage is an ordered sequence of these units or words Env⊥ ronment Printer Slide 15.1.9 Stages of an interpreter input to each stage The second stage then parses those words into a structure that Lexical analyzer) "(average 4(+55) we can use for evaluation. In particular, we convert the linear sequence of words into a tree structure. We are using pairs here Parser for convenience but that is not required we could use any other 回国国 representation of trees as well Evaluator As we do this, we are going convert the self-evaluating expressions into their internal values So notice the form we get Environment for the next stage: it's a tree structure, and hanging off of the symbol + leaves of the tree are numbers, symbols, or other objects that Printer are represented as basic words. This is the input to the next6.001 Structure and Interpretation of Computer Programs. Copyright © 2004 by Massachusetts Institute of Technology. Slide 15.1.6 To do that, let's talk about the input and output characteristics of each of them. By focusing on the input to each successive stage in the interpretation, we can get a sense of what should happen at each stage, and thus get a sense of how to build an interpreter. Slide 15.1.7 The initial input is a string of characters, which represents the typewritten version of the expression we want to evaluate. This is exactly the thing that we would type in at a terminal if we wanted to have an expression evaluated. So the initial input is a string of characters. Slide 15.1.8 The first step is to use a lexical analyzer to convert that string of characters into units or words. This is shown here, where the string gets converted into a set of words or isolated characters like "(" and ")" and "+" and numbers. Thus the input to the next stage is an ordered sequence of these units or words. Slide 15.1.9 The second stage then parses those words into a structure that we can use for evaluation. In particular, we convert the linear sequence of words into a tree structure. We are using pairs here for convenience but that is not required. We could use any other representation of trees as well. As we do this, we are going convert the self-evaluating expressions into their internal values. So notice the form we get for the next stage: it's a tree structure, and hanging off of the leaves of the tree are numbers, symbols, or other objects that are represented as basic words. This is the input to the next stage