1
1
<!DOCTYPE HTML>
2
- < html lang ="en " class ="sidebar-visible no-js light ">
2
+ < html lang ="en " class ="light " dir =" ltr ">
3
3
< head >
4
4
<!-- Book generated using mdBook -->
5
5
< meta charset ="UTF-8 ">
10
10
11
11
< meta name ="description " content ="">
12
12
< meta name ="viewport " content ="width=device-width, initial-scale=1 ">
13
- < meta name ="theme-color " content ="#ffffff " / >
13
+ < meta name ="theme-color " content ="#ffffff ">
14
14
15
15
< link rel ="icon " href ="../favicon.svg ">
16
16
< link rel ="shortcut icon " href ="../favicon.png ">
32
32
< link rel ="stylesheet " href ="../theme/custom.css ">
33
33
34
34
</ head >
35
- < body >
35
+ < body class =" sidebar-visible no-js " >
36
36
< div id ="body-container ">
37
37
<!-- Provide site root to javascript -->
38
38
< script >
62
62
try { theme = localStorage . getItem ( 'mdbook-theme' ) ; } catch ( e ) { }
63
63
if ( theme === null || theme === undefined ) { theme = default_theme ; }
64
64
var html = document . querySelector ( 'html' ) ;
65
- html . classList . remove ( 'no-js' )
66
65
html . classList . remove ( 'light' )
67
66
html . classList . add ( theme ) ;
68
- html . classList . add ( 'js' ) ;
67
+ var body = document . querySelector ( 'body' ) ;
68
+ body . classList . remove ( 'no-js' )
69
+ body . classList . add ( 'js' ) ;
69
70
</ script >
70
71
72
+ < input type ="checkbox " id ="sidebar-toggle-anchor " class ="hidden ">
73
+
71
74
<!-- Hide / unhide sidebar before it is displayed -->
72
75
< script >
73
- var html = document . querySelector ( 'html ' ) ;
76
+ var body = document . querySelector ( 'body ' ) ;
74
77
var sidebar = null ;
78
+ var sidebar_toggle = document . getElementById ( "sidebar-toggle-anchor" ) ;
75
79
if ( document . body . clientWidth >= 1080 ) {
76
80
try { sidebar = localStorage . getItem ( 'mdbook-sidebar' ) ; } catch ( e ) { }
77
81
sidebar = sidebar || 'visible' ;
78
82
} else {
79
83
sidebar = 'hidden' ;
80
84
}
81
- html . classList . remove ( 'sidebar-visible' ) ;
82
- html . classList . add ( "sidebar-" + sidebar ) ;
85
+ sidebar_toggle . checked = sidebar === 'visible' ;
86
+ body . classList . remove ( 'sidebar-visible' ) ;
87
+ body . classList . add ( "sidebar-" + sidebar ) ;
83
88
</ script >
84
89
85
90
< nav id ="sidebar " class ="sidebar " aria-label ="Table of contents ">
86
91
< div class ="sidebar-scrollbox ">
87
92
< ol class ="chapter "> < li class ="chapter-item expanded "> < a href ="../intro.html "> < strong aria-hidden ="true "> 1.</ strong > Introduction</ a > </ li > < li class ="chapter-item expanded "> < a href ="../crash_course.html "> < strong aria-hidden ="true "> 2.</ strong > Crash Course on Computing</ a > </ li > < li class ="chapter-item expanded "> < a href ="../01_calculator/calc_intro.html "> < strong aria-hidden ="true "> 3.</ strong > Calculator</ a > </ li > < li > < ol class ="section "> < li class ="chapter-item expanded "> < a href ="../01_calculator/grammar_lexer_parser.html "> < strong aria-hidden ="true "> 3.1.</ strong > Grammar, Lexer and Parser</ a > </ li > < li class ="chapter-item expanded "> < a href ="../01_calculator/ast.html " class ="active "> < strong aria-hidden ="true "> 3.2.</ strong > Abstract Syntax Tree (AST) and Interpreter</ a > </ li > < li class ="chapter-item expanded "> < a href ="../01_calculator/jit_intro.html "> < strong aria-hidden ="true "> 3.3.</ strong > Just-In-Time (JIT) Compiler with LLVM</ a > </ li > < li > < ol class ="section "> < li class ="chapter-item expanded "> < a href ="../01_calculator/basic_llvm.html "> < strong aria-hidden ="true "> 3.3.1.</ strong > Basic Example</ a > </ li > < li class ="chapter-item expanded "> < a href ="../01_calculator/ast_traversal.html "> < strong aria-hidden ="true "> 3.3.2.</ strong > AST Traversal Patterns</ a > </ li > </ ol > </ li > < li class ="chapter-item expanded "> < a href ="../01_calculator/exercise.html "> < strong aria-hidden ="true "> 3.4.</ strong > Exercises</ a > </ li > < li class ="chapter-item expanded "> < a href ="../01_calculator/vm.html "> < strong aria-hidden ="true "> 3.5.</ strong > Virtual Machine (VM), Bytecode and Interpreter</ a > </ li > < li class ="chapter-item expanded "> < a href ="../01_calculator/repl.html "> < strong aria-hidden ="true "> 3.6.</ strong > Read-Eval-Print Loop (REPL)</ a > </ li > </ ol > </ li > < li class ="chapter-item expanded "> < div > < strong aria-hidden ="true "> 4.</ strong > Firstlang</ div > </ li > < li > < ol class ="section "> < li class ="chapter-item expanded "> < div > < strong aria-hidden ="true "> 4.1.</ strong > Static Typing and Type Inference</ div > </ li > </ ol > </ li > < li class ="chapter-item expanded "> < div > < strong aria-hidden ="true "> 5.</ strong > Object System and Object Oriented Language</ div > </ li > < li class ="chapter-item expanded "> < div > < strong aria-hidden ="true "> 6.</ strong > TENTATIVE: Mini Standard Library</ div > </ li > < li class ="chapter-item expanded "> < div > < strong aria-hidden ="true "> 7.</ strong > Resources</ div > </ li > </ ol >
88
93
</ div >
89
- < div id ="sidebar-resize-handle " class ="sidebar-resize-handle "> </ div >
94
+ < div id ="sidebar-resize-handle " class ="sidebar-resize-handle ">
95
+ < div class ="sidebar-resize-indicator "> </ div >
96
+ </ div >
90
97
</ nav >
91
98
92
99
<!-- Track and set sidebar scroll position -->
117
124
< div id ="menu-bar-hover-placeholder "> </ div >
118
125
< div id ="menu-bar " class ="menu-bar sticky ">
119
126
< div class ="left-buttons ">
120
- < button id ="sidebar-toggle " class ="icon-button " type =" button " title ="Toggle Table of Contents " aria-label ="Toggle Table of Contents " aria-controls ="sidebar ">
127
+ < label id ="sidebar-toggle " class ="icon-button " for =" sidebar-toggle-anchor " title ="Toggle Table of Contents " aria-label ="Toggle Table of Contents " aria-controls ="sidebar ">
121
128
< i class ="fa fa-bars "> </ i >
122
- </ button >
129
+ </ label >
123
130
< button id ="theme-toggle " class ="icon-button " type ="button " title ="Change theme " aria-label ="Change theme " aria-haspopup ="true " aria-expanded ="false " aria-controls ="theme-list ">
124
131
< i class ="fa fa-paint-brush "> </ i >
125
132
</ button >
@@ -168,7 +175,7 @@ <h1 class="menu-title">Create Your Own Programming Language with Rust</h1>
168
175
< div id ="content " class ="content ">
169
176
< main >
170
177
< h2 id ="abstract-syntax-tree-ast "> < a class ="header " href ="#abstract-syntax-tree-ast "> Abstract Syntax Tree (AST)</ a > </ h2 >
171
- < p > AST comes into picture when we want to go from the string representation of our program like < code > "-1" </ code > or < code > " 1 + 2" </ code > to something more manageable and easier to work with. Since our program is not a random string (the grammar is for), we can use the structure within the expressions < code > "-1" </ code > and < code > " 1 + 2" </ code > to our own advantage and come up with a < em > new representation</ em > like a < a href ="https://en.wikipedia.org/wiki/Tree_structure "> tree</ a > </ p >
178
+ < p > AST comes into picture when we want to go from the string representation of our program like < code > "-1" </ code > or < code > " 1 + 2" </ code > to something more manageable and easier to work with. Since our program is not a random string (the grammar is for), we can use the structure within the expressions < code > "-1" </ code > and < code > " 1 + 2" </ code > to our own advantage and come up with a < em > new representation</ em > like a < a href ="https://en.wikipedia.org/wiki/Tree_structure "> tree</ a > </ p >
172
179
< p align ="center ">
173
180
</ br >
174
181
< a href > < img alt ="ast " src ="../img/ast.svg "> </ a >
@@ -201,7 +208,7 @@ <h2 id="abstract-syntax-tree-ast"><a class="header" href="#abstract-syntax-tree-
201
208
</ code > </ pre >
202
209
</ li >
203
210
</ ul >
204
- < p > So for example, the expression < code > " -1 + (2 + 3)" </ code > has this recursive structure</ p >
211
+ < p > So for example, the expression < code > " -1 + (2 + 3)" </ code > has this recursive structure</ p >
205
212
< p align ="center ">
206
213
</ br >
207
214
< a href > < img alt ="compiler " src ="../img/ast_recursive.svg "> </ a >
@@ -274,9 +281,9 @@ <h2 id="interpreter"><a class="header" href="#interpreter">Interpreter</a></h2>
274
281
fn from_ast(ast: Vec<Node>) -> Self::Output;
275
282
276
283
fn from_source(source: &str) -> Self::Output {
277
- println!(" Compiling the source: {}" , source);
284
+ println!(" Compiling the source: {}" , source);
278
285
let ast: Vec<Node> = parser::parse(source).unwrap();
279
- println!(" {:?}" , ast);
286
+ println!(" {:?}" , ast);
280
287
Self::from_ast(ast)
281
288
}
282
289
}</ code > </ pre >
@@ -297,7 +304,7 @@ <h2 id="interpreter"><a class="header" href="#interpreter">Interpreter</a></h2>
297
304
}</ code > </ pre >
298
305
< p > < span class ="filename "> Filename: calculator/src/compiler/interpreter.rs</ span > </ p >
299
306
< p > and test</ p >
300
- < pre > < code class ="language-rust ignore "> assert_eq!(Interpreter::from_source(" 1 + 2" ).unwrap(), 3);</ code > </ pre >
307
+ < pre > < code class ="language-rust ignore "> assert_eq!(Interpreter::from_source(" 1 + 2" ).unwrap(), 3);</ code > </ pre >
301
308
< p > Run such tests locally with</ p >
302
309
< pre > < code class ="language-text "> cargo test interpreter --tests
303
310
</ code > </ pre >
@@ -310,7 +317,7 @@ <h2 id="interpreter"><a class="header" href="#interpreter">Interpreter</a></h2>
310
317
< i class ="fa fa-angle-left "> </ i >
311
318
</ a >
312
319
313
- < a rel ="next " href ="../01_calculator/jit_intro.html " class ="mobile-nav-chapters next " title ="Next chapter " aria-label ="Next chapter " aria-keyshortcuts ="Right ">
320
+ < a rel ="next prefetch " href ="../01_calculator/jit_intro.html " class ="mobile-nav-chapters next " title ="Next chapter " aria-label ="Next chapter " aria-keyshortcuts ="Right ">
314
321
< i class ="fa fa-angle-right "> </ i >
315
322
</ a >
316
323
@@ -324,7 +331,7 @@ <h2 id="interpreter"><a class="header" href="#interpreter">Interpreter</a></h2>
324
331
< i class ="fa fa-angle-left "> </ i >
325
332
</ a >
326
333
327
- < a rel ="next " href ="../01_calculator/jit_intro.html " class ="nav-chapters next " title ="Next chapter " aria-label ="Next chapter " aria-keyshortcuts ="Right ">
334
+ < a rel ="next prefetch " href ="../01_calculator/jit_intro.html " class ="nav-chapters next " title ="Next chapter " aria-label ="Next chapter " aria-keyshortcuts ="Right ">
328
335
< i class ="fa fa-angle-right "> </ i >
329
336
</ a >
330
337
</ nav >
0 commit comments