Skip to content

Commit

Permalink
Port everything to Racket
Browse files Browse the repository at this point in the history
  • Loading branch information
dbgrigsby committed Mar 3, 2018
1 parent e7f9129 commit 61303f3
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 23 deletions.
18 changes: 12 additions & 6 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,14 @@
# Created by https://www.gitignore.io/api/scheme
# Created by https://www.gitignore.io/api/scheme,racket

### Racket ###
*.rkt~
*.rkt.bak
\#*.rkt#
\#*.rkt#*#
*.dep
*.zo

compiled

### Scheme ###
*.ss~
Expand All @@ -9,10 +19,6 @@
*.scm#*
.#*.scm

# End of https://www.gitignore.io/api/scheme

### WINDOWS ###
*.bak
# End of https://www.gitignore.io/api/scheme,racket

#### MAC ###
.DS_Store
5 changes: 3 additions & 2 deletions interpreter.scm
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
; Brett Johnson
; Adam Beck
; Daniel Grigsby

(load "simpleParser.scm")
#lang racket
(require "simpleParser.scm")
(provide (all-defined-out))

; This section reads code from a file, parses it to a list,
; interprets it and returns the return value or error
Expand Down
8 changes: 4 additions & 4 deletions lex.scm
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
; Uncomment these two lines if you are using racket instead of scheme
;#lang racket
;(provide (all-defined-out))
#lang racket
(provide (all-defined-out))

;;===============================================================
;; The Lexical Analyzer
Expand Down Expand Up @@ -41,7 +41,7 @@

; read the next character from the file

(define readchar
(define readchar
(lambda (port)
(if saved-last-char
(begin
Expand Down Expand Up @@ -79,7 +79,7 @@

; return a lexeme with the next read symbol

(define return-id-lex
(define return-id-lex
(lambda (id)
(if (memq id reserved-word-list)
(if (or (eq? id 'false) (eq? id 'true))
Expand Down
16 changes: 7 additions & 9 deletions simpleParser.scm
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
; If you are using racket instead of scheme, uncomment these two lines, comment the (load "lex.scm") line and uncomment the (require "lex.scm") line
;#lang racket
;(provide (all-defined-out))
#lang racket
(provide (all-defined-out))

; A simple parser for a Java-ish language
; EECS 345: Programming Language Concepts
Expand All @@ -14,8 +14,8 @@
;
; The return value is a parse tree in list format

(load "lex.scm")
;(require "lex.scm")
;(load "lex.scm")
(require "lex.scm")

(define parser
(lambda (filename)
Expand Down Expand Up @@ -165,8 +165,8 @@
(lambda ()
(let* ((firstoperand (value-parse))
(op (get-next-symbol)))
(if (and (eq? (car op) 'BINARY-OP)
(or (eq? (cdr op) '==)
(if (and (eq? (car op) 'BINARY-OP)
(or (eq? (cdr op) '==)
(eq? (cdr op) '<)
(eq? (cdr op) '>)
(eq? (cdr op) '<=)
Expand All @@ -186,7 +186,7 @@
(begin
(unget-next-symbol)
(cons 'var lhs))))))


; parse an assignment statement: a left-hand-side followed by an = followed by a value

Expand Down Expand Up @@ -338,5 +338,3 @@
((eq? (car firstsymbol) 'ID) (cdr firstsymbol))
((eq? (car firstsymbol) 'BOOLEAN) (cdr firstsymbol))
(else (error 'parser "Unknown statmement")))));)


10 changes: 8 additions & 2 deletions tester.scm
Original file line number Diff line number Diff line change
@@ -1,11 +1,17 @@
(load "interpreter.scm")
#lang racket
(require "interpreter.scm")


; Tester

; General testing framework
(define test
(lambda (filename expected-output)
(if (eq? (interpret filename) expected-output)
(string-append "Passed " filename)
(string-append "Failed " filename " ! Expected output: " (number->string expected-output) ", Interpreter output: " (symbol->string (interpret filename))))))
(string-append "Failed " filename
", ! Expected output: " (number->string expected-output)
", Interpreter output: " (symbol->string (interpret filename))))))

; Tests 1
(newline)(newline)
Expand Down

0 comments on commit 61303f3

Please sign in to comment.