Skip to content

Commit cd93ab0

Browse files
committed
deploy: 0df3357
1 parent e86c7d1 commit cd93ab0

21 files changed

+623
-354
lines changed

01_calculator/ast.html

+25-18
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<!DOCTYPE HTML>
2-
<html lang="en" class="sidebar-visible no-js light">
2+
<html lang="en" class="light" dir="ltr">
33
<head>
44
<!-- Book generated using mdBook -->
55
<meta charset="UTF-8">
@@ -10,7 +10,7 @@
1010

1111
<meta name="description" content="">
1212
<meta name="viewport" content="width=device-width, initial-scale=1">
13-
<meta name="theme-color" content="#ffffff" />
13+
<meta name="theme-color" content="#ffffff">
1414

1515
<link rel="icon" href="../favicon.svg">
1616
<link rel="shortcut icon" href="../favicon.png">
@@ -32,7 +32,7 @@
3232
<link rel="stylesheet" href="../theme/custom.css">
3333

3434
</head>
35-
<body>
35+
<body class="sidebar-visible no-js">
3636
<div id="body-container">
3737
<!-- Provide site root to javascript -->
3838
<script>
@@ -62,31 +62,38 @@
6262
try { theme = localStorage.getItem('mdbook-theme'); } catch(e) { }
6363
if (theme === null || theme === undefined) { theme = default_theme; }
6464
var html = document.querySelector('html');
65-
html.classList.remove('no-js')
6665
html.classList.remove('light')
6766
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');
6970
</script>
7071

72+
<input type="checkbox" id="sidebar-toggle-anchor" class="hidden">
73+
7174
<!-- Hide / unhide sidebar before it is displayed -->
7275
<script>
73-
var html = document.querySelector('html');
76+
var body = document.querySelector('body');
7477
var sidebar = null;
78+
var sidebar_toggle = document.getElementById("sidebar-toggle-anchor");
7579
if (document.body.clientWidth >= 1080) {
7680
try { sidebar = localStorage.getItem('mdbook-sidebar'); } catch(e) { }
7781
sidebar = sidebar || 'visible';
7882
} else {
7983
sidebar = 'hidden';
8084
}
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);
8388
</script>
8489

8590
<nav id="sidebar" class="sidebar" aria-label="Table of contents">
8691
<div class="sidebar-scrollbox">
8792
<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>
8893
</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>
9097
</nav>
9198

9299
<!-- Track and set sidebar scroll position -->
@@ -117,9 +124,9 @@
117124
<div id="menu-bar-hover-placeholder"></div>
118125
<div id="menu-bar" class="menu-bar sticky">
119126
<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">
121128
<i class="fa fa-bars"></i>
122-
</button>
129+
</label>
123130
<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">
124131
<i class="fa fa-paint-brush"></i>
125132
</button>
@@ -168,7 +175,7 @@ <h1 class="menu-title">Create Your Own Programming Language with Rust</h1>
168175
<div id="content" class="content">
169176
<main>
170177
<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>&quot;-1&quot;</code> or <code>&quot;1 + 2&quot;</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>&quot;-1&quot;</code> and <code>&quot;1 + 2&quot;</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>
172179
<p align="center">
173180
</br>
174181
<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-
201208
</code></pre>
202209
</li>
203210
</ul>
204-
<p>So for example, the expression <code>&quot;-1 + (2 + 3)&quot;</code> has this recursive structure</p>
211+
<p>So for example, the expression <code>"-1 + (2 + 3)"</code> has this recursive structure</p>
205212
<p align="center">
206213
</br>
207214
<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>
274281
fn from_ast(ast: Vec&lt;Node&gt;) -&gt; Self::Output;
275282

276283
fn from_source(source: &amp;str) -&gt; Self::Output {
277-
println!(&quot;Compiling the source: {}&quot;, source);
284+
println!("Compiling the source: {}", source);
278285
let ast: Vec&lt;Node&gt; = parser::parse(source).unwrap();
279-
println!(&quot;{:?}&quot;, ast);
286+
println!("{:?}", ast);
280287
Self::from_ast(ast)
281288
}
282289
}</code></pre>
@@ -297,7 +304,7 @@ <h2 id="interpreter"><a class="header" href="#interpreter">Interpreter</a></h2>
297304
}</code></pre>
298305
<p><span class="filename">Filename: calculator/src/compiler/interpreter.rs</span></p>
299306
<p>and test</p>
300-
<pre><code class="language-rust ignore">assert_eq!(Interpreter::from_source(&quot;1 + 2&quot;).unwrap(), 3);</code></pre>
307+
<pre><code class="language-rust ignore">assert_eq!(Interpreter::from_source("1 + 2").unwrap(), 3);</code></pre>
301308
<p>Run such tests locally with</p>
302309
<pre><code class="language-text">cargo test interpreter --tests
303310
</code></pre>
@@ -310,7 +317,7 @@ <h2 id="interpreter"><a class="header" href="#interpreter">Interpreter</a></h2>
310317
<i class="fa fa-angle-left"></i>
311318
</a>
312319

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">
314321
<i class="fa fa-angle-right"></i>
315322
</a>
316323

@@ -324,7 +331,7 @@ <h2 id="interpreter"><a class="header" href="#interpreter">Interpreter</a></h2>
324331
<i class="fa fa-angle-left"></i>
325332
</a>
326333

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">
328335
<i class="fa fa-angle-right"></i>
329336
</a>
330337
</nav>

0 commit comments

Comments
 (0)