Last active
June 21, 2019 15:15
-
-
Save 9214/e6378c30f21af4c75436692776fa9589 to your computer and use it in GitHub Desktop.
Extended MATH dialect.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Red [ | |
Title: "Extended MATH dialect" | |
Author: 9214 | |
Date: 12-Nov-18 | |
] | |
math: function [ | |
"Evaluate expression using PEMDAS precedence rules" | |
body [any-list!] | |
/local match | |
][ | |
table: [ | |
'** | |
['* | '/ | '% | '//] | |
['+ | '-] | |
] | |
wrap: [change copy match [skip operator skip] (do match)] | |
body: copy/deep body | |
do also body foreach operator table [ | |
parse body rule: [ | |
any [ | |
if (operator = '**) skip operator rule [fail] | |
| ahead paren! into rule [fail] | |
| some [ahead wrap] [fail] | |
| skip | |
] | |
] | |
] | |
] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment