CS314 – Section 5 Recitation 3

Slides:



Advertisements
Similar presentations
Grammar types There are 4 types of grammars according to the types of rules: – General grammars – Context Sensitive grammars – Context Free grammars –
Advertisements

Chapter 5: Languages and Grammar 1 Compiler Designs and Constructions ( Page ) Chapter 5: Languages and Grammar Objectives: Definition of Languages.
CPSC Compiler Tutorial 4 Midterm Review. Deterministic Finite Automata (DFA) Q: finite set of states Σ: finite set of “letters” (input alphabet)
1 Introduction to Computability Theory Lecture3: Regular Expressions Prof. Amos Israeli.
Lecture 3UofH - COSC Dr. Verma 1 COSC 3340: Introduction to Theory of Computation University of Houston Dr. Verma Lecture 3.
CS 310 – Fall 2006 Pacific University CS310 Pushdown Automata Sections: 2.2 page 109 October 9, 2006.
CS Master – Introduction to the Theory of Computation Jan Maluszynski - HT Lecture 4 Context-free grammars Jan Maluszynski, IDA, 2007
January 14, 2015CS21 Lecture 51 CS21 Decidability and Tractability Lecture 5 January 14, 2015.
CS 490: Automata and Language Theory Daniel Firpo Spring 2003.
Fall 2006Costas Busch - RPI1 Non-Deterministic Finite Automata.
PZ02B Programming Language design and Implementation -4th Edition Copyright©Prentice Hall, PZ02B - Regular grammars Programming Language Design.
1 Non-Deterministic Finite Automata. 2 Alphabet = Nondeterministic Finite Automaton (NFA)
Thopson NFA Presenter: Yuen-Shuo Li Date: 2014/5/7 Department of Computer Science and Information Engineering National Cheng Kung University, Taiwan R.O.C.
PZ02B Programming Language design and Implementation -4th Edition Copyright©Prentice Hall, PZ02B - Regular grammars Programming Language Design.
Pushdown Automata CS 130: Theory of Computation HMU textbook, Chap 6.
Lecture # 3 Chapter #3: Lexical Analysis. Role of Lexical Analyzer It is the first phase of compiler Its main task is to read the input characters and.
Grammars CPSC 5135.
2. Scanning College of Information and Communications Prof. Heejin Park.
4b 4b Lexical analysis Finite Automata. Finite Automata (FA) FA also called Finite State Machine (FSM) –Abstract model of a computing entity. –Decides.
1 Syntax Specification (Sections ) CSCI 431 Programming Languages Fall 2003 A modification of slides developed by Felix Hernandez-Campos at UNC.
Regular Grammars Chapter 7. Regular Grammars A regular grammar G is a quadruple (V, , R, S), where: ● V is the rule alphabet, which contains nonterminals.
Regular Grammars Chapter 7 1. Regular Grammars A regular grammar G is a quadruple (V, , R, S), where: ● V is the rule alphabet, which contains nonterminals.
Finite Automata – Definition and Examples Lecture 6 Section 1.1 Mon, Sep 3, 2007.
Finite Automata Chapter 1. Automatic Door Example Top View.
Regular Grammars Reading: 3.3. What we know so far…  FSA = Regular Language  Regular Expression describes a Regular Language  Every Regular Language.
Context Free Grammars and Regular Grammars Needs for CFG Grammars and Production Rules Context Free Grammars (CFG) Regular Grammars (RG)
using Deterministic Finite Automata & Nondeterministic Finite Automata
Algorithms for hard problems Automata and tree automata Juris Viksna, 2015.
Mid-Terms Exam Scope and Introduction. Format Grades: 100 points -> 20% in the final grade Multiple Choice Questions –8 questions, 7 points each Short.
Deterministic Finite Automata Nondeterministic Finite Automata.
Context Free Grammars & Parsing CPSC 388 Fall 2001 Ellen Walker Hiram College.
1 Regular grammars Programming Language Design and Implementation (4th Edition) by T. Pratt and M. Zelkowitz Prentice Hall, 2001 Section
Costas Busch - LSU1 Deterministic Finite Automata And Regular Languages.
Department of Software & Media Technology
Topic 3: Automata Theory 1. OutlineOutline Finite state machine, Regular expressions, DFA, NDFA, and their equivalence, Grammars and Chomsky hierarchy.
Theory of Languages and Automata By: Mojtaba Khezrian.
Chapter 3 – Describing Syntax
CS314 – Section 5 Recitation 2
Finite automate.
Lexical analysis Finite Automata
Non Deterministic Automata
Regular grammars Programming Language Design and Implementation (4th Edition) by T. Pratt and M. Zelkowitz Prentice Hall, 2001 Section
Syntax Specification and Analysis
Complexity and Computability Theory I
Natural Language Processing - Formal Language -
Context Sensitive Grammar & Turing Machines
CSE 105 theory of computation
Department of Software & Media Technology
REGULAR LANGUAGES AND REGULAR GRAMMARS
Regular Grammar.
Non-Deterministic Finite Automata
Chapter 7 Regular Grammars
COSC 3340: Introduction to Theory of Computation
Non Deterministic Automata
Lecture 4: Lexical Analysis & Chomsky Hierarchy
Finite Automata.
4b Lexical analysis Finite Automata
Homework #5 (Models of Computation, Spring, 2001) Due: Section 1; February 27 Section 2; February 28 ** Please put your homework in the collection.
Compiler Construction
4b Lexical analysis Finite Automata
Theory of Computation Lecture #
Regular grammars Programming Language Design and Implementation (4th Edition) by T. Pratt and M. Zelkowitz Prentice Hall, 2001 Section
CSE 105 theory of computation
Pushdown automata The Chinese University of Hong Kong Fall 2011
Regular Grammars.
Announcements - P1 part 1 due Today - P1 part 2 due on Friday Feb 1st
Regular grammars Programming Language Design and Implementation (4th Edition) by T. Pratt and M. Zelkowitz Prentice Hall, 2001 Section
Lexical Analysis Uses formalism of Regular Languages
PZ02B - Regular grammars Programming Language Design and Implementation (4th Edition) by T. Pratt and M. Zelkowitz Prentice Hall, 2001 Section PZ02B.
CSE 105 theory of computation
Presentation transcript:

CS314 – Section 5 Recitation 3 Long Zhao (lz311@rutgers.edu) DFA, NFA Context Free Grammars Slides available at http://www.ilab.rutgers.edu/~lz311/CS314

Finite-State Automaton A Finite-State Automaton is a quadruple: <S, s, F, T> S is a set of states s is the start state F is a set of final states T is a set of labeled transitions, of the form (state, input) => state

DFA & NFA DFA - Determistic Finite Automaton: At most one transition for a state and an input symbol. (Recognizers should be a DFA.) NFA - Nondeterministic Finite Automaton: More than one transition possible for a state and an input symbol.

Constructing a DFA from a RE Regular Expression (RE) →NFA with ϵ moves NFA with ϵ moves to NFA NFA→DFA

NFA with ϵ moves (5 rules) B AB

NFA with ϵ moves (5 rules) A|B B ϵ ϵ ϵ ϵ A ϵ A* ϵ

NFA with ϵ moves (Examples) (A|B)C A ϵ ϵ ϵ C B ϵ ϵ

NFA with ϵ moves (Examples) A|BC A ϵ ϵ ϵ B C ϵ ϵ

NFA with ϵ moves (Examples) ((A|B)C)* ϵ A ϵ ϵ ϵ ϵ C ϵ ϵ B ϵ ϵ

NFA with ϵ moves (Examples) ((A|B)C)* ϵ A C B ϵ

NFA with ϵ moves to NFA ((A|B)C)* 1 2 3 A B C ϵ* (->)1 2 - 1,3 3

NFA with ϵ moves to NFA ((A|B)C)* 1 2 3 ϵ*Aϵ* ϵ*Bϵ* ϵ*Cϵ* (->|O)1 2 Since ϵ*(1) is {1, 3} which contains the final state 3, state 1 should be a final state in the new NFA as well. ((A|B)C)* ϵ*Aϵ* ϵ*Bϵ* ϵ*Cϵ* (->|O)1 2 - 1,3 (O)3 ϵ A,B C 1 2 3 ϵ

NFA with ϵ moves to NFA ((A|B)C)* 1 2 3 ϵ*Aϵ* ϵ*Bϵ* ϵ*Cϵ* (->|O)1 2 1,3 (O)3 C A,B A,B 1 2 3 C

NFA to DFA ϵ*Aϵ* ϵ*Bϵ* ϵ*Cϵ* 2 - 1,3 (O)3 A B C 2 - 1,3 (O)1,3

NFA to DFA ((A|B)C)* A B C (->|O)1 2 - 1,3 (O)1,3 A,B A,B 1 2 1,3 C

NFA to DFA All strings contain {a, b} and end with an ‘a’. RE: (a|b)*a 1 2 a,b

NFA to DFA (a|b)*a a b (->)1 1,2 1 (O)2 - a 1 2 a,b

NFA to DFA (a|b)*a a b (->)1 1,2 1 (O)2 - a b (->)1 1,2 1 (O)1,2

NFA to DFA (a|b)*a a b (->)1 1,2 1 (O)1,2 a 1 1,2 b b a

NFA to DFA (Example) 2 ϵ a a b NFA without ϵ move? DFA? 1 3 c c 4 ϵ

NFA to DFA (Example) 2 1 3 4 a b c ϵ* (->)1 2 - 4 1 3 1,2 (O)3 3,4

NFA to DFA (Example) 2 1 3 4 ϵ*aϵ* ϵ*bϵ* ϵ*cϵ* (->)1 1,2 - 3,4 2 3

NFA to DFA (Example) 2 1 3 4 a ϵ*aϵ* ϵ*bϵ* ϵ*cϵ* (->)1 1,2 - 3,4 2 NFA without ϵ move NFA to DFA (Example) a 2 ϵ*aϵ* ϵ*bϵ* ϵ*cϵ* (->)1 1,2 - 3,4 2 3 (O)3 (O)4 a a b,c c a a c 1 3 a a a c c 4

NFA to DFA (Example) a b c (->)1 1,2 - 3,4 2 3 (O)3 (O)4 a b c

NFA to DFA (Example) 1 3 a b c (->)1 1,2 - 3,4 3 (O)3,4 (O)3 a a a

Context-Free Grammars A formalism for describing languages CFGs are a quadruple < T,N,P,S >: A set T of terminal symbols (tokens) A set N of nonterminal symbols A set P production rules A special start symbol S BNF is a notation for describing CFGs.

Simple BNF Grammar Terminals letters, digits, := Nonterminals <letter> <digit> <stmt> <identifier> Productions <letter> ::= A | B | C | ...| Z <digit> ::= 0 | 1 | 2 | ...| 9 <identifier> ::= <letter> |<identifier> <letter> |<identifier> <digit> <stmt> ::= <identifier> := 0 Start Symbol <stmt>

Regular Grammars CFGs with restrictions on the shapes of production rules. Left-linear: <N> ::= <X> a b <X> ::= a | <X> b Right-linear: N ::= b | b <Y> Y ::= a b | a b <Y>

Context-Free Grammars Give the context-free grammar in BNF notation that generates the following language: 0 𝑛 1 𝑛 𝑛≥0}, with alphabet {0, 1} 𝑎 𝑚 𝑏 𝑐 𝑛 𝑚,𝑛≥0}, with alphabet {a, b, c} All strings of the form 0 𝑎 1 𝑏 0 𝑐 such that a + c = b.

Context-Free Grammars 0 𝑛 1 𝑛 𝑛≥0}, with alphabet {0, 1} Terminals 0, 1, ϵ Nonterminals <S> Productions <S> ::= 0<S>1 <S> ::= ϵ Start Symbol <S>

Context-Free Grammars 𝑎 𝑚 𝑏 𝑐 𝑛 𝑚,𝑛≥0}, with alphabet {a, b, c} The regular expression a*bc* Terminals a, b, c, ϵ Nonterminals <S> <A> <C> Productions <S> ::= <A> <A> ::= a<A>|b<C> <C> ::= c<C>|ϵ Start Symbol <S>

Context-Free Grammars All strings of the form 0 𝑎 1 𝑏 0 𝑐 such that a + c = b. Terminals 0, 1, ϵ Nonterminals <S> <T> <U> Productions <S> ::= <T><U> <T> ::= 0<T>1|ϵ <U> ::= 1<U>0|ϵ Start Symbol <S>