This is an automated archive made by the Lemmit Bot.

The original was posted on /r/programminglanguages by /u/Appropriate_Piece197 on 2024-08-12 08:18:09+00:00.


In a language that I’m working on, functions are defined like this: func f() = ;. Notice the semicolon at the end.

Also, I have block expressions (similar to Rust), meaning a function can be defined with a block, which looks like this:

func avg(a, b) = (a + b) / 2;

// alternatively
func avg(a, b) = {
  var c = a + b;
  return c / 2;
};

I find the semicolons ugly especially the one on the last line in the code block above. This is why I’m revising the syntax to make the language semicolon-less into something like this:

func avg(a, b) = (a + b) / 2

// alternatively
func avg(a, b) = {
  var c = a + b
  return c / 2
}

I have a question regarding the parsing stage. For languages that operate with optional semicolons, does the lexer automatically insert “SEMICOLON” tokens? If so, does the parser parse the semicolons? If not, how does the parser detect the end of a statement without the semicolon tokens? Thank you for your insights.