Article directory
variable
The most fundamental feature in a programming language is that the ability to变量
store and access brings to programs. The question is: where is the variable stored? More importantly how does the program find them? Explain that you need to design a good set of rules to store variables and find them easily, and that's it .变量
状态
作用域
traditional compiled language
A piece of source code in a program goes through three steps, collectively 编译
:
- Lexical analysis:
decompose each piece of code into meaningful code blocks
suchvar = 1
as intovar
,=
,1
. - Syntax analysis
This process词法单元流
converts into a tree that represents the grammatical structure of the program, called抽象语法树
,
for exampleVariableDeclaration
, a node that contains aIdentifier = var
andAssignmentExpression
node,
andAssignmentExpression
that containsNumericLiteral = 1
a node. - Code generation converts
into executable code, and this process is closely related to . Simply put, there is some way to turn the of into a series of machine instructions to perform this operation.抽象语法树
语言、目标平台
var = 1
抽象语法树
JavaScript engine
- The JavaScript
语法分析
engine代码生成
has specific steps in the and process to optimize the running performance. - JavaScript engines don't have a lot of time to optimize, and the compilation process doesn't happen before the build.
Usually the JS code fragment is compiled before execution, and after compilation, it will be ready for execution and executed immediately.