1 / 47

Chapter 2 A Simple Syntax-Directed Translator

Chapter 2 A Simple Syntax-Directed Translator. Figure 2.1: A code fragment to be translated. Figure 2.2: Simplified intermediate code for the program fragment in Fig. 2.1. Figure 2.3: A model of a compiler front end. Figure 2.4: Intermediate code for "do i = i + 1 ; while ( a [il < v) ; ".

elewa
Download Presentation

Chapter 2 A Simple Syntax-Directed Translator

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. Chapter 2A Simple Syntax-Directed Translator

  2. Figure 2.1: A code fragment to be translated

  3. Figure 2.2: Simplified intermediate code for the program fragment in Fig. 2.1

  4. Figure 2.3: A model of a compiler front end

  5. Figure 2.4: Intermediate code for "do i = i + 1 ; while ( a [il < v) ; "

  6. Figure 2.5: Parse tree for 9-5+2 according to the grammar in Example 2.1

  7. Figure 2.6: Two parse trees for 9-5+2

  8. Figure 2.7: Parse trees for left- and right-associative grammars

  9. Figure 2.8: A grammar for a subset of Java statements

  10. Figure 2.9: Attribute values at nodes in a parse tree

  11. Figure 2.10: Syntax-directed definition for infix to postfix translation

  12. Figure 2.11: A depth-first traversal of a tree

  13. Figure 2.12: Example of a depth-first traversal of a tree

  14. Figure 2.13: An extra leaf is constructed for a semantic action

  15. Figure 2.14: Actions translating 9-5+2 into 95-2+

  16. Figure 2.15: Actions for translating into postfix notation

  17. Figure 2.16: A grammar for some statements in C and Java

  18. Figure 2.17: A parse tree according to the grammar in Fig. 2.16

  19. Figure 2.18: Top-down parsing while scanning the input from left to right

  20. Figure 2.19: Pseudocode for a predictive parser

  21. Figure 2.20: Left- and right-recursive ways of generating a string

  22. Figure 2.21: Actions for translating into postfix notation

  23. Figure 2.22: Syntax tree for 9-5+2

  24. Figure 2.23: Translation scheme after left-recursion elimination

  25. Figure 2.24: Translation of 9-5+2 to 95-2+

  26. Figure 2.25: Pseudocode for non-terminals expr, rest, and term

  27. Figure 2.26: Eliminating tail recursion in the procedure rest of Fig. 2.25

  28. Figure 2.27: Java program to translate infix expressions into postfix form

  29. Figure 2.28: Actions for translating into postfix notation

  30. Figure 2.29: Skipping white space

  31. Figure 2.30: Grouping digits into integers

  32. Figure 2.31: Distinguishing keywords from identifiers

  33. Figure 2.32: Class Token and subclasses Nurn and Word

  34. Figure 2.33: Subclasses Num and Word of Token

  35. Figure 2.34: Code for a lexical analyzer, part 1 of 2

  36. Figure 2.35: Code for a lexical analyzer, part 2 of 2

  37. Figure 2.36: Chained symbol tables for Example 2.15

  38. Figure 2.37: Class Env implements chained symbol tables

  39. Figure 2.38: The use of symbol tables for translating a language with blocks

  40. Figure 2.39: Construction of syntax trees for expressions and statements

  41. Figure 2.40: Part of a syntax tree for a statement list consisting of an ifstatementand a while-statement

  42. Figure 2.41: Concrete and abstract syntax for several Java operators

  43. Figure 2.42: Code layout for if-statements

  44. Figure 2.43: Function gen in class If generates three-address code

  45. Figure 2.44: Pseudocode for function lualue

  46. Figure 2.45: Pseudocode for function rvalue

  47. Figure 2.46: Two possible translations of a statement

More Related