Initial data commit
This commit is contained in:
parent
72d218235f
commit
f23f22d71c
199087 changed files with 3378941 additions and 0 deletions
53
Task/Arithmetic-evaluation/TXR/arithmetic-evaluation.txr
Normal file
53
Task/Arithmetic-evaluation/TXR/arithmetic-evaluation.txr
Normal file
|
|
@ -0,0 +1,53 @@
|
|||
@(next :args)
|
||||
@(define space)@/ */@(end)
|
||||
@(define mulop (nod))@\
|
||||
@(local op)@\
|
||||
@(space)@\
|
||||
@(cases)@\
|
||||
@{op /[*]/}@(bind nod @(intern op *user-package*))@\
|
||||
@(or)@\
|
||||
@{op /\//}@(bind (nod) @(list 'trunc))@\
|
||||
@(end)@\
|
||||
@(space)@\
|
||||
@(end)
|
||||
@(define addop (nod))@\
|
||||
@(local op)@(space)@{op /[+\-]/}@(space)@\
|
||||
@(bind nod @(intern op *user-package*))@\
|
||||
@(end)
|
||||
@(define number (nod))@\
|
||||
@(local n)@(space)@{n /[0-9]+/}@(space)@\
|
||||
@(bind nod @(int-str n 10))@\
|
||||
@(end)
|
||||
@(define factor (nod))@(cases)(@(expr nod))@(or)@(number nod)@(end)@(end)
|
||||
@(define term (nod))@\
|
||||
@(local op nod1 nod2)@\
|
||||
@(cases)@\
|
||||
@(factor nod1)@\
|
||||
@(cases)@(mulop op)@(term nod2)@(bind nod (op nod1 nod2))@\
|
||||
@(or)@(bind nod nod1)@\
|
||||
@(end)@\
|
||||
@(or)@\
|
||||
@(addop op)@(factor nod1)@\
|
||||
@(bind nod (op nod1))@\
|
||||
@(end)@\
|
||||
@(end)
|
||||
@(define expr (nod))@\
|
||||
@(local op nod1 nod2)@\
|
||||
@(term nod1)@\
|
||||
@(cases)@(addop op)@(expr nod2)@(bind nod (op nod1 nod2))@\
|
||||
@(or)@(bind nod nod1)@\
|
||||
@(end)@\
|
||||
@(end)
|
||||
@(cases)
|
||||
@ {source (expr e)}
|
||||
@ (output)
|
||||
source: @source
|
||||
AST: @(format nil "~s" e)
|
||||
value: @(eval e nil)
|
||||
@ (end)
|
||||
@(or)
|
||||
@ (maybe)@(expr e)@(end)@bad
|
||||
@ (output)
|
||||
erroneous suffix "@bad"
|
||||
@ (end)
|
||||
@(end)
|
||||
Loading…
Add table
Add a link
Reference in a new issue