{"id":281683,"date":"2026-06-21T21:20:54","date_gmt":"2026-06-21T21:20:54","guid":{"rendered":"https:\/\/ushopwell.com\/ublog\/how-do-compilers-work-lets-invent-a-programming-language-to-find-out\/"},"modified":"2026-06-21T21:20:54","modified_gmt":"2026-06-21T21:20:54","slug":"how-do-compilers-work-lets-invent-a-programming-language-to-find-out","status":"publish","type":"post","link":"https:\/\/ushopwell.com\/ublog\/how-do-compilers-work-lets-invent-a-programming-language-to-find-out\/","title":{"rendered":"How do compilers work? Let\u2019s invent a programming language to find out"},"content":{"rendered":"<div class=\"youtubomatic-video-container\"><iframe loading=\"lazy\" width=\"580\" height=\"380\" src=\"https:\/\/www.youtube.com\/embed\/awsH0iq0O1A?autoplay=1&#038;controls=1&#038;hl=en\" frameborder=\"0\" allowfullscreen><\/iframe><\/div>\n<p>Before code can run, a computer has to somehow turn human-readable text into instructions it can execute.<\/p>\n<p>So in this video, we do exactly that from scratch. We invent a tiny programming language, write a compiler for it, and build a virtual machine that can actually run the programs we write.<\/p>\n<p>You do not need to be an expert to follow along. The goal of this video is to make programming languages feel less mysterious by building one piece by piece, slowly and visually. If you have never written code before, you can watch this as a guided tour of how computers understand instructions. If you are technical, you will get a practical walkthrough of lexing, parsing, abstract syntax trees, bytecode, stack machines, function calls, local variables, and control flow.<\/p>\n<p>A full table of contents is below, but at a high level we cover<br \/>\n1. What programming languages really are<br \/>\n2. How source code becomes tokens<br \/>\n3. How parsers turn text into structure<br \/>\n4. How math expressions, variables, and conditionals work<br \/>\n5. How functions are represented and executed<br \/>\n6. How compilers generate lower-level instructions<br \/>\n7. How a stack-based virtual machine runs code<br \/>\n8. Why computers do not \u201cunderstand\u201d code the way humans do<\/p>\n<p>All the code written in this video: <a href=\"https:\/\/github.com\/milen-patel\/tinylang\" target=\"_blank\">https:\/\/github.com\/milen-patel\/tinylang<\/a><\/p>\n<p>Chapters:<br \/>\n00: 00: 00 &#8211; Introduction<br \/>\n00: 06: 20 &#8211; Basic Addition\/Subtraction and Formalizing Our Intuition<br \/>\n00: 11: 30 &#8211; Viewing Expressions as Trees<br \/>\n00: 25: 17 &#8211; Evaluating Expression Trees Starts at the Bottom and Works Upward<br \/>\n00: 26: 20 &#8211; Throwing Multiplication\/Division into the mix (remember PEMDAS?)<br \/>\n00: 29: 07 &#8211; How do we take a math expression and convert it to this new tree format<br \/>\n00: 33: 47 &#8211; Introduction to Context Free Grammars<br \/>\n00: 57: 32 &#8211; Formal Definition of a Context Free Grammar<br \/>\n01: 33: 48 &#8211; Simplifying Our Context Free Grammar for Math Expressions<br \/>\n01: 54: 40 &#8211; Real Programming Languages Have Context Free Grammars!<br \/>\n01: 58: 58 &#8211; A brief introduction to the Kotlin Programming Language<br \/>\n02: 23: 11 &#8211; Tokens, the building blocks of a programming language<br \/>\n02: 29: 07 &#8211; Splitting our input into tokens (Lexer Introduction)<br \/>\n02: 49: 28 &#8211; Testing our Lexer<br \/>\n03: 07: 26 &#8211; Commit 1 Checkpoint [Splitting an input program into tokens]<br \/>\n03: 08: 21 &#8211; How do we get our tokens into a tree (Parser)<br \/>\n03: 53: 50 &#8211; Testing our Parser<br \/>\n04: 29: 09 &#8211; Let\u2019s Invent a Language to Compile Into (TAM)<br \/>\n05: 06: 32 &#8211; Commit 3 Checkpoint [Taking an input programming, and visualizing it as a tree]<br \/>\n05: 06: 37 &#8211; Walking over the tree to translate a program<br \/>\n05: 29: 20 &#8211; Making Recursion a Bit More Visible<br \/>\n05: 38: 45 &#8211; Commit 4, we have a compiler!<br \/>\n05: 39: 00 &#8211; Simulating the Machine to Run Compiled Programs<br \/>\n05: 46: 26 &#8211; Adding support for variables into our language<br \/>\n06: 24: 19 &#8211; Updating our target language to support variables<br \/>\n06: 42: 29 &#8211; Commits 6+7 [Constants into the programming language]<br \/>\n06: 44: 50 &#8211; But wait, we can\u2019t update a variable<br \/>\n07: 07: 44 &#8211; Commit 8 [Making constants into variables]<br \/>\n07: 08: 15 &#8211; Comparison Operators (Less Than or Greater Than)<br \/>\n07: 33: 27 &#8211; Commit 8 [Add support for comparison of integers]<br \/>\n07: 33: 49 &#8211; If Statements and Conditional Logic<br \/>\n08: 11: 48-  Commit 9 [Support for condition if statement]<br \/>\n08: 12: 43 &#8211; A brief interlude on loops<br \/>\n08: 17: 14 &#8211; Introducing Functions to our Language<br \/>\n08: 35: 20 &#8211; Adding new instructions to the machine to support functions<br \/>\n08: 45: 09 &#8211; Updating the Context Free Grammar to Support Functions<br \/>\n08: 54: 40 &#8211; Start Implementing Functions<br \/>\n10: 15: 15 &#8211; Writing a function in our new language<br \/>\n10: 24: 08 &#8211; Commit 10 [Support Functions]<br \/>\n10: 24: 37 &#8211; We cheated on implementing functions, let\u2019s make it more realistic<br \/>\n10: 41: 59 &#8211; Function Patching<br \/>\n10: 58: 58 &#8211; Writing a programming that tests every feature of our language<br \/>\n11: 03: 56 &#8211; Visualizing Compilers and Programs<br \/>\n11: 22: 47 &#8211; An Apology to You<br \/>\n11: 24: 00 &#8211; Conclusion<br \/>\n11: 25: 26 &#8211; How to View the Code from this Video,<br \/>\n11: 28: 09 &#8211; Where I would go if I had more time<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Before code can run, a computer has to somehow turn human-readable text into instructions it can execute. So in this video, we do exactly that from scratch. We invent a tiny programming language, write a compiler for it, and build a virtual machine that can actually run the programs we write. You do not need to be an expert to follow along. The goal of this video is to make&#8230;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":"","tve_updated_post":"","tve_custom_css":"","tve_user_custom_css":"","tve_globals":{},"tcb2_ready":0,"tcb_editor_enabled":0,"tve_landing_page":"","_tve_header":"","_tve_footer":""},"categories":[1],"tags":[],"class_list":["post-281683","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v28.5 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>How do compilers work? Let\u2019s invent a programming language to find out - UshopWell.com<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/ushopwell.com\/ublog\/how-do-compilers-work-lets-invent-a-programming-language-to-find-out\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"How do compilers work? Let\u2019s invent a programming language to find out - UshopWell.com\" \/>\n<meta property=\"og:description\" content=\"Before code can run, a computer has to somehow turn human-readable text into instructions it can execute. So in this video, we do exactly that from scratch. We invent a tiny programming language, write a compiler for it, and build a virtual machine that can actually run the programs we write. You do not need to be an expert to follow along. The goal of this video is to make...\" \/>\n<meta property=\"og:url\" content=\"https:\/\/ushopwell.com\/ublog\/how-do-compilers-work-lets-invent-a-programming-language-to-find-out\/\" \/>\n<meta property=\"og:site_name\" content=\"UshopWell.com\" \/>\n<meta property=\"article:published_time\" content=\"2026-06-21T21:20:54+00:00\" \/>\n<meta name=\"author\" content=\"UShopWell\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"UShopWell\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"3 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/ushopwell.com\\\/ublog\\\/how-do-compilers-work-lets-invent-a-programming-language-to-find-out\\\/#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/ushopwell.com\\\/ublog\\\/how-do-compilers-work-lets-invent-a-programming-language-to-find-out\\\/\"},\"author\":{\"name\":\"UShopWell\",\"@id\":\"https:\\\/\\\/ushopwell.com\\\/ublog\\\/#\\\/schema\\\/person\\\/6fd1f9e0ff932e534c86c70d5acff0fc\"},\"headline\":\"How do compilers work? Let\u2019s invent a programming language to find out\",\"datePublished\":\"2026-06-21T21:20:54+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/ushopwell.com\\\/ublog\\\/how-do-compilers-work-lets-invent-a-programming-language-to-find-out\\\/\"},\"wordCount\":581,\"commentCount\":0,\"publisher\":{\"@id\":\"https:\\\/\\\/ushopwell.com\\\/ublog\\\/#organization\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\\\/\\\/ushopwell.com\\\/ublog\\\/how-do-compilers-work-lets-invent-a-programming-language-to-find-out\\\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/ushopwell.com\\\/ublog\\\/how-do-compilers-work-lets-invent-a-programming-language-to-find-out\\\/\",\"url\":\"https:\\\/\\\/ushopwell.com\\\/ublog\\\/how-do-compilers-work-lets-invent-a-programming-language-to-find-out\\\/\",\"name\":\"How do compilers work? Let\u2019s invent a programming language to find out - UshopWell.com\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/ushopwell.com\\\/ublog\\\/#website\"},\"datePublished\":\"2026-06-21T21:20:54+00:00\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/ushopwell.com\\\/ublog\\\/how-do-compilers-work-lets-invent-a-programming-language-to-find-out\\\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/ushopwell.com\\\/ublog\\\/how-do-compilers-work-lets-invent-a-programming-language-to-find-out\\\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/ushopwell.com\\\/ublog\\\/how-do-compilers-work-lets-invent-a-programming-language-to-find-out\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/ushopwell.com\\\/ublog\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"How do compilers work? Let\u2019s invent a programming language to find out\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/ushopwell.com\\\/ublog\\\/#website\",\"url\":\"https:\\\/\\\/ushopwell.com\\\/ublog\\\/\",\"name\":\"UshopWell.com\",\"description\":\"The Premiere Online Marketplace\",\"publisher\":{\"@id\":\"https:\\\/\\\/ushopwell.com\\\/ublog\\\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/ushopwell.com\\\/ublog\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\\\/\\\/ushopwell.com\\\/ublog\\\/#organization\",\"name\":\"UshopWell\",\"url\":\"https:\\\/\\\/ushopwell.com\\\/ublog\\\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/ushopwell.com\\\/ublog\\\/#\\\/schema\\\/logo\\\/image\\\/\",\"url\":\"https:\\\/\\\/ushopwell.com\\\/ublog\\\/wp-content\\\/uploads\\\/2018\\\/01\\\/pandaSwea.png\",\"contentUrl\":\"https:\\\/\\\/ushopwell.com\\\/ublog\\\/wp-content\\\/uploads\\\/2018\\\/01\\\/pandaSwea.png\",\"width\":365,\"height\":359,\"caption\":\"UshopWell\"},\"image\":{\"@id\":\"https:\\\/\\\/ushopwell.com\\\/ublog\\\/#\\\/schema\\\/logo\\\/image\\\/\"}},{\"@type\":\"Person\",\"@id\":\"https:\\\/\\\/ushopwell.com\\\/ublog\\\/#\\\/schema\\\/person\\\/6fd1f9e0ff932e534c86c70d5acff0fc\",\"name\":\"UShopWell\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/4adb372cadd43b4d4c57964dab95b0f69618bf960d131c4acf49d96d6bbc9c6e?s=96&d=mm&r=g\",\"url\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/4adb372cadd43b4d4c57964dab95b0f69618bf960d131c4acf49d96d6bbc9c6e?s=96&d=mm&r=g\",\"contentUrl\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/4adb372cadd43b4d4c57964dab95b0f69618bf960d131c4acf49d96d6bbc9c6e?s=96&d=mm&r=g\",\"caption\":\"UShopWell\"},\"url\":\"https:\\\/\\\/ushopwell.com\\\/ublog\\\/author\\\/kburnettu\\\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"How do compilers work? Let\u2019s invent a programming language to find out - UshopWell.com","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/ushopwell.com\/ublog\/how-do-compilers-work-lets-invent-a-programming-language-to-find-out\/","og_locale":"en_US","og_type":"article","og_title":"How do compilers work? Let\u2019s invent a programming language to find out - UshopWell.com","og_description":"Before code can run, a computer has to somehow turn human-readable text into instructions it can execute. So in this video, we do exactly that from scratch. We invent a tiny programming language, write a compiler for it, and build a virtual machine that can actually run the programs we write. You do not need to be an expert to follow along. The goal of this video is to make...","og_url":"https:\/\/ushopwell.com\/ublog\/how-do-compilers-work-lets-invent-a-programming-language-to-find-out\/","og_site_name":"UshopWell.com","article_published_time":"2026-06-21T21:20:54+00:00","author":"UShopWell","twitter_card":"summary_large_image","twitter_misc":{"Written by":"UShopWell","Est. reading time":"3 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/ushopwell.com\/ublog\/how-do-compilers-work-lets-invent-a-programming-language-to-find-out\/#article","isPartOf":{"@id":"https:\/\/ushopwell.com\/ublog\/how-do-compilers-work-lets-invent-a-programming-language-to-find-out\/"},"author":{"name":"UShopWell","@id":"https:\/\/ushopwell.com\/ublog\/#\/schema\/person\/6fd1f9e0ff932e534c86c70d5acff0fc"},"headline":"How do compilers work? Let\u2019s invent a programming language to find out","datePublished":"2026-06-21T21:20:54+00:00","mainEntityOfPage":{"@id":"https:\/\/ushopwell.com\/ublog\/how-do-compilers-work-lets-invent-a-programming-language-to-find-out\/"},"wordCount":581,"commentCount":0,"publisher":{"@id":"https:\/\/ushopwell.com\/ublog\/#organization"},"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/ushopwell.com\/ublog\/how-do-compilers-work-lets-invent-a-programming-language-to-find-out\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/ushopwell.com\/ublog\/how-do-compilers-work-lets-invent-a-programming-language-to-find-out\/","url":"https:\/\/ushopwell.com\/ublog\/how-do-compilers-work-lets-invent-a-programming-language-to-find-out\/","name":"How do compilers work? Let\u2019s invent a programming language to find out - UshopWell.com","isPartOf":{"@id":"https:\/\/ushopwell.com\/ublog\/#website"},"datePublished":"2026-06-21T21:20:54+00:00","breadcrumb":{"@id":"https:\/\/ushopwell.com\/ublog\/how-do-compilers-work-lets-invent-a-programming-language-to-find-out\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/ushopwell.com\/ublog\/how-do-compilers-work-lets-invent-a-programming-language-to-find-out\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/ushopwell.com\/ublog\/how-do-compilers-work-lets-invent-a-programming-language-to-find-out\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/ushopwell.com\/ublog\/"},{"@type":"ListItem","position":2,"name":"How do compilers work? Let\u2019s invent a programming language to find out"}]},{"@type":"WebSite","@id":"https:\/\/ushopwell.com\/ublog\/#website","url":"https:\/\/ushopwell.com\/ublog\/","name":"UshopWell.com","description":"The Premiere Online Marketplace","publisher":{"@id":"https:\/\/ushopwell.com\/ublog\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/ushopwell.com\/ublog\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/ushopwell.com\/ublog\/#organization","name":"UshopWell","url":"https:\/\/ushopwell.com\/ublog\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/ushopwell.com\/ublog\/#\/schema\/logo\/image\/","url":"https:\/\/ushopwell.com\/ublog\/wp-content\/uploads\/2018\/01\/pandaSwea.png","contentUrl":"https:\/\/ushopwell.com\/ublog\/wp-content\/uploads\/2018\/01\/pandaSwea.png","width":365,"height":359,"caption":"UshopWell"},"image":{"@id":"https:\/\/ushopwell.com\/ublog\/#\/schema\/logo\/image\/"}},{"@type":"Person","@id":"https:\/\/ushopwell.com\/ublog\/#\/schema\/person\/6fd1f9e0ff932e534c86c70d5acff0fc","name":"UShopWell","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/secure.gravatar.com\/avatar\/4adb372cadd43b4d4c57964dab95b0f69618bf960d131c4acf49d96d6bbc9c6e?s=96&d=mm&r=g","url":"https:\/\/secure.gravatar.com\/avatar\/4adb372cadd43b4d4c57964dab95b0f69618bf960d131c4acf49d96d6bbc9c6e?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/4adb372cadd43b4d4c57964dab95b0f69618bf960d131c4acf49d96d6bbc9c6e?s=96&d=mm&r=g","caption":"UShopWell"},"url":"https:\/\/ushopwell.com\/ublog\/author\/kburnettu\/"}]}},"_links":{"self":[{"href":"https:\/\/ushopwell.com\/ublog\/wp-json\/wp\/v2\/posts\/281683","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/ushopwell.com\/ublog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/ushopwell.com\/ublog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/ushopwell.com\/ublog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/ushopwell.com\/ublog\/wp-json\/wp\/v2\/comments?post=281683"}],"version-history":[{"count":0,"href":"https:\/\/ushopwell.com\/ublog\/wp-json\/wp\/v2\/posts\/281683\/revisions"}],"wp:attachment":[{"href":"https:\/\/ushopwell.com\/ublog\/wp-json\/wp\/v2\/media?parent=281683"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/ushopwell.com\/ublog\/wp-json\/wp\/v2\/categories?post=281683"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/ushopwell.com\/ublog\/wp-json\/wp\/v2\/tags?post=281683"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}