220 likes | 572 Views
Languages, Grammar, and Automata. Reading: 1.2. Languages. FORMAL languages, not natural languages (not even machine languages) Alphabet is all symbols allowed. Σ is alphabet, λ is null letter String variables: w = abba Concatenation, reverse, length
E N D
Languages, Grammar, and Automata Reading: 1.2
Languages • FORMAL languages, not natural languages (not even machine languages) • Alphabet is all symbols allowed. Σ is alphabet, λ is null letter String variables: w = abba Concatenation, reverse, length Σ* is 0 or more letters, Σ+ is 1 or more letters
Set Notation for Languages • Σ = {a,b} • Σ* = {λ,a,b,aa,ab,ba,bb,aaa,aab,…} • Σ+ = Σ* - {λ} • L = {anbn : n >0} • Which are in L? • λ • ab • aaa • aba • aaaaaabbb
More Language Notation Σ = {a,b,c}, L1 = {ab, bc, aba}, L2 = {c,bc,bcc} • L1 U L2 = • L1 ∩ L2 = • L1 = • L1 ∩ L2 = • L1L2 = • L10 = • L22 = • L1* = • L2R =
Grammars • A set of rules which govern the structure of a language <sentence> <nounPhrase><predicate> <nounPhrase> Fritz <nounPhrase> The dog <predicate> ate <predicate> left
Formal Grammar Notation • G = {V,T,S,P} • V are variables (<predicate>) • T are terminals (Fritz) • S is the start variable (<sentence>) • P are the production rules • Let W be a string of variables and terminals • W Y means that W can be transformed into Y using the production rules
Languages + Grammars • A grammar defines a language • Many grammars can define the same language • Grammars that generate the same language are equivalent.
Coming: Automata Input Tape a b b a a b Tape Head (moves ->) Current State 0 1
Exercises • If L = {anbn ,n>0} what is L2? • Write a grammar that generates:L={anbm, n<2, m<=2} • What language does this generate? S -> aA | λ A -> bS
... or Puzzles? • Write a grammar that generates:L={anbm, n>0, m>=0} • Write a grammar that generates all strings on {a,b}* with exactly 2 a’s • Write a grammar that generates:L={anbn, n>0} • Write a grammar that generates: • L = {w {a}*: |w| mod 4 = 0}
Mathy Questions • Suppose a grammar for L1 has start symbol S1 and a grammar for L2 has start symbol S2. What grammar describes • L1 U L2? • L1L2? • L1*? • Can you prove that your answer is correct? • Can you prove your neighbor’s answer is wrong?