Florian Rappl

Building a Compiler with C#

Stop treating compilers like a black box. Learn to build your own simple language and virtual machine from scratch using C#.

Building a Compiler with C#
#1about 4 minutes

Understanding Roslyn as a compiler-as-a-platform

Roslyn is not just a compiler black box but a full platform with APIs that provide language services to IDEs and inspired the Language Server Protocol.

#2about 2 minutes

Visualizing code structure with Roslyn and LINQPad

A practical demonstration in LINQPad shows how Roslyn can expose the intermediate language and abstract syntax tree for any C# code snippet.

#3about 4 minutes

Why build a custom language for game development

The "majors" language was created to meet the performance demands of a game that dynamically generated 3D worlds from user-provided mathematical formulas.

#4about 3 minutes

Defining a new language with a formal grammar

Creating a new language requires a formal specification and grammar that defines its syntax and rules, which serves as the blueprint for the compiler.

#5about 4 minutes

Comparing native and managed compiler architectures

Native compilers produce machine-specific object files, while managed compilers generate platform-independent intermediate language like MSIL or bytecode to be run by a virtual machine.

#6about 5 minutes

The four fundamental stages of compiler parsing

The compiler's front-end processes code through four stages: decoding the byte stream, tokenizing characters into blocks, generating an abstract syntax tree, and performing semantic analysis.

#7about 5 minutes

Representing code structure with an abstract syntax tree

The abstract syntax tree (AST) is a crucial data structure that represents code hierarchically, distinguishing between statements and expressions and enforcing operator precedence.

#8about 3 minutes

Traversing the abstract syntax tree with the visitor pattern

The Visitor design pattern provides a type-safe and extensible method for traversing an abstract syntax tree using a dedicated TreeWalker class for analysis or code generation.

#9about 3 minutes

A live demonstration of a custom language REPL

A live demo showcases the custom "majors" language REPL, including its support for function definitions, currying, and a built-in command for inspecting the AST.

#10about 3 minutes

Implementing operator precedence with Pratt parsing

The Pratt parsing technique simplifies handling operator precedence by using a hierarchy of recursive function calls that naturally builds the correct abstract syntax tree.

#11about 4 minutes

Transforming the AST into a linear intermediate language

The compiler flattens the hierarchical abstract syntax tree into a linear sequence of instructions, known as intermediate language, for efficient execution by a process virtual machine.

Related jobs
Jobs that call for the skills explored in this talk.

test

Milly
Vienna, Austria

Intermediate

test

Milly
Vienna, Austria

Intermediate

Featured Partners

Related Articles

View all articles
BB
Benedikt Bischof
How we Build The Software of Tomorrow
Welcome to this issue of the WeAreDevelopers Live Talk series. This article recaps an interesting talk by Thomas Dohmke who introduced us to the future of AI – coding.This is how Thomas describes himself:I am the CEO of GitHub and drive the company’s...
How we Build The Software of Tomorrow
CH
Chris Heilmann
WeAreDevelopers LIVE days are changing - get ready to take part
Starting with this week's Web Dev Day edition of WeAreDevelopers LIVE Days, we changed the the way we run these online conferences. The main differences are:Shorter talks (half an hour tops)More interaction in Q&AA tips and tricks "Did you know" sect...
WeAreDevelopers LIVE days are changing - get ready to take part

From learning to earning

Jobs that call for the skills explored in this talk.