summaryrefslogtreecommitdiff
path: root/full-parse.rkt
diff options
context:
space:
mode:
authorHugo <hugo.hornquist@gmail.com>2016-05-09 15:52:13 +0200
committerHugo <hugo.hornquist@gmail.com>2016-05-09 16:10:36 +0200
commit9c3637a69c186fb23fce6b253c866ddfe3a70d1e (patch)
tree53294e2c6a99d512fed053711730468056567f48 /full-parse.rkt
parentparser now handles numbers with more than one digit, inculding decimals and o... (diff)
downloadmath-parse-9c3637a69c186fb23fce6b253c866ddfe3a70d1e.tar.gz
math-parse-9c3637a69c186fb23fce6b253c866ddfe3a70d1e.tar.xz
removed everything but the parser, move project from racket to guile
Diffstat (limited to 'full-parse.rkt')
-rw-r--r--full-parse.rkt67
1 files changed, 0 insertions, 67 deletions
diff --git a/full-parse.rkt b/full-parse.rkt
deleted file mode 100644
index a20583c..0000000
--- a/full-parse.rkt
+++ /dev/null
@@ -1,67 +0,0 @@
-#lang racket
-
-(provide full-parse)
-
-; parses a function written in mathematical notation to lisp notation
-; currently handles (+ - * / ^). It does respect the order of operations
-(define (full-parse str)
- (define (get-general expr operator next-operation)
-
- ; adds a operation to the list of operations
- ; if it's a number or a single variable then it's just added
- ; if it's an operation then it's evaluated
- (define (add-operation-to-list operation seq)
- (cons (if (= (length operation) 1)
- (char->wanted (car operation))
- (next-operation (reverse operation)))
- seq))
-
- (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)
- (inner '()
- (add-operation-to-list current-term other-terms)
- (cdr remaining-expression))]
- [else
- (inner (cons (car remaining-expression) current-term)
- other-terms
- (cdr remaining-expression))]))
-
-
- (if (not (contains operator expr))
- (next-operation expr)
- (cons (char->wanted operator) (reverse (inner '() '() expr)))))
-
- (define (contains value seq)
- (memq value seq))
-
- ; char->number if numerical
- ; char->symbol otherwise
- (define (char->wanted c)
- ((if (char-numeric? c)
- string->number string->symbol)
- (string c)))
-
- ; goes from a list of chars to a number
- ; returns #f if conversion is not possible
- (define (make-number expr)
- (if (list? expr)
- (string->number (list->string expr))
- expr))
-
- ; creates a fucntion for the current operator,
- ; with a function call for the next operatior as a parameter
- (define (create-trace expr ops)
- (lambda (expr)
- ;(display expr) (newline)
- (get-general expr (car ops)
- (if (null? (cdr ops))
- (lambda (x) (make-number x))
- (create-trace expr (cdr ops))))))
-
- ; start the function, with the operations
- ; in order, from outermost to innermost.
- (let ((expr (string->list str)))
- ((create-trace expr '(#\+ #\- #\* #\/ #\^)) expr)))