summaryrefslogtreecommitdiff
path: root/full-parse.rkt
diff options
context:
space:
mode:
Diffstat (limited to 'full-parse.rkt')
-rw-r--r--full-parse.rkt34
1 files changed, 34 insertions, 0 deletions
diff --git a/full-parse.rkt b/full-parse.rkt
new file mode 100644
index 0000000..25239a2
--- /dev/null
+++ b/full-parse.rkt
@@ -0,0 +1,34 @@
+#lang racket
+
+(provide full-parse)
+
+; + - * / ^ ( ) [0-9]
+
+(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)))
+ (define (add-operation-to-list operation seq)
+ (cons (if (= (length operation) 1)
+ (char->wanted (car operation))
+ (next-operation operation))
+ seq))
+ (define (inner cfac facts rexpr)
+ (cond
+ ((null? rexpr)
+ (reverse (add-operation-to-list cfac facts)))
+ ((eqv? (car rexpr) operator)
+ (inner '() (add-operation-to-list cfac facts) (cdr rexpr)))
+ (else
+ (inner (cons (car rexpr) cfac) facts (cdr rexpr)))))
+ (cons (char->wanted operator) (inner '() '() expr)))
+
+ (define (get-parts expr)
+ (get-general
+ expr
+ #\+
+ (lambda (expr)
+ (get-general expr #\* (lambda (x) x)))))
+ (get-parts (string->list str)))