Introduction
Wen-Guey Tzeng
Computer Science Department
National Chiao Tung University
Formal languages and finite automata
• We have been building computing machines for solving computing problems.22222
• Computers are everywhere.• Questions
– What is a computing machine?– What problems can be solved by a computing machine?– What problems cannot be solved?
• Finite automata: abstract models of computing machines
• Formal languages: formal representation of computing problems
22017 Spring
Classification
• Finite automata: by types of memories– Finite automata
– Pushdown automata
– Turing machines
• Formal languages: by types of grammars– Regular languages
– Context-free languages
– Recursive languages (solvable)
– Recursively enumerable languages (semi-solvable)
– …
32017 Spring
Relations
• Finite automata and regular languages
• Pushdown down automata and context-free
languages
• Turing machines and recursive languages
• Complexity classes: by runtime or space used by
Turing machines– P: polynomial time computable
– NP: non-deterministic polynomial time computable
– EXP: solvable in exponential time
– …
42017 Spring
5
Computing problems
Computing machines
Finite automata
Form
aliz
atio
n
Formal languages
Ab
stra
ctio
n
Relations
Classification by: memory,
runtime, space, etc.
Classification by: grammars, machines, etc. • Regular vs. finite automata
• Context-free vs. pushdown• Recursive vs. Turing machines• Complexity classes• …
Yes/No problems
2017 Spring
Applications
• Programming languages• Compilers• Natural language processing• Algorithm design• Software engineering• Pattern recognitions• Machine learning• …
62017 Spring
72017 Spring
8
How to compile a Java program, like the above?• We need a grammar for the Java programming
language• Context-free grammar
• We need a compiler to compile it• Pushdown automata
2017 Spring
92017 Spring
Mathematical notation
• Set: a collection of elements
– |S|: the number of elements in S
– SxT={(x, y) | xS, yT}
• Function
– f: S1S2
• Binary relation
– R S1xS2
– xS1 and yS2 has relation R if (x, y)R
102017 Spring
Three Basic Concepts
1. Languages– Symbol set (alphabet) ={a, b, c, …}
– String: w=a1a2…an, n0, ai
• |w|: length of string
• String concatenation: w1w2
• String reversing: wR=anan-1…a1
• an = aa… a (repeated n times)
• Prefix(w)={, a1, a1a2, …, a1a2…an}
• Suffix(w)={, an, an-1an, …, a1a2…an}
• Empty string , – ||=0
– w= w=w112017 Spring
Alphabet={a,b}
Strings:aba, baba, …
Languages:L={aba, abbaa,
aaba, aa, …}
– A language L over is a subset of strings over
– The language consists of all strings: *
• * over {a,b} = {, a, b, aa, ab, ba, bb, …}
– The language consists of all non-empty strings +
• + = * - {}
– Operations over languages• Reverse L: LR = {wR: wL }
• Complementation of L: Lc = * - L
• Concatenation: L1L2 = {xy: xL1, yL2}
• Ln = {x1x2…xn: xiL}– L0 = {}
– L* = L0 L1 …
– L+ = L1 L2 …
122017 Spring
2. Grammar: a set of rules for generating strings
– G=(V, T, P, S)
– V: set of variables
– T: set of terminals (symbols)
– P: set of production rules
– SV: the start variable
132017 Spring
Example
G=({S,A,B}, {a,b}, {SaA, AbS, S}, S)
• String generation/derivation
• The language generated by G
– L(G) = {w | S * w}
142017 Spring
• Problem: find grammars for languages over ={a, b}
– L1 = {anbn | n0}
– L2 = {w | na(w)=nb(w)}
– L3 = {anbm | nm0}
152017 Spring
3. Automaton: an abstract model of a digital computer
– Input
– Control unit: represented by “states”
– Storage
– Output
– Operating in discrete time frame
162017 Spring
172017 Spring
Language representation
• Informal description
– L = {aa, aaa, aab, aaaa, …}
– L = {anbn | n0 }
• Formal description
– Grammar: language generator
• It tells us how a string in a language is generated
– Automata: language acceptor
• It tells us whether a given string belongs to a language
2017 Spring 18
Top Related