Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Grammar Ambiguity in while #29

Open
iwillspeak opened this issue Apr 24, 2019 · 1 comment
Open

Grammar Ambiguity in while #29

iwillspeak opened this issue Apr 24, 2019 · 1 comment
Labels

Comments

@iwillspeak
Copy link
Owner

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.

  • For while we could mandate () around the condition
  • For while we could have an opening do or similar
  • For all expressions we could use end of line as a separator. Expressions would only parse infix operators over newlines if they're in a grouping expression?
  • Some kind of explicit statement separator to fix this in the general case, e.g. ; in C

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 iwillspeak added the Bug label Apr 24, 2019
@iwillspeak
Copy link
Owner Author

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

  • T, which can be either ;, or \n
  • DO, which is either the literal "do" or T.

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

while foo
   (100)
end

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant