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 printer module is used by the parent parser module to print a tree of the C AST to stdout.

Structs§

AstBasicType
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.
AstDeclaredType
An AstDeclaredType represents a parsed type declaration which is not yet resolved to its canonical AstType.
AstExpression
An expression.
AstExpressionFlags
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.
AstNodeId
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.
AstStorageClassSpecifier
A storage class specifier in a declaration.
AstTypeAliasDeclaration
A typedef declaration.
AstUniqueName
A unique string name for a variable, function, or type alias identifier.
AstVariableDeclaration
A variable declaration with optional definition.
ParseError
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§

AstAddressConstant
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.
AstAssignmentOp
Assignment operators.
AstBasicTypeSpecifier
A basic type specifier.
AstBinaryOp
Binary operators.
AstBinaryOpFamily
Families or groups of binary operators.
AstBlockItem
An item in a block can be a statement or a declaration.
AstConstantFp
A constant floating-point value.
AstConstantInteger
A constant integer value.
AstConstantValue
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.
AstDeclaratorKind
The kind of declarator.
AstExpressionFlag
A flag which indicates a property of an AST expression.
AstExpressionKind
The kind of expression, which may in fact be a subexpression inside a tree of a larger expression.
AstFloatLiteralKind
The kind of floating-point literal.
AstForInitializer
A for-statement initializer can either be a variable declaration or an expression, or nothing.
AstIntegerLiteralKind
The kind of integer literal.
AstLinkage
The linkage of an identifier determines the scope that it can be referenced from.
AstStatement
A statement.
AstStaticStorageInitializer
A constant, compile-time initializer value for a static storage variable.
AstStorageClassSpecifierKind
Storage class specifiers determine an identifier’s scope, storage lifetime, and linkage.
AstStorageDuration
The storage duration of an identifier determines its lifetime.
AstType
The canonical type of an expression.
AstUnaryOp
Unary operators.
AstVariableInitializer
A variable initializer.
EnclosingStatement
An outer switch or loop statement which is in effect while we are parsing statements inside it.
EnclosingStatementChain
An outer switch/loop statement which is in effect while we are parsing statements inside it, plus an option parent switch/loop statement.

Traits§

AstStorageClassSpecifierOption

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§

ParseResult
The result type returned by parsing functions.