Skip to content

Commit da1d0c3

Browse files
committed
deploy: 7b01c38
1 parent 644086a commit da1d0c3

69 files changed

Lines changed: 9611 additions & 5427 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

01_calculator/ast.html

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717
<link rel="stylesheet" href="../css/variables.css">
1818
<link rel="stylesheet" href="../css/general.css">
1919
<link rel="stylesheet" href="../css/chrome.css">
20-
<link rel="stylesheet" href="../css/print.css" media="print">
2120

2221
<!-- Fonts -->
2322
<link rel="stylesheet" href="../FontAwesome/css/font-awesome.css">
@@ -145,9 +144,6 @@ <h2 class="mdbook-help-title">Keyboard shortcuts</h2>
145144
<h1 class="menu-title">Create Your Own Programming Language with Rust</h1>
146145

147146
<div class="right-buttons">
148-
<a href="../print.html" title="Print this book" aria-label="Print this book">
149-
<i id="print-button" class="fa fa-print"></i>
150-
</a>
151147
<a href="https://github.com/ehsanmok/create-your-own-lang-with-rust" title="Git repository" aria-label="Git repository">
152148
<i id="git-repository-button" class="fa fa-github"></i>
153149
</a>
@@ -183,6 +179,9 @@ <h1 class="menu-title">Create Your Own Programming Language with Rust</h1>
183179
<div id="content" class="content">
184180
<main>
185181
<h2 id="abstract-syntax-tree-ast"><a class="header" href="#abstract-syntax-tree-ast">Abstract Syntax Tree (AST)</a></h2>
182+
<blockquote>
183+
<p>Think of source code as a <em>sentence</em> and the AST as its <em>diagram</em>. Just like “The cat sat on the mat” can be diagrammed into subject/verb/object, <code>1 + 2</code> can be diagrammed into left/operator/right. The AST is that diagram - it captures <em>structure</em>, not just text.</p>
184+
</blockquote>
186185
<p>AST comes into the 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 (that’s what the grammar ensures), we can use the structure within the expressions <code>"-1"</code> and <code>"1 + 2"</code> to our advantage and come up with a <em>new representation</em> like a <a href="https://en.wikipedia.org/wiki/Tree_structure">tree</a>:</p>
187186
<p align="center">
188187
</br>
@@ -318,6 +317,24 @@ <h2 id="interpreter"><a class="header" href="#interpreter">Interpreter</a></h2>
318317
<p>Run such tests locally with</p>
319318
<pre><code class="language-bash">cargo test interpreter --tests
320319
</code></pre>
320+
<div class="checkpoint">
321+
<strong>Checkpoint</strong>
322+
<p>At this point, you should be able to:</p>
323+
<ul>
324+
<li>Parse <code>1 + 2</code> and build an AST with a <code>Binary</code> node</li>
325+
<li>Evaluate <code>1 + 2 - 3</code> and get <code>0</code></li>
326+
<li>Handle nested expressions like <code>-1 + (2 + 3)</code></li>
327+
</ul>
328+
</div>
329+
<div class="related-topics">
330+
<strong>Related Topics</strong>
331+
<ul>
332+
<li><a href="./grammar_lexer_parser.html">Grammar and Parser</a> - How input becomes tokens</li>
333+
<li><a href="./jit_intro.html">JIT Compilation</a> - Compile AST to machine code</li>
334+
<li><a href="./vm.html">Virtual Machine</a> - Compile AST to bytecode</li>
335+
<li><a href="../02_firstlang/functions.html">Firstlang AST</a> - AST for a full language</li>
336+
</ul>
337+
</div>
321338

322339
</main>
323340

01_calculator/ast_traversal.html

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717
<link rel="stylesheet" href="../css/variables.css">
1818
<link rel="stylesheet" href="../css/general.css">
1919
<link rel="stylesheet" href="../css/chrome.css">
20-
<link rel="stylesheet" href="../css/print.css" media="print">
2120

2221
<!-- Fonts -->
2322
<link rel="stylesheet" href="../FontAwesome/css/font-awesome.css">
@@ -145,9 +144,6 @@ <h2 class="mdbook-help-title">Keyboard shortcuts</h2>
145144
<h1 class="menu-title">Create Your Own Programming Language with Rust</h1>
146145

147146
<div class="right-buttons">
148-
<a href="../print.html" title="Print this book" aria-label="Print this book">
149-
<i id="print-button" class="fa fa-print"></i>
150-
</a>
151147
<a href="https://github.com/ehsanmok/create-your-own-lang-with-rust" title="Git repository" aria-label="Git repository">
152148
<i id="git-repository-button" class="fa fa-github"></i>
153149
</a>

01_calculator/basic_llvm.html

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717
<link rel="stylesheet" href="../css/variables.css">
1818
<link rel="stylesheet" href="../css/general.css">
1919
<link rel="stylesheet" href="../css/chrome.css">
20-
<link rel="stylesheet" href="../css/print.css" media="print">
2120

2221
<!-- Fonts -->
2322
<link rel="stylesheet" href="../FontAwesome/css/font-awesome.css">
@@ -145,9 +144,6 @@ <h2 class="mdbook-help-title">Keyboard shortcuts</h2>
145144
<h1 class="menu-title">Create Your Own Programming Language with Rust</h1>
146145

147146
<div class="right-buttons">
148-
<a href="../print.html" title="Print this book" aria-label="Print this book">
149-
<i id="print-button" class="fa fa-print"></i>
150-
</a>
151147
<a href="https://github.com/ehsanmok/create-your-own-lang-with-rust" title="Git repository" aria-label="Git repository">
152148
<i id="git-repository-button" class="fa fa-github"></i>
153149
</a>
@@ -234,6 +230,23 @@ <h3 id="add-function"><a class="header" href="#add-function">Add Function</a></h
234230
assert_eq!(add.call(x, y), x + y);
235231
}</code></pre>
236232
<p>Yes! all of this just to add two integers.</p>
233+
<div class="checkpoint">
234+
<strong>Checkpoint</strong>
235+
<p>At this point, you should be able to:</p>
236+
<ul>
237+
<li>Run the LLVM example with <code>rustup run nightly cargo run</code></li>
238+
<li>See the JIT execute and return <code>3</code> (for <code>1 + 2</code>)</li>
239+
<li>Understand the context → module → function → basic block hierarchy</li>
240+
</ul>
241+
</div>
242+
<div class="related-topics">
243+
<strong>Related Topics</strong>
244+
<ul>
245+
<li><a href="./ast_traversal.html">AST Traversal Patterns</a> - Compile full AST to LLVM</li>
246+
<li><a href="../03_secondlang/ir.html">LLVM IR Basics</a> - Understanding LLVM IR syntax</li>
247+
<li><a href="../03_secondlang/codegen.html">Secondlang Codegen</a> - Full compiler to LLVM</li>
248+
</ul>
249+
</div>
237250

238251
</main>
239252

01_calculator/calc_intro.html

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717
<link rel="stylesheet" href="../css/variables.css">
1818
<link rel="stylesheet" href="../css/general.css">
1919
<link rel="stylesheet" href="../css/chrome.css">
20-
<link rel="stylesheet" href="../css/print.css" media="print">
2120

2221
<!-- Fonts -->
2322
<link rel="stylesheet" href="../FontAwesome/css/font-awesome.css">
@@ -145,9 +144,6 @@ <h2 class="mdbook-help-title">Keyboard shortcuts</h2>
145144
<h1 class="menu-title">Create Your Own Programming Language with Rust</h1>
146145

147146
<div class="right-buttons">
148-
<a href="../print.html" title="Print this book" aria-label="Print this book">
149-
<i id="print-button" class="fa fa-print"></i>
150-
</a>
151147
<a href="https://github.com/ehsanmok/create-your-own-lang-with-rust" title="Git repository" aria-label="Git repository">
152148
<i id="git-repository-button" class="fa fa-github"></i>
153149
</a>

0 commit comments

Comments
 (0)