diff options
Diffstat (limited to 'full-parse.rkt')
-rw-r--r-- | full-parse.rkt | 16 |
1 files changed, 10 insertions, 6 deletions
diff --git a/full-parse.rkt b/full-parse.rkt index ae80640..cec14e2 100644 --- a/full-parse.rkt +++ b/full-parse.rkt @@ -11,6 +11,7 @@ ((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 ; 3 and x are in the product iteration @@ -21,16 +22,19 @@ (char->wanted (car operation)) (next-operation operation)) seq)) + (define (contains value seq) (memq value seq)) - (define (inner cfac facts rexpr) + + (define (inner current-term other-terms remaining-expression) (cond - [(null? rexpr) - (reverse (add-operation-to-list cfac facts))] - [(eqv? (car rexpr) operator) - (inner '() (add-operation-to-list cfac facts) (cdr rexpr))] + [(null? remaining-expression) + (reverse (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 - (inner (cons (car rexpr) cfac) facts (cdr rexpr))])) + (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)))) |