Does your DSL little language need operator precedence?
Posted by ingve 4 days ago
Comments
Comment by vrighter 1 day ago
But yes, it does need it, usually. And it's not a huge thing to implement. I usually implement it in the grammar, with inline node folding inserted for left associative operators, which gets me a very nice clean AST.
Comment by bitwize 2 days ago
Comment by aleph_minus_one 2 days ago
Not if the programming language has evaluation order from left to right, e.g.
2+3*4
is evaluated as
(2+3)*4.
For example J uses this kind of evaluation.
Comment by Someone 2 days ago
“All J verbs (functions and operators) have the same priority and associate right-to-left. For example, a b + c is equivalent to a * (b + c), not (a * b) + c.”*
Your point about not needing operator precedence still stands, though.
Comment by aleph_minus_one 2 days ago
You are indeed right (it has been quite a long time since I experimented with J):
> https://www.jsoftware.com/help/jforc/preliminaries.htm (scroll down to "Order of Evaluation")
Comment by lmz 2 days ago
Comment by fjfaase 2 days ago
Comment by recursivedoubts 2 days ago
https://github.com/bigskysoftware/_hyperscript/blob/06f9078a...
https://github.com/bigskysoftware/_hyperscript/blob/06f9078a...
this eliminates most practical precendence questions
NB: one thing that may strike people as strange is that the parse methods are on the parse elements themselves, I like to localize everything about a parse element in one place
Comment by aappleby 2 days ago
Comment by childintime 2 days ago
The infamous dragon book convinced people to use the wrong tools and have the wrong mindset. It was a work of incompetence. There were no dragons, but the book itself.