Live data from Hacker News

Ask HN: How to learn to write a compiler and interpreter?

news.ycombinator.com

21–22 of 22 posts

Re: Ask HN: How to learn to write a compiler and interpreter?

#21
Practical steps:

1. Create a grammar for your language. Start with Lex/Yacc and model your grammar with Lex/Yacc. Use them to generate lexer/parser.

2. Create sample code in your new language. Parse the generated parser on said language file into a list of Syntax trees.

3. With said Syntax trees, generate target code - Compiler (or) evaluate the tree and print results - Interpreter.

Iterate and repeat steps until your language is complete.

Re: Ask HN: How to learn to write a compiler and interpreter?

#22
I found tutorials like this [0] one to be pretty useful, since they show how to actually use frameworks like LLVM, and lex/yacc/etc. practically. Note that this one is from 2009, and uses an outdated version of LLVM. Actually following along requires some debugging and digging through documentation, which is also helpful in its own way.

[0] https://gnuu.org/2009/09/18/writing-your-own-toy-compiler/

Post reply on HN