180 likes | 352 Views
Grammars and Automata. Review Questions (1/2). What is the size of the empty set? What is the size of the set containing just the empty string? Let L 2 = { λ , 00,0000} be defined over the alphabet ∑ = {0}. Describe the strings in the set L 2 *. Describe the complement of L 2.
E N D
Review Questions (1/2) • What is the size of the empty set? • What is the size of the set containing just the empty string? • Let L2 = {λ, 00,0000} be defined over the alphabet ∑ = {0}. Describe the strings in the set L2*. • Describe the complement of L2.
Questions (2/2) • Let L3 = {awb | w {a,b}*}. Define the language L3R • How would you prove that L3 = {a}.{a,b}*.{b}? • How would you prove that L3 ≠ L3R?
Grammars • One formal way to present a solution to a problem. • Describes rules on how to form string for a language. • A grammar generates a language
English Grammar • <sentence> -> <noun-phrase> <predicate> • <noun-phrase> -> <article> <noun> • <predicate> -> <verb> • <article> -> a | the
Definition of a Grammar • A grammar G is a 4-tuple (V,T,S,P), where • V is a finite set of variables • T is a finite set of terminal symbols • S V is the start variable • P is a finite set of productions
Productions of a Grammar • A production has the form x -> y, where • x (V T)+ • y (V T)* • And can be applied to a string w = uxv by replacing x with y. • Productions are generally used to generate a string of terminals from the start symbol.
Example • Let G=({S,A},{0,1},S,P), where P contains • S -> A1 • A -> 0A | 1A | λ
Derivations • w => z if • w = uxv, and • z = uyv, and • x -> y is a production in the grammar • If w1 => w2 => w3 => … => wn then w1 =>* wn
Language of a Grammar • The set of strings of terminals that can be generated from the start symbol of the grammar. • L(G) = { w T* | S =>* w }
Automata • Abstract model of a computer • May contain: • Input file • Temporary storage • Control unit – contains states and transitions • Output • Acceptor – output is yes or no • Transducer – output is a string
Example - Acceptor b 1 a a 0 b 2 b a
Example - Transducer 0/𝜆 0/𝜆 0/1 0/𝜆 0 1 2 3 4 1/0
Example • Design automata that accepts passwords. • A password must contain at least one upper case character and at least one digit. • Assume that the only terminals are upper and lower case characters and digits.