Open Akuli opened 1 year ago
Perhaps, operator precedence?
The way operator precedence is implemented now is super simple: if a function parse_foo()
calls parse_bar()
, then bar has higher precedence than foo, because parse_bar()
parses as much bar as it can, and all that occurs inside a foo.
The ->
operator has higher precedence than ++
, so that foo->bar++
works properly. But it means that foo++->bar
doesn't work. The two functions for parsing ++
and ->
should either be combined together, or they could call each other recursively.
Functions and parentheses mark precedence for the interior otherwise left to right? This would allow functions called in a function to get called in proper order and statements can get done properly (i.e. 5(3+(5-6))
is equal to 10) but statements that want to be read left to right are the default. You could also make parentheses evaluate earlier so you do something like (foo++)->bar
?
(foo++)->bar
is already supported.
Now that I look at this again, IMO it's pefectly fine if the compiler doesn't understand foo++->bar
. Someone new to Jou could easily struggle with understanding that:
++->
means ++
then ->
->
does not mean -
then >
++
does not mean +
then +
again.That said, the compiler's error message isn't great. For this file
def main() -> int:
foo++->bar
return 0
it produces:
compiler error in file "a.jou", line 2: expected end of line, got '->'
https://github.com/Akuli/jou/blob/a3f82bc3d8d5cc228d278a4dfb6feb2f55bb9778/self_hosted/parser.jou#L31
Ideally
foo++->bar
would be valid syntax. Whenfoo
is a pointer to a struct, this increments the pointer and retrievesbar
field from the instance where the pointer pointed before incrementing. But it doesn't work.