Context-Free Grammars
Consider L = cfw_anbn | n 0
o L is not regular, so there is no fsa or regular expression for L.
o However, we can describe elements in L recursively:
1. L
2. if w L then awb L
o We can combine 1 and 2
S | aSb
where S is a variable, m
CS 311-01 Language Translation and Automata
Homework #2
(Due: 2 PM, Wednesday, 2/5/2014)
1. Construct a NFSA with at least one -moves to accept each of the following languages.
(a) cfw_wcfw_0,1* | w corresponds to the binary encoding of a positive integer
CS 311-01 Language Translation and Automata
Project #2
(Due: 2 PM, Monday, 2/24/2013)
Write a program that (1) accepts a set of input strings on lower case English letters
and create a Non-deterministic Finite State Automaton (NFSA) for accepting only tha
CS 311-02 Formal Languages and Automata
Homework #1
(Due: 1 PM, Tuesday, 1/17/2017)
1. Construct a DFSA to accept each of the following languages.
(a) cfw_x cfw_a,b* | x does not have ababa as a substring
(b) cfw_x cfw_0,1,2* | the sum of the digits of x
CS311 Formal Language and
Automata
Tingting Chen
Computer Science
Cal Poly Pomona
Fall 2016
DFA to right-linear grammar
Example: Construct a right-linear grammar for
the language L = L(aab*a)
First, build an NFA for L:
q0
a
q1
a
q2
b
a
qf
DFA to right-l
CS311 Formal Language and
Automata
Tingting Chen
Computer Science
Cal Poly Pomona
Fall 2016
Membership Question
Question: Given regular language L and
string w, how can we check if w L?
Answer: Take the DFA that accepts L and
check if w is accepted.
L is
CS311 Formal Language and
Automata
Tingting Chen
Computer Science
Cal Poly Pomona
Fall 2016
NFA ->DFA
We are given an NFA M.
We want to convert it to an equivalent DFA M, with
L(M) = L(M)
Example: convert NFA to DFA
NFA:
DFA:
Theorem
Take NFA M, Apply
CS311 Formal Language and
Automata
Tingting Chen
Computer Science
Cal Poly Pomona
Fall 2016
Why NFA?
More natural when modeling a lot of real problems, such as
in game theory.
We can express languages easier than DFA.
L(M1) = cfw_a
L(M2)=cfw_a
Formal De
CS311 Formal Language and
Automata
Tingting Chen
Computer Science
Cal Poly Pomona
Fall 2016
In/distinguishable States
Two states p and q of a DFA are called
indistinguishable if
* (p, w) F * (q, w) F ,
and
* (p, w) F * (q, w) F ,
for all w *.
If there e
CS311 Formal Language and
Automata
Tingting Chen
Computer Science
Cal Poly Pomona
Fall 2016
Ambiguity
A grammar G is ambiguous if there is a string
w L(G) has two or more possible derivation trees.
In other words,
A grammar G is ambiguous if there is a st
CS311 Formal Language and
Automata
Tingting Chen
Computer Science
Cal Poly Pomona
Fall 2016
The Pumping Lemma Formally
Given an infinite regular language L
There exists an integer m
For any string w L, with length |w| m
we can write w=xyz
with |xy|<=m and
CS311 Formal Language and
Automata
Tingting Chen
Computer Science
Cal Poly Pomona
Fall 2016
Reading
Section 1.1, 1.2
Section 2.1
Grammars
Grammars are used to generate languages.
A grammar G is defined as a quadruple:
G = (V, T, S, P)
Where V is a finite
CS311 Formal Language and
Automata
Tingting Chen
Computer Science
Cal Poly Pomona
Fall 2016
Pushdown Automaton - PDA
Initial Stack Symbol
The States
Non-Determinism
A lot of PDAs are non-deterministic
Allow non-deterministic transitions
Example PDA
PDA
CS311 Formal Language and
Automata
Tingting Chen
Computer Science
Cal Poly Pomona
Fall 2016
Generalized Transition Graph
A generalized transition graph (GTG) is a transition
graph whose edges are labeled with regular
expressions; otherwise it is the same
CS311 Formal Language and
Automata
Tingting Chen
Computer Science
Cal Poly Pomona
Fall 2016
NFA DFA
Exercise: Convert this NFA to a DFA.
NDFA DFA
Example:
Minimal DFAs
We say M is minimal if there is no other DFA with a
smaller number of states which als
CS311 Formal Language and
Automata
Tingting Chen
Computer Science
Cal Poly Pomona
Fall 2016
Topic of course
What are the fundamental capabilities and
limitations of computers?
To answer this, we will study abstract
mathematical models of computers
Thes
CS311 Formal Language and
Automata
Tingting Chen
Computer Science
Cal Poly Pomona
Fall 2016
Languages
A language is a set of strings.
String: A sequence of letters.
Example: cat, dog, house
Defined over an alphabet:
S = cfw_a, b, c, , z.
Alphabets an
CS311 Formal Language and
Automata
Tingting Chen
Computer Science
Cal Poly Pomona
Fall 2016
Regular Expressions
and Regular Languages
Let M = (Q, S, q0, d, A) be an FA.
A string x S * is accepted by M if
d*(q0, x) A
The language accepted (or recognized)
CS311 Formal Language and
Automata
Tingting Chen
Computer Science
Cal Poly Pomona
Fall 2016
Chomsky Normal Form
There are other ways to limit the form a
grammar can have.
A context-free grammar in Chomsky Normal
Form (CNF) has all of its rules restricte
Context-Free Grammars
Consider L = cfw_anbn | n 0
o L is not regular, so there is no fsa or regular expression for L.
o However, we can describe elements in L recursively:
1. L
2. if w L then awb L
o We can combine 1 and 2
S | aSb
where S is a variable,
CS 311-02 Formal Languages and Automata
Project #1
(Due: 1 PM, Thursday, 1/26/2017)
Once a finite state automaton (FSA) is designed, its transition diagram can be
translated in a straightforward manner into program code. However, this translation process
CS 311-02 Formal Languages and Automata
Homework #2
(Due: 1 PM, Thursday, 2/2/2017)
1. Construct a NFSA with at least one -moves to accept each of the following languages.
(a) cfw_wcfw_0,1* | w corresponds to the binary encoding of a positive integer that
/*
* Name: Zhenxing He
* Class: CS 311
* Project2
* Date:February 17, 2017
*
* Purpose: This program is an implementation of a dynamic finite state
automaton. The program first reads the java reserved words
*
from Proj2_Input1.txt. Then it read a java pro
/*
* Name: Zhenxing He
* Class: CS 311
* Project2
* Date:February 17, 2017
*
* Purpose: This program is an implementation of a dynamic finite state
automaton. The program first reads the java reserved words
*
from Proj2_Input1.txt. Then it read a java pro
/*
* Name: Zhenxing He
* Class: CS 311
* Project 1
* Date: January 22 2017
*
* Purpose: This program is an implementation of an universal finite state
automata. This program reads from an input file which contains
*
information of the FSA. This program ca
import java.util.ArrayList;
public class universalFSA cfw_
public
public
public
public
int numOfStates;
boolean finalStates[];
char alphabet[];
int transitions[][];
/constructor
public universalFSA(int numOfStates)
cfw_
this.numOfStates = numOfStates;
fin
Processes
Nick Pantic
January 11, 2017
Nick Pantic
Processes
January 11, 2017
1 / 39
Processes
A process is an instance of a program currently being executed by a
computer
This must include the instructions to execute, register contents, and
open resource