In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-03-31 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/02 Report--
This article mainly shows you "how to compile C#program", the content is simple and easy to understand, organized clearly, I hope to help you solve doubts, let Xiaobian lead you to study and learn "how to compile C#program" this article bar.
C#compiler
Before we talk about C#compilers, let's understand one thing: computers cannot understand high-level languages directly, only machine languages, so high-level languages must be translated into machine languages for computers to execute programs written in high-level languages. There are two ways of translation, one is compilation and the other is interpretation.
The only difference between the two is the translation time. Before the program written in compiled language is executed, a special compilation process is required to compile the program into a machine language file, such as an exe (com) file. If you want to run it later, you don't have to retranslate it, and you can use the compiled result directly (exe file).
The C#compilation phase is as follows:
C#compiler to translate a C#source program into the target program work process is divided into five stages: 1, lexical analysis;2, syntax analysis;3, intermediate code generation;4, code optimization;5, object code generation. Mainly lexical analysis and syntax analysis, also known as source code analysis, analysis process found syntax errors, give prompt information.
1. Lexical analysis
The task of lexical analysis is to process the words composed of characters, scan the source program from left to right character by character, generate word symbols one by one, and transform the source program as a character string into an intermediate program of the word symbol string. A program that performs lexical analysis is called a lexical analyzer or scanner.
Word symbols in the source program are analyzed by the scanner and generally produce binary expressions: word type; the value of the word itself. Word classes are usually coded with integers. If a class contains only one word symbol, the class code represents the value of the word symbol. If a category contains many word symbols, then for each of its word symbols, in addition to giving the category code, you should also give its own value.
Lexical analyzers are generally constructed in two ways: manually constructed and automatically generated. Manual construction can be done using state diagrams and automatic generation can be done using deterministic finite automata.
2. Syntax analysis
Compiler program syntax analyzer with word symbols as input, analyze whether the word symbol string forms a grammatical unit that conforms to the grammar rules, such as expressions, assignments, loops, etc., *** to see if it constitutes a program that meets the requirements, according to the grammar rules used by the language analysis to check whether each sentence has the correct logical structure, the program is the final one of the grammatical units. Compiler syntax rules can be characterized by context-free grammars.
There are two methods of grammar analysis: top-down analysis and bottom-up analysis. From top to bottom is to start from the beginning of the grammar symbol, downward deduction, deducing sentences. The bottom-up analysis method uses the method of shift reduction. The basic idea is to move the input symbols into the stack one by one by using the first-in-last-out stack of a registered symbol. When a candidate for a production is formed at the top of the stack, the part at the top of the stack is reduced to the left-adjacent symbol of the production.
3. Intermediate code generation
Intermediate code is an internal representation of the source program, or intermediate language. The function of intermediate code is to make the structure of compiled program more simple and clear logically, especially to make the optimization of object code easier to realize. Intermediate code is an intermediate language program whose complexity lies between source language and machine language. Intermediate languages come in many forms, common ones being inverse Polish notation, quaternions, triples, and trees.
4. Code optimization
Code optimization is to transform a program to generate more efficient object code. Equivalence means not changing the results of the program. Effective mainly refers to the short running time of the target code and the small storage space occupied. This transformation is called optimization.
There are two types of optimizations: those performed on parsed intermediate code, which are independent of the specific computer, and those performed on target code generation, which are largely computer-dependent. For the former optimization, it can be divided into three different levels: local optimization, circular optimization and global optimization according to the scope of the program it involves.
5. Object code generation
Object code generation is a *** phase of compilation. The object code generator transforms the parsed or optimized intermediate code into object code.
Three problems that directly affect the speed of object code should be considered in the stage of object code generation: one is how to generate shorter object code; the other is how to make full use of the registers in the computer to reduce the number of times the object code accesses the storage unit; the third is how to make full use of the characteristics of the computer instruction system to improve the quality of the object code.
6. Form management procedure
Various information of the source program is kept in various tables during compilation, and the work of each stage of compilation involves constructing, searching, or updating the relevant tables.
7. Error Handling Procedures
If an error is found in the source program during compilation, the compiler should report the nature of the error and where it occurred, and limit the impact of the error to as little as possible so that the rest of the source program can continue to be compiled.
This is also the general compilation process of compiled languages, but it should be noted that C#has a special place, that is, C#can be compiled into TL files first, the code compiled into intermediate code (IL) is neither source nor cpu instructions, when the program runs JIT will translate IL into local cpu instructions and then execute, because the compilation is an intermediate language, so the speed is faster than the general interpreted language.
Java also has this feature, java programs also need to compile, but not directly compiled called machine language, but compiled called bytecode, and then interpreted to execute bytecode.
The above is "C#how to compile programs" all the content of this article, thank you for reading! I believe that everyone has a certain understanding, hope to share the content to help everyone, if you still want to learn more knowledge, welcome to pay attention to the industry information channel!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.