-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path12-Compiler.js
More file actions
32 lines (27 loc) · 1.25 KB
/
12-Compiler.js
File metadata and controls
32 lines (27 loc) · 1.25 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
/**
* JavaScript is under category of “dynamic” or “interpreted” language, which it's compiler has many steps in JavaScript, including:
* a)Tokenizing
* b)Parsing
* c)Code-Generation
*
*/
/**
* Tokenizing:
* Breaking up a string of characters into meaningful (to the language) chunks, called tokens.
* For instance, consider the program var a = 2;. This program would likely be broken up into the following
* tokens: var, a, =, 2, and ;. Whitespace may or may not be persisted as a token, depending on whether its meaningful or not.
*/
/**
* Parsing:
* taking a stream (array) of tokens and turning it into a tree of nested elements, which collectively represent the grammatical structure
* of the program. This tree is called an “AST” (abstract syntax tree).
* The tree for var a = 2; might start with a top-level node called Variable Declaration, with a child node called Identifier
* (whose value is a), and another child called Assignment Expression, which itself has a child called NumericLiteral
* (whose value is 2).
*/
/**
* Code-Generation:
* The process of taking an AST and turning it into executable code.
* This part varies greatly depending on the language, the platform it’s targeting, and so on.
*
*/