Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Like any tool that processes text, the pretty-printer needs to parse the input f

ID: 3543631 • Letter: L

Question

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.

Parser

The parser gets tokens from the scanner and analyzes the syntactic structure of the token stream. Since

Scheme has a very simple grammar, parsing using a recursive-descent parser is not difficult.

Pretty Printing

Print the output according to the following rules:

Explanation / Answer



  

procedure

(pretty-print v [port quote-depth]) ? void?

(require racket/pretty)
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote