ps06 - CS51 Assignment 6: Tunes Due: Tue, April 7th, 2009,...

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

View Full Document Right Arrow Icon

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

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

Unformatted text preview: CS51 Assignment 6: Tunes Due: Tue, April 7th, 2009, 11:59 PM Total Points: 55 (including 5 style points) In this assignment, you will use the parser combinators we learned about in lecture to parse an input file. You will begin by writing a Backus-Naur Form grammar describing the proper format for a specific type of input. Then, generalizing to arbitrary structures represented in flat XML text files, we will use the magic of parser combinators to bring these structures to life in our code. You should refer to Lecture 11 and Section 6 notes for more information about parsing in Scheme. The file , which is included at the top of the Scheme file, has all of the parser combinators and other functions youll need for this assignment, including those used below. (You may not need all of the combinators defined in the file.) You can download the file on the website in order to see the definitions of the combinators, or look in the lecture notes. Note: this assignment may seem extraordinarily long dont panic! This is because weve written lots and lots of code for you, as well as duplicated much of the code from the .scm file in the PDF. You have to make sense of it, but only have to write a very small amount of code yourself. 1 Understanding Parsing In Project 1b, we wrote a function valid-parse? that told us whether a sentence was valid in the pirate grammar. However, in Lectures 11 and 12, we learned that valid-parse? was not actually a parser it was, as we now know, a recognizer, since it only returned # t or # f depending on whether an input was in the language. In this problem set, we will see why a parser can be more useful than a recognizer: when a parser processes valid input, rather than just returning #t , a parser can return a value that represents the structural meaning of the input. For example, consider Googles search box as the input field for a parser. Everyone knows about the neat trick where you type a valid arithmetic expression, and Google solves it for you. In order to do this, Google must know that it should evaluate 1+1, but search for 1 2 XML GRAMMAR CS51 Assignment 6: Tunes 1++1. A recognizer for valid arithmetic expressions can tell it that. But given that has a valid arithmetic expression, like 1+1 or 3+5*7 or 2*the answer to life, the universe, and everything, how does it actually evaluate it? It needs to take the input string 3+5*7 and parse it, perhaps creating a rooted tree like: + / \ 3 * / \ 5 7 or, more concisely, 1 (+ 3 (* 5 7)) Given the input in this form, its fairly easy to write a function that evaluates it as an arithmetic expression. (Try it!) Parsing is especially useful in compiling programming languages, where (as with arith- metic expressions) a parser takes source code and returns an abstract syntax tree : i.e., a tree like the above, but with arbitrary operators and language constructs at the nodes. In last years problem set, we wrote a parser for Scheme in C++. This year, were going to be...years problem set, we wrote a parser for Scheme in C++....
View Full Document

This note was uploaded on 07/26/2009 for the course COMPUTERSC CS51 taught by Professor Gregmorrisett during the Spring '09 term at Harvard.

Page1 / 14

ps06 - CS51 Assignment 6: Tunes Due: Tue, April 7th, 2009,...

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