summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHugo <hugo.hornquist@gmail.com>2016-05-09 18:32:26 +0200
committerHugo <hugo.hornquist@gmail.com>2016-05-09 18:32:26 +0200
commit560fabd16c0d8bf9d9ade28d661a2ec3478ca061 (patch)
treef48b09bad142453b812bcbd7df6ea4bc234f0a9e
parentremoved everything but the parser, move project from racket to guile (diff)
downloadmath-parse-560fabd16c0d8bf9d9ade28d661a2ec3478ca061.tar.gz
math-parse-560fabd16c0d8bf9d9ade28d661a2ec3478ca061.tar.xz
now returns #f if given an invalid expression
-rw-r--r--math-parser.scm18
1 files changed, 10 insertions, 8 deletions
diff --git a/math-parser.scm b/math-parser.scm
index 1048250..b9ef4b9 100644
--- a/math-parser.scm
+++ b/math-parser.scm
@@ -14,16 +14,16 @@
(define (inner current-term other-terms remaining-expression)
(cond
- [(null? remaining-expression)
- (add-operation-to-list current-term other-terms)]
- [(eqv? (car remaining-expression) operator)
+ ((null? remaining-expression)
+ (add-operation-to-list current-term other-terms))
+ ((eqv? (car remaining-expression) operator)
(inner '()
(add-operation-to-list current-term other-terms)
- (cdr remaining-expression))]
- [else
+ (cdr remaining-expression)))
+ (else
(inner (cons (car remaining-expression) current-term)
other-terms
- (cdr remaining-expression))]))
+ (cdr remaining-expression)))))
(if (not (contains operator expr))
@@ -59,5 +59,7 @@
; start the function, with the operations
; in order, from outermost to innermost.
- (let ((expr (string->list str)))
- ((create-trace expr '(#\+ #\- #\* #\/ #\^)) expr)))
+ (let* ((expr (string->list str))
+ (trace ((create-trace expr '(#\+ #\- #\* #\/ #\^)) expr)))
+ (if (contains-false? trace)
+ #f trace)))