Difference Between Compilers and Interpreter
- A compiler is computer software that readily translates programming language into machine code or assembly language or low-level language. It translates every program to binary digit 0 and 1 that a computer feasibly understand and does the tasks that corresponds to the code. One condition that a complier has to follow is the syntax of the programming language that is used. Thus, if the syntax of the program does not match the analysis of the compiler , an error arises that has to be corrected manually in the program written.
- The main work of the compiler is to translate the program into machine code and let the programmer know if there are any errors, ranges, limits, etc., especially the syntactical errors in the program. It analyses the entire program and converts it into machine code. The working of a compiler can be categorized into the following phases:
- Lexical analysis: splitting of source code into an abstract fragment known as lexeme. A token is generated for each of the lexemes , reffering to whether it is a keyword, a string, or some other variable.
- Semantic analysis: the AST is checked for semantic errors like the wrong variable assigned, using an undeclared variable, usig keywords as variable, etc.
- An interpreter is a computer program that converts program statements into machine code. Program statements include source code, pre-compiled code, and scripts.
- An interpreter works more or less similar to a compiler. The only difference between their working is that the interpreter does not any intermediate code forms, reads the program line to line checking for errors, and runs the program simultaneously.
- It coverts program statements, line by line , into machine code.
- Allows modification of program while executing.
- Execution of the program is relatively slow as analysis takes place every time the program is run. The running time of the interpreter is much slower than the compiler. The interpreter has no rigorous optimization takes place as code is evaluated line by line.
- The input through the lines of code for analysis. The interpreter takes in lines of code for analysis. The programming languages are PHP, PERL, Ruby are interpreter-based programming languages.