Now before i start asking dumb questions,i'd like to say that i have a big experience in both JavaScript and C#.
So recently i went to the journey of creating my own porgramming language.
I found a good tutorial that uses javaScript
(http://lisperator.net/pltut/dream) but i don't quite understand this one little thing.
How do you create a "stand alone" compiler. Now, this is a a made up word to describe a compiler that runs as a whole new program. For example 'node index.js'. You dont' have to compile the compiler with something else right.
Where if i create the compiler with say JavaScript, i'd still need to compile the compiler like this for ex 'node compiler.js nameofthefile.ext'.
So then i found that thing called bootstrapping a compiler. So you create a compiler for a your new language with Java or C for example, and then you create a new compiler written in the new language, and compile it with that compiler to get a new compiler written in the new language. But i still don't understand how do run it.
For example if were to make it with C (that is what i am planning to do) then i'd have that file called compiler.c
Now i need to compile the C code so i do for example 'make compiler.c' and that gives me the a compiled version of the c code called just 'compiler'(in Linux that i use) or 'compiler.exe' (in Windows).
So now to run that program i can do ./compiler and than give it for example an argument the/path/to/the/programming_language.someExt
And if all runs well that is going to do what ever the program i wrote in the new language does.
But even now i can't give that version of the compiler to a windows user because the compiler needs to be .exe file.
If you still reading this, there is more...
What if a then want to bootstrap the current compiler.
So now the compiler it self will be called compiler.theExtOfTheProgrammingLang and the code that i want to compiler would be hello_world.theExtOfTheProgrammingLang. But now i can not just run the compiler, because i will need to compile it first using the previous compiler.
That all just made a big mess in my head but i don't want to give up on it.
I'll try to paint you a picture.
You're creating a new language L
. For that language you wrote a compiler, CL in (for instance) Java that compiles from L
to x86 and creates an ELF executable file (i.e. Linux executable). You need to use the JVM in order to use CL (well, technically there are tool-chains that will compile Java to native, but lets ignore that).
Say you don't want to be JVM bound, and instead prefer to run natively on Linux. Well, no problem. You just wrote a compiler that compiles from L to native Linux executable. You just need to use that compiler, CL, to write a new compiler C2L. C2L does the same thing as CL only it's written in L
instead of Java and so you can compile it to native with CL (running CL on the JVM). Once you've compiled C2L, you no longer need the JVM to run or compile anything because C2L runs natively and compiles to native executables.
Now, if you want to create another compiler that runs on Windows, you'll need to create a third compiler, C3L, that compiles L
to native EXE (or whatever Windows-compatible format you'll choose) - that compiler will be compiled with CL or C2L. Once you've compiled C3L you can take that executable over to a Windows machine and you're done.