1 / 86

(2 + 1 – 4) * ( – (5 + 2) + 6) * – + + 4 – 6

(2 + 1 – 4) * ( – (5 + 2) + 6) * – + + 4 – 6 2 1 + 5 2. (2 + 1 – 4) * ( – (5 + 2) + 6) * – + + 4 – 6 2 1 +

dorit
Download Presentation

(2 + 1 – 4) * ( – (5 + 2) + 6) * – + + 4 – 6

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. (2 + 1 – 4) * ( – (5 + 2) + 6) * – + + 4 – 6 2 1 + 5 2 interpreters, T-diagrams

  2. (2 + 1 – 4) * ( – (5 + 2) + 6) * – + + 4 – 6 2 1 + 5 2 This form, often called an Abstract Syntax Tree, abstracts away from the details of the textual representation (in this case: parentheses) and explicitly represents the structure of the expression. interpreters, T-diagrams

  3. (2 + 1 – 4) * ( – (5 + 2) + 6) * – + + 4 – 6 2 1 + 5 2 This form, often called an Abstract Syntax Tree, abstracts away from the details of the textual representation (in this case: parentheses) and explicitly represents the structure of the expression. It is, for instance, very easy to compute the value of the expression from this form. interpreters, T-diagrams

  4. (2 + 1 – 4) * ( – (5 + 2) + 6) * – + + 4 – 6 2 1 + 5 2 This form, often called an Abstract Syntax Tree, abstracts away from the details of the textual representation (in this case: parentheses) and explicitly represents the structure of the expression. It is, for instance, very easy to compute the value of the expression from this form. interpreters, T-diagrams

  5. (2 + 1 – 4) * ( – (5 + 2) + 6) * – + + 4 – 6 2 1 + 5 2 This form, often called an Abstract Syntax Tree, abstracts away from the details of the textual representation (in this case: parentheses) and explicitly represents the structure of the expression. It is, for instance, very easy to compute the value of the expression from this form. interpreters, T-diagrams

  6. (2 + 1 – 4) * ( – (5 + 2) + 6) * – + + 4 – 6 2 1 + 5 2 This form, often called an Abstract Syntax Tree, abstracts away from the details of the textual representation (in this case: parentheses) and explicitly represents the structure of the expression. It is, for instance, very easy to compute the value of the expression from this form. interpreters, T-diagrams

  7. (2 + 1 – 4) * ( – (5 + 2) + 6) * – + + 4 – 6 2 1 + 5 2 This form, often called an Abstract Syntax Tree, abstracts away from the details of the textual representation (in this case: parentheses) and explicitly represents the structure of the expression. It is, for instance, very easy to compute the value of the expression from this form. 2 interpreters, T-diagrams

  8. (2 + 1 – 4) * ( – (5 + 2) + 6) * – + + 4 – 6 2 1 + 5 2 This form, often called an Abstract Syntax Tree, abstracts away from the details of the textual representation (in this case: parentheses) and explicitly represents the structure of the expression. It is, for instance, very easy to compute the value of the expression from this form. 1 2 interpreters, T-diagrams

  9. (2 + 1 – 4) * ( – (5 + 2) + 6) * – + + 4 – 6 2 1 + 5 2 This form, often called an Abstract Syntax Tree, abstracts away from the details of the textual representation (in this case: parentheses) and explicitly represents the structure of the expression. It is, for instance, very easy to compute the value of the expression from this form. 3 1 2 interpreters, T-diagrams

  10. (2 + 1 – 4) * ( – (5 + 2) + 6) * – + + 4 – 6 2 1 + 5 2 This form, often called an Abstract Syntax Tree, abstracts away from the details of the textual representation (in this case: parentheses) and explicitly represents the structure of the expression. It is, for instance, very easy to compute the value of the expression from this form. 3 4 interpreters, T-diagrams

  11. (2 + 1 – 4) * ( – (5 + 2) + 6) * – + + 4 – 6 2 1 + 5 2 This form, often called an Abstract Syntax Tree, abstracts away from the details of the textual representation (in this case: parentheses) and explicitly represents the structure of the expression. It is, for instance, very easy to compute the value of the expression from this form. – 1 3 4 interpreters, T-diagrams

  12. (2 + 1 – 4) * ( – (5 + 2) + 6) * – + + 4 – 6 2 1 + 5 2 This form, often called an Abstract Syntax Tree, abstracts away from the details of the textual representation (in this case: parentheses) and explicitly represents the structure of the expression. It is, for instance, very easy to compute the value of the expression from this form. – 1 interpreters, T-diagrams

  13. (2 + 1 – 4) * ( – (5 + 2) + 6) * – + + 4 – 6 2 1 + 5 2 This form, often called an Abstract Syntax Tree, abstracts away from the details of the textual representation (in this case: parentheses) and explicitly represents the structure of the expression. It is, for instance, very easy to compute the value of the expression from this form. – 1 interpreters, T-diagrams

  14. (2 + 1 – 4) * ( – (5 + 2) + 6) * – + + 4 – 6 2 1 + 5 2 This form, often called an Abstract Syntax Tree, abstracts away from the details of the textual representation (in this case: parentheses) and explicitly represents the structure of the expression. It is, for instance, very easy to compute the value of the expression from this form. – 1 interpreters, T-diagrams

  15. (2 + 1 – 4) * ( – (5 + 2) + 6) * – + + 4 – 6 2 1 + 5 2 This form, often called an Abstract Syntax Tree, abstracts away from the details of the textual representation (in this case: parentheses) and explicitly represents the structure of the expression. It is, for instance, very easy to compute the value of the expression from this form. – 1 5 interpreters, T-diagrams

  16. (2 + 1 – 4) * ( – (5 + 2) + 6) * – + + 4 – 6 2 1 + 5 2 This form, often called an Abstract Syntax Tree, abstracts away from the details of the textual representation (in this case: parentheses) and explicitly represents the structure of the expression. It is, for instance, very easy to compute the value of the expression from this form. – 1 5 2 interpreters, T-diagrams

  17. (2 + 1 – 4) * ( – (5 + 2) + 6) * – + + 4 – 6 2 1 + 5 2 This form, often called an Abstract Syntax Tree, abstracts away from the details of the textual representation (in this case: parentheses) and explicitly represents the structure of the expression. It is, for instance, very easy to compute the value of the expression from this form. – 1 7 5 2 interpreters, T-diagrams

  18. (2 + 1 – 4) * ( – (5 + 2) + 6) * – + + 4 – 6 2 1 + 5 2 This form, often called an Abstract Syntax Tree, abstracts away from the details of the textual representation (in this case: parentheses) and explicitly represents the structure of the expression. It is, for instance, very easy to compute the value of the expression from this form. – 1 – 7 interpreters, T-diagrams

  19. (2 + 1 – 4) * ( – (5 + 2) + 6) * – + + 4 – 6 2 1 + 5 2 This form, often called an Abstract Syntax Tree, abstracts away from the details of the textual representation (in this case: parentheses) and explicitly represents the structure of the expression. It is, for instance, very easy to compute the value of the expression from this form. – 1 – 7 6 interpreters, T-diagrams

  20. (2 + 1 – 4) * ( – (5 + 2) + 6) * – + + 4 – 6 2 1 + 5 2 This form, often called an Abstract Syntax Tree, abstracts away from the details of the textual representation (in this case: parentheses) and explicitly represents the structure of the expression. It is, for instance, very easy to compute the value of the expression from this form. – 1 – 1 – 7 6 interpreters, T-diagrams

  21. (2 + 1 – 4) * ( – (5 + 2) + 6) * – + + 4 – 6 2 1 + 5 2 This form, often called an Abstract Syntax Tree, abstracts away from the details of the textual representation (in this case: parentheses) and explicitly represents the structure of the expression. It is, for instance, very easy to compute the value of the expression from this form. 1 – 1 – 1 interpreters, T-diagrams

  22. (2 + 1 – 4) * ( – (5 + 2) + 6) * – + + 4 – 6 2 1 + 5 2 A program that performs this computation is an interpreter of arithmetic expressions : given an expression, it “executes” it by finding its value. 1 interpreters, T-diagrams

  23. (2 + 1 – 4) * ( – (5 + 2) + 6) * – + + 4 – 6 2 1 + 5 2 A program that performs this computation is an interpreter of arithmetic expressions : given an expression, it “executes” it by finding its value. It would not be too difficult to extend the interpreted language with variables, assignments, conditional statements and the like. 1 interpreters, T-diagrams

  24. For example, we could represent a := 2; b := a * 2; if b > 4 then c := b else c := a fi as a tree (for the statements and expressions) and an array (for the variables): ; := ; v[0] 2 := if v[1] * > := := v[0] 2 v[1] 4 v[2] v[1] v[2] v[0] v interpreters, T-diagrams

  25. For example, we could represent a := 2; b := a * 2; if b > 4 then c := b else c := a fi as a tree (for the statements and expressions) and an array (for the variables): ; := ; v[0] 2 := if v[1] * > := := v[0] 2 v[1] 4 v[2] v[1] v[2] v[0] “Execution” would consist in traversing the tree, updating the values of the variables in the array etc. v interpreters, T-diagrams

  26. For example, we could represent a := 2; b := a * 2; if b > 4 then c := b else c := a fi as a tree (for the statements and expressions) and an array (for the variables): ; := ; v[0]2 := if v[1] * > := := v[0] 2 v[1] 4 v[2] v[1] v[2] v[0] “Execution” would consist in traversing the tree, updating the values of the variables in the array etc. 2 v interpreters, T-diagrams

  27. For example, we could represent a := 2; b := a * 2; if b > 4 then c := b else c := a fi as a tree (for the statements and expressions) and an array (for the variables): ; := ; v[0] 2 := if v[1] * > := := v[0] 2 v[1] 4 v[2] v[1] v[2] v[0] “Execution” would consist in traversing the tree, updating the values of the variables in the array etc. 2 v interpreters, T-diagrams

  28. For example, we could represent a := 2; b := a * 2; if b > 4 then c := b else c := a fi as a tree (for the statements and expressions) and an array (for the variables): ; := ; v[0] 2 := if v[1] * > := := v[0] 2 v[1] 4 v[2] v[1] v[2] v[0] “Execution” would consist in traversing the tree, updating the values of the variables in the array etc. 2 v 4 interpreters, T-diagrams

  29. For example, we could represent a := 2; b := a * 2; if b > 4 then c := b else c := a fi as a tree (for the statements and expressions) and an array (for the variables): ; := ; v[0] 2 := if v[1] * > := := v[0] 2 v[1] 4 v[2] v[1] v[2] v[0] “Execution” would consist in traversing the tree, updating the values of the variables in the array etc. 2 4 v 4 interpreters, T-diagrams

  30. For example, we could represent a := 2; b := a * 2; if b > 4 then c := b else c := a fi as a tree (for the statements and expressions) and an array (for the variables): ; := ; v[0] 2 := if v[1] * > := := v[0] 2 v[1] 4 v[2] v[1] v[2] v[0] “Execution” would consist in traversing the tree, updating the values of the variables in the array etc. 2 4 v interpreters, T-diagrams

  31. For example, we could represent a := 2; b := a * 2; if b > 4 then c := b else c := a fi as a tree (for the statements and expressions) and an array (for the variables): ; := ; v[0] 2 := if v[1] * > := := v[0] 2 v[1]4 v[2] v[1] v[2] v[0] “Execution” would consist in traversing the tree, updating the values of the variables in the array etc. 2 4 v false interpreters, T-diagrams

  32. For example, we could represent a := 2; b := a * 2; if b > 4 then c := b else c := a fi as a tree (for the statements and expressions) and an array (for the variables): ; := ; v[0] 2 := if v[1] * > := := v[0] 2 v[1] 4 v[2] v[1] v[2]v[0] “Execution” would consist in traversing the tree, updating the values of the variables in the array etc. 2 4 2 v interpreters, T-diagrams

  33. For example, we could represent a := 2; b := a * 2; if b > 4 then c := b else c := a fi as a tree (for the statements and expressions) and an array (for the variables): ; := ; v[0] 2 := if v[1] * > := := v[0] 2 v[1] 4 v[2] v[1] v[2] v[0] “Execution” would consist in traversing the tree, updating the values of the variables in the array etc. Notice that this does not involve translating the interpreted program to machine code! 2 4 2 v

  34. We could also translate our expression from a tree to some other language, for example by converting it to an A1 program that would print out the value. * – + + 4 – 6 2 1 + 5 2 interpreters, T-diagrams

  35. We could also translate our expression from a tree to some other language, for example by converting it to an A1 program that would print out the value. * – + + 4 – 6 2 1 + 5 2 LOA L1 …. L1 LIT 2 … … interpreters, T-diagrams

  36. We could also translate our expression from a tree to some other language, for example by converting it to an A1 program that would print out the value. * – + + 4 – 6 2 1 + 5 2 LOA L1 ADD L2 …. L1 LIT 2 L2 LIT 1 … … interpreters, T-diagrams

  37. We could also translate our expression from a tree to some other language, for example by converting it to an A1 program that would print out the value. * – + + 4 – 6 2 1 + 5 2 LOA L1 ADD L2 SUB L3 …. L1 LIT 2 L2 LIT 1 L3 LIT 4 … … interpreters, T-diagrams

  38. We could also translate our expression from a tree to some other language, for example by converting it to an A1 program that would print out the value. * – + + 4 – 6 2 1 + 5 2 LOA L1 ADD L2 SUB L3 STO MUL – 1 …. L1 LIT 2 L2 LIT 1 L3 LIT 4 … … interpreters, T-diagrams

  39. We could also translate our expression from a tree to some other language, for example by converting it to an A1 program that would print out the value. * – + + 4 – 6 2 1 + 5 2 LOA L1 ADD L2 SUB L3 STO MUL – 1 LOA L4 …. L1 LIT 2 L2 LIT 1 L3 LIT 4 L4 LIT 5 … … interpreters, T-diagrams

  40. We could also translate our expression from a tree to some other language, for example by converting it to an A1 program that would print out the value. * – + + 4 – 6 2 1 + 5 2 LOA L1 ADD L2 SUB L3 STO MUL – 1 LOA L4 ADD L5 …. L1 LIT 2 L2 LIT 1 L3 LIT 4 L4 LIT 5 L5 LIT 2 … … interpreters, T-diagrams

  41. We could also translate our expression from a tree to some other language, for example by converting it to an A1 program that would print out the value. * – + + 4 – 6 2 1 + 5 2 LOA L1 ADD L2 SUB L3 STO MUL – 1 LOA L4 ADD L5 XOR ONES ADD ONE …. L1 LIT 2 L2 LIT 1 L3 LIT 4 L4 LIT 5 L5 LIT 2 … ONES LIT #11111 ONE LIT 1 … interpreters, T-diagrams

  42. We could also translate our expression from a tree to some other language, for example by converting it to an A1 program that would print out the value. * – + + 4 – 6 2 1 + 5 2 LOA L1 ADD L2 SUB L3 STO MUL – 1 LOA L4 ADD L5 XOR ONES ADD ONE ADD L6 …. L1 LIT 2 L2 LIT 1 L3 LIT 4 L4 LIT 5 L5 LIT 2 L6 LIT 6 ONES LIT #11111 ONE LIT 1 … interpreters, T-diagrams

  43. We could also translate our expression from a tree to some other language, for example by converting it to an A1 program that would print out the value. * – + + 4 – 6 2 1 + 5 2 LOA L1 ADD L2 SUB L3 STO MUL – 1 LOA L4 ADD L5 XOR ONES ADD ONE ADD L6 STO MUL – 2 …. L1 LIT 2 L2 LIT 1 L3 LIT 4 L4 LIT 5 L5 LIT 2 L6 LIT 6 ONES LIT #11111 ONE LIT 1 … interpreters, T-diagrams

  44. We could also translate our expression from a tree to some other language, for example by converting it to an A1 program that would print out the value. * – + + 4 – 6 2 1 + 5 2 LOA L1 ADD L2 SUB L3 STO MUL – 1 LOA L4 ADD L5 XOR ONES ADD ONE ADD L6 STO MUL – 2 CAL MUL …. L1 LIT 2 L2 LIT 1 L3 LIT 4 L4 LIT 5 L5 LIT 2 L6 LIT 6 ONES LIT #11111 ONE LIT 1 … interpreters, T-diagrams

  45. We could also translate our expression from a tree to some other language, for example by converting it to an A1 program that would print out the value. * – + + 4 – 6 2 1 + 5 2 Instead of an interpreter of expressions, our program would now become a compiler of expressions. interpreters, T-diagrams

  46. We could also translate our expression from a tree to some other language, for example by converting it to an A1 program that would print out the value. * – + + 4 – 6 2 1 + 5 2 Instead of an interpreter of expressions, our program would now become a compiler of expressions. Interpreters and compilers are the two kinds of translators of programming languages (interpretation involves only translation to a convenient internal form). interpreters, T-diagrams

  47. The important thing to remember is this: • a compiler translates a program to another language (usually a simpler one) interpreters, T-diagrams

  48. The important thing to remember is this: • a compiler translates a program to another language (usually a simpler one); • an interpreter executes the program without such translation (though the program is usually converted to some internal representation). interpreters, T-diagrams

  49. So now we can have a single program that works in three phases: • it converts the expression (or program) to a tree; • it converts the tree to RPN; • it executes the RPN. • Phases 1 and 2 constitute a compiler. Phase 3 is interpretation/emulation. • We could also have to or even three different programs that do the same thing. • The important thing to remember is this: • a compiler translates a program to another language (usually a simpler one); • an interpreter executes the program without such translation (though the program is usually converted to some internal representation). • Nowadays many languages are implemented by a combination of compilation and • interpretation: interpreters, T-diagrams

  50. So now we can have a single program that works in three phases: • it converts the expression (or program) to a tree; • it converts the tree to RPN; • it executes the RPN. • Phases 1 and 2 constitute a compiler. Phase 3 is interpretation/emulation. • We could also have to or even three different programs that do the same thing. • The important thing to remember is this: • a compiler translates a program to another language (usually a simpler one); • an interpreter executes the program without such translation (though the program is usually converted to some internal representation). • Nowadays many languages are implemented by a combination of compilation and • interpretation: • the program is translated to the code of a virtual machine that is designed to make such translation particularly convenient; interpreters, T-diagrams

More Related