Lab 5: Scanning & Parsing
Bard College – Computer Science – Design of Programming Languages

This labs gives us practice using lexing and parsing tools to interpret (non-lisp) programs. Specifically, we’ll be processing JavaScript Object Notation (JSON). From Eloquent JavaScript, “JSON is widely used as a data storage and communication format on the Web, even in languages other than JavaScript.” Fun data sets represented in JSON can be found in Darius Kazemi’s  corpora project.

Warm Up: Infix Expressions

Use sllgen  and define-datatype to parse infix expressions (from Exercise B.1).
#lang racket
(require eopl)

(define the-lexical-spec
  '((whitespace (whitespace) skip)
    (mul-op ("*") symbol)
    (add-op ("+") symbol)
    (number (digit (arbno digit)) number)))

(define the-grammar
  '((a-expr ;:==
        (a-term (arbno add-op a-term))       binop)
    (a-term ;:==
        (a-factor (arbno mul-op a-factor))   binop)
    (a-factor ;:==
         (number)                            number)
    (a-factor ;:==
         ("(" a-expr ")")                    factor)))

(define-datatype infix infix?
  (binop
    (left infix?)
    (operators (list-of symbol?))
    (right (list-of infix?)))
  (factor
    (value infix?))
  (number
    (value integer?)))

(define just-scan
    (sllgen:make-string-scanner the-lexical-spec the-grammar))

(define scan&parse
  (sllgen:make-string-parser the-lexical-spec the-grammar))

(display (just-scan "2 + 3 * 4"))
(newline)
(display (scan&parse "2 + 3 * 4"))
(newline)

What does the program output? Put this information in a comment.