#lang scheme ;; Assignment 9 Problem 1 (partial solution) ;; ;; Author: Gordon V. Cormack ;; Modified: Matt McPherrin and Ondrej Lhotak (update for Scheme 4.x) ;; Version: 081110.1 ;; Modified: Brad Lushman (June 30, 2011) ;; (require (lib "string.ss" "srfi" "13")) ;; ;; Helper functions and data structures ;; (define T ;; table of terminal symbols, needed for reading WLPPI format (make-immutable-hash '(("BOF") ("BECOMES") ("COMMA") ("ELSE") ("EOF") ("EQ") ("GE") ("GT") ("ID") ("IF") ("INT") ("LBRACE") ("LE") ("LPAREN") ("LT") ("MINUS") ("NE") ("NUM") ("PCT") ("PLUS") ("PRINTLN") ("RBRACE") ("RETURN") ("RPAREN") ("SEMI") ("SLASH") ("STAR") ("WAIN") ("WHILE") ("AMP") ("LBRACK") ("RBRACK") ("NEW") ("DELETE") ("NULL")) )) (define (read-parse lhs) ;; read and return wlppi parse tree (define line (read-line)) (define r (rest (string-tokenize line))) (cons line (if (hash-ref T lhs #f) empty (map read-parse r)))) (define (gen-symbols t) empty) (define (gen-code t) empty) ;; ;; Main Program ;; (define parse-tree (read-parse "S")) ;; read in wlppi format parse tree (void)