19 lines
449 B
Plaintext
19 lines
449 B
Plaintext
#import std
|
|
#import nat
|
|
#import flo
|
|
|
|
lex = ~=' '*~F+ rlc both -=digits # separate into tokens
|
|
|
|
parse = # build a tree
|
|
|
|
--<';'>; @iNX ~&l->rh ^/~< cases~&lhh\~&lhPNVrC {
|
|
'*/': ^|C/~&hNV associate '*/',
|
|
'+-': ^|C/~&hNV associate '*/+-',
|
|
');': @r ~&htitBPC+ associate '*/+-'}
|
|
|
|
associate "ops" = ~&tihdh2B-="ops"-> ~&thd2tth2hNCCVttt2C
|
|
|
|
traverse = *^ ~&v?\%ep ^H\~&vhthPX '+-*/'-$<plus,minus,times,div>@dh
|
|
|
|
evaluate = traverse+ parse+ lex
|