Hacker News new | ask | show | jobs
by sklogic 3833 days ago
Writing an interpreter is much, much harder than implementing a simple, straightforward compiler.

Interpreter is unavoidably convoluted, it is full of very complex things like environment handling, it cannot be split into smaller parts in any sane way.

Compiler, on the other hand, is nothing but a trivial sequence of very simple tranforms (as simple as you like), each is nothing but a couple of term rewriting rules. You do not need a Turing-complete language to implement a compiler.

1 comments

Maybe if the compiler is very simple. But I have said:

""" How make a REPL, a debugger, how implement pattern matching, type checking, if a interpreter can be fast enough, if possible to avoid to do a whole VM for it, etc... """

REPL, debugger, no-VM and other stuff look easier with interpreters than compilers.

However, I will be happy to be wrong: I wanna the simplest way to get where I want to.

Currently: Working with F#, wanna REPL, debugger, AGDTs, pattern-matching, go-like concurrency, iterators, semi-functional...

Where I hit a big block is how do interop with a interpreter (ie: Call .NET methods) and that look easier with a compiler...

And with REPL and debugger requirements it is even easier to implement a compiler than an interpreter.

Pattern matching must be compiled anyway, even if the rest is interpreted, same for the static typing.

Any tutorial on that? Because I don't have find a resource that show me how do this.