Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

It's a deal breaker, I think.

For example:

    if x > y and x < max_x
looks fine with parens:

    if (x > y) and (x < max_x)
but when it becomes slightly more complicated:

   if (x > (y + 1)) and (x - 1 < max_x)
it really looks awkward.

Or how about this?

    x = 5 + 10
is parsed as

    (x = 5) + 10
and I'd really hate to have to write simple assignments as

    x = (5 + 10)
just to avoid that kind of snafu.

I don't think your compiler should get much more complicated with operator precedence. Just have a precedence stack that always reflects the operator precedence in the current scope. Parse the expressions without operator precedence (e.g. always LtR), then at a later compilation stage, swap the subexpressions in the AST until the AST adheres to the precedence rules, and you're done.



I do agree on the if statements; they're fairly complex, although easily readable. I wonder how that'd end up feeling in the real world. It'd definitely irritate me at first, at the very least.

As for assignments, this would actually be a nonissue. For example, x = 5 + 10 would be parsed as:

  (x = (5 + 10))
Same with a = b = c + d:

  (a = (b = (c + d)))
Edit: Hmm, I was just thinking about this, and this order of parsing could potentially cause issues. It'd work for most arithmetic, but in the case of complex operations (specifically operator overloads on things like matrices) it could cause problems. I need to think a bit more on this issue.


My bad, I assumed you would pick the opposite parsing order as default, because we read left to right.

I'm not sure if I could get used to

   3 * a + 1 
getting parsed as

   3 * (a + 1)
It would also be really awkward when considering slots/accessors/etc

   person.name = "Jack"
surely should never be:

   person.(name = "Jack")


The more I think about it, the more I realize that parsing order just plain wouldn't work. I'm starting to think that while doing things left-to-right could generally work, implementing some sort of simple precedence would probably just be easier. Thanks for the insight. It's threads like these that make me love asking this community for input.




Consider applying for YC's Winter 2027 batch! Applications are open till November 2.

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: