Introduction to Dang
Dang is based on the clang compiler in a number of ways. I'll here list the elements of Dang.
Libs
As clang, Dang is based on a number of libraries. All of them are listed here, along with dependencies.
- Basic - Every lib uses the Basic lib.
- Lexer - Have no other dependencies then basic.
- Parser - Depends on Lexer.
- AST - Depends on Sema and Lexer
- Sema - Depends on AST and Parser
- CodeGen? - Depends on Sema and AST
- Tools - Depends on AST
- Driver - Uses all the libs and compiles to the "Dang" binary application.
Basic
Source handling and error messages is both handled in the Basic lib. The error messages is the same format as clang, a 3 line error message for each error. The SourceManager? is responsible for supplying SourceLocation? for all the files loaded. A SourceLocation? is a position in a file.
Lexer
The lexer lib contains the Lexer that tokenize the file, and supply a stream of Tokens. Each Token contain a type along with a SourceLocation?. Size is here kept on a minimum. The Lexer supplies two methods for usage, a next and a peek.
Parser
As the only lib, Parses uses the Lexer to get all the tokens of a file. The Parser then analyze the Tokens and calls actions on the Parser-libs Action-interface. This means that whenever the Parser analyze that the file contains an Declaration, it will call the action that builds a Declaration.
AST
The Abstract Syntax Tree is the binary representation of the source file. This tree contains a series of ASTNodes, that will make it possible to analyze the sourcefile for erros.
Sema
Semantic is responsible for applying an implementation of the Parser's Action that builds an AST based on the actions called. Then it defines Scopes, Symbols and Types so that an in-depth analyze can decide if it's an syntax and semantic correct source file. If no error is raises when the semantic analyzes is done, the source-file is a correct expressed D source file.
CodeGen?
Used by the Driver to output the AST as bytecode. To do this, the LLVM backend is used.
Tools
A set of tools that apply other forms of action on the AST then codegen. This includes pretty printing and header writing.
