csci 3136 principles of programming languages
play

CSCI 3136 Principles of Programming Languages Lexical Analysis and - PowerPoint PPT Presentation

CSCI 3136 Principles of Programming Languages Lexical Analysis and Automata Theory - 2 Summer 2013 Faculty of Computer Science Dalhousie University 1 / 12 Class Location Change for two days in July Lecture class on Monday July 15 and Wed.


  1. CSCI 3136 Principles of Programming Languages Lexical Analysis and Automata Theory - 2 Summer 2013 Faculty of Computer Science Dalhousie University 1 / 12

  2. Class Location Change for two days in July Lecture class on Monday July 15 and Wed. July 17 would be at Room 226, Chemistry building. 2 / 12

  3. Scanner Parser (DFA) (PDA) recognizes recognizes Regular Expression Context-free Grammar are gen- are gen- erated erated by by Regular Language Context-free Language

  4. Scanner Implementation Also known as RegEx = ⇒ Scanner (DFA) • RegEx = ⇒ NFA (nondeterministic finite automaton) • NFA = ⇒ DFA (deterministic finite automaton) • Minimizing the DFA 4 / 12

  5. Deterministic Finite Automata (DFA) A deterministic finite automaton (DFA) is a simple machine that accepts or rejects a given input string. This defines a formal language: the set of strings accepted by the DFA. We say the DFA recognizes this language. A language is regular if and only if there exists a DFA that recognizes this language. 5 / 12

  6. Example of a DFA 1 0 1 q 1 q 2 start 0 Informal definition of a DFA Transition Function • Finite set of states • Designated start state 0 1 • Designated set of final states → q 1 q 1 q 2 • Reads input one symbol at a time. � q 2 q 1 q 2 New state is calculated as a function of current state and read symbol. • String is accepted if and only if a final state is reached after reading the entire string. 6 / 12

  7. Example of a DFA 1 0 1 q 1 q 2 start 0 Which language does this DFA recognize? 7 / 12

  8. Formal Definition of a DFA 0 1 1 q 0 q 1 start 0 A DFA is a 5-tuple ( Q , Σ , δ, q 0 , F ) 0 1 • Q is a finite set of states → q 0 q 0 q 1 • Σ is a finite set of input symbols (i.e., q 1 � q 0 q 1 an alphabet ) • δ : Q × Σ → Q is a transition function • q 0 ∈ Q is the start state • F ⊆ Q is the set of final or accepting states The DFA accepts a string σ ∈ Σ ∗ if and only if it reaches a final state after consuming all letters in σ . The language recognized by a DFA D is the set of strings L ( D ) := { σ ∈ Σ ∗ | D accepts σ } . 8 / 12

  9. Non-Deterministic Finite Automata (NFA) A DFA is deterministic in the sense that every input traces exactly one path through the automaton. A non-deterministic finite automaton (NFA) is identical to a DFA, except that there are possibly many paths traced by an input. Two sources of non-determinism • ǫ -transitions ǫ q 1 q 2 start • Multiple successor states for the same input symbol q 2 1 1 q 1 q 3 start An NFA accepts a string σ ∈ Σ ∗ if one of the paths traced by σ ends in an accepting state. 9 / 12

  10. Example of an NFA 0/1 0/1 0/ ǫ 1 q 1 q 2 q 3 start Transition Function 0 1 ǫ → q 1 { q 1 } { q 1 , q 2 } – q 2 { q 3 } – { q 3 } q 3 � { q 3 } { q 3 } – Which language does this NFA recognize? 10 / 12

  11. Formal Definition of an NFA An NFA is a 5-tuple ( Q , Σ , δ, q 0 , F ) • Q is a finite set of states • Σ is a finite set of input symbols (i.e., an alphabet ) • δ : Q × (Σ ∪ { ǫ } ) → 2 Q is a transition function • q 0 ∈ Q is the start state • F ⊆ Q is the set of final or accepting states Every input σ ∈ Σ ∗ defines a set of paths traced by δ while consuming σ . The NFA accepts a string σ if and only if one such path defined by σ ends in a final states. The language recognized by an NFA D is the set of strings L ( D ) := { σ ∈ Σ ∗ | D accepts σ } . 11 / 12

  12. 12 / 12

Download Presentation
Download Policy: The content available on the website is offered to you 'AS IS' for your personal information and use only. It cannot be commercialized, licensed, or distributed on other websites without prior consent from the author. To download a presentation, simply click this link. If you encounter any difficulties during the download process, it's possible that the publisher has removed the file from their server.

Recommend


More recommend