CSCI 301 L30 Worksheet

Lecture 30 - Exercises

Here’s the RPN grammar: \[ \begin{align*} S & \rightarrow \_ S \mid PS \mid DNT \mid \epsilon \\ T & \rightarrow \_ S \mid PS \mid \epsilon \\ N & \rightarrow DN \mid \epsilon \\ D & \rightarrow 0 \mid 1 \mid 2 \mid \cdots \mid 9 \\ P & \rightarrow + \mid - \mid * \mid / \\ \end{align*} \]

Part A - FIRST and FOLLOW

  1. Compute the FIRST set for each nonterminal in the grammar. | Nonterminal | FIRST | | —|—————- | | \(S\) | | | \(T\) | | | \(N\) | | | \(D\) | | | \(P\) | |

Part B - Recursive Descent Parsing

Here’s the function for the \(T\) production. The parse table is given in the header comment. Complete the code for this function by filling in the TODO items.

;; T
;; prediction
;;     P    _   D   null
;; T-> PS   _S  err e
(define T
  (lambda (input)
    (cond [(null? input) ; TODO]
          [(char-whitespace? (car input)) ; TODO]
          [(D? (car input)) ; TODO]
          [ ; TODO: handle P]
           )))