📄 antlr.g
字号:
} if ( p!=NULL ) p->use_def_MT_handler = $use_def_MT_handler || local_use_def_MT_handler; $node = (Node *)p; >> | <<if ( $not ) warn("~ WILDCARD is an undefined operation (implies 'nothing')");>> "." <<$$ = buildWildCard(LATEXT(1)); p=((TokNode *)((Junction *)$$.left)->p1);>> ( "^" <<p->astnode=ASTroot;>> | <<p->astnode=ASTchild;>> | "!" <<p->astnode=ASTexclude;>> ) <<list_add(&MetaTokenNodes, (void *)p);>> << if ( $first_on_line ) { CurAltStart = (Junction *)$$.left; altAdd(CurAltStart); /* MR7 */ p->altstart = CurAltStart; if ( label!=NULL ) { p->el_label = label->str; label->elem = (Node *)p; } } $node = (Node *)p; >> | <<if ( $not ) warn("~ NONTERMINAL is an undefined operation");>> NonTerminal <<$$ = buildRuleRef(LATEXT(1));>> { "!" <<q = (RuleRefNode *) ((Junction *)$$.left)->p1; q->astnode=ASTexclude;>> } { {"\<"} PassAction <<addParm(((Junction *)$$.left)->p1, LATEXT(1));>> } <<rr=(RuleRefNode *) ((Junction *)$$.left)->p1;>> { <<char *a;>> "\>" PassAction << a = (char *) calloc(strlen(LATEXT(1))+1, sizeof(char)); require(a!=NULL, "rule element: cannot allocate assignment"); strcpy(a, LATEXT(1)); rr->assign = a; >> } << if ( label!=NULL ) { rr->el_label = label->str; label->elem = (Node *)rr; } if ( $first_on_line ) { CurAltStart = (Junction *)$$.left; altAdd(CurAltStart); /* MR7 */ ((RuleRefNode *)((Junction *)$$.left)->p1)->altstart = CurAltStart; } $node = (Node *)rr; >> ) | <<if ( $not ) warn("~ ACTION is an undefined operation");>> Action <<$0 = buildAction(LATEXT(1),action_file,action_line, 0);>> <<if ( $first_on_line ) { /* MR7 */ CurAltStart = (Junction *)$0.left; /* MR7 */ altAdd(CurAltStart); /* MR7 */ };>> /* MR7 */ <<$node = (Node *) ((Junction *)$0.left)->p1;>> | <<if ( $not ) warn("~ SEMANTIC-PREDICATE is an undefined operation");>> Pred <<$0 = buildAction(LATEXT(1),action_file,action_line, 1);>> <<act = (ActionNode *) ((Junction *)$0.left)->p1;>> <<if (numericActionLabel) { /* MR10 */ list_add(&NumericPredLabels,act); /* MR10 */ numericActionLabel=0; /* MR10 */ }; /* MR10 */ >> { <<char *a;>> PassAction << a = (char *) calloc(strlen(LATEXT(1))+1, sizeof(char)); require(a!=NULL, "rule element: cannot allocate predicate fail action"); strcpy(a, LATEXT(1)); act->pred_fail = a; >> } <<if ( $first_on_line ) { /* MR7 */ CurAltStart = (Junction *)$0.left; /* MR7 */ altAdd(CurAltStart); /* MR7 */ };>> /* MR7 */ <<$node = (Node *)act;>> | <<if ( $not ) warn("~ BLOCK is an undefined operation");>> <<BlkLevel++;>> { "{\\}#pragma" ( "approx" <<approx=LL_k;>> | "LL(1)" <<approx = 1;>> | "LL(2)" <<approx = 2;>> ) } ( "\(" block[&toksrefd,&rulesrefd] "\)" <<blk = $$ = $2; --BlkLevel;>> ( "\*" <<$$ = makeLoop($$,approx);>> | "\+" <<$$ = makePlus($$,approx);>> | "?" ( ( "=>" <<ampersandStyle=0;>> | "&&" <<ampersandStyle=1;>> /* MR10 (g)? && <<p>>? */ ) Pred /* generalized predicate */ /* first make into a predicate */ <<$$ = buildAction(LATEXT(1),action_file,action_line,1);>> <<act = (ActionNode *) ((Junction *)$$.left)->p1;>> <<semDepth=predicateLookaheadDepth(act);>> /* MR10 */ <<if (numericActionLabel) { /* MR10 */ list_add(&NumericPredLabels,act); /* MR10 */ numericActionLabel=0; /* MR10 */ }; /* MR10 */ >> { <<char *a;>> PassAction << a = (char *)calloc(strlen(LATEXT(1))+1, sizeof(char)); require(a!=NULL, "rule element: cannot allocate predicate fail action"); strcpy(a, LATEXT(1)); act->pred_fail = a; >> } <<if ($first_on_line) { /* MR7 */ CurAltStart=(Junction *)$$.left; /* MR7 */ altAdd(CurAltStart); /* MR7 */ };>> <<$node = (Node *)act;>> /* for now, just snag context */ << pred = computePredicateFromContextGuard(blk,&predMsgDone); /* MR10 */ if ( pred==NULL) { /* MR10 */ if ( !predMsgDone) err("invalid or missing context guard"); /* MR10 */ predMsgDone=1; /* MR10 */ } else { /* MR10 */ act->guardNodes=(Junction *)blk.left; /* MR11 */ pred->expr = act->action; pred->source = act;/* MR10 */ pred->ampersandStyle = ampersandStyle; /* 0 means (g)? => ... 1 means (g)? && ... *//* MR13 */ if (pred->tcontext != NULL) {/* MR13 */ height=MR_max_height_of_tree(pred->tcontext);/* MR13 */ equal_height=MR_all_leaves_same_height(pred->tcontext,height);/* MR13 */ if (! equal_height) {/* MR13 */ errFL("in guarded predicates all tokens in the guard must be at the same height",/* MR13 */ FileStr[act->file],act->line);/* MR13 */ };/* MR13 */ }/* MR10 */ if (ampersandStyle) {/* MR10 */ act->ampersandPred = pred;/* MR11 */ if (! HoistPredicateContext) {/* MR11 */ errFL("without \"-prc on\" (guard)? && <<pred>>? ... doesn't make sense",/* MR11 */ FileStr[act->file],act->line);/* MR11 */ };/* MR10 */ } else {/* MR10 */ act->guardpred = pred;/* MR10 */ };/* MR10 */ if (pred->k != semDepth) {/* MR10 */ warn(eMsgd2("length of guard (%d) does not match the length of semantic predicate (%d)",/* MR10 */ pred->k,semDepth));/* MR10 */ }; } >> | <<$$ = makeBlk($$,approx); FoundGuessBlk = 1; ((Junction *) ((Junction *)$$.left)->p1)->guess=1; if ( !$first_on_line ) { err("(...)? predicate must be first element of production"); } >> ) | <<$$ = makeBlk($$,approx);>> ) << if ( pred==NULL && !predMsgDone) { /* MR10 */ ((Junction *)((Junction *)$$.left)->p1)->blockid = CurBlockID; ((Junction *)((Junction *)$$.left)->p1)->tokrefs = toksrefd; ((Junction *)((Junction *)$$.left)->p1)->rulerefs = rulesrefd; if ( $first_on_line ) { /* MR7 */ CurAltStart = (Junction *)((Junction *)((Junction *)$$.left)->p1); /* MR7 */ altAdd(CurAltStart); /* MR7 */ }; /* MR7 */ $node = (Node *) ((Junction *)$$.left)->p1; } >> | "\{" block[&toksrefd,&rulesrefd] <<$$ = makeOpt($2,approx); --BlkLevel;>> "\}" << ((Junction *)((Junction *)$$.left)->p1)->blockid = CurBlockID; ((Junction *)((Junction *)$$.left)->p1)->tokrefs = toksrefd; ((Junction *)((Junction *)$$.left)->p1)->rulerefs = rulesrefd; >> <<if ( $first_on_line ) { /* MR7 */ CurAltStart = (Junction *) ((Junction *)((Junction *)$$.left)->p1); /* MR7 */ altAdd(CurAltStart); /* MR7 */ }; >> <<$node = (Node *) ((Junction *)$$.left)->p1;>> )/* Error catching alternatives */ | "\*" <<warn("don't you want a ')' with that '*'?"); CannotContinue=TRUE;>> | "\+" <<warn("don't you want a ')' with that '+'?"); CannotContinue=TRUE;>> | "\>" <<warn("'>' can only appear after a nonterminal"); CannotContinue=TRUE;>> | PassAction <<warn("[...] out of context 'rule > [...]'"); CannotContinue=TRUE;>> ; <<CannotContinue=TRUE;>>default_exception_handler : exception_group > [DefaultExGroup] ;exception_group > [ExceptionGroup *eg] : <<ExceptionHandler *h; LabelEntry *label=NULL; /* MR6 */ FoundException = 1; FoundExceptionGroup = 1;>> /* MR6 */ "exception" <<$eg = (ExceptionGroup *)calloc(1, sizeof(ExceptionGroup));>> { <<char *p;>> PassAction /* did they attach a label? */ << p = LATEXT(1)+1; p[strlen(p)-1] = '\0'; /* kill trailing space */ label = (LabelEntry *) hash_get(Elabel, LATEXT(1)+1); if ( label==NULL ) { err(eMsg1("unknown label in exception handler: '%s'", LATEXT(1)+1)); } >> } ( exception_handler > [h] <<list_add(&($eg->handlers), (void *)h);>> )* { "default" ":" Action <<{ ExceptionHandler *eh = (ExceptionHandler *) calloc(1, sizeof(ExceptionHandler)); char *a = (char *) calloc(strlen(LATEXT(1))+1, sizeof(char)); require(eh!=NULL, "exception: cannot allocate handler"); require(a!=NULL, "exception: cannot allocate action"); strcpy(a, LATEXT(1)); eh->action = a; eh->signalname = (char *) calloc(strlen("default")+1, sizeof(char)); require(eh->signalname!=NULL, "exception: cannot allocate sig name"); strcpy(eh->signalname, "default"); list_add(&($eg->handlers), (void *)eh); }>> } << if ( label!=NULL ) { /* Record ex group in sym tab for this label */ if ( label->ex_group!=NULL ) { err(eMsg1("duplicate exception handler for label '%s'",label->str)); } else { label->ex_group = $eg; /* Label the exception group itself */ $eg->label = label->str; /* Make the labelled element pt to the exception also *//* MR6 */ if (label->elem == NULL) {/* MR6 */ err(eMsg1("reference in exception handler to undefined label '%s'",label->str));/* MR6 */ } else { switch ( label->elem->ntype ) { case nRuleRef : { RuleRefNode *r = (RuleRefNode *)label->elem; r->ex_group = $eg; break; } case nToken : { TokNode *t = (TokNode *)label->elem; t->ex_group = $eg; break; } } /* end switch *//* MR6 */ }; /* end test on label->elem */ } /* end test on label->ex_group */ } /* end test on exception label *//* MR7 *//* MR7 */ if (BlkLevel == 1 && label == NULL) {/* MR7 */ $eg->forRule=1;/* MR7 */ } else if (label == NULL) {/* MR7 */ $eg->altID = makeAltID(CurBlockID,CurAltNum);/* MR7 */ egAdd($eg);/* MR7 */ } else {/* MR7 */ $eg->labelEntry=label;/* MR7 */ };/* MR7 *//* MR7 */ /* You may want to remove this exc from the rule list *//* MR7 */ /* and handle at the labeled element site. *//* MR7 *//* MR7 */ if (label != NULL) {/* MR7 */ $eg = NULL;/* MR7 */ }; >> ; <<CannotContinue=TRUE;>>exception_handler > [ExceptionHandler *eh] : <<;>> /* MR9 Removed unreferenced variable "a" */ "catch" << $eh = (ExceptionHandler *)calloc(1, sizeof(ExceptionHandler)); require($eh!=NULL, "exception: cannot allocate handler"); >> ( NonTerminal << $eh->signalname = (char *) calloc(strlen(LATEXT(1))+1, sizeof(char)); require($eh->signalname!=NULL, "exception: cannot allocate sig name"); strcpy($eh->signalname, LATEXT(1)); >> | TokenTerm << $eh->signalname = (char *) calloc(strlen(LATEXT(1))+1, sizeof(char)); require($eh->signalname!=NULL, "exception: cannot allocate sig name"); strcpy($eh->signalname, LATEXT(1)); >> ) ":" { <<$eh->action = NULL;>> Action << $eh->action = (char *) calloc(strlen(LATEXT(1))+1, sizeof(char)); require($eh->action!=NULL, "exception: cannot allocate action"); strcpy($eh->action, LATEXT(1)); >> } ; <<CannotContinue=TRUE;>>#token NonTerminal "[a-z] [A-Za-z0-9_]*" << while ( zzchar==' ' || zzchar=='\t' ) { zzadvance(); } if ( zzchar == ':' && inAlt ) NLA = LABEL; >>#token TokenTerm "[A-Z] [A-Za-z0-9_]*" << while ( zzchar==' ' || zzchar=='\t' ) { zzadvance(); } if ( zzchar == ':' && inAlt ) NLA = LABEL; >>#token "{\\}#[A-Za-z0-9_]*" <<warn(eMsg1("unknown meta-op: %s",LATEXT(1))); zzskip(); >>#lexclass PARSE_ENUM_FILE#token "[\t\ ]+" << zzskip(); >> /* Ignore White */#token "\n|\r|\r\n" << zzline++; zzskip(); >> /* Track Line # */#token "//" << zzmode(TOK_DEF_CPP_COMMENTS); zzmore(); >>#token "/\*" << zzmode(TOK_DEF_COMMENTS); zzskip(); >>#token "#ifdef" << zzmode(TOK_DEF_CPP_COMMENTS); zzskip(); >>#token "#if" << zzmode(TOK_DEF_CPP_COMMENTS); zzskip(); >>#token "#ifndef" << ; >>#token "#else" << zzmode(TOK_DEF_CPP_COMMENTS); zzskip(); >>#token "#endif" << zzmode(TOK_DEF_CPP_COMMENTS); zzskip(); >>#token "#undef" << zzmode(TOK_DEF_CPP_COMMENTS); zzskip(); >>#token "#import" << zzmode(TOK_DEF_CPP_COMMENTS); zzskip(); >>#token "@" << ; >>enum_file[char *fname] : { "#ifndef" ID { "#define" ID /* ignore if it smells like a gate */ /* First #define after the first #ifndef (if any) is ignored */ } } ( ( enum_def[$fname] )+ | defines[$fname] ) | ;defines[char *fname] : <<int v; int maxt=(-1); char *t;>> /* MR3 */ ( "#define" ID <<t = mystrdup(LATEXT(1));>> INT << v = atoi(LATEXT(1));/* fprintf(stderr, "#token %s=%d\n", t, v);*/ /* MR2 Andreas Magnusson (Andreas.Magnusson@mailbox.swipnet.se) */ /* MR2 Fix to bug introduced by 1.33MR1 for #tokdefs */ /* MR2 Don't let #tokdefs be confused by */ /* MR2 DLGminToken and DLGmaxToken */ if ( ! isDLGmaxToken(t)) { /* MR2 */ TokenNum = v;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -