mp8 - MP 8 A Parser for PicoML CS 421 Fall 2007 Revision 1...

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: MP 8 A Parser for PicoML CS 421 Fall 2007 Revision 1 . 1 Assigned Tuesday October 30, 2007 Due Tuesday November 13, 2007 23:59 PM Extension 48 hours (20% penalty) 1 Change Log 1.1 Section 3: Corrected name of main file to picomlparse.mly (from picomllex.mly ), also names of skeletons Section 7: Added ExpoOp to the list of binary operators 1.0 Initial Release. 2 Overview In this MP, we will deal with the process of converting PicoML code into an abstract syntax tree using a parser. We will use the occamlyacc tool to generate our parser from a description of the grammar. This parser will be combined with the lexer and type inferencer from previous MPs to make an interactive PicoML interpreter (well, it does not interpret yet), where you can type in PicoML expressions and see a proof tree of the expressions type: Welcome to the Student parser > let x = 5;; val x : int final environment: {x=>int} proof: {} |= 5 : int > To complete this MP, you will need to be familiar with describing languages with BNF grammars, adding attributes to return computations resulting from the parse, and expressing these attribute grammars in a form acceptable as input to ocamlyacc . 3 Given Files picomlparse-skeleton.mly: You should copy the file picomlparse-skeleton.mly to picomlparse.mly . The skeleton contains some pieces of code that we have started for you, with triple dots indicating places where you should add code. picomlIntPar.ml: This file contains the main body of the PicoML executable. It essentially connects your lexer, parser, and type inference code and provides a friendly prompt to enter PicoML expressions. 1 picomllex.mll This file contains the ocamllex specification for the lexer. It is a modest expansion to the lexer you wrote for MP7. mp8common.ml: This file includes the types of expressions and declarations. It also contains the type inferencing code. Appropriate code from this file will automatically be called by the interactive loop defined in picomlInt- Par.ml: . 4 Overview of ocamlyacc Take a look at the given picomlparse.mly file. The grammar specification has a similar layout to the lexer specification of MP7. It begins with a header section (where you can add raw OCaml code), then has a section for directives (these start with a % character), then has a section that describes the grammar (this is the part after %% ). You will only need to add to the last section. 4.1 Example The following is the exp example from class (lecture 19-lrgrammars, slides 52 59): %token <string> Id_token %token Left_parenthesis Right_parenthesis %token Times_token Divide_token %token Plus_token Minus_token %token EOL %start main %type <expr> main %% exp: term { Term_as_Expr $1 } | term Plus_token exp { Plus_Expr ($1, $3) } | term Minus_token exp { Minus_Expr ($1, $3) } term: factor { Factor_as_Term $1 } | factor Times_token term { Mult_Term ($1, $3) } | factor Divide_token term { Div_Term ($1, $3) } factor: Id_token { Id_as_Factor $1 } | Left_parenthesis exp Right_parenthesis...
View Full Document

This homework help was uploaded on 04/21/2008 for the course CS 421 taught by Professor Kamin during the Fall '08 term at University of Illinois at Urbana–Champaign.

Page1 / 14

mp8 - MP 8 A Parser for PicoML CS 421 Fall 2007 Revision 1...

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