Wiki source code of Evaluating R-value Expressions

Last modified by John Stroy on 2018/10/19 11:40

Show last authors
1 {{toc/}}
2
3 = Abstract =
4
5 In this specification, we attempt to describe the process of HSP's implementation of r-values.
6
7 = Specification =
8
9 Construct an expression tree for the r-value expression.
10
11 ##{{{expression}}}## := ##{{{operand}}}##
12 ##{{{operand}}}## := ##{{{literal}}}## | ##{{{function}}}##**(**##{{{operandList}}}##**)** | ##{{{operand}}}## ##{{{infixOperator}}}## ##{{{operand}}}## | ##{{{prefixOperator}}}## ##{{{operand}}}## | ##{{{operand}}}## ##{{{postfixOperand}}}## | **(**##{{{operand}}}##**)**
13 ##{{{operandList}}}## := //##{{{empty}}}##// | ##{{{operand}}}## | (##{{{operand}}}## **,**)+ ##{{{operand}}}##
14 ##{{{literal}}}## := //##{{{numeric}}}##// | //##{{{string}}}##//
15
16 For each operator or function, add child nodes as parsed from left-to-right to the tree from left-to-right.
17
18 Evaluate expressions by walking the tree, depth first, evaluating the left-most unevaluated child first.
19
20 On encountering one or more invalid operands for an operator, an error will be thrown after evaluating both operands.
21
22 Grouping does not influence the order of operand evaluation (e.g. most nested term is not necessarily evaluated first), but grouping does influence the order of operator evaluation (e.g. restructures the tree to select which expression is a child of the other expression).