From e4ef3cda16994283c7fc6dda62181d5dfd8edfdd Mon Sep 17 00:00:00 2001 From: Hugo Date: Wed, 27 Apr 2016 15:58:35 +0200 Subject: full-parse now returns the operations in the correct order! --- full-parse.rkt | 28 +++++++++++++++++----------- 1 file 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)))))) -- cgit v1.2.3