# Regular Languages. MACM 300 Formal Languages and Automata. Formal Languages: Recap. Regular Languages

Size: px
Start display at page:

Download "Regular Languages. MACM 300 Formal Languages and Automata. Formal Languages: Recap. Regular Languages"

Transcription

1 Regular Languages MACM 3 Formal Languages and Automata Anoop Sarkar The set of regular languages: each element is a regular language Each regular language is an example of a (formal) language, i.e. a set of strings e.g. { a m b n : m, n are +ve integers } 2/9/6 2/9/6 3 Formal Languages: Recap Symbols: a, b, c Alphabet : finite set of symbols! = {a, b} String: sequence of symbols bab Empty string: Define:! =! # {} Set of all strings:!* (Formal) Language: a set of strings { a n b n : n > } cf. The Library of Babel, Jorge Luis Borges Regular Languages Defining the set of all regular languages: The empty set and {a} for all a in! are regular languages If L and L 2 and L are regular languages, then: (union) (Kleene closure) are also regular languages There are no other regular languages (concatenation) 2/9/6 2 2/9/6 4

2 Formal Grammars A formal grammar is a concise description of a formal language A formal grammar uses a specialized syntax For example, a regular expression is a concise description of a regular language (a#b)*abb : is the set of all strings over the alphabet {a, b} which end in abb Regular Expressions: Examples Alphabet {, } All strings that represent binary numbers divisible by 4 (but accept ) ((#)*) All strings that do not contain as a substring ** 2/9/6 5 2/9/6 7 Regular Expressions: Definition Every symbol of! # { } is a regular expression The empty language \$ is a regular expression Note that *\$ = \$ If r and r 2 are regular expressions, so are Concatenation: r r 2 Alternation: r # r 2 Repetition: r * Nothing else is. But grouping re s is allowed: e.g. aa#bc vs. ((aa)#b)c Finite Automata: Recap A set of states S One start state q, zero or more final states F An alphabet % of input symbols A transition function: &: S x! ' S Example: &(, a) = 2 2/9/6 6 2/9/6 8

3 Finite Automata: Example What regular expression does this automaton accept? Answer: (#)* 2/9/6 9 Thompson s construction Converts regexps to NFA Six simple rules Empty language Symbols Empty String Alternation (r or r 2 ) Concatenation (r followed by r 2 ) Repetition (r *) 2/9/6 NFAs NFA: like a DFA, except A transition can lead to more than one state, that is, &: S x! ' 2 S One state is chosen non-deterministically Transitions can be labeled with, meaning states can be reached without reading any input, that is, &: S x! # { } ' 2 S Thompson Rule For the empty language \$ (optionally include a sinkhole state)!! 2/9/6 2/9/6 2

4 Thompson Rule For each symbol x of the alphabet, there is a NFA that accepts it (optionally include a sinkhole state) x Thompson Rule 3 Given two NFAs for r, r 2, there is a NFA that accepts r #r 2 r!\x! r2 2/9/6 3! 2/9/6 5 Thompson Rule 2 There is an NFA that accepts only!! Thompson Rule 4 Given two NFAs for r, r 2, there is a NFA that accepts r r 2 r r2 no longer final state after concatenation 2/9/6 4 2/9/6 6

5 Thompson Rule 5 Given a NFA for r, there is an NFA that accepts r * Basic Blocks and r (this version does not report errors: no sinkholes) 2/9/6 7 2/9/6 9 Example Set of all binary strings that are divisible by four (include in this set) Defined by the regexp: ((#)*)# Apply Thompson s Rules to create an NFA 2/9/6 8 2/9/6 2

6 ( )* 2/9/6 2 (( )*) 2/9/ ( )* 2/9/6 22 (( )*) 2/9/6 24

7 NFA to DFA Conversion Subset construction Idea: subsets of set of all NFA states are equivalent and become one DFA state Algorithm simulates movement through NFA Key problem: how to treat -transitions? NFA Simulation After computing the -closure move, we get a set of states On some input extend all these states to get a new set of states 2/9/6 25 2/9/6 27 -Closure NFA Simulation Start state: q -closure(s): S is a set of states Start state: q Input: c,, c k 2/9/6 26 2/9/6 28

8 Conversion from NFA to DFA -closure(q ) Conversion method closely follows the NFA simulation algorithm Instead of simulating, we can collect those NFA states that behave identically on the same input Group this set of states to form one state in the DFA /9/6 29 2/9/6 3 Example: subset construction move(-closure(q ), ) /9/6 3 2/9/6 32

9 -closure(move(-closure(q ), )) -closure(move(-closure(q ), )) /9/6 33 2/9/6 35 move(-closure(q ), ) DFA (partial) [, 2, 3, 4, 6, 9, 2] [3, 4, 5, 6, 8, 9,, 3, 4] [3, 4, 6, 7, 8, 9] 2/9/6 34 2/9/6 36

10 [, 2, 3, 4, 6, 9, 2] DFA for (( )*) [3, 4, 5, 6, 8, 9,, 3, 4] [3, 4, 6, 7, 8, 9] [3, 4, 5, 6, 8, 9, ] [3, 4, 5, 6, 8, 9,,, 4] Minimization (II) [3, 4, 6, 7, 8, 9] [3, 4, 5, 6, 8, 9, ] [3, 4, 5, 6, 8, 9,,, 4] 2/9/6 37 2/9/6 39 [, 2, 3, 4, 6, 9, 2] Minimization (I) [3, 4, 6, 7, 8, 9] [3, 4, 5, 6, 8, 9, ] [3, 4, 5, 6, 8, 9,,, 4] 2/9/6 38 Minimization of DFAs Algorithm for minimizing the number of states in a DFA Step : partition states into 2 groups: accepting and non-accepting A D B 2/9/6 4 E C

11 Minimization of DFAs Step 2: in each group, find a sub-group of states having property P P: The states have transitions on each symbol (in the alphabet) to the same group A, : blue A, : yellow E, : blue E, : yellow D, : yellow D, : yellow A D B 2/9/6 4 E C B, : blue B, : yellow C, : blue C, : yellow Minimization of DFAs Step 4: each group becomes a state in the minimized DFA Transitions to individual states are mapped to a single state representing the group of states A D B E C 2/9/6 43 Minimization of DFAs NFA to DFA Step 3: if a sub-group does not obey P split up the group into a separate group Go back to step 2. If no further sub-groups emerge then continue to step 4 A, : blue A, : green E, : blue E, : green D, : yellow D, : green A D B 2/9/6 42 E C B, : blue B, : green C, : blue C, : green Subset construction converts NFA to DFA Complexity: in programs we measure time complexity in number of steps For FSAs, we measure complexity in terms of the number of states 2/9/6 44

12 NFA to DFA NFA to DFA Problem: An n state NFA can sometimes become a 2 n state DFA, an exponential increase in complexity Try the subset construction on NFA built for the regexp A*aA n- where A is the regexp (a b) Minimization can reduce the number of states But minimization requires determinization 2/9/6 45 2/9/6 47 NFA to DFA NFA to DFA 2/9/ = 32 states 2/9/6 48

13 Equivalence of Regexps NFA to RegExp (R S) T == R (S T) == R S T (RS)T == R(ST) (R S) == (S R) R*R* == (R*)* == R* == RR* R** == R* (R S)T = RT ST R(S T) == RS RT (R S)* == (R*S*)* == (R*S)*R* == (R* S*)* RR* == R*R (RS)*R == R(SR)* R = R R = R = R A = a B A B = b D b C a B b b D a a C D = a B C = a D 2/9/6 49 2/9/6 5 Equivalence of Regexps NFA to RegExp ()* ()* ()()* ()* ()()* ()()* ()()* ()* (RS)*R == R(SR)* RS == (RS) R* == RR* R == R R R* == RR* Three steps in the algorithm (apply in any order):. Substitution: for B = X pick every A = B T and replace to get A = X T 2. Factoring: (R S) (R T) = R (S # T) and (R T) (S T) = (R # S) T 3. Arden's Rule: For any set of strings S and T, the equation X = (S X) T has X = (S*) T as a solution. 2/9/6 5 2/9/6 52

14 NFA to RegExp Summary A = a B B = b D b C D = a B C = a D Substitute: A = a B B = b D b a D D = a B Factor: A = a B B = (b # b a) D D = a B Substitute: A = a (b # b a) D D = a (b # b a) D Recognition of a string in a regular language: is a string accepted by an NFA? Conversion of regular expressions to NFAs Determinization: converting NFA to DFA Converting an NFA into a regular expression Other useful closure properties: union, concatenation, Kleene closure, intersection 2/9/6 53 2/9/6 55 NFA to RegExp A = a (b # b a) D D = a (b # b a) D Factor: A = (a b # a b a) D D = (a b # a b a) D Arden: A = (a b # a b a) D D = (a b # a b a)* Remove epsilon: A = (a b # a b a) D D = (a b # a b a)* Substitute: A = (a b # a b a) (a b # a b a)* Simplify: A = (a b # a b a)+ 2/9/6 54

### Implementation of Lexical Analysis

Implementation of Lexical Analysis Outline Specifying lexical structure using regular expressions Finite automata Deterministic Finite Automata (DFAs) Non-deterministic Finite Automata (NFAs) Implementation

### Implementation of Lexical Analysis

Implementation of Lexical Analysis Outline Specifying lexical structure using regular expressions Finite automata Deterministic Finite Automata (DFAs) Non-deterministic Finite Automata (NFAs) Implementation

### Implementation of Lexical Analysis

Implementation of Lexical Analysis Lecture 4 (Modified by Professor Vijay Ganesh) Tips on Building Large Systems KISS (Keep It Simple, Stupid!) Don t optimize prematurely Design systems that can be tested

### Lexical Analysis. Implementation: Finite Automata

Lexical Analysis Implementation: Finite Automata Outline Specifying lexical structure using regular expressions Finite automata Deterministic Finite Automata (DFAs) Non-deterministic Finite Automata (NFAs)

### Formal Languages and Compilers Lecture IV: Regular Languages and Finite. Finite Automata

Formal Languages and Compilers Lecture IV: Regular Languages and Finite Automata Free University of Bozen-Bolzano Faculty of Computer Science POS Building, Room: 2.03 artale@inf.unibz.it http://www.inf.unibz.it/

### CS 432 Fall Mike Lam, Professor. Finite Automata Conversions and Lexing

CS 432 Fall 2017 Mike Lam, Professor Finite Automata Conversions and Lexing Finite Automata Key result: all of the following have the same expressive power (i.e., they all describe regular languages):

### 6 NFA and Regular Expressions

Formal Language and Automata Theory: CS21004 6 NFA and Regular Expressions 6.1 Nondeterministic Finite Automata A nondeterministic finite automata (NFA) is a 5-tuple where 1. is a finite set of states

### Lexical Analysis. Chapter 2

Lexical Analysis Chapter 2 1 Outline Informal sketch of lexical analysis Identifies tokens in input string Issues in lexical analysis Lookahead Ambiguities Specifying lexers Regular expressions Examples

### CSE450. Translation of Programming Languages. Lecture 20: Automata and Regular Expressions

CSE45 Translation of Programming Languages Lecture 2: Automata and Regular Expressions Finite Automata Regular Expression = Specification Finite Automata = Implementation A finite automaton consists of:

### Introduction to Lexical Analysis

Introduction to Lexical Analysis Outline Informal sketch of lexical analysis Identifies tokens in input string Issues in lexical analysis Lookahead Ambiguities Specifying lexical analyzers (lexers) Regular

### Formal Languages and Compilers Lecture VI: Lexical Analysis

Formal Languages and Compilers Lecture VI: Lexical Analysis Free University of Bozen-Bolzano Faculty of Computer Science POS Building, Room: 2.03 artale@inf.unibz.it http://www.inf.unibz.it/ artale/ Formal

### Lexical Analysis. Lecture 2-4

Lexical Analysis Lecture 2-4 Notes by G. Necula, with additions by P. Hilfinger Prof. Hilfinger CS 164 Lecture 2 1 Administrivia Moving to 60 Evans on Wednesday HW1 available Pyth manual available on line.

### MIT Specifying Languages with Regular Expressions and Context-Free Grammars. Martin Rinard Massachusetts Institute of Technology

MIT 6.035 Specifying Languages with Regular essions and Context-Free Grammars Martin Rinard Massachusetts Institute of Technology Language Definition Problem How to precisely define language Layered structure

### MIT Specifying Languages with Regular Expressions and Context-Free Grammars

MIT 6.035 Specifying Languages with Regular essions and Context-Free Grammars Martin Rinard Laboratory for Computer Science Massachusetts Institute of Technology Language Definition Problem How to precisely

### 1. (10 points) Draw the state diagram of the DFA that recognizes the language over Σ = {0, 1}

CSE 5 Homework 2 Due: Monday October 6, 27 Instructions Upload a single file to Gradescope for each group. should be on each page of the submission. All group members names and PIDs Your assignments in

### Implementation of Lexical Analysis

Outline Implementation of Lexical nalysis Specifying lexical structure using regular expressions Finite automata Deterministic Finite utomata (DFs) Non-deterministic Finite utomata (NFs) Implementation

### Last lecture CMSC330. This lecture. Finite Automata: States. Finite Automata. Implementing Regular Expressions. Languages. Regular expressions

Last lecture CMSC330 Finite Automata Languages Sets of strings Operations on languages Regular expressions Constants Operators Precedence 1 2 Finite automata States Transitions Examples Types This lecture

### Finite automata. We have looked at using Lex to build a scanner on the basis of regular expressions.

Finite automata We have looked at using Lex to build a scanner on the basis of regular expressions. Now we begin to consider the results from automata theory that make Lex possible. Recall: An alphabet

### 2010: Compilers REVIEW: REGULAR EXPRESSIONS HOW TO USE REGULAR EXPRESSIONS

2010: Compilers Lexical Analysis: Finite State Automata Dr. Licia Capra UCL/CS REVIEW: REGULAR EXPRESSIONS a Character in A Empty string R S Alternation (either R or S) RS Concatenation (R followed by

### Lexical Analysis. Lecture 3-4

Lexical Analysis Lecture 3-4 Notes by G. Necula, with additions by P. Hilfinger Prof. Hilfinger CS 164 Lecture 3-4 1 Administrivia I suggest you start looking at Python (see link on class home page). Please

### Derivations of a CFG. MACM 300 Formal Languages and Automata. Context-free Grammars. Derivations and parse trees

Derivations of a CFG MACM 300 Formal Languages and Automata Anoop Sarkar http://www.cs.sfu.ca/~anoop strings grow on trees strings grow on Noun strings grow Object strings Verb Object Noun Verb Object

### Automating Construction of Lexers

Automating Construction of Lexers Regular Expression to Programs Not all regular expressions are simple. How can we write a lexer for (a*b aaa)? Tokenizing aaaab Vs aaaaaa Regular Expression Finite state

### Behaviour Diagrams UML

Behaviour Diagrams UML Behaviour Diagrams Structure Diagrams are used to describe the static composition of components (i.e., constraints on what intstances may exist at run-time). Interaction Diagrams

### Lexical Analysis. Dragon Book Chapter 3 Formal Languages Regular Expressions Finite Automata Theory Lexical Analysis using Automata

Lexical Analysis Dragon Book Chapter 3 Formal Languages Regular Expressions Finite Automata Theory Lexical Analysis using Automata Phase Ordering of Front-Ends Lexical analysis (lexer) Break input string

### CSE450. Translation of Programming Languages. Automata, Simple Language Design Principles

CSE45 Translation of Programming Languages Automata, Simple Language Design Principles Finite Automata State Graphs A state: The start state: An accepting state: A transition: a A Simple Example A finite

### Ambiguous Grammars and Compactification

Ambiguous Grammars and Compactification Mridul Aanjaneya Stanford University July 17, 2012 Mridul Aanjaneya Automata Theory 1/ 44 Midterm Review Mathematical Induction and Pigeonhole Principle Finite Automata

### Converting a DFA to a Regular Expression JP

Converting a DFA to a Regular Expression JP Prerequisite knowledge: Regular Languages Deterministic Finite Automata Nondeterministic Finite Automata Regular Expressions Conversion of Regular Expression

### Languages and Compilers

Principles of Software Engineering and Operational Systems Languages and Compilers SDAGE: Level I 2012-13 3. Formal Languages, Grammars and Automata Dr Valery Adzhiev vadzhiev@bournemouth.ac.uk Office:

### UNIT -2 LEXICAL ANALYSIS

OVER VIEW OF LEXICAL ANALYSIS UNIT -2 LEXICAL ANALYSIS o To identify the tokens we need some method of describing the possible tokens that can appear in the input stream. For this purpose we introduce

### CSE 431S Scanning. Washington University Spring 2013

CSE 431S Scanning Washington University Spring 2013 Regular Languages Three ways to describe regular languages FSA Right-linear grammars Regular expressions Regular Expressions A regular expression is

### CIT3130: Theory of Computation. Regular languages

ƒ CIT3130: Theory of Computation Regular languages ( M refers to the first edition of Martin and H to IALC by Hopcroft et al.) Definitions of regular expressions and regular languages: A regular expression

### Finite Automata. Dr. Nadeem Akhtar. Assistant Professor Department of Computer Science & IT The Islamia University of Bahawalpur

Finite Automata Dr. Nadeem Akhtar Assistant Professor Department of Computer Science & IT The Islamia University of Bahawalpur PhD Laboratory IRISA-UBS University of South Brittany European University

### Computer Science Department Carlos III University of Madrid Leganés (Spain) David Griol Barres

Computer Science Department Carlos III University of Madrid Leganés (Spain) David Griol Barres dgriol@inf.uc3m.es Introduction: Definitions Lexical analysis or scanning: To read from left-to-right a source

### Implementation of Lexical Analysis. Lecture 4

Implementation of Lexical Analysis Lecture 4 1 Tips on Building Large Systems KISS (Keep It Simple, Stupid!) Don t optimize prematurely Design systems that can be tested It is easier to modify a working

### Skyup's Media. PART-B 2) Construct a Mealy machine which is equivalent to the Moore machine given in table.

Code No: XXXXX JAWAHARLAL NEHRU TECHNOLOGICAL UNIVERSITY, HYDERABAD B.Tech II Year I Semester Examinations (Common to CSE and IT) Note: This question paper contains two parts A and B. Part A is compulsory

### COMP-421 Compiler Design. Presented by Dr Ioanna Dionysiou

COMP-421 Compiler Design Presented by Dr Ioanna Dionysiou Administrative! [ALSU03] Chapter 3 - Lexical Analysis Sections 3.1-3.4, 3.6-3.7! Reading for next time [ALSU03] Chapter 3 Copyright (c) 2010 Ioanna

### Lexical Analysis. Prof. James L. Frankel Harvard University

Lexical Analysis Prof. James L. Frankel Harvard University Version of 5:37 PM 30-Jan-2018 Copyright 2018, 2016, 2015 James L. Frankel. All rights reserved. Regular Expression Notation We will develop a

### JNTUWORLD. Code No: R

Code No: R09220504 R09 SET-1 B.Tech II Year - II Semester Examinations, April-May, 2012 FORMAL LANGUAGES AND AUTOMATA THEORY (Computer Science and Engineering) Time: 3 hours Max. Marks: 75 Answer any five

### David Griol Barres Computer Science Department Carlos III University of Madrid Leganés (Spain)

David Griol Barres dgriol@inf.uc3m.es Computer Science Department Carlos III University of Madrid Leganés (Spain) OUTLINE Introduction: Definitions The role of the Lexical Analyzer Scanner Implementation

### CSEP 501 Compilers. Languages, Automata, Regular Expressions & Scanners Hal Perkins Winter /8/ Hal Perkins & UW CSE B-1

CSEP 501 Compilers Languages, Automata, Regular Expressions & Scanners Hal Perkins Winter 2008 1/8/2008 2002-08 Hal Perkins & UW CSE B-1 Agenda Basic concepts of formal grammars (review) Regular expressions

### Non-deterministic Finite Automata (NFA)

Non-deterministic Finite Automata (NFA) CAN have transitions on the same input to different states Can include a ε or λ transition (i.e. move to new state without reading input) Often easier to design

### DVA337 HT17 - LECTURE 4. Languages and regular expressions

DVA337 HT17 - LECTURE 4 Languages and regular expressions 1 SO FAR 2 TODAY Formal definition of languages in terms of strings Operations on strings and languages Definition of regular expressions Meaning

### HKN CS 374 Midterm 1 Review. Tim Klem Noah Mathes Mahir Morshed

HKN CS 374 Midterm 1 Review Tim Klem Noah Mathes Mahir Morshed Midterm topics It s all about recognizing sets of strings! 1. String Induction 2. Regular languages a. DFA b. NFA c. Regular expressions 3.

### Compiler Construction

Compiler Construction Thomas Noll Software Modeling and Verification Group RWTH Aachen University https://moves.rwth-aachen.de/teaching/ss-16/cc/ Conceptual Structure of a Compiler Source code x1 := y2

### Regular Expressions. Agenda for Today. Grammar for a Tiny Language. Programming Language Specifications

Agenda for Today Regular Expressions CSE 413, Autumn 2005 Programming Languages Basic concepts of formal grammars Regular expressions Lexical specification of programming languages Using finite automata

### Dr. D.M. Akbar Hussain

1 2 Compiler Construction F6S Lecture - 2 1 3 4 Compiler Construction F6S Lecture - 2 2 5 #include.. #include main() { char in; in = getch ( ); if ( isalpha (in) ) in = getch ( ); else error (); while

### CSE 105 THEORY OF COMPUTATION

CSE 105 THEORY OF COMPUTATION Spring 2017 http://cseweb.ucsd.edu/classes/sp17/cse105-ab/ Today's learning goals Sipser Ch 1.2, 1.3 Design NFA recognizing a given language Convert an NFA (with or without

### CS308 Compiler Principles Lexical Analyzer Li Jiang

CS308 Lexical Analyzer Li Jiang Department of Computer Science and Engineering Shanghai Jiao Tong University Content: Outline Basic concepts: pattern, lexeme, and token. Operations on languages, and regular

### Outline. 1 Scanning Tokens. 2 Regular Expresssions. 3 Finite State Automata

Outline 1 2 Regular Expresssions Lexical Analysis 3 Finite State Automata 4 Non-deterministic (NFA) Versus Deterministic Finite State Automata (DFA) 5 Regular Expresssions to NFA 6 NFA to DFA 7 8 JavaCC:

### CSE 413 Programming Languages & Implementation. Hal Perkins Winter 2019 Grammars, Scanners & Regular Expressions

CSE 413 Programming Languages & Implementation Hal Perkins Winter 2019 Grammars, Scanners & Regular Expressions 1 Agenda Overview of language recognizers Basic concepts of formal grammars Scanner Theory

### CSE 413 Programming Languages & Implementation. Hal Perkins Autumn 2012 Grammars, Scanners & Regular Expressions

CSE 413 Programming Languages & Implementation Hal Perkins Autumn 2012 Grammars, Scanners & Regular Expressions 1 Agenda Overview of language recognizers Basic concepts of formal grammars Scanner Theory

### Lexical Analysis 1 / 52

Lexical Analysis 1 / 52 Outline 1 Scanning Tokens 2 Regular Expresssions 3 Finite State Automata 4 Non-deterministic (NFA) Versus Deterministic Finite State Automata (DFA) 5 Regular Expresssions to NFA

### Lexical Analyzer Scanner

Lexical Analyzer Scanner ASU Textbook Chapter 3.1, 3.3, 3.4, 3.6, 3.7, 3.5 Tsan-sheng Hsu tshsu@iis.sinica.edu.tw http://www.iis.sinica.edu.tw/~tshsu 1 Main tasks Read the input characters and produce

### Lexical Analyzer Scanner

Lexical Analyzer Scanner ASU Textbook Chapter 3.1, 3.3, 3.4, 3.6, 3.7, 3.5 Tsan-sheng Hsu tshsu@iis.sinica.edu.tw http://www.iis.sinica.edu.tw/~tshsu 1 Main tasks Read the input characters and produce

### Lexical Analysis. Lexical analysis is the first phase of compilation: The file is converted from ASCII to tokens. It must be fast!

Lexical Analysis Lexical analysis is the first phase of compilation: The file is converted from ASCII to tokens. It must be fast! Compiler Passes Analysis of input program (front-end) character stream

### Implementation of Lexical Analysis

Written ssignments W assigned today Implementation of Lexical nalysis Lecture 4 Due in one week y 5pm Turn in In class In box outside 4 Gates Electronically Prof. iken CS 43 Lecture 4 Prof. iken CS 43

### Implementation of Lexical Analysis

Written ssignments W assigned today Implementation of Lexical nalysis Lecture 4 Due in one week :59pm Electronic hand-in Prof. iken CS 43 Lecture 4 Prof. iken CS 43 Lecture 4 2 Tips on uilding Large Systems

### Module 6 Lexical Phase - RE to DFA

Module 6 Lexical Phase - RE to DFA The objective of this module is to construct a minimized DFA from a regular expression. A NFA is typically easier to construct but string matching with a NFA is slower.

### Front End: Lexical Analysis. The Structure of a Compiler

Front End: Lexical Analysis The Structure of a Compiler Constructing a Lexical Analyser By hand: Identify lexemes in input and return tokens Automatically: Lexical-Analyser generator We will learn about

### Administrivia. Lexical Analysis. Lecture 2-4. Outline. The Structure of a Compiler. Informal sketch of lexical analysis. Issues in lexical analysis

dministrivia Lexical nalysis Lecture 2-4 Notes by G. Necula, with additions by P. Hilfinger Moving to 6 Evans on Wednesday HW available Pyth manual available on line. Please log into your account and electronically

### Lexical Analysis. COMP 524, Spring 2014 Bryan Ward

Lexical Analysis COMP 524, Spring 2014 Bryan Ward Based in part on slides and notes by J. Erickson, S. Krishnan, B. Brandenburg, S. Olivier, A. Block and others The Big Picture Character Stream Scanner

### COMP Logic for Computer Scientists. Lecture 25

COMP 1002 Logic for Computer Scientists Lecture 25 B 5 2 J Admin stuff Assignment 4 is posted. Due March 23 rd. Monday March 20 th office hours From 2:30pm to 3:30pm I need to attend something 2-2:30pm.

### 1. Draw the state graphs for the finite automata which accept sets of strings composed of zeros and ones which:

P R O B L E M S Finite Autom ata. Draw the state graphs for the finite automata which accept sets of strings composed of zeros and ones which: a) Are a multiple of three in length. b) End with the string

Nondeterministic Finite Automata (NFA): Nondeterministic Finite Automata (NFA) states of an automaton of this kind may or may not have a transition for each symbol in the alphabet, or can even have multiple

### FAdo: Interactive Tools for Learning Formal Computational Models

FAdo: Interactive Tools for Learning Formal Computational Models Rogério Reis Nelma Moreira DCC-FC& LIACC, Universidade do Porto R. do Campo Alegre 823, 4150 Porto, Portugal {rvr,nam}@ncc.up.pt Abstract

### Finite Automata Part Three

Finite Automata Part Three Recap from Last Time A language L is called a regular language if there exists a DFA D such that L( D) = L. NFAs An NFA is a Nondeterministic Finite Automaton Can have missing

### 1.0 Languages, Expressions, Automata

.0 Languages, Expressions, Automata Alphaet: Language: a finite set, typically a set of symols. a particular suset of the strings that can e made from the alphaet. ex: an alphaet of digits = {-,0,,2,3,4,5,6,7,8,9}

### 2. Lexical Analysis! Prof. O. Nierstrasz!

2. Lexical Analysis! Prof. O. Nierstrasz! Thanks to Jens Palsberg and Tony Hosking for their kind permission to reuse and adapt the CS132 and CS502 lecture notes.! http://www.cs.ucla.edu/~palsberg/! http://www.cs.purdue.edu/homes/hosking/!

### Course Project 2 Regular Expressions

Course Project 2 Regular Expressions CSE 30151 Spring 2017 Version of February 16, 2017 In this project, you ll write a regular expression matcher similar to grep, called mere (for match and echo using

### CS402 Theory of Automata Solved Subjective From Midterm Papers. MIDTERM SPRING 2012 CS402 Theory of Automata

Solved Subjective From Midterm Papers Dec 07,2012 MC100401285 Moaaz.pk@gmail.com Mc100401285@gmail.com PSMD01 MIDTERM SPRING 2012 Q. Point of Kleen Theory. Answer:- (Page 25) 1. If a language can be accepted

### Chapter 3 Lexical Analysis

Chapter 3 Lexical Analysis Outline Role of lexical analyzer Specification of tokens Recognition of tokens Lexical analyzer generator Finite automata Design of lexical analyzer generator The role of lexical

### R10 SET a) Construct a DFA that accepts an identifier of a C programming language. b) Differentiate between NFA and DFA?

R1 SET - 1 1. a) Construct a DFA that accepts an identifier of a C programming language. b) Differentiate between NFA and DFA? 2. a) Design a DFA that accepts the language over = {, 1} of all strings that

### Compiler course. Chapter 3 Lexical Analysis

Compiler course Chapter 3 Lexical Analysis 1 A. A. Pourhaji Kazem, Spring 2009 Outline Role of lexical analyzer Specification of tokens Recognition of tokens Lexical analyzer generator Finite automata

### Compiler Design. 2. Regular Expressions & Finite State Automata (FSA) Kanat Bolazar January 21, 2010

Compiler Design. Regular Expressions & Finite State Automata (FSA) Kanat Bolazar January 1, 010 Contents In these slides we will see 1.Introduction, Concepts and Notations.Regular Expressions, Regular

### CS415 Compilers. Lexical Analysis

CS415 Compilers Lexical Analysis These slides are based on slides copyrighted by Keith Cooper, Ken Kennedy & Linda Torczon at Rice University Lecture 7 1 Announcements First project and second homework

### Compiler Construction

Compiler Construction Lecture 2: Lexical Analysis I (Introduction) Thomas Noll Lehrstuhl für Informatik 2 (Software Modeling and Verification) noll@cs.rwth-aachen.de http://moves.rwth-aachen.de/teaching/ss-14/cc14/

### 8 ε. Figure 1: An NFA-ǫ

0 1 2 3 4 a 6 5 7 8 9 10 LECTURE 27 Figure 1: An FA-ǫ 12.1 ǫ Transitions In all automata that we have seen so far, every time that it has to change from one state to another, it must use one input symol.

### Regular Languages and Regular Expressions

Regular Languages and Regular Expressions According to our definition, a language is regular if there exists a finite state automaton that accepts it. Therefore every regular language can be described

### Finite Automata Part Three

Finite Automata Part Three Friday Four Square! Today at 4:15PM, Outside Gates. Announcements Problem Set 4 due right now. Problem Set 5 out, due next Friday, November 2. Play around with finite automata

### Formal Languages. Formal Languages

Regular expressions Formal Languages Finite state automata Deterministic Non-deterministic Review of BNF Introduction to Grammars Regular grammars Formal Languages, CS34 Fall2 BGRyder Formal Languages

### Lexical Analysis - 2

Lexical Analysis - 2 More regular expressions Finite Automata NFAs and DFAs Scanners JLex - a scanner generator 1 Regular Expressions in JLex Symbol - Meaning. Matches a single character (not newline)

### Zhizheng Zhang. Southeast University

Zhizheng Zhang Southeast University 2016/10/5 Lexical Analysis 1 1. The Role of Lexical Analyzer 2016/10/5 Lexical Analysis 2 2016/10/5 Lexical Analysis 3 Example. position = initial + rate * 60 2016/10/5

### Concepts Introduced in Chapter 3. Lexical Analysis. Lexical Analysis Terms. Attributes for Tokens

Concepts Introduced in Chapter 3 Lexical Analysis Regular Expressions (REs) Nondeterministic Finite Automata (NFA) Converting an RE to an NFA Deterministic Finite Automatic (DFA) Lexical Analysis Why separate

### 1. [5 points each] True or False. If the question is currently open, write O or Open.

University of Nevada, Las Vegas Computer Science 456/656 Spring 2018 Practice for the Final on May 9, 2018 The entire examination is 775 points. The real final will be much shorter. Name: No books, notes,

### T.E. (Computer Engineering) (Semester I) Examination, 2013 THEORY OF COMPUTATION (2008 Course)

*4459255* [4459] 255 Seat No. T.E. (Computer Engineering) (Semester I) Examination, 2013 THEY OF COMPUTATION (2008 Course) Time : 3 Hours Max. Marks : 100 Instructions : 1) Answers to the two Sections

### Kinder, Gentler Nation

Lexical Analysis Finite Automata (Part 2 of 2) # Kinder, Gentler Nation In our post drop-deadline world things get easier. While we re here: reading quiz. #2 Summary Regular expressions provide a concise

### CS Lecture 2. The Front End. Lecture 2 Lexical Analysis

CS 1622 Lecture 2 Lexical Analysis CS 1622 Lecture 2 1 Lecture 2 Review of last lecture and finish up overview The first compiler phase: lexical analysis Reading: Chapter 2 in text (by 1/18) CS 1622 Lecture

### [Lexical Analysis] Bikash Balami

1 [Lexical Analysis] Compiler Design and Construction (CSc 352) Compiled By Central Department of Computer Science and Information Technology (CDCSIT) Tribhuvan University, Kirtipur Kathmandu, Nepal 2

### CMSC 350: COMPILER DESIGN

Lecture 11 CMSC 350: COMPILER DESIGN see HW3 LLVMLITE SPECIFICATION Eisenberg CMSC 350: Compilers 2 Discussion: Defining a Language Premise: programming languages are purely formal objects We (as language

### Automata Theory TEST 1 Answers Max points: 156 Grade basis: 150 Median grade: 81%

Automata Theory TEST 1 Answers Max points: 156 Grade basis: 150 Median grade: 81% 1. (2 pts) See text. You can t be sloppy defining terms like this. You must show a bijection between the natural numbers

### Theory Bridge Exam Example Questions Version of June 6, 2008

Theory Bridge Exam Example Questions Version of June 6, 2008 This is a collection of sample theory bridge exam questions. This is just to get some idea of the format of the bridge exam and the level of

### lec3:nondeterministic finite state automata

lec3:nondeterministic finite state automata 1 1.introduction Nondeterminism is a useful concept that has great impact on the theory of computation. When the machine is in a given state and reads the next

### Finite Automata Part Three

Finite Automata Part Three Recap from Last Time A language L is called a regular language if there exists a DFA D such that L( D) = L. NFAs An NFA is a Nondeterministic Finite Automaton Can have missing

### Lexical Analysis. Finite Automata. (Part 2 of 2)

# Lexical Analysis Finite Automata (Part 2 of 2) PA0, PA Although we have included the tricky file ends without a newline testcases in previous years, students made good cases against them (e.g., they

### Lecture 3: Lexical Analysis

Lecture 3: Lexical Analysis COMP 524 Programming Language Concepts tephen Olivier January 2, 29 Based on notes by A. Block, N. Fisher, F. Hernandez-Campos, J. Prins and D. totts Goal of Lecture Character

### Complexity Theory. Compiled By : Hari Prasad Pokhrel Page 1 of 20. ioenotes.edu.np

Chapter 1: Introduction Introduction Purpose of the Theory of Computation: Develop formal mathematical models of computation that reflect real-world computers. Nowadays, the Theory of Computation can be

### WFST: Weighted Finite State Transducer. September 12, 2017 Prof. Marie Meteer

+ WFST: Weighted Finite State Transducer September 12, 217 Prof. Marie Meteer + FSAs: A recurring structure in speech 2 Phonetic HMM Viterbi trellis Language model Pronunciation modeling + The language

### QUESTION BANK. Formal Languages and Automata Theory(10CS56)

QUESTION BANK Formal Languages and Automata Theory(10CS56) Chapter 1 1. Define the following terms & explain with examples. i) Grammar ii) Language 2. Mention the difference between DFA, NFA and εnfa.