V8 Engine
V8 is open source high-performance javascript engine. it compiles and executes javascript code It is used in chrome browser and NodeJS and it is written in C++. V8 is high performed engine because it combines two parts of the engine the compiler and the interpreter, Today all engine uses the same technique.
How does the v8 engine work?
- Parser
parsing phase process of analyzing the whole source code, checking for errors and breaks into parts for easy translation.
- Abstract syntax tree(AST) conversion
The Parser produces a data structure called AST, AST is a tree graph of source code it doesn't show all details of the original syntax but it contains structural details.
- Interpreter
The interpreter executes each line of code line by line, without requiring them to be compiled into a machine language program. Interpreters take less time for analysing the source code, In the interpreter Execution of the program happens after every line is checked or evaluated this helps to translate code into more efficient machine code that executes precompiled code made by a compiler.
- Profiler
In modern engines, the interpreter starts reading the code line by line while the profiler watches for frequently used code and flags then passes it to the compiler to be optimized.
- Compiler
The compiler executes the whole source code at once into a machine language program. In a compiler, the source code is translated to object code successfully if it is free of errors.
Conclusion
Thank you