Home  >  Article  >  What types of computer languages ​​are there?

What types of computer languages ​​are there?

小老鼠
小老鼠Original
2023-06-29 17:46:4411239browse

Computer language types include: 1. High-level language and low-level language; 2. Dynamic type and static type; 3. Mandatory type and weak type; 4. Compiled, interpreted, semi-compiled and semi-interpreted; 5. Object-oriented type and process-oriented type; 6. Distinguish between compiled type and interpreted type.

What types of computer languages ​​are there?

Three major categories of computer languages ​​(divided by level)

The correlation with hardware gradually decreases

Computer languages ​​have There are many types; according to different functions and implementation methods, they can be roughly divided into three categories: machine language assembly language and high-level language.

1. Machine language, a language that a computer can recognize directly without translation is called machine language (also known as binary code language). This language is a sequence of instructions composed of binary numbers 0 or 1.

2. Assembly language. Assembly language uses English letters or symbol strings to replace machine language. Machine language that is difficult to understand and remember is converted into assembly instructions according to the corresponding relationship. Assembly language is easier to read and understand than machine language.

3. High-level language. High-level language is not a language but a collective name for a class of languages. It is closer to the language used by humans than assembly language and is easy to understand, remember and use. Because high-level languages ​​have nothing to do with computer architecture and instruction sets, they have good portability. High-level languages ​​are widely used for program development, including C, C, Java, VB, C#, Python, Ruby, etc.

Common classification methods classification

1. High-level language and low-level language

Common low-level languages ​​include: machine code, assembly language

High-level language Common languages ​​include: c, c, java, python, PHP, Ruby, go, kotlin, and swift.

Machine code, a secondary code that can be directly recognized by the computer. No matter how advanced the language is, it must be converted into a secondary file for the computer to recognize and run.

Assembly, use mnemonics to replace the opcode of the machine instruction, use address symbol Symbol or label to replace the address of the instruction or operand, there are different instruction sets in different devices

High-level language, in order to save unnecessary operation details during programming, save the amount of code, have strong readability and maintainability, and be more humane.

The difference between high-level languages ​​and low-level languages: Most high-level languages ​​cannot directly deal with hardware, which makes the relative program running speed slower. In a word, the language that is closer to human nature is more advanced.

Six processes of high-level language compilation

Compilation is the process of translating high-level language source programs into target programs.

The entire process can generally be divided into six stages: lexical analysis, syntax analysis, semantic analysis, intermediate code generation, code optimization and target code generation.

  • Lexical analysis, lexical analysis is the first stage. The task of this stage is to read the source program character by character from left to right, and scan the character stream that constitutes the source program. and decomposition to identify each word.

  • Grammatical analysis, the task of grammatical analysis is to decompose word programs into grammatical phrases based on lexical analysis.

  • Semantic analysis, semantic analysis is to review the source program for semantic errors and collect type information for the code generation stage.

  • Intermediate code generation, after performing the above syntax analysis stage and other work, some compilers turn the source program into an internal representation. This internal representation is called intermediate Language or intermediate code. The intermediate code generation stage further converts the source program into an internal representation based on syntax and semantic analysis. It is usually easy to generate and translate into target code, but not all languages ​​must go through this step.

  • Code optimization, the task of this stage is to transform or transform the intermediate code generated in the previous stage, with the purpose of making the generated target code more efficient. In the code optimization stage, it is not necessary to transform or transform the intermediate code generated in the previous stage to save more time and space when generating target code.

  • Target code generation, the task of this stage is to transform the intermediate code into absolute instruction code or relocatable instruction code or assembly instruction code on a specific machine.

2. Dynamic type and static type

Dynamic language refers to the type of data that is specified for variables during the running of the program. It is common in Python and Ruby, and static type Type languages ​​are just the opposite. When writing program code, you must specify the type of the variable. This language has cc java

3. Forced type and weak type

We can know that a variable in C language It can only be defined as one type such as float type, then it can only be of float type and cannot be assigned to int type without conversion. This is the specific embodiment of forced type.

But in python, variables in python can be copied arbitrarily without type boundaries. This is weak typing

Forced typing is more rigorous and less prone to errors, but weakly typed languages ​​are more elegant and comfortable to write

4. Compiled and interpreted half-compiled and half-interpreted

For source program compiled languages, the source files will be converted into machine code all at once during the execution of the program, while interpreted languages ​​will be compiled and interpreted at the same time

Compiled languages ​​are inseparable from interpreters, which also causes interpreted languages ​​to be slower at runtime. Interpreted languages ​​are more convenient to transplant as long as there is an interpreter, while compiled languages ​​need to be compiled for different systems. Yes, the work is tedious and slow when debugging the program.

Compiled languages ​​can be found in cc, etc.

Interpreted languages ​​can be found in python, JavaScript, Perlshell, etc.

And java is half compiled and half The interpreted language java will convert the source file into bytecode in the jVM, that is, the .class file will be converted into a binary file when the program is running. It is a bit different from .net in C#. The .net target code compiled by C# is close to the portability of binary files and is not as good as java. Java is "compile once and execute everywhere". C# is "encode once and compile everywhere".

5. Object-oriented and process-oriented

Process-oriented is to decide how to pave a road to reach the end, while object-oriented is to use images with specific functions to do both. Different thoughts.

c is a partially object-oriented Java language with encapsulation and is completely object-oriented. The C language is a process-oriented language.

There is also a functional type here

The concept of dynamic, static and strong and weak types of programming language paradigm - The wind is clear and the heart is flying - Blog Park The concept of dynamic, static and strong and weak types of programming language paradigm is learning When learning languages, we often encounter several concepts. For example, Java is an object-oriented language, C is a process-oriented language, Lisp is a functional programming language, and Scala is a static language. What do these mean? https://www.cnblogs.com/binbinbin /articles/14012424.html

6. Distinguish between compiled type and interpreted type

1. The compiled program is compiled as a whole to form the target code and then executed at once.

The interpreter interprets and executes at the same time. Explanation of a sentence and then submitting it to the computer for execution does not form a target program. Just like "interpretation" in foreign language translation, it does not produce translated text.

2. Compilation means that except for the first compilation, the target code is executed by the machine = result

, while the interpreter is always the code interpreter machine execution = result

in detail It is said that the compiler compiles each statement of the source program into machine language and saves it as a binary file. In this way, the computer can directly run the program in machine language at runtime, which is very fast.

The interpreter only interprets the program one by one into machine language for the computer to execute, so the running speed is not as fast as the compiled program. This is because the computer cannot directly recognize and execute the statements we write, it can only recognize machine language (in binary form)

7. Reasons for classification by level

1. Intermediate code

Intermediate code generation is the process of generating intermediate code. The so-called "intermediate code" is a notation system with a simple structure and clear meaning. The complexity of this notation system is between the source program language and the machine language, and it is easy to translate it into the target code. In addition, machine-independent optimizations can be performed at the intermediate code level.

Assembly code is the target code. The intermediate code is theoretically machine-independent.

In the compilation principle, knowledge ternary, quaternary, reverse Polish, etc. represent intermediate codes.

2. Object code

Object code; object code refers to the code generated by the compiler or assembler in computer science after processing the source code. It is generally composed of machine code or code close to machine language. composition. Object file is a computer file that stores object code. It is often called binary file; binaries. The object file contains machine code; data that can be directly executed by the computer's central processor and used by the code during runtime, such as relocation information such as program symbols for linking or debugging; names of variables and functions, and other debugging information. The object file is an intermediate product of the process of generating program files from source code files. The linker generates an executable file or library file by linking the object files together. The only element in an object file is machine code. For example, an object file for an embedded system may contain only machine code.

The target code usually takes three forms: machine language assembly language to be assembled into the machine language module.

Issues that should be considered when generating target code

(1)How to make the generated target code shorter

(2)How to make full use of registers to reduce the number of memory accesses

(3) How to make full use of the features of the pointing system.

In assembly language, register AX, instruction register IR, etc. are often directly used. Different register parameters are different, so assembly language is more hardware language.

The above is the detailed content of What types of computer languages ​​are there?. 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