Professional Documents
Culture Documents
Formal Languages
Outline
Overview of languages
Strings & languages
Introduction to grammars
Regular grammars | languages
Context Free grammars | Languages
◼ Natural Languages
❑ rules come after the language
❑ evolve and develop
❑ highly flexible
❑ quite powerful
Disadvantages
❑ vague
❑ imprecise
❑ ambiguous
◼ Formal Languages
❑ developed with strict rules
→predefined syntax and semantics
❑ precise
❑ unambiguous
Derivation tree for the simple sentence: A person entered the room.
Ex. ∑ = {0, 1} => ∑* = {λ, 0, 1, 01, 00, 11, 111, 0101, 0000, …}
❑ ∑i is a set of strings of length i, i = 0, 1, 2, …
*
❑ Let x Є ∑ and /x/ = n, then x = a1a2…an, ai Є ∑
❑ Operations on strings
◼ Concatenation operation
❑ Let x, y Є ∑* and /x/ = n and /y/ = m. Then xy,
concatenation of x and y, = a1a2…anb1b2…bm, ai, bi Є ∑
❑ The set ∑* has an identity element λ with respect to the
binary operation of concatenation.
Ex. x Є ∑* , xλ = λx = x
❑ ∑* has left and right cancellation
For x, y, z Є ∑*,
zx = zy => x = y (left cancellation)
xz = yz => x = y (right cancellation)
❑ For x, y Є ∑* , we have /xy/ = /x/ + /y/
◼ Transpose operation
❑ For any x in ∑* and a in ∑, (xa)T = a(x)T
Ex. (aaabab)T = babaaa
❑ A palindrome of even length can be obtained by the
concatenation of a string and its transpose.
❑ A prefix of a string is a substring of leading symbols of that
string.
w is a prefix of y if there exists y’ in ∑* such that y=wy’
Ex. y = 123, list all prefixes of y.
❑ A suffix of a string is a substring of trailing symbols of that
string.
w is a prefix of y if there exists y’ in ∑* such that y=y’w
Ex. y = 123, list all suffixes of y.
❑ | stands for OR
◼ Derivation
1. If α generates β, then we write α => β
2. If α1 => α2, α2 => α3, …, αn-1 => αn, then we write
+
α1 => α2 => α3 => … => αn or α1 => αn
◼ Let G = (N, T, P, S) be a grammar, if S => α in
zero or more steps, α Є (N U T)*, then α is called a
sentential form.
◼ A sentence (in G) is a sentential form in T*.
◼ The language generated from the grammar G is
denoted by L(G). L(G) = {x Є T* | S => * x}
◼ Ex3.
S → a|bS
◼ Ex4.
S → aA|bB|a|b
A → aA|a
B → bB|b
◼ Example:
Let G=(N, T, P, S) be a regular grammar with
P: S→aA|bB
A→aA|a
B→bB|b
Draw a transition diagram that represents G