2. Kaleidoscope: Implementing a Parser and AST — LLVM 20.0.0git documentation
Welcome to Chapter 2 of the “Implementing a language with LLVM” tutorial. This chapter shows you how to use the lexer, built in Chapter 1, to build a full parser for our Kaleidoscope language. Once we have a parser, we’ll define and build an Abstract Syntax Tree (AST). The parser we will build uses a combination of Recursive Descent Parsing and Operator-Precedence Parsing to parse the Kaleidoscope language (the latter for binary expressions and the former for everything else). Before we get to parsing though, let’s talk about the output of the parser: the Abstract Syntax Tree. The AST for a program captures its behavior in such a way that it is easy for later stages of the compiler (e.g. code generation) to interpret. We basically want one object for each construct in the language, and the AST should closely model the language. In Kaleidoscope, we have expressions, a prototype, and a function object. We’ll start with expressions first: The code above shows the definition of the base Ex
2. Kaleidoscope: Implementing a Parser and AST — LLVM 23.0.0git documentation Navigation index next | previous | LLVM Home | Documentation >> Getting Started/Tutorials » LLVM Tutorial: Table of Contents » My First Language Frontend with LLVM Tutorial » 2. Kaleidoscope: Implementing a Parser and AST Documentation Getting Started/Tutorials User Guides Reference Getting Involved Contributing to LLVM Submitting Bug Reports Mailing Lists Discord Meetups and Social Events Additional Links FAQ Glossary Publications Github Repository This Page Show Source Quick search 2. Kaleidosc
Explore this link on the map →saved by
related reading
- 1. Kaleidoscope: Kaleidoscope Introduction and the Lexer — LLVM 23.0.0git documentationllvm.org
- 9. Kaleidoscope: Adding Debug Information — LLVM 23.0.0git documentationllvm.org
- A Gentle Introduction to LLVM IR · mcyoungmcyoung.xyz
- Parsing Expressions · Crafting Interpreterscraftinginterpreters.com
- Laurence Tratt: Which Parsing Approach?tratt.net
- Reading 12: Regular Expressions & Grammarsweb.mit.edu
- Reading 19: Parsersweb.mit.edu
- Pratt Parsers: Expression Parsing Made Easy - journal.stuffwithstuff.comjournal.stuffwithstuff.com
- Abstract syntax tree - Wikipediaen.wikipedia.org
- Representing Code · Crafting Interpreterscraftinginterpreters.com
- Shunting yard algorithm - Wikipediaen.wikipedia.org
- Problem Set 3: Memelyweb.mit.edu