Changes between Version 3 and Version 4 of NQP-rx Operator Precedence Parsing
- Timestamp:
- 03/22/10 06:31:34 (3 years ago)
Legend:
- Unmodified
- Added
- Removed
- Modified
-
NQP-rx Operator Precedence Parsing
v3 v4 51 51 (If you don't know about the ternary, don't fret. Just nod and smile when your buddies get all giddy...) 52 52 53 There's a couple of choices for how to recognize ternary, but the most direct is the easiest, and since there's only one ternary op, it's the route the optable parser takes: ''you do it! ''53 There's a couple of choices for how to recognize ternary, but the most direct is the easiest, and since there's only one ternary op, it's the route the optable parser takes: ''you do it! '' 54 54 55 55 The trick is that parsing the individual `<op>` strings is still the responsibility of the coder. So is exponentiation going to be `^` or `**`? It's up to you. And so ternary is treated as a ''binary'' operator, because that code is already written. It's just that you need to recognize both parts of the op, ''and'' recognize the intermediary sub-expression: … … 192 192 '''IMPORTANT:''' Never mark a unary operator as anything but unary associative. Even if the language grammar specifies "oh, this operator is left-associative", you must mark it as `unary`. Marking it as unary tells the optable "don't look for anything else but this", whereas marking it `left` or `right` would imply "there should be another operand somewhere, you should look for it" - resulting in painful horrible death, or worse. 193 193 194 === left, right===194 ==== left, right ==== 195 195 196 196 A left- or right- associative operator will require two or more arguments, but will group them differently when they appear in bunches. A left association, like addition, will create a group starting on the left: `a + b + c` becomes `(a+b) +c`. A right association, like exponentiation, groups the other way: `x ** y ** z` becomes `(x** (y**z))`. … … 200 200 '''IMPORTANT:''' See note in unary, above. 201 201 202 === list===202 ==== list ==== 203 203 204 204 List associativity is a special treatment, mainly for the comma(`,`) operator. Instead of building a tree, the expression parser will build an array with the operands in order:
