Home Explore Blog CI



rustc

1st chunk of `src/syntax-intro.md`
6bfe733309759fa3d798eb83584e27faf0d91ef580691bef00000001000002ce
# Syntax and the AST

Working directly with source code is very inconvenient and error-prone.
Thus, before we do anything else, we convert raw source code into an
[Abstract Syntax Tree (AST)][AST]. It turns out that doing this involves a lot of work,
including [lexing, parsing], [macro expansion], [name resolution], conditional
compilation, [feature-gate checking], and [validation] of the [AST].
In this chapter, we take a look at all of these steps.

Notably, there isn't always a clean ordering between these tasks.
For example, macro expansion relies on name resolution to resolve the names of macros and imports.
And parsing requires macro expansion, which in turn may require parsing the output of the macro.


Title: Syntax and Abstract Syntax Tree (AST) Conversion
Summary
Working with raw source code is inconvenient, so it's converted into an Abstract Syntax Tree (AST) through a series of steps including lexing, parsing, macro expansion, name resolution, conditional compilation, feature-gate checking, and AST validation. These tasks aren't always cleanly ordered and can be interdependent.