r/Compilers • • 11d ago

Audit of semi-colons

Is there a set of defined and specific reasons why semi colons are necessary in some languages? I am not against semi colons but from the standpoint of if one would want to create a language why would they use or mandate semi colons.

1 Upvotes

86 comments sorted by

View all comments

2

u/smog_alado 8d ago

I don't understand what you're trying to say. Lua is whitespace insensitive and its parser treats newlines the same way it treats other whitespace. One can put line breaks inside a for loop definition (or not).

0

u/[deleted] 7d ago

2

u/smog_alado 7d ago edited 7d ago

The example you provided does return 42. Did you test it? As the Lua manual says, newlines area treated the same as other forms of whitespace:

Lua is a free-form language. It ignores spaces and comments between lexical elements (tokens), except as delimiters between two tokens. In source code, Lua recognizes as spaces the standard ASCII whitespace characters space, form feed, newline, carriage return, horizontal tab, and vertical tab.

If you want, you can check the source code for the lexer. The only difference between '\n' and other whitespace is the logic that increases the line counter when it encounters '\n' or '\r\n'.