Writing Your First Compiler - Part 7: Taking Stock
dev.to·9h·
Discuss: DEV
Flag this post

We’ve built a complete compiler frontend. Source code becomes tokens, tokens become an abstract syntax tree. Before we jump into code generation, let’s take a moment to understand what we actually have.

What We Built

Look at the pipeline we’ve constructed:

  1. Lexer (lexer.py) - Turns source code into tokens
  2. AST Nodes (abstract.py) - Defines the tree structure
  3. Parser (parser.py) - Turns tokens into an AST

A complete frontend. We can take YFC source code and produce a structured representation of what it means.

The language itself:

  • Functions - named chunks of code with parameters
  • Conditionals - if/else expressions for branching
  • Recursion - functions that call themselves
  • Arithmetic - +, -, *, /
  • Comparison - <,…

Similar Posts

Loading similar posts...