Skip to content

Commit

Permalink
Reformat all code
Browse files Browse the repository at this point in the history
  • Loading branch information
AdamKBeck committed May 1, 2018
1 parent 6773803 commit b3a371c
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 19 deletions.
9 changes: 6 additions & 3 deletions expression-ops.scm
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#lang racket
(provide (all-defined-out))

; Checks if an expression is a a valid expression
(define G-expr?
(lambda (arglist)
(cond
Expand All @@ -15,6 +16,7 @@

(define get-op-from-expr car)

; Checks to see if a math expression is encountered
(define math-expr?
(lambda (op)
(cond
Expand All @@ -25,6 +27,7 @@
((eq? op '%) #t)
(else #f))))

; Checks to see if a boolean expression is encountered
(define boolean-expr?
(lambda (op)
(cond
Expand All @@ -33,6 +36,7 @@
((eq? op '!) #t)
(else #f))))

; Checks to see if a comparing expression is encountered
(define compare-expr?
(lambda (op)
(cond
Expand All @@ -44,8 +48,6 @@
((eq? op '>=) #t)
(else #f))))



; Determines whether a boolean in java boolean notation was encountered
(define java-boolean?
(lambda (value)
Expand All @@ -54,7 +56,7 @@
((eq? value 'false) #t)
(else #f))))


; Converted a java boolean name to a scheme boolean name (e.g. true in java is #t in scheme)
(define java-bool-to-scheme-bool
(lambda (value)
(cond
Expand Down Expand Up @@ -103,6 +105,7 @@
(or arg1 arg2)))
(else (error "unsupported boolean expression")))))

; Determines what type of operator we have
(define compare-operator-to-function-multi
(lambda (op)
(cond
Expand Down
4 changes: 2 additions & 2 deletions interpreter.scm
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,12 @@
(with-handlers ([exn:fail? error->handler])
(show-parse-tree-output (evaluate-parse-tree->retval_state (get-main-code classname staticstate)
staticstate))))))
; Used as a debugging helper for testing our code.
(define debug-call
(lambda (filename classname)
(let* ([staticstate (G-parsed-file-to-state->state (parser filename) initstate)])
`(evaluate-parse-tree->retval_state ,(get-main-code classname staticstate) ,staticstate))))

; display the value from the parse tree output
(define show-parse-tree-output
(lambda (parse-tree-output)
Expand All @@ -41,8 +43,6 @@
; gets the code portion of a function closure (arglist + code)
(define get-code-from-function-closure cadr)



(define append-main
(lambda (program)
(append program '((return (funcall main))))))
Expand Down
12 changes: 6 additions & 6 deletions state-manipulation.scm
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
(require racket/trace)



; State-empty? checks if an empty state is encountered, or if the state contains no more elements (empty)
(define state-empty?
(lambda (state)
(cond
Expand Down Expand Up @@ -40,16 +40,16 @@



; Evaluates a list of statements
(define evaluate-statement-list->state
(lambda (program state cfuncsinstance)
(cond
((null? program) state)
((not (list? program)) (error "Invalid program syntax"))
((pair? (program-head program))
(evaluate-statement-list->state
(program-tail program)
(evaluate-statement->state (program-head program) state cfuncsinstance)
cfuncsinstance))
(evaluate-statement-list->state (program-tail program)
(evaluate-statement->state (program-head program) state cfuncsinstance)
cfuncsinstance))
(else (error "Invalid statement list syntax")))))

; Returns state updated after evaluating pair
Expand Down Expand Up @@ -102,12 +102,12 @@
;------------------------------------------------------------------------------------------------------------------

; Function definition section

(define G-define-function->state
(lambda (arglist state cfuncsinstance)
(declare-function (get-function-name arglist) (get-function-formal-args arglist) (get-function-body arglist) state)))


; evaluates a declare function
(define declare-function
(lambda (function-name function-args function-body state)
(cond
Expand Down
8 changes: 3 additions & 5 deletions state-structs.scm
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,9 @@

(define cfuncs-wipe-all-but-catch
(lambda (cfuncsinstance)
(cfuncs-update-break
(cfuncs-update-continue
(cfuncs-update-return cfuncsinstance identity)
identity)
identity)))
(cfuncs-update-break (cfuncs-update-continue (cfuncs-update-return cfuncsinstance identity)
identity)
identity)))

(define identity-catch
(lambda (a b)
Expand Down
10 changes: 7 additions & 3 deletions tester.scm
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,20 @@
(if (eq? (interpret filename (findmain (parser filename))) expected-output)
(string-append "Passed " filename)
(string-append "Failed " filename
", ! Expected output: " (if (number? expected-output) (number->string expected-output) (symbol->string expected-output))
", Interpreter output: " (if (number? (interpret filename (findmain (parser filename)))) (number->string (interpret filename (findmain (parser filename)))) (symbol->string
(interpret filename (findmain (parser filename)))))))))
", ! Expected output: " (if (number? expected-output)
(number->string expected-output)
(symbol->string expected-output))
", Interpreter output: " (if (number? (interpret filename (findmain (parser filename))))
(number->string (interpret filename (findmain (parser filename))))
(symbol->string (interpret filename (findmain (parser filename)))))))))

(define member*
(lambda (x lis)
(cond
((null? lis) #f)
((not (list? lis)) (equal? x lis))
(else (or (member* x (car lis)) (member* x (cdr lis)))))))

(define findmain
(lambda (parse-tree)
(cond
Expand Down

0 comments on commit b3a371c

Please sign in to comment.