Exercise: (aa)* | (aaa)* Construct automaton and eliminate epsilons.

Slides:



Advertisements
Similar presentations
4b Lexical analysis Finite Automata
Advertisements

Nondeterministic Finite Automata CS 130: Theory of Computation HMU textbook, Chapter 2 (Sec 2.3 & 2.5)
Finite Automata CPSC 388 Ellen Walker Hiram College.
1 1 CDT314 FABER Formal Languages, Automata and Models of Computation Lecture 3 School of Innovation, Design and Engineering Mälardalen University 2012.
Pushdown Automata Chapter 12. Recognizing Context-Free Languages Two notions of recognition: (1) Say yes or no, just like with FSMs (2) Say yes or no,
NFAs Sipser 1.2 (pages 47–54). CS 311 Fall Recall… Last time we showed that the class of regular languages is closed under: –Complement –Union.
Regular operations Sipser 1.1 (pages 44 – 47). CS 311 Mount Holyoke College 2 Building languages If L is a language, then its complement is L’ = {w |
Finite Automata Great Theoretical Ideas In Computer Science Anupam Gupta Danny Sleator CS Fall 2010 Lecture 20Oct 28, 2010Carnegie Mellon University.
NFAs Sipser 1.2 (pages 47–54). CS 311 Mount Holyoke College 2 Recall… Last time we showed that the class of regular languages is closed under: –Complement.
1 Introduction to Computability Theory Discussion1: Non-Deterministic Finite Automatons Prof. Amos Israeli.
1 FORMAL LANGUAGES, AUTOMATA AND COMPUTABILITY (For next time: Read Chapter 1.3 of the book)
Finite Automata and Non Determinism
Finite Automata Finite-state machine with no output. FA consists of States, Transitions between states FA is a 5-tuple Example! A string x is recognized.
1 The scanning process Goal: automate the process Idea: –Start with an RE –Build a DFA How? –We can build a non-deterministic finite automaton (Thompson's.
CS 490: Automata and Language Theory Daniel Firpo Spring 2003.
Automating Construction of Lexers. Example in javacc TOKEN: { ( | | "_")* > | ( )* > | } SKIP: { " " | "\n" | "\t" } --> get automatically generated code.
Finite State Machines Data Structures and Algorithms for Information Processing 1.
Regular Languages A language is regular over  if it can be built from ;, {  }, and { a } for every a 2 , using operators union ( [ ), concatenation.
Regular Model Checking Ahmed Bouajjani,Benget Jonsson, Marcus Nillson and Tayssir Touili Moran Ben Tulila
CPSC 388 – Compiler Design and Construction Scanners – Finite State Automata.
Finite-State Machines with No Output Longin Jan Latecki Temple University Based on Slides by Elsa L Gunter, NJIT, and by Costas Busch Costas Busch.
Finite-State Machines with No Output
Nondeterministic Finite Automata CS 130: Theory of Computation HMU textbook, Chapter 2 (Sec 2.3 & 2.5)
Introduction to CS Theory Lecture 3 – Regular Languages Piotr Faliszewski
1 Regular Expressions. 2 Regular expressions describe regular languages Example: describes the language.
Automating Construction of Lexers. Example in javacc TOKEN: { ( | | "_")* > | ( )* > | } SKIP: { " " | "\n" | "\t" } --> get automatically generated code.
Lecture 05: Theory of Automata:08 Kleene’s Theorem and NFA.
2. Scanning College of Information and Communications Prof. Heejin Park.
Overview of Previous Lesson(s) Over View  An NFA accepts a string if the symbols of the string specify a path from the start to an accepting state.
4b 4b Lexical analysis Finite Automata. Finite Automata (FA) FA also called Finite State Machine (FSM) –Abstract model of a computing entity. –Decides.
1 CD5560 FABER Formal Languages, Automata and Models of Computation Lecture 3 Mälardalen University 2010.
Lexer input and Output i d 3 = 0 LF w i d 3 = 0 LF w id3 = 0 while ( id3 < 10 ) id3 = 0 while ( id3 < 10 ) lexer Stream of Char-s ( lazy List[Char] ) class.
Overview of Previous Lesson(s) Over View  Symbol tables are data structures that are used by compilers to hold information about source-program constructs.
Fundamentals of Informatics
CMSC 330: Organization of Programming Languages Theory of Regular Expressions Finite Automata.
CS 208: Computing Theory Assoc. Prof. Dr. Brahim Hnich Faculty of Computer Sciences Izmir University of Economics.
Exercise 1 Consider a language with the following tokens and token classes: ID ::= letter (letter|digit)* LT ::= " " shiftL ::= " >" dot ::= "." LP ::=
Exercise Solution for Exercise (a) {1,2} {3,4} a b {6} a {5,6,1} {6,2} {4} {3} {5,6} { } b a b a a b b a a b a,b b b a.
UNIT - I Formal Language and Regular Expressions: Languages Definition regular expressions Regular sets identity rules. Finite Automata: DFA NFA NFA with.
Chapter 2 Scanning. Dr.Manal AbdulazizCS463 Ch22 The Scanning Process Lexical analysis or scanning has the task of reading the source program as a file.
using Deterministic Finite Automata & Nondeterministic Finite Automata
Overview of Previous Lesson(s) Over View  A token is a pair consisting of a token name and an optional attribute value.  A pattern is a description.
Finite Automata Great Theoretical Ideas In Computer Science Victor Adamchik Danny Sleator CS Spring 2010 Lecture 20Mar 30, 2010Carnegie Mellon.
LECTURE 5 Scanning. SYNTAX ANALYSIS We know from our previous lectures that the process of verifying the syntax of the program is performed in two stages:
Regular Languages Chapter 1 Giorgi Japaridze Theory of Computability.
Tree Automata First: A reminder on Automata on words Typing semistructured data.
Pushdown Automata Chapter 12. Recognizing Context-Free Languages Two notions of recognition: (1) Say yes or no, just like with FSMs (2) Say yes or no,
What do we know? DFA = NFA =  -NFA We have seen algorithms to transform DFA to NFA (trival) NFA to  NFA (trivial) NFA to DFA (subset construction)
Deterministic Finite Automata Nondeterministic Finite Automata.
Lecture 2 Compiler Design Lexical Analysis By lecturer Noor Dhia
1/29/02CSE460 - MSU1 Nondeterminism-NFA Section 4.1 of Martin Textbook CSE460 – Computability & Formal Language Theory Comp. Science & Engineering Michigan.
Recap: Nondeterministic Finite Automaton (NFA) A deterministic finite automaton (NFA) is a 5-tuple (Q, , ,s,F) where: Q is a finite set of elements called.
WELCOME TO A JOURNEY TO CS419 Dr. Hussien Sharaf Dr. Mohammad Nassef Department of Computer Science, Faculty of Computers and Information, Cairo University.
Language Recognition MSU CSE 260.
CIS Automata and Formal Languages – Pei Wang
Finite automate.
Lecture 2 Lexical Analysis
Lexical analysis Finite Automata
Two issues in lexical analysis
Recognizer for a Language
Chapter 2 FINITE AUTOMATA.
Non-Determinism 12CS45 Finite Automata.
COSC 3340: Introduction to Theory of Computation
CSE322 CONSTRUCTION OF FINITE AUTOMATA EQUIVALENT TO REGULAR EXPRESSION Lecture #9.
4. Properties of Regular Languages
Non-Deterministic Finite Automata
4b Lexical analysis Finite Automata
4b Lexical analysis Finite Automata
Finite-State Machines with No Output
CHAPTER 1 Regular Languages
Presentation transcript:

Exercise: (aa)* | (aaa)* Construct automaton and eliminate epsilons

Determinization: Subset Construction –keep track of a set of all possible states in which automaton could be –view this finite set as one state of new automaton Apply to (aa)* | (aaa)* –can also eliminate epsilons during determinization

Remark: Relations and Functions Relation r  B x C r = {..., (b,c1), (b,c2),... } Corresponding function: f : B -> P (C)2 C f = {... (b,{c1,c2})... } f(b) = { c | (b,c)  r } Given a state, next-state function returns the set of new states –for deterministic automaton, the set has exactly 1 element

Running NFA in Scala def  (q : State, a : Char) : Set[States] = {... } def  '(S : Set[States], a : Char) : Set[States] = { for (q1 <- S, q2 <-  (q1,a)) yield q2 } def accepts(input : MyStream[Char]) : Boolean = { var S : Set[State] = Set(q0) // current set of states while (!input.EOF) { val a = input.current S =  '(S,a) // next set of states } !(S.intersect(finalStates).isEmpty) }

Minimization: Merge States Only limit the freedom to merge (prove !=) if we have evidence that they behave differently (final/non-final, or leading to states shown !=) When we run out of evidence, merge the rest –merge the states in the previous automaton for (aa)* | (aaa)* Very special case: if successors lead to same states on all symbols, we know immediately we can merge –but there are cases when we can merge even if successors lead to merged states

Minimization for example Start from all accepting disequal all non-accepting. Result: only {1} and {2,4} are merged. Here, the special case is sufficient, but in general, we need the above construction (take two copies of same automaton and union them).

Clarifications Non-deterministic state machines where a transition on some input is not defined We can apply determinization, and we will end up with –singleton sets –empty set (this becomes trap state) Trap state: a state that has self-loops for all symbols, and is non-accepting.

Exercise done on board left for self-study

Complementation, Inclusion, Equivalence Can compute complement: switch accepting and non-accepting states in deterministic machine (wrong for non-deterministic) We can compute intersection, inclusion, equivalence Intersection: complement union of complements Set difference: intersection with complement Inclusion: emptiness of set difference Equivalence: two inclusions

Short Demo Automated interactive tool for practicing finite-state automata constructions See home page of Damien Zufferey

Exercise: first, nullable For each of the following languages find the first set. Determine if the language is nullable. –(a|b)* (b|d) ((c|a|d)* | a*) –language given by automaton:

Automated Construction of Lexers –let r 1, r 2,..., r n be regular expressions for token classes –consider combined regular expression: (r 1 | r 2 |... | r n )* –recursively map a regular expression to a non-deterministic automaton –eliminate epsilon transitions and determinize –optionally minimize A 3 to reduce its size  A 4 –the result only checks that input can be split into tokens, does not say how to split it

From (r 1 |r 2 |...|r n )* to a Lexer Construct machine for each r i labelling different accepting states differently for each accepting state of r i specify the token class i being recognized longest match rule: remember last token and input position for a last accepted state when no accepting state can be reached (effectively: when we are in a trap state) –revert position to last accepted state –return last accepted token

Exercise: Build Lexical Analyzer Part For these two tokens, using longest match, where first has the priority: binaryToken ::= ( z |1) * ternaryToken ::= (0|1|2) * 1111z1021z1 

Lexical Analyzer binaryToken ::= ( z |1) * ternaryToken ::= (0|1|2) * 1111z1021z1 