The functions for generating and translating the Abstract Syntax Tree (AST).
More...
#include "./apg.h"
#include "./lib.h"
#include "./parserp.h"
#include "./astp.h"
Go to the source code of this file.
|
| void * | vpAstCtor (void *vpParserCtx) |
| | The AST object constructor. More...
|
| |
| void | vAstDtor (void *vpCtx) |
| |
| abool | bAstValidate (void *vpCtx) |
| | Validate an AST context pointer. More...
|
| |
| void | vAstClear (void *vpCtx) |
| | Clear the AST records for reuse of the AST object. More...
|
| |
| void | vAstInfo (void *vpCtx, ast_info *spInfo) |
| | Retrieve basic information about the AST object. More...
|
| |
| void | vAstTranslate (void *vpCtx, void *vpUserData) |
| | Do a depth-first traversal of the AST with user-defined callback functions to translate the AST records. More...
|
| |
| void | vAstSetRuleCallback (void *vpCtx, aint uiRuleIndex, ast_callback pfnCallback) |
| | Define a callback function for a single rule on the AST. More...
|
| |
| void | vAstSetUdtCallback (void *vpCtx, aint uiUdtIndex, ast_callback pfnCallback) |
| | Define a callback function for a single UDT on the AST. More...
|
| |
| void | vAstRuleOpen (void *vpCtx, aint uiRuleIndex, aint uiPhraseOffset) |
| | Called by parser's RNM operator before downward traversal. More...
|
| |
| void | vAstRuleClose (void *vpCtx, aint uiRuleIndex, aint uiState, aint uiPhraseOffset, aint uiPhraseLength) |
| | Called by parser's RNM operator after upward traversal. More...
|
| |
| void | vAstOpOpen (void *vpCtx) |
| | Called in preparation for a downward traversal of an RNM or UDT node. More...
|
| |
| void | vAstOpClose (void *vpCtx, aint uiState) |
| | Called to finish up after an upward traversal of an RNM or UDT node. More...
|
| |
The functions for generating and translating the Abstract Syntax Tree (AST).
Definition in file ast.c.
◆ bAstValidate()
| abool bAstValidate |
( |
void * |
vpCtx | ) |
|
Validate an AST context pointer.
- Parameters
-
| vpCtx | Pointer to a possible AST context returned by vpAstCtor(). |
- Returns
- True if the pointer is valid, false otherwise.
Definition at line 104 of file ast.c.
◆ vAstClear()
| void vAstClear |
( |
void * |
vpCtx | ) |
|
Clear the AST records for reuse of the AST object.
- Parameters
-
| vpCtx | Pointer to an AST context returned from vpAstCtor(); Silently ignored if NULL. However, if non-NULL it must be a valid AST context pointer or the application will exit with BAD_CONTEXT. |
Definition at line 118 of file ast.c.
◆ vAstDtor()
| void vAstDtor |
( |
void * |
vpCtx | ) |
|
Definition at line 81 of file ast.c.
◆ vAstInfo()
| void vAstInfo |
( |
void * |
vpCtx, |
|
|
ast_info * |
spInfo |
|
) |
| |
Retrieve basic information about the AST object.
- Parameters
-
| vpCtx | Pointer to a valid AST context returned by vpAstCtor(). If invalid, the application will silently exit with a BAD_CONTEXT exit code; |
| spInfo | Pointer to the user's info struct to receive the information. |
Definition at line 137 of file ast.c.
◆ vAstOpClose()
| void vAstOpClose |
( |
void * |
vpCtx, |
|
|
aint |
uiState |
|
) |
| |
Called to finish up after an upward traversal of an RNM or UDT node.
- Parameters
-
| vpCtx | - AST context handle returned from |
- See also
- vpAstCtor. No validation is done here as this function is always called by a trusted parser operator function.
- Parameters
-
| uiState | ID_MATCH or ID_NOMATCH, the result of the parse. |
Definition at line 403 of file ast.c.
◆ vAstOpOpen()
| void vAstOpOpen |
( |
void * |
vpCtx | ) |
|
Called in preparation for a downward traversal of an RNM or UDT node.
- Parameters
-
| vpCtx | - AST context handle returned from |
- See also
- vpAstCtor. No validation is done here as this function is always called by a trusted parser operator function.
Definition at line 392 of file ast.c.
◆ vAstRuleClose()
| void vAstRuleClose |
( |
void * |
vpCtx, |
|
|
aint |
uiRuleIndex, |
|
|
aint |
uiState, |
|
|
aint |
uiPhraseOffset, |
|
|
aint |
uiPhraseLength |
|
) |
| |
Called by parser's RNM operator after upward traversal.
- Parameters
-
| vpCtx | - AST context handle returned from |
- See also
- vpAstCtor. No validation is done here as this function is always called by a trusted parser operator function.
- Parameters
-
| uiRuleIndex | The index of the RNM rule. If uiRuleIndex > uiRuleCount then it represents a UDT whose index is uiRuleIndex - uiRuleCount. |
| uiState | ID_MATCH or ID_NOMATCH, the result of the parse for this rule or UDT. |
| uiPhraseOffset | Offset into the input string of the offest of the matched phrase. |
| uiPhraseLength | The number of match characters in the phrase. |
Definition at line 329 of file ast.c.
◆ vAstRuleOpen()
| void vAstRuleOpen |
( |
void * |
vpCtx, |
|
|
aint |
uiRuleIndex, |
|
|
aint |
uiPhraseOffset |
|
) |
| |
Called by parser's RNM operator before downward traversal.
- Parameters
-
| vpCtx | Pointer to a valid AST context returned by vpAstCtor(). No validation is done here as this function is always called by a trusted parser operator function. |
| uiRuleIndex | The index of the RNM rule. If uiRuleIndex > uiRuleCount then it represents a UDT whose index is uiRuleIndex - uiRuleCount. |
| uiPhraseOffset | Offset into the input string of the offest of the matched phrase. |
Definition at line 286 of file ast.c.
◆ vAstSetRuleCallback()
| void vAstSetRuleCallback |
( |
void * |
vpCtx, |
|
|
aint |
uiRuleIndex, |
|
|
ast_callback |
pfnCallback |
|
) |
| |
Define a callback function for a single rule on the AST.
NOTE: There is an important difference between the role of the call back functions during parsing and translation. See this note for a discussion of this important distinction.
- Parameters
-
| vpCtx | Pointer to a valid AST context returned by vpAstCtor(). If invalid, the application will silently exit with a BAD_CONTEXT exit code; |
| uiRuleIndex | The index of the rule to attach this callback function to. |
| pfnCallback | Pointer to the callback function. Must match the ast_callback prototype. |
Definition at line 243 of file ast.c.
◆ vAstSetUdtCallback()
| void vAstSetUdtCallback |
( |
void * |
vpCtx, |
|
|
aint |
uiUdtIndex, |
|
|
ast_callback |
pfnCallback |
|
) |
| |
Define a callback function for a single UDT on the AST.
NOTE: There is an important difference between the role of the call back functions during parsing and translation. See this note for a discussion of this important distinction.
- Parameters
-
| vpCtx | Pointer to a valid AST context returned by vpAstCtor(). If invalid, the application will silently exit with a BAD_CONTEXT exit code; |
| uiUdtIndex | The index of the UDT to attach this callback function to. |
| pfnCallback | Pointer to the callback function. Must match the ast_callback prototype. |
Definition at line 266 of file ast.c.
◆ vAstTranslate()
| void vAstTranslate |
( |
void * |
vpCtx, |
|
|
void * |
vpUserData |
|
) |
| |
Do a depth-first traversal of the AST with user-defined callback functions to translate the AST records.
NOTE: There is an important difference between the role of the call back functions during parsing and translation. See this note for a discussion of this important distinction.
- Parameters
-
| vpCtx | Pointer to a valid AST context returned by vpAstCtor(). If invalid, the application will silently exit with a BAD_CONTEXT exit code; |
| vpUserData | Pointer to optional user data. This pointer is passed to the user's callback functions for any purpose the application requires for the translation. May be NULL. |
Definition at line 165 of file ast.c.
◆ vpAstCtor()
| void* vpAstCtor |
( |
void * |
vpParserCtx | ) |
|
The AST object constructor.
This object is a "sub-object" of the parser. The parser will keep a pointer to and use this object to generate the AST records. Note that there is no associated destructor. This object is destroyed by its parent parser object's destructor, vParserDtor().
- Parameters
-
| vpParserCtx | Pointer to a valid parser context returned from vpParserCtor(); If invalid, the application will silently exit with a BAD_CONTEXT exit code; |
- Returns
- Returns a pointer to the object context. Throws an exception on any errors.
Definition at line 51 of file ast.c.
APG Version 7.0 is licensed under the
2-Clause BSD License,
an Open Source Initiative Approved License.