Hacker News new | ask | show | jobs
by david-given 3397 days ago
Having tried this in the past with personal programming languages, I always found I needed the parentheses to disambiguate control flow statements. You end up with stuff like:

  if foo*bar baz()
...being parseable as either of these:

  if (foo) { *bar } baz()
  if (foo*bar) { baz() }
That example can be solved with enough lookahead but I think I found cases where it couldn't be (although I can't bring them to mind). Terminator tokens are another way to solve it, so you get Ada-style:

  if foo*bar then baz() endif
...or Go-style:

  if foo*bar { baz() }
2 comments

If you stop putting multiple expressions per line it disambiguates too:

    if foo
      *bar
    baz()

    if foo*bar
      baz()
That's only if newlines are meaningful in the grammar. In C and related languages they are not, and where they are they tend to be a pain (the dreaded semicolon insertion...)

And even if you make newlines meaningful you only trade one pain for another, namely, you now need some kind of line continuation construct and lots of special cases where newlines are allowed...

In short: it's not that simple.

Can't you just treat newlines like any other delimiter? Granted many tools assume newlines, but you could just not use those tools, or replace newlines with a placeholder so you can parse programs as a single line.
Rust confronts this by making curlies mandatory