How to Implement a Programming Language in JavaScript
lisperator.net
How to Implement a Programming Language in JavaScript
1–10 of 36 posts
Re: How to Implement a Programming Language in JavaScript
#2And if you want to actually build a "real" programming language, I advise you to try llvm - it really takes away the pain of generating bytecode, and gives you everything you need to deal with the actual design of your language.
Re: How to Implement a Programming Language in JavaScript
#3Anyways, this is such a detailed series of tutorials I may be distracted for days bringing my half finished programming language back from the dead.
Re: How to Implement a Programming Language in JavaScript
#4I'm glad they didn't write a tutorial that made another Lisp - I'd your audience is javacript developers, a lisp isn't all that appealing usually. Anyways, this is such a detailed series of tutorials I may be distracted for days bringing my half finished programming language back from the dead.
Re: How to Implement a Programming Language in JavaScript
#5I'm glad they didn't write a tutorial that made another Lisp - I'd your audience is javacript developers, a lisp isn't all that appealing usually. Anyways, this is such a detailed series of tutorials I may be distracted for days bringing my half finished programming language back from the dead.
I do a lot of JavaScript and Lisp is extremely appealing to me. JavaScript is a functional language, but not a very good one. Lisps are much better at doing functional programming than JavaScript. So a Lisp that translates to JavaScript is right up my alley.
Re: How to Implement a Programming Language in JavaScript
#6I get that it's a beginners tutorial and they have some constraints, but it starts off with "let's dream up a language" and then presents a super standard language, it's basically just Javascript with obligatory semicolons..
Re: How to Implement a Programming Language in JavaScript
#7I have a good analogy to explain this. Take this OCaml program.
let sum_file filename =
let file = In_channel.create filename in
let numbers = List.map ~f:Int.of_string (In_channel.input_lines file) in
let sum = List.fold ~init:0 ~f:(+) numbers in
In_channel.close file;
sum
;;
This is roughly equivalent to: def sum_file(filename):
with open(filename) as f:
return sum([int(x) for x in f])
Now think of the degree to which OCaml is awkward here. That's exactly how awkward Python and JS are for writing languages :)OCaml is based around ML-style typed records, which are exactly what you need for manipulating languages.
I am not a type safety guy, but when you write languages, there are tons of nested conditionals. In Python in JS or C, you end up with bugs in those corners. It is quite easy to crash any non-trivial parser, like the CPython parser, or Clang's parsers, etc. The type safety that ML offers helps a lot with this.
The code for writing parsers and interpreters is just SHORTER in OCaml than in Python. I used to think Python was the most concise language. But no, it depends on the problem domain. Try it and you'll see.
Someone saying the same thing here:
Re: How to Implement a Programming Language in JavaScript
#8Re: How to Implement a Programming Language in JavaScript
#9I've written multiple parsers/interpreters in both JS and Python -- Python being my favorite language. From that experience, I've come around to the fact that they're both the wrong language for writing languages -- lexers, parsers, interpreter loops, compilers. I have a good analogy to explain this. Take this OCaml program. let sum_file filename = let file = In_channel.create filename in let numbers = List.map ~f:In…
Re: How to Implement a Programming Language in JavaScript
#10Possibly more digestable, I recommend the walkthrough of building "Egg" in the fantastic (and free!) Eloquent JavaScript by Marijn Haverbeke: http://eloquentjavascript.net/11_language.html