📄 antlr.c
字号:
return;
fail:
zzEXIT(zztasp1);
CannotContinue=TRUE;
zzsyn(zzMissText, zzBadTok, (ANTLRChar *)"", zzMissSet, zzMissTok, zzErrk, zzBadText);
zzresynch(setwd4, 0x20);
}
}
void
#ifdef __USE_PROTOS
token(void)
#else
token()
#endif
{
zzRULE;
zzBLOCK(zztasp1);
zzMake0;
{
char *t=NULL, *e=NULL, *a=NULL; int tnum=0;
char *akaString=NULL; TermEntry *te;int save_file=0,save_line=0;
zzmatch(120);
tokenActionActive=1;
zzCONSUME;
{
zzBLOCK(zztasp2);
zzMake0;
{
if ( (LA(1)==TokenTerm) ) {
zzmatch(TokenTerm);
t=mystrdup(LATEXT(1));
zzCONSUME;
{
zzBLOCK(zztasp3);
zzMake0;
{
if ( (LA(1)==114) ) {
zzmatch(114); zzCONSUME;
zzmatch(QuotedTerm);
akaString=mystrdup(StripQuotes(LATEXT(1)));
/* MR11 */ save_file=CurFile;save_line=zzline;
/* MR11 */
zzCONSUME;
zzmatch(115); zzCONSUME;
}
else {
if ( (setwd4[LA(1)]&0x40) ) {
}
else {zzFAIL(1,zzerr20,&zzMissSet,&zzMissText,&zzBadTok,&zzBadText,&zzErrk); goto fail;}
}
zzEXIT(zztasp3);
}
}
{
zzBLOCK(zztasp3);
zzMake0;
{
if ( (LA(1)==121) ) {
zzmatch(121); zzCONSUME;
zzmatch(122);
tnum = atoi(LATEXT(1));
zzCONSUME;
}
else {
if ( (setwd4[LA(1)]&0x80) ) {
}
else {zzFAIL(1,zzerr21,&zzMissSet,&zzMissText,&zzBadTok,&zzBadText,&zzErrk); goto fail;}
}
zzEXIT(zztasp3);
}
}
}
else {
if ( (setwd5[LA(1)]&0x1) ) {
}
else {zzFAIL(1,zzerr22,&zzMissSet,&zzMissText,&zzBadTok,&zzBadText,&zzErrk); goto fail;}
}
zzEXIT(zztasp2);
}
}
{
zzBLOCK(zztasp2);
zzMake0;
{
if ( (LA(1)==QuotedTerm) ) {
zzmatch(QuotedTerm);
e=mystrdup(LATEXT(1));
zzCONSUME;
}
else {
if ( (setwd5[LA(1)]&0x2) ) {
}
else {zzFAIL(1,zzerr23,&zzMissSet,&zzMissText,&zzBadTok,&zzBadText,&zzErrk); goto fail;}
}
zzEXIT(zztasp2);
}
}
{
zzBLOCK(zztasp2);
zzMake0;
{
if ( (LA(1)==Action) ) {
zzmatch(Action);
a = (char *) calloc(strlen(LATEXT(1))+1, sizeof(char));
require(a!=NULL, "rule token: cannot allocate action");
strcpy(a, LATEXT(1));
zzCONSUME;
}
else {
if ( (setwd5[LA(1)]&0x4) ) {
}
else {zzFAIL(1,zzerr24,&zzMissSet,&zzMissText,&zzBadTok,&zzBadText,&zzErrk); goto fail;}
}
zzEXIT(zztasp2);
}
}
{
zzBLOCK(zztasp2);
zzMake0;
{
if ( (LA(1)==107) ) {
zzmatch(107); zzCONSUME;
}
else {
if ( (setwd5[LA(1)]&0x8) ) {
}
else {zzFAIL(1,zzerr25,&zzMissSet,&zzMissText,&zzBadTok,&zzBadText,&zzErrk); goto fail;}
}
zzEXIT(zztasp2);
}
}
chkToken(t, e, a, tnum);
if (t != NULL) {
te=(TermEntry *)hash_get(Tname,t);
if (te != NULL && akaString != NULL) {
if (te->akaString != NULL) {
if (strcmp(te->akaString,akaString) != 0) {
warnFL(eMsg2("this #token statment conflicts with a previous #token %s(\"%s\") statement",
t,te->akaString),
FileStr[save_file],save_line);
};
} else {
te->akaString=akaString;
};
};
};
zzEXIT(zztasp1);
return;
fail:
zzEXIT(zztasp1);
CannotContinue=TRUE;
zzsyn(zzMissText, zzBadTok, (ANTLRChar *)"", zzMissSet, zzMissTok, zzErrk, zzBadText);
zzresynch(setwd5, 0x10);
}
}
void
#ifdef __USE_PROTOS
block(set * toksrefd,set * rulesrefd)
#else
block(toksrefd,rulesrefd)
set *toksrefd;
set *rulesrefd ;
#endif
{
zzRULE;
zzBLOCK(zztasp1);
zzMake0;
{
Graph g, b;
set saveblah;
int saveinalt = inAlt;
ExceptionGroup *eg;
* toksrefd = empty;
* rulesrefd = empty;
set_clr(AST_nodes_refd_in_actions);
CurBlockID++;
/* MR23 */ CurBlockID_array[BlkLevel] = CurBlockID;
CurAltNum = 1;
/* MR23 */ CurAltNum_array[BlkLevel] = CurAltNum;
saveblah = attribsRefdFromAction;
attribsRefdFromAction = empty;
alt( toksrefd,rulesrefd );
b = g = zzaArg(zztasp1,1);
if ( ((Junction *)g.left)->p1->ntype == nAction )
{
ActionNode *actionNode=(ActionNode *)
( ( (Junction *)g.left) ->p1);
if (!actionNode->is_predicate )
{
actionNode->init_action = TRUE;
/* MR12c */ if (actionNode->noHoist) {
/* MR12c */ errFL("<<nohoist>> appears as init-action - use <<>> <<nohoist>>",
/* MR12c */ FileStr[actionNode->file],actionNode->line);
/* MR12c */ };
}
}
((Junction *)g.left)->blockid = CurBlockID;
{
zzBLOCK(zztasp2);
zzMake0;
{
while ( (LA(1)==133) ) {
eg = exception_group();
if ( eg!=NULL ) {
/* MR7 ***** eg->altID = makeAltID(CurBlockID,CurAltNum); *****/
/* MR7 ***** CurAltStart->exception_label = eg->altID; *****/
list_add(&CurExGroups, (void *)eg);
}
zzLOOP(zztasp2);
}
zzEXIT(zztasp2);
}
}
CurAltNum++;
/* MR23 */ CurAltNum_array[BlkLevel] = CurAltNum;
{
zzBLOCK(zztasp2);
zzMake0;
{
while ( (LA(1)==123) ) {
zzmatch(123);
inAlt=1;
zzCONSUME;
alt( toksrefd,rulesrefd );
g = Or(g, zzaArg(zztasp2,2));
((Junction *)g.left)->blockid = CurBlockID;
{
zzBLOCK(zztasp3);
zzMake0;
{
while ( (LA(1)==133) ) {
eg = exception_group();
if ( eg!=NULL ) {
/* MR7 ***** eg->altID = makeAltID(CurBlockID,CurAltNum); *****/
/* MR7 ***** CurAltStart->exception_label = eg->altID; *****/
list_add(&CurExGroups, (void *)eg);
}
zzLOOP(zztasp3);
}
zzEXIT(zztasp3);
}
}
CurAltNum++;
/* MR23 */ CurAltNum_array[BlkLevel] = CurAltNum;
zzLOOP(zztasp2);
}
zzEXIT(zztasp2);
}
}
zzaArg(zztasp1,0) = b;
attribsRefdFromAction = saveblah; inAlt = saveinalt;
zzEXIT(zztasp1);
return;
fail:
zzEXIT(zztasp1);
CannotContinue=TRUE;
zzsyn(zzMissText, zzBadTok, (ANTLRChar *)"", zzMissSet, zzMissTok, zzErrk, zzBadText);
zzresynch(setwd5, 0x20);
}
}
void
#ifdef __USE_PROTOS
alt(set * toksrefd,set * rulesrefd)
#else
alt(toksrefd,rulesrefd)
set *toksrefd;
set *rulesrefd ;
#endif
{
zzRULE;
zzBLOCK(zztasp1);
zzMake0;
{
int n=0; Graph g; int e_num=0, old_not=0; Node *node; set elems, dif;
int first_on_line = 1, use_def_MT_handler = 0;
g.left=NULL; g.right=NULL;
CurAltStart = NULL;
elems = empty;
inAlt = 1;
{
zzBLOCK(zztasp2);
zzMake0;
{
if ( (LA(1)==88) ) {
zzmatch(88);
use_def_MT_handler = 1;
zzCONSUME;
}
else {
if ( (setwd5[LA(1)]&0x40) ) {
}
else {zzFAIL(1,zzerr26,&zzMissSet,&zzMissText,&zzBadTok,&zzBadText,&zzErrk); goto fail;}
}
zzEXIT(zztasp2);
}
}
{
zzBLOCK(zztasp2);
zzMake0;
{
;
while ( (setwd5[LA(1)]&0x80) ) {
{
zzBLOCK(zztasp3);
zzMake0;
{
old_not=0;
if ( (LA(1)==124) ) {
zzmatch(124);
old_not=1;
zzCONSUME;
}
else {
if ( (setwd6[LA(1)]&0x1) ) {
}
else {zzFAIL(1,zzerr27,&zzMissSet,&zzMissText,&zzBadTok,&zzBadText,&zzErrk); goto fail;}
}
zzEXIT(zztasp3);
}
}
node = element( old_not, first_on_line, use_def_MT_handler );
if ( node!=NULL && node->ntype!=nAction ) first_on_line = 0;
if ( zzaArg(zztasp2,2 ).left!=NULL ) {
g = Cat(g, zzaArg(zztasp2,2));
n++;
if ( node!=NULL ) {
if ( node->ntype!=nAction ) e_num++;
/* record record number of all rule and token refs */
if ( node->ntype==nToken ) {
TokNode *tk = (TokNode *)((Junction *)zzaArg(zztasp2,2 ).left)->p1;
tk->elnum = e_num;
set_orel(e_num, &elems);
}
else if ( node->ntype==nRuleRef ) {
RuleRefNode *rn = (RuleRefNode *)((Junction *)zzaArg(zztasp2,2 ).left)->p1;
rn->elnum = e_num;
set_orel(e_num, rulesrefd);
}
}
}
zzLOOP(zztasp2);
}
zzEXIT(zztasp2);
}
}
if ( n == 0 ) g = emptyAlt();
zzaArg(zztasp1,0) = g;
/* We want to reduce number of LT(i) calls and the number of
* local attribute variables in C++ mode (for moment, later we'll
* do for C also). However, if trees are being built, they
* require most of the attrib variables to create the tree nodes
* with; therefore, we gen a token ptr for each token ref in C++
*/
if ( GenCC && !GenAST )
{
/* This now free's the temp set -ATG 5/6/95 */
set temp;
temp = set_and(elems, attribsRefdFromAction);
set_orin( toksrefd, temp);
set_free(temp);
}
else set_orin( toksrefd, elems);
if ( GenCC ) {
dif = set_dif(attribsRefdFromAction, elems);
if ( set_deg(dif)>0 )
err("one or more $i in action(s) refer to non-token elements");
set_free(dif);
}
set_free(elems);
set_free(attribsRefdFromAction);
inAlt = 0;
zzEXIT(zztasp1);
return;
fail:
zzEXIT(zztasp1);
CannotContinue=TRUE;
zzsyn(zzMissText, zzBadTok, (ANTLRChar *)"", zzMissSet, zzMissTok, zzErrk, zzBadText);
zzresynch(setwd6, 0x2);
}
}
LabelEntry *
#ifdef __USE_PROTOS
element_label(void)
#else
element_label()
#endif
{
LabelEntry * _retv;
zzRULE;
zzBLOCK(zztasp1);
PCCTS_PURIFY(_retv,sizeof(LabelEntry * ))
zzMake0;
{
TermEntry *t=NULL; LabelEntry *l=NULL; RuleEntry *r=NULL; char *lab;
zzmatch(LABEL);
lab = mystrdup(LATEXT(1));
zzCONSUME;
UsedNewStyleLabel = 1;
if ( UsedOldStyleAttrib ) err("cannot mix with new-style labels with old-style $i");
t = (TermEntry *) hash_get(Tname, lab);
if ( t==NULL ) t = (TermEntry *) hash_get(Texpr, lab);
if ( t==NULL ) r = (RuleEntry *) hash_get(Rname, lab);
if ( t!=NULL ) {
err(eMsg1("label definition clashes with token/tokclass definition: '%s'", lab));
_retv = NULL;
}
else if ( r!=NULL ) {
err(eMsg1("label definition clashes with rule definition: '%s'", lab));
_retv = NULL;
}
else {
/* we don't clash with anybody else */
l = (LabelEntry *) hash_get(Elabel, lab);
if ( l==NULL ) { /* ok to add new element label */
l = (LabelEntry *)hash_add(Elabel,
lab,
(Entry *)newLabelEntry(lab));
/* add to list of element labels for this rule */
list_add(&CurElementLabels, (void *)lab);
/* MR7 */ leAdd(l); /* list of labels waiting for exception group definitions */
_retv = l;
}
else {
err(eMsg1("label definitions must be unique per rule: '%s'", lab));
_retv = NULL;
}
}
zzmatch(106); zzCONSUME;
zzEXIT(zztasp1);
return _retv;
fail:
zzEXIT(zztasp1);
zzsyn(zzMissText, zzBadTok, (ANTLRChar *)"", zzMissSet, zzMissTok, zzErrk, zzBadText);
zzresynch(setwd6, 0x4);
return _retv;
}
}
Node *
#ifdef __USE_PROTOS
element(int old_not,int first_on_line,int use_def_MT_handler)
#else
element(old_not,first_on_line,use_def_MT_handler)
int old_not;
int first_on_line;
int use_def_MT_handler ;
#endif
{
Node * _retv;
zzRULE;
zzBLOCK(zztasp1);
PCCTS_PURIFY(_retv,sizeof(Node * ))
zzMake0;
{
Attrib blk;
Predicate *pred = NULL;
int local_use_def_MT_handler=0;
ActionNode *act;
RuleRefNode *rr;
set toksrefd, rulesrefd;
TermEntry *term;
TokNode *p=NULL; RuleRefNode *q; int approx=0;
LabelEntry *label=NULL;
int predMsgDone=0;
int semDepth=0;
int ampersandStyle;
int height; /* MR11 */
int equal_height; /* MR11 */
char* pFirstSetSymbol = NULL; /* MR21 */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -