system
Given the following post, respond as if you're commenting on Reddit:
human
Can you build a program in C++ to compile any language?

I was reading up on how Node.js came about, which lead me to Google V8 and what it was. I know some Java, and not C++, and the "compiling Javascript to Native Machine Code" description, finally made me interested in the JVM, and made me look up some of the differences between Java and C++.

So, is there something special about JavaScript that lets C++ make a program to compile it, or can it do with any language?

And when you do something like that, how complicated of a task is it? It seems pretty complicated to build a program from another language, whose purpose is to understand another language and then compile that.
gpt
Yes, you can write a compiler for any language in C++. In fact, you can write a compiler for any language in any language, because all a compiler does is read your source code file and write another file that your operating system and CPU are able to interpret; that obviously requires knowledge of the OS and CPU your compiler targets. A program that has input and output is by definition "a program".

Writing a fast virtual machine (like the JVM, or even VirtualBox/VMware/dotNet) however, does require a programming language that can direct the CPU to execute any code it wants directly. That's something that C++ and C can do, but there's no implementation of JavaScript or Java that can do that directly. (Oversimplification alert: you can write a very small unit of code that your Java VM will load via JNI that could do that... but that's not Java anymore).