{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

170_Problem_Set_2

170_Problem_Set_2 - CS143 Summer2011 Handout17 July8th,2011...

Info icon This preview shows pages 1–4. Sign up to view the full content.

View Full Document Right Arrow Icon
CS143 Handout 17 Summer 2011 July 8 th , 2011 Written Set 2: Parsing This written assignment will give you a chance to play around with the various parsing  algorithms we've talked about in class.  Once you've completed this written assignment,  you should have a much deeper understanding of how the different parsing algorithms  work and will be able to reason about their strengths and weaknesses. For the purposes of this handout, you can assume that all context-free grammars are  “clean” grammars.  That means that 1. Every nonterminal can eventually derive a string of terminals.  In other words,  we won't be dealing with CFGs like   A where the nonterminal A can't be further expanded, or  Sa where S can never be fully expanded. 2. Every nonterminal is reachable from the start symbol.  That is, grammars like  a | bS  c are not allowed. Due Monday, July 18 th  at 5:00PM
Image of page 1

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

View Full Document Right Arrow Icon
Warm-up exercises.   We won't be grading either of the next two problems; they're here  purely for you to get a chance to play around with the material before diving into the  trickier questions in this problem set.  While they aren't mandatory, I  strongly  suggest  that you play around with them to make sure that you understand how the different  parsing algorithms work. Warm-up exercise 1: LL parsing In class, we explored a simple programming language with the following structure: Program  Statement Statement if  Expression  then  Block while  Expression  do  Block Expression ; Expression   Term  =>   identifier isZero?  Term not  Expression ++   identifier --  identifier Term identifier constant Block Statement {  Statements  } Statements Statement Statements ε Trace through how an LL(1) parser for this grammar would parse the program while isZero? identifier do { if not isZero? identifer then constant => identifier; }
Image of page 2
When tracing through the parser steps, you don't need to explicitly construct FIRST and  FOLLOW sets.  Try reasoning your way through how the parser would operate to see if  you  understand why all of the given productions would be applied at each point. Warm-up exercise 2: LR parsing (courtesy of Julie Zelenski).  Before jumping into the mechanics of creating and analyzing LR parsers, you might  want to start with an exercise to verify you have an intuitive understanding of how LR  parsing operates.  Consider the following grammar for a simplified C-like function  prototype. The terminals are  {T_Ident T_Int T_Double T_Char ( ) ; , }.
Image of page 3

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

View Full Document Right Arrow Icon
Image of page 4
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

What students are saying

  • Left Quote Icon

    As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

    Student Picture

    Kiran Temple University Fox School of Business ‘17, Course Hero Intern

  • Left Quote Icon

    I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

    Student Picture

    Dana University of Pennsylvania ‘17, Course Hero Intern

  • Left Quote Icon

    The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

    Student Picture

    Jill Tulane University ‘16, Course Hero Intern