1 / 33

Chapter 07

Chapter 07. The four parts of a grammar. N , a nonterminal alphabet T , a terminal alphabet P , a set of rules of production S , the start symbol, an element of N. A grammar for C++ identifiers. N = {<identifier>, <letter>,<digit>} T = {a, b, c, 1, 2, 3} P = the productions

admon
Download Presentation

Chapter 07

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 07

  2. The four parts of a grammar • N, a nonterminal alphabet • T, a terminal alphabet • P, a set of rules of production • S, the start symbol, an element of N

  3. A grammar for C++ identifiers • N = {<identifier>, <letter>,<digit>} • T = {a, b, c, 1, 2, 3} • P = the productions • <identifier>  <letter> • <identifier> <identifier> <letter> • <identifier> <identifier> <digit> • <letter> a • <letter>  b • <letter> c • <letter> 1 • <digit> 2 • <digit> 3 • S = <identifier>

  4. A grammar for signed integers • N = {I, F, M} • T = {+, -, d} • P = the productions • I  FM • F  + • F  – • F  • M dM • M  d • S = I

  5. A context-sensitive grammar • N = {A, B, C} • T = {a, b, c} • P = the productions • A  aABC • A  abC • CB  BC • bB  bb • bC  bc • cC  cc • S = A

  6. The difference between deriving an arbitrary sentence and parsing a proposed sentence

  7. A grammar for expressions • N = {E, T, F} • T = {+, *, (, ), a} • P = the productions • E  E + T • E  T • T  T * F • T  F • F  (E) • F  a • S = E

  8. A grammar for a subset of the C++ language • Please click on the following link Programs\c07g05.gif to view the appropriate program.

  9. A finite state machine (FSM) to parse an identifier

  10. A finite state machine (FSM) to parse an identifier (Cont’d)

  11. The FSM of Figure 7.5 without the failure state

  12. The FSM of Figure 7.5 without the failure state (Cont’d)

  13. A nondeterministic FSM to parse a signed integer

  14. A nondeterministic FSM to parse a signed integer

  15. An FSM with an empty transition to parse a signed integer

  16. An FSM with an empty transition to parse a signed integer (Cont’d)

  17. Removing an empty transition

  18. Removing the empty transition from the FSM of Figure 7.8

  19. Removing an empty transition

  20. Combining two machines to construct one FSM that recognizes both tokens

  21. Transforming the FSM of Figure 7.12(b)

  22. An FSM to parse a Pep/7 assembly language identifier or symbol definition

  23. Steps in the compilation process

  24. The two FSM implementation techniques • Table lookup • Direct code

  25. Implementation of the FSM of Figure 7.5 with the table lookup technique • Please click on the following link Programs\c07p01_prog.GIF to view the appropriate program.

  26. A programmer-designed parse of an integer string • Please click on the following link Programs\c07p02_prog.gif to view the appropriate program.

  27. A finite machine that recognizes multiple tokens

  28. A finite machine that recognizes multiple tokens (Cont’d) • Please click on the following links, Programs\c07p03_prog.GIF and Programs\c07p03_io.GIF, to view the appropriate programs.

  29. The structure of token in Program 7.3

  30. A language translator • Please click on the following links, Programs\c07p04_prog.GIF and Programs\c07p04_io.GIF, to view the appropriate programs.

  31. The FSM for the parser ProcessSourceLine of Program 7.4

  32. The three translation phases of Program 7.4 • Lexical analyzer: getToken • Parser: processSourceLine • Code generator: generateCode

  33. The hierarchy diagram of Program 7.4

More Related