Steps of source code change to executable application

Source: Internet
Author: User

The whole process of running the program, learn a bit

    • source code →
    • preprocessor (preprocessor) →
    • compiler (compiler) →
    • compilation program (assembler) →
    • Object code →
    • connector (Linker) →
    • executable Program (executables)

1. Lexical analysis

The lexical analyzer identifies each token in the source program according to the word rules, each representing a class of words (Lexeme). Common tokens in the source program can be categorized into several categories: keywords, identifiers, literals, and special symbols. The input of the lexical analyzer is the source program, and the output is the identified tick stream. The task of the lexical analyzer is to change the character flow of the source file into a tick stream. Essentially it looks at successive characters and recognizes them as "words".

2. Grammatical analysis

The parser identifies the structure (phrase, sentence) in the tick stream according to the grammatical rules, and constructs a syntax tree that correctly reflects the structure.

3. Semantic Analysis

The semantic parser makes a static semantic check of the grammatical elements in the syntax tree according to the semantic rules, and the purpose of this is to ensure that the syntactically correct structure is semantically valid, if the type is checked and transformed.

4. Intermediate code generation

The intermediate code generator generates intermediate code based on the output of the semantic parser. Intermediate codes can take several forms, and their common characteristics are not related to specific machines. One of the most commonly used intermediate codes is the three address code, which is implemented in a four-yuan manner. The advantages of the three address codes are easy to read and easy to optimize.

5. Intermediate code optimization

Optimization is an important part of the compiler, because the compiler's work of translating the source program into intermediate code is mechanically and in fixed mode, so the resulting intermediate code is often wasted in time and space. When you need to generate efficient target code, you must optimize it.

6. Target code generation

Target code generation is the last phase of the compiler. There are several issues to consider when generating the target code: The system structure of the computer, the instruction system, the allocation of registers, and the organization of the memory. Compiler generated target program code can be in many forms: assembly language, Relocatable binary code, memory form.

7 Symbol Table Management

The function of the symbol table is to record the necessary information of the symbols in the source program and organize them reasonably so that they can be quickly and accurately searched and manipulated at each stage of the compiler. Some content in the symbol table is even persisted to the program's run stage.

8 Error Handling

User-written source programs often have some errors, can be divided into static errors and dynamic errors in two categories. The so-called dynamic error, refers to the source program logic errors, they occur when the program is running, also known as dynamic semantic errors, such as the value of the variable is zero as a divisor, the array element refers to when the label out of bounds. Static errors can be divided into syntax errors and static semantic errors. Grammatical errors refer to errors in the structure of a language, such as misspelled words, missing operands in an expression, begin and end mismatches, and so on. A static semantic error is a linguistic error that can be found when parsing a source program, such as an integer variable name in the two operands of an addition, and an array name, among other things.

Steps of source code change to executable application

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.