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

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

Theory of Computation Dr. Weiss Extra Practice Exam Solutions

Ambiguous Grammars and Compactification

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

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

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

Chapter Seven: Regular Expressions

6 NFA and Regular Expressions

Lexical Analysis. Implementation: Finite Automata

COMP-421 Compiler Design. Presented by Dr Ioanna Dionysiou

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

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

JNTUWORLD. Code No: R

DVA337 HT17 - LECTURE 4. Languages and regular expressions

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

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.

Formal Languages and Compilers Lecture VI: Lexical Analysis

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

CSE 105 THEORY OF COMPUTATION

Automating Construction of Lexers

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

Languages and Finite Automata

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

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

CS5371 Theory of Computation. Lecture 8: Automata Theory VI (PDA, PDA = CFG)

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

QUESTION BANK. Unit 1. Introduction to Finite Automata

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

Front End: Lexical Analysis. The Structure of a Compiler

Learn Smart and Grow with world

Multiple Choice Questions

Regular Languages and Regular Expressions

Formal Languages and Automata

Closure Properties of CFLs; Introducing TMs. CS154 Chris Pollett Apr 9, 2007.

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

CT32 COMPUTER NETWORKS DEC 2015

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

Final Course Review. Reading: Chapters 1-9

1.3 Functions and Equivalence Relations 1.4 Languages

Converting a DFA to a Regular Expression JP

ECS 120 Lesson 7 Regular Expressions, Pt. 1

CSE 105 THEORY OF COMPUTATION

TOPIC PAGE NO. UNIT-I FINITE AUTOMATA

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

Finite Automata Part Three

Introduction to Lexical Analysis

Implementation of Lexical Analysis

Implementation of Lexical Analysis

Midterm I (Solutions) CS164, Spring 2002

UNIT I PART A PART B

UNION-FREE DECOMPOSITION OF REGULAR LANGUAGES

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

lec3:nondeterministic finite state automata

Non-deterministic Finite Automata (NFA)

Languages and Strings. Chapter 2

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

CS308 Compiler Principles Lexical Analyzer Li Jiang

Models of Computation II: Grammars and Pushdown Automata

CS103 Handout 14 Winter February 8, 2013 Problem Set 5

Lexical Analysis. Chapter 2

Languages and Compilers

Implementation of Lexical Analysis

CS6160 Theory of Computation Problem Set 2 Department of Computer Science, University of Virginia

Lexical Analysis. Introduction

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


LECTURE NOTES THEORY OF COMPUTATION

CS143 Midterm Fall 2008

LECTURE NOTES THEORY OF COMPUTATION

Lexical Analyzer Scanner

Automata & languages. A primer on the Theory of Computation. The imitation game (2014) Benedict Cumberbatch Alan Turing ( ) Laurent Vanbever

Context-Free Grammars

UNIT -2 LEXICAL ANALYSIS

Lexical Analysis. Lecture 2-4

Theory of Computations Spring 2016 Practice Final Exam Solutions

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

Name: Finite Automata

CS 403 Compiler Construction Lecture 3 Lexical Analysis [Based on Chapter 1, 2, 3 of Aho2]

COMP 330 Autumn 2018 McGill University

Chapter Seven: Regular Expressions. Formal Language, chapter 7, slide 1

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

Compiler Construction

Slides for Faculty Oxford University Press All rights reserved.

MIT Specifying Languages with Regular Expressions and Context-Free Grammars

Finite Automata Theory and Formal Languages TMV027/DIT321 LP4 2016

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

Concepts. Lexical scanning Regular expressions DFAs and FSAs Lex. Lexical analysis in perspective

Lexical Analyzer Scanner

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

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

Finite Automata Part Three

Chapter 4. Lexical analysis. Concepts. Lexical scanning Regular expressions DFAs and FSAs Lex. Lexical analysis in perspective

Dr. D.M. Akbar Hussain

Lexical Analysis (ASU Ch 3, Fig 3.1)

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

Lexical Analysis. Lecture 3-4


CSE 431S Scanning. Washington University Spring 2013

CMSC 330: Organization of Programming Languages

2. Lexical Analysis! Prof. O. Nierstrasz!

Transcription:

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. Context-free languages a. Context-free grammar

String Induction Proof standards are strictest here - stick to the definitions! Be careful of the order of the if-else branches

Language Definitions A DFA recognizes (or accepts) a language L iff every string in L is accepted by the DFA, and every string not in L is rejected by the DFA. Likewise for NFAs, regular expressions A context-free language L is generated by a CFG iff (almost copy and paste from above)

Regular Languages & Expressions Formally, one of a. The empty set b. The set containing one string c. The union, concatenation, or Kleene closure of regular language(s) Additionally, closed under intersection, set difference, reversal, homomorphisms, inverse homomorphisms Regular expressions follow the structure of the formal definition

Deterministic Finite Automata Formally, In drawings, Q is the set of circles, δ is the set of arrows, s is the circle with an arrow leading into it without any source, and A is the set of doubly-circled circles

Non-deterministic Finite Automata Formally, Drawn similarly like DFAs, but with the extra epsilon transitions An NFA accepts a string s can reach at least one of the accepting states

Regular Languages: Useful Theorems Source: CSCI

Is it regular? First, determine if the language definition can be simplified Then, check if you need an unbounded counter If so, try to create a fooling set If possible, choose the simplest prefixes you can find Be careful of generalized string splits - a string belongs to a presented language if any permitted combo of strings satisfies the conditions within the set condition Use letter changes to guard against these splits If not, try to create a DFA/NFA/Regex

Regular Expressions: Examples Write regular expressions for the following languages over the alphabet Σ = {a, b}: (a) (b) (c) All strings that do not end with aa All strings that contain an even number of b s All strings which do not contain ba Source: Stanford

Regular Expressions: Examples Write regular expressions for the following languages over the alphabet Σ = {a, b}: (a) All strings that do not end with aa + a + b + (a + b) (ab + ba + bb) (b) All strings that contain an even number of b s a (ba ba ) (c) All strings which do not contain ba a b Source: Stanford

Regular Languages: Example Is the language { xyx r x, y {0,1} + } regular? Is the language { xyxyxy x, y {0,1} + } regular?

Regular Languages: Example Is the language { xyx r x, y {0,1} + } regular? Answer: Yes - equivalent to 0(0+1) + 0 + 1(0+1) + 1 Is the language L = { xyxyxy x, y {0,1} + } regular? Answer: No - use 1 to indicate end of string xy in fooling set Fooling set: F = {0 n 1 n n >= 0} Suffix (z) : 0 n 1 n 0 n 1 n x= 0 n 1 n y= 0 i 1 i i n xz L but yz L

Deterministic Finite Automata: Examples Draw DFAs for the following languages over the alphabet Σ = {a, b}: (a) (b) (c) All strings that do not end with aa All strings that contain an even number of b s All strings which do not contain ba Source: Stanford

Deterministic Finite Automata: Examples Draw DFAs for the following languages over the alphabet Σ = {a, b}: (a) (b) (c) All strings that do not end with aa All strings that contain an even number of b s All strings which do not contain ba Source: Stanford

Context-free Grammars and Languages Formally, Not closed under intersection or set difference Design: a. Pair letters - identify their positions and guarantee that substrings hold certain properties b. Drop letters - useful for inequalities or early termination c. Cumulative counting - does the difference operator Δ hit zero?

Context-free Grammars: Examples Construct context-free grammars for each of the following languages: a) {a m b n m >= n} b) {a m b n c p d q m + n = p + q} c) {w (a+b)* w has twice as many b s as a s} d) {uawb u, w (a+b)*, u = w } Source: UT-Austin

Context-free Grammars: Examples Construct context-free grammars for each of the following languages: a) {a m b n m >= n} Answer: S asb acb ε, C ac ε b) {a m b n c p d q m + n = p + q} Answer: S asd T U, T atc V, U bud V, V bvc ϵ c) {w (a+b)* w has twice as many b s as a s} Answer: S SaSbSbS SbSaSbS SbSbSaS ϵ d) {uawb u, w (a+b)*, u = w } Answer: S Tb, T ata atb bta btb a Source: UT-Austin

Language Transformation

Language Transformation

True/False Examples

True/False Examples

True/False Examples

True/False Examples

True/False Examples

True/False Examples