Question

Solve the following 5 questions with explanations of answers.


q1.png

q2.png

Image transcriptions

Problem 1 [8pt] Write down the set of strings recognized by the following regular expressions. If the set is infinite, write down the first 7 shortest elements; otherwise, write down all elements. 1. (4pt) (a b)(a b)(a|b) 2. (4pt) a(aa bb)*b Problem 2 [10pt] 1. (5pt) Write down a regular expression that captures nonempty binaries (strings with 0's and 1's) that start and end with the same digit and with at least two digits. For example, 010 and 1101 are such binaries, while 1 and 01 1 are not. 2. (5pt) Write down a regular expression for the language consisting of declarations (in a single line) of variables of type int in C. Multiple variables can be declared in a single declaration, separated by commas, and each can have an optional initial value (given by a constant). A declaration is terminated by a semi-colon. For example, the following two lines are both valid declarations: int x 3; int x, y 5, z; For your convenience, use symbols ID and N for identifiers and integers respectively in your RE. Moreover, assume there is no space in the definition except for the one after int. Use \s for the space character.

Problem 4 [7pt] Write down a context free grammar for all strings with matching parentheses, such as " "(0)", "00", "((O)0)". Problem 5 [10pt] For each of the following grammars state whether it is ambiguous or unambiguous. If it is ambiguous give an equivalent unambiguous grammar. If it is unambiguous, state all the precedences and associativeties enforced by the grammar. Assume Id generates identifiers. 1/2 A) E : =E+FF F ::=F *F Id\(E) b) E ::= FnE| FUE| F F ::= FAG\FVGIG G:= Id (E)

Problem 1 [8pt] Write down the set of strings recognized by the following regular expressions. If the set is infinite, write down the first 7...
Get unstuck

321,403 students got unstuck by Course
Hero in the last week

step by step solutions

Our Expert Tutors provide step by step solutions to help you excel in your courses