3 ms·
> newlines terminate statements unless there is a semicolon, which does the same early Since I'm writing a toy language with optional semicolons, I'm curious -
by lioeters 7y ago
> newlines terminate statements unless there is a semicolon, which does the same early
Since I'm writing a toy language with optional semicolons, I'm curious - how are you solving ambiguities in multi-line expressions? For example:
1
-1
Does your language not allow multi-line expressions, treating the above as two statements? Or, perhaps they must be explicitly an expression, like:
(1
-1)
I agree with you on another comment, that JavaScript's automatic semicolon insertion is complicated - so I'd like know if there's a sensible solution for languages without semicolons.
- jakear 7y agoPython behaves "sensibly" with regard to this. Semicolons are statement breaks. Endlines are statement breaks, unless theres some reason for them not to be, such as being in a open brace state.
- saagarjha 7y agoIn this language, there's very few multi-line expressions. However, for your specific case: yes, I would consider that two statements. 1 - 1 would be one: putting a binary operator by itself in one line would cause the parser to keep looking.
- lioeters 7y agoAh, I see, so new lines are like invisible operators (with low precedence) that ends a statement unless preceded by another operator. Right, that makes sense.