-
Notifications
You must be signed in to change notification settings - Fork 26
Expressions as Binary Trees
Matthew McCall edited this page Mar 23, 2024
·
8 revisions
Consider the following expression:
Note that we strictly follow PEMDAS as the same equation can be represented with multiple different trees. As such, we try to follow PEMDAS as strictly as possible to make the tree-matching patterns as simple as possible. Operations done first in PEMDAS are deeper in the tree. Oasis offers a convenient declarative syntax for building expression. The following represents the above expression:
Oasis::Subtract {
Oasis::Add {
Oasis::Multiply {
Oasis::Real { 2.0f },
Oasis::Exponent {
Oasis::Variable { "x" },
Oasis::Real { 2.0f }
}
},
Oasis::Variable { "x" }
},
Oasis::Real { 1.0f }
};