Ok, so I have some understanding about parsers and compilers, at least the basics of how it works, and i've written a calculator and a really small toy language that compiles to another high-level language. Now if i want to write a complete language (by complete, i mean that it can be evaluated) is it bad to write the parser in some easy scripting language (like Python), convert it to my own "bytecode" and implement a small VM in C/C++?

I'm not exactly worried about performance right now, but if this is a "wrong way" to do it, i don't wanna waste my time. Also, all languages i've seen have been implemented in only one low-level language, like C, or they already have a self-hosting compiler. Is there any language compiler/interpreter implemented in this way?

closed as too broad by gnat, jwenting, durron597, Ixrec, user22815 May 10 '15 at 0:11

Please edit the question to limit it to a specific problem with enough detail to identify an adequate answer. Avoid asking multiple distinct questions at once. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.

  • Ocaml is notably implemented as a self-hosted compiler to bytecode + a bytecode VM implemented in C ; however, the advantage of a self-hosted compiler is to be a real-size test case for your language. – Basile Starynkevitch May 9 '15 at 5:53
  • This is not uncommon. I can think of many languages implemented in such way, compilers for most non-java languages that targets the JVM is written in Java, although the JVM reference implementation (Oracle) is implemented in C++. – Lie Ryan May 9 '15 at 8:53

I can't think of any downsides to this so long as your parser non parser sides are truly separate. If you end up implementing the same things twice, in two different languages, that is problematic due to bugs when they likely don't always behave the same ways, as well as duplicated effort. If that isn't going to happen, it seems like a fine idea and makes sense to use a parsing friendly language for the parsing and something else for the other stuff. In a way, you can think of lexx and yac type utilities doing what you are doing. The parsing is done completely separate from the rest of it. I say go for it, use the best tool for each job.

Not the answer you're looking for? Browse other questions tagged or ask your own question.