Live data from Hacker News

How to Implement a Programming Language in JavaScript

lisperator.net

1–10 of 36 posts

Re: How to Implement a Programming Language in JavaScript

#2
Another really good course to learn the basic about programming language design:

http://nathansuniversity.com/

And 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

#3
I'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

#4

I'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

#5

I'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.

You might enjoy wisp: https://github.com/Gozala/wisp

Re: How to Implement a Programming Language in JavaScript

#6
Given the domain name I was hoping they'd first implement a Lisp in 12 lines of Javascript, and then implement the new language in that lisp, that would've been an interesting tutorial.

I 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

#7
I'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: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:

http://flint.cs.yale.edu/cs421/case-for-ml.html

Re: How to Implement a Programming Language in JavaScript

#9
post #7

I'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…

I had just stumbled on this C# 1.1 parser written in F# yesterday. I'm not sure if a syntax-tree and parser in 350 lines is decent, but I can at least see what you're talking about in regards to ML/OCaml being well-suited for the task.

http://www.fssnip.net/lf

Post reply on HN