Live data from Hacker News

Ask HN: Resources for building a programming language?

news.ycombinator.com

41–50 of 87 posts

Re: Ask HN: Resources for building a programming language?

#42

Using Forth as a substrate lets you focus on the more interesting aspects to an even higher degree than Lisp. The last thing you want is detailed instructions; unless you're just building another whatever, which never really made sense to me. Build the most simple and naive thing possible that works the way you want it to, and go from there. That's how Snabel was born: https://github.com/andreas-gone-wild/snackis/blo…

Therein lies my problem with Forth. Yes there is a ton of power, but that is inaccessible to a lot of users. I know I can look at Jones Forth & MeCrisp, but I honestly couldn't see where to start. I'd like to see a tutorial start with either an assembly or C base and then teach Forth fundamentals such as how to start your dictionary and choose between direct/indirect threading and how to implement each. I'm always cu…

I believe the gforth manual contains a fair bit about its implementation and design decisions.

For threading, this is probably a good start: https://www.complang.tuwien.ac.at/forth/gforth/Docs-html/Thr...

EDIT: I don't know how well you know Forth, but it's probably a waste of time trying to implement it before you grok it from userland, if that's where you are. Understanding first the concatenative paradigm and then (more importantly) the deep metaprogramming runtime-is-a-fundamental-part-of-your-application paradigm (which Forth shares with Lisp and Smalltalk) is super important

Re: Ask HN: Resources for building a programming language?

#44

Here's a cool programming language in a live-coding environment that I developed with my interns two summers ago. It enables natural language programming which is great for introducing young kids to computer science. It is built in Java and uses a recursive descent parser to parse sentences like "draw a red circle at 300, 300", and is well commented because the intention was for advanced students at my education prog…

That idea runs into scaling problems quickly. See COBOL-60 and HyperTalk, which are are surprisingly similar.

A useful question: you want to talk to a computer conversationally, and get beyond the Alexa/Siri level of tasks. How would you do that? Fully general natural language requires strong AI. Could you come up with some more restricted form with enough expressive power but understandable by a computer? The computer might have to rephrase your questions and ask "did you mean...?" Come up with a way to converge when the understanding is poor, and you'll have something.

Re: Ask HN: Resources for building a programming language?

#45

Most of the responses so far are about implementing. My favorite intro to programming languages was http://www.eopl3.com/ (though the first edition was more fun and not quite so focused on being a classroom textbook). Working through it, you write interpreters, but that's to make the ideas concrete and testable, not to replace a compilers class. There are newer books that may be better -- I hope someone who's studied…

The first edition of EOPL was eye opening. I learned what a continuation was, (and how to do CPS) from it.

The second and third editions feel less "hard core" somehow.

Re: Ask HN: Resources for building a programming language?

#46
I highly recommend Write Yourself a Scheme [0]. It is self-contained; besides knowing Haskell (and perhaps Scheme), it doesn't expect you to know anything about writing compilers.

While I'm here, does anyone know of any practical resources on how to implement LLVM languages with GC? The documentation [1] leaves something to be desired.

[0] https://en.wikibooks.org/wiki/Write_Yourself_a_Scheme_in_48_...

[1] https://llvm.org/docs/GarbageCollection.html

Re: Ask HN: Resources for building a programming language?

#47
post #25

You'll want the Dragon Book as a reference, not necessary to get started with, but to build the semantic tree on which you will need to pin concepts on. https://www.amazon.com/Compilers-Principles-Techniques-Tools... If you aren't yet committed to any language, you can start building a parser with PyParsing. It's really easy. http://pyparsing.wikispaces.com/ If you want to take a quick (albeit expensive) class on it,…

Hmm. This might be kind of blasphemous, but I think I'd recommend against the dragon book? As I remember, the emphasis in that book is on syntax-directed translation. I might argue that the less you're thinking about syntax and lexing/parsing crap the better. (For that reason: ignore other answers that tell you to learn about a particular parser generator (e.g. ANTLR). That's just fluff.) Really, if you're coming to…

Only the first couple chapters deal with lexing and parsing. The Dragon book covers a lot more than just the syntax analysis: semantic analysis, type checking, run time environment design, intermediate language design, code generation, code optimization, and more. It doesn't have the newer stuff like JIT or Hindley–Milner type system, but those can be picked up separately with reading the papers.

OP asks for resource to build a language. The Dragon book is a very good book to cover the whole process.

Re: Ask HN: Resources for building a programming language?

#48

https://interpreterbook.com is a pretty good resource to hit the ground running, with unit tests and little magic. Once you've gone through it, you'll probably want to use the magic tools as they're well tested at this point, and make your life easier. Still, understanding what they're doing for you is a massive boon. I should note, it uses Go but not in an idiomatic way. Strings instead of using an error type, etc.…

Author of the book here. Thanks for the shout out! I'm happy to hear that you appreciate the book exactly in the way it was intended to - little magic, lots of code and unit tests.

I'm also super curious about your "not in an idiomatic way" comment. If you have a minute, feel free to send me a longer version - me at thorstenball.com. I'd really love to hear what you'd do differently and what could be more idiomatic.

Re: Ask HN: Resources for building a programming language?

#49
post #12

I strongly suggest you build something esoteric and fun first. This should be a "bare minimum" VM or interpreter. Here's one of mine that I wrote like a 8 years ago[1]: https://github.com/dvx/zeded/ Don't start off with YACC/Bison as they hide a lot of stuff under the hood. It's cool learning things from scratch. The most commonly-suggested book on compilers is known as the Dragon Book [2] and if you want to take thi…

For the dragon book, the first edition is significantly cheaper. Is there anything in the new version making it worth over 10x as much?

The later chapters on ILP, software pipelining, optimizing for parallelism and locality are completely new. Basically, chapters 8-11 have been either re-written or written from scratch. On the other hand, the 2nd dropped the Want to write a compiler and A look at some compilers chapters.

Re: Ask HN: Resources for building a programming language?

#50
Have a look at http://t3x.org

There are lots of small, comprehensible compilers and interpreters there, and there is an interpreter and runtime construction kit, look for "S9 core" in http://t3x.org/s9fes/. You can also order books explaining all the stuff. And yes, I'm the author! :)

Post reply on HN