lecture12 - 3/10/2009 Today COMPUTER SCIENCE 51 Spring 2009

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

View Full Document Right Arrow Icon
3/10/2009 1 COMPUTER SCIENCE 51 Spring 2009 cs51.seas.harvard.edu Prof. Greg Morrisett Prof. Ramin Zabih Today Check your email: do the survey!!! Parsing how to describe syntax (BNF) how to implement a recognizer (later, a parser ) from the syntax description. using lambda to generate code for you. Some Motivation Consider a service like Google search: www.google.com/search?q=Morrisett In essence, calling a search procedure with a parameter of “Morrisett”. www.google.com/search?q=Morrisett+Zabih Now searching for pages with “Morrisett” and “Zabih”. More Google Image search: www.google.com/images?q=Greg Return first 100 links instead of default: Where the pages are in Chinese: h-CN There are Many Options. .. Search Terms conjunction: ?q=Greg+Morrisett disjunction: Restrict search to domain: ... Order doesn’t matter. What Has to Happen? Google gets URL as a request: It must turn this string of characters into procedure calls to its search engine. This is proprietary to Google But for many web services, the URL gets converted into a SQL query for a database. e.g., “SELECT * FROM table WHERE . ..” perform post-processing (e.g., get only 100) print the results as HTML
Background image of page 1

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

View Full DocumentRight Arrow Icon
3/10/2009 2 Imagine. .. You have a “database” of papers. title, authors, journal, date, etc. perhaps represented as a list of structs. You have written a set of procedures: add entries to the list sort the list by some field filter the list by some predicate And now you want to turn this into a web service like Google’s search. accept URL’s as commands perform commands specified by the URL print any results as HTML Taking a string of characters like: search?author=Morrisett or recognize: checking that the string is legal i.e., it is a proper command parse: figuring out what command the string represents i.e., call filter and sort with appropriate arguments i.e., create new struct, and add it to the list First Task: Recognition We can describe the syntax of commands using something like Backus-Naur Form (BNF): com ::= ? add fieldarg+ | ? search fieldarg+ sortarg? fieldarg ::= & field = id+ | & year = number sortarg ::= & sort = field | field ::= author | title | journal id ::= [ a - zA - Z ]+ number := [ 1 - 9 ][ 0 - 9 ]* Some abbreviations: * is zero or more, + is one or more, ? is 0 or 1, [0-9] = 0 | 1 | 2 | 3 | . .. | 8 | 9 How Not to Write a Parser ;; com ::= ? add fieldarg+ | ? search fieldarg+ sortarg? (define (check_com cs)
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.

Page1 / 9

lecture12 - 3/10/2009 Today COMPUTER SCIENCE 51 Spring 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