Live data from Hacker News

Ask HN: Resources for building a programming language?

news.ycombinator.com

61–70 of 87 posts

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

#61

Many suggest resources for compiler implementations, i personally would start prototyping the language itself, think about it's type system and its runtime properties. There are many possibilities in terms of type systems, from static to dynamic and everything in between, concepts like linear types, algebraic types, etc. Runtime properties are things like it's memory model (garbage collection, yes or no). All of this…

>I personally prefer hand-written recursive descent parsers

>using a parser combinator framework (like https://github.com

>/Geal/nom) over parser generators.

Why?

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

#62

Many suggest resources for compiler implementations, i personally would start prototyping the language itself, think about it's type system and its runtime properties. There are many possibilities in terms of type systems, from static to dynamic and everything in between, concepts like linear types, algebraic types, etc. Runtime properties are things like it's memory model (garbage collection, yes or no). All of this…

>I personally prefer hand-written recursive descent parsers >using a parser combinator framework (like https://github.com >/Geal/nom) over parser generators. Why?

Why handwritten, or why using a parser combinator framework?

Handwritten parsers are most commonly used because most tools have problems making things like proper error reporting good enough to be worthwhile.

Parser combinators is really just a fancy way of composing a parser from higher order functions instead of writing out a function body. If well done it basically provides a DSL to build the parsers, and the way this works by composing small fragments is pretty much what we do with recursive descent anyway, so it's a good fit.

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

#63

I've really been enjoying http://www.craftinginterpreters.com/ unfortunately it isn't complete yet.

I've been recommending this to co-workers who want to learn how to write their own language. I had ideas on how I would write a book on compilers and Bob had all the same idea, but he actually went ahead and acted on them.

1. Avoid long discussions on the theory of parsing, how to transform regular expressions into table-driven DFAs, how to build an LR(1) parser, etc.. These topics can be interesting later on, but for the benefit person who just wants to learn to write a language, the author should instead focus how to write the scanner and the parser by hand using a predictive recursive-descent. The value of this approach are three-fold: (1) the book is shorter, (2) it's a simple approach that works with any language without specialized tool (useful if someone wants to write such a tool for vim or Emacs, say), (3) it feels more concrete, more "real" to write a parser by hand rather than create a few grammar rules and let an external tool create the code that does the parsing.

2. "Breadth-first" rather than "depth-first". In a typical compiler textbook, each chapter exhausts almost all that there is to say about a topic before moving on. I think a more practical book will avoid such deep discussions and try to go as quickly as possible from source language to executable program. After the initial implementation is complete, the author can go back and add more details. Bob's approach of having two interpreters, one AST-walker and one that builds bytecode, fits that idea quite well.

3. Multiple implementation languages. The implementation of a language is largely guided by its host language: if using ML or Haskell, then sum types will be quite handy; in Java we can rely on the library's excellent collections. It's cool that Bob decided to write an interpreter in Java and another one in C; the reader will get to see how some decisions in the former (e.g., using exceptions) are "translated" in the later.

4. A full implementation in the book. Many compiler textbooks use pseudo-code and steer clear of "pedestrian" topics like good error handling. By having a full implementation, Bob ensures that the little dirty details are addressed also and not swept under the rug and left for the readers to discover and struggle with.

I really look forward to the day when I can order a copy of Crafting Interpreter, I have no doubt that it will be a terrific book.

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

#64

Earlier quoted context omitted.

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 came into Forth with 32 years of mixed experience from Lisp, Smalltalk, Haskell, C++, C, Java, Perl, Python, Clojure, Scala and more; it's difficult for me to judge anything from that perspective. I've never written a standard Forth program in my life though, never installed any other implementation. The second I was introduced to Forth, it clicked; Lisp took me much, much longer to get by comparison. Like I said,…

Thanks for the reply. I'll take a look. When you said it clicked. What we're you looking at? Starting or Thinking Forth or what? I'm trying to find out how most people learn to build their own system.

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

#65

Earlier quoted context omitted.

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…

I understand a bit of userland, but not a whole lot. I figured you needed to learn Forth via a bit of both as all things tend to get circular, as in I'd understand this better if I knew how it was implemented.

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

#66

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…

Check out Moving Forth: http://www.bradrodriguez.com/papers/moving1.htm

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

#67
post #7

What do you want to do? You could write a LISP interpreter in a high level language in an hour, you could target the JVM/CLR/whatever and get fairly high performance and GC without too much work, you could spend months/years writing a quality language runtime + native compiler, etc. http://www.craftinginterpreters.com/ is coming along really nicely. Reading academic papers can give you some excellent ideas once you g…

[deleted]

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

#69
post #55

To keep motivation, you need to have result quickly while focusing on topics you are interested in. You should choose the high level language (with at least a GC) where you are the more proficient. Have very small exigences in error diagnostic. If your interest is mainly in language syntax and semantic, you can either write an interpreter or target an existing language (C++ was initially generating C).

This is a useful comment. The suggestion to go with an interpreter first if you want to have something in a relatively short amount of time is a good one.

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

#70

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.

Do the later editions have less content? Would your recommendation be to read the first edition? Thanks!
Post reply on HN