170_Problem_Set_2

170_Problem_Set_2 - CS143 Summer2011 Handout17 July8th,2011

Info iconThis 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  S   A where the nonterminal A can't be further expanded, or S   Sa where S can never be fully expanded. 2. Every nonterminal is reachable from the start symbol.  That is, grammars like S   a | bS X   c are not allowed. Due Monday, July 18 th  at 5:00PM
Background image of page 1

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

View Full DocumentRight 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; }
Background 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 ( ) ; , }. These tokens will be  recognized by the scanner and passed to the parser. Proto
Background image of page 3

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

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

This document was uploaded on 07/18/2011.

Page1 / 10

170_Problem_Set_2 - CS143 Summer2011 Handout17 July8th,2011

This preview shows document pages 1 - 4. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online