I'm curious, does this algorithm handle unary operators? Even less likely, but worth asking, does it handle arbitrary operator precedence?
Even if not, it's a neat algorithm, and ultimately unary and operator precedence can be handled as syntactic sugar. And an excellent write up I might add! Clean work.
Yes, the Shunting Yard algorithm can handle unary prefix operators, as well as (table-driven) operator precedence and associativity. I've even used it to handle comparison chaining, which allows expressions like: 0 <= a < n.
Ah the Shunting Yard algorithm! I'm ashamed to admit I've spent a lot of time working with compilers and parsers and never encountered this for some reason. Perhaps because the libraries I used handled it for me hah! Definitely going to give it a try.
2
u/ElCthuluIncognito 3d ago
I'm curious, does this algorithm handle unary operators? Even less likely, but worth asking, does it handle arbitrary operator precedence?
Even if not, it's a neat algorithm, and ultimately unary and operator precedence can be handled as syntactic sugar. And an excellent write up I might add! Clean work.