News for hackers. Stuff that matters.
Re:Essentials of Interpretation by Areading314 on Wednesday March 11, 2020 @05:04PM (#22550589)
Javascript for a compiler course? That seems like a very unusual choice. Good luck to you!
Re:Essentials of Interpretation by chrisseaton on Wednesday March 11, 2020 @05:54PM (#22551204)
The great thing about compilers is they're conceptually pure functions - take an array of characters as input and produce an array of bytes as output. You can do that in any general-purpose language - high level, low level, old, new, whatever, you don't even need any libraries - it's all just numbers in and numbers out! So yeah pick whatever you want. Algebraic and object-oriented languages seem to work well in practice as the problems are data-structure-intensive, but many other paradigms also work well. I really love compilers, I think they're the perfect program.
Re:Essentials of Interpretation by JadeNB on Wednesday March 11, 2020 @08:18PM (#22552228)
> The great thing about compilers is they're conceptually pure functions - take an array of characters as input and produce an array of bytes as output.

While this is undoubtedly strictly true, it seems so high-level that the same could be said of essentially any programming task, with I/O suitably modelled, and so gets awfully close to "the C language is purely functional" (http://conal.net/blog/posts/the-c-language-is-purely-functio...).

Re:Essentials of Interpretation by chrisseaton on Wednesday March 11, 2020 @08:43PM (#22552357)
My friends who work on web services have to send out tens of requests to other services to get anything done. So their request handlers aren’t pure functions.

People think about compilers as being systems code but it’s the opposite. It’s the web and business code that’s a nest of state and dependencies on systems.

Compilers are just numbers in numbers out.

Re:Essentials of Interpretation by DmitrySoshnikov on Wednesday March 11, 2020 @05:21PM (#22550816)
Thanks! Yes, we use JavaScript as the most popular language, however the code should be easily portable to any other language.

The multi-paradigm nature of JS, with its first-class functions, closures, static scope semantics, class-based and prototype-based inheritance fits the best to study semantics of programming languages -- and all these concepts we implement in the course.

For low-level bytecode interpreter there will be a C++ implementation.

Re:Essentials of Interpretation by hadcomplained on Wednesday March 11, 2020 @06:04PM (#22551301)
IMHO what is essential as a language feature for writing interpreters/compilers is algebraic data types and pattern matching on them, because they make things much easier when manipulating ASTs, which is a frequent task in implementing these programs.

Unfortunately besides functional programming languages (Haskell, OCaml, etc) or modern languages (such as Rust), there are few having these features, and JavaScript is no exception. Of course you can use a poor man's substitute such as the Visitor pattern, but it's quite a hassle without a direct language support.

Re:Essentials of Interpretation by DmitrySoshnikov on Wednesday March 11, 2020 @06:11PM (#22551362)
Yes, good point on pattern matching and algebraic data types (initially I was actually considering Rust for implementation, but not OCaml). The visitor pattern is a classic though, and is transferable knowledge further, to process different kinds of graphs, trees, etc. BTW, JavaScript will likely be getting pattern matching soon as well.
Re:Essentials of Interpretation by seanmcdirmid on Thursday March 12, 2020 @12:09AM (#22553686)
I’ve been writing all my language runtimes and compilers in TypeScript lately, mainly because they also have web UIs. It really isn’t that bad.
Re:Essentials of Interpretation by DmitrySoshnikov on Thursday March 12, 2020 @07:22PM (#22563099)
Indeed, TypeScript is also a good choice for this.