Re:Puffs: Parsing Untrusted File Formats Safely
by evincarofautumn on Thursday November 16, 2017 @09:19AM
(#15712739)
I agree, although I suppose different operators could still have different associativity in a language without precedence. I took that phrasing from the “Puffs the Language” documentation.
Re:Puffs: Parsing Untrusted File Formats Safely
by masklinn on Thursday November 16, 2017 @09:33AM
(#15712841)
> I suppose different operators could still have different associativity in a language without precedence
That… is true, and I have a hard time computing how it would even work.
Re:Puffs: Parsing Untrusted File Formats Safely
by evincarofautumn on Thursday November 16, 2017 @11:16AM
(#15713815)
One way to do it would be to have a default associativity between different operators, but chains of the same operator can override it, e.g. suppose “⧺” means concatenation (rightward), “×” means repetition (leftward), and the default is leftward:
[1, 2] ⧺ [3, 4] ⧺ [5, 6] × 2 × 3
(([1, 2] ⧺ ([3, 4] ⧺ [5, 6])) × 2) × 3
[ [ [1…6], [1…6] ],
[ [1…6], [1…6] ],
[ [1…6], [1…6] ] ]
I dunno how good an idea that would be in practice, though.
Re:Puffs: Parsing Untrusted File Formats Safely
by klodolph on Thursday November 16, 2017 @11:06AM
(#15713738)
Think exponentiation, where 2^3^4 might be 2^(3^4), but where subtraction 2-3-4 is (2-3)-4.
Re:Puffs: Parsing Untrusted File Formats Safely
by mnarayan01 on Thursday November 16, 2017 @11:13AM
(#15713791)
Consider:
2-3^4
Re:Puffs: Parsing Untrusted File Formats Safely
by irishsultan on Thursday November 16, 2017 @12:18PM
(#15714470)
Since there is no precedence in this (hypothetical) language that would be an invalid expression.
Re:Puffs: Parsing Untrusted File Formats Safely
by nigeltao on Thursday November 16, 2017 @06:54PM
(#15717800)
What I mean is that you can't write "2 + 3 * 4", not even with implicit LTR, you have to write either "(2 + 3) * 4" or "2 + (3 * 4)".
See e.g the "precedence bug" comment I wrote elsewhere on this page.
Re:Puffs: Parsing Untrusted File Formats Safely
by masklinn on Friday November 17, 2017 @03:57AM
(#15720326)
My point is that's not "equal precedence". Smalltalk has equal precedence, "2 + 3 * 4" parses as "(2 + 3) * 4". If you reject the expression entirely you don't have equal precedences, you have unmixable operators or precedences (the latter being if "2 + 3 - 4" is still allowed).
Doesn't that mean it rejects precedence? In a language equal precedence (e.g. Smalltalk), operators would just be executed from LTR or RTL.