3 ms·
A compiler is a language translator. To me it makes no difference whether it generates machine code (one type of language, machine executable), asm (equivalent
by vrighter 1y ago
A compiler is a language translator. To me it makes no difference whether it generates machine code (one type of language, machine executable), asm (equivalent language but which needs additional preprocessing into machine code), or some other language (which also needs additional preprocessing into machine code, but the tool for this is another compiler). Or it might output Java bytecode or MSIL, which doesn't even target a real, physical machine at all.
They translate one language into another. The line between compiler/transpiler just doesn't make sense to me.
- orthoxerox 1y agoLet's put it this way: if a program translates code written in a "smarter" language into code written in a "stupider" language, then it is okay to call it a compiler. If it translates a restricted subset of BASIC into Go, it doesn't really do anything beyond replacing one syntax with another.
- vrighter 1y ago"Smarter" and "stupider" are completely subjective terms. It translates one language into another, while maintaining logical correctness and its original semantics. Some cases are easier to do than others, but it doesn't change the nature of what is being done: language translation. It isn't as simple as you think. Ex. in basic, the goto statement allows you to jump from anywhere to anywhere. Go has restrictions, such as it may not jump over variables coming into scope (being declared), nor can it jump into another scope, only outwards. So, for starters, this probably needs to scan the BASIC code for variables and hoist everything to the top as well as rewrite any code where it is trying to jump into a deeper scope (ex. jump from the topmost scope of a function into the body of a for loop). Yes, it is a compiler. Maintaining semantics.