Hacker News new | ask | show | jobs
by chrisseaton 1908 days ago
> I don't see the point in a javascript-based compiler

JavaScript is a full programming language. Why wouldn't it be a fine choice to write a compiler in? People have a funny idea that compilers are more complex software or are somehow something low-level? In reality they're conceptually simple - as long as your language lets you write a function from one array of bytes to another array of bytes, then you can write a compiler in it. And for practicalities beyond that you just need basic records or objects or some other kind of structure, and you can have a pleasant experience writing a compiler.

> Surely any file format/DSL/programming language you write will be parsed server-side?

JavaScript can be used user-side, or anywhere else. It's just a regular programming language.

2 comments

> I don't see the point in a javascript-based compiler

Typescript, sass, jsx... There are a lot of languages running on top of js. Or you might want to do colorizing, autoformating on input in the browser?

Along with all that, there's as mentioned nodejs, deno for running server side.

But at any rate - lots of front-end problems involve various kinds of parsing/validation and transformation (eg: processing.js).

> Why wouldn't it be a fine choice to write a compiler in?

Javascript doesn't seem suited to compiler construction because it lacks lots of features that make compiler construction pleasant (e.g. strong rich types, algebraic data types, etc.)

It might be "fine" but it's not "good".