iwillspeak / ullage

A statically-typed compiled language defined by a simple grammar
http://willspeak.me/ullage/
Other
23 stars 1 forks source link

Grammar Ambiguity in `while` #29

Open iwillspeak opened 5 years ago

iwillspeak commented 5 years ago

Given the following:

var foo: Bool = true

while foo
      (print 100)
end

The parse tree will be a function call to foo, rather than a grouping expression in the body of the while loop. To solve this we need some kind of expression separator.

In general I'm not a fan of the whitespace solution. I'd rather the language wasn't whitespace sensitive. If we move to a traditional if/elif/else block this will become more pressing as the same ambiguity exists there.

iwillspeak commented 5 years ago

The Ruby grammar appears to solve this problem with a pair grammar non-terminals:

which means you can write loops like while foo do (100) end and

while foo
   (100)
end