📄 antlr.g
字号:
{ "\>" PassAction << ret = (char *) calloc(strlen(LATEXT(1))+1, sizeof(char)); require(ret!=NULL, "rule rule: cannot allocate ret type"); strcpy(ret, LATEXT(1)); CurRetDef = ret; >> } { QuotedTerm <<if ( q!=NULL ) q->egroup=mystrdup(LATEXT(1));>> } << if ( GenEClasseForRules && q!=NULL ) { e = newECnode; require(e!=NULL, "cannot allocate error class node"); if ( q->egroup == NULL ) {a = q->str; a[0] = (char)toupper(a[0]);} else a = q->egroup; if ( Tnum( a ) == 0 ) { e->tok = addTname( a ); list_add(&eclasses, (char *)e); if ( q->egroup == NULL ) a[0] = (char)tolower(a[0]); /* refers to itself */ list_add(&(e->elist), mystrdup(q->str)); } else { warn(eMsg1("default errclass for '%s' would conflict with token/errclass/tokclass",a)); if ( q->egroup == NULL ) a[0] = (char)tolower(a[0]); free((char *)e); } } >> <<BlkLevel++;>> ":" <<inAlt=1;>> block[&toksrefd, &rulesrefd] <<r = makeBlk($7,0); CurRuleBlk = (Junction *)r.left; CurRuleBlk->blockid = CurBlockID; CurRuleBlk->jtype = RuleBlk; if ( q!=NULL ) CurRuleBlk->rname = q->str; CurRuleBlk->file = f; CurRuleBlk->line = l; CurRuleBlk->pdecl = pdecl; CurRuleBlk->ret = ret; CurRuleBlk->lock = makelocks(); CurRuleBlk->pred_lock = makelocks(); CurRuleBlk->tokrefs = toksrefd; CurRuleBlk->rulerefs = rulesrefd; p = newJunction(); /* add EndRule Node */ ((Junction *)r.right)->p1 = (Node *)p; r.right = (Node *) p; p->jtype = EndRule; p->lock = makelocks(); p->pred_lock = makelocks(); CurRuleBlk->end = p; if ( q!=NULL ) q->rulenum = NumRules; $7 = r; >> <<--BlkLevel;>> <<altFixup();leFixup();egFixup();>> /* MR7 */ ";" <<inAlt=0;>> { Action << a = (char *) calloc(strlen(LATEXT(1))+1, sizeof(char)); require(a!=NULL, "rule rule: cannot allocate error action"); strcpy(a, LATEXT(1)); CurRuleBlk->erraction = a; >> } ( exception_group > [eg] <<if ( eg!=NULL ) { list_add(&CurExGroups, (void *)eg); if (eg->label == NULL || *eg->label=='\0' ) q->has_rule_exception = 1; } >> )* <<if ( q==NULL ) $0.left = NULL; else $0 = $7;>> <<CurRuleNode = NULL;>> <<CurRuleBlk->exceptions = CurExGroups;>> <<CurRuleBlk->el_labels = CurElementLabels;>> ; <<CannotContinue=TRUE;>>/*pragma : "{\\}#pragma" "dup\-labeled\-tokens" <<Pragma_DupLabeledTokens=1;>> ;*/laction : <<char *a;>> "{\\}#lexaction" Action << a = (char *) calloc(strlen(LATEXT(1))+1, sizeof(char)); require(a!=NULL, "rule laction: cannot allocate action"); strcpy(a, LATEXT(1)); list_add(&LexActions, a); >> ; <<CannotContinue=TRUE;>>/* MR1 *//* MR1 11-Apr-97 Provide mechanism for inserting code into DLG class *//* MR1 via #lexmember <<....>> & #lexprefix <<...>> *//* MR1 */lmember: <<char *a;>> /* MR1 *//* MR1 */ "{\\}#lexmember"/* MR1 */ Action/* MR1 */ <</* MR1 */ if (! GenCC) {/* MR1 */ err("Use #lexmember only in C++ mode (to insert code in DLG class header");/* MR1 */ } else {/* MR1 */ a = (char *) calloc(strlen(LATEXT(1))+1, sizeof(char));/* MR1 */ require(a!=NULL, "rule lmember: cannot allocate action");/* MR1 */ strcpy(a, LATEXT(1));/* MR1 */ list_add(&LexMemberActions, a);/* MR1 */ };/* MR1 */ >>/* MR1 */ ;/* MR1 */ <<CannotContinue=TRUE;>>lprefix: <<char *a;>> /* MR1 *//* MR1 */ "{\\}#lexprefix"/* MR1 */ Action/* MR1 */ <</* MR1 */ if (! GenCC) {/* MR1 */ err("Use #lexprefixr only in C++ mode (to insert code in DLG class header");/* MR1 */ } else {/* MR1 */ a = (char *) calloc(strlen(LATEXT(1))+1, sizeof(char));/* MR1 */ require(a!=NULL, "rule lprefix: cannot allocate action");/* MR1 */ strcpy(a, LATEXT(1));/* MR1 */ list_add(&LexPrefixActions, a);/* MR1 */ };/* MR1 */ >>/* MR1 */ ;/* MR1 */ <<CannotContinue=TRUE;>>/* #pred upper <<isupper()>>? predicate literal #pred lower <<islower()>>? predicate literal #pred up_or_low upper || lower predicate expression concealed interdependence #pred up_or_low_2 <<isletter()>>? A || B predicate literal equals predicate expr analyze using lower||upper generate using isLetter()*/aPred: <<PredEntry *predEntry=NULL; char *name=NULL; Predicate *predExpr=NULL; char *predLiteral=NULL; int save_file; int save_line; int predExprPresent=0; >> "{\\}#pred" << MR_usingPredNames=1; /* will need to use -mrhoist version of genPredTree */ >> /* used to allow NonTerminal but it caused problems when a rule name immediately followed a #pred statement */ TokenTerm <<name=mystrdup(LATEXT(1));>> << /* don't free - referenced in predicates */ CurPredName=(char *)calloc(1,strlen(name) + 10); strcat("#pred ",CurPredName); strcat(name,CurPredName); predEntry=(PredEntry *) hash_get(Pname,name); if (predEntry != NULL) { warnFL(eMsg1("#pred %s previously defined - ignored",name), FileStr[action_file],action_line); name=NULL; }; >> ( Pred <<predLiteral=mystrdup(LATEXT(1)); save_line=action_line; save_file=action_file; >> { predOrExpr>[predExpr] <<predExprPresent=1;>> } <<if (predLiteral != NULL && name != NULL) { /* * predExpr may be NULL due to syntax errors * or simply omitted by the user */ predEntry=newPredEntry(name); predEntry->file=save_file; predEntry->line=save_line; predExpr=MR_predFlatten(predExpr); predEntry->predLiteral=predLiteral; if (! predExprPresent || predExpr == NULL) { predExpr=new_pred(); predExpr->expr=predLiteral; predExpr->source=newActionNode(); predExpr->source->action=predExpr->expr; predExpr->source->rname=CurPredName; predExpr->source->line=action_line; predExpr->source->file=action_file; predExpr->source->is_predicate=1; predExpr->k=predicateLookaheadDepth(predExpr->source); }; predEntry->pred=predExpr; hash_add(Pname,name,(Entry *)predEntry); predExpr=NULL; }; predicate_free(predExpr); >> | <<save_line=zzline; save_file=CurFile;>> predOrExpr>[predExpr] <<if (predExpr != NULL && name != NULL) { predEntry=newPredEntry(name); predEntry->file=CurFile; predEntry->line=zzline; predExpr=MR_predFlatten(predExpr); predEntry->pred=predExpr; hash_add(Pname,name,(Entry *)predEntry); predExpr=NULL; }; predicate_free(predExpr); >> ) {";"};/* fail */<<predicate_free(predExpr);>>predOrExpr>[Predicate *result] : <<Predicate *ORnode; Predicate *predExpr; Predicate **tail=NULL; >> predAndExpr>[predExpr] << ORnode=new_pred(); ORnode->expr=PRED_OR_LIST; if (predExpr != NULL) { ORnode->down=predExpr; tail=&predExpr->right; }; >> ( "\|\|" predAndExpr>[predExpr] << if (predExpr != NULL) { *tail=predExpr; tail=&predExpr->right; }; >> )* << $result=ORnode; ORnode=NULL; >>;/* fail */<<predicate_free(ORnode);>>predAndExpr>[Predicate *result] : <<Predicate *ANDnode; Predicate *predExpr; Predicate **tail=NULL; >> predPrimary>[predExpr] << ANDnode=new_pred(); ANDnode->expr=PRED_AND_LIST; if (predExpr != NULL) { ANDnode->down=predExpr; tail=&predExpr->right; }; >> ( "&&" predPrimary>[predExpr] << if (predExpr != NULL) { *tail=predExpr; tail=&predExpr->right; }; >> )* << $result=ANDnode; ANDnode=NULL; >>;/* fail */<<predicate_free(ANDnode);>>predPrimary>[Predicate *result] : << char *name=NULL; PredEntry *predEntry=NULL; Predicate *predExpr=NULL; int inverted=0; >> TokenTerm <<name=mystrdup(LATEXT(1));>> << predEntry=(PredEntry *) hash_get(Pname,name); if (predEntry == NULL) { warnFL(eMsg1("no previously defined #pred with name \"%s\"",name), FileStr[CurFile],zzline); name=NULL; $result=NULL; } else { predExpr=predicate_dup(predEntry->pred); predExpr->predEntry=predEntry; $result=predExpr; }; >> | "\(" predOrExpr>[predExpr] "\)" << $result=predExpr; >> | "!" predPrimary>[predExpr] << predExpr->inverted=!predExpr->inverted; $result=predExpr; >>;/* fail */ << predicate_free(predExpr); >>aLexclass: "{\\}#lexclass" TokenTerm <<lexclass(mystrdup(LATEXT(1)));>> ; <<CannotContinue=TRUE;>>error : <<char *t=NULL; ECnode *e; int go=1; TermEntry *p;>> "{\\}#errclass" (<<;>> TokenTerm <<t=mystrdup(LATEXT(1));>> | QuotedTerm <<t=mystrdup(LATEXT(1));>> ) <<e = newECnode; require(e!=NULL, "cannot allocate error class node"); e->lexclass = CurrentLexClass; if ( Tnum( (t=StripQuotes(t)) ) == 0 ) { if ( hash_get(Texpr, t) != NULL ) warn(eMsg1("errclass name conflicts with regular expression '%s'",t)); e->tok = addTname( t ); set_orel(e->tok, &imag_tokens); require((p=(TermEntry *)hash_get(Tname, t)) != NULL, "hash table mechanism is broken"); p->classname = 1; /* entry is errclass name, not token */ list_add(&eclasses, (char *)e); } else { warn(eMsg1("redefinition of errclass or conflict w/token or tokclass '%s'; ignored",t)); free( (char *)e ); go=0; } >> "\{" ( NonTerminal <<if ( go ) t=mystrdup(LATEXT(1));>> | TokenTerm <<if ( go ) t=mystrdup(LATEXT(1));>> | QuotedTerm <<if ( go ) t=mystrdup(LATEXT(1));>> ) <<if ( go ) list_add(&(e->elist), t);>> ( ( NonTerminal <<if ( go ) t=mystrdup(LATEXT(1));>> | TokenTerm <<if ( go ) t=mystrdup(LATEXT(1));>> | QuotedTerm <<if ( go ) t=mystrdup(LATEXT(1));>> ) <<if ( go ) list_add(&(e->elist), t);>> )* "\}" ; <<CannotContinue=TRUE;>>tclass : <<char *t=NULL; TCnode *e; int go=1,tok,totok; TermEntry *p, *term, *toterm;>> <<char *totext=NULL; >> "{\\}#tokclass" TokenTerm <<t=mystrdup(LATEXT(1));>> <<e = newTCnode; require(e!=NULL, "cannot allocate token class node");
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -