Exercise 1 Consider a language with the following tokens and token classes: ID ::= letter (letter|digit)* LT ::= " " shiftL ::= " >" dot ::= "." LP ::=

Slides:



Advertisements
Similar presentations
Regular Expressions and DFAs COP 3402 (Summer 2014)
Advertisements

Finite Automata CPSC 388 Ellen Walker Hiram College.
COMP-421 Compiler Design Presented by Dr Ioanna Dionysiou.
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,
Exercise: Build Lexical Analyzer Part For these two tokens, using longest match, where first has the priority: binaryToken ::= ( z |1) * ternaryToken ::=
1 Introduction to Computability Theory Lecture3: Regular Expressions Prof. Amos Israeli.
1 Introduction to Computability Theory Lecture12: Decidable Languages Prof. Amos Israeli.
1 Introduction to Computability Theory Lecture4: Regular Expressions Prof. Amos Israeli.
1 Introduction to Computability Theory Lecture3: Regular Expressions Prof. Amos Israeli.
Winter 2007SEG2101 Chapter 81 Chapter 8 Lexical Analysis.
Courtesy Costas Busch - RPI1 Non Deterministic Automata.
1 The scanning process Main goal: recognize words/tokens Snapshot: At any point in time, the scanner has read some input and is on the way to identifying.
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.
CS5371 Theory of Computation Lecture 6: Automata Theory IV (Regular Expression = NFA = DFA)
Fall 2006Costas Busch - RPI1 Non-Deterministic Finite Automata.
FSA Lecture 1 Finite State Machines. Creating a Automaton  Given a language L over an alphabet , design a deterministic finite automaton (DFA) M such.
Automating Construction of Lexers. Example in javacc TOKEN: { ( | | "_")* > | ( )* > | } SKIP: { " " | "\n" | "\t" } --> get automatically generated code.
1.Defs. a)Finite Automaton: A Finite Automaton ( FA ) has finite set of ‘states’ ( Q={q 0, q 1, q 2, ….. ) and its ‘control’ moves from state to state.
Costas Busch - LSU1 Non-Deterministic Finite Automata.
Lexical Analysis The Scanner Scanner 1. Introduction A scanner, sometimes called a lexical analyzer A scanner : – gets a stream of characters (source.
Regular Model Checking Ahmed Bouajjani,Benget Jonsson, Marcus Nillson and Tayssir Touili Moran Ben Tulila
1 CD5560 FABER Formal Languages, Automata and Models of Computation Lecture 7 Mälardalen University 2010.
CPSC 388 – Compiler Design and Construction Scanners – Finite State Automata.
Nondeterministic Finite Automata CS 130: Theory of Computation HMU textbook, Chapter 2 (Sec 2.3 & 2.5)
Theory of Computation, Feodor F. Dragan, Kent State University 1 Regular expressions: definition An algebraic equivalent to finite automata. We can build.
By: Er. Sukhwinder kaur.  What is Automata Theory? What is Automata Theory?  Alphabet and Strings Alphabet and Strings  Empty String Empty String 
어휘분석 (Lexical Analysis). Overview Main task: to read input characters and group them into “ tokens. ” Secondary tasks: –Skip comments and whitespace;
Exercise 1 Consider a language with the following tokens and token classes: ident ::= letter (letter|digit)* LT ::= " " shiftL ::= " >" dot ::= "." LP.
Lecture # 3 Chapter #3: Lexical Analysis. Role of Lexical Analyzer It is the first phase of compiler Its main task is to read the input characters and.
Automating Construction of Lexers. Example in javacc TOKEN: { ( | | "_")* > | ( )* > | } SKIP: { " " | "\n" | "\t" } --> get automatically generated code.
Cs3102: Theory of Computation Class 6: Pushdown Automata Spring 2010 University of Virginia David Evans TexPoint fonts used in EMF. Read the TexPoint manual.
2. Scanning College of Information and Communications Prof. Heejin Park.
CS412/413 Introduction to Compilers Radu Rugina Lecture 4: Lexical Analyzers 28 Jan 02.
CS 536 Fall Scanner Construction  Given a single string, automata and regular expressions retuned a Boolean answer: a given string is/is not in.
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.
CHAPTER 1 Regular Languages
Overview of Previous Lesson(s) Over View  Symbol tables are data structures that are used by compilers to hold information about source-program constructs.
CS 203: Introduction to Formal Languages and Automata
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
98 Nondeterministic Automata vs Deterministic Automata We learned that NFA is a convenient model for showing the relationships among regular grammars,
CS 154 Formal Languages and Computability February 11 Class Meeting Department of Computer Science San Jose State University Spring 2016 Instructor: Ron.
CS 404Ahmed Ezzat 1 CS 404 Introduction to Compiler Design Lecture 1 Ahmed Ezzat.
Regular Languages Chapter 1 Giorgi Japaridze Theory of Computability.
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,
Deterministic Finite Automata Nondeterministic Finite Automata.
Lecture 2 Compiler Design Lexical Analysis By lecturer Noor Dhia
Department of Software & Media Technology
Topic 3: Automata Theory 1. OutlineOutline Finite state machine, Regular expressions, DFA, NDFA, and their equivalence, Grammars and Chomsky hierarchy.
Deterministic Finite-State Machine (or Deterministic Finite Automaton) A DFA is a 5-tuple, (S, Σ, T, s, A), consisting of: S: a finite set of states Σ:
CIS Automata and Formal Languages – Pei Wang
CS314 – Section 5 Recitation 2
Finite automate.
Foundations of Computing Science
Non Deterministic Automata
Deterministic Finite Automata
Finite Automata & Regular Languages
Chapter 2 FINITE AUTOMATA.
Deterministic Finite Automata
4. Properties of Regular Languages
Non-Deterministic Finite Automata
Non Deterministic Automata
FORMAL LANGUAGES, AUTOMATA, AND COMPUTABILITY
CS21 Decidability and Tractability
Chapter 1 Regular Language
Announcements - P1 part 1 due Today - P1 part 2 due on Friday Feb 1st
Presentation transcript:

Exercise 1 Consider a language with the following tokens and token classes: ID ::= letter (letter|digit)* LT ::= " " shiftL ::= " >" dot ::= "." LP ::= "(" RP ::= ")" Give a sequence of tokens for the following character sequence, applying the longest match rule: (List >)(myL).headhead Note that the input sequence contains no space character

Exercise 2 Find a regular expression that generates all alternating sequences of 0 and 1 with arbitrary length (including lengths zero, one, two,...). For example, the alternating sequences of length one are 0 and 1, length two are 01 and 10, length three are 010 and 101. Note that no two adjacent character can be the same in an alternating sequence.

Exercise 3 a) Describe any algorithm using a single unbounded integer counter that determines if a string consists of well-nested parentheses b) Construct a DFA (deterministic finite-state automaton) for the language L of well-nested parenthesis of nesting depth at most 3. For example, ε, ()(), (()(())) and (()())()() should be in L, but not (((()))) nor (()(()(()))), nor ())).

Exercise 4 Find two equivalent states in the automaton, and merge them to produce a smaller automaton that recognizes the same language. Repeat until there are no longer equivalent states. Recall that the general algorithm for minimizing finite automata works in reverse. First, find all pairs of inequivalent states. States X, Y are inequivalent if X is final and Y is not, or (by iteration) if and and X’ and Y’ are inequivalent. After this iteration ceases to find new pairs of inequivalent states, then X, Y are equivalent, if they are not inequivalent.

Exercise 5 Let tail be a function that returns all the symbols of a string except the last one. For example tail(mama)=mam tail is undefined for an empty string. If L 1  A*, then TAIL(L 1 ) applies the function to all non-empty words in L 1, ignoring  if it is in L 1 : TAIL(L 1 ) = { v  A* |  a  A. va  L 1 } TAIL({aba,aaaa,bb,  }) = {ab,aaa,b} L(r) denotes the language of a regular expression r. Then TAIL(L(abba|ba*|ab*)) = L(ba*|ab*|  ) Tasks: Prove that if language L 1 is regular, then so is TAIL(L 1 ) Give an algorithm that, given a regular expression r for L 1, computes a regular expression rtail(r) for language TAIL(L 1 )

Exercise 5 - solution

Approach II –First construct a regular expression for tail(L) using the following construction –Convert the regular expression to an automata

Exercise 6. Given NFA A, find first(L(A)) Compute the set of first symbols of words accepted by the following non-deterministic finite state machine with epsilon transitions: Describe an algorithm that solves this problem given a given NFA

More Questions Find automaton or regular expression for: –Any sequence of open and closed parentheses of even length? –as many digits before as after decimal point? –Sequence of balanced parentheses ( ( () ) ())- balanced ( ) ) ( ( ) - not balanced –Comment as a sequence of space,LF,TAB, and comments from // until LF –Nested comments like /*... /* */ … */

Automaton that Claims to Recognize { a n b n | n >= 0 } Make the automaton deterministic Let the resulting DFA have K states, |Q|=K Feed it a, aa, aaa, …. Let q i be state after reading a i q 0, q 1, q 2,..., q K This sequence has length K+1 -> a state must repeat q i = q i+p p > 0 Then the automaton should accept a i+p b i+p. But then it must also accept a i b i+p because it is in state after reading a i as after a i+p. So it does not accept the given language.

Limitations of Regular Languages Every automaton can be made deterministic Automaton has finite memory, cannot count Deterministic automaton from a given state behaves always the same If a string is too long, deterministic automaton will repeat its behavior

Pumping Lemma If L is a regular language, then there exists a positive integer p (the pumping length) such that every string s  L for which |s| ≥ p, can be partitioned into three pieces, s = x y z, such that |y| > 0 |xy| ≤ p ∀ i ≥ 0. xy i z  L Let’s try again: { a n b n | n >= 0 }

Automata are Limited Let us use grammars!