UnionCompilerDesign / compiler_core

The core of the compiler, runtime, and builder setup.
MIT License
1 stars 1 forks source link

Binary Vs Unary Minus #118

Closed kjwelch closed 3 weeks ago

kjwelch commented 4 weeks ago

This concludes issue #93

Dalyj24 commented 4 weeks ago

This looks awesome, but I messed up badly by suggesting adding a new token. Don't worry though, the fix shouldn't be too bad. So, the lexer technically can't distinguish unary and binary minus, but the PARSER can. So what you have to do so in the parse router make a special case for the MINUS token separate from the other binary expression ones, and if there's an operand on the both sides of the minus then use parse binary expression, and if there isn't then use parse unary expression. I'm sorry, that suggestion's on me. I think there's a function is_operand or something in parse_binary_exp you can use to get the two comparisons.

Dalyj24 commented 4 weeks ago

https://teaching.idallen.com/cst8152/97s/unary_minus.html

Dalyj24 commented 4 weeks ago

This also may not work if a binary expression is already being parsed, but we can worry about that later...or not at all, honestly.

CalebLItalien commented 4 weeks ago

I think the token should just be dash and we should repeat this pattern with any other tokens that are trying to infer their semantic meaning. @kjwelch , can you triage with #97 and make sure this is the standard?