Use match a little more.
This commit is contained in:
parent
93556efeeb
commit
c4d80f6c4e
|
|
@ -55,25 +55,18 @@
|
||||||
|
|
||||||
(define (joy-eval symbol stack expression dict)
|
(define (joy-eval symbol stack expression dict)
|
||||||
(match symbol
|
(match symbol
|
||||||
("+" ((joy-func +) stack expression dict))
|
((or "+" "add") ((joy-func +) stack expression dict))
|
||||||
("-" ((joy-func -) stack expression dict))
|
((or "-" "sub") ((joy-func -) stack expression dict))
|
||||||
("*" ((joy-func *) stack expression dict))
|
((or "*" "mul") ((joy-func *) stack expression dict))
|
||||||
("/" ((joy-func quotient) stack expression dict)) ; but for negative divisor, no!?
|
((or "/" "div") ((joy-func quotient) stack expression dict)) ; but for negative divisor, no!?
|
||||||
("%" ((joy-func modulo) stack expression dict))
|
((or "%" "mod") ((joy-func modulo) stack expression dict))
|
||||||
|
|
||||||
("add" ((joy-func +) stack expression dict))
|
|
||||||
("sub" ((joy-func -) stack expression dict))
|
|
||||||
("mul" ((joy-func *) stack expression dict))
|
|
||||||
("div" ((joy-func quotient) stack expression dict)) ; but for negative divisor, no!?
|
|
||||||
("mod" ((joy-func modulo) stack expression dict))
|
|
||||||
|
|
||||||
("<" ((joy-func <) stack expression dict))
|
("<" ((joy-func <) stack expression dict))
|
||||||
(">" ((joy-func >) stack expression dict))
|
(">" ((joy-func >) stack expression dict))
|
||||||
("<=" ((joy-func <=) stack expression dict))
|
("<=" ((joy-func <=) stack expression dict))
|
||||||
(">=" ((joy-func >=) stack expression dict))
|
(">=" ((joy-func >=) stack expression dict))
|
||||||
("=" ((joy-func =) stack expression dict))
|
("=" ((joy-func =) stack expression dict))
|
||||||
("<>" ((joy-func not-equal) stack expression dict))
|
((or "<>" "!=") ((joy-func not-equal) stack expression dict))
|
||||||
("!=" ((joy-func not-equal) stack expression dict))
|
|
||||||
|
|
||||||
("bool" (joy-bool stack expression dict))
|
("bool" (joy-bool stack expression dict))
|
||||||
|
|
||||||
|
|
@ -183,9 +176,10 @@
|
||||||
(values (cons (tokenator token) el) rest)))))
|
(values (cons (tokenator token) el) rest)))))
|
||||||
|
|
||||||
(define (one-token-lookahead token tokens)
|
(define (one-token-lookahead token tokens)
|
||||||
(cond ((string=? token "]") (error "Extra closing bracket."))
|
(match token
|
||||||
((string=? token "[") (expect-right-bracket tokens '()))
|
("]" (error "Extra closing bracket."))
|
||||||
(else (values (tokenator token) tokens))))
|
("[" (expect-right-bracket tokens '()))
|
||||||
|
(_ (values (tokenator token) tokens))))
|
||||||
|
|
||||||
(define (parse0 tokens acc)
|
(define (parse0 tokens acc)
|
||||||
(if (null? tokens)
|
(if (null? tokens)
|
||||||
|
|
@ -229,7 +223,8 @@
|
||||||
(load-defs! (make-hash-table string=? string-hash)))
|
(load-defs! (make-hash-table string=? string-hash)))
|
||||||
|
|
||||||
(define (load-defs! dict)
|
(define (load-defs! dict)
|
||||||
(for-each (lambda (def) (add-def! def dict)) (defs)) ;defs is defined in defs.scm
|
(for-each (lambda (def) (add-def! def dict)) (defs))
|
||||||
|
; defs is defined in defs.scm
|
||||||
dict)
|
dict)
|
||||||
|
|
||||||
(define (add-def! def dict)
|
(define (add-def! def dict)
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue