-
Notifications
You must be signed in to change notification settings - Fork 0
Concepts
Abe Pralle edited this page Nov 23, 2021
·
2 revisions
- 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++.
- 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).
- 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. - AST's are often processed using the visitor pattern. The logic for traversing the AST is encapsulated within a base
Visitorclass. Visitors may be extended to peform custom logic and modifications per node type. - In other words Froley generates the full
ScannerandParserand produces an AST made ofCmdnodes that is ready for further processing. The application should next resolve the AST using extendedVisitorclasses and can then either execute it ("interpret" it) or output it to ML etc. ("compile" it), using additional extended visitors in either case.