Home  >  Article  >  What can convert a source program written in a high-level language into a target program?

What can convert a source program written in a high-level language into a target program?

青灯夜游
青灯夜游Original
2020-11-03 17:02:4156529browse

The "compiler" converts a source program written in a high-level language into a target program. A compiler refers to a translation program that translates a source program written in a high-level programming language into an equivalent target program in machine language format; a compiler takes a source program written in a high-level programming language as input and uses assembly language or machine language as input. Represents the target program as output.

What can convert a source program written in a high-level language into a target program?

#The "compiler" converts a source program written in a high-level language into a target program. The program written in a high-level language is called a "source program", and the program represented by binary code is called a "target program". The conversion of the source program into a target program that can be recognized by the machine is completed by the "compiler".

Compiler, compiling program, also called a compiler, refers to a translation program that translates a source program written in a high-level programming language into an equivalent target program in machine language format. Compilers are translation programs implemented using a generative implementation approach.

The compiler takes a source program written in a high-level programming language as input, and a target program expressed in assembly language or machine language as output. The compiled target program usually also goes through a running stage in order to run with the support of the running program, process the initial data, and calculate the required calculation results.

Features

The compiler must analyze the source program and then synthesize it into the target program. First, check the correctness of the source program and decompose it into several basic components; secondly, establish corresponding equivalent target program parts based on these basic components. In order to complete these tasks, the compiler must create some tables during the analysis phase and transform the source program into an intermediate language form so that it can be easily referenced and processed during analysis and synthesis.

The main data structures used in data structure analysis and synthesis include symbol tables, constant tables and intermediate language programs. The symbol table consists of the identifiers used in the source program together with their attributes, which include types (such as variables, arrays, structures, functions, procedures, etc.), types (such as integers, real types, strings, complex types, labels) etc.), and other information required by the target program. The constant table consists of the constants used in the source program, including the machine representation of the constants, and the target program addresses assigned to them. An intermediate language program is an intermediate form of program introduced before translating the source program into the target program. The choice of its representation depends on how the compiler will use and process it later. Commonly used intermediate language forms include Polish representation, triples, quadruples, and indirect triples.

Analysis of part of the source program is achieved through three steps: lexical analysis, syntax analysis and semantic analysis. Lexical analysis is completed by a lexical analysis program (also called a scanner), whose task is to identify words (i.e. identifiers, constants, reserved words, and various operators, punctuation marks, etc.), create symbol tables and constant tables, and convert The source program is converted into an internal form that is easy to analyze and process by the compiler. The syntax analyzer is the core part of the compiler. Its main task is to check whether the source program is grammatical according to the grammatical rules of the language. If it is not grammatical, a syntax error message will be output; if it is grammatical, the grammatical structure of the source program will be decomposed and an internal program in the form of intermediate language will be constructed. The purpose of grammatical analysis is to understand how words form sentences and how statements form programs. The semantic analysis program further checks the semantic correctness of legal program structures. Its purpose is to ensure the correct use of identifiers and constants, collect and save necessary information into symbol tables or intermediate language programs, and perform corresponding semantic processing.

The above is the detailed content of What can convert a source program written in a high-level language into a target program?. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn