> Markdown version of [/videos/116-building-a-compiler-with-c](https://www.wearedevelopers.com/videos/116-building-a-compiler-with-c). Every page supports `.md` or `Accept: text/markdown`. Links point to the HTML versions so they work for humans too. Agent guide: [/agents.md](https://www.wearedevelopers.com/agents.md). --- # Building a Compiler with C# When mathematically driven games hit processing limits, standard engines failed. Discover how building a custom C# expression compiler unlocked execution speeds two magnitudes faster. - **Speakers:** Florian Rappl - **Event:** WeAreDevelopers LIVE - **Published:** March 3, 2021 - **Duration:** 41:21 - **URL:** https://www.wearedevelopers.com/videos/116-building-a-compiler-with-c ## Summary Building a customized expression compiler in C# illustrates the mechanics of transforming raw syntax into highly optimized execution pipelines. When developers for mathematically driven game environments reached the processing constraints of typical Unity engines, building a custom mathematical parser enabled execution speeds two magnitudes faster. Designing a lightweight language requires breaking compilation down into specialized stages: stream processing decodes raw bytes into mapped characters, tokenization groups these characters into discrete syntax blocks without applying meaning, and finally, abstract syntax tree (AST) generation enforces syntax constraints and builds structural representation. Microsoft’s Roslyn framework pioneered the model of exposing these compilation phases as flexible APIs, effectively opening the compiler's black box. This architectural shift from a closed loop to an open language service not only powered advanced IDE refactoring but directly laid the groundwork for ubiquitous tooling like the Language Server Protocol (LSP). Within bespoke parsing engines, managing statement flows and expression calculations requires robust architecture. Implementing the classic Visitor design pattern ensures that tree traversal and analysis logic remain entirely detached from individual AST node implementations, heavily reducing maintenance overhead as custom keywords and rules expand. A core performance insight in compiler design is that directly evaluating code against a hierarchical AST creates extreme processing drag. Instead, traversing the parsed tree should result in returning the code to a "linear again" format—an intermediate language (IL) tailored for a process-level virtual machine. Furthermore, developers can bypass the notoriously complex bookkeeping involved in mathematical operator precedence by utilizing Pratt parsing. This recursive, stack-based approach gracefully delegates hierarchy climbing to the application's runtime logic, allowing the deepest nested operations to organically rise to the top of the execution tree. **Keywords:** c# compiler configuration, roslyn compiler platform, abstract syntax tree, language server protocol, pratt parsing pattern, visitor design pattern, intermediate language output, process virtual machines, stream processing decoders, source code tokenization, operator precedence logic, syntax tree traversal, mathematical expression parsing, game engine performance tuning ## Chapters 1. **Evolution of custom compilers and virtual machines** (00:17) — Iterative architectural development allows compiler and virtual machine bases to achieve high code readability. 1. **Exposing compiler APIs with the Roslyn platform** (02:09) — Providing language services directly from the compiler engine enables deep syntax integration inside advanced IDEs. 1. **Transpiling target code into intermediate language sequences** (06:26) — Directly converting source expressions into intermediate language visualizes the structural translation logic applied by core runtime environments. 1. **Accelerating dynamic mathematical expression parsing inside games** (08:19) — Evaluating complex formulas within restricted game loop states requires dedicated expression parsers optimized for extreme execution speeds. 1. **Formalizing grammar rules for new programming languages** (12:32) — Defining strict syntax boundaries identifies exactly how incoming text inputs should map into valid language implementations. 1. **Navigating the traditional source code compilation pipeline** (15:30) — Transforming high-level code into executable binaries involves staged analysis formats that separate frontend concepts from target machine instructions. 1. **Decoding character streams into parseable syntax blocks** (19:31) — Normalizing continuous byte inputs into tokenized keyword definitions produces the minimal distinct fragments necessary for semantic evaluation. 1. **Structuring interpreted execution order with syntax trees** (24:22) — Transforming isolated tokens into hierarchical trees organizes nested expressions and discrete statements correctly according to mathematical precedence. 1. **Traversing syntax trees safely with visitor patterns** (29:47) — Applying standardized tree walking behaviors simplifies extending node investigations without breaking unhandled structural expression variations. 1. **Inspecting live node hierarchies via customized terminal REPLs** (32:26) — Typing uncompiled commands directly into iterative console interfaces provides immediate feedback regarding function assignments and parsed runtime blocks. 1. **Managing complex operation sequence weights using recursive parsing** (35:12) — Wrapping grouped operators inside separate nested functions allows the unrolling call stack to naturally process and sequence precedence logic. 1. **Generating linear evaluation outputs for process virtual machines** (37:49) — Converting deeply nested syntax structures back into flattened instruction streams readies logic blocks for isolated and stable interpreter execution. ## Related Moments - [Understanding the basics of .NET source generators](https://www.wearedevelopers.com/videos/100154-code-that-writes-code-net-source-generators) (from "Code that writes code - .NET Source generators") - [Managing compilation performance and implementation specifics of advanced typing](https://www.wearedevelopers.com/videos/455-where-we-re-going-we-don-t-need-javascript-programming-with-type-annotations) (from "Where we're going we don't need JavaScript - Programming with Type Annotations") - [Overview of C# source generators and compilation pipeline](https://www.wearedevelopers.com/videos/192-c-9-source-generators-let-the-machine-do-the-programming) (from "C# 9 Source Generators - let the machine do the programming") - [Improving performance with advanced compiled language tooling](https://www.wearedevelopers.com/videos/404-to-new-frontiers-the-future-of-frontend-development) (from "To New Frontiers: The Future of Frontend Development") - [Abstractions and the push towards compiling natural language](https://www.wearedevelopers.com/videos/1909-wearedevelopers-live-back-to-code100) (from "WeAreDevelopers LIVE - Back to CODE100") - [Understanding the purpose of compiler lowering in C#](https://www.wearedevelopers.com/videos/1548-c-lowering-what-is-it-and-why-should-i-care) (from "C# Lowering - What is it and why should I care?") ## Related Articles - [MLOps And AI Driven Development](https://www.wearedevelopers.com/magazine/82-mlops-and-ai-driven-development) - [Liuba Gonta and Yuliya Khadasevic - GitHub Copilot Beyond the Basics - 10 Ways to Elevate Your Coding](https://www.wearedevelopers.com/magazine/490-liuba-gonta-and-yuliya-khadasevic-github-copilot-beyond-the-basics-10-ways-to-elevate-your-coding) - [Using Java 17 latest features in real world projects](https://www.wearedevelopers.com/magazine/121-using-java-17-latest-features-in-real-world-projects) - [Dev Digest 138 - Are you secure about this?](https://www.wearedevelopers.com/magazine/486-dev-digest-138-are-you-secure-about-this) ## Related Jobs - [Senior Software Engineer](https://www.wearedevelopers.com/jobs/ext/15942-senior-software-engineer) at **GitHub** - [Principal Software Engineer, Enterprise AI Platform](https://www.wearedevelopers.com/jobs/ext/1467292-principal-software-engineer-enterprise-ai-platform) at **GitHub** - [Staff Software Engineer, Copilot Experiences](https://www.wearedevelopers.com/jobs/ext/164361-staff-software-engineer-copilot-experiences) at **GitHub** - [Senior Software Engineer, Client Apps Platform](https://www.wearedevelopers.com/jobs/ext/1773893-senior-software-engineer-client-apps-platform) at **GitHub** - [Machine Learning Engineer](https://www.wearedevelopers.com/jobs/ext/1597388-machine-learning-engineer) at **ZEISS Group** - [Senior Software Engineer, Enterprise Products](https://www.wearedevelopers.com/jobs/ext/1841248-senior-software-engineer-enterprise-products) at **GitHub**