Hacker Newsnew | past | comments | ask | show | jobs | submit | kinga254's commentslogin

Any specific resources you've used that you could recommend in line with compiler construction?


I wrote a C compiler* using flex [1] and bison [2] that generated MIPS code. The biggest downside was the rather complex glue code.

At some point ANTLR [3] looked promising, but these days I'd probably write a lexer and recursive descent parser by hand, then generate LLVM IR [4].

[1] https://github.com/westes/flex

[2] https://www.gnu.org/software/bison/

[3] https://www.antlr.org/

[4] https://llvm.org/

* for a subset of the full C89 spec


You could use https://en.wikipedia.org/wiki/Yacc

I decided to write my own lexer/parser/compiler it's pretty straightforward.

Sources I use(d) to program this, e.g look at resulting assembly from other compilers or look at how the AST is generated for other languages.

https://en.wikipedia.org/wiki/Recursive_descent_parser

https://en.cppreference.com/w/c/language/operator_precedence

https://godbolt.org/

https://astexplorer.net/

I didn't start writing C yesterday, and most of the things are just stuff I've learned over the years and seeing how other languages work and then just use what I know to try to program in a logical manner.

Also I've written a implementation of a scripting language (compiler and VM) before in similar fashion.

https://github.com/riicchhaarrd/gsc


This is specific to interpreters but the beginning part related to parsing and AST is common: http://craftinginterpreters.com/contents.html


I've had good luck with ANTLR4 and ObjWeb ASM for my JVM language Imp https://github.com/mh15/imp


Nice, thanks. Traefik have a working go interpreter https://github.com/traefik/yaegi. Been meaning to go through the source code to borrow a few pointers(pun intended) as well.


Much appreciated!


Whose has used mithril and how does it compare to vue?


Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: