CSCE 5400 ASSIGNMENT #1 SOLUTION

Size: px
Start display at page:

Download "CSCE 5400 ASSIGNMENT #1 SOLUTION"

Transcription

1 CSCE 5400 ASSIGNMENT #1 SOLUTION 1. Design deterministic finite automata to recognize the languages below. Test your DFA s using Prolog on the indicated strings in the language, as well as some strings which are not in the language. (a) L = {w w is a floating point constant in a typical programming language (e.g. C++)}. Example strings include 10.87, 2.0E7, 6.625E 27, etc. Script started on Tue 11 Sep :42:50 AM CDT brb0164@faculty% cat as2f18-1a.pro delta(q0, [- X]) :- delta(q1, X). delta(q0, [D X]) :- D >= 0, D =< 9, delta(q2, X). delta(q1, [D X]) :- D >= 0, D =< 9, delta(q2, X). delta(q2, [. X]) :- delta(q3, X). delta(q2, [D X]) :- D >= 0, D =< 9, delta(q2, X). delta(q3, [D X]) :- D >= 0, D =< 9, delta(q4, X). delta(q4, [e X]) :- delta(q5, X). delta(q4, [D X]) :- D >= 0, D =< 9, delta(q4, X). delta(q4, []). /* q4 is a final state. */ delta(q5, [+ X]) :- delta(q6, X). delta(q5, [- X]) :- delta(q6, X). delta(q5, [D X]) :- D >= 0, D =< 9, delta(q7, X). delta(q6, [D X]) :- D >= 0, D =< 9, delta(q7, X). delta(q7, [D X]) :- D >= 0, D =< 9, delta(q7, X). delta(q7, []). /* q7 is a final state. */ brb0164@faculty% gprolog?- consult( as2f18-1a ). compiling /home/brb0164/csce5400/prolog/as2f18-1a.pro for byte code... /home/brb0164/csce5400/prolog/as2f18-1a.pro compiled, 15 lines read bytes writ?- delta(q0, [-, 1, 0,., 8, 7]).?- delta(q0, [2,., 0, e, 7]).?- delta(q0, [6,., 6, 2, 5, e, -, 2, 7]).

2 Script done on Tue 11 Sep :43:00 AM CDT (b) L = {w w {0, 1}, w contains either three consecutive 0 s or three consecutive 1 s}. Example strings include 0111, 0000 and Script started on Tue 11 Sep :02:20 AM CDT brb0164@faculty% cat as2f18-1b.pro delta(q0, [0 X]) :- delta(q1, X). delta(q0, [1 X]) :- delta(q3, X). delta(q1, [0 X]) :- delta(q2, X). delta(q1, [1 X]) :- delta(q3, X). delta(q2, [0 X]) :- delta(q5, X). delta(q2, [1 X]) :- delta(q3, X). delta(q3, [0 X]) :- delta(q1, X). delta(q3, [1 X]) :- delta(q4, X). delta(q4, [0 X]) :- delta(q1, X). delta(q4, [1 X]) :- delta(q5, X). delta(q5, [0 X]) :- delta(q5, X). delta(q5, [1 X]) :- delta(q5, X). delta(q5, []). brb0164@faculty% gprolog?- consult( as2f18-1b ). compiling /home/brb0164/csce5400/prolog/as2f18-1b.pro for byte code... /home/brb0164/csce5400/prolog/as2f18-1b.pro compiled, 13 lines read bytes writ?- delta(q0, [0, 1, 1, 1]).?- delta(q0, [0, 0, 0, 0]).?- delta(q0, [0, 0, 0, 1, 1, 1, 0]).

3 Script done on Tue 11 Sep :03:47 AM CDT 2. Design nondeterministic finite automata to recognize the languages below. Test your NFA s using Prolog on the indicated strings in the language, as well as some strings which are not in the language. (a) L = {w w {0, 1}, some two 0 s are separated by a string whose length is 4i, for some i 0}. Example strings include (i = 0), (i = 1), (i = 2), etc. Script started on Tue 11 Sep :19:20 AM CDT brb0164@faculty% cat as2f18-2a.pro delta(q0, [0 X]) :- delta(q0, X). delta(q0, [0 X]) :- delta(q1, X). delta(q0, [1 X]) :- delta(q0, X). delta(q1, [0 X]) :- delta(q2, X). /* previous 0 is first in pair */ delta(q1, [0 X]) :- delta(q5, X). /* previous 0 and current 0 4i apart */ delta(q1, [1 X]) :- delta(q2, X). delta(q2, [0 X]) :- delta(q3, X). /* 1st symbol after first 0 */ delta(q2, [1 X]) :- delta(q3, X). delta(q3, [0 X]) :- delta(q4, X). /* 2nd symbol after first 0 */ delta(q3, [1 X]) :- delta(q4, X). delta(q4, [0 X]) :- delta(q1, X). /* 3rd symbol after first 0 */ delta(q4, [1 X]) :- delta(q1, X). delta(q5, [0 X]) :- delta(q5, X). delta(q5, [1 X]) :- delta(q5, X). delta(q5, []). brb0164@faculty:~/csce5400/prolog$ gprolog?- consult( as2f18-2a ). compiling /home/brb0164/csce5400/prolog/as2f18-2a.pro for byte code... /home/brb0164/csce5400/prolog/as2f18-2a.pro compiled, 15 lines read bytes writ?- delta(q0, [1, 0, 1, 0, 0, 1]).

4 ?- delta(q0, [0, 1, 1, 1, 1, 0]).?- delta(q0, [0, 1, 0, 1, 0, 1, 1, 0, 1, 0]). (4 ms) Script done on Tue 11 Sep :19:30 AM CDT (b) L = {w w a b c, the number of a s plus the number of b s is odd or the number of b s plus the number of c s is even}. Example strings include b, cc, aaabbcc, etc. Script started on Wed 11 Sep :05:16 PM CDT brb0164@faculty% cat as2f18-2b.pro delta(q0, [a X]) :- delta(q1, X). delta(q0, [b X]) :- delta(q6, X). delta(q0, [c X]) :- delta(q11, X). delta(q0, []). delta(q1, [a X]) :- delta(q2, X). /* # a s is odd */ delta(q1, [b X]) :- delta(q3, X). delta(q1, [c X]) :- delta(q5, X). delta(q1, []). delta(q2, [a X]) :- delta(q1, X). /* # a s is even */ delta(q2, [b X]) :- delta(q6, X). delta(q2, [c X]) :- delta(q11, X). delta(q2, []). delta(q3, [b X]) :- delta(q4, X). /* # a s is odd, # b s is odd */ delta(q3, [c X]) :- delta(q6, X). delta(q4, [b X]) :- delta(q3, X). /* # a s is odd, # b s is even */ delta(q4, [c X]) :- delta(q5, X). delta(q4, []). delta(q5, [c X]) :- delta(q5, X). delta(q5, []). delta(q6, [b X]) :- delta(q7, X). /* # a s is even, # b s is odd */ delta(q6, [c X]) :- delta(q8, X). delta(q6, []). delta(q7, [b X]) :- delta(q6, X). /* # a s is even, # b s is even */ delta(q7, [c X]) :- delta(q10, X). delta(q7, []). delta(q8, [c X]) :- delta(q9, X). /* # b s is odd, # c s is odd */ delta(q8, []). delta(q9, [c X]) :- delta(q8, X). /* # b s is odd, # c s is even */

5 delta(q10, [c X]) :- delta(q11, X). /* # b s is even, # c s is even */ delta(q10, []). delta(q11, [c X]) :- delta(q10, X). /* # b s is even, # c s is odd */ brb0164@faculty% gprolog?- consult( as2f18-2b ). compiling /home/brb0164/csce5400/prolog/as2f18-2b.pro for byte code... /home/brb0164/csce5400/prolog/as2f18-2b.pro compiled, 31 lines read bytes writ?- delta(q0, [b]).?- delta(q0, [c, c]).?- delta(q0, [a, a, a, b, b, c, c]).?- delta(q0, [a, a, c]). no Script done on Wed 11 Sep :28:24 PM CDT 3. Convert the NFA M=({q 1, q 2, q 3 }), {a, b}, δ,q 1, {q 2 }), where δ is: δ (q 1, ɛ) = {q 2 } δ (q 1, a) = {q 3 } δ (q 2, a) = {q 1 } δ (q 3, a) = {q 2 } δ (q 3, b) = {q 2, q 3 } into an equivalent DFA. Taking the e-closure, we get: d(q1, a) = {q1, q3} Let q4 = {q1, q3}, q5 = {q2, q3}, and q6 = {q1, q2}. Then:

6 d(q1, a) = q4 d(q2, a) = q1 d(q3, a) = q2 d(q3, b) = q5 d(q4, a) = q5 d(q4, b) = q5 d(q5, a) = q6 d(q5, b) = q5 d(q6, a) = q4 Final states are q1, q5 and q6. 4. A deterministic finite transducer is a 6-tuple M=(Q,Σ,,δ,q 0,F ), where 1) Q is a finite set of states. 2) Σ is a finite input alphabet. 3) is a finite output alphabet. 4) δ is a mapping from Q (Σ {ε}) to Q. Determinism implies that 1) either δ(q, a) contains at most one element for each a Σ, and δ(q, ε) =, or 2) δ(q, ε) contains one element, and for all a Σ, δ(q, a) =. That is, there can be no moves involving a choice between making an ε-move or consuming an input symbol. 5) q 0 Q is the initial state. 6) F Q is the set of final states. Note that a finite transducer accepts its input when it reaches a final state and outputs a string over for each input string accepted. (a) Construct a deterministic finite transducer whose input is of the form ( ) + $, the set of all ternary numbers terminated with a $, and whose output is the residue modulo 5 of the input. For example, on input 210$, the output is 1, on input $, the output is 4, and on input 11110$, the output is 0. (b) Test your DFT using Prolog on the above example strings in the language. Note that a DFT transition of the form δ (q 0, a) = (q 1, bc) is written in Prolog as: delta(q0,[a RestOfInput], InitialOutput, FinalOutput) :- append(initialoutput, [b, c], NewOutput), To run on the first string above, use the goal: delta(q0, [2, 1, 0, $ ], [], Output). The others are similar. Script started on Wed 11 Sep :32:28 PM CDT brb0164@faculty% cat dftf18-4.pro delta(p0, [0 RestOfInput], InitialOutput, FinalOutput) :-

7 delta(q0, RestOfInput, NewOutput, FinalOutput). delta(p0, [1 RestOfInput], InitialOutput, FinalOutput) :- delta(p0, [2 RestOfInput], InitialOutput, FinalOutput) :- delta(q2, RestOfInput, NewOutput, FinalOutput). delta(q0, [0 RestOfInput], InitialOutput, FinalOutput) :- delta(q0, RestOfInput, NewOutput, FinalOutput). delta(q0, [1 RestOfInput], InitialOutput, FinalOutput) :- delta(q0, [2 RestOfInput], InitialOutput, FinalOutput) :- delta(q2, RestOfInput, NewOutput, FinalOutput). delta(q0, [ $ RestOfInput], InitialOutput, FinalOutput) :- append(initialoutput, [0], NewOutput), delta(q1, [0 RestOfInput], InitialOutput, FinalOutput) :- delta(q3, RestOfInput, NewOutput, FinalOutput). delta(q1, [1 RestOfInput], InitialOutput, FinalOutput) :- delta(q4, RestOfInput, NewOutput, FinalOutput). delta(q1, [2 RestOfInput], InitialOutput, FinalOutput) :- delta(q0, RestOfInput, NewOutput, FinalOutput). delta(q1, [ $ RestOfInput], InitialOutput, FinalOutput) :- append(initialoutput, [1], NewOutput), delta(q2, [0 RestOfInput], InitialOutput, FinalOutput) :- delta(q2, [1 RestOfInput], InitialOutput, FinalOutput) :- delta(q2, RestOfInput, NewOutput, FinalOutput). delta(q2, [2 RestOfInput], InitialOutput, FinalOutput) :- delta(q3, RestOfInput, NewOutput, FinalOutput). delta(q2, [ $ RestOfInput], InitialOutput, FinalOutput) :- append(initialoutput, [2], NewOutput), delta(q3, [0 RestOfInput], InitialOutput, FinalOutput) :- delta(q4, RestOfInput, NewOutput, FinalOutput). delta(q3, [1 RestOfInput], InitialOutput, FinalOutput) :-

8 delta(q0, RestOfInput, NewOutput, FinalOutput). delta(q3, [2 RestOfInput], InitialOutput, FinalOutput) :- delta(q3, [ $ RestOfInput], InitialOutput, FinalOutput) :- append(initialoutput, [3], NewOutput), delta(q4, [0 RestOfInput], InitialOutput, FinalOutput) :- delta(q2, RestOfInput, NewOutput, FinalOutput). delta(q4, [1 RestOfInput], InitialOutput, FinalOutput) :- delta(q3, RestOfInput, NewOutput, FinalOutput). delta(q4, [2 RestOfInput], InitialOutput, FinalOutput) :- delta(q4, RestOfInput, NewOutput, FinalOutput). delta(q4, [ $ RestOfInput], InitialOutput, FinalOutput) :- append(initialoutput, [4], NewOutput), delta(pf, [], Output, Output). /* pf is the final state */ brb0164@faculty% gprolog?- consult( dftf18-4 ). compiling /home/brb0164/csce5400/prolog/dftf18-4.pro for byte code... /home/brb0164/csce5400/prolog/dftf18-4.pro compiled, 76 lines read bytes written, (4 ms)?- delta(p0, [2, 1, 0, $ ], [], Output). Output = [1]??- delta(p0, [0, 0, 1, 1, 2, 2, $ ], [], Output). Output = [4]??- delta(p0, [1, 1, 1, 1, 0, $ ], [], Output). Output = [0]?

9 Script done on Wed 11 Sep :32:55 PM CDT

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

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

More information

6 NFA and Regular Expressions

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

More information

CS 310: State Transition Diagrams

CS 310: State Transition Diagrams CS 30: State Transition Diagrams Stefan D. Bruda Winter 207 STATE TRANSITION DIAGRAMS Finite directed graph Edges (transitions) labeled with symbols from an alphabet Nodes (states) labeled only for convenience

More information

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

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

More information

CSE 105 THEORY OF COMPUTATION

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

More information

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

More information

Lexical Analysis. Implementation: Finite Automata

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)

More information

lec3:nondeterministic finite state automata

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

More information

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

More information

I have read and understand all of the instructions below, and I will obey the Academic Honor Code.

I have read and understand all of the instructions below, and I will obey the Academic Honor Code. Midterm Exam CS 341-451: Foundations of Computer Science II Fall 2014, elearning section Prof. Marvin K. Nakayama Print family (or last) name: Print given (or first) name: I have read and understand all

More information

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

More information

Front End: Lexical Analysis. The Structure of a Compiler

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

More information

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

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/

More information

CT32 COMPUTER NETWORKS DEC 2015

CT32 COMPUTER NETWORKS DEC 2015 Q.2 a. Using the principle of mathematical induction, prove that (10 (2n-1) +1) is divisible by 11 for all n N (8) Let P(n): (10 (2n-1) +1) is divisible by 11 For n = 1, the given expression becomes (10

More information

CS 181 B&C EXAM #1 NAME. You have 90 minutes to complete this exam. You may assume without proof any statement proved in class.

CS 181 B&C EXAM #1 NAME. You have 90 minutes to complete this exam. You may assume without proof any statement proved in class. CS 8 B&C EXAM # NAME SPRING 204 UCLA ID You have 90 minutes to complete this exam. You may assume without proof any statement proved in class. Give a simple verbal description of the language recognized

More information

Compiler Construction

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

More information

ECS 120 Lesson 7 Regular Expressions, Pt. 1

ECS 120 Lesson 7 Regular Expressions, Pt. 1 ECS 120 Lesson 7 Regular Expressions, Pt. 1 Oliver Kreylos Friday, April 13th, 2001 1 Outline Thus far, we have been discussing one way to specify a (regular) language: Giving a machine that reads a word

More information

Converting a DFA to a Regular Expression JP

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

More information

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

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

More information

Theory of Computation Dr. Weiss Extra Practice Exam Solutions

Theory of Computation Dr. Weiss Extra Practice Exam Solutions Name: of 7 Theory of Computation Dr. Weiss Extra Practice Exam Solutions Directions: Answer the questions as well as you can. Partial credit will be given, so show your work where appropriate. Try to be

More information

Regular Languages and Regular Expressions

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

More information

Announcements! P1 part 1 due next Tuesday P1 part 2 due next Friday

Announcements! P1 part 1 due next Tuesday P1 part 2 due next Friday Announcements! P1 part 1 due next Tuesday P1 part 2 due next Friday 1 Finite-state machines CS 536 Last time! A compiler is a recognizer of language S (Source) a translator from S to T (Target) a program

More information

Lexical Analysis. Prof. James L. Frankel Harvard University

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

More information

Formal Languages and Automata

Formal Languages and Automata Mobile Computing and Software Engineering p. 1/3 Formal Languages and Automata Chapter 3 Regular languages and Regular Grammars Chuan-Ming Liu cmliu@csie.ntut.edu.tw Department of Computer Science and

More information

CSE 431S Scanning. Washington University Spring 2013

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

More information

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

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

More information

Actually talking about Turing machines this time

Actually talking about Turing machines this time Actually talking about Turing machines this time 10/25/17 (Using slides adapted from the book) Administrivia HW due now (Pumping lemma for context-free languages) HW due Friday (Building TMs) Exam 2 out

More information

Assignment 1 (Lexical Analyzer)

Assignment 1 (Lexical Analyzer) Assignment 1 (Lexical Analyzer) Compiler Construction CS4435 (Spring 2015) University of Lahore Maryam Bashir Assigned: Saturday, March 14, 2015. Due: Monday 23rd March 2015 11:59 PM Lexical analysis Lexical

More information

Assignment 1 (Lexical Analyzer)

Assignment 1 (Lexical Analyzer) Assignment 1 (Lexical Analyzer) Compiler Construction CS4435 (Spring 2015) University of Lahore Maryam Bashir Assigned: Saturday, March 14, 2015. Due: Monday 23rd March 2015 11:59 PM Lexical analysis Lexical

More information

Midterm Exam II CIS 341: Foundations of Computer Science II Spring 2006, day section Prof. Marvin K. Nakayama

Midterm Exam II CIS 341: Foundations of Computer Science II Spring 2006, day section Prof. Marvin K. Nakayama Midterm Exam II CIS 341: Foundations of Computer Science II Spring 2006, day section Prof. Marvin K. Nakayama Print family (or last) name: Print given (or first) name: I have read and understand all of

More information

Midterm I (Solutions) CS164, Spring 2002

Midterm I (Solutions) CS164, Spring 2002 Midterm I (Solutions) CS164, Spring 2002 February 28, 2002 Please read all instructions (including these) carefully. There are 9 pages in this exam and 5 questions, each with multiple parts. Some questions

More information

ECS 120 Lesson 16 Turing Machines, Pt. 2

ECS 120 Lesson 16 Turing Machines, Pt. 2 ECS 120 Lesson 16 Turing Machines, Pt. 2 Oliver Kreylos Friday, May 4th, 2001 In the last lesson, we looked at Turing Machines, their differences to finite state machines and pushdown automata, and their

More information

Regular Expression Constrained Sequence Alignment

Regular Expression Constrained Sequence Alignment Regular Expression Constrained Sequence Alignment By Abdullah N. Arslan Department of Computer science University of Vermont Presented by Tomer Heber & Raz Nissim otivation When comparing two proteins,

More information

CMPE 4003 Formal Languages & Automata Theory Project Due May 15, 2010.

CMPE 4003 Formal Languages & Automata Theory Project Due May 15, 2010. CMPE 4003 Formal Languages & Automata Theory Project Due May 15, 2010. Regular Expression Engine (This document contains 5 pages. Read carefully all parts of this document.) Introduction In this project,

More information

Dixita Kagathara Page 1

Dixita Kagathara Page 1 2014 Sem - VII Lexical Analysis 1) Role of lexical analysis and its issues. The lexical analyzer is the first phase of compiler. Its main task is to read the input characters and produce as output a sequence

More information

Figure 2.1: Role of Lexical Analyzer

Figure 2.1: Role of Lexical Analyzer Chapter 2 Lexical Analysis Lexical analysis or scanning is the process which reads the stream of characters making up the source program from left-to-right and groups them into tokens. The lexical analyzer

More information

Lexical Analysis - 2

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)

More information

NFAs and Myhill-Nerode. CS154 Chris Pollett Feb. 22, 2006.

NFAs and Myhill-Nerode. CS154 Chris Pollett Feb. 22, 2006. NFAs and Myhill-Nerode CS154 Chris Pollett Feb. 22, 2006. Outline Bonus Questions Equivalence with Finite Automata Myhill-Nerode Theorem. Bonus Questions These questions are open to anybody. I will only

More information

[Lexical Analysis] Bikash Balami

[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

More information

COMP-421 Compiler Design. Presented by Dr Ioanna Dionysiou

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

More information

Zhizheng Zhang. Southeast University

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

More information

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

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:

More information

Formal Definition of Computation. Formal Definition of Computation p.1/28

Formal Definition of Computation. Formal Definition of Computation p.1/28 Formal Definition of Computation Formal Definition of Computation p.1/28 Computation model The model of computation considered so far is the work performed by a finite automaton Formal Definition of Computation

More information

Finite Automata Theory and Formal Languages TMV027/DIT321 LP4 2016

Finite Automata Theory and Formal Languages TMV027/DIT321 LP4 2016 Finite Automata Theory and Formal Languages TMV027/DIT321 LP4 2016 Lecture 15 Ana Bove May 23rd 2016 More on Turing machines; Summary of the course. Overview of today s lecture: Recap: PDA, TM Push-down

More information

Compiler Construction I

Compiler Construction I TECHNISCHE UNIVERSITÄT MÜNCHEN FAKULTÄT FÜR INFORMATIK Compiler Construction I Dr. Michael Petter SoSe 2015 1 / 58 Organizing Master or Bachelor in the 6th Semester with 5 ECTS Prerequisites Informatik

More information

Finite Automata. Lecture 4 Sections Robb T. Koether. Hampden-Sydney College. Wed, Jan 21, 2015

Finite Automata. Lecture 4 Sections Robb T. Koether. Hampden-Sydney College. Wed, Jan 21, 2015 Finite Automt Lecture 4 Sections 3.6-3.7 Ro T. Koether Hmpden-Sydney College Wed, Jn 21, 2015 Ro T. Koether (Hmpden-Sydney College) Finite Automt Wed, Jn 21, 2015 1 / 23 1 Nondeterministic Finite Automt

More information

David Griol Barres 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 Computer Science Department Carlos III University of Madrid Leganés (Spain) OUTLINE Introduction: Definitions The role of the Lexical Analyzer Scanner Implementation

More information

Automating Construction of Lexers

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

More information

University of Waterloo Midterm Examination

University of Waterloo Midterm Examination University of Waterloo Midterm Examination 1 Fall 2008 Student Name: UW Student ID Number: UW Userid: Course Abbreviation and Number: CS 241 Course Title: Foundations of Sequential Programs Section(s):

More information

Finite Automata Theory and Formal Languages TMV027/DIT321 LP4 2018

Finite Automata Theory and Formal Languages TMV027/DIT321 LP4 2018 Finite Automata Theory and Formal Languages TMV027/DIT321 LP4 2018 Lecture 11 Ana Bove April 26th 2018 Recap: Regular Languages Decision properties of RL: Is it empty? Does it contain this word? Contains

More information

Compiler Construction

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/

More information

Compiler Construction I

Compiler Construction I TECHNISCHE UNIVERSITÄT MÜNCHEN FAKULTÄT FÜR INFORMATIK Compiler Construction I Dr. Michael Petter, Dr. Axel Simon SoSe 2014 1 / 59 Organizing Master or Bachelor in the 6th Semester with 5 ECTS Prerequisites

More information

Lexical Analysis. Introduction

Lexical Analysis. Introduction Lexical Analysis Introduction Copyright 2015, Pedro C. Diniz, all rights reserved. Students enrolled in the Compilers class at the University of Southern California have explicit permission to make copies

More information

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

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.

More information

CS/ECE 374 Fall Homework 1. Due Tuesday, September 6, 2016 at 8pm

CS/ECE 374 Fall Homework 1. Due Tuesday, September 6, 2016 at 8pm CSECE 374 Fall 2016 Homework 1 Due Tuesday, September 6, 2016 at 8pm Starting with this homework, groups of up to three people can submit joint solutions. Each problem should be submitted by exactly one

More information

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

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.

More information

(a) R=01[((10)*+111)*+0]*1 (b) ((01+10)*00)*. [8+8] 4. (a) Find the left most and right most derivations for the word abba in the grammar

(a) R=01[((10)*+111)*+0]*1 (b) ((01+10)*00)*. [8+8] 4. (a) Find the left most and right most derivations for the word abba in the grammar Code No: R05310501 Set No. 1 III B.Tech I Semester Regular Examinations, November 2008 FORMAL LANGUAGES AND AUTOMATA THEORY (Computer Science & Engineering) Time: 3 hours Max Marks: 80 Answer any FIVE

More information

Implementation of Lexical Analysis

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

More information

Theory of Computations Spring 2016 Practice Final

Theory of Computations Spring 2016 Practice Final 1 of 6 Theory of Computations Spring 2016 Practice Final 1. True/False questions: For each part, circle either True or False. (23 points: 1 points each) a. A TM can compute anything a desktop PC can, although

More information

CSE302: Compiler Design

CSE302: Compiler Design CSE302: Compiler Design Instructor: Dr. Liang Cheng Department of Computer Science and Engineering P.C. Rossin College of Engineering & Applied Science Lehigh University February 13, 2007 Outline Recap

More information

R10 SET a) Explain the Architecture of 8085 Microprocessor? b) Explain instruction set Architecture Design?

R10 SET a) Explain the Architecture of 8085 Microprocessor? b) Explain instruction set Architecture Design? Code No: R22054 COMPUTER ORGANIZATION (Com. to CSE, ECC) 1. a) Explain the Architecture of 8085 Microprocessor? b) Explain instruction set Architecture Design? 2. Explain Memory Subsystem Organization

More information

CSc 453 Lexical Analysis (Scanning)

CSc 453 Lexical Analysis (Scanning) CSc 453 Lexical Analysis (Scanning) Saumya Debray The University of Arizona Tucson Overview source program lexical analyzer (scanner) tokens syntax analyzer (parser) symbol table manager Main task: to

More information

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

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

More information

Theory of Computations Spring 2016 Practice Final Exam Solutions

Theory of Computations Spring 2016 Practice Final Exam Solutions 1 of 8 Theory of Computations Spring 2016 Practice Final Exam Solutions Name: Directions: Answer the questions as well as you can. Partial credit will be given, so show your work where appropriate. Try

More information

CMPSCI 250: Introduction to Computation. Lecture 20: Deterministic and Nondeterministic Finite Automata David Mix Barrington 16 April 2013

CMPSCI 250: Introduction to Computation. Lecture 20: Deterministic and Nondeterministic Finite Automata David Mix Barrington 16 April 2013 CMPSCI 250: Introduction to Computation Lecture 20: Deterministic and Nondeterministic Finite Automata David Mix Barrington 16 April 2013 Deterministic and Nondeterministic Finite Automata Deterministic

More information

CISC 4090 Theory of Computation

CISC 4090 Theory of Computation CISC 4090 Theory of Computation Turing machines Professor Daniel Leeds dleeds@fordham.edu JMH 332 Alan Turing (1912-1954) Father of Theoretical Computer Science Key figure in Artificial Intelligence Codebreaker

More information

Lexical Analysis. Lecture 3-4

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

More information

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

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

More information

Symbolic Automata Library for Fast Prototyping

Symbolic Automata Library for Fast Prototyping http://excel.fit.vutbr.cz Symbolic Automata Library for Fast Prototyping Michaela Bieliková not_in{@} in{e,x,c} in{e,l} F I T Abstract Finite state automata are widely used in the fields of computer science

More information

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

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

More information

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

More information

2068 (I) Attempt all questions.

2068 (I) Attempt all questions. 2068 (I) 1. What do you mean by compiler? How source program analyzed? Explain in brief. 2. Discuss the role of symbol table in compiler design. 3. Convert the regular expression 0 + (1 + 0)* 00 first

More information

Midterm I review. Reading: Chapters 1-4

Midterm I review. Reading: Chapters 1-4 Midterm I review Reading: Chapters 1-4 1 Test Details In class, Wednesday, Feb. 25, 2015 3:10pm-4pm Comprehensive Closed book, closed notes 2 Syllabus Formal proofs Finite Automata NFA, DFA, -NFA Regular

More information

INTRODUCTION PRINCIPLES OF PROGRAMMING LANGUAGES. Norbert Zeh Winter Dalhousie University 1/10

INTRODUCTION PRINCIPLES OF PROGRAMMING LANGUAGES. Norbert Zeh Winter Dalhousie University 1/10 INTRODUCTION PRINCIPLES OF PROGRAMMING LANGUAGES Norbert Zeh Winter 2018 Dalhousie University 1/10 GOAL OF THIS COURSE 2/10 GOAL OF THIS COURSE Encourage you to become better programmers 2/10 GOAL OF THIS

More information

Outline. Language Hierarchy

Outline. Language Hierarchy Outline Language Hierarchy Definition of Turing Machine TM Variants and Equivalence Decidability Reducibility Language Hierarchy Regular: finite memory CFG/PDA: infinite memory but in stack space TM: infinite

More information

Limited Automata and Unary Languages

Limited Automata and Unary Languages Limited Automata and Unary Languages Giovanni Pighizzini and Luca Prigioniero Dipartimento di Informatica, Università degli Studi di Milano, Italy {pighizzini,prigioniero}@di.unimi.it Abstract. Limited

More information

Decision, Computation and Language

Decision, Computation and Language Decision, Computation and Language Regular Expressions Dr. Muhammad S Khan (mskhan@liv.ac.uk) Ashton Building, Room G22 http://www.csc.liv.ac.uk/~khan/comp218 Regular expressions M S Khan (Univ. of Liverpool)

More information

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

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

More information

Languages and Compilers

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:

More information

Computer Sciences Department

Computer Sciences Department 1 Reference Book: INTRODUCTION TO THE THEORY OF COMPUTATION, SECOND EDITION, by: MICHAEL SIPSER 3 D E C I D A B I L I T Y 4 Objectives 5 Objectives investigate the power of algorithms to solve problems.

More information

Lexical Analysis. Lecture 3. January 10, 2018

Lexical Analysis. Lecture 3. January 10, 2018 Lexical Analysis Lecture 3 January 10, 2018 Announcements PA1c due tonight at 11:50pm! Don t forget about PA1, the Cool implementation! Use Monday s lecture, the video guides and Cool examples if you re

More information

JNTUWORLD. Code No: R

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

More information

Test I Solutions MASSACHUSETTS INSTITUTE OF TECHNOLOGY Fall Department of Electrical Engineering and Computer Science

Test I Solutions MASSACHUSETTS INSTITUTE OF TECHNOLOGY Fall Department of Electrical Engineering and Computer Science Department of Electrical Engineering and Computer cience MAACHUETT INTITUTE OF TECHNOLOGY 6.035 Fall 2017 Test I olutions Mean 83.63 Median 86 td. dev 12.03 1 I Regular Expressions and Finite-tate Automata

More information

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

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

More information

CS2 Practical 2 CS2Ah

CS2 Practical 2 CS2Ah CS2 Practical 2 Finite automata This practical is based on material in the language processing thread. The practical is made up of two parts. Part A consists of four paper and pencil exercises, designed

More information

Lexical Error Recovery

Lexical Error Recovery Lexical Error Recovery A character sequence that can t be scanned into any valid token is a lexical error. Lexical errors are uncommon, but they still must be handled by a scanner. We won t stop compilation

More information

VALLIAMMAI ENGNIEERING COLLEGE SRM Nagar, Kattankulathur 603203. DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING Year & Semester : III Year, V Semester Section : CSE - 1 & 2 Subject Code : CS6503 Subject

More information

CS415 Compilers. Lexical Analysis

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

More information

Variants of Turing Machines

Variants of Turing Machines November 4, 2013 Robustness Robustness Robustness of a mathematical object (such as proof, definition, algorithm, method, etc.) is measured by its invariance to certain changes Robustness Robustness of

More information

Equivalence of NTMs and TMs

Equivalence of NTMs and TMs Equivalence of NTMs and TMs What is a Turing Machine? Similar to a finite automaton, but with unlimited and unrestricted memory. It uses an infinitely long tape as its memory which can be read from and

More information

Gujarat Technological University Sankalchand Patel College of Engineering, Visnagar B.E. Semester VII (CE) July-Nov Compiler Design (170701)

Gujarat Technological University Sankalchand Patel College of Engineering, Visnagar B.E. Semester VII (CE) July-Nov Compiler Design (170701) Gujarat Technological University Sankalchand Patel College of Engineering, Visnagar B.E. Semester VII (CE) July-Nov 2014 Compiler Design (170701) Question Bank / Assignment Unit 1: INTRODUCTION TO COMPILING

More information

Lexical Analysis. Lecture 2-4

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.

More information

Implementation of Lexical Analysis

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

More information

Definition 2.8: A CFG is in Chomsky normal form if every rule. only appear on the left-hand side, we allow the rule S ǫ.

Definition 2.8: A CFG is in Chomsky normal form if every rule. only appear on the left-hand side, we allow the rule S ǫ. CS533 Class 02b: 1 c P. Heeman, 2017 CNF Pushdown Automata Definition Equivalence Overview CS533 Class 02b: 2 c P. Heeman, 2017 Chomsky Normal Form Definition 2.8: A CFG is in Chomsky normal form if every

More information

Non-deterministic Finite Automata (NFA)

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

More information

Complementing Non-CFLs If A and B are context free languages then: AR is a context-free language TRUE

Complementing Non-CFLs If A and B are context free languages then: AR is a context-free language TRUE Lecture : Parsimonious Menu Fix proof from last class Interpretive Dance! Parsimonious (Parsimoniously) P Comments Available oday P will be returned uesday cs0: heory of Computation University of Virginia

More information

QUESTION BANK. Unit 1. Introduction to Finite Automata

QUESTION BANK. Unit 1. Introduction to Finite Automata QUESTION BANK Unit 1 Introduction to Finite Automata 1. Obtain DFAs to accept strings of a s and b s having exactly one a.(5m )(Jun-Jul 10) 2. Obtain a DFA to accept strings of a s and b s having even

More information

Multiple Choice Questions

Multiple Choice Questions Techno India Batanagar Computer Science and Engineering Model Questions Subject Name: Formal Language and Automata Theory Subject Code: CS 402 Multiple Choice Questions 1. The basic limitation of an FSM

More information

UNIT -2 LEXICAL ANALYSIS

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

More information

Final Course Review. Reading: Chapters 1-9

Final Course Review. Reading: Chapters 1-9 Final Course Review Reading: Chapters 1-9 1 Objectives Introduce concepts in automata theory and theory of computation Identify different formal language classes and their relationships Design grammars

More information