
The eopl language is now racket-based rather than mzscheme-based. This test-suite, which was originally distributed on the book's web-site has been re-written in the new language. Changes include dropping all drscheme-init.scm and top.scm files. Remaining files were renamed to use the .rkt extension and edited to use the #lang syntax (instead of modulue). Require and provide forms were changed to reflect racket's syntax instead of mzscheme's (eg, only-in vs. only). Several occurrences of one-armed ifs were changed to use when and unless. All tests have been run successfully.
97 lines
2.1 KiB
Racket
Executable File
97 lines
2.1 KiB
Racket
Executable File
#lang eopl
|
|
|
|
;; grammar for the CHECKED language
|
|
|
|
(provide (all-defined-out))
|
|
|
|
;;;;;;;;;;;;;;;; grammatical specification ;;;;;;;;;;;;;;;;
|
|
|
|
(define the-lexical-spec
|
|
'((whitespace (whitespace) skip)
|
|
(comment ("%" (arbno (not #\newline))) skip)
|
|
(identifier
|
|
(letter (arbno (or letter digit "_" "-" "?")))
|
|
symbol)
|
|
(number (digit (arbno digit)) number)
|
|
(number ("-" digit (arbno digit)) number)
|
|
))
|
|
|
|
(define the-grammar
|
|
'((program (expression) a-program)
|
|
|
|
(expression (number) const-exp)
|
|
(expression
|
|
("-" "(" expression "," expression ")")
|
|
diff-exp)
|
|
|
|
(expression
|
|
("zero?" "(" expression ")")
|
|
zero?-exp)
|
|
|
|
(expression
|
|
("if" expression "then" expression "else" expression)
|
|
if-exp)
|
|
|
|
(expression (identifier) var-exp)
|
|
|
|
(expression
|
|
("let" identifier "=" expression "in" expression)
|
|
let-exp)
|
|
|
|
(expression
|
|
("proc" "(" identifier ":" type ")" expression)
|
|
proc-exp)
|
|
|
|
(expression
|
|
("(" expression expression ")")
|
|
call-exp)
|
|
|
|
(expression
|
|
("letrec"
|
|
type identifier "(" identifier ":" type ")" "=" expression
|
|
"in" expression)
|
|
letrec-exp)
|
|
|
|
(type
|
|
("int")
|
|
int-type)
|
|
|
|
(type
|
|
("bool")
|
|
bool-type)
|
|
|
|
(type
|
|
("(" type "->" type ")")
|
|
proc-type)
|
|
|
|
))
|
|
|
|
;;;;;;;;;;;;;;;; sllgen boilerplate ;;;;;;;;;;;;;;;;
|
|
|
|
(sllgen:make-define-datatypes the-lexical-spec the-grammar)
|
|
|
|
(define show-the-datatypes
|
|
(lambda () (sllgen:list-define-datatypes the-lexical-spec the-grammar)))
|
|
|
|
(define scan&parse
|
|
(sllgen:make-string-parser the-lexical-spec the-grammar))
|
|
|
|
(define just-scan
|
|
(sllgen:make-string-scanner the-lexical-spec the-grammar))
|
|
|
|
;;;;;;;;;;;;;;;; type-to-external-form ;;;;;;;;;;;;;;;;
|
|
|
|
;; type-to-external-form : Type -> List
|
|
;; Page: 243
|
|
(define type-to-external-form
|
|
(lambda (ty)
|
|
(cases type ty
|
|
(int-type () 'int)
|
|
(bool-type () 'bool)
|
|
(proc-type (arg-type result-type)
|
|
(list
|
|
(type-to-external-form arg-type)
|
|
'->
|
|
(type-to-external-form result-type))))))
|
|
|