4 ms·
Here is a link to the source code for a C like interpreter that I many years ago: http://www.zeusedit.com/tools.html http://www.zeusedit.com/tools.html Is it
by jussij 11y ago
Here is a link to the source code for a C like interpreter that I many years ago:
http://www.zeusedit.com/tools.html http://www.zeusedit.com/tools.html
Is it any good? Not really. There are many far better interpreters out there to choose from.
But it was my first and last ever interpreter, written some 20+ years ago, written when I was fresh out of university.
Was it hard to write?
I did not think so and I only had an engineering degree ;)
Now lets try to write a compiler. Suddenly things get far more difficult!!!
- yoklov 11y agoA compiler isn't actually that much more difficult than an interpreter. Extending an interpreter to compile instead of interpret is not that much code, and the code won't be that difficult or complex either. The hard part is making the generated code perform well, which requires much more work.
- sklogic 11y agoCompilers are much simpler than interpreters, unless you go into some really complicated optimisations.
- pjmlp 11y agoAround the same time as you wrote yours I did this one with a friend It was a basic exercise for our CS compiler classes in 1998, written in the newly introduced Java language and generates bytecode and native. https://github.com/pjmlp/L98 https://github.com/pjmlp/L98 The code is actually pretty basic, and I did some improvements (Makefile to Maven, Java 1.0 to 7, replaced C runtime by pure Asm) in the last couple of years just for fun. If anything, it taught me a very interesting trick for writing compilers as if they were interpreters. Create bytecodes as intermediate language that can be easily mapped into Assembly macros. Then instead of interpreting, just make them go through the macro assembler. It won't generate the fastest code in the world, the register allocator will be pretty stupid, but hey it compiles straight to native.