| ▲ | Does your DSL little language need operator precedence?(utcc.utoronto.ca) | |||||||||||||||||||||||||||||||
| 19 points by ingve 4 days ago | 10 comments | ||||||||||||||||||||||||||||||||
| ▲ | vrighter a day ago | parent | next [-] | |||||||||||||||||||||||||||||||
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. | ||||||||||||||||||||||||||||||||
| ▲ | bitwize 2 days ago | parent | prev | next [-] | |||||||||||||||||||||||||||||||
Not if it's s-expression-based! (laughs in smug lisp weenie) | ||||||||||||||||||||||||||||||||
| ||||||||||||||||||||||||||||||||
| ▲ | fjfaase 2 days ago | parent | prev | next [-] | |||||||||||||||||||||||||||||||
Just a single function per level is sufficient for implementing both right and left association. I do not see the problem. | ||||||||||||||||||||||||||||||||
| ▲ | recursivedoubts 2 days ago | parent | prev | next [-] | |||||||||||||||||||||||||||||||
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 | ||||||||||||||||||||||||||||||||
| ▲ | aappleby 2 days ago | parent | prev [-] | |||||||||||||||||||||||||||||||
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. | ||||||||||||||||||||||||||||||||
| ||||||||||||||||||||||||||||||||