Module parser
Expand description
The parser module parses the stream of tokens produced by the lexer and produces an AST of the C code.
We use a recursive descent parser except when parsing binary operations, where we use precedence climbing instead. The parser performs identifier resolution. This allows us to solve the “typedef-name: identifier” ambiguity problem.
Modules§
- printer
- The
printermodule is used by the parent parser module to print a tree of the C AST to stdout.
Structs§
- AstBasic
Type - The basic type of a declaration.
- AstBlock
- A block is a list of statements and declarations wrapped in braces. A function’s body and a compound statement are both blocks.
- AstDeclarator
- A parsed declarator.
- AstDeclared
Type - An
AstDeclaredTyperepresents a parsed type declaration which is not yet resolved to its canonicalAstType. - AstExpression
- An expression.
- AstExpression
Flags - Metadata flags associated with an
AstExpression. - AstFunction
- A function declaration with optional definition.
- AstIdentifier
- An identifier is a user-defined name for variables, functions, enums, etc.
- AstMetadata
- AST metadata produced by the parser.
- AstNode
Id - A unique numerical identifier for a node in the AST. Identifiers start from 1.
- AstRoot
- The root of the AST, representing the file scope of the translation unit.
- AstStorage
Class Specifier - A storage class specifier in a declaration.
- AstType
Alias Declaration - A
typedefdeclaration. - AstUnique
Name - A unique string name for a variable, function, or type alias identifier.
- AstVariable
Declaration - A variable declaration with optional definition.
- Parse
Error - An error type signaling a parse error. The error is emitted to the compiler driver’s diagnostics.
- Parser
- The parser interprets tokens produced by the lexer to generate an abstract syntax tree.
Enums§
- AstAddress
Constant - An address constant is a null pointer, a pointer to an object of static storage duration, or a pointer to a function designator. A string literal has static storage duration so its address can be used as an address constant.
- AstAssignment
Op - Assignment operators.
- AstBasic
Type Specifier - A basic type specifier.
- AstBinary
Op - Binary operators.
- AstBinary
OpFamily - Families or groups of binary operators.
- AstBlock
Item - An item in a block can be a statement or a declaration.
- AstConstant
Fp - A constant floating-point value.
- AstConstant
Integer - A constant integer value.
- AstConstant
Value - A constant value that was either parsed from a literal or was evaluated from a constant expression.
- AstDeclaration
- A declaration introduces a name and is either a variable or function declaration.
- AstDeclarator
Kind - The kind of declarator.
- AstExpression
Flag - A flag which indicates a property of an AST expression.
- AstExpression
Kind - The kind of expression, which may in fact be a subexpression inside a tree of a larger expression.
- AstFloat
Literal Kind - The kind of floating-point literal.
- AstFor
Initializer - A for-statement initializer can either be a variable declaration or an expression, or nothing.
- AstInteger
Literal Kind - The kind of integer literal.
- AstLinkage
- The linkage of an identifier determines the scope that it can be referenced from.
- AstStatement
- A statement.
- AstStatic
Storage Initializer - A constant, compile-time initializer value for a static storage variable.
- AstStorage
Class Specifier Kind - Storage class specifiers determine an identifier’s scope, storage lifetime, and linkage.
- AstStorage
Duration - The storage duration of an identifier determines its lifetime.
- AstType
- The canonical type of an expression.
- AstUnary
Op - Unary operators.
- AstVariable
Initializer - A variable initializer.
- Enclosing
Statement - An outer switch or loop statement which is in effect while we are parsing statements inside it.
- Enclosing
Statement Chain - An outer switch/loop statement which is in effect while we are parsing statements inside it, plus an option parent switch/loop statement.
Traits§
Functions§
- add_
error - Emits an error diagnostic with the given message.
- add_
error_ at_ eof - Emits an error diagnostic at the end of the source file.
- parse
- Parses the stream of tokens produced by the lexer and generates an abstract syntax tree (AST) representing the source C code, and then passes ownership of the AST to the semantic analysis stage.
- to_
c_ declarator - Creates a C declarator string representation of the given
AstType.
Type Aliases§
- Parse
Result - The result type returned by parsing functions.