So for example, something like Babel for JS is considered a compiler, because its output is JavaScript, which is a standardized language.
On the other hand, Python is not usually considered a compiler, even though it writes .pyc files to disk, because its output is bytecode that only Python itself is expected to understand.
Even this is a little bit grey though, because we would say that Python contains a bytecode compiler as one of its components, but I don't think that most people would say that the Python binary is a compiler.
I'd disagree, simply because this is exactly what javac does too.
http://docs.oracle.com/javase/specs/jvms/se7/html/jvms-6.htm...
Python bytecode on the other hand is not standardized: its bytecode is considered an implementation detail of CPython and can vary from version to version.
Your example reinforces my point.
If things were such that "java" runs all .java files and creates those .class files as bytecode cache, then java won't have been called a compiler.
And similarly, if python had two different programs, one to create *.pyc files and the other runs it, the former one would have been called a python compiler.
For example, CPython could be considered to technically be a virtual machine because it does garbage collection on dead objects since v 2.4 at least, rather than being pure reference counting.
Yet most people would call CPython a straight interpreter.
Now what if before building such a machine, I wanted to simulate one? I could write a "virtual" machine, which is really just a program that acts like a physical machine with native JavaScript instructions. Also known as a JavaScript interpreter.
If all you have are compilers, you can never run a program. All you can do is convert it between different languages. Fortunately your computer comes with an interpreter built in: you can think of your cpu as an interpreter for machine code, implemented in hardware.
In theory, compilation is reversible, execution is not.
Something that compiles to an executable format for your environment is most likely to be actually called a compiler. Some "interpreters" are actually compiling to opcodes for a virtual machine then running on the virtual machine.
My personal recommendation in this field is nanopass compiler architecture. It's a more manageable approach to the task of implementing a compiler, through the use of lots of incremental passes rather than a few heroic ones.
http://andykeep.com/pubs/np-preprint.pdf
NB "When a paper on the first nanopass framework was accepted for ICFP 2004, however, the program committee required the authors to refocus the paper on education because they did not believe the nanopass methodology was suitable for commercial compilers. They were principally concerned with the compile-time overhead of repeated traversals. This concern was impossible to refute at the time because the prototype infrastructure and implementation were not mature enough to put to the test."
I did just that. The data structure matches the language exactly.
It is also slow.
The plan was to benchmark it and optimize the slowest parts, but they turn out to be all equally slow.
It is better to skip this step and directly create some byte-code or something. Probably less work than changing it later
Step 1. Write a program that reads the input program into a data structure that exactly represents the language. You just wrote a parser.
Step 2. Write a program that operates on the data structure from (1) to execute the program. You just wrote an interpreter.
Step 3 (Optional): Write a program that converts the data structure from (1) into a different data structure that you can interpret more efficiently. You just wrote an optimizer.
Step 4 (Optional): Keep iterating on (3) until the output of your optimizer is machine code. You just wrote a compiler.
Not saying the above obviates the need for a book like this one (at all), I just had never thought of it in quite this way and wanted to write it down. :)