diff options
author | Hugo <hugo.hornquist@gmail.com> | 2016-04-27 15:58:35 +0200 |
---|---|---|
committer | Hugo <hugo.hornquist@gmail.com> | 2016-04-27 15:58:35 +0200 |
commit | e4ef3cda16994283c7fc6dda62181d5dfd8edfdd (patch) | |
tree | 84af0bb2abd8554b84c2562788a9c3bfd2042476 | |
parent | added more reverse, works fine except top level which is backwards (diff) | |
download | math-parse-e4ef3cda16994283c7fc6dda62181d5dfd8edfdd.tar.gz math-parse-e4ef3cda16994283c7fc6dda62181d5dfd8edfdd.tar.xz |
full-parse now returns the operations in the correct order!
-rw-r--r-- | full-parse.rkt | 28 |
1 files changed, 17 insertions, 11 deletions
diff --git a/full-parse.rkt b/full-parse.rkt index cb1d38b..832e2a6 100644 --- a/full-parse.rkt +++ b/full-parse.rkt @@ -7,10 +7,6 @@ ; 5+3*x (define (full-parse str) (define (get-general expr operator next-operation) - (define (char->wanted c) - ((if (char-numeric? c) - string->number string->symbol) - (string c))) ; used to add a completed part of the operation to the list of operations ; 5 is one of those in the addition iteration @@ -20,7 +16,7 @@ ;(newline) (cons (if (= (length operation) 1) (char->wanted (car operation)) - (next-operation operation)) + (next-operation (reverse operation))) seq)) (define (contains value seq) @@ -29,19 +25,29 @@ (define (inner current-term other-terms remaining-expression) (cond [(null? remaining-expression) - (reverse (add-operation-to-list current-term other-terms))] + (add-operation-to-list current-term other-terms)] [(eqv? (car remaining-expression) operator) - (reverse (inner '() (add-operation-to-list current-term other-terms) (cdr remaining-expression)))] + (inner '() + (add-operation-to-list current-term other-terms) + (cdr remaining-expression))] [else - (reverse (inner (cons (car remaining-expression) current-term) other-terms (cdr remaining-expression)))])) + (inner (cons (car remaining-expression) current-term) + other-terms + (cdr remaining-expression))])) (if (not (contains operator expr)) (next-operation expr) - (cons (char->wanted operator) (inner '() '() expr)))) + (cons (char->wanted operator) (reverse (inner '() '() expr))))) + + (define (char->wanted c) + ((if (char-numeric? c) + string->number string->symbol) + (string c))) (define (create-trace expr ops) - (lambda (expr) - (get-general expr (car ops) + (lambda (expr) + (display expr) (newline) + (get-general expr (car ops) (if (null? (cdr ops)) (lambda (x) x) (create-trace expr (cdr ops)))))) |