Compiler Exercises
Compiler Exercises
EXERCISE 3.3.2
a(a|b)*a
EXERCISE 3.3.5
a. all strings of lowercase letters that contain the five vowels in order.
→∗( | ∗
) ( | )∗ ( | )∗ ( | )∗ ( | )∗
→[ ℎ ]
EXERCISE 3.4.1
e. (aa|bb)*((ab|ba)(aa|bb)*(ab|ba)(aa|bb)*)*
EXERCISE 4.2.2
Repeat exercise 4.2.1 for each of the following grammars and strings:
→
→
→
→
→
→
→
Provide a right derivation for the string
→
→
→
→
→
→
Provide a syntactic parse tree for the string.
The grammar is ambiguous since more than one derivation can be made, that is, from the left.
to the right, the same string is obtained.
The set of all strings of a's and b's with the same number of a's and b's.
EXERCISE 4.4.1
For each of the following grammars, devise predictive syntax analyzers and
show the parse tables. You can factor out the left or eliminate it.
left recursion of their grammars first.
Left factorization
S → 0A
A → S1|1
Eliminate left recursion
S → 0A
A → 0A1 | 1
Input symbol
Non-terminal symbol
0 1 $$
S S→0A
A A→0A1 1
EXERCISE 4.4.4
Calculate FIRST and FOLLOW for each of the grammars in exercise 4.2.2
next(s)
we use rule 3
→
( )→ ( )
( )( →
) ( )
We use the case (→) ( ) ( )
Next(s) = [a, b, $]
EXERCISE 4.5.1
For the grammarS → 0S1 | 01from exercise 4.2.2(a), indicate the handle in each of the
following right sentence forms.
a. 000111
01