Home > Web Front-end > Front-end Q&A > What is the interpreter of javascript

What is the interpreter of javascript

青灯夜游
Release: 2021-12-07 16:30:32
Original
4160 people have browsed it

The JavaScript interpreter, also known as the "JavaScript engine", is a virtual machine that specializes in processing JavaScript scripts and is generally included with web browsers; the JavaScript interpreter has four components: lexical analyzer, syntax analyzer Parser, bytecode generator, bytecode interpreter.

What is the interpreter of javascript

The operating environment of this tutorial: windows7 system, javascript version 1.8.5, Dell G3 computer.

What is a javascript interpreter?

JavaScript is a scripting language that needs to be interpreted and executed by others. This other person is the JavaScript interpreter . It reads a JS statement, translates it, executes it, then reads the next JS statement, and the cycle begins again.

The JavaScript interpreter, also known as the JavaScript engine, is a virtual machine that specializes in processing JavaScript scripts and is generally included with web browsers. Its function is to execute JavaScript source code.

The JavaScript parsing engine is a program that can "read" JavaScript code and accurately provide the results of the code execution.

Composition of JavaScript interpreter

The JavaScript interpreter has four components: lexical parser, syntactic parser, and bytecode generation processor, bytecode interpreter.

Lexical parser

It can split lines of code source code into the smallest units of word meaning. The so-called semantic unit is the smallest single character or combination of characters that cannot be divided grammatically.

  var number = 2;
  //解析成下面的json格式
  [
      {
        'type':'keyword',
        'value':'var'
      },
      {
        'type':'identifier',
        'value':'number',
      },
      {
        'type':'Punctuator',
        'value':'=',
      },
      {
       'type':'Numeric',
       'value':'2',
      }
      {
       'type':'Punctuator',
       'value':';'
      }
  ]
Copy after login

Syntax analyzer

Convert the above analyzed array into an abstract syntax tree according to the grammar rules. You can use the Esprimas parsing tool to know and convert it into json format.

What is the use of this abstract syntax tree?

People talk about compressing and optimizing code, but I don’t understand this. Then they say that compilers, IDEs, etc. have many uses (there is no way to go into it now because the skills are not enough)

On Meituan Dianping I saw in technology that syntax trees can be used to reconstruct javaScript code

bytecode generator

Its function is to convert the syntax tree into javaScript Binary code that the engine can read and execute.

Each javascript engine has its own bytecode format. The simplest way is to translate the semantic units into binary

Bytecode interpreter

Of course, this link after link has binary code, then the next step is to execute the binary code, producing results that you can see with your eyes.

[Related recommendations: javascript learning tutorial]

The above is the detailed content of What is the interpreter of javascript. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template