AParser.cpp revision 4fd606d1f5abe38e1f42c38de1d2e895166bd0f4
/* ANTLRParser.C
*
* 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
*/
#include "pcctscfg.h"
#include "pccts_stdlib.h"
#include "pccts_stdarg.h"
#include "pccts_string.h"
#include "pccts_stdio.h"
/* I have to put this here due to C++ limitation
* that you can't have a 'forward' decl for enums.
* I hate C++!!!!!!!!!!!!!!!
* Of course, if I could use real templates, this would go away.
*/
// MR1
// MR1 10-Apr-97 133MR1 Prevent use of varying sizes for the
// MR1 ANTLRTokenType enum
// MR1
#define ANTLR_SUPPORT_CODE
#include ATOKEN_H
#include ATOKENBUFFER_H
#include APARSER_H
/* L o o k a h e a d M a c r o s */
* we only use 8 bits of it.
*/
0x00000001, 0x00000002, 0x00000004, 0x00000008,
0x00000010, 0x00000020, 0x00000040, 0x00000080
};
~ANTLRParser()
{
delete [] token_type;
delete [] zzFAILtext; // MR16 Manfred Kogler
}
int k,
int use_inf_look,
int dlook,
int ssize)
{
LLk = k;
/* MR14 */ if (dlook != 0) {
/* MR14 */
/* MR14 */ };
demand_look = 0; /* demand_look = dlook; */
guessing = 0;
// allocate lookahead buffer
lap = 0;
labase = 0;
#ifdef ZZDEFER_FETCH
stillToFetch = 0; // MR19
#endif
dirty = 0;
inf_labase = 0; // MR7
inf_last = 0; // MR7
/* prime lookahead buffer, point to inputTokens */
this->inputTokens = _inputTokens;
this->inputTokens->setMinTokens(k);
traceOptionValueDefault=0; // MR10
traceReset(); // MR10
zzGuessSeq=0; // MR10
syntaxErrCount=0; // MR11
}
void ANTLRParser::init()
{
traceReset(); // MR10
}
void ANTLRParser::traceReset()
{
traceDepth=0;
}
#ifdef _MSC_VER // MR23
//Turn off warning:
//interaction between '_setjmp' and C++ object destruction is non-portable
#endif
int ANTLRParser::
{
guessing = 1;
}
#ifdef _MSC_VER // MR23
#pragma warning(default: 4611)
#endif
void ANTLRParser::
{
}
void ANTLRParser::
{
int i;
int prevTraceOptionValue;
// restore lookahead buffer from k tokens before restored TokenBuffer position
// if demand_look, then I guess we don't look backwards for these tokens.
lap = 0;
labase = 0;
/* MR10 */
if ( (prevTraceOptionValue > 0) !=
(traceOptionValue > 0)) {
if (traceOptionValue > 0) {
"trace enable restored in rule %s depth %d\n",
};
if (traceOptionValue <= 0) {
"trace disable restored in rule %s depth %d\n",
traceCurrentRuleName, /* MR21 */
};
}
};
}
/* Get the next symbol from the input stream; put it into lookahead buffer;
* fill token_type[] fast reference cache also. NLA is the next place where
* a lookahead ANTLRAbstractToken should go.
*/
void ANTLRParser::
consume()
{
#ifdef ZZDEBUG_CONSUME_ACTION
#endif
// MR19 V.H. Simonis
// Defer Fetch feature
// Moves action of consume() into LA() function
#ifdef ZZDEFER_FETCH
stillToFetch++;
#else
dirty--;
#endif
}
LT(int i)
{
// MR19 V.H. Simonis
// Defer Fetch feature
// Moves action of consume() into LA() function
#ifdef ZZDEFER_FETCH
undeferFetch();
#endif
#ifdef DEBUG_TOKENBUFFER
{
sprintf(buf, "The minimum number of tokens you requested that the\nANTLRTokenBuffer buffer is not enough to satisfy your\nLT(%d) request; increase 'k' argument to constructor for ANTLRTokenBuffer\n", i);
}
#endif
}
void
look(int k)
{
for (i=1; i<=c; i++) consume();
}
/* fill the lookahead buffer up with k symbols (even if DEMAND_LOOK);
*/
void
{
int i;
dirty=0;
// lap = 0; // MR14 Sinan Karasu (sinan.karasu@boeing.com)
// labase = 0; // MR14
}
/* check to see if the current input symbol matches '_t'.
* During NON demand lookahead mode, dirty will always be 0 and
* hence the extra code for consuming tokens in _match is never
* executed; the same routine can be used for both modes.
*/
int ANTLRParser::
{
consume();
}
return 0;
}
dirty++;
return 1;
}
/* check to see if the current input symbol matches '_t'.
* Used during exception handling.
*/
int ANTLRParser::
{
consume();
}
dirty++;
return 1;
}
/* check to see if the current input symbol matches any token in a set.
* During NON demand lookahead mode, dirty will always be 0 and
* hence the extra code for consuming tokens in _match is never
* executed; the same routine can be used for both modes.
*/
int ANTLRParser::
{
consume();
}
return 0;
}
dirty++;
return 1;
}
int ANTLRParser::
{
consume();
}
dirty++;
return 1;
}
/* Exception handling routines */
//
// 7-Apr-97 133MR1
// Change suggested by Eli Sternheim (eli@interhdl.com)
//
void ANTLRParser::
{
}
//
// 7-Apr-97 133MR1
// Change suggested by Eli Sternheim (eli@interhdl.com)
//
void ANTLRParser::
consumeUntilToken(int t)
{
int tmp; // MR1
}
/* Old error stuff */
void ANTLRParser::
{
/* MR8 S.Bochnak@microtool.com.pl */
/* MR8 Change file scope static "consumed" to instance var */
/* if you enter here without having consumed a token from last resynch
* force a token consumption.
*/
/* if current token is in resynch set, we've got what we wanted */
/* scan until we find something in the resynch set */
}
/* standard error reporting function that assumes DLG-based scanners;
* you should redefine in subclass to change it or if you use your
* own scanner.
*/
/* MR23 THM There appears to be a parameter "badText" passed to syn()
which is not present in the parameter list. This may be
because in C mode there is no attribute function which
returns the text, so the text representation of the token
must be passed explicitly. I think.
*/
void ANTLRParser::
ANTLRTokenType etok, int k)
{
int line;
syntaxErrCount++; /* MR11 */
/* MR23 If the token is not an EOF token, then use the ->getText() value.
If the token is the EOF token the text returned by ->getText()
may be garbage. If the text from the token table is "@" use
"<eof>" instead, because end-users don't know what "@" means.
If the text is not "@" then use that text, which must have been
supplied by the grammar writer.
*/
}
else
{
}
}
/* is b an element of set p? */
int ANTLRParser::
{
}
int ANTLRParser::
set_deg(SetWordType *a)
{
/* Fast compute degree of a set... the number
of elements present in the set. Assumes
that all word bits are used in the set
*/
register SetWordType *p = a;
register int degree = 0;
if ( a == NULL ) return 0;
while ( p < endp )
{
register SetWordType t = *p;
register SetWordType *b = &(bitmask[0]);
do {
if (t & *b) ++degree;
p++;
}
return(degree);
}
void ANTLRParser::
edecode(SetWordType *a)
{
register SetWordType *p = a;
register unsigned e = 0;
do {
register SetWordType t = *p;
register SetWordType *b = &(bitmask[0]);
do {
e++;
} while (++p < endp);
}
/* input looks like:
* zzFAIL(k, e1, e2, ...,&zzMissSet,&zzMissText,&zzBadTok,&zzBadText,&zzErrk)
* where the zzMiss stuff is set here to the token that did not match
* (and which set wasn't it a member of).
*/
// MR9 29-Sep-97 Stan Bochnak (S.Bochnak@microTool.com.pl)
// MR9 Original fix to static allocated text didn't
// MR9 work because a pointer to it was passed back
// MR9 to caller. Replace with instance variable.
const int SETWORDCOUNT=20;
void
ANTLRParser::FAIL(int k, ...)
{
//
// MR1 10-Apr-97
//
//
// 7-Apr-97 133MR1
// err_k is passed as a "int *", not "unsigned *"
//
int *err_k; // MR1
int i;
zzFAILtext[0] = '\0';
for (i=1; i<=k; i++) /* collect all lookahead sets */
{
}
for (i=1; i<=k; i++) /* look for offending token */
{
}
if ( i>k )
{
/* bad; lookahead is permutation that cannot be matched,
* but, the ith token of lookahead is valid at the ith position
* (The old LL sub 1 (k) versus LL(k) parsing technique)
*/
*err_k = k;
//
// MR4 20-May-97 erroneously deleted contents of f[]
// MR4 reported by Bruce Guenter (bruceg@qcc.sk.ca)
// MR1 10-Apr-97 release temporary storage
//
delete [] f; // MR1
return; // MR1
}
/* MR23 printMessage(stderr, "%s not in %dth set\n", zztokens[LA(i)], i);*/
*miss_set = f[i-1];
*miss_text = zzFAILtext;
else *err_k = k;
//
// MR4 20-May-97 erroneously deleted contents of f[]
// MR4 reported by Bruce Guenter (bruceg@qcc.sk.ca)
// MR1 10-Apr-97 release temporary storage
//
delete [] f; // MR1
return; // MR1
}
int ANTLRParser::
{
{
syntaxErrCount++; /* MR11 */
"line %d: syntax error at \"%s\" missing %s\n",
return 0;
}
else {
dirty++;
/* if ( !demand_look ) consume(); */
return 1;
}
}
int ANTLRParser::
{
{
syntaxErrCount++; /* MR11 */
"line %d: syntax error at \"%s\" missing %s\n",
return 0;
}
else {
dirty++;
/* if ( !demand_look ) consume(); */
return 1;
}
}
char *ANTLRParser::
{
return eMsgBuffer;
}
char *ANTLRParser::
{
return eMsgBuffer;
}
char *ANTLRParser::
{
return eMsgBuffer;
}
void ANTLRParser::
{
}
} // MR1
int doIt=0;
if (traceCurrentRuleName == NULL) return;
if (traceOptionValue <= 0) {
doIt=0;
} else if (traceGuessOptionValue <= 0) {
doIt=0;
} else {
doIt=1;
};
if (doIt) {
state->traceDepth);
} else {
};
};
}
void ANTLRParser::traceGuessFail() {
int doIt=0;
if (traceOptionValue <= 0) {
doIt=0;
} else if (guessing && traceGuessOptionValue <= 0) {
doIt=0;
} else {
doIt=1;
};
if (doIt) {
};
}
/* traceOption:
zero value turns off trace
*/
int doIt=0;
traceDepth++;
if (traceOptionValue <= 0) {
doIt=0;
} else if (guessing && traceGuessOptionValue <= 0) {
doIt=0;
} else {
doIt=1;
};
if (doIt) {
rule,
};
return;
}
int doIt=0;
traceDepth--;
if (traceOptionValue <= 0) {
doIt=0;
} else if (guessing && traceGuessOptionValue <= 0) {
doIt=0;
} else {
doIt=1;
};
if (doIt) {
rule,
traceDepth+1);
};
}
if (traceCurrentRuleName != NULL) {
if (prevValue <= 0 && traceOptionValue > 0) {
/* MR23 */ printMessage(stderr,"trace enabled in rule %s depth %d\n",traceCurrentRuleName,traceDepth);
};
if (prevValue > 0 && traceOptionValue <= 0) {
/* MR23 */ printMessage(stderr,"trace disabled in rule %s depth %d\n",traceCurrentRuleName,traceDepth);
};
};
return prevValue;
}
if (traceCurrentRuleName != NULL) {
if (prevValue <= 0 && traceGuessOptionValue > 0) {
/* MR23 */ printMessage(stderr,"guess trace enabled in rule %s depth %d\n",traceCurrentRuleName,traceDepth);
};
if (prevValue > 0 && traceGuessOptionValue <= 0) {
/* MR23 */ printMessage(stderr,"guess trace disabled in rule %s depth %d\n",traceCurrentRuleName,traceDepth);
};
};
return prevValue;
}
// MR19 V.H. Simonis Defer Fetch feature
void ANTLRParser::undeferFetch()
{
#ifdef ZZDEFER_FETCH
if (stillToFetch) {
dirty--;
}
stillToFetch = 0;
}
#else
return;
#endif
}
int ANTLRParser::isDeferFetchEnabled()
{
#ifdef ZZDEFER_FETCH
return 1;
#else
return 0;
#endif
}
//MR23
{
return iRet;
}
{
}
// MR23 Move semantic predicate error handling from macro to virtual function
//
// Called by the zzfailed_pred
{
}