News for hackers. Stuff that matters.
Re:The naked truth about writing a programming language (2014) by a1369209993 on Saturday May 02, 2020 @09:25PM (#23056175)
Note that "context free grammars", in the technical sense, is completely the wrong thing. Eg, enforcing consistent indentation is not context free:

  foo()
      {
      return;
      }
  ↓↓↓↓↓↓↓↓↓↓↓
  aaaa{
  bbbbreturn;
  cccc}
  ↓↓↓↓↓↓↓↓↓↓↓
  aaaabbbbcccc
This is equivalent to aⁿbⁿcⁿ, which is pretty much the canonical example of a non-context-free language.

What you acually want is not context-free grammar, but, as TFA says:

> the code should be parseable without having to look things up in a symbol table

Re:The naked truth about writing a programming language (2014) by qznc on Sunday May 03, 2020 @02:45AM (#23057332)
There is a trick for indentation: Use a context-sensitive lexer in front of a context-free parser. The lexer serves indent and dedent tokens to the parser.

With this trick, you can parse Python with a context-free grammar.

Re:The naked truth about writing a programming language (2014) by bmn__ on Sunday May 03, 2020 @06:56AM (#23058234)
There are plenty, the majority even, of programming languages that do not enforce consistent indentation. You make a false generalisation when you claim that CFG are completely the wrong thing.
Re:The naked truth about writing a programming language (2014) by gbear605 on Sunday May 03, 2020 @09:25AM (#23058838)
I'd suggest that generally the grammar should be context-free, but that a few features = can be non-context-free. Formatting like this should specifically be a separate check IMO.
Re:The naked truth about writing a programming language (2014) by tom_mellior on Sunday May 03, 2020 @08:11AM (#23058532)
> This is equivalent to aⁿbⁿcⁿ

Is it? You only indent with spaces, so a = b = c = ' ', and the problem you claim disappears.

Re:The naked truth about writing a programming language (2014) by gbear605 on Sunday May 03, 2020 @09:24AM (#23058827)
I'm not sure that's a solution. The problem is verifying that the three 'n's are equal, not that 'a', 'b', and 'c' are equal. Solving this cannot be done in a context free grammar [0].

[0]: https://cs.stackexchange.com/questions/33153/is-an-bn-cn-con...

Re:The naked truth about writing a programming language (2014) by tom_mellior on Sunday May 03, 2020 @10:41AM (#23059273)
Yeah, you're right. I got confused by the original phrasing.