{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

# hw1Ans6 - CS 6353 Compiler Construction Homework#1 1 Write...

This preview shows pages 1–5. Sign up to view the full content.

CS 6353 Compiler Construction, Homework #1 1. Write regular expressions for the following informally described languages: a. All strings of 0’s and 1’s with the subsequence 011. Intuitive solution: (0|1) * 0 (0|1) * 1 (0|1) * 1 (0|1) * Derive from DFA: 1 * 0 + 10 * 10 * (0|1) * Another possible solution: 1 * 0 + 1 + 0 * 1 + 0 * (0|1) * There may be many different solutions b. All strings of 0’s and 1’s with the substring 00*1. Intuitive solution: (0|1) * 00*1(0|1) * 2. Consider Σ = {a, b}. Answer the following DFA related questions. When constructing DFA, there is no need to show your construction steps, but you need to informally state how you get the DFAs. a. Construct a DFA that accepts (a|b)* except for aabb. a S 0 S 2 S 3 S f a b b a, b b S 4 a a, b S 1 a b b. Construct a DFA that accepts (a|b)* except for b*a*. b S 0 S 1 a a, b S 2 b a c. Based on the techniques you use in (a) and (b), can you come up with a DFA construction algorithm for the “except for” type of languages? Step 1: (Optional) Construct NFA accepting the language corresponding to the “except for” part. For example, in (a), construct NFA accepting “aabb”. Step 2: Convert NFA to DFA Step 3: Reverse states, i.e., changing original “accept” states to “reject” states and original “reject” states to “accept” states.

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
3. Consider the regular expression aac* | b(a|b)c* defined on Σ = {a, b, c}. a. Construct the NFA for the regular expression. You can directly draw the NFA without going through the RE-to-NFA steps. b. Convert the NFA to DFA. You need to show the conversion steps. S0 = {1, 2, 8} S1 = {3} S2 = {9, 10, 12} S3 = {4, 5, 7, 18} S4 = {11, 14, 15, 17, 18} S5 = {13, 14, 15, 17, 18} S6 = {5, 6, 7, 18} S7 = {15, 16, 17, 18} b a b c S0 S1 S2 - S1 S3 - - S2 S4 S5 - S3 - - S6 F S4 - - S7 F S5 - - S7 F S6 - - S6 F S7 - - S7 F
c. Minimize the DFA. You need to show the minimization steps. First, divide the states into two groups, final, non-final 4. Consider Σ = {a, b, c}. a. Construct a minimized DFA for token recognition and the tokens are defined as follows. T1 = aab T2 = baa* T3 = ca* T4 = aaa* The DFA should specify the specific token names (T1, T2, …) it accepts at the corresponding final states. You do not need to show the steps for the construction if you can draw the DFA directly. Note that the longest matching and first matching rules for ambiguity resolution should be observed. Also, the backtracking mark should be given. a b c S0’s transitions on a,b are all to G0 S1’s transitions on a is to G3, on b to Null S2’s transition on a,b are all to G3 divide S0 | S1| S2 (they are all different) In G3, all transitions on c are back to G3 for a,b are all Null no division S0 S1 S2 - G0 S1 S3 - - S2 S4 S5 - S3 - - S6 F G3 S4 - - S7 F S5 - - S7 F S6 - - S6 F S7 - - S7 F a b c No further division needed S0 S1 S2 - G0 S1 S3 - - G1 S2 S4 S5 - G2 S3 - - S6 F G3 S4 - - S7 F S5 - - S7 F S6 - - S6 F S7 - - S7 F a G0 G1 b G2 a G3 a|b c

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
b. Execute your DFA to process the following string to identify tokens. List every token string and its token name. Also, describe all the backtracking actions taken during the process.
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}