Skip to content

Concepts

Abe Pralle edited this page Nov 23, 2021 · 2 revisions
  1. A compiler is an application that reads plain-text source code, expressed following the rules of an arbitrary language and translates it into some output language such as Machine Language, Assembly, or C++.
  2. Under the hood, a scanner (AKA lexer or tokenizer) converts plain text into a stream of small objects or data chunks called tokens. A parser then creates command nodes that represent the operations being described by the tokens and assembles the nodes in to an single abstract syntax tree (AST). The AST is then further processed and analyzed for correctness. The resolved AST can then be compiled (written out in the form of a target language) or interpreted (executed in place).
  3. Using Froley you define token types as well as the logic for a Scanner and Parser. Command nodes (base type Cmd) are defined as part of the Parser. Executing Froley will create a framework with Token, TokenType, Scanner, Parser, Cmd, and Visitor classes, along with a few others.
  4. AST's are often processed using the visitor pattern. The logic for traversing the AST is encapsulated within a base Visitor class. Visitors may be extended to peform custom logic and modifications per node type.
  5. In other words Froley generates the full Scanner and Parser and produces an AST made of Cmd nodes that is ready for further processing. The application should next resolve the AST using extended Visitor classes and can then either execute it ("interpret" it) or output it to ML etc. ("compile" it), using additional extended visitors in either case.

Clone this wiki locally