XIDEK
|
Abstract Syntax Tree Parser
IntroductionThe baseline Abstract Syntax Tree parsers, cll\base\ast.syn and pll\base\ast.syn are used to create Abstract Syntax Trees for the CLL and PLL languages respectively. These trees, in turn, are used by the astxi and astci interpreters, which implement the buildTree function defined in support\base\astdefs.h.The reduction procedures use the public member functions of the AbstractSyntaxTree class. Each of these functions creates a node for the parse tree and returns a pointer to the node. When the entire tree has been completed, a pointer to the root node is stored in the root member field of the tree object. In what follows, we describe first the features of the CLL version of the ast.syn syntax file and how it differs from the cll.syn file. The differences between the PLL version of ast.syn and pll.syn are identical.
C PrologueThe C prologue in ast.syn contains the declaration of the Tree struct, derived from AbstractSyntaxTree.The Tree struct provides linkage between the parser and the syntax tree code. It contains one member field: parser_pcb_struct *pcbPointer;a pointer to the parser control block, and overrides context(), defined in AbstractSyntaxtTree to provide the correct context information for each node in the tree. The implementation of context() and the class constructor are found in the embedded C portion of the syntax file. The macro AST is used simply to make the reduction procedures appear less forbidding.
Configuration SectionConfiguration parameters that are common to all the parsers in the kit are discussed here. The following configuration parameters are set in ast.syn:
Parser Control Block ExtensionsIn order to support reentrancy, it is convenient to declare local data used by the parser in the parser control block. It is also convenient to declare functions used by the parser as members of the parser control block, though this is not, strictly speaking, necessary.
Added Fields
Local FunctionsThe actual implementations of the following functions are found in the embedded C portion of the syntax file:
Reduction ProceduresThe useful work of any parser is carried out by the reduction procedures which indicate what is to be done when a grammar rule is matched. In the case of the abstract syntax tree parser, parse(), apart from the lexical rules, reduction procedures simply combine nodes furnished by the tokens in a rule to create a new node for the tree. The functions used are defined in described in astdefs.htm.
Embedded CThe embedded C section of the syntax file contains support code for the parser.
Macro DefinitionsThere are two macro definitions:
Tree Member Functions
Parser Control Block Member FunctionsThe following member functions of parse_pcb_struct are declared in the extensions to the parser control block.
External Interface Function
|
Table of Contents | | | Parsifal Software Home Page |
---|
XIDEK
Extensible Interpreter Development Kit
Copyright © 1997-2002, Parsifal Software.
All Rights Reserved.