AParser.h revision 4fd606d1f5abe38e1f42c38de1d2e895166bd0f4
*
* Define the generic ANTLRParser superclass, which is subclassed to
* define an actual parser.
*
* Before entry into this file: ANTLRTokenType must be set.
*
* 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 APARSER_H_GATE
#define APARSER_H_GATE
#include "pcctscfg.h"
#include "pccts_stdio.h"
#include "pccts_setjmp.h"
#include ATOKEN_H
#include ATOKENBUFFER_H
#ifdef ZZCAN_GUESS
#ifndef ZZINF_LOOK
#define ZZINF_LOOK
#endif
#endif
typedef unsigned char SetWordType;
/* Define external bit set stuff (for SetWordType) */
#define EXT_WORDSIZE (sizeof(char)*8)
#define EXT_LOGWORDSIZE 3
/* s y n t a c t i c p r e d i c a t e s t u f f */
#ifndef zzUSER_GUESS_HOOK
#endif
#ifndef zzUSER_GUESS_DONE_HOOK
#define zzUSER_GUESS_DONE_HOOK(seqFrozen)
#endif
/* MR14 Add zzUSER_GUESS_FAIL_HOOK and related code */
#ifndef zzUSER_GUESS_FAIL_HOOK
#define zzUSER_GUESS_FAIL_HOOK(zzGuessSeq)
#endif
typedef struct _zzjmp_buf {
} zzjmp_buf;
/* these need to be macros not member functions */
#define zzNON_GUESS_MODE if ( !guessing )
#define zzGUESS_FAIL guess_fail();
/* Note: zzGUESS_DONE does not execute longjmp() */
#define zzGUESS_DONE {zzrv=1; inputTokens->rewind(_marker); guess_done(&zzst);zzUSER_GUESS_DONE_HOOK(zzGuessSeqFrozen) }
guessing = 1; \
zzGuessSeqFrozen = ++zzGuessSeq; \
if ( zzrv ) zzGUESS_DONE
#ifndef zzTRACEIN
#endif
#ifndef zzTRACEOUT
#endif
/* a n t l r p a r s e r d e f */
struct ANTLRParserState {
/* class variables */
int guessing;
int inf_labase;
int inf_last;
int dirty;
int traceOptionValue; // MR10
int traceGuessOptionValue; // MR10
int traceDepth; // MR10
};
/* notes:
*
* multiple inheritance is a cool way to include what stuff is needed
* in this structure (like guess stuff). however, i'm not convinced that
* multiple inheritance works correctly on all platforms. not that
* much space is used--just include all possibly useful members.
*
* the class should also be a template with arguments for the lookahead
* depth and so on. that way, more than one parser can be defined (as
* each will probably have different lookahead requirements). however,
* am i sure that templates work? no, i'm not sure.
*
* no attributes are maintained and, hence, the 'asp' variable is not
* needed. $i can still be referenced, but it refers to the token
* associated with that rule element. question: where are the token's
* stored if not on the software stack? in local variables created
* and assigned to by antlr.
*/
/* class variables */
static char eMsgBuffer[500];
int LLk; // number of lookahead symbols (old LL_K)
int demand_look;
int bsetsize; // size of bitsets created by ANTLR in
// units of SetWordType
int guessing; // if guessing (using (...)? predicate)
// infinite lookahead stuff
int can_use_inf_look; // set by subclass (generated by ANTLR)
int inf_lap;
int inf_labase;
int inf_last;
int *_inf_line;
int dirty; // used during demand lookahead
// ANTLRLightweightToken **token; // the token with all its attributes
int lap;
int labase;
#ifdef ZZDEFER_FETCH
int stillToFetch; // MR19 V.H. Simonis
#endif
void fill_inf_look();
traceGuessFail(); // MR10
void look(int);
_ANTLRTokenPtr *, SetWordType **);
_ANTLRTokenPtr *, SetWordType **,
int _match_wsig(ANTLRTokenType);
int _setmatch_wsig(SetWordType *);
void prime_lookahead();
int set_deg(SetWordType *);
int traceOptionValue; // MR10
int traceGuessOptionValue; // MR10
int traceDepth; // MR10
void traceReset(); // MR10
int zzGuessSeq; // MR10
int k=1,
int use_inf_look=0,
int demand_look=0,
int bsetsize=1);
virtual ~ANTLRParser();
ANTLRTokenType LA(int i)
{
//
// MR14 demand look will always be 0 for C++ mode
//
//// return demand_look ? token_type[(labase+(i)-1)&(LLk-1)] :
//// token_type[(lap+(i)-1)&(LLk-1)];
// MR19 V.H. Simonis Defer fetch feature
#ifdef ZZDEFER_FETCH
undeferFetch();
#endif
}
_ANTLRTokenPtr LT(int i);
static char *eMsgd(char *,int);
static char *eMsg(char *,char *);
static char *eMsg2(char *,char *,char *);
void consumeUntilToken(int t);
int traceOptionValueDefault; // MR11
// MR8 5-Aug-97 S.Bochnak@microtool.com.pl
// MR8 Move resynch static local variable
// MR8 to class instance
int syntaxErrCount; // MR12
protected: // MR8
int resynchConsumed; // MR8
char *zzFAILtext; // workarea required by zzFAIL // MR9
void undeferFetch(); // MR19 V.H. Simonis
int isDeferFetchEnabled(); // MR19 V.H. Simonis
};
if ( !_match_wsig((ANTLRTokenType)_t) ) if ( guessing ) zzGUESS_FAIL else {_signal=MismatchedToken; goto handler;}
if ( !_setmatch_wsig(_ts) ) if ( guessing ) zzGUESS_FAIL else {_signal=MismatchedToken; goto handler;}
/* For the dflt signal matchers, a FALSE indicates that an error occurred
* just like the other matchers, but in this case, the routine has already
* recovered--we do NOT want to consume another token. However, when
* the match was successful, we do want to consume hence _signal=0 so that
* a token is consumed by the "if (!_signal) consume(); _signal=NoSignal;"
* preamble.
*/
// MR1 10-Apr-97 zzfailed_pred() macro does not backtrack in guess mode.
// MR1 Identification and correction due to J. Lilley
//
// MR23 Call virtual method to report error.
// MR23 Provide more control over failed predicate action
// without any need for user to worry about guessing internals.
#ifndef zzfailed_pred
if (guessing) { \
zzGUESS_FAIL; \
} else { \
}
#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
#endif
#define zzRULE \
#endif
/* S t a n d a r d E x c e p t i o n S i g n a l s */
#define NoSignal 0
#define MismatchedToken 1
#define NoViableAlt 2
#define NoSemViableAlt 3
/* MR7 Allow more control over signalling */
/* by adding "Unwind" and "SetSignal" */
#define Unwind 4