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...
View the step-by-step solution to:

Question

Solve the following 5 questions with explanations of answers.


src="/qa/attachment/10699611/" alt="q1.png" />

q2.png

q1.png

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.

q2.png

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)

Recently Asked Questions

Why Join Course Hero?

Course Hero has all the homework and study help you need to succeed! We’ve got course-specific notes, study guides, and practice tests along with expert tutors.

-

Educational Resources
  • -

    Study Documents

    Find the best study resources around, tagged to your specific courses. Share your own to gain free Course Hero access.

    Browse Documents
  • -

    Question & Answers

    Get one-on-one homework help from our expert tutors—available online 24/7. Ask your own questions or browse existing Q&A threads. Satisfaction guaranteed!

    Ask a Question
Ask Expert Tutors You can ask 0 bonus questions You can ask 0 questions (0 expire soon) You can ask 0 questions (will expire )
Answers in as fast as 15 minutes