antlr.h
来自「SRI international 发布的OAA框架软件」· C头文件 代码 · 共 808 行 · 第 1/2 页
H
808 行
/* antlr.h
*
* 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-2000
*/
#ifndef ANTLR_H
#define ANTLR_H
#include "pcctscfg.h"
#include "pccts_stdio.h"
/* turn off warnings for unreferenced labels */
#ifdef _MSC_VER
#pragma warning(disable:4102)
#endif
/*
* Define all of the stack setup and manipulation of $i, #i variables.
*
* Notes:
* The type 'Attrib' must be defined before entry into this .h file.
*/
#ifdef __USE_PROTOS
#include "pccts_stdlib.h"
#else
#ifdef VAXC
#include <stdlib.h>
#else
#include <malloc.h>
#endif
#endif
#include "pccts_string.h"
#if 0
#include "set.h"
#endif
typedef int ANTLRTokenType;
typedef unsigned char SetWordType;
typedef char ANTLRChar;
/* G u e s s S t u f f */
#ifdef ZZCAN_GUESS
#ifndef ZZINF_LOOK
#define ZZINF_LOOK
#endif
#endif
#ifdef ZZCAN_GUESS
typedef struct _zzjmp_buf {
jmp_buf state;
} zzjmp_buf;
#endif
/* can make this a power of 2 for more efficient lookup */
#ifndef ZZLEXBUFSIZE
#define ZZLEXBUFSIZE 8000 /* MR22 raise from 2k to 8k */
#endif
#define zzOvfChk \
if ( zzasp <= 0 ) \
{ \
fprintf(stderr, zzStackOvfMsg, __FILE__, __LINE__); \
exit(PCCTS_EXIT_FAILURE); \
}
#ifndef ZZA_STACKSIZE
#define ZZA_STACKSIZE 400
#endif
#ifndef ZZAST_STACKSIZE
#define ZZAST_STACKSIZE 400
#endif
#ifndef zzfailed_pred
#ifdef ZZCAN_GUESS
#define zzfailed_pred(_p,_hasuseraction,_useraction) \
if (zzguessing) { \
zzGUESS_FAIL; \
} else { \
zzfailed_pred_action(_p,_hasuseraction,_useraction); \
}
#else
#define zzfailed_pred(_p,_hasuseraction,_useraction) \
zzfailed_pred_action(_p,_hasuseraction,_useraction);
#endif
#endif
/* MR23 Provide more control over failed predicate action
without any need for user to worry about guessing internals.
_hasuseraction == 0 => no user specified error action
_hasuseraction == 1 => user specified error action
*/
#ifndef zzfailed_pred_action
#define zzfailed_pred_action(_p,_hasuseraction,_useraction) \
if (_hasuseraction) { _useraction } \
else { fprintf(stderr, "semantic error; failed predicate: '%s'\n",_p); }
#endif
/* MR19 zzchar_t additions */
#ifdef LL_K
#define LOOKAHEAD \
int zztokenLA[LL_K]; \
zzchar_t zztextLA[LL_K][ZZLEXBUFSIZE]; \
int zzlap = 0, zzlabase=0; /* labase only used for DEMAND_LOOK */
#else
#define LOOKAHEAD \
int zztoken;
#endif
#ifndef zzcr_ast
#define zzcr_ast(ast,attr,tok,text)
#endif
#ifdef DEMAND_LOOK
#define DemandLookData int zzdirty=1;
#else
#define DemandLookData
#endif
#ifndef zzUSER_GUESS_HOOK
#define zzUSER_GUESS_HOOK(seqFrozen,zzrv)
#endif
#ifndef zzUSER_GUESS_DONE_HOOK
#define zzUSER_GUESS_DONE_HOOK(seqFrozen)
#endif
/* S t a t e S t u f f */
#ifdef ZZCAN_GUESS
#define zzGUESS_BLOCK zzantlr_state zzst; int zzrv; int zzGuessSeqFrozen;
/* MR10 change zzGUESS: do zzGUESS_DONE when zzrv==1 after longjmp as in C++ mode */
#define zzGUESS zzsave_antlr_state(&zzst); \
zzguessing = 1; \
zzGuessSeqFrozen=++zzGuessSeq; \
zzrv = setjmp(zzguess_start.state); \
zzUSER_GUESS_HOOK(zzGuessSeqFrozen,zzrv) \
if (zzrv) zzGUESS_DONE;
#ifdef zzTRACE_RULES
#define zzGUESS_FAIL { zzTraceGuessFail(); longjmp(zzguess_start.state, 1); }
#else
#define zzGUESS_FAIL longjmp(zzguess_start.state, 1)
#endif
/* MR10 change zzGUESS_DONE: zzrv=1 to simulate longjmp() return value as in C++ mode */
#define zzGUESS_DONE { zzrestore_antlr_state(&zzst); zzrv=1; zzUSER_GUESS_DONE_HOOK(zzGuessSeqFrozen) }
#define zzNON_GUESS_MODE if ( !zzguessing )
#define zzGuessData \
zzjmp_buf zzguess_start; \
int zzguessing;
#else
#define zzGUESS_BLOCK
#define zzGUESS
#define zzGUESS_FAIL
#define zzGUESS_DONE
#define zzNON_GUESS_MODE
#define zzGuessData
#endif
typedef struct _zzantlr_state {
#ifdef ZZCAN_GUESS
zzjmp_buf guess_start;
int guessing;
#endif
int asp;
int ast_sp;
#ifdef ZZINF_LOOK
int inf_lap; /* not sure we need to save this one */
int inf_labase;
int inf_last;
/* MR6 Gunnar Rxnning (gunnar@candleweb.no) */
/* MR6 Additional state needs to be saved/restored */
/* MR6 Matching changes in err.h */
int *inf_tokens; /* MR6 */
char **inf_text; /* MR6 */
char *inf_text_buffer; /* MR6 */
int *inf_line; /* MR6 */
#endif
#ifdef DEMAND_LOOK
int dirty;
#endif
#ifdef LL_K
int tokenLA[LL_K];
char textLA[LL_K][ZZLEXBUFSIZE];
int lap;
int labase;
#else
int token;
char text[ZZLEXBUFSIZE];
#endif
#ifdef zzTRACE_RULES
int traceOptionValue; /* MR10 */
int traceGuessOptionValue; /* MR10 */
char *traceCurrentRuleName; /* MR10 */
int traceDepth; /* MR10 */
#endif
} zzantlr_state;
#ifdef zzTRACE_RULES
extern int zzTraceOptionValueDefault;
extern int zzTraceOptionValue;
extern int zzTraceGuessOptionValue;
extern char *zzTraceCurrentRuleName;
extern int zzTraceDepth;
#endif
extern int zzGuessSeq; /* MR10 */
extern int zzSyntaxErrCount; /* MR11 */
extern int zzLexErrCount; /* MR11 */
/* I n f i n i t e L o o k a h e a d */
#ifdef ZZINF_LOOK
#define InfLookData \
int *zzinf_tokens; \
char **zzinf_text; \
char *zzinf_text_buffer; \
int *zzinf_line; \
int zzinf_labase; \
int zzinf_last;
#else
#define InfLookData
#endif
#ifdef ZZINF_LOOK
#ifndef ZZINF_DEF_TEXT_BUFFER_SIZE
#define ZZINF_DEF_TEXT_BUFFER_SIZE 20000
#endif
#ifndef ZZINF_DEF_TOKEN_BUFFER_SIZE
#define ZZINF_DEF_TOKEN_BUFFER_SIZE 2000
#endif
/* WARNING!!!!!!
* ZZINF_BUFFER_TEXT_CHUNK_SIZE must be > sizeof(text) largest possible token.
*/
#ifndef ZZINF_BUFFER_TEXT_CHUNK_SIZE
#define ZZINF_BUFFER_TEXT_CHUNK_SIZE 5000
#endif
#ifndef ZZINF_BUFFER_TOKEN_CHUNK_SIZE
#define ZZINF_BUFFER_TOKEN_CHUNK_SIZE 1000
#endif
#if ZZLEXBUFSIZE > ZZINF_BUFFER_TEXT_CHUNK_SIZE
#define ZZINF_BUFFER_TEXT_CHUNK_SIZE ZZLEXBUFSIZE+5
#endif
/* make inf_look user-access macros */
#ifdef LL_K
#define ZZINF_LA_VALID(i) (((zzinf_labase+i-1)-LL_K+1) <= zzinf_last)
#define ZZINF_LA(i) zzinf_tokens[(zzinf_labase+i-1)-LL_K+1]
#define ZZINF_LATEXT(i) zzinf_text[(zzinf_labase+i-1)-LL_K+1]
/* MR6 In 1.33 vanilla the #define ZZINF_LINE(i) is was commented out */
#define ZZINF_LINE(i) zzinf_line[(zzinf_labase+i-1)-LL_K+1]
#else
#define ZZINF_LA_VALID(i) (((zzinf_labase+i-1)) <= zzinf_last)
#define ZZINF_LA(i) zzinf_tokens[(zzinf_labase+i-1)]
#define ZZINF_LATEXT(i) zzinf_text[(zzinf_labase+i-1)]
#endif
#define inf_zzgettok _inf_zzgettok()
extern void _inf_zzgettok();
#endif /* ZZINF_LOOK */
#ifdef LL_K
#ifdef __USE_PROTOS
#define ANTLR_INFO \
Attrib zzempty_attr(void) {static Attrib a; return a;} \
Attrib zzconstr_attr(int _tok, char *_text) \
{Attrib a; zzcr_attr((&a),_tok,_text); return a;} \
int zzasp=ZZA_STACKSIZE; \
char zzStackOvfMsg[]="fatal: attrib/AST stack overflow %s(%d)!\n"; \
Attrib zzaStack[ZZA_STACKSIZE]; DemandLookData \
InfLookData \
zzGuessData
#else
#define ANTLR_INFO \
Attrib zzempty_attr() {static Attrib a; return a;} \
Attrib zzconstr_attr(_tok, _text) int _tok; char *_text; \
{Attrib a; zzcr_attr((&a),_tok,_text); return a;} \
int zzasp=ZZA_STACKSIZE; \
char zzStackOvfMsg[]="fatal: attrib/AST stack overflow %s(%d)!\n"; \
Attrib zzaStack[ZZA_STACKSIZE]; DemandLookData \
InfLookData \
zzGuessData
#endif
#else
#ifdef __USE_PROTOS
#define ANTLR_INFO \
Attrib zzempty_attr(void) {static Attrib a; return a;} \
Attrib zzconstr_attr(int _tok, char *_text) \
{Attrib a; zzcr_attr((&a),_tok,_text); return a;} \
int zzasp=ZZA_STACKSIZE; \
char zzStackOvfMsg[]="fatal: attrib/AST stack overflow %s(%d)!\n"; \
Attrib zzaStack[ZZA_STACKSIZE]; DemandLookData \
InfLookData \
zzGuessData
#else
#define ANTLR_INFO \
Attrib zzempty_attr() {static Attrib a; return a;} \
Attrib zzconstr_attr(_tok, _text) int _tok; char *_text; \
{Attrib a; zzcr_attr((&a),_tok,_text); return a;} \
int zzasp=ZZA_STACKSIZE; \
char zzStackOvfMsg[]="fatal: attrib/AST stack overflow %s(%d)!\n"; \
Attrib zzaStack[ZZA_STACKSIZE]; DemandLookData \
InfLookData \
zzGuessData
#endif
#endif /* LL_k */
#ifdef ZZINF_LOOK
#ifdef LL_K
#ifdef DEMAND_LOOK
#define zzPrimeLookAhead {zzdirty=LL_K; zzlap = zzlabase = 0;}
#else
#define zzPrimeLookAhead {zzlap = zzlabase = 0; zzfill_inf_look();\
{int _i; for(_i=1;_i<=LL_K; _i++) \
{zzCONSUME;} zzlap = zzlabase = 0;}}
#endif
#else /* LL_K */
#ifdef DEMAND_LOOK
#define zzPrimeLookAhead zzfill_inf_look(); zzdirty=1
#else
#define zzPrimeLookAhead zzfill_inf_look(); inf_zzgettok
#endif
#endif /* LL_K */
#else /* ZZINF_LOOK */
#ifdef LL_K
#ifdef DEMAND_LOOK
#define zzPrimeLookAhead {zzdirty=LL_K; zzlap = zzlabase = 0;}
#else
#define zzPrimeLookAhead {int _i; zzlap = 0; for(_i=1;_i<=LL_K; _i++) \
{zzCONSUME;} zzlap = 0;}
#endif
#else
#ifdef DEMAND_LOOK
#define zzPrimeLookAhead zzdirty=1
#else
#define zzPrimeLookAhead zzgettok()
#endif
#endif /* LL_K */
#endif /* ZZINF_LOOK */
#ifdef LL_K
#define zzenterANTLRs(s) \
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?