0% found this document useful (0 votes)
26 views2 pages

Midterm2 Spring2021 AnthonyLe

The document outlines a midterm exam for a compiler course with 7 questions. It covers topics like grammars, Chomsky hierarchy, ambiguity, left recursion removal, First/Follow sets, parsing tables, recursive descent parsing and predictive parsing.

Uploaded by

John Johnson
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
26 views2 pages

Midterm2 Spring2021 AnthonyLe

The document outlines a midterm exam for a compiler course with 7 questions. It covers topics like grammars, Chomsky hierarchy, ambiguity, left recursion removal, First/Follow sets, parsing tables, recursive descent parsing and predictive parsing.

Uploaded by

John Johnson
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

CS 323 – Midterm 2 – 200 points – 7 Questions

Section ______ Name

NUMBER AND ANSWER ALL THE QUESTIONS (20-30 points each)


SHOW YOUR WORK AND ADD MORE PAGES AS NEEDED
Technically CLOSED BOOK – NO COPY & PASTE

1. Use your own words to answer the following questions (30):

a) What is the formal definition of grammar G (explain the tuples)? (10)


b) Explain the different types of languages and complexity level in Chomsky’s
hierarchy. (20)

2. Given the following productions, and the string w = ‘abab’. Is this grammar ambiguous
and if so, explain ambiguity and show why? (30)

1) E − aEbE 2) E − bEaE 3) E − cdE 4) E − 

3. Remove all left recursions and backtracking in the following productions if needed. (30)

1)E − EaE 2)E− F 3)F− mE 4)F− Tde 5) F − Tfg 6) T − id

4. Define the First and Follow sets for each non-terminal symbol (30)

D − ONE
O − xy | b | 
N − Ez | cd | 
E − m | fg | 

5. Given the following productions, construct the parsing table for table driven predictive
parser - it is a top-down parser. (30)

1) S − S & C 2) S − S @ C 3) S − C 4) C − x

6. Given the following production rules, write a recursive descent function that returns a
boolean value for the productions Q. Write the function using syntactically correct C, C++,
C#, python (for 20 points maximum) or pseudo code (15 points). Use any of the pre-existing
functions lexer(), getNextChar(), currentChar(), first(), follow(), token(), backup(), error()
or match() only if needed. (20 points total)

1) E − TQ 2) Q − #TQ 3) Q −  )  − id
7. Given the following predictive parsing table, parse the string “ {xyx} ”
to see if it accepted. (30 points)

x y { } $

S CB CB
B yCB  
C x {S}

Use any of the following: Stack input Production/Action

You might also like