--- /dev/null
+/*\r
+ * syn.h\r
+ *\r
+ * This file includes definitions and macros associated with syntax diagrams\r
+ *\r
+ * SOFTWARE RIGHTS\r
+ *\r
+ * We reserve no LEGAL rights to the Purdue Compiler Construction Tool\r
+ * Set (PCCTS) -- PCCTS is in the public domain. An individual or\r
+ * company may do whatever they wish with source code distributed with\r
+ * PCCTS or the code generated by PCCTS, including the incorporation of\r
+ * PCCTS, or its output, into commerical software.\r
+ *\r
+ * We encourage users to develop software with PCCTS. However, we do ask\r
+ * that credit is given to us for developing PCCTS. By "credit",\r
+ * we mean that if you incorporate our source code into one of your\r
+ * programs (commercial product, research project, or otherwise) that you\r
+ * acknowledge this fact somewhere in the documentation, research report,\r
+ * etc... If you like PCCTS and have developed a nice tool with the\r
+ * output, please mention that you developed it using PCCTS. In\r
+ * addition, we ask that this header remain intact in our source code.\r
+ * As long as these guidelines are kept, we expect to continue enhancing\r
+ * this system and expect to make other tools available as they are\r
+ * completed.\r
+ *\r
+ * ANTLR 1.33\r
+ * Terence Parr\r
+ * Parr Research Corporation\r
+ * with Purdue University and AHPCRC, University of Minnesota\r
+ * 1989-2001\r
+ */\r
+\r
+#include "set.h"\r
+\r
+#define NumNodeTypes 4\r
+#define NumJuncTypes 9\r
+\r
+/* List the different node types */\r
+#define nJunction 1\r
+#define nRuleRef 2\r
+#define nToken 3\r
+#define nAction 4\r
+\r
+/* Different types of junctions */\r
+#define aSubBlk 1\r
+#define aOptBlk 2\r
+#define aLoopBlk 3\r
+#define EndBlk 4\r
+#define RuleBlk 5\r
+#define Generic 6 /* just a junction--no unusual characteristics */\r
+#define EndRule 7\r
+#define aPlusBlk 8\r
+#define aLoopBegin 9\r
+\r
+typedef int NodeType;\r
+\r
+#define TreeBlockAllocSize 500\r
+#define JunctionBlockAllocSize 200\r
+#define ActionBlockAllocSize 50\r
+#define RRefBlockAllocSize 100\r
+#define TokenBlockAllocSize 100\r
+\r
+#ifdef __cplusplus\r
+class ActionNode;\r
+class Junction;\r
+#endif\r
+\r
+/* note that 'right' is used by the tree node allocator as a ptr for linked list */\r
+typedef struct _tree {\r
+ struct _tree *down, *right;\r
+ int token;\r
+ union {\r
+ int rk; /* if token==EpToken, => how many more tokens req'd */\r
+ struct _tree *tref; /* if token==TREE_REF */\r
+ set sref; /* if token==SET */\r
+ } v;\r
+#ifdef TREE_DEBUG\r
+ int in_use;\r
+ int seq;\r
+#endif\r
+ } Tree;\r
+\r
+\r
+/* a predicate is defined to be a predicate action and a token tree with\r
+ * context info (if used); later, this struct may include the\r
+ * "hoisting distance" when we hoist past tokens.\r
+ *\r
+ * A tree is used to indicate && vs ||\r
+ *\r
+ * p\r
+ * |\r
+ * q--r\r
+ *\r
+ * indicates p && (q||r).\r
+ *\r
+ * If expr is PRED_AND_LIST or PRED_OR_LIST, then it's an operation node\r
+ * and indicates the start of an && or || list.\r
+ */\r
+\r
+typedef struct _Predicate {\r
+ struct _Predicate *down, *right; /* these have to be first */\r
+ struct _Predicate *up, *left; /* doubly-link me */\r
+ char *expr;\r
+ Tree *tcontext; /* used if lookahead depth of > one is needed (tree) */\r
+ int k; /* lookahead depth for this tcontext */\r
+ set scontext[2];/* used if lookahead depth of one is needed (set) */\r
+ /* scontext[0] is not used; only needed so genExprSets()\r
+ routine works (it expects an array)\r
+ */\r
+ set completionTree; /* which lookahead depths are required to complete tcontext? */\r
+ set completionSet; /* MR10 separate completion set for sets and trees */\r
+ struct _PredEntry *predEntry; /* MR11 */\r
+\r
+#ifdef __cplusplus\r
+ ActionNode *source; /* where did this predicate come from? */\r
+#else\r
+ struct _anode *source; /* where did this predicate come from? */\r
+#endif\r
+\r
+ char cloned; /* MR10 don't want to free original guard pred */\r
+ char redundant; /* MR10 predicate tree simplification */\r
+ char ampersandStyle; /* MR10 (g)? && <<p>>? */\r
+ char inverted; /* MR11 ! predName */\r
+ char isConst; /* MR11 */\r
+ char constValue; /* MR11 */\r
+ char conflictReported; /* MR11 */\r
+\r
+ set plainSet; /* MR12b */\r
+\r
+ /*** remember to change new_predicate() and predicate_dup() when changing this ***/\r
+\r
+} Predicate;\r
+\r
+typedef struct _ExceptionHandler {\r
+ char *signalname;\r
+ char *action;\r
+ } ExceptionHandler;\r
+\r
+typedef struct _ExceptionGroup {\r
+ struct _ListNode *handlers; /* list of ExceptionHandler's */\r
+ char *label; /* label==""; implies not attached to any\r
+ * particular rule ref.\r
+ */\r
+ char *altID; /* which alt did it come from (blk#:alt#) */\r
+\r
+ struct _ExceptionGroup *pendingLink; /* for alternative EG MR7 */\r
+ struct _ExceptionGroup *outerEG; /* for alternative EG MR7 */\r
+ struct _LabelEntry *labelEntry; /* for alternative EG MR7 */\r
+ int forRule; /* MR7 */\r
+ int used; /* MR7 */\r
+ } ExceptionGroup ;\r
+\r
+\r
+#define TokenString(_i) ((TokenInd!=NULL)?TokenStr[TokenInd[_i]]:TokenStr[_i])\r
+#define ExprString(_i) ((TokenInd!=NULL)?ExprStr[TokenInd[_i]]:ExprStr[_i])\r
+\r
+\r
+ /* M e s s a g e P a s s i n g T o N o d e s */\r
+\r
+/*\r
+ * assumes a 'Junction *r' exists. This macro calls a function with\r
+ * the pointer to the node to operate on and a pointer to the rule\r
+ * in which it is enclosed.\r
+ */\r
+#define TRANS(p) {if ( (p)==NULL ) fatal("TRANS: NULL object"); \\r
+ if ( (p)->ntype == nJunction ) (*(fpJTrans[((Junction *)(p))->jtype]))( p );\\r
+ else (*(fpTrans[(p)->ntype]))( p );}\r
+\r
+#define PRINT(p) {if ( (p)==NULL ) fatal("PRINT: NULL object");\\r
+ (*(fpPrint[(p)->ntype]))( p );}\r
+\r
+#define REACH(p,k,rk,a) {if ( (p)==NULL ) fatal("REACH: NULL object");\\r
+ (a) = (*(fpReach[(p)->ntype]))( p, k, rk );}\r
+\r
+#define TRAV(p,k,rk,a) {if ( (p)==NULL ) {\\r
+ if ( ContextGuardTRAV ) (a)=NULL; \\r
+ else fatal("TRAV: NULL object");\\r
+ } \\r
+ else (a) = (*(fpTraverse[(p)->ntype]))( p, k, rk );}\r
+\r
+/**\r
+*** #define TRAV(p,k,rk,a) {if ( (p)==NULL ) fatal("TRAV: NULL object");\\r
+*** (a) = (*(fpTraverse[(p)->ntype]))( p, k, rk );}\r
+**/\r
+\r
+/* All syntax diagram nodes derive from Node -- superclass\r
+ */\r
+#ifdef __cplusplus\r
+class Node {\r
+public:\r
+ NodeType ntype;\r
+ char *rname; /* what rule does this element live in? */\r
+ int file; /* index in FileStr */\r
+ int line; /* line number that element occurs on */\r
+ };\r
+#else\r
+typedef struct _node {\r
+ NodeType ntype;\r
+ char *rname; /* what rule does this element live in? */\r
+ int file; /* index in FileStr */\r
+ int line; /* line number that element occurs on */\r
+ } Node;\r
+#endif\r
+\r
+#ifdef __cplusplus\r
+class ActionNode : public Node {\r
+public:\r
+#else\r
+typedef struct _anode {\r
+ NodeType ntype;\r
+ char *rname; /* what rule does this action live in? */\r
+ int file; /* index in FileStr (name of file with action) */\r
+ int line; /* line number that action occurs on */\r
+#endif\r
+ Node *next;\r
+ char *action;\r
+ int is_predicate; /* true if action is a <<...>>? predicate action */\r
+ int done; /* don't dump if action dumped (used for predicates) */\r
+ int init_action; /* is this the 1st action of 1st prod of block? */\r
+ char *pred_fail; /* what to do/print when predicate fails */\r
+ Predicate *guardpred; /* if '(context)? =>' was present, already done */\r
+ unsigned char frmwarned;/* have we dumped a warning for pred yet? */\r
+ unsigned char ctxwarned;/* have we dumped a warning for pred yet? */\r
+ unsigned char predTooLong; /* MR10 have we dumped warning for pred yet */\r
+ unsigned char noHoist; /* MR12 literally "noHoist" */\r
+ Predicate *ampersandPred; /* MR10 (g)? && <<p>>? expr */\r
+#ifdef __cplusplus\r
+ Junction *guardNodes; /* MR11 */\r
+#else\r
+ struct _junct *guardNodes; /* MR11 */\r
+#endif\r
+ struct _PredEntry *predEntry; /* MR11 */\r
+ int inverted; /* MR11 <<!predSymbol>>? */\r
+#ifdef __cplusplus\r
+ };\r
+#else\r
+ } ActionNode;\r
+#endif\r
+\r
+#ifdef __cplusplus\r
+class TokNode : public Node {\r
+public:\r
+#else\r
+typedef struct _toknode {\r
+ NodeType ntype;\r
+ char *rname; /* name of rule it's in */\r
+ int file; /* index in FileStr (name of file with rule) */\r
+ int line; /* line number that token occurs on */\r
+#endif\r
+ Node *next;\r
+ int token;\r
+ int astnode; /* leaf/root/excluded (used to build AST's) */\r
+ unsigned char label;/* token label or expression ? */\r
+ unsigned char remapped;\r
+ /* used if token id's are forced to certain positions;\r
+ * a function walks the tree reassigning token numbers */\r
+ int upper_range; /* MR13 - was char */\r
+ /* used only if Token is of type T1..T2; in this case,\r
+ * use token..upper_range as the range; else\r
+ * upper_range must be 0 */\r
+ unsigned char wild_card;\r
+ /* indicates that the token is the "." wild-card;\r
+ * field token is ignored if wild_card is set\r
+ */\r
+ unsigned int elnum; /* element number within the alternative */\r
+#ifdef __cplusplus\r
+ Junction *altstart; /* pointer to node that starts alt */\r
+#else\r
+ struct _junct *altstart; /* pointer to node that starts alt */\r
+#endif\r
+ struct _TCnode *tclass; /* token class if tokclass ref */\r
+ set tset; /* set of tokens represented by meta token */\r
+ char *el_label; /* el_label:toknode */\r
+ unsigned char complement; /* complement the set? */\r
+ ExceptionGroup *ex_group; /* any exception[el_label] attached? */\r
+ unsigned char use_def_MT_handler;\r
+ unsigned char label_used_in_semantic_pred; /* MR10 */\r
+#ifdef __cplusplus\r
+ };\r
+#else\r
+ } TokNode;\r
+#endif\r
+\r
+#ifdef __cplusplus\r
+class RuleRefNode : public Node {\r
+public:\r
+#else\r
+typedef struct _rrnode {\r
+ NodeType ntype;\r
+ char *rname; /* name of rule it's in */\r
+ int file; /* index in FileStr (name of file with rule)\r
+ it's in */\r
+ int line; /* line number that rule ref occurs on */\r
+#endif\r
+ Node *next;\r
+ char *text; /* reference to which rule */\r
+ char *parms; /* point to parameters of rule invocation\r
+ (if present) */\r
+ char *assign; /* point to left-hand-side of assignment\r
+ (if any) */\r
+ int linked; /* Has a FoLink already been established? */\r
+ int astnode; /* excluded? (used to build AST's) */\r
+ unsigned int elnum; /* element number within the alternative */\r
+#ifdef __cplusplus\r
+ Junction *altstart;\r
+#else\r
+ struct _junct *altstart;\r
+#endif\r
+ char *el_label; /* el_label:rrnode */\r
+ ExceptionGroup *ex_group; /* any exception[el_label] attached? */\r
+#ifdef __cplusplus\r
+ };\r
+#else\r
+ } RuleRefNode;\r
+#endif\r
+\r
+#ifdef __cplusplus\r
+class Junction : public Node {\r
+public:\r
+#else\r
+typedef struct _junct {\r
+ NodeType ntype;\r
+ char *rname; /* name of rule junction is in */\r
+ int file; /* index in FileStr (name of file with rule)\r
+ if blk == RuleBlk */\r
+ int line; /* line number that rule occurs on */\r
+#endif\r
+ int seq; /* MR10 sequence number */\r
+ char ignore; /* used by FIRST computation to ignore\r
+ empty alt added for the (...)+ blks */\r
+ char visited; /* used by recursive routines to avoid\r
+ infinite recursion */\r
+ char pvisited; /* used by print routines to avoid\r
+ infinite recursion */\r
+ char fvisited; /* used by FoLink() to avoid\r
+ infinite recursion */\r
+ char *lock; /* used by REACH to track infinite recursion */\r
+ char *pred_lock; /* used by find_predicates to track infinite recursion */\r
+ int altnum; /* used in subblocks. altnum==0 means not an\r
+ alt of subrule */\r
+ int jtype; /* annotation for code-gen/FIRST/FOLLOW.\r
+ Junction type */\r
+#ifdef __cplusplus\r
+ Junction *end; /* pointer to node with EndBlk in it\r
+ if blk == a block type */\r
+#else\r
+ struct _junct *end; /* pointer to node with EndBlk in it\r
+ if blk == a block type */\r
+#endif\r
+ Node *p1, *p2;\r
+ char halt; /* never move past a junction with halt==TRUE */ /* MR10 was int */\r
+ char *pdecl; /* point to declaration of parameters on rule\r
+ (if present) */\r
+ char *parm; /* point to parameter of block invocation\r
+ (if present) */\r
+ char predparm; /* indicates that the 'parm' is a predicate\r
+ * to be used in the while loop generated\r
+ * for blocks */ /* MR10 was int */\r
+ char *ret; /* point to return type of rule (if present) */\r
+ char *erraction; /* point to error action (if present) */\r
+ int blockid; /* this is a unique ID */\r
+ char *exception_label; /* goto label for this alt */\r
+ set *fset; /* used for code generation */\r
+ Tree *ftree; /* used for code generation */\r
+ Predicate *predicate;/* predicate that can be used to disambiguate */\r
+ char guess; /* true if (...)? block */\r
+ char alpha_beta_guess_end; /* MR14 1 => end block of guess sub block */\r
+ Node *guess_analysis_point; /* MR14 */\r
+ char approx; /* limit block to use linear approx lookahead? */\r
+ set tokrefs; /* if ith element of alt is tokref then i is member */\r
+ set rulerefs; /* if ith element of alt is rule ref then i is member */\r
+ struct _ListNode *exceptions; /* list of exceptions groups for rule */\r
+ struct _ListNode *el_labels; /* list of element labels for rule */\r
+ ExceptionGroup *outerEG; /* MR7 */\r
+ int curAltNum; /* MR7 */\r
+ char* pFirstSetSymbol; /* #pragma FirstSetSymbol(Foo) MR21 */\r
+#ifdef __cplusplus\r
+ Junction *pendingLink; /* MR7 */\r
+#else\r
+ struct _junct *pendingLink; /* MR7 */\r
+#endif\r
+ char overlap_warning; /* MR10 */\r
+#ifdef __cplusplus\r
+ };\r
+#else\r
+ } Junction;\r
+#endif\r
+\r
+typedef struct { Node *left, *right;} Graph;\r
+\r