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