Compilation Principles.Longshu Learning 1

Chapter One:

Compiler: Translates a program into a form that can be executed by the computer

Interpreter: The interpreter directly uses input provided by the user to perform operations specified in the source program.

The structure of a compiler

The compiler maps the source program into a semantically equivalent target program. This mapping process consists of two parts: the analysis part and the synthesis part.

If a language uses a policy that allows the compiler to statically decide a certain issue, then we say that the language uses a static policy, or that the issue can be determined at compile time . On the other hand, a policy that only allows decisions to be made while running the program The policy that is decided is called a dynamic policy or is considered to require decisions to be made at run time

The environment is a mapping from names to storage locations, because variables are memory locations (i.e. "lvalues" in the C language term)

A state is a mapping from a memory location to their value. In C terms, a state maps lvalues ​​to their corresponding rvalues.

Chapter 2 - A simple grammar-guided translator

The syntax of a programming language describes the correct form of programs in that language

The semantics of the language define the meaning of the program

A model of a compiler front-end

syntax tree

Grammar definition

Gramma analysis

The task of grammar analysis is to accept a terminal symbol string as input and find a way to derive this string from the beginning symbol of the grammar. If the terminal string cannot be deduced from the start symbol of the grammar, report that the terminal string contains a syntax error

parse tree

Another definition of a grammar for a language is any set of strings of symbols that can be generated by a parse tree. The process of constructing a parser for a given terminal string is called parsing the string.

A grammar may have multiple parse trees that can generate a given terminal symbol string. Such a grammar is called ambiguity. We need to design unambiguous grammars for compiled applications, or use additional rules to disambiguate when using ambiguous grammars

regular expression

The last one is the complement of the character range

lexical analysis

One of the five stages of compiler implementation - lexical analysis.

  1. The goal of lexical analysis is to split code into lexical units, such as keywords, variable names, operators, etc. The lexical analyzer will accomplish this task by identifying the delimiters between different units.
  2. Each lexical unit has a corresponding category, such as identifier, keyword, operator, etc. The lexer will identify and classify these substrings and pass them to the parser.
  3. The parser will receive the output of the lexer in the form of a series of categories and substrings that make up a so-called "token".

Guess you like

Origin blog.csdn.net/zaizai1007/article/details/132995358