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

Size: px
Start display at page:

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

Transcription

1 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. F 5. F id 6. ( E ) Input: id + id Reverse right derivtion (the rt of finding hndles). The hndles re underlined: id + id F + id T + id E + id E + F E + T E (strt symol ccept) The trnsfotion to right derivtion is clled the cnonicl reduction sequence. This sequence is reched y so-clled "hndle pruning" (hndle elimintion). How is this sequence rrived t? where Method: w = γ n γ n-1... γ 1 γ 0 = S w: sttement γ n, γ n-1,..., γ 1 : sententil fos γ 0 : strt symol 1. oclize the hndle β n in the sententil fo γ n. 2. Replce the hndle β n with A. (There is rule A β n ). Then we get γ n oclize the hndle β n-1 in sententil fo γ n etc. until the trget symol is reched. A shift-reduce prser finds the rules in the order: 5, 4, 2, 5, 4, 1. ecture 4 & 5 Bottom-up prsing Pge 106 ecture 4 & 5 Bottom-up prsing Pge 107 A stck is needed to implement shift-reduce prser. New symols: $ (or _!_, or ) mrks the end of the string mrks the strt (the stck is empty) Stck Input w Configurtion t the strt S Configurtion t the end The nlyser works y shifting symols on the stck (from input) to hndle (i.e., complete right side of some rule) is on the top of the stck (never inside). Then the hndle is reduced to the corresponding left side (i.e., nonteinl). Exmple: Prse id + id ccording to G(E): Step Stck Input Event Hndle Rule 1 id+id Shift 2 id +id Reduce F id 5 3 F +id Reduce T F 4 4 T +id Reduce E T 2 5 E +id Shift 6 E+ id Shift 7 E+id Reduce F id 5 8 E+F Reduce T F 4 9 E+T Reduce E E + T 1 10 E Accept Accept only if we only hve the trget symol on the stck nd there is no more input (otherwise n error hs occurred). Prolems: 1. How do we find the hndle? 2. How is reduction ccomplished when we hve severl rules which hve the sme right side? An R-prser uses lookhed. ecture 4 & 5 Bottom-up prsing Pge 108 ecture 4 & 5 Bottom-up prsing Pge 109

2 R-prser Automtic construction Chrcteristics: + An R nlyser cn nlyze lmost ll lnguges which cn e descried with CFG. + More generlly: Rewriting seldom needed, left recursion, right recursion, severl rules with the sme symols t the eginning re not prolem. + As fst s hnd-written. + Discovers the error s soon s it is possile. - The semntics cn not e introduced so esily. - Difficult to generte y hnd. R clsses R(0) SR(1) AR(1) R(1) R(k) Too wek (no lookhed) Simple R, 1 token lookhed Most common, 1 token lookhed 1 token lookhed - tles fr too ig k tokens lookhed Exmple of tle size: Pscl: AR(1) 20 pges, 2 ytes per entry. Differences: Tle size vries widely. Errors not discovered s quickly. imittions in the lnguge definition. Augmented gmr (extended gmr) Add rule which includes the trget symol <S> nd the end symol (egentligen inte, men synlig-gör slutsymolen) <SYS> <S> Exmple of prsing using the R method (See the following pges for gmr nd prse tles) Input:, Step Stck Input Tle entries 1 0, ACTION[0, ] = S4 2 04, ACTION[4,,] = R3 (E ) 0E, GOTO[0, E] = 6 3 0E6, ACTION[6,,] = R2 ( E) 0, GOTO[0, ] = , ACTION[1,,] = S2 5 01,2 ACTION[2, ] = S5 6 01,25 ACTION[5, ] = R4 (E ) 01,2E GOTO[2, E] = ,2E3 ACTION[3, ] = R1 (,E) 0 GOTO[0, ] = ACTION[1, ] = A (ccept) ecture 4 & 5 Bottom-up prsing Pge 110 ecture 4 & 5 Bottom-up prsing Pge 111 P A R S E R A C T I O N T A B E Exmple of n SR(1) gmr T E R M I N A S V O C A B U A R Y N O N T E R M I N A S 1. _!_ 5. <list> 2., 6. <element> GOA SYMBO IS: <list> P R O D U C T I O N S 1. <list> ::= <list>, <element> 2.! <element> 3. <element> ::= 4.! TOP OF STACK INPUT SYMBO -!-, STATE NAME! ! <SYS>! X X S4 S5 1 <list>! A S2 * * 2,! X X S4 S5 3 <element>! R1 R1 * * 4! R3 R3 X X 5! R4 R4 X X 6 <element>! R2 R2 * * G O T O T A B E! (Note: The GOTO tle is not the sme s the GOTO grph, which! represents oth the ACTION tle nd the GOTO tle) TOP OF STACK SYMBO <list><element> STATE NAME! ! <SYS>! <list>! * * 2,! * 3 3 <element>! * * 4! * * 5! * * 6 <element>! * *!! NB: the following revitions re used in the tles ove!! X = error!! * = impossile to end up here! ecture 4 & 5 Bottom-up prsing Pge 112 ecture 4 & 5 Bottom-up prsing Pge 113

3 Construction of prse tree (Bottom-up) Shift opertions: Crete one-node tree contining the shifted symol. Reduce opertions: When reducing hndle β to A (s in A β), crete new node A whose children re those nodes tht were creted in the hndle. During the nlysis we hve forest of su-trees. Ech entry in the stck points to its corresponding su-tree. When we ccept, the whole prse tree is completed. Exmple. Construction of prse tree. Step 2 prse stck 0 4 semntic stck Step 4 0 1, E E E E Step 3 0 E 6 E Step 5 (clened up) 0 1, 2 Step 8 0 1, E E, E ecture 4 & 5 Bottom-up prsing Pge 114 ecture 4 & 5 Bottom-up prsing Pge 115 Definition: R-gmr: A gmr for which unique R-tle cn e constructed is clled n R gmr (R(0), SR(1), AR(1), R(1),...). No miguous gmrs re R gmrs. There re unmiguous gmrs which re not R gmrs. The stte t the top of the stck contins ll the infotion we need. Definition: Vile prefix The prefixes of right sententil fo which do not contin ny symols to the right of hndle. Exmple: (See next pge for gmr nd prse tle) Input:,, 1. <list> <list>, <element> 2. <element> 3. <element> 4. Right derivtion (hndles re underlined) <list> <list>, <element> <list>, <list>, <element>, <list>,, <element>,,,, Vile prefixes of the sententil fo: <list>,, re { ε, <list>, <list>,, <list>, } ecture 4 & 5 Bottom-up prsing Pge 116 ecture 4 & 5 Bottom-up prsing Pge 117

4 A prser genertor constructs DFA which recognises ll vile prefixes. This DFA is then trnsfoed into tle fo. Automtic construction of the ACTION- nd GOTOtle: Definition: R(0) item An R(0) item of rule P is rule with dot somewhere in the right side. Exmple: All R(0) items of the production 1. <list> <list>, <element> re <list> <list>, <element> <list> <list>, <element> <list> <list>, <element> <list> <list>, <element> Intuitively n item is interpreted s how much of the rule we hve found nd how much remins. Items re put together in sets which ecome the R nlyser s stte. We wnt to construct DFA which recognises ll vile prefixes of G(<SYS>): Augmented gmr: 0. <SYS> <list> 1. <list> <list>, <element> 2. <element> 3. <element> 4. strt <list>, 0 <element> <SYS> <list> <list> <list>, <element> <element> 6 4 <element> <list> <element> 5 <element> GOTO-grph (A GOTO-grph is not the sme s GOTO-tle ut corresponds to n ACTION + GOTO-tle. The grph discovers vile prefixes.) ecture 4 & 5 Bottom-up prsing Pge 118 ecture 4 & 5 Bottom-up prsing Pge 119 Algorithm to construct GOTO-grph from the set of R(0)-items (A detiled description is given in the textook p. 221 ff) Bsed on the cnonicl collection of R(0) items drw the GOTO grph. 0 <SYS> <list> Kernel (Bsis) <list> <list>, <element> <list> <element> <element> <element> Ech set corresponds to node in the GOTO grph. When we hve found the symol ehind we move the dot over the symol. 1 <SYS> <list> <list> <list>, <element> (empty closure s precedes teinls) (shift-reduce conflict in the Kernel set!) Closure (of kernel items) Kernel Closure The GOTO grph discovers those prefixes of right sententil fos which hve (t most) one hndle furthest to the right in the prefix. GOTO grph with its R(0) items: strt I 0 S, E E E E I 1 S,, E E I 6 E I 2, E E E I 3 2 <list> <list>, <element> Kernel I 4 E <element> <element> etc., (see the finl result elow). Closure I 5 E ecture 4 & 5 Bottom-up prsing Pge 120 ecture 4 & 5 Bottom-up prsing Pge 121

5 Cnonicl collection of R(0) items for the gmr G(<SYS>) I 0 <SYS> <list> <list> <list>, <element> <list> <element> <element> <element> R ( 0 ) S E T S O F I T E M S STATENR. ITEMSET SUCCESSOR 0 <SYS> -->.<list> 1 <list> -->.<list>, <element> 1 <list> -->.<element> 6 <element> -->. 4 <element> -->. 5 1 <SYS> --> <list>. ==>0 <list> --> <list>., <element> 2 I 1 <SYS> <list> <list> <list>, <element> 2 <list> --> <list>,.<element> 3 <element> -->. 4 <element> -->. 5 I 2 <list> <list>, <element> <element> <element> I 3 <list> <list>, <element> 3 <list> --> <list>, <element>. ==>1 4 <element> -->. ==>3 5 <element> -->. ==>4 6 <list> --> <element>. ==>2 I 4 <element> I 5 <element> I 6 <list> <element> O O K - A H E A D S E T S NONTERMINA SYMBOS OOK-AHEAD SET <list> _!_, <element> _!_, ecture 4 & 5 Bottom-up prsing Pge 122 ecture 4 & 5 Bottom-up prsing Pge 123 Fill in the ACTION tle ccording to the GOTO grph I i : stte i (line i, itemset i) 1. If there is n item nd <A> α β I i GOTO(I i, ) = I j i I i Fill in shift j for row i nd column for symol. j I j 2. If there is complete item (i.e., ends in dot ): <A> α I i Fill in reduce x where x is the production numer for x: <A> α In which column(s) should reduce x e written? R(0) fills in for ll input. SR(1) fills in for ll input in FOOW(<A>). AR(1) fills in for ll those tht cn follow certin instnce of <A> ACTION: i shift j 3. If we hve <SYS> <S> ccept the symol 4. Otherwise error. ecture 4 & 5 Bottom-up prsing Pge 124 ecture 4 & 5 Bottom-up prsing Pge 125

6 Fill in the GOTO tle <A> α I i If the GOTO grph(i i, <A>) = I j fill in GOTO[ i, <A>] = j imittions of R gmrs No miguous gmr is R(k) Shift-Reduce conflict Reduce-Reduce conflict GOTO: <A> Wht is conflict? i j Given the current stte nd input symol it is not possile to select n ction (there re two or more entries in the ction tle). Exmple. Reduce/Reduce-conflict procid ident exp ident Exmple. Shift/Reduce-conflict if... then... else Stck top Next token ecture 4 & 5 Bottom-up prsing Pge 126 ecture 4 & 5 Bottom-up prsing Pge 127 dp Exmple of Reduce/Reduce conflict: X ( A ) ( B ) A REA INTEGER IDENT B BOO CHAR IDENT Fctorised gmr: X ( A ) ( B ) ( C ) X ( A ) IDENT X Conflict elimintion y fctorising expnsion rewriting A REA INTEGER B BOO CHAR C IDENT ( B ) IDENT Exmple of Shift/Reduce conflict: X ( A ) OPT_Y ( B ) OPT_Y ε Y Y... A... B... Expnded gmr: (One token lookhed: ( ) X ( A ) X X ( A ) ( B ) Y ( B ) Y... A... B... OPT_Y ε ( B ) ecture 4 & 5 Bottom-up prsing Pge 128 ecture 4 & 5 Bottom-up prsing Pge 129

7 A concrete exmple from the ook pp. 174, 175: rewriting stmt if expr then stmt if expr then stmt else stmt other Amiguous gmr, s the following sttement hs two prse trees: -lt 2 if E1 then if E2 then S1 else S2 -lt 1 stmt if expr then stmt E1 if expr then stmt else stmt Rewriting the gmr stmt mtched_stmt unmtched_stmt mtched_stmt if expr then mtched_stmt else mtched_stmt other unmtched_stmt if expr then stmt if expr then mtched_stmt else unmtched_stmt This gmr will crete the first lterntive of prse tree, i.e. try to mtch immeditely if possile. E2 S1 S2 stmt if expr then stmt else stmt E1 if expr then stmt S2 E2 S1 ecture 4 & 5 Bottom-up prsing Pge 130 ecture 4 & 5 Bottom-up prsing Pge 131 Shift-Reduce conflict If oth criterion (1) nd (2) hold for certin item-set: <A> α <B> γ β An AR(1) gmr run through the SR(1) genertor Mny conflicts re resolved in SR(1) nd AR(1) y using lookhed. These methods construct FOOWsets, e.g.: FOOW(<list>) = {,, } V O C A B U A R Y This set specifies teinl symols which cn follow the nonteinl <list> during derivtion, lso clled the lookhed-set. All SR(1) gmrs re unmiguous ut there re unmiguous gmrs which re not SR(1). The sme is true for R(k). For R(k) the intersection of the lookhed sets must lso e non-empty. Reduce-Reduce conflict If there re severl complete items in n item-set, e.g. T E R M I N A S N O N T E R M I N A S 1. _!_ 7. <S> 2. B 8. <A> 3. C 4. A 5. E 6. D GOA SYMBO IS: <S> 1. <S> ::= B <A> C 2.! A E C 3.! A <A> D 4. <A> ::= E P R O D U C T I O N S 1. <A> α (reduce 1) 2. <B> β α (reduce 2) ecture 4 & 5 Bottom-up prsing Pge 132 ecture 4 & 5 Bottom-up prsing Pge 133

8 R ( 0 ) S E T S O F I T E M S STATENR. ITEMSET SUCCESSOR 0 <SYS> -->.<S> 1 <S> -->.B <A> C 2 <S> -->.A E C 6 <S> -->.A <A> D 6 1 <SYS> --> <S>. ==>0 2 <S> --> B.<A> C 3 <A> -->.E 5 3 <S> --> B <A>.C 4 4 <S> --> B <A> C. ==>1 5 <A> --> E. ==>4 6 <S> --> A.E C 7 <S> --> A.<A> D 9 <A> -->.E 7 7 <A> --> E. ==>4 <S> --> A E.C 8 8 <S> --> A E C. ==>2 9 <S> --> A <A>.D 10 An AR(1) gmr run through the AR(1) genertor T E R M I N A S V O C A B U A R Y N O N T E R M I N A S 1. _!_ 7. <s> <> 3. c e 6. d Gol symol is: <s> 1. <s> ::= <> c 2.! e c 3.! <> d 4. <> ::= e P R O D U C T I O N S 10 <S> --> A <A> D. ==>3 O O K - A H E A D S E T S NONTERMINA SYMBOS OOK-AHEAD SET <S> _!_ <A> C D ****** SHIFT-REDUCE CONFICT IN STATE 7 PRODUCTIONS: 2 4 THIS GRAMMAR IS NOT SR(1) ecture 4 & 5 Bottom-up prsing Pge 134 ecture 4 & 5 Bottom-up prsing Pge 135 R ( 0 ) S E T S O F I T E M S sttenr. itemset successor 0 <SYS> -->.<s> 1 <s> -->. <> c 2 <s> -->. e c 6 <s> -->. <> d 6 1 <SYS> --> <s>. ==>0 2 <s> -->.<> c 3 <> -->.e 5 3 <s> --> <>.c 4 4 <s> --> <> c. ==>1 5 <> --> e. ==>4 6 <s> -->.e c 7 <s> -->.<> d 9 <> -->.e 7 7 <> --> e. ==>4 <s> --> e.c 8 8 <s> --> e c. ==>2 9 <s> --> <>.d <s> --> <> d. ==>3 O O K - A H E A D S E T S STATE PRODUCTION OOK-AHEAD SET 1 0 _!_ 4 1 _!_ c e d 5 4 _!_ c e d 7 4 d 8 2 _!_ c e d 10 3 _!_ c e d P A R S E R A C T I O N T A B E TOP OF STACK INPUT SYMBO STATE NAME! ! <SYS>! X S2 X S6 X X 1 <s>! A X X X X X 2! X X X X -4 X 3 <>! X X -1 X X X 6! X X X X S7 X 7 e! X X -2 X X R4 9 <>! * * * * * -3 G O T O T A B E TOP OF STACK SYMBO STATE NAME! ! <SYS>! 1 * 1 <s>! * * 2! * 3 3 <>! * * 6! * 9 7 e! * * 9 <>! * * NB: The tles re optimised. For exmple, -4 in the ction tle stnds for shift-reduce ccording to rule 4. ecture 4 & 5 Bottom-up prsing Pge 136 ecture 4 & 5 Bottom-up prsing Pge 137

9 Methods for syntx error mngement 1. Pnic mode 2. Coding of wrong entries in the ACTION tle 3. Wrong productions 4. nguge-independent methods: 4) Continution method, Röchrich (1980) 4) Automtic error recovery, Burke & Fisher (1982) 1. Pnic mode c) Skip input until either i) Prsing cn continue, or ii) An importnt symol hs een found (e.g. PROCEDURE, BEGIN, WHIE,...) d) If prsing cn not continue: Pop the stck until the importnt symol is ccepted. If you rech the ottom of the stck: "Quit --Unrecoverle error." - Much input cn e removed. - Semntic info on the stck disppers. + Systemtic, simple to implement. + Efficient, very fst nd does not require extr memory. (The other methods re delt with lter in the section on error mngement.) ecture 4 & 5 Bottom-up prsing Pge 138 ecture 4 & 5 Bottom-up prsing Pge 139

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

CS 314 Principles of Programming Languages

CS 314 Principles of Programming Languages C 314 Principles of Progrmming Lnguges Lecture 6: LL(1) Prsing Zheng (Eddy) Zhng Rutgers University Ferury 5, 2018 Clss Informtion Homework 2 due tomorrow. Homework 3 will e posted erly next week. 2 Top

More information

Review for the Midterm

Review for the Midterm Review for the Midterm Stephen A. Edwrds Columi University Fll 2018 The Midterm Structure of Compiler Scnning Lnguges nd Regulr Expressions NFAs Trnslting REs into NFAs: Thompson s Construction Building

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

Parsing and Pattern Recognition

Parsing and Pattern Recognition Topics in IT Prsing nd Pttern Recognition Week Context-Free Prsing College of Informtion Science nd Engineering Ritsumeikn University this week miguity in nturl lnguge in mchine lnguges top-down, redth-first

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

More on automata. Michael George. March 24 April 7, 2014

More on automata. Michael George. March 24 April 7, 2014 More on utomt Michel George Mrch 24 April 7, 2014 1 Automt constructions Now tht we hve forml model of mchine, it is useful to mke some generl constructions. 1.1 DFA Union / Product construction Suppose

More information

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

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

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

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

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

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

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

Context-Free Grammars and Languages

Context-Free Grammars and Languages 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;

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

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

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

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

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

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

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

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

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

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

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

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

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

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

General idea LR(0) SLR LR(1) LALR To best exploit JavaCUP, should understand the theoretical basis (LR parsing);

General idea LR(0) SLR LR(1) LALR To best exploit JavaCUP, should understand the theoretical basis (LR parsing); Bottom up prsing Generl ide LR(0) SLR LR(1) LLR To best exploit JvCUP, should understnd the theoreticl bsis (LR prsing); 1 Top-down vs Bottom-up Bottom-up more powerful thn top-down; Cn process more powerful

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

Homework 4. 0 ε 0. (00) ε 0 ε 0 (00) (11) CS 341: Foundations of Computer Science II Prof. Marvin Nakayama

Homework 4. 0 ε 0. (00) ε 0 ε 0 (00) (11) CS 341: Foundations of Computer Science II Prof. Marvin Nakayama CS 341: Foundtions of Computer Science II Prof. Mrvin Nkym Homework 4 1. UsetheproceduredescriedinLemm1.55toconverttheregulrexpression(((00) (11)) 01) into n NFA. Answer: 0 0 1 1 00 0 0 11 1 1 01 0 1 (00)

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

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

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

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

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

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

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

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

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

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

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

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

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

Name Ima Sample ASU ID

Name Ima Sample ASU ID Nme Im Smple ASU ID 2468024680 CSE 355 Test 1, Fll 2016 30 Septemer 2016, 8:35-9:25.m., LSA 191 Regrding of Midterms If you elieve tht your grde hs not een dded up correctly, return the entire pper to

More information

CS 311 Homework 3 due 16:30, Thursday, 14 th October 2010

CS 311 Homework 3 due 16:30, Thursday, 14 th October 2010 CS 311 Homework 3 due 16:30, Thursdy, 14 th Octoer 2010 Homework must e sumitted on pper, in clss. Question 1. [15 pts.; 5 pts. ech] Drw stte digrms for NFAs recognizing the following lnguges:. L = {w

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

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

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

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

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

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

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

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-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

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

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

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

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

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

Regular Language. Nonregular Languages The Pumping Lemma. The pumping lemma. Regular Language. The pumping lemma. Infinitely long words 3/17/15

Regular Language. Nonregular Languages The Pumping Lemma. The pumping lemma. Regular Language. The pumping lemma. Infinitely long words 3/17/15 Regulr Lnguge Nonregulr Lnguges The Pumping Lemm Models of Comput=on Chpter 10 Recll, tht ny lnguge tht cn e descried y regulr expression is clled regulr lnguge In this lecture we will prove tht not ll

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

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

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

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

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

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

Closure Properties of Regular Languages

Closure Properties of Regular Languages of Regulr Lnguges Dr. Neil T. Dntm CSCI-561, Colordo School of Mines Fll 2018 Dntm (Mines CSCI-561) Closure Properties of Regulr Lnguges Fll 2018 1 / 50 Outline Introduction Closure Properties Stte Minimiztion

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

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

Prof. Mohamed Hamada Software Engineering Lab. The University of Aizu Japan

Prof. Mohamed Hamada Software Engineering Lab. The University of Aizu Japan Language Processing Systems Prof. Mohamed Hamada Software Engineering La. The University of izu Japan Syntax nalysis (Parsing) 1. Uses Regular Expressions to define tokens 2. Uses Finite utomata to recognize

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

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

Anatomy of a Deterministic Finite Automaton. Deterministic Finite Automata. A machine so simple that you can understand it in less than one minute

Anatomy of a Deterministic Finite Automaton. Deterministic Finite Automata. A machine so simple that you can understand it in less than one minute Victor Admchik Dnny Sletor Gret Theoreticl Ides In Computer Science CS 5-25 Spring 2 Lecture 2 Mr 3, 2 Crnegie Mellon University Deterministic Finite Automt Finite Automt A mchine so simple tht you cn

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

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

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

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

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

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

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

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

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

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

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

Fundamentals of Computer Science

Fundamentals of Computer Science Fundmentls of Computer Science Chpter 3: NFA nd DFA equivlence Regulr expressions Henrik Björklund Umeå University Jnury 23, 2014 NFA nd DFA equivlence As we shll see, it turns out tht NFA nd DFA re equivlent,

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

Finite Automata Theory and Formal Languages TMV027/DIT321 LP4 2018

Finite Automata Theory and Formal Languages TMV027/DIT321 LP4 2018 Finite Automt Theory nd Forml Lnguges TMV027/DIT321 LP4 2018 Lecture 10 An Bove April 23rd 2018 Recp: Regulr Lnguges We cn convert between FA nd RE; Hence both FA nd RE ccept/generte regulr lnguges; More

More information

12.1 Nondeterminism Nondeterministic Finite Automata. a a b ε. CS125 Lecture 12 Fall 2014

12.1 Nondeterminism Nondeterministic Finite Automata. a a b ε. CS125 Lecture 12 Fall 2014 CS125 Lecture 12 Fll 2014 12.1 Nondeterminism The ide of nondeterministic computtions is to llow our lgorithms to mke guesses, nd only require tht they ccept when the guesses re correct. For exmple, simple

More information

Chapter 1, Part 1. Regular Languages. CSC527, Chapter 1, Part 1 c 2012 Mitsunori Ogihara 1

Chapter 1, Part 1. Regular Languages. CSC527, Chapter 1, Part 1 c 2012 Mitsunori Ogihara 1 Chpter 1, Prt 1 Regulr Lnguges CSC527, Chpter 1, Prt 1 c 2012 Mitsunori Ogihr 1 Finite Automt A finite utomton is system for processing ny finite sequence of symols, where the symols re chosen from finite

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

Languages & Automata

Languages & Automata Lnguges & Automt Dr. Lim Nughton Lnguges A lnguge is sed on n lphet which is finite set of smols such s {, } or {, } or {,..., z}. If Σ is n lphet, string over Σ is finite sequence of letters from Σ, (strings

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

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

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

Lecture 3. In this lecture, we will discuss algorithms for solving systems of linear equations.

Lecture 3. In this lecture, we will discuss algorithms for solving systems of linear equations. Lecture 3 3 Solving liner equtions In this lecture we will discuss lgorithms for solving systems of liner equtions Multiplictive identity Let us restrict ourselves to considering squre mtrices since one

More information

Bottom-Up Parsing. Canonical Collection of LR(0) items. Part II

Bottom-Up Parsing. Canonical Collection of LR(0) items. Part II 2 ottom-up Prsing Prt II 1 Cnonil Colletion of LR(0) items CC_LR(0)_I items(g :ugmented_grmmr){ C = {CLOURE({ })} ; repet{ foreh(i C) foreh(grmmr symol X) if(goto(i,x) && GOTO(I,X) C) C = C {GOTO(I,X)};

More information

Bases for Vector Spaces

Bases for Vector Spaces Bses for Vector Spces 2-26-25 A set is independent if, roughly speking, there is no redundncy in the set: You cn t uild ny vector in the set s liner comintion of the others A set spns if you cn uild everything

More information