930 likes | 950 Views
This lecture covers finite state machines, regular languages, and the differences between deterministic and non-deterministic finite state machines. It also discusses right-linear grammars and their conversion to NFAs.
E N D
Lecture 3: Finite State Machines Xiaoyin Wang CS 5363 Spring 2019
Last Class • Formal Languages • What are languages? • What are grammars? • Phrase-Structure Grammars • Classification of Grammars (and corresponding languages)
Today’s Class • Finite State Machines • Regular Languages and FSMs • DFA vs. NFA
Finite State Machines • A state transition system • Takes a sequence of characters as its input • State transits according to the input • Whether an input is accepted: • If the system stops at an acceptance state
Finite State Machines • Two types of machines • Recognizers • No output • Transducers • Moore Machine: Output on states • Mealy Machine : Output on transitions
Finite State Machine Input Tape String Output “Accept” or “Reject” State Transition
Transition Graph initial state accepting state transition state
Alphabet For every state, there is a transition for every symbol in the alphabet
Initial Configuration head Input Tape Input String Initial state
Input finished accept
A Rejection Case Input String
Input finished reject
Another Rejection Case Tape is empty Input Finished reject
To accept a string: all the input string is scanned and the last state is accepting To reject a string: all the input string is scanned and the last state is non-accepting
Formal Definition • Deterministic Finite Automaton (DFA) : set of states : input alphabet : transition function : initial state : set of accepting states
Set of States Example
Input Alphabet :the input alphabet never contains Example
Initial State Example
Set of Accepting States Example
Transition Function Describes the result of a transition from state with symbol
Transition Table for symbols states
Language Accepted by DFA Language of DFA : it is denoted as and contains all the strings accepted by We say that a language is accepted (or recognized) by DFA if
For a DFA • Language accepted by :
Today’s Class • Finite State Machines • FSM and Regular Languages • DFA vs. NFA
Grammar is right-linear Example:
Construct NFA such that • every state is a grammar variable: special final state
In General • A right-linear grammar • has variables: • and productions: or
We construct the NFA such that: • each variable corresponds to a node: special final state
For each production: • we add transition
For each production: • we add transitions and intermediate nodes
In General For any transition: Add production: variable terminal variable
In General If p is acceptance state Add production: