proj1 - Project 1: Scheme Pretty-Printer CSC 4101, Fall...

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: Project 1: Scheme Pretty-Printer CSC 4101, Fall 2011 Due: 29 September 2011 For this programming assignment, you will implement a pretty-printer for Scheme in either C++ or Java. The code should be developed in a team of two using pair programming. Your pretty-printer will read a Scheme program from standard input, parse it, and print it back out onto standard output. The output program will be indented in a uniform style. (It won’t really be all that pretty.) You should use an object- oriented programming style using inheritance and virtual functions where appropriate. Structure of the Pretty-Printer Like any tool that processes text, the pretty-printer needs to parse the input first and store it in an internal data structure, before it can print it in some indented style. The pretty-printer consists of the following parts: 1. a lexical analyzer that splits the input text into tokens, 2. a recursive-descent parser that analyses the structure of the input program and builds a parse tree, 3. a parse-tree traversal that pretty-prints the input program. Lexical Analysis In lexical analysis, the input file is broken into individual words or symbols. These words or symbols are then represented as tokens and passed to the parser. Your lexical analyzer needs to read ASCII characters from standard input and do the following: 1. discard white space (space, tab, newline, carriage-return, and form-feed characters), 2. discard comments (everything from a semicolon to the end of the line), 3. recognize quotes, dots, and open and closing parentheses, 4. recognize the boolean constants #t and #f , 5. recognize integer constants (for simplicity only decimal digits without a sign), 6. recognize string constants (anything between double quotes), 7. recognize identifiers. For the precise definition of identifiers, see the Revised 5 Scheme Report and follow that specification: •˜jaffer/r5rs_4.html 1 •˜jaffer/r5rs_9.html Scheme does not distinguish between uppercase and lowercase characters in identifiers. It is, therefore, easiest for later parts of the pretty printer or the interpreter to convert all letters to lowercase. The typical structure of a lexical analyzer is to write a function getNextToken() , that reads a char- acter at a time from the input and returns the next token that it finds. Use a program structure like this (in C++ syntax): enum TokenType { QUOTE, DOT, LPAREN, RPAREN, TRUET, FALSET, INT, STRING, IDENT }; class Token { TokenType tt; // ... }; class IntToken : public Token { int intVal; // ......
View Full Document

This note was uploaded on 12/31/2011 for the course CSC 4101 taught by Professor Kraft,d during the Fall '08 term at LSU.

Page1 / 6

proj1 - Project 1: Scheme Pretty-Printer CSC 4101, Fall...

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