18.104.22.168 describe program compilation stages: lexical and syntactic analysis, code generation and optimization
Stages of compiler design
When a programmer uses a computer language (high level) to write a program the statements are called source code.
The compiler translates source code in to machine code (low level).
The code that is compiled is stored as an executable file also called object file. When the file runs the machine code is processed by the CPU.
Stages in the compilation of a program
Lexical analysis is the process of analyzing a stream of individual characters (normally arranged as lines), into a sequence of lexical tokens (tokenization of words and symbols) to feed into the parser that the compiler will understand.
Source code is written by programmers using ASCII characters. During lexical analysis, the compiler breaks down this stream of ASCII characters into its component parts, called "lexemes".
This is alternatively known as parsing. This stage analyses the syntax of the statements to ensure they conform to the rules of grammar for the computer language in question.
The code generated by the compiler is an object code of some lower-level programming language, for example, assembly language.
Minimum properties of low-level object code:
Making the compile time as short as possible. Optimization is a program transformation technique, which tries to improve the code by making it consume less resources (i.e. CPU, Memory) and deliver high speed.
Optimizations provided by a compiler includes:
Give two examples of high level languages. (Marks: 1)
A compiler is used to run them. What does it do? (Marks: 1)
What is an advantage of writing a program using Pascal or Python compared to writing the same program in assembly code? (Marks: 1)
Why would a company not want to distribute source code when they sell a software package? (Marks: 2)
|Просмотров: 111 | ||
|Всего комментариев: 0|