2. Lexical Analysis. Oscar Nierstrasz
|
|
- Imogene Griffith
- 5 years ago
- Views:
Transcription
1 2. Lexicl Anlysis Oscr Nierstrsz Thnks to Jens Plserg nd Tony Hosking for their kind permission to reuse nd dpt the CS132 nd CS502 lecture notes.
2 Rodmp > Introduction > Regulr lnguges > Finite utomt recognizers > From RE to DFAs nd ck gin > Limits of regulr lnguges See, Modern compiler implementtion in Jv (Second edition), chpter 2. 2
3 Rodmp > Introduction > Regulr lnguges > Finite utomt recognizers > From RE to DFAs nd ck gin > Limits of regulr lnguges 3
4 Lexicl Anlysis Source Code Scnner Tokens Prser IR errors 1. Mps sequences of chrcters to tokens 2. Elimintes white spce (ts, lnks, comments etc.) x = x + y <ID,x> <EQ> <ID,x> <PLUS> <ID,y> The string vlue of token is lexeme. 4
5 How to specify rules for token clssifiction? A scnner must recognize vrious prts of the lnguge s syntx Some prts re esy: White spce <ws> ::= <ws> <ws> \t \t Keywords nd opertors specified s literl ptterns: do, end Comments opening nd closing delimiters: /* */ 5
6 Specifying ptterns Other prts re hrder: Identifiers lphetic followed y k lphnumerics (_, $, &, )) Numers integers: 0 or digit from 1-9 followed y digits from 0-9 decimls: integer. digits from 0-9 rels: (integer or deciml) E (+ or ) digits from 0-9 complex: ( rel, rel ) We need n expressive nottion to specify these ptterns! A key issue is... 6
7 Rodmp > Introduction > Regulr lnguges > Finite utomt recognizers > From RE to DFAs nd ck gin > Limits of regulr lnguges 7
8 Lnguges nd Opertions A lnguge is set of strings Opertion Definition Union L M = { s s L or s M } Conctention LM = { st s L nd t M } Kleene closure Positive closure L* = I=0, L i L + = I=1, L i 8
9 Production Grmmrs > Powerful formlism for lnguge description Non-terminls (A, B) Terminls (,) Production rules (A->A) Strt symol (S0) > Rewriting Recursively enumerle Context sensitive Context free Regulr 9
10 Detil: The Chomsky Hierrchy > Type 0: α β Unrestricted grmmrs generte recursively enumerle lnguges. Miniml requirement for recognizer: Turing mchine. > Type 1: αaβ αγβ Context-sensitive grmmrs generte context-sensitive lnguges, recognizle y liner ounded utomt > Type 2: A γ Context-free grmmrs generte context-free lnguges, recognizle y non-deterministic push-down utomt > Type 3: A nd A B Regulr grmmrs generte regulr lnguges, recognizle y finite stte utomt NB: A is non-terminl; α, β, γ re strings of terminls nd non-terminls 10
11 Grmmrs for regulr lnguges Regulr grmmrs generte regulr lnguges Definition: In regulr grmmr, ll productions hve one of two forms: 1. A A 2. A where A is ny non-terminl nd is ny terminl symol These re lso clled type 3 grmmrs (Chomsky) 11
12 Regulr lnguges cn e descried y Regulr Expressions Regulr expressions (RE) over n lphet Σ: 1. ε is RE denoting the set {ε} 2. If Σ, then is RE denoting {} 3. If r nd s re REs denoting L(r) nd L(s), then: > (r) (s) is RE denoting L(r) L(s) > (r)(s) is RE denoting L(r)L(s) > (r)* is RE denoting L(r)* We dopt precedence for opertors: Kleene closure, then conctention, then lterntion s the order of precedence. For ny RE r, there exists grmmr g such tht L(r) = L(g) 12
13 Exmples Let Σ = {,} > denotes {,} > ( ) ( ) denotes {,,,} > * denotes {ε,,,, } > ( )* denotes the set of ll strings of s nd s (including ε) > Universit(ä e)t Bern(e )... 13
14 Algeric properties of REs r s = s r r (s t) = (r s) t r (st) = (rs)t r(s t) = rs rt (s t)r = sr tr εr = r rε = r is commuttive is ssocitive conctention is ssocitive conctention distriutes over ε is the identity for conctention r * = (r ε)* ε is contined in * r ** = r* * is idempotent 14
15 Exmples of using REs to specify lexicl ptterns identifiers letter ( c z A B C Z ) digit ( ) id letter ( letter digit )* numers integer (+ ε) (0 ( ) digit * ) deciml integer. ( digit )* rel ( integer deciml ) E (+ ) digit * complex ( rel, rel ) 15
16 Rodmp > Introduction > Regulr lnguges > Finite utomt recognizers > From RE to DFAs nd ck gin > Limits of regulr lnguges 16
17 Recognizers letter ( c z A B C Z ) digit ( ) id letter ( letter digit )* From regulr expression we cn construct deterministic finite utomton (DFA) 17
18 Code for the recognizer 18
19 Tles for the recognizer Two tles control the recognizer chr_clss chr -z A-Z 0-9 other vlue letter letter digit other next_stte letter 1 1 digit 3 1 other 3 2 To chnge lnguges, we cn just chnge tles 19
20 Automtic construction > Scnner genertors utomticlly construct code from regulr expression-like descriptions construct DFA use stte minimiztion techniques emit code for the scnner (tle driven or direct code ) > A key issue in utomtion is n interfce to the prser > lex is scnner genertor supplied with UNIX emits C code for scnner provides mcro definitions for ech token (used in the prser) nowdys JvCC is more populr 20
21 NFA exmple Wht out the RE ( )*? Stte s 0 hs multiple trnsitions on! This is non-deterministic finite utomton 21
22 Review: Finite Automt A non-deterministic finite utomton (NFA) consists of: 1. set of sttes S = { s 0,, s n } 2. set of input symols Σ (the lphet) 3. trnsition function move (δ) mpping stte-symol pirs to sets of sttes 4. distinguished strt stte s 0 5. set of distinguished ccepting (finl) sttes F A Deterministic Finite Automton (DFA) is specil cse of n NFA: 1. no stte hs ε-trnsition, nd 2. for ech stte s nd input symol, there is t most one edge leled leving s. A DFA ccepts x iff there exists unique pth through the trnsition grph from the s 0 to n ccepting stte such tht the lels long the edges spell x. 22
23 DFA exmple Exmple: the set of strings contining n even numer of zeros nd n even numer of ones The RE is (00 11)*((01 10)(00 11)*(01 10)(00 11)*)* Note how the RE wlks through the DFA. 23
24 DFAs nd NFAs re equivlent 1. DFAs re suset of NFAs 2. Any NFA cn e converted into DFA, y simulting sets of simultneous sttes: ech DFA stte corresponds to set of NFA sttes NB: possile exponentil lowup 24
25 NFA to DFA using the suset construction 25
26 Rodmp > Introduction > Regulr lnguges > Finite utomt recognizers > From RE to DFAs nd ck gin > Limits of regulr lnguges 26
27 Constructing DFA from RE > RE NFA Build NFA for ech term; connect with ε moves > NFA DFA Simulte the NFA using the suset construction > DFA minimized DFA Merge equivlent sttes > DFA RE Construct R k ij = R k-1 ik (R k-1 kk)* R k-1 kj R k-1 ij Or convert vi Generlized NFA (GNFA) 27
28 RE to NFA Strt Stte 28
29 RE to NFA exmple: ( )* ( ) ( )* ( )* 29
30 NFA to DFA: the suset construction Input: NFA N Output: DFA D with sttes S D nd trnsitions T D such tht L(D) = L(N) Method: Let s e stte in N nd P e set of sttes. Use the following opertions: > ε-closure(s) set of sttes of N rechle from s y ε trnsitions lone > ε-closure(p) set of sttes of N rechle from some s in P y ε trnsitions lone > move(t,) set of sttes of N to which there is trnsition on input from some s in P dd stte P = ε-closure(s 0 ) unmrked to S D while unmrked stte P in S D mrk P for ech input symol U = ε-closure(move(p,)) if U S D then dd U unmrked to S D T D [P,] = U end for end while ε-closure(s 0 ) is the strt stte of D A stte of D is ccepting if it contins n ccepting stte of N 30
31 NFA to DFA using suset construction: exmple A = {0,1,2,4,7} B = {1,2,3,4,6,7,8} C = {1,2,4,5,6,7} D = {1,2,4,5,6,7,9} E = {1,2,4,5,6,7,10} A C B D E 31
32 DFA Minimiztion Theorem: For ech regulr lnguge tht cn e ccepted y DFA, there exists DFA with minimum numer of sttes. A B D Minimiztion pproch: merge equivlent sttes. C E Sttes A nd C re indistinguishle, so they cn e merged! 32
33 DFA Minimiztion lgorithm > Crete lower-tringulr tle DISTINCT, initilly lnk > For every pir of sttes (p,q): If p is finl nd q is not, or vice vers DISTINCT(p,q) = ε > Loop until no chnge for n itertion: For every pir of sttes (p,q) nd ech symol α If DISTINCT(p,q) is lnk nd DISTINCT( δ(p,α), δ(q,α) ) is not lnk DISTINCT(p,q) = α > Comine ll sttes tht re not distinct 33
34 Minimiztion in ction A C B D E C nd A re indistinguishle so cn e merged A A A A A B B B B B C C C C C D D D D D E E ε ε ε ε E ε ε ε ε E ε ε ε ε E ε ε ε ε A B C D E A B C D E A B C D E A B C D E A B C D E 34
35 DFA Minimiztion exmple A C B D E It is esy to see tht this is in fct the miniml DFA for ( )*
36 DFA to RE vi GNFA > A Generlized NFA is n NFA where trnsitions my hve ny RE s lels > Conversion lgorithm: 1. Add new strt stte nd ccept stte with ε-trnsitions to/from the old strt/end sttes 2. Merge multiple trnsitions etween two sttes to single RE choice trnsition 3. Add empty trnsitions etween sttes where missing 4. Itertively rip out old sttes nd replce dngling trnsitions with ppropritely leled trnsitions etween remining sttes 5. STOP when ll old sttes re gone nd only the new strt nd ccept sttes remin 36
37 GNFA conversion lgorithm 1. Let k e the numer of sttes of G, k 2 2. If k=2, then RE is the lel found etween q s nd q (strt nd ccept sttes of G) 3. While k>2, select q rip q s or q Q = Q {q rip } For ny q i Q {q } let δ (q i,q j ) = R 1 R 2 * R 3 R 4 where: R 1 = δ (q i,q rip ), R 2 = δ (q rip,q rip ), R 2 = δ (q rip,q j ), R 4 = δ (q i,q j ) Replce G y G 37
38 The initil DFA
39 ε ε s Add new strt nd ccept sttes
40 ε ε s Add missing empty trnsitions (we ll just pretend they re there)
41 1 2 3 ε ε s Delete n ritrry stte
42 1 2 3 * * ε s Fix dngling trnsitions s 1 nd 3 1 Don t forget to merge the existing trnsitions!
43 Simplify the RE Delete nother stte 2 3 * * ε s NB: * = (* ε) = *
44 * 2 3 ** ** ε s
45 * 2 ** ** ε s
46 * ** 2 ** s NB: * ** = (ε *)* = **
47 ** 2 ** s
48 ** ** s
49 Hm not wht we expected s ** (**)*
50 ** (**)* = ( )*? > We cn rewrite: ** (**)* ** (**)* (**)* ** > But does this hold? (**)* ** = ( )* We cn show tht the miniml DFAs for these REs re isomorphic
51 Rodmp > Introduction > Regulr lnguges > Finite utomt recognizers > From RE to DFAs nd ck gin > Limits of regulr lnguges 51
52 Limits of regulr lnguges Not ll lnguges re regulr! One cnnot construct DFAs to recognize these lnguges: L = { p k q k } L = { wcw r w Σ*, w r is w reversed } In generl, DFAs cnnot count! However, one cn construct DFAs for: Alternting 0 s nd 1 s: (ε 1)(01)*(ε 0) Sets of pirs of 0 s nd 1 s (01 10) + 52
53 So, wht is hrd? Certin lnguge fetures cn cuse prolems: > Reserved words PL/I hd no reserved words if then then then = else; else else = then > Significnt lnks FORTRAN nd Algol68 ignore lnks do 10 i = 1,25 do 10 i = 1.25 > String constnts Specil chrcters in strings Newline, t, quote, comment delimiter > Finite limits Some lnguges limit identifier lengths Add stte to count length FORTRAN 66 6 chrcters(!) 53
54 How d cn it get? Compiler needs context to distinguish vriles from control constructs! 54
55 Wht you should know! Wht re the key responsiilities of scnner? Wht is forml lnguge? Wht re opertors over lnguges? Wht is regulr lnguge? Why re regulr lnguges interesting for defining scnners? Wht is the difference etween deterministic nd non-deterministic finite utomton? How cn you generte DFA recognizer from regulr expression? Why ren t regulr lnguges expressive enough for prsing? 55
56 Cn you nswer these questions? Why do compilers seprte scnning from prsing? Why doesn t NFA DFA trnsltion normlly result in n exponentil increse in the numer of sttes? Why is it necessry to minimize sttes fter trnsltion NFA to DFA? How would you progrm scnner for lnguge like FORTRAN? 56
57 Attriution-ShreAlike 4.0 Interntionl (CC BY-SA 4.0) You re free to: Shre copy nd redistriute the mteril in ny medium or formt Adpt remix, trnsform, nd uild upon the mteril for ny purpose, even commercilly. The licensor cnnot revoke these freedoms s long s you follow the license terms. Under the following terms: Attriution You must give pproprite credit, provide link to the license, nd indicte if chnges were mde. You my do so in ny resonle mnner, ut not in ny wy tht suggests the licensor endorses you or your use. ShreAlike If you remix, trnsform, or uild upon the mteril, you must distriute your contriutions under the sme license s the originl. No dditionl restrictions You my not pply legl terms or technologicl mesures tht leglly restrict others from doing nything the license permits.
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 informationCS415 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 informationLecture 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 informationRegular 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 informationCMSC 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 informationCS 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 informationFinite 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 informationRegular 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 informationFABER 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 informationMinimal 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 informationTypes 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 informationTypes 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 informationCHAPTER 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 informationConvert 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 informationLexical 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 informationLexical 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 informationFirst 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 informationJava 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 informationNFA 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 informationDeterministic 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 informationHomework 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 informationAUTOMATA 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 information1 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 informationAutomata 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 informationFinite 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 informationFundamentals 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ɛ-closure, Kleene s Theorem,
DEGefW5wiGH2XgYMEzUKjEmtCDUsRQ4d 1 A nice pper relevnt to this course is titled The Glory of the Pst 2 NICTA Resercher, Adjunct t the Austrlin Ntionl University nd Griffith University ɛ-closure, Kleene
More informationLet'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 informationDesigning 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 informationFormal 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 informationFirst 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 informationCSCI 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 informationCompiler 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 informationThoery 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 informationChapter 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 informationAssignment 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 informationChapter 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 informationClosure 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 informationTable 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 informationCS 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 informationFinite 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 informationThe 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 information5. (±±) Λ = 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 informationFormal 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 information12.1 Nondeterminism Nondeterministic Finite Automata. a a b ε. CS125 Lecture 12 Fall 2016
CS125 Lecture 12 Fll 2016 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 informationNon-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 information1 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 informationAnatomy 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 informationCISC 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 informationCS 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 information1. 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 informationTheory 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 informationSpeech 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 informationNFAs continued, Closure Properties of Regular Languages
Algorithms & Models of Computtion CS/ECE 374, Fll 2017 NFAs continued, Closure Properties of Regulr Lnguges Lecture 5 Tuesdy, Septemer 12, 2017 Sriel Hr-Peled (UIUC) CS374 1 Fll 2017 1 / 31 Regulr Lnguges,
More informationSpeech Recognition Lecture 2: Finite Automata and Finite-State Transducers. Mehryar Mohri Courant Institute and Google Research
Speech Recognition Lecture 2: Finite Automt nd Finite-Stte Trnsducers Mehryr Mohri Cournt Institute nd Google Reserch mohri@cims.nyu.com Preliminries Finite lphet Σ, empty string. Set of ll strings over
More informationWorked 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 informationConverting 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 informationHarvard 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 informationCHAPTER 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 informationCS375: 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 information3 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 informationTheory of Computation Regular Languages
Theory of Computtion Regulr Lnguges Bow-Yw Wng Acdemi Sinic Spring 2012 Bow-Yw Wng (Acdemi Sinic) Regulr Lnguges Spring 2012 1 / 38 Schemtic of Finite Automt control 0 0 1 0 1 1 1 0 Figure: Schemtic of
More informationNFAs 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 informationCMPSCI 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 informationCMSC 330: Organization of Programming Languages. DFAs, and NFAs, and Regexps (Oh my!)
CMSC 330: Orgniztion of Progrmming Lnguges DFAs, nd NFAs, nd Regexps (Oh my!) CMSC330 Spring 2018 Types of Finite Automt Deterministic Finite Automt (DFA) Exctly one sequence of steps for ech string All
More informationContext-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 information1.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 informationReview 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 informationToday s Topics Automata and Languages
Tody s Topics Automt nd Lnguges Prof. Mohmed Hmd Softwre Engineering L. The University of Aizu Jpn DFA to Regulr Expression GFNA DFAèGNFA GNFA è RE DFA è RE Exmples 2 DFA è RE NFA DFA -NFA REX GNFA 3 Definition
More informationAutomata and Languages
Automt nd Lnguges Prof. Mohmed Hmd Softwre Engineering L. The University of Aizu Jpn Tody s Topics DFA to Regulr Expression GFNA DFAèGNFA GNFA è RE DFA è RE Exmples 2 DFA è RE NFA DFA -NFA REX GNFA 3 Definition
More informationNon-deterministic Finite Automata
Non-deterministic Finite Automt From Regulr Expressions to NFA- Eliminting non-determinism Rdoud University Nijmegen Non-deterministic Finite Automt H. Geuvers nd J. Rot Institute for Computing nd Informtion
More informationCS 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 informationMore 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 informationCS 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 informationSome 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 informationCSC 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 informationa,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 informationCS:4330 Theory of Computation Spring Regular Languages. Equivalences between Finite automata and REs. Haniel Barbosa
CS:4330 Theory of Computtion Spring 208 Regulr Lnguges Equivlences between Finite utomt nd REs Hniel Brbos Redings for this lecture Chpter of [Sipser 996], 3rd edition. Section.3. Finite utomt nd regulr
More informationTalen 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 informationNon-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 information80 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 informationGNFA GNFA GNFA GNFA GNFA
DFA RE NFA DFA -NFA REX GNFA Definition GNFA A generlize noneterministic finite utomton (GNFA) is grph whose eges re lele y regulr expressions, with unique strt stte with in-egree, n unique finl stte with
More informationOverview 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 information1.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 informationCS103B 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 informationNormal 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 informationNondeterminism 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 informationCS375: Logic and Theory of Computing
CS375: Logic nd Theory of Computing Fuhu (Frnk) Cheng Deprtment of Computer Science University of Kentucky 1 Tble of Contents: Week 1: Preliminries (set lgebr, reltions, functions) (red Chpters 1-4) Weeks
More informationLecture 6 Regular Grammars
Lecture 6 Regulr Grmmrs COT 4420 Theory of Computtion Section 3.3 Grmmr A grmmr G is defined s qudruple G = (V, T, S, P) V is finite set of vribles T is finite set of terminl symbols S V is specil vrible
More informationFinite-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 informationGrammar. 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 informationCS 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 informationCS 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 informationCSE : 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 informationCS311 Computational Structures Regular Languages and Regular Grammars. Lecture 6
CS311 Computtionl Strutures Regulr Lnguges nd Regulr Grmmrs Leture 6 1 Wht we know so fr: RLs re losed under produt, union nd * Every RL n e written s RE, nd every RE represents RL Every RL n e reognized
More informationFORMAL LANGUAGES, AUTOMATA AND COMPUTABILITY. FLAC (15-453) - Spring L. Blum
15-453 FORMAL LANGUAGES, AUTOMATA AND COMPUTABILITY THE PUMPING LEMMA FOR REGULAR LANGUAGES nd REGULAR EXPRESSIONS TUESDAY Jn 21 WHICH OF THESE ARE REGULAR? B = {0 n 1 n n 0} C = { w w hs equl numer of
More informationNFAs continued, Closure Properties of Regular Languages
lgorithms & Models of omputtion S/EE 374, Spring 209 NFs continued, losure Properties of Regulr Lnguges Lecture 5 Tuesdy, Jnury 29, 209 Regulr Lnguges, DFs, NFs Lnguges ccepted y DFs, NFs, nd regulr expressions
More informationLanguages & 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 informationLecture 09: Myhill-Nerode Theorem
CS 373: Theory of Computtion Mdhusudn Prthsrthy Lecture 09: Myhill-Nerode Theorem 16 Ferury 2010 In this lecture, we will see tht every lnguge hs unique miniml DFA We will see this fct from two perspectives
More informationMore general families of infinite graphs
More generl fmilies of infinite grphs Antoine Meyer Forml Methods Updte 2006 IIT Guwhti Prefix-recognizle grphs Theorem Let G e grph, the following sttements re equivlent: G is defined y reltions of the
More information