27 March 2000 Release 2.22 Notes for New Users of PCCTS Version 1.33MR22
46
the pipeline size is rounded up because TJP decided it was faster to use a bit-wise "and" to compute the next
position in a circular buffer rather than (n+1) mod k.
(C Mode) ASTs
#200.
Define a zzd_ast() to recover resources when an AST is deleted
#201.
How to place prototypes for routines using ASTs in the #header
Add #include "ast.h" after the #define AST_FIELDS and before any references to AST:
#define AST_FIELDS int token;char *text;
#include "ast.h"
#define zzcr_ast(ast,attr,tok,astText) \
create_ast(ast,attr,tok,text)
void create_ast (AST *ast,Attr *attr,int tok,char *text);
#202.
To free an AST tree use zzfree_ast() to recursively descend the AST tree and free all sub-trees
The user should supply a routine zzd_ast() to free any resources used by a single node - such as pointers to
character strings allocated on the heap.
#203.
Use #define zzAST_DOUBLE to add support for doubly linked ASTs
There is an option for doubly linked ASTs in the module ast.c. It is controlled by #define zzAST_DOUBLE. Even
with zzAST_DOUBLE only the right and down fields are filled while the AST tree is constructed. Once the tree is
constructed the user must call the routine zzdouble_link(tree,0,0) to traverse the tree and fill in the left and up fields.
Extended Examples and Short Descriptions of Distributed Source Code
Examples mentioned in these notes are available as .zip files at the sites mentioned in Item #1. In keeping with the
restrictions in
PCCTS
, I have used neither templates nor multiple inheritance in these examples.
All these examples use AST classes which are derived from NoLeakAST. Some of them use tokens which are derived
from NoLeakToken. These classes maintain a doubly-linked list of all ASTs (or tokens) which have been created but not
yet deleted making it possible to recover memory for these objects.
#1.
DLG
definitions for C and C++ comments, character literals, and string literals
See files in notes/cstuff/cstr.g (C mode) or notes/cstuff/cppstr.g (C++ mode). Contributed by John D. Mitchell
(johnm@jGuru.com).
#2.
A simple floating point calculator implemented using
PCCTS
attributes and inheritance
This is
the PCCTS
equivalent of the approach used in the canonical yacc example. See notes/calctok/*.
#3.
A simple floating point calculator implemented using
PCCTS
ASTs and C++ virtual functions
See files in notes/calcAST/*.
In this example an expression tree is built using ASTs. For each operator in the tree there is a different class derived
from AST with an operator specific implementation of the virtual function "eval()". Evaluation of the expression is
performed by calling eval() for the root node of the AST tree. Each node invokes eval() for its children nodes,
computes its own operation, and passed the result to its parent in a recursive manner.
#4.
An
ANTLR
Token class for variable length strings allocated from the heap
This is no longer useful since
ANTLR
CommonToken uses the heap.
#5.
How to extend
PCCTS
C++ classes using the example of adding column information
See files in notes/col/*
This demonstrates how to add column information to tokens and to produce syntax error messages using this
information. This example derives classes from
ANTLR
Token and
ANTLR
TokenBuffer.
#6.
Use of parser exception handling in C and C++ programs
For C see notes/exc/extestc.g and test1.dat
For C++ see notes/excpp/extestcpp.g and test1.dat