-
Hi! I am a bit confused by the fact that let x = 2 * if (false) 3 else 4 + 5 compiles (in the Try window) and prints 18 Can this be explained in terms of operator priorities or BNF-like grammar? |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 3 replies
This comment has been hidden.
This comment has been hidden.
-
Hey @dermagen. You can find Grain's general operator precedence here: https://github.com/grain-lang/grain/blob/main/docs/contributor/operator_precedence.md There'll be a page about this on the website as well, but it hasn't made it there just yet. It doesn't contain any information about how this interacts with
I'm not sure what you mean when you say traditional operator grammars. In most languages, I think the important thing to consider here is that the multiplication doesn't have anything to do with the rest of the line and isn't the deciding factor in how the addition interacts with the |
Beta Was this translation helpful? Give feedback.
Hey @dermagen. You can find Grain's general operator precedence here: https://github.com/grain-lang/grain/blob/main/docs/contributor/operator_precedence.md
There'll be a page about this on the website as well, but it hasn't made it there just yet. It doesn't contain any information about how this interacts with
if
expressions, though.else
attempts to parse as much as it can as an expression, so it captures the entire expression4 + 5
. You can look at this in Grain's grammar if you'd like: https://github.com/grain-lang/grain/blob/main/compiler/src/parsing/parser.mly#L502I'm not sure what you mean when you say traditional operator grammars. In most languages,
if
is a statement rather than…