You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: index.html
+72-57Lines changed: 72 additions & 57 deletions
Original file line number
Diff line number
Diff line change
@@ -181,50 +181,61 @@ <h1 class="menu-title">Create Your Own Programming Language with Rust</h1>
181
181
<divclass="license-notice">
182
182
<p><em>Materials in this book are distributed under the terms of <ahref="https://github.com/ehsanmok/create-your-own-lang-with-rust/blob/master/LICENSE">Creative Commons BY-NC-SA 4.0</a></em></p>
<p>This book assumes some basic knowledge of the Rust language. Please take a look at the official <ahref="https://doc.rust-lang.org/book/">Rust book</a>.</p>
186
-
<p>The accompanying code and materials for this book are available on <ahref="https://github.com/ehsanmok/create-your-own-lang-with-rust">GitHub</a>. To follow along, make sure you have</p>
<p>This book assumes basic knowledge of Rust. If you’re new to Rust, start with the official <ahref="https://doc.rust-lang.org/book/">Rust book</a>.</p>
193
+
<p>The code and materials are available on <ahref="https://github.com/ehsanmok/create-your-own-lang-with-rust">GitHub</a>. To follow along:</p>
194
+
<pre><codeclass="language-bash"># Clone the repository
<h2id="motivations-and-goals"><aclass="header" href="#motivations-and-goals">Motivations and Goals</a></h2>
219
230
<p>This book arises from my frustration of not finding modern, clear, and concise teaching materials that are readily accessible to beginners like me who want to learn how to create their own programming language.</p>
220
-
<p>The following are my guidelines:</p>
221
231
<blockquote>
222
-
<p>“If you don’t know how <em>compilers</em> work, then you don’t know how computers work” <sup><ahref="http://steve-yegge.blogspot.com/2007/06/rich-programmer-food.html?">1</a></sup></p>
232
+
<p><em>“If you don’t know how compilers work, then you don’t know how computers work”</em><sup><ahref="http://steve-yegge.blogspot.com/2007/06/rich-programmer-food.html">1</a></sup></p>
223
233
</blockquote>
224
234
<blockquote>
225
-
<p>“If you can’t explain something in simple terms, you don’t understand it” <sup><ahref="https://skeptics.stackexchange.com/questions/8742/did-einstein-say-if-you-cant-explain-it-simply-you-dont-understand-it-well-en">2</a></sup></p>
235
+
<p><em>“If you can’t explain something in simple terms, you don’t understand it”</em><sup><ahref="https://skeptics.stackexchange.com/questions/8742/did-einstein-say-if-you-cant-explain-it-simply-you-dont-understand-it-well-en">2</a></sup></p>
226
236
</blockquote>
227
-
<p><spanstyle="font-family:Trebuchet MS">Pedagogically, one of the most effective methods of teaching is co-creating interactively. Introducing the core aspects around the <em>simplest example</em> (here, our calculator language) helps a lot to build knowledge and confidence. For that, we will use mature technologies instead of spending tons of time partially reinventing the wheel and boring the reader.</span></p>
237
+
<p><spanstyle="font-family:Trebuchet MS">Pedagogically, one of the most effective methods of teaching is co-creating interactively. Introducing the core aspects around the <em>simplest example</em> (here, our calculator language) helps build knowledge and confidence. We use mature technologies instead of reinventing the wheel.</span></p>
@@ -241,58 +252,62 @@ <h3 id="part-i-calculator"><a class="header" href="#part-i-calculator">Part I: C
241
252
Term = _{Int | "(" ~ Expr ~ ")" }
242
253
...
243
254
</code></pre>
244
-
<p>This minimal language lets us focus on the fundamentals without distraction: what is a grammar? How does pest generate a parser? What is an AST? We also explore <em>three different backends</em> (interpreter, bytecode VM, JIT) to show that the same AST can be executed in multiple ways.</p>
255
+
<p>This minimal language lets us focus on the fundamentals: what is a grammar? How does pest generate a parser? What is an AST? We explore <em>three different backends</em> (interpreter, bytecode VM, JIT) to show that the same AST can be executed in multiple ways.</p>
<p>We focus on a single backend (tree-walking interpreter) to deeply understand scoping, call stacks, and recursion. The culminating example is computing Fibonacci recursively.</p>
<p>We add <em>static types</em> and compile to native code. The grammar changes are minimal (just 7 more lines), but the compiler grows significantly:</p>
260
-
<pre><codeclass="language-text">// New: Type annotations
271
+
<pre><codeclass="language-text">// Type annotations
<p>This demonstrates a key insight: types are primarily a <em>semantic</em> addition, not a syntactic one. The grammar changes are small, but we need new compiler phases (type checking, type inference) and can now generate efficient native code via LLVM.</p>
279
+
<p>Types are primarily a <em>semantic</em> addition, not a syntactic one. The grammar changes are small, but we need new compiler phases (type checking, type inference) and can now generate efficient native code via LLVM.</p>
<p>This introduces heap allocation (<code>malloc</code>/<code>free</code>), struct types in LLVM, and the <code>self</code> parameter for methods. We see how OOP features map to lower-level constructs.</p>
<li><ahref="./crash_course.html">Crash Course on Computing</a> where we briefly set up definitions and foundations</li>
284
-
<li><ahref="./01_calculator/calc_intro.html"><strong>Calculator</strong></a>: Our first language supporting simple integer addition and subtraction. We use <ahref="https://en.wikipedia.org/wiki/Parsing_expression_grammar">PEG</a> to define our grammar, <ahref="https://pest.rs/">pest</a> to generate the parser, and explore AST interpretation, JIT compilation with <ahref="https://github.com/TheDan64/inkwell">inkwell</a>, and a bytecode VM</li>
285
-
<li><ahref="./02_firstlang/intro.html"><strong>Firstlang</strong></a>: An interpreted language with variables, functions, control flow, and recursion. We implement <ahref="./02_firstlang/fibonacci.html">Fibonacci</a> as the culminating example</li>
286
-
<li><ahref="./03_secondlang/intro.html"><strong>Secondlang</strong></a>: A statically typed language that compiles to native code via LLVM. We add <ahref="./03_secondlang/annotations.html">type annotations</a>, <ahref="./03_secondlang/inference.html">type inference</a>, AST <ahref="./03_secondlang/optimizations.html">optimization passes</a> with the visitor pattern, and <ahref="./03_secondlang/jit_fibonacci.html">JIT compilation</a></li>
287
-
<li><ahref="./04_thirdlang/intro.html"><strong>Thirdlang</strong></a>: An object-oriented language with <ahref="./04_thirdlang/classes_syntax.html">classes</a>, <ahref="./04_thirdlang/methods.html">methods</a>, <ahref="./04_thirdlang/constructors.html">constructors/destructors</a>, and <ahref="./04_thirdlang/memory.html">explicit memory management</a> via <code>new</code> and <code>delete</code></li>
<li><ahref="https://www.foodbankscanada.ca/">Food Bank of Canada</a></li>
295
+
<li><ahref="./crash_course.html">Crash Course on Computing</a> - definitions and foundations</li>
296
+
<li><ahref="./01_calculator/calc_intro.html"><strong>Calculator</strong></a> - integer arithmetic with PEG, pest, AST interpretation, JIT compilation, and bytecode VM</li>
297
+
<li><ahref="./02_firstlang/intro.html"><strong>Firstlang</strong></a> - variables, functions, control flow, recursion, culminating in <ahref="./02_firstlang/fibonacci.html">Fibonacci</a></li>
0 commit comments