
Top-Down operator precedence parsing - mnemonik
http://eli.thegreenplace.net/2010/01/02/top-down-operator-precedence-parsing/
======
zck
The more I code, the more reasons I find to simply use parentheses everywhere.
Why bother even thinking about 1 + 2 * 4 when you could write 1 + (2 * 4)

Ok, if you've got a lot of operators in one line, it can get difficult, but
you're probably running into trouble reading it even without parenthesization.
It seems like one of the huge wins of Lisp that you don't have to worry about
this problem.

~~~
daeken
This brings up an interesting problem for me. I've written a number of
compilers where operators were not defined at parse-time, but handled via
macros that can be defined at any point. This makes the logic for transforming
infix operators very difficult. If a change was made to make all operators
operate left-to-right, this issue would go away. What do you guys think about
this? Would it cause you serious problems while writing code?

~~~
gruseom
In addition to Smalltalk, the APL family (including J and K) do this too. It
doesn't cause serious problems while writing code; once you get used to it,
it's a whole lot simpler. It does, however, create a barrier to mainstream
acceptance. So it seems to me your decision depends on how badly you want the
latter.

~~~
BigZaphod
I've often seen the claim that not having operator precedence hurts a
language's acceptance, but is there any concrete evidence of that? Could it
just be a coincidence?

Were it not for the closed/licensed/expensive/commercial nature of Smalltalks,
the language probably would not have fallen into to the relative obscurity it
suffers today. I personally doubt that operators had anything to do with it.
From what I've read of the history of the era, the language itself was much-
loved and rising in popularity until the introduction of Java disrupted the
traditional Smalltalk business models.

~~~
silentbicycle
While it isn't exactly the same thing, OCaml requires you to use different
operators (e.g. + vs. +.) for ints and floating point numbers, and it's a
_very_ common complaint about the language. (It has conventional precedence.)

When conventional arithmetic doesn't "just work", languages will often give a
first impression of being awkward, even though the rules of operator
precedence are actually more complicated than just consistently using prefix
or infix left-to-right.

