Context-Free Grammars and Languages

Size: px
Start display at page:

Download "Context-Free Grammars and Languages"

Transcription

1 Context-Free Grmmrs nd Lnguges (Bsed on Hopcroft, Motwni nd Ullmn (2007) & Cohen (1997)) Introduction Consider n exmple sentence: A smll ct ets the fish English grmmr hs rules for constructing sentences; e.g., 1. A sentence cn e suject followed y predicte (Suject: A smll ct) (Predicte: ets the fish) 2. A suject cn e noun-phrse (Noun-Phrse: A smll ct) 3. A noun-phrse cn e n rticle, followed y n djective followed y noun (Article: A) (Adjective: smll) (Noun: ct) 4. A predicte cn e ver-phrse (Ver-Phrse: ets the fish) 5. A ver-phrse cn e ver followed y noun-phrse (Ver: ets) (Noun-Phrse: the fish) 7. A noun-phrse cn e n rticle, followed y noun (Article: the) (Noun: fish) 8. A ver cn e: uries, touches, grs, ets 9. An djective cn e: ig, smll 10. An rticle cn e: the,, n Definition: The things tht cnnot e replced y nything re clled terminls. Definition: The things tht must e replced y other things re clled nonterminls or vriles In the ove exmple, smll nd ets re terminls, nd noun-phrse nd ver-phrse re nonterminls. Definition: The sequence of pplictions of the rules tht produces the finished string of terminls from the strting symol is clled derivtion. For derivtion of smll ct ets the fish using Context-Free Grmmr (CFG), visit this pge: Context-Free Grmmr (CFG) Exmple 1: terminls: = { } Nonterminls: N = { S } productions: S S S ^ The ove CFG defines * = { ^,,,,,,... } It cn generte or derive s follows: S => S => S => S => S => 1

2 The sme derivtion cn lso e written s: S => S => S => S => S => Exmple 2: Terminl: = { } Nonterminl: N = { S } Productions: S SS S S ^ This CFG cn e written in more compct nottion: S SS ^ which is lso clled the Bckus Norml Form or Bckus-Nur Form (BNF). The ove CFG defines the sme CFL: * = { ^,,,,,... } This CFG cn generte the string s follows: S => SS => SSS => SS => SSS => SS => S => In this grmmr, string in the CFL hs infinitely mny derivtions. In other exmples, string is usully generted in limited numer of wys. Definition: A context-free grmmr (CFG) is composed of: 1. : A finite non-empty set of symols clled terminls from which strings of the lnguge re mde. 2. N: A finite set of symols clled nonterminls. nd N re disjoint. 3. S: A specil strt symol in N. 4. P: A finite set of productions of the form: N i string from ( + N)* where N i is in N. Thus, ech production is of the form: one nonterminl -> finite string of terminls nd/or nonterminls, where the string of terminls nd/or nonterminls cn consist of only terminls or only nonterminls, or ny mixture of terminls nd nonterminls or even the empty string. We require tht t lest one production hs the nonterminl S s its left side. On the right side of the rrow ny string from ( + N)* is llowed. Some ooks represent terminls y T; in tht cse, the productions of the form N i (T + N)* re llowed in CFG. Convention: Terminls will typiclly e lowercse letters. Nonterminls will typiclly e uppercse letters. Exmple 3: A CFG for * = {,,,,,.... } 1. Terminls: = {, }, 2. Nonterminl: N = {S, B} 3. Productions: P = { S B B B ^ } DERIVATION of using the CFG of exmple 3: S => B => B => B => B => 2

3 Most of the time the set of productions re explicitly given for CFG nd the terminls nd the non-terminls re understood from the context s shown in exmples 4-6 : Exmple 4: A CFG for * = {,,,,.... } S A A A ^ DERIVATION of using the CFG of exmple 4: S => A => A => A => A => Exmple 5: A CFG for * = {,,,,.... } S B B B ^ DERIVATION of using the CFG of exmple 5: S => B => B => B => B => B => Exmple 6: A CFG for { n c n :n > 0} = { c, c, c,.... } S S c DERIVATION of c using the CFG of exmple 6: S => S => S => c Definition: The lnguge generted (defined, derived, produced) y CFG, G, is the set of ll strings of terminls tht cn e produced from the strt symol S using the productions s sustitutions. A lnguge generted y CFG, G, is clled context-free lnguge (CFL) nd is denoted y L(G). Exmple: Terminls: = {}, Nonterminl: N = {S} Productions: P = S S S ^ Let L1 the lnguge generted y this CFG, nd let L2 e the lnguge generted y regulr expression *. Clim: L1 = L2. Proof: We first show tht L2 L1. Consider ^n L2 for n >= 1. We cn generte n y using first production n times, nd then second production. Cn generte ^ L2 y using second production only. 3

4 Hence L2 L1. We now show tht L1 L2. Since is the only terminl, CFG cn only produce strings hving only s. Thus, L1 L2. Note tht Two types of rrows: -> used in sttement of productions => used in derivtion of string in the ove derivtion of 4, there were mny unfinished stges tht consisted of oth terminls nd nonterminls. These re clled working strings. ^ is neither nonterminl (since it cnnot e replced with something else) nor terminl (since it disppers from the string). Exmple: terminls: = {, } Nonterminls: { S } Productions: S -> S S -> S S -> S -> More compct nottion: S -> S S This CFG cn derive the string s follows: S => S => S => S => S => Let L1 e the CFL, nd let L2 e the lnguge generted y the regulr expression ( + )+. Clim: L1 = L2. Proof: First we show tht L2 L1. Consider ny string w L2. Red letters of w from left to right. For ech letter red in, if it is not the lst, then use the production S -> S if the letter is or use the production S -> S if the letter is For the lst letter of the string, use the production S -> if the letter is or use the production S -> if the letter is In ech stge of the derivtion, the working string hs the form (string of terminls)s. Hence, we hve shown how to generte w using the CFG, which mens tht w L1. Hence, L2 L1. Now we show tht L1 L2. To show this, we need to show tht if w L1, then w L2. This is equivlent to showing tht if w L2, then w L1. 4

5 Note tht the only string w L2 is w = A. But note tht A cnnot e generted y the CFG, so A L1. Hence, we hve proven tht L1 L2. Trees cn e used to illustrte how string is derived from CFG. Definition: A tree is n cyclic grph. Trees sed on grmmr (or syntx definition) re clled syntx trees, prse trees, genertion trees, production trees, or derivtion trees. Exmple: The following CFG defines L 6 = { { n c*} n } Terminls: { {, }, c } Nonterminls: { S, X } Productions: S {S} {X} X cx ^ Every string generted y this CFG hs lnced open nd closed rces like progrmming lnguges such s Jv. Consider the following derivtion: S => {S} => {{S}} => {{{X}}} => {{{cx}}} => {{{ccx}}} => {{{cc}}} The ove derivtion corresponds to the following derivtion tree or prse tree: 5

6 Exmple: CFG for simplified rithmetic expressions. Terminls : +, _, 0, 1, 2,..., 9 Nonterminls : S Productions : S S + S S - S Consider the expression Amiguous how to evlute this: Does this men (2-3) + 4 = 10 or 2 - (3 + 4) = 14? Cn eliminte miguity y exmining the two possile derivtion trees S S / \ / \ / \ / \ / \ / \ / \ / \ S + S S * S / \ / \ / \ / \ 2 * Eliminte the S s s follows: + * / \ / \ / \ / \ / \ / \ / \ / \ * / \ / \ / \ / \ Note tht we cn construct new nottion for mthemticl expressions: strt t top of tree wlk round tree keeping left hnd touching tree first time hit ech terminl, print it out. This gives us string which is in opertor prefix nottion or Polish nottion. In ove exmples, first tree yields + _ second tree yields _ To evlute the string: 1. scn string from left to right. 6

7 2. the first time we red sustring of the form opertor-opernd-opernd (o-o-o), replce the three symols with the one result of the indicted rithmetic clcultion. 3. go ck to step 1 Exmple: (from ove) first tree yields: string first o-o-o sustring + _ _ second tree yields: string first o-o-o sustring _ _ 2 7 _ Definition: A CFG is miguous if for t lest one string in its CFL there re two possile derivtions of the string tht correspond to two different syntx trees. Exmple: PALINDROME Terminls :, Nonterminls : S Productions : S S S ^ Cn generte the string s follows: S => S => S => S => which hs derivtion tree: S / \ S / \ S / \ S ^ Cn show tht this CFG is unmiguous. 7

8 Definition: For given CFG, the totl lnguge tree is the tree with root S, whose children re ll the productions of S, whose second descendents re ll the working strings tht cn e constructed y pplying one production to the leftmost nonterminl in ech of the children, nd so on. Exmple: Terminls :, Nonterminls : S, X Productions : S -> X X XX X -> This CFG hs totl lnguge tree s follows: S / \ / \ / \ / \ / \ X X XX / / / \ / / / \ X X / \ / \ The CFL is finite. Other References: 8

9 Chpter 13 Grmmticl Formt Regulr Grmmrs We previously sw tht CFG s cn generte ll regulr lnguges. CFG s cn generte some non-regulr lnguges (tht re Context-Free). All regulr lnguges cn e generted y CFG s, ecuse ll regulr lnguges re CF. some non-regulr lnguges cnnot e generted y CFG s, ecuse they re non-cf. One cn turn n FA into CFG s follows: Exmple: L = ll strings ending in. FA: A+ S- B Definition: The pth development of string processed on mchine: Strt in strting stte S. For ech stte visited, print out the input letters used thus fr nd the current stte. 9

10 The string hs following pth development on the FA: S A B A B B A Now we define the following productions: S -> A B A -> A B _ B > A B Note tht: The CFG hs production X -> cy if nd only if in the FA, there is n rc from stte X to stte Y leled with c. The CFG hs production X -> A if nd only if stte X in the FA is finl stte. Derivtion of using the CFG: S => A => B => A => B => B => A => There is one-to-one correspondence etween pth developments on the FA nd derivtions in the CFG; i.e., we cn use the pigeonhole principle. The derivtion of the string using the CFG is exctly the sme s the pth development given ove. Theorem 21 All regulr lnguges re CFL s. 10

11 Exmple: FA: A+ S- C+ B productions: S => S A A => C B A B => B C C => A B A Consider CFG G = (E,, R, S), where E is the set of terminls is the set of nonterminls, nd S is the strting nonterminl R (E+ )* is the set of productions, where production (N, U) R with N nd U (E + )* is written s N -> U Definition: For given CFG G = (E,,R, S), W is semiword if W E * ; i.e., W is string of terminls (mye none) cnctented with exctly one nonterminl (on the right). Exmple: N is semiword if N is nonterminl nd nd re terminls. Definition: A Regulr grmmr, RG, is composed of 1. : A finite non-empty set of symols clled terminls 11

12 2. N: A finite set of symols, clled Non-terminls. nd N re disjoint 3. S: A specil strt symol in N. 4. P: A set of productions in one of the following two forms (not oth): 4. Right RG: N i *N j * 4. Left RG: N i N j * * A regulr grmmr cn e either Right Regulr or Left Regulr not oth. Ech of N i nd N j is single non-terminl nd they could e the sme. Tht is, N i = N j is llowed. Theorem 22 If CFG is regulr grmmr, then the lnguge generted y this CFG is regulr. Proof. We will prove theorem y showing tht there is TG tht ccepts the lnguge enerted y the CFG. Suppose CFG is s follows: N1 -> w1m1 N2 -> w2m2... Nn -> wnmn Nn+1 -> wn+1 Nn+2 -> wn+2... Nn+m! wn+m where Ni nd Mi re nonterminls (not necessrily distinct) nd wi E* re strings of terminls. Thus, wimi is semiword. At lest one of the Ni = S. Assume tht N1 = S. Crete stte of the TG for ech nonterminl Ni nd for ech nonterminl Mj. Also crete stte +. Mke the stte for nonterminl S the initil stte of the trnsition grph. Drw n rc leled with wi from stte Ni to stte Mi if nd only if there is production Ni -> wimi. Drw n rc leled with wi from stte Ni to stte + if nd only if there is production Ni -> wi. Thus, we hve creted TG. By considering the pth developments of words ccepted y the TG, we cn show tht there is one-to-one correspondence etween words ccepted y TG nd words in CFL. Thus, these re the sme lnguge. Kleene s Theorem implies tht the lnguge hs regulr expression. Thus, lnguge is regulr. Remrks: ll regulr lnguges cn e generted y some regulr grmmrs (Theorem 21) 12

13 ll regulr grmmrs generte some regulr lnguge. regulr lnguge my hve mny CFG s tht generte it, where some of the CFG s my not e regulr grmmrs. Exmple: CFG productions: S -> B A A B A -> A B -> A Corresponding TG (note tht CFG does not generte A): A S-, + B ^ Definition: A production (N, U) R is A-production if U = A, i.e., the production is N -> A. If CFG does not contin A -production, then A CFL. However, CFG my hve A -production nd A CFL. Exmple: productions: S -> X X -> A Chomsky Norml Form 13

14 A Productions nd Nullle Nonterminls Recll we previously defined A -production: N-> A where N is some nonterminl. Note tht If some CFL contins the word A, then the CFG must hve A -production. However, if CFG hs A -production, then the CFL does not necessrily contin A; e.g., S -> X X -> A which defines the CFL {}. Definition: For given CFG with s its set of nonterminls E nd A s its set of terminls, working string W 2 (E + )* is ny string of nonterminls nd/or terminls tht cn e generted from the CFG strting from ny nonterminl. Definition: For given CFG hving nonterminl X nd W possile working string, we use the nottion X => W if there is some derivtion in the CFG strting from X tht cn result in the working string W. Exmple: CFG: S X Y X Y A Y X Since we hve the following derivtion S => Y => X => we cn write S *=> Y nd S *=> X nd S *=>. Definition: In given CFG, nonterminl X is nullle if 1. There is production X -> A, or 2. X *=> A; i.e., there is derivtion tht strts t X nd leds to A 3. X =>. => A Chomsky Norml Form Definition: A CFG G = (E,,R, S) is in Chomsky Norml Form (CNF) if (N, U) R implies U () + E; i.e., ech of its productions hs one of the two forms: 14

15 1. Nonterminl -> string of exctly two Nonterminls 2. Nonterminl -> one terminl Theorem 26 For ny CFL L, the non- A words of L cn e generted y CFG in CNF. Leftmost Nonterminls nd Derivtions Definition: The leftmost nonterminl (LMN) in working string is the first nonterminl tht we encounter when we scn the string from left to right. Exmple: In the string XY SXY, the LMN is X. Definition: If word w is generted y CFG y certin derivtion nd t ech step in the derivtion, rule of production is pplied to the leftmost nonterminl in the working string, then this derivtion is clled leftmost derivtion (LMD). Exmple: CFG: S XS X X The following is Left-Most Derivtion (LMD): S => XS => XS => XS => S => Exmple: CFG: S XY X Y X Y Y Y XX The word hs the following derivtion tree: S / \ / \ 15

16 / \ / \ / \ X _ Y _ / \ / / \ \ Y / \ / \ X X / \ / \ X / \ / \ Y Y / \ / \ Note tht if we wlk round the tree strting down the left rnch of the root with our left hnd lwys touching the tree, then the order in which we first visit ech nonterminl corresponds to the order in which the nonterminls re replced in LMD. This is true for ny derivtion in ny CFG Theorem 27 Any word tht cn e generted y given CFG y some derivtion lso hs LMD. Other References: 16

17 Chpter 14 Pushdown Automt Introduction Previously, we sw connection etween Regulr lnguges nd Finite utomt We sw tht certin lnguges generted y CFG s could not e ccepted y FA s. Pushdown Automt Now we will introduce new kind of mchine: pushdown utomton (PDA). Will see connection etween context-free lnguges nd pushdown utomt Pushdown utomt nd FA s shre some fetures, ut PDA cn hve one extr key feture: STACK. (infinitely long INPUT TAPE on which input is written.) INPUT TAPE is divided into cells, nd ech cell holds one input letter or lnk Δ. A Once lnk Δ is encountered on INPUT TAPE, ll of the following cells lso contin Δ. Red TAPE one cell t time, from left to right. Cnnot go ck. START, ACCEPT, nd REJECT sttes. 17

18 Once enter either ACCEPT or REJECT stte, cnnot ever leve. READ stte to red input letter from INPUT TAPE. Also, hve n infinitely tll PUSHDOWN STACK, which hs Lst-In-First-Out (LIFO) discipline. Alwys strt with STACK empty. STACK cn hold letters of STACK lphet (which cn e sme s input lphet) nd lnks. PUSH nd POP sttes lter contents of STACK. PUSH dds something to the top of the STACK. POP tkes off the thing on the top of the STACK. A B B.. Exmple: Convert FA to PDA - + Figure 2: An FA which is converted to PDA in Figure 3 18

19 Strt Red Red Red Accept Reject Reject Figure 3: A PDA 19

20 A pushdown utomton for { n n : where n >= 0 } is given elow in Figure 4. Plese note tht X is used stck symol; tht is, when n is red from input X is pushed into the stck nd when is red from the input X is poped out of the stck. On the other hnd, could lso hve een used s stck symol. Figure 4. A Pushdown Automton 20

21 Determinism nd Nondeterminism Definition: A PDA is deterministic if ech input string cn only e processed y the mchine in one wy. Definition: A PDA is nondeterministic if there is some string tht cn e processed y the mchine in more thn one wy. A nondeterministic PDA my hve more thn one edge with the sme lel leding out of certin READ stte or POP stte. my hve more thn one rc leving the START stte. Both deterministic nd nondeterministic PDAs my hve no edge with certin lel leding out of certin READ stte or POP stte. if we re in READ or POP stte nd encounter letter for which there is no outedge from this stte, the PDA crshes. Remrks: For FA s, nondeterminism does not increse power of mchines. For PDA s, nondeterminism does increse power of mchines. Exmple: Lnguge PALINDROMEX, which consists of ll words of the form sxreverse(s) where s is ny string generted y ( + )_. PALINDROMEX = {X, X, X, X, X, X, X,...} Ech word in PALINDROMEX hs odd length nd X in middle. When processing word on PDA, first red letters from TAPE nd PUSH letters onto STACK until red in X. Then POP letters off STACK, nd check if they re the sme s rest of input string on TAPE. PDA: Input lphet E = {,,X} Stck lphet L = {, } 21

22 Strt Push Red 1 X Red 2 POP1 Push POP2 Accept POP3 Forml Definition of PDA Definition: A pushdown utomton (PDA) is collection of eight things: An lphet of input letters. An input TAPE (infinite in one direction), which initilly contins the input string to e processed followed y n infinite numer of lnks An lphet E of STACK chrcters. A pushdown STACK (infinite in one direction), which initilly contins ll lnks. One START stte tht hs only out-edges, no in-edges. Cn hve more thn one rc leving the START stte. There re no lels on rcs leving the START stte. Hlt sttes of two kinds: 1. zero or more ACCEPT sttes 2. zero or more REJECT sttes Ech of the Hlt sttes hve in-edges ut no out-edges. Finitely mny nonrnching PUSH sttes tht introduce chrcters from E onto the top of the STACK. Finitely mny rnching sttes of two kinds: 1. READ sttes, which red the next unused letter from TAPE nd my hve out-edges leled with letters from or lnk. (There is no 22

23 restriction on dupliction of lels nd no requirement tht there e lel for ech letter of, or.) 2. POP sttes, which red the top chrcter of STACK nd my hve outedges leled with letters of E nd the lnk chrcter, with no restrictions. Remrks: The definition for PDA llows for nondeterminism. If we wnt to consider PDA tht does not hve nondeterminism, then we will cll it deterministic PDA. Deterministic PDA (DPDA) ccept only suset of CF lnguges. Tht is, PDA nd DPDA re not equivlent. Other References:

Closure Properties of Regular Languages

Closure Properties of Regular Languages Closure Properties of Regulr Lnguges Regulr lnguges re closed under mny set opertions. Let L 1 nd L 2 e regulr lnguges. (1) L 1 L 2 (the union) is regulr. (2) L 1 L 2 (the conctention) is regulr. (3) L

More information

1.4 Nonregular Languages

1.4 Nonregular Languages 74 1.4 Nonregulr Lnguges The number of forml lnguges over ny lphbet (= decision/recognition problems) is uncountble On the other hnd, the number of regulr expressions (= strings) is countble Hence, ll

More information

Regular expressions, Finite Automata, transition graphs are all the same!!

Regular expressions, Finite Automata, transition graphs are all the same!! CSI 3104 /Winter 2011: Introduction to Forml Lnguges Chpter 7: Kleene s Theorem Chpter 7: Kleene s Theorem Regulr expressions, Finite Automt, trnsition grphs re ll the sme!! Dr. Neji Zgui CSI3104-W11 1

More information

Formal languages, automata, and theory of computation

Formal languages, automata, and theory of computation Mälrdlen University TEN1 DVA337 2015 School of Innovtion, Design nd Engineering Forml lnguges, utomt, nd theory of computtion Thursdy, Novemer 5, 14:10-18:30 Techer: Dniel Hedin, phone 021-107052 The exm

More information

Assignment 1 Automata, Languages, and Computability. 1 Finite State Automata and Regular Languages

Assignment 1 Automata, Languages, and Computability. 1 Finite State Automata and Regular Languages Deprtment of Computer Science, Austrlin Ntionl University COMP2600 Forml Methods for Softwre Engineering Semester 2, 206 Assignment Automt, Lnguges, nd Computility Smple Solutions Finite Stte Automt nd

More information

First Midterm Examination

First Midterm Examination Çnky University Deprtment of Computer Engineering 203-204 Fll Semester First Midterm Exmintion ) Design DFA for ll strings over the lphet Σ = {,, c} in which there is no, no nd no cc. 2) Wht lnguge does

More information

Chapter Five: Nondeterministic Finite Automata. Formal Language, chapter 5, slide 1

Chapter Five: Nondeterministic Finite Automata. Formal Language, chapter 5, slide 1 Chpter Five: Nondeterministic Finite Automt Forml Lnguge, chpter 5, slide 1 1 A DFA hs exctly one trnsition from every stte on every symol in the lphet. By relxing this requirement we get relted ut more

More information

1 Nondeterministic Finite Automata

1 Nondeterministic Finite Automata 1 Nondeterministic Finite Automt Suppose in life, whenever you hd choice, you could try oth possiilities nd live your life. At the end, you would go ck nd choose the one tht worked out the est. Then you

More information

Talen en Automaten Test 1, Mon 7 th Dec, h45 17h30

Talen en Automaten Test 1, Mon 7 th Dec, h45 17h30 Tlen en Automten Test 1, Mon 7 th Dec, 2015 15h45 17h30 This test consists of four exercises over 5 pges. Explin your pproch, nd write your nswer to ech exercise on seprte pge. You cn score mximum of 100

More information

AUTOMATA AND LANGUAGES. Definition 1.5: Finite Automaton

AUTOMATA AND LANGUAGES. Definition 1.5: Finite Automaton 25. Finite Automt AUTOMATA AND LANGUAGES A system of computtion tht only hs finite numer of possile sttes cn e modeled using finite utomton A finite utomton is often illustrted s stte digrm d d d. d q

More information

CS 275 Automata and Formal Language Theory

CS 275 Automata and Formal Language Theory CS 275 utomt nd Forml Lnguge Theory Course Notes Prt II: The Recognition Prolem (II) Chpter II.5.: Properties of Context Free Grmmrs (14) nton Setzer (Bsed on ook drft y J. V. Tucker nd K. Stephenson)

More information

I. Theory of Automata II. Theory of Formal Languages III. Theory of Turing Machines

I. Theory of Automata II. Theory of Formal Languages III. Theory of Turing Machines CI 3104 /Winter 2011: Introduction to Forml Lnguges Chter 13: Grmmticl Formt Chter 13: Grmmticl Formt I. Theory of Automt II. Theory of Forml Lnguges III. Theory of Turing Mchines Dr. Neji Zgui CI3104-W11

More information

Parse trees, ambiguity, and Chomsky normal form

Parse trees, ambiguity, and Chomsky normal form Prse trees, miguity, nd Chomsky norml form In this lecture we will discuss few importnt notions connected with contextfree grmmrs, including prse trees, miguity, nd specil form for context-free grmmrs

More information

Thoery of Automata CS402

Thoery of Automata CS402 Thoery of Automt C402 Theory of Automt Tle of contents: Lecture N0. 1... 4 ummry... 4 Wht does utomt men?... 4 Introduction to lnguges... 4 Alphets... 4 trings... 4 Defining Lnguges... 5 Lecture N0. 2...

More information

CS375: Logic and Theory of Computing

CS375: Logic and Theory of Computing CS375: Logic nd Theory of Computing Fuhu (Frnk) Cheng Deprtment of Computer Science University of Kentucky 1 Tle of Contents: Week 1: Preliminries (set lger, reltions, functions) (red Chpters 1-4) Weeks

More information

Harvard University Computer Science 121 Midterm October 23, 2012

Harvard University Computer Science 121 Midterm October 23, 2012 Hrvrd University Computer Science 121 Midterm Octoer 23, 2012 This is closed-ook exmintion. You my use ny result from lecture, Sipser, prolem sets, or section, s long s you quote it clerly. The lphet is

More information

CSCI 340: Computational Models. Kleene s Theorem. Department of Computer Science

CSCI 340: Computational Models. Kleene s Theorem. Department of Computer Science CSCI 340: Computtionl Models Kleene s Theorem Chpter 7 Deprtment of Computer Science Unifiction In 1954, Kleene presented (nd proved) theorem which (in our version) sttes tht if lnguge cn e defined y ny

More information

Table of contents: Lecture N Summary... 3 What does automata mean?... 3 Introduction to languages... 3 Alphabets... 3 Strings...

Table of contents: Lecture N Summary... 3 What does automata mean?... 3 Introduction to languages... 3 Alphabets... 3 Strings... Tle of contents: Lecture N0.... 3 ummry... 3 Wht does utomt men?... 3 Introduction to lnguges... 3 Alphets... 3 trings... 3 Defining Lnguges... 4 Lecture N0. 2... 7 ummry... 7 Kleene tr Closure... 7 Recursive

More information

CMPSCI 250: Introduction to Computation. Lecture #31: What DFA s Can and Can t Do David Mix Barrington 9 April 2014

CMPSCI 250: Introduction to Computation. Lecture #31: What DFA s Can and Can t Do David Mix Barrington 9 April 2014 CMPSCI 250: Introduction to Computtion Lecture #31: Wht DFA s Cn nd Cn t Do Dvid Mix Brrington 9 April 2014 Wht DFA s Cn nd Cn t Do Deterministic Finite Automt Forml Definition of DFA s Exmples of DFA

More information

Designing finite automata II

Designing finite automata II Designing finite utomt II Prolem: Design DFA A such tht L(A) consists of ll strings of nd which re of length 3n, for n = 0, 1, 2, (1) Determine wht to rememer out the input string Assign stte to ech of

More information

The University of Nottingham SCHOOL OF COMPUTER SCIENCE A LEVEL 2 MODULE, SPRING SEMESTER LANGUAGES AND COMPUTATION ANSWERS

The University of Nottingham SCHOOL OF COMPUTER SCIENCE A LEVEL 2 MODULE, SPRING SEMESTER LANGUAGES AND COMPUTATION ANSWERS The University of Nottinghm SCHOOL OF COMPUTER SCIENCE LEVEL 2 MODULE, SPRING SEMESTER 2016 2017 LNGUGES ND COMPUTTION NSWERS Time llowed TWO hours Cndidtes my complete the front cover of their nswer ook

More information

Grammar. Languages. Content 5/10/16. Automata and Languages. Regular Languages. Regular Languages

Grammar. Languages. Content 5/10/16. Automata and Languages. Regular Languages. Regular Languages 5//6 Grmmr Automt nd Lnguges Regulr Grmmr Context-free Grmmr Context-sensitive Grmmr Prof. Mohmed Hmd Softwre Engineering L. The University of Aizu Jpn Regulr Lnguges Context Free Lnguges Context Sensitive

More information

Nondeterminism and Nodeterministic Automata

Nondeterminism and Nodeterministic Automata Nondeterminism nd Nodeterministic Automt 61 Nondeterminism nd Nondeterministic Automt The computtionl mchine models tht we lerned in the clss re deterministic in the sense tht the next move is uniquely

More information

CS103B Handout 18 Winter 2007 February 28, 2007 Finite Automata

CS103B Handout 18 Winter 2007 February 28, 2007 Finite Automata CS103B ndout 18 Winter 2007 Ferury 28, 2007 Finite Automt Initil text y Mggie Johnson. Introduction Severl childrens gmes fit the following description: Pieces re set up on plying ord; dice re thrown or

More information

Exercises Chapter 1. Exercise 1.1. Let Σ be an alphabet. Prove wv = w + v for all strings w and v.

Exercises Chapter 1. Exercise 1.1. Let Σ be an alphabet. Prove wv = w + v for all strings w and v. 1 Exercises Chpter 1 Exercise 1.1. Let Σ e n lphet. Prove wv = w + v for ll strings w nd v. Prove # (wv) = # (w)+# (v) for every symol Σ nd every string w,v Σ. Exercise 1.2. Let w 1,w 2,...,w k e k strings,

More information

Homework 3 Solutions

Homework 3 Solutions CS 341: Foundtions of Computer Science II Prof. Mrvin Nkym Homework 3 Solutions 1. Give NFAs with the specified numer of sttes recognizing ech of the following lnguges. In ll cses, the lphet is Σ = {,1}.

More information

Convert the NFA into DFA

Convert the NFA into DFA Convert the NF into F For ech NF we cn find F ccepting the sme lnguge. The numer of sttes of the F could e exponentil in the numer of sttes of the NF, ut in prctice this worst cse occurs rrely. lgorithm:

More information

FABER Formal Languages, Automata and Models of Computation

FABER Formal Languages, Automata and Models of Computation DVA337 FABER Forml Lnguges, Automt nd Models of Computtion Lecture 5 chool of Innovtion, Design nd Engineering Mälrdlen University 2015 1 Recp of lecture 4 y definition suset construction DFA NFA stte

More information

Chapter 2 Finite Automata

Chapter 2 Finite Automata Chpter 2 Finite Automt 28 2.1 Introduction Finite utomt: first model of the notion of effective procedure. (They lso hve mny other pplictions). The concept of finite utomton cn e derived y exmining wht

More information

Formal Languages and Automata Theory. D. Goswami and K. V. Krishna

Formal Languages and Automata Theory. D. Goswami and K. V. Krishna Forml Lnguges nd Automt Theory D. Goswmi nd K. V. Krishn Novemer 5, 2010 Contents 1 Mthemticl Preliminries 3 2 Forml Lnguges 4 2.1 Strings............................... 5 2.2 Lnguges.............................

More information

5. (±±) Λ = fw j w is string of even lengthg [ 00 = f11,00g 7. (11 [ 00)± Λ = fw j w egins with either 11 or 00g 8. (0 [ ffl)1 Λ = 01 Λ [ 1 Λ 9.

5. (±±) Λ = fw j w is string of even lengthg [ 00 = f11,00g 7. (11 [ 00)± Λ = fw j w egins with either 11 or 00g 8. (0 [ ffl)1 Λ = 01 Λ [ 1 Λ 9. Regulr Expressions, Pumping Lemm, Right Liner Grmmrs Ling 106 Mrch 25, 2002 1 Regulr Expressions A regulr expression descries or genertes lnguge: it is kind of shorthnd for listing the memers of lnguge.

More information

Normal Forms for Context-free Grammars

Normal Forms for Context-free Grammars Norml Forms for Context-free Grmmrs 1 Linz 6th, Section 6.2 wo Importnt Norml Forms, pges 171--178 2 Chomsky Norml Form All productions hve form: A BC nd A vrile vrile terminl 3 Exmples: S AS S AS S S

More information

Minimal DFA. minimal DFA for L starting from any other

Minimal DFA. minimal DFA for L starting from any other Miniml DFA Among the mny DFAs ccepting the sme regulr lnguge L, there is exctly one (up to renming of sttes) which hs the smllest possile numer of sttes. Moreover, it is possile to otin tht miniml DFA

More information

First Midterm Examination

First Midterm Examination 24-25 Fll Semester First Midterm Exmintion ) Give the stte digrm of DFA tht recognizes the lnguge A over lphet Σ = {, } where A = {w w contins or } 2) The following DFA recognizes the lnguge B over lphet

More information

5.1 Definitions and Examples 5.2 Deterministic Pushdown Automata

5.1 Definitions and Examples 5.2 Deterministic Pushdown Automata CSC4510 AUTOMATA 5.1 Definitions nd Exmples 5.2 Deterministic Pushdown Automt Definitions nd Exmples A lnguge cn be generted by CFG if nd only if it cn be ccepted by pushdown utomton. A pushdown utomton

More information

CMSC 330: Organization of Programming Languages

CMSC 330: Organization of Programming Languages CMSC 330: Orgniztion of Progrmming Lnguges Finite Automt 2 CMSC 330 1 Types of Finite Automt Deterministic Finite Automt (DFA) Exctly one sequence of steps for ech string All exmples so fr Nondeterministic

More information

1.3 Regular Expressions

1.3 Regular Expressions 56 1.3 Regulr xpressions These hve n importnt role in describing ptterns in serching for strings in mny pplictions (e.g. wk, grep, Perl,...) All regulr expressions of lphbet re 1.Ønd re regulr expressions,

More information

CS 275 Automata and Formal Language Theory

CS 275 Automata and Formal Language Theory CS 275 Automt nd Forml Lnguge Theory Course Notes Prt II: The Recognition Problem (II) Chpter II.5.: Properties of Context Free Grmmrs (14) Anton Setzer (Bsed on book drft by J. V. Tucker nd K. Stephenson)

More information

Let's start with an example:

Let's start with an example: Finite Automt Let's strt with n exmple: Here you see leled circles tht re sttes, nd leled rrows tht re trnsitions. One of the sttes is mrked "strt". One of the sttes hs doule circle; this is terminl stte

More information

Finite Automata-cont d

Finite Automata-cont d Automt Theory nd Forml Lnguges Professor Leslie Lnder Lecture # 6 Finite Automt-cont d The Pumping Lemm WEB SITE: http://ingwe.inghmton.edu/ ~lnder/cs573.html Septemer 18, 2000 Exmple 1 Consider L = {ww

More information

CHAPTER 1 Regular Languages. Contents

CHAPTER 1 Regular Languages. Contents Finite Automt (FA or DFA) CHAPTE 1 egulr Lnguges Contents definitions, exmples, designing, regulr opertions Non-deterministic Finite Automt (NFA) definitions, euivlence of NFAs nd DFAs, closure under regulr

More information

Tutorial Automata and formal Languages

Tutorial Automata and formal Languages Tutoril Automt nd forml Lnguges Notes for to the tutoril in the summer term 2017 Sestin Küpper, Christine Mik 8. August 2017 1 Introduction: Nottions nd sic Definitions At the eginning of the tutoril we

More information

Types of Finite Automata. CMSC 330: Organization of Programming Languages. Comparing DFAs and NFAs. NFA for (a b)*abb.

Types of Finite Automata. CMSC 330: Organization of Programming Languages. Comparing DFAs and NFAs. NFA for (a b)*abb. CMSC 330: Orgniztion of Progrmming Lnguges Finite Automt 2 Types of Finite Automt Deterministic Finite Automt () Exctly one sequence of steps for ech string All exmples so fr Nondeterministic Finite Automt

More information

Overview HC9. Parsing: Top-Down & LL(1) Context-Free Grammars (1) Introduction. CFGs (3) Context-Free Grammars (2) Vertalerbouw HC 9: Ch.

Overview HC9. Parsing: Top-Down & LL(1) Context-Free Grammars (1) Introduction. CFGs (3) Context-Free Grammars (2) Vertalerbouw HC 9: Ch. Overview H9 Vertlerouw H 9: Prsing: op-down & LL(1) do 3 mei 2001 56 heo Ruys h. 8 - Prsing 8.1 ontext-free Grmmrs 8.2 op-down Prsing 8.3 LL(1) Grmmrs See lso [ho, Sethi & Ullmn 1986] for more thorough

More information

CSCI 340: Computational Models. Transition Graphs. Department of Computer Science

CSCI 340: Computational Models. Transition Graphs. Department of Computer Science CSCI 340: Computtionl Models Trnsition Grphs Chpter 6 Deprtment of Computer Science Relxing Restrints on Inputs We cn uild n FA tht ccepts only the word! 5 sttes ecuse n FA cn only process one letter t

More information

Formal Languages and Automata

Formal Languages and Automata Moile Computing nd Softwre Engineering p. 1/5 Forml Lnguges nd Automt Chpter 2 Finite Automt Chun-Ming Liu cmliu@csie.ntut.edu.tw Deprtment of Computer Science nd Informtion Engineering Ntionl Tipei University

More information

CHAPTER 1 Regular Languages. Contents. definitions, examples, designing, regular operations. Non-deterministic Finite Automata (NFA)

CHAPTER 1 Regular Languages. Contents. definitions, examples, designing, regular operations. Non-deterministic Finite Automata (NFA) Finite Automt (FA or DFA) CHAPTER Regulr Lnguges Contents definitions, exmples, designing, regulr opertions Non-deterministic Finite Automt (NFA) definitions, equivlence of NFAs DFAs, closure under regulr

More information

NFAs and Regular Expressions. NFA-ε, continued. Recall. Last class: Today: Fun:

NFAs and Regular Expressions. NFA-ε, continued. Recall. Last class: Today: Fun: CMPU 240 Lnguge Theory nd Computtion Spring 2019 NFAs nd Regulr Expressions Lst clss: Introduced nondeterministic finite utomt with -trnsitions Tody: Prove n NFA- is no more powerful thn n NFA Introduce

More information

Types of Finite Automata. CMSC 330: Organization of Programming Languages. Comparing DFAs and NFAs. Comparing DFAs and NFAs (cont.) Finite Automata 2

Types of Finite Automata. CMSC 330: Organization of Programming Languages. Comparing DFAs and NFAs. Comparing DFAs and NFAs (cont.) Finite Automata 2 CMSC 330: Orgniztion of Progrmming Lnguges Finite Automt 2 Types of Finite Automt Deterministic Finite Automt () Exctly one sequence of steps for ech string All exmples so fr Nondeterministic Finite Automt

More information

CS 310 (sec 20) - Winter Final Exam (solutions) SOLUTIONS

CS 310 (sec 20) - Winter Final Exam (solutions) SOLUTIONS CS 310 (sec 20) - Winter 2003 - Finl Exm (solutions) SOLUTIONS 1. (Logic) Use truth tles to prove the following logicl equivlences: () p q (p p) (q q) () p q (p q) (p q) () p q p q p p q q (q q) (p p)

More information

Finite Automata. Informatics 2A: Lecture 3. Mary Cryan. 21 September School of Informatics University of Edinburgh

Finite Automata. Informatics 2A: Lecture 3. Mary Cryan. 21 September School of Informatics University of Edinburgh Finite Automt Informtics 2A: Lecture 3 Mry Cryn School of Informtics University of Edinburgh mcryn@inf.ed.c.uk 21 September 2018 1 / 30 Lnguges nd Automt Wht is lnguge? Finite utomt: recp Some forml definitions

More information

CS 330 Formal Methods and Models Dana Richards, George Mason University, Spring 2016 Quiz Solutions

CS 330 Formal Methods and Models Dana Richards, George Mason University, Spring 2016 Quiz Solutions CS 330 Forml Methods nd Models Dn Richrds, George Mson University, Spring 2016 Quiz Solutions Quiz 1, Propositionl Logic Dte: Ferury 9 1. (4pts) ((p q) (q r)) (p r), prove tutology using truth tles. p

More information

Lecture 08: Feb. 08, 2019

Lecture 08: Feb. 08, 2019 4CS4-6:Theory of Computtion(Closure on Reg. Lngs., regex to NDFA, DFA to regex) Prof. K.R. Chowdhry Lecture 08: Fe. 08, 2019 : Professor of CS Disclimer: These notes hve not een sujected to the usul scrutiny

More information

CS 275 Automata and Formal Language Theory

CS 275 Automata and Formal Language Theory CS 275 Automt nd Forml Lnguge Theory Course Notes Prt II: The Recognition Problem (II) Chpter II.6.: Push Down Automt Remrk: This mteril is no longer tught nd not directly exm relevnt Anton Setzer (Bsed

More information

Intermediate Math Circles Wednesday, November 14, 2018 Finite Automata II. Nickolas Rollick a b b. a b 4

Intermediate Math Circles Wednesday, November 14, 2018 Finite Automata II. Nickolas Rollick a b b. a b 4 Intermedite Mth Circles Wednesdy, Novemer 14, 2018 Finite Automt II Nickols Rollick nrollick@uwterloo.c Regulr Lnguges Lst time, we were introduced to the ide of DFA (deterministic finite utomton), one

More information

1. For each of the following theorems, give a two or three sentence sketch of how the proof goes or why it is not true.

1. For each of the following theorems, give a two or three sentence sketch of how the proof goes or why it is not true. York University CSE 2 Unit 3. DFA Clsses Converting etween DFA, NFA, Regulr Expressions, nd Extended Regulr Expressions Instructor: Jeff Edmonds Don t chet y looking t these nswers premturely.. For ech

More information

CS 330 Formal Methods and Models

CS 330 Formal Methods and Models CS 330 Forml Methods nd Models Dn Richrds, George Mson University, Spring 2017 Quiz Solutions Quiz 1, Propositionl Logic Dte: Ferury 2 1. Prove ((( p q) q) p) is tutology () (3pts) y truth tle. p q p q

More information

Chapter 7. Kleene s Theorem. 7.1 Kleene s Theorem. The following theorem is the most important and fundamental result in the theory of FA s:

Chapter 7. Kleene s Theorem. 7.1 Kleene s Theorem. The following theorem is the most important and fundamental result in the theory of FA s: Chpte 7 Kleene s Theoem 7.1 Kleene s Theoem The following theoem is the most impotnt nd fundmentl esult in the theoy of FA s: Theoem 6 Any lnguge tht cn e defined y eithe egul expession, o finite utomt,

More information

Converting Regular Expressions to Discrete Finite Automata: A Tutorial

Converting Regular Expressions to Discrete Finite Automata: A Tutorial Converting Regulr Expressions to Discrete Finite Automt: A Tutoril Dvid Christinsen 2013-01-03 This is tutoril on how to convert regulr expressions to nondeterministic finite utomt (NFA) nd how to convert

More information

CSE : Exam 3-ANSWERS, Spring 2011 Time: 50 minutes

CSE : Exam 3-ANSWERS, Spring 2011 Time: 50 minutes CSE 260-002: Exm 3-ANSWERS, Spring 20 ime: 50 minutes Nme: his exm hs 4 pges nd 0 prolems totling 00 points. his exm is closed ook nd closed notes.. Wrshll s lgorithm for trnsitive closure computtion is

More information

Coalgebra, Lecture 15: Equations for Deterministic Automata

Coalgebra, Lecture 15: Equations for Deterministic Automata Colger, Lecture 15: Equtions for Deterministic Automt Julin Slmnc (nd Jurrin Rot) Decemer 19, 2016 In this lecture, we will study the concept of equtions for deterministic utomt. The notes re self contined

More information

Finite Automata. Informatics 2A: Lecture 3. John Longley. 22 September School of Informatics University of Edinburgh

Finite Automata. Informatics 2A: Lecture 3. John Longley. 22 September School of Informatics University of Edinburgh Lnguges nd Automt Finite Automt Informtics 2A: Lecture 3 John Longley School of Informtics University of Edinburgh jrl@inf.ed.c.uk 22 September 2017 1 / 30 Lnguges nd Automt 1 Lnguges nd Automt Wht is

More information

3 Regular expressions

3 Regular expressions 3 Regulr expressions Given n lphet Σ lnguge is set of words L Σ. So fr we were le to descrie lnguges either y using set theory (i.e. enumertion or comprehension) or y n utomton. In this section we shll

More information

Chapter 4 Regular Grammar and Regular Sets. (Solutions / Hints)

Chapter 4 Regular Grammar and Regular Sets. (Solutions / Hints) C K Ngpl Forml Lnguges nd utomt Theory Chpter 4 Regulr Grmmr nd Regulr ets (olutions / Hints) ol. (),,,,,,,,,,,,,,,,,,,,,,,,,, (),, (c) c c, c c, c, c, c c, c, c, c, c, c, c, c c,c, c, c, c, c, c, c, c,

More information

PART 2. REGULAR LANGUAGES, GRAMMARS AND AUTOMATA

PART 2. REGULAR LANGUAGES, GRAMMARS AND AUTOMATA PART 2. REGULAR LANGUAGES, GRAMMARS AND AUTOMATA RIGHT LINEAR LANGUAGES. Right Liner Grmmr: Rules of the form: A α B, A α A,B V N, α V T + Left Liner Grmmr: Rules of the form: A Bα, A α A,B V N, α V T

More information

CS 373, Spring Solutions to Mock midterm 1 (Based on first midterm in CS 273, Fall 2008.)

CS 373, Spring Solutions to Mock midterm 1 (Based on first midterm in CS 273, Fall 2008.) CS 373, Spring 29. Solutions to Mock midterm (sed on first midterm in CS 273, Fll 28.) Prolem : Short nswer (8 points) The nswers to these prolems should e short nd not complicted. () If n NF M ccepts

More information

SWEN 224 Formal Foundations of Programming WITH ANSWERS

SWEN 224 Formal Foundations of Programming WITH ANSWERS T E W H A R E W Ā N A N G A O T E Ū P O K O O T E I K A A M Ā U I VUW V I C T O R I A UNIVERSITY OF WELLINGTON Time Allowed: 3 Hours EXAMINATIONS 2011 END-OF-YEAR SWEN 224 Forml Foundtions of Progrmming

More information

CS 330 Formal Methods and Models

CS 330 Formal Methods and Models CS 0 Forml Methods nd Models Dn Richrds, George Mson University, Fll 2016 Quiz Solutions Quiz 1, Propositionl Logic Dte: Septemer 8 1. Prove q (q p) p q p () (4pts) with truth tle. p q p q p (q p) p q

More information

CISC 4090 Theory of Computation

CISC 4090 Theory of Computation 9/6/28 Stereotypicl computer CISC 49 Theory of Computtion Finite stte mchines & Regulr lnguges Professor Dniel Leeds dleeds@fordhm.edu JMH 332 Centrl processing unit (CPU) performs ll the instructions

More information

Some Theory of Computation Exercises Week 1

Some Theory of Computation Exercises Week 1 Some Theory of Computtion Exercises Week 1 Section 1 Deterministic Finite Automt Question 1.3 d d d d u q 1 q 2 q 3 q 4 q 5 d u u u u Question 1.4 Prt c - {w w hs even s nd one or two s} First we sk whether

More information

Regular Expressions (RE) Regular Expressions (RE) Regular Expressions (RE) Regular Expressions (RE) Kleene-*

Regular Expressions (RE) Regular Expressions (RE) Regular Expressions (RE) Regular Expressions (RE) Kleene-* Regulr Expressions (RE) Regulr Expressions (RE) Empty set F A RE denotes the empty set Opertion Nottion Lnguge UNIX Empty string A RE denotes the set {} Alterntion R +r L(r ) L(r ) r r Symol Alterntion

More information

Non Deterministic Automata. Linz: Nondeterministic Finite Accepters, page 51

Non Deterministic Automata. Linz: Nondeterministic Finite Accepters, page 51 Non Deterministic Automt Linz: Nondeterministic Finite Accepters, pge 51 1 Nondeterministic Finite Accepter (NFA) Alphbet ={} q 1 q2 q 0 q 3 2 Nondeterministic Finite Accepter (NFA) Alphbet ={} Two choices

More information

CSC 311 Theory of Computation

CSC 311 Theory of Computation CSC 11 Theory of Computtion Tutoril on DFAs, NFAs, regulr expressions, regulr grmmr, closure of regulr lnguges, context-free grmmrs, non-deterministic push-down utomt, Turing mchines,etc. Tutoril 2 Second

More information

I. Theory of Automata II. Theory of Formal Languages III. Theory of Turing Machines

I. Theory of Automata II. Theory of Formal Languages III. Theory of Turing Machines CI 3104 /Winter 2011: Introduction to Forml Lnguges Chpter 16: Non-Context-Free Lnguges Chpter 16: Non-Context-Free Lnguges I. Theory of utomt II. Theory of Forml Lnguges III. Theory of Turing Mchines

More information

Automata Theory 101. Introduction. Outline. Introduction Finite Automata Regular Expressions ω-automata. Ralf Huuck.

Automata Theory 101. Introduction. Outline. Introduction Finite Automata Regular Expressions ω-automata. Ralf Huuck. Outline Automt Theory 101 Rlf Huuck Introduction Finite Automt Regulr Expressions ω-automt Session 1 2006 Rlf Huuck 1 Session 1 2006 Rlf Huuck 2 Acknowledgement Some slides re sed on Wolfgng Thoms excellent

More information

Non-Deterministic Finite Automata. Fall 2018 Costas Busch - RPI 1

Non-Deterministic Finite Automata. Fall 2018 Costas Busch - RPI 1 Non-Deterministic Finite Automt Fll 2018 Costs Busch - RPI 1 Nondeterministic Finite Automton (NFA) Alphbet ={} q q2 1 q 0 q 3 Fll 2018 Costs Busch - RPI 2 Nondeterministic Finite Automton (NFA) Alphbet

More information

Finite-State Automata: Recap

Finite-State Automata: Recap Finite-Stte Automt: Recp Deepk D Souz Deprtment of Computer Science nd Automtion Indin Institute of Science, Bnglore. 09 August 2016 Outline 1 Introduction 2 Forml Definitions nd Nottion 3 Closure under

More information

CS415 Compilers. Lexical Analysis and. These slides are based on slides copyrighted by Keith Cooper, Ken Kennedy & Linda Torczon at Rice University

CS415 Compilers. Lexical Analysis and. These slides are based on slides copyrighted by Keith Cooper, Ken Kennedy & Linda Torczon at Rice University CS415 Compilers Lexicl Anlysis nd These slides re sed on slides copyrighted y Keith Cooper, Ken Kennedy & Lind Torczon t Rice University First Progrmming Project Instruction Scheduling Project hs een posted

More information

CS 301. Lecture 04 Regular Expressions. Stephen Checkoway. January 29, 2018

CS 301. Lecture 04 Regular Expressions. Stephen Checkoway. January 29, 2018 CS 301 Lecture 04 Regulr Expressions Stephen Checkowy Jnury 29, 2018 1 / 35 Review from lst time NFA N = (Q, Σ, δ, q 0, F ) where δ Q Σ P (Q) mps stte nd n lphet symol (or ) to set of sttes We run n NFA

More information

Worked out examples Finite Automata

Worked out examples Finite Automata Worked out exmples Finite Automt Exmple Design Finite Stte Automton which reds inry string nd ccepts only those tht end with. Since we re in the topic of Non Deterministic Finite Automt (NFA), we will

More information

Java II Finite Automata I

Java II Finite Automata I Jv II Finite Automt I Bernd Kiefer Bernd.Kiefer@dfki.de Deutsches Forschungszentrum für künstliche Intelligenz Finite Automt I p.1/13 Processing Regulr Expressions We lredy lerned out Jv s regulr expression

More information

Non-deterministic Finite Automata

Non-deterministic Finite Automata Non-deterministic Finite Automt Eliminting non-determinism Rdoud University Nijmegen Non-deterministic Finite Automt H. Geuvers nd T. vn Lrhoven Institute for Computing nd Informtion Sciences Intelligent

More information

Compiler Design. Fall Lexical Analysis. Sample Exercises and Solutions. Prof. Pedro C. Diniz

Compiler Design. Fall Lexical Analysis. Sample Exercises and Solutions. Prof. Pedro C. Diniz University of Southern Cliforni Computer Science Deprtment Compiler Design Fll Lexicl Anlysis Smple Exercises nd Solutions Prof. Pedro C. Diniz USC / Informtion Sciences Institute 4676 Admirlty Wy, Suite

More information

Lexical Analysis Finite Automate

Lexical Analysis Finite Automate Lexicl Anlysis Finite Automte CMPSC 470 Lecture 04 Topics: Deterministic Finite Automt (DFA) Nondeterministic Finite Automt (NFA) Regulr Expression NFA DFA A. Finite Automt (FA) FA re grph, like trnsition

More information

Speech Recognition Lecture 2: Finite Automata and Finite-State Transducers

Speech Recognition Lecture 2: Finite Automata and Finite-State Transducers Speech Recognition Lecture 2: Finite Automt nd Finite-Stte Trnsducers Eugene Weinstein Google, NYU Cournt Institute eugenew@cs.nyu.edu Slide Credit: Mehryr Mohri Preliminries Finite lphet, empty string.

More information

Deterministic Finite Automata

Deterministic Finite Automata Finite Automt Deterministic Finite Automt H. Geuvers nd J. Rot Institute for Computing nd Informtion Sciences Version: fll 2016 J. Rot Version: fll 2016 Tlen en Automten 1 / 21 Outline Finite Automt Finite

More information

NFA DFA Example 3 CMSC 330: Organization of Programming Languages. Equivalence of DFAs and NFAs. Equivalence of DFAs and NFAs (cont.

NFA DFA Example 3 CMSC 330: Organization of Programming Languages. Equivalence of DFAs and NFAs. Equivalence of DFAs and NFAs (cont. NFA DFA Exmple 3 CMSC 330: Orgniztion of Progrmming Lnguges NFA {B,D,E {A,E {C,D {E Finite Automt, con't. R = { {A,E, {B,D,E, {C,D, {E 2 Equivlence of DFAs nd NFAs Any string from {A to either {D or {CD

More information

Scanner. Specifying patterns. Specifying patterns. Operations on languages. A scanner must recognize the units of syntax Some parts are easy:

Scanner. Specifying patterns. Specifying patterns. Operations on languages. A scanner must recognize the units of syntax Some parts are easy: Scnner Specifying ptterns source code tokens scnner prser IR A scnner must recognize the units of syntx Some prts re esy: errors mps chrcters into tokens the sic unit of syntx x = x + y; ecomes

More information

Revision Sheet. (a) Give a regular expression for each of the following languages:

Revision Sheet. (a) Give a regular expression for each of the following languages: Theoreticl Computer Science (Bridging Course) Dr. G. D. Tipldi F. Bonirdi Winter Semester 2014/2015 Revision Sheet University of Freiurg Deprtment of Computer Science Question 1 (Finite Automt, 8 + 6 points)

More information

a,b a 1 a 2 a 3 a,b 1 a,b a,b 2 3 a,b a,b a 2 a,b CS Determinisitic Finite Automata 1

a,b a 1 a 2 a 3 a,b 1 a,b a,b 2 3 a,b a,b a 2 a,b CS Determinisitic Finite Automata 1 CS4 45- Determinisitic Finite Automt -: Genertors vs. Checkers Regulr expressions re one wy to specify forml lnguge String Genertor Genertes strings in the lnguge Deterministic Finite Automt (DFA) re nother

More information

1 From NFA to regular expression

1 From NFA to regular expression Note 1: How to convert DFA/NFA to regulr expression Version: 1.0 S/EE 374, Fll 2017 Septemer 11, 2017 In this note, we show tht ny DFA cn e converted into regulr expression. Our construction would work

More information

input tape head moves current state

input tape head moves current state CPS 140 - Mthemticl Foundtions of CS Dr. Susn Rodger Section: Finite Automt (Ch. 2) (lecture notes) Things to do in clss tody (Jn. 13, 2004): ffl questions on homework 1 ffl finish chpter 1 ffl Red Chpter

More information

80 CHAPTER 2. DFA S, NFA S, REGULAR LANGUAGES. 2.6 Finite State Automata With Output: Transducers

80 CHAPTER 2. DFA S, NFA S, REGULAR LANGUAGES. 2.6 Finite State Automata With Output: Transducers 80 CHAPTER 2. DFA S, NFA S, REGULAR LANGUAGES 2.6 Finite Stte Automt With Output: Trnsducers So fr, we hve only considered utomt tht recognize lnguges, i.e., utomt tht do not produce ny output on ny input

More information

Theory of Computation Regular Languages. (NTU EE) Regular Languages Fall / 38

Theory of Computation Regular Languages. (NTU EE) Regular Languages Fall / 38 Theory of Computtion Regulr Lnguges (NTU EE) Regulr Lnguges Fll 2017 1 / 38 Schemtic of Finite Automt control 0 0 1 0 1 1 1 0 Figure: Schemtic of Finite Automt A finite utomton hs finite set of control

More information

a b b a pop push read unread

a b b a pop push read unread A Finite Automton A Pushdown Automton 0000 000 red unred b b pop red unred push 2 An Exmple A Pushdown Automton Recll tht 0 n n not regulr. cn push symbols onto the stck cn pop them (red them bck) lter

More information

CSC 473 Automata, Grammars & Languages 11/9/10

CSC 473 Automata, Grammars & Languages 11/9/10 CSC 473 utomt, Grmmrs & Lnguges 11/9/10 utomt, Grmmrs nd Lnguges Discourse 06 Decidbility nd Undecidbility Decidble Problems for Regulr Lnguges Theorem 4.1: (embership/cceptnce Prob. for DFs) = {, w is

More information

Kleene s Theorem. Kleene s Theorem. Kleene s Theorem. Kleene s Theorem. Kleene s Theorem. Kleene s Theorem 2/16/15

Kleene s Theorem. Kleene s Theorem. Kleene s Theorem. Kleene s Theorem. Kleene s Theorem. Kleene s Theorem 2/16/15 Models of Comput:on Lecture #8 Chpter 7 con:nued Any lnguge tht e defined y regulr expression, finite utomton, or trnsi:on grph cn e defined y ll three methods We prove this y showing tht ny lnguge defined

More information

Lexical Analysis Part III

Lexical Analysis Part III Lexicl Anlysis Prt III Chpter 3: Finite Automt Slides dpted from : Roert vn Engelen, Florid Stte University Alex Aiken, Stnford University Design of Lexicl Anlyzer Genertor Trnslte regulr expressions to

More information

The transformation to right derivation is called the canonical reduction sequence. Bottom-up analysis

The transformation to right derivation is called the canonical reduction sequence. Bottom-up analysis Bottom-up nlysis Shift-reduce prsing. Constructs the derivtion tree from ottom to top. Reduces the string to the strt symol. Produces reverse right derivtion. Exmple: G(E): 1. E E + T 2. T 3. T T * F 4.

More information

The University of Nottingham SCHOOL OF COMPUTER SCIENCE A LEVEL 2 MODULE, SPRING SEMESTER MACHINES AND THEIR LANGUAGES ANSWERS

The University of Nottingham SCHOOL OF COMPUTER SCIENCE A LEVEL 2 MODULE, SPRING SEMESTER MACHINES AND THEIR LANGUAGES ANSWERS The University of ottinghm SCHOOL OF COMPUTR SCIC A LVL 2 MODUL, SPRIG SMSTR 2015 2016 MACHIS AD THIR LAGUAGS ASWRS Time llowed TWO hours Cndidtes my omplete the front over of their nswer ook nd sign their

More information