Homework2-sol - COP 5555 Programming Language Principles...

Info iconThis preview shows pages 1–3. Sign up to view the full content.

View Full Document Right Arrow Icon
COP 5555 Programming Language Principles Homework 2 Solution 1. Problem 1 (25 Points) Consider the following grammar: A -> B (',' B)+ => "a" -> B B -> B '&' C => "b" -> C C -> D '#' C => "c" -> D D -> <identifier> Write the skeleton of a recursive descent parser for this grammar, including 'BuildTree' statements that will build the AST bottom-up, for the original grammar. Hint: See Powerpoint lecture 6. Solution: Proc A; { A -> B ("," B)+ => "a" ->B } Var N: Integer; B; N :=1; While Next_Token = T_, do Read (T_,); B; N := N + 1; Od Build_Tree ("a",N); end; Proc B; { B -> B "&" C => "b" -> C } C; while NexT_Token = T_& do Read (T_&); C;
Background image of page 1

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

View Full DocumentRight Arrow Icon
Build_Tree ("b", 2); Od end; Proc C; { C -> D "#" C => "c" -> D } D; if NexT_Token = T_# then Read (T_#); C; Build_Tree ("b", 2); end end; proc D; {D - > <ideng er> } Read( T_<ideng er> ); end; 2. Problem 2 (25 Points) The followinG RPAL proGram is overly parenthesized; remove all superfluous parentheses, i.e. minimize the parentheses without chanGinG the meaninG of
Background image of page 2
Image of page 3
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 01/22/2012 for the course COP 5555 taught by Professor Staff during the Fall '08 term at University of Florida.

Page1 / 3

Homework2-sol - COP 5555 Programming Language Principles...

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

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