1 / 20

Context Free Grammars Comparison to RE Notation Specification of Context Free Grammar Rules

Chapter 3. Context Free Grammars Comparison to RE Notation Specification of Context Free Grammar Rules Derivations & Language Defined by a Grammar Examples. Parse Trees & Abstract Syntax Trees. Parse Trees Abstract Syntax Tree Examples. Ambiguity. Ambiguous Grammars

eliot
Download Presentation

Context Free Grammars Comparison to RE Notation Specification of Context Free Grammar Rules

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 3 • Context Free Grammars • Comparison to RE Notation • Specification of Context Free Grammar Rules • Derivations & Language Defined by a Grammar • Examples Department of Software & Media Technology

  2. Parse Trees & Abstract Syntax Trees • Parse Trees • Abstract Syntax Tree • Examples Department of Software & Media Technology

  3. Ambiguity • Ambiguous Grammars • Precedence and Associativity • Dangling Else Problem • Inessential Ambiguity Department of Software & Media Technology

  4. Extended Notations • EBNF Notation • Syntax Diagrams • Examples Department of Software & Media Technology

  5. Formal Properties of CFG • Grammar Rles as Equations • Chomsky Hierarchy • Limits of Syntax as Context Free Rules Department of Software & Media Technology

  6. FA from Grammar • One state for each non-terminal • A rule of the form • Nt1 ::= terminal, generates transition from a state to final state • A rule of the form • Nt1 ::= terminal Nt2 • Generates transition from state 1 to state 2 on an arc labeled by the terminal Department of Software & Media Technology

  7. digit digit S letter letter letter underscore digit identifier digit Graphic representation of FA Department of Software & Media Technology

  8. FA from RE • Each RE corresponds to a grammar • For all REs • A natural translation to FSM exists • Alternation often leads to non-deterministic machines Department of Software & Media Technology

  9. Deterministic Finite Automata (DFA) • For all states S • For all characters C • There is at most one arc from any state S that is labeled with C • Easier to implement • No backtracking Conventions for DFA: • Error transitions are not explicitly shown • Input symbols that result in the same transition are grouped together (this set can even be given a name) • Still not displayed: stopping conditions and actions Department of Software & Media Technology

  10. Non-Deterministic Finite Automata (NFA) • A non-deterministic FA • Has at least one state • With two arcs to two distinct states • Labeled with the same character • Example: from start state, a digit can begin an integer literal or a real literal • Implementation requires backtracking Department of Software & Media Technology

  11. letter letter [other] start in_id finish return id digit Lookahead & Backtracking in NFA Department of Software & Media Technology

  12. letter letter [other] start in_id finish return id digit Implementation of FA Department of Software & Media Technology

  13. letter letter [other] start in_id finish return id digit From RE to DFA & RE to NFA Department of Software & Media Technology

  14. NFA to DFA • There is an algorithm for converting a non-deterministic machine to a deterministic one • Result may have exponentially more states • Intuitively: need new states to express uncertainty about token: int or real • Other algorithms for minimizing number of states of FSM, for showing equivalence, etc. Department of Software & Media Technology

  15. Example DFA Department of Software & Media Technology

  16. Another view of the same DFA Department of Software & Media Technology

  17. Yet another view of the same DFA Department of Software & Media Technology

  18. State Minimization in DFA Department of Software & Media Technology

  19. TINY DFA: Department of Software & Media Technology

  20. Lex for Scanner • Lex Conventions for RE • Format of a Lex Input File Department of Software & Media Technology

More Related