UnionCompilerDesign / compiler_core

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

Unary vs binary minus #93

Closed Dalyj24 closed 3 weeks ago

Dalyj24 commented 1 month ago

Details

Right now there's only one minus token and the parser can't distinguish between a unary and a binary - sign. This means that something like "5 - 1" is detected right, but the number "-5" is not.

Issue Type

Requirements

Probably add a new token so that the parser can know the difference, and then edit the parser to parse a unary - correctly.

Notes

CalebLItalien commented 1 month ago

@Dalyj24 What kind of token would you consider adding?

kjwelch commented 1 month ago

Image

kjwelch commented 1 month ago

Here is my approach to unary vs binary operators worked out in pseudocode for '-'. In dealing with subtraction vs negative tokens for '-', these other binary cases (-= and --) should be handled as well (To cover all tokens with '-'). Currently, tokens do not exist for the following binary (-=,+=) and unary (--, ++) operators despite existing in the list of acceptable tokens. Similar logic should also extend to +, +=, and ++.

This may or may not be helpful for issue #57 @Dalyj24 :)