1 / 10

Programming Languages 2nd edition Tucker and Noonan

Programming Languages 2nd edition Tucker and Noonan. Chapter 3 Lexical and Syntactic Analysis Syntactic sugar causes cancer of the semicolon. A. Perlis. Contents. 3.1 Chomsky Hierarchy 3.2 Lexical Analysis 3.3 Syntactic Analysis. 3.1 Chomsky Hierarchy.

joelle
Download Presentation

Programming Languages 2nd edition Tucker and Noonan

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. Programming Languages2nd editionTucker and Noonan Chapter 3 Lexical and Syntactic Analysis Syntactic sugar causes cancer of the semicolon. A. Perlis

  2. Contents 3.1 Chomsky Hierarchy 3.2 Lexical Analysis 3.3 Syntactic Analysis

  3. 3.1 Chomsky Hierarchy • Regular grammar -- least powerful • Context-free grammar (BNF) • Context-sensitive grammar • Unrestricted grammar

  4. Regular Grammar • Simplest; least powerful • Equivalent to: • Regular expression • Finite-state automaton • Right regular grammar:  T*, B  N A → B A → 

  5. Example • Integer→ 0 Integer | 1 Integer | ... | 9 Integer | • 0 | 1 | ... | 9

  6. Regular Grammars • Left regular grammar: equivalent • Used in construction of tokenizers • Less powerful than context-free grammars • Not a regular language { aⁿ bⁿ | n ≥ 1 } i.e., cannot balance: ( ), { }, begin end

  7. Context-free Grammars • BNF a stylized form of CFG • Equivalent to a pushdown automaton • For a wide class of unambiguous CFGs, there are table-driven, linear time parsers

  8. Context-Sensitive Grammars • Production: • α → β |α| ≤ |β| • α, β (N  T)* • ie, lefthand side can be composed of strings of terminals and nonterminals

  9. Undecidable Properties of CSGs • Given a string  and grammar G: L(G) • L(G) is non-empty • Defn: Undecidable means that you cannot write a computer program that is guaranteed to halt to decide the question for all L(G).

  10. Unrestricted Grammar • Equivalent to: • Turing machine • von Neumann machine • C++, Java • That is, can compute any computable function.

More Related