News for hackers. Stuff that matters.
Re:What can we learn from how compilers are designed? by justinpombrio on Friday March 16, 2018 @06:15PM (#16604376)
> One of the interesting insights I got while building my own compiler was that despite what every compiler book says, there are languages that can be compiled on the fly without building an AST.

PL (but not compiler) researcher here. What you're saying sounds to me like "One of the interesting insights I got while programming my own game was that despite what every game programming book says, there are games that can be programmed without defining any functions." I mean, yes, you can do that, and it may in fact be more efficient, but it's going to cause trouble down the line if you ever want to do something more complex.

Re:What can we learn from how compilers are designed? by munificent on Friday March 16, 2018 @07:17PM (#16604674)
> What you're saying sounds to me like "One of the interesting insights I got while programming my own game was that despite what every game programming book says, there are games that can be programmed without defining any functions."

Ex-game programmer and current PL programmer here. I think a better analogy is that you can make a game without having a scene graph. And, indeed, you can. And it works fine for many simple games, though as some scales it starts to be a hindrance.

Re:What can we learn from how compilers are designed? by compiler-guy on Friday March 16, 2018 @07:04PM (#16604604)
Yeah, the grandparent is only true if you don't want to do interesting things with the language, like nearly any but the most basic peephole optimization.

But a fun fact, if you know about single-pass compiling, you can figure out a lot of why the original C syntax is what it is. A declaration is a "reserve some memory" statement. Local variables had to be declared at the beginning of scope so that the compiler could deallocate them at scope close. Without an AST, the compiler had to produce instructions immediately.

With a true AST, you don't need such a restrictive syntax.

There are many other possible examples.

Re:What can we learn from how compilers are designed? by skybrian on Friday March 16, 2018 @07:03PM (#16604593)
Yes, there's a reason compiler books start with parsing and building an AST.

But I think studying Lua [1] or the Wren codebase [2] is still worthwhile, provided you keep in mind that they're relatively simple languages that are designed to be both fast and embedded.

[1] https://www.lua.org/doc/jucs05.pdf [2] https://github.com/munificent/wren

Re:What can we learn from how compilers are designed? by HumanDrivenDev on Saturday March 17, 2018 @01:51AM (#16605761)
well there's no need for an AST in a concatenative language - that might be what he's talking about.
Re:What can we learn from how compilers are designed? by mojuba on Friday March 16, 2018 @07:04PM (#16604603)
No, it's not the same thing. A compiler without the AST phase itself is more compact and arguably more beautiful, but again not every language is compile-able this way (C++ being a notable example).