**whether the interpretation follows compilation phase during the exection of a pgm?**simply what happens when we run a program?if these are different things then what will perform syntax checking before interpretation.As i read python is a interpreted language then checking of statements done by what?
1 Answer
You have two options:
- Compiled languages
- Interpreted languages
In a compiled language, you need a compiler that gets source code as input and generates a binary as output that can run on a given target platform. For example, C, C++ or Java are compiled languages. After compiler generates the binary, you execute that binary on the target platform. The main steps involved in the compilation process to generate a binary are lexic, syntactic and semantic analysis, and code generation.
The compiler is a program (binary) that runs on the native platform and generates code for a given target platform. You have two options:
* target_platform == native_platform (native-compiler)
* target_platform != native_platform (cross-compiler).
If you have a x86_64 desktop PC, your compiler runs on x86_64 and generates code that runs on x86_64, your have a native compiler. In this case, the compiler generates native machine code.
If you have a x86_64 desktop PC, your compiler runs on x86_64 and generates code that runs on a different platform (such as JVM), you have a cross-compiler. You should understand that Java language uses a cross-compiler that gets java language as input, and generates byte-code that runs on the JVM (not on the x86_64 machine) as output.
Other cross-compilers such as arm-linux-gcc, mips-linux-gcc, ppc-linux-gcc, and more, get C source code as input and generate binary to run on the proper target platform (ARM, MIPS, PPC).
In an interpreted language, you don't need a compiler to generate code, so a binary is not generated at the end of the process. bash and python are interpreted languages. The interpreter of the language (a binary installed in your PC such as /bin/bash or /usr/bin/python) receives input source code, interprets it, and executes it to generate the output. The steps followed to interpret the source code are exactly the same followed by a compiler, except the interpreter doesn't generate code, just executes it after analyzing.
I wrote an article some time ago explaining how you can write an interpreter of a custom-defined language using python. This article is written in spanish, but the whole process is explained step-by-step, so you can learn a lot if you are interested on it. At the end of the articles you can find the source code to download and test. Source code is available in github. The article is available at this link
Hope it helps! :)