alt.hn

4/17/2026 at 6:12:15 AM

Does your DSL little language need operator precedence?

https://utcc.utoronto.ca/~cks/space/blog/programming/LittleLanguagesVsOpPrecedence

by ingve

4/20/2026 at 8:08:06 AM

You can ignore precedence in the grammar, and then use a pratt parser or shunting yard or something to parse the precedence.

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.

by vrighter

4/19/2026 at 7:15:33 AM

Just a single function per level is sufficient for implementing both right and left association. I do not see the problem.

by fjfaase

4/19/2026 at 1:43:12 AM

hyperscript has some operator precedence, but within a given general precedence level you have to explicitly parenthesize if you use different operators:

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

by recursivedoubts

4/19/2026 at 5:25:16 AM

Yes, but it doesn't need any funny parsing trick to handle them. Just parse the whole statement as a list of expressions joined by operators, and then you can convert the flat list into a precedence-respecting tree with a few lines of code and an operator-to-precedence table.

by aappleby

4/19/2026 at 5:43:29 AM

Yes, it's as easy as that. Or check out Jonathan Blow on precedence.

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.

by childintime

4/19/2026 at 12:40:15 AM

Not if it's s-expression-based! (laughs in smug lisp weenie)

by bitwize

4/19/2026 at 1:22:56 AM

Or, if the programming language uses infix binary operators:

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.

by aleph_minus_one

4/19/2026 at 8:45:54 AM

J is APL-inspired, and APL is right-associative, so that would surprise me. https://www.jsoftware.com/help/jforc/preliminaries.htm#_Toc1... agrees with that, saying

“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.

by Someone

4/19/2026 at 10:47:51 AM

> J is APL-inspired, and APL is right-associative, so that would surprise me.

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")

by aleph_minus_one

4/19/2026 at 2:39:24 AM

Smalltalk also.

by lmz