CS 6353 Compiler Construction, Homework #1. 1. Write regular expressions for the following informally described languages:

Similar documents
Lecture 4: Parsing. Administrivia

Source code. where each α ij is a terminal or nonterminal symbol. We say that. α 1 α m 1 Bα m+1 α n α 1 α m 1 β 1 β p α m+1 α n

CS 361 Meeting 12 10/3/18

EEO 401 Digital Signal Processing Prof. Mark Fowler

Propositional Logic. Combinatorial Problem Solving (CPS) Albert Oliveras Enric Rodríguez-Carbonell. May 17, 2018

Syntax Analysis. Context-free grammar Top-down and bottom-up parsing. cs5363 1

UNTYPED LAMBDA CALCULUS (II)

1 Minimum Cut Problem

Roadmap. XML Indexing. DataGuide example. DataGuides. Strong DataGuides. Multiple DataGuides for same data. CPS Topics in Database Systems

The Matrix Exponential

The Matrix Exponential

LR(0) Analysis. LR(0) Analysis

Higher order derivatives

Chapter 6 Folding. Folding

COMPUTER GENERATED HOLOGRAMS Optical Sciences 627 W.J. Dallas (Monday, April 04, 2005, 8:35 AM) PART I: CHAPTER TWO COMB MATH.

Brief Introduction to Statistical Mechanics

(Upside-Down o Direct Rotation) β - Numbers

Fourier Transforms and the Wave Equation. Key Mathematics: More Fourier transform theory, especially as applied to solving the wave equation.

That is, we start with a general matrix: And end with a simpler matrix:

Alpha and beta decay equation practice

perm4 A cnt 0 for for if A i 1 A i cnt cnt 1 cnt i j. j k. k l. i k. j l. i l

u x v x dx u x v x v x u x dx d u x v x u x v x dx u x v x dx Integration by Parts Formula

Week 3: Connected Subgraphs

First derivative analysis

Elements of Statistical Thermodynamics

Abstract Interpretation: concrete and abstract semantics

Limiting value of higher Mahler measure


Exam 1. It is important that you clearly show your work and mark the final answer clearly, closed book, closed notes, no calculator.

Strongly Connected Components

Note If the candidate believes that e x = 0 solves to x = 0 or gives an extra solution of x = 0, then withhold the final accuracy mark.

5. B To determine all the holes and asymptotes of the equation: y = bdc dced f gbd

The pn junction: 2 Current vs Voltage (IV) characteristics

Calculus concepts derivatives

PHA 5127 Answers Homework 2 Fall 2001

22/ Breakdown of the Born-Oppenheimer approximation. Selection rules for rotational-vibrational transitions. P, R branches.

Gradebook & Midterm & Office Hours

Problem Set 6 Solutions

A Propagating Wave Packet Group Velocity Dispersion

The van der Waals interaction 1 D. E. Soper 2 University of Oregon 20 April 2012

ME 321 Kinematics and Dynamics of Machines S. Lambert Winter 2002

MCB137: Physical Biology of the Cell Spring 2017 Homework 6: Ligand binding and the MWC model of allostery (Due 3/23/17)

ECE602 Exam 1 April 5, You must show ALL of your work for full credit.

INTEGRALS. Chapter 7. d dx. 7.1 Overview Let d dx F (x) = f (x). Then, we write f ( x)

Thus, because if either [G : H] or [H : K] is infinite, then [G : K] is infinite, then [G : K] = [G : H][H : K] for all infinite cases.

2. Background Material

6.1 Integration by Parts and Present Value. Copyright Cengage Learning. All rights reserved.

Addition of angular momentum

Search sequence databases 3 10/25/2016

2008 AP Calculus BC Multiple Choice Exam

Solution: APPM 1360 Final (150 pts) Spring (60 pts total) The following parts are not related, justify your answers:

General Notes About 2007 AP Physics Scoring Guidelines

cycle that does not cross any edges (including its own), then it has at least

Addition of angular momentum

A. Limits and Horizontal Asymptotes ( ) f x f x. f x. x "±# ( ).

Einstein Equations for Tetrad Fields

Slide 1. Slide 2. Slide 3 DIGITAL SIGNAL PROCESSING CLASSIFICATION OF SIGNALS

Differentiation of Exponential Functions

Why is a E&M nature of light not sufficient to explain experiments?

Problem Set #2 Due: Friday April 20, 2018 at 5 PM.

PHYSICS 489/1489 LECTURE 7: QUANTUM ELECTRODYNAMICS

COHORT MBA. Exponential function. MATH review (part2) by Lucian Mitroiu. The LOG and EXP functions. Properties: e e. lim.

Differential Equations

Dealing with quantitative data and problem solving life is a story problem! Attacking Quantitative Problems

Formal Languages: Review

Quasi-Classical States of the Simple Harmonic Oscillator

MA 262, Spring 2018, Final exam Version 01 (Green)

1997 AP Calculus AB: Section I, Part A

Introduction to Condensed Matter Physics

Announce. ECE 2026 Summer LECTURE OBJECTIVES READING. LECTURE #3 Complex View of Sinusoids May 21, Complex Number Review

10. Limits involving infinity

Y 0. Standing Wave Interference between the incident & reflected waves Standing wave. A string with one end fixed on a wall

Electrochemistry L E O

Section 6.1. Question: 2. Let H be a subgroup of a group G. Then H operates on G by left multiplication. Describe the orbits for this operation.

EXST Regression Techniques Page 1

Constants and Conversions:

Background: We have discussed the PIB, HO, and the energy of the RR model. In this chapter, the H-atom, and atomic orbitals.

Voltage, Current, Power, Series Resistance, Parallel Resistance, and Diodes

Give the letter that represents an atom (6) (b) Atoms of A and D combine to form a compound containing covalent bonds.

u 3 = u 3 (x 1, x 2, x 3 )

Instructions for Section 1

The graph of y = x (or y = ) consists of two branches, As x 0, y + ; as x 0, y +. x = 0 is the

ANALYSIS IN THE FREQUENCY DOMAIN

Calculus II (MAC )

Complex Powers and Logs (5A) Young Won Lim 10/17/13

ECE 344 Microwave Fundamentals

Chapter 10. The singular integral Introducing S(n) and J(n)

GEOMETRICAL PHENOMENA IN THE PHYSICS OF SUBATOMIC PARTICLES. Eduard N. Klenov* Rostov-on-Don, Russia

There is an arbitrary overall complex phase that could be added to A, but since this makes no difference we set it to zero and choose A real.

4. (5a + b) 7 & x 1 = (3x 1)log 10 4 = log (M1) [4] d = 3 [4] T 2 = 5 + = 16 or or 16.

10. The Discrete-Time Fourier Transform (DTFT)

4. Money cannot be neutral in the short-run the neutrality of money is exclusively a medium run phenomenon.

Construction of asymmetric orthogonal arrays of strength three via a replacement method

Unit 6: Solving Exponential Equations and More

MSLC Math 151 WI09 Exam 2 Review Solutions

Estimation of apparent fraction defective: A mathematical approach

September 23, Honors Chem Atomic structure.notebook. Atomic Structure

Content Skills Assessments Lessons. Identify, classify, and apply properties of negative and positive angles.

MATHEMATICS (B) 2 log (D) ( 1) = where z =

Supplementary Materials

Transcription:

CS 6353 Compilr Construction, Homwork #1 1. Writ rgular xprssions for th following informally dscribd languags: a. All strings of 0 s and 1 s with th substring 01*1. Answr: (0 1)*01*1(0 1)* b. All strings of 0 s and 1 s with an odd numbr of 0 s and odd numbr of 1 s. Answr: vn*( 0 vn*1 1 vn* 0 ) vn* vn* = (00 11)*((01/10)(00 11)*(01/10)(00 11)*)* as shown in nots 2. Considr. Answr th following DFA rlatd qustions. Whn constructing DFA, thr is no nd to show your construction stps, but you nd to informally stat how you gt th DFAs. a. Construct a DFA that accpts (a b)* xcpt for a*b*b. b. Basd on th tchniqus you us in (a) and (b), can you com up with a DFA construction algorithm for th xcpt for typ of languags? Stp 1: (Optional) Construct NFA accpting th languag corrsponding to th xcpt for part. Stp 2: Convrt NFA to DFA Stp 3: Rvrs stats, i.., changing original accpt stats to rjct stats and original rjct stats to accpt stats.

3. Considr th rgular xprssion aac* b(a b)c* dfind on. a. Construct th NFA for th rgular xprssion. You can dirctly draw th NFA without going through th RE-to-NFA stps. b. Convrt th NFA to DFA. You nd to show th convrsion stps. c. Minimiz th DFA. You nd to show th minimization stps.

4. A tokn rcognizr is dsignd to handl th following tokns, whr. T1 = aab T2 = bcc* T3 = bcd* T4 = aabcd* a. Construct a minimizd DFA for tokn rcognition and th tokns ar dfind as follows. Th DFA should spcify th spcific tokn nams (T1, T2, ) it accpts at th corrsponding final stats. You do not nd to show th stps for th construction if you can draw th DFA dirctly. Not that th longst matching and first matching ruls for ambiguity rsolution should b usd.

b. Excut your DFA to procss th following string to idntify tokns. List vry tokn string and its tokn nam. Also, dscrib all th backtracking actions takn during th procss. aabaabcdddbcbccccaabbcddd aab aabcdddbcbccccaabbcddd aab aabcddd bcbccccaabbcddd -- got tokn aab(t1) -- got tokn aabcddd (T4) aab aabcddd bc bccccaabbcddd aab aabcddd bc bcccc aabbcddd -- got tokn bc(t2) -- got tokn bcccc(t2) aab aabcddd bc bcccc aab bcddd aab aabcddd bc bcccc aab bcddd -- got tokn aab(t1) -- got tokn bcddd (T3) c. Crat th lx dfinition fil for th tokn rcognizr. Us lx to gnrat th scannr program from th dfinition fil. Aftr compiling th scannr, gnrat input strings to tst it. Attach th print out for th dfinition fil, th input string, and th output of th scannr. dfition fil: %{ #includ <studio.h> %} %% aab {printf("tokn: T1; string = %s.\n", yytxt);} bcc* {printf("tokn: T2; string = %s.\n", yytxt);} bcd* {printf("tokn: T3; string = %s.\n", yytxt);}

aabcd* {printf("tokn: T4; string = %s.\n", yytxt);} %% Input string: aabaabcdddbcbccccaabbcddd Output of th scannr: Tokn: T1; string = aab. Tokn:T4; string = aabcddd. Tokn: T2; string = bc. Tokn: T2; string = bcccc. Tokn: T1; string = aab. Tokn: T3; string = bcddd. 5. Considr th languag: All strings of 0 s and 1 s such that vry 0 is immdiatly followd by at last on 1. (a) Construct a DFA for th languag. 1 0 0 1 1 (b) Convrt th DFA to a rgular grammar (following th convrsion algorithm). S 0 = 1S 0 0S 1 S 1 = 1S 0 (c) As w discussd in class, th grammar you constructd in (a) is a rgular grammar (typ 3 grammar). Th following grammar G (G is not a rgular grammar) is also for th sam languag. Show a pars tr for th string 1011101. S -> BA A -> 01BA B -> 1B

S B A 1 B 0 1 B A 1 B 0 1 B A 1 B (d) Giv th lftmost drivation for (b) from G. () Giv th rightmost drivation for (b) from G. (f) How many diffrnt drivations from G can th string 1011101 has? Brifly driv your answr. S AB ( 01BA ( ( 011B 0111B 0111) ( 01BA ( 01 ε)) )) ( 1B 1) a b c d f g h i j Equivalnt to xcution of: a { b { ( c d ) ( f ( g h )) } } ( i j ) Simplifid to: a { b { ( cd ) ( f ( g h )) } } ( ij ) Numbr of diffrnt ordrs in xcuting (g h) = C(2,1) = 2 --.g., hg or gh Numbr of diffrnt ordrs in xcuting f (g h) = 2 -- squntial xcution has no altrnativ Numbr of diffrnt ordrs in xcuting (cd fgh) = C(6,3) = 20 --.g., cfdgh, cdfgh, fgcdh,

Numbr of diffrnt ordrs in xcuting (cd f (g h)) = C(6,3) = 20 * 2 = 40 Lt X = b { ( c d ) ( f ( g h )) } and Xk is on way to xcut X Numbr of diffrnt ordrs in xcuting Xk ij = C(9,2) = 36 Numbr of diffrnt ordrs in xcuting X ij = 36 * 40 = 1440 -- X has 40 xcution ordrs Numbr of diffrnt ordrs in xcuting a { X ij } is still 1440 So, th answr is 1440 6. Considr th following languag: Th languag consists of strings of som numbrs of 0 s, 1 s, and * s. Th strings hav th sam numbr of 0 s and 1 s, and at any point in a string, thr ar qual numbr of 0 s and 1 s or mor 0 s than 1 s. Zro or mor * s can appar anywhr in a string. For xampl, 00011*1, 001*0**1011, 01, ******, and ar in th languag, but 01001110* is not in th languag. Construct a contxt fr grammar for th languag. Mak sur th grammar you giv is not ambiguous. 7. Considr th following grammar dfind ovr S -> 0S11 S -> S1 S -> (a) Show that this grammar is ambiguous by giving a string that can b parsd in two diffrnt ways and showing th two corrsponding pars trs. Th pars tr for string 0011111 can b th following:

S S 0 S 1 1 0 S 1 1 S 1 0 S 1 1 0 S 1 1 S 1 (b) Rwrit th grammar to liminat th ambiguity. S -> 0E11 E-> E1 8. Construct a typ-0/1 grammar for th languag, whr can b any string of a s and b s. For xampl abcab is in th languag but abcba is not. Basic concpt: gnrat δ c δ, which is contxt fr and asy to do. Thn, switch δ to δ. Us R to mark th rvrs mov, F th forward mov, and E th nd of string S X R E X a X A b X B c First mov th last nontrminal backward, us R to mark it A A R A R A A B R B R A B A R A R B B B R B R B

Till th last nontrminal rachs a trminal, now it is at th corrct position for th nontrminal, chang it to a trminal, chang R to F so that F can latr b movd forward c A R c a F c B R c b F a A R a a F a B R a b F b A R b a F b B R b b F F nds to b movd to th nd, th ordr of th nontrminals do not chang F A A A F A F A B A F B F B A B F A F B B B F B Whn F movs to th nd, bfor th last trminal, switch and chang it to R F A E A R E F B E B R E Trmination, should b don whn only on trminal lft a A R E a a -- could also trminat on y F Y E, but won t b symmtric with c Y R E a B R E a b b A R E b a b B R E b b c A R E c a - whn w is of lngth 1 c B R E c b c R E c - whn w is an mpty string