📄 antlr.g
字号:
e->lexclass = CurrentLexClass; if ( Tnum( t ) == 0 ) { e->tok = addTname( t ); set_orel(e->tok, &imag_tokens); set_orel(e->tok, &tokclasses); require((p=(TermEntry *)hash_get(Tname, t)) != NULL, "hash table mechanism is broken"); p->classname = 1; /* entry is class name, not token */ p->tclass = e; /* save ptr to this tclass def */ list_add(&tclasses, (char *)e); } else { warn(eMsg1("redefinition of tokclass or conflict w/token '%s'; ignored",t)); free( (char *)e ); go=0; } >> "\{" ( ( TokenTerm <<if ( go ) { term = (TermEntry *) hash_get(Tname, LATEXT(1)); if ( term==NULL && UserDefdTokens ) { err("implicit token definition not allowed with #tokdefs"); go = 0; } else {t=mystrdup(LATEXT(1)); tok=addTname(LATEXT(1));} }>> { ".." TokenTerm <<if ( go ) { toterm = (TermEntry *) hash_get(Tname, LATEXT(1)); if ( toterm==NULL && UserDefdTokens ) { err("implicit token definition not allowed with #tokdefs"); go = 0; } else { totext=mystrdup(LATEXT(1)); totok=addTname(LATEXT(1)); } } >> } | QuotedTerm <<if ( go ) { term = (TermEntry *) hash_get(Texpr, LATEXT(1)); if ( term==NULL && UserDefdTokens ) { err("implicit token definition not allowed with #tokdefs"); go = 0; } else {t=mystrdup(LATEXT(1)); tok=addTexpr(LATEXT(1));} }>> ) <<if ( go ) { if (totext == NULL) { list_add(&(e->tlist), t); } else { list_add(&(e->tlist),".."); list_add(&(e->tlist),t); list_add(&(e->tlist),totext); } totext=NULL; } >> )* "\}" ; <<CannotContinue=TRUE;>>token : <<char *t=NULL, *e=NULL, *a=NULL; int tnum=0;>> <<char *akaString=NULL; TermEntry *te;int save_file=0,save_line=0;>> /* MR11 */ "{\\}#token"/* MR1 10-Apr-97 MR1 Allow shift right operator in DLG actions *//* MR1 Danger when parser feedback to lexer *//* MR1 */ <<tokenActionActive=1;>> /* MR1 */ { TokenTerm <<t=mystrdup(LATEXT(1));>>/* MR11 */ {/* MR11 */ "\("/* MR11 */ QuotedTerm/* MR11 */ <<akaString=mystrdup(StripQuotes(LATEXT(1)));/* MR11 */ save_file=CurFile;save_line=zzline;/* MR11 */ >>/* MR11 */ "\)"/* MR11 */ } { "=" "[0-9]+" /* define the token type number */ <<tnum = atoi(LATEXT(1));>> } } { QuotedTerm <<e=mystrdup(LATEXT(1));>> } { Action << a = (char *) calloc(strlen(LATEXT(1))+1, sizeof(char)); require(a!=NULL, "rule token: cannot allocate action"); strcpy(a, LATEXT(1)); >> } { ";" } /* MR11 */ <<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; }; }; }; >> ; <<CannotContinue=TRUE;>>block[set *toksrefd, set *rulesrefd] : << Graph g, b; set saveblah; int saveinalt = inAlt; ExceptionGroup *eg; *$toksrefd = empty; *$rulesrefd = empty; set_clr(AST_nodes_refd_in_actions); CurBlockID++; CurAltNum = 1; saveblah = attribsRefdFromAction; attribsRefdFromAction = empty; >> alt[toksrefd,rulesrefd] <<b = g = $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; >> ( exception_group > [eg] << if ( eg!=NULL ) {/* MR7 ***** eg->altID = makeAltID(CurBlockID,CurAltNum); *****//* MR7 ***** CurAltStart->exception_label = eg->altID; *****/ list_add(&CurExGroups, (void *)eg); } >> )* <<CurAltNum++;>> ( "\|" <<inAlt=1;>> alt[toksrefd,rulesrefd] <<g = Or(g, $2);>> << ((Junction *)g.left)->blockid = CurBlockID; >> ( exception_group > [eg] << if ( eg!=NULL ) {/* MR7 ***** eg->altID = makeAltID(CurBlockID,CurAltNum); *****//* MR7 ***** CurAltStart->exception_label = eg->altID; *****/ list_add(&CurExGroups, (void *)eg); } >> )* <<CurAltNum++;>> )* <<$0 = b;>> <<attribsRefdFromAction = saveblah; inAlt = saveinalt;>> ; <<CannotContinue=TRUE;>>alt[set *toksrefd, set *rulesrefd] : <<int n=0,ne=0; Graph g; int e_num=0, 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; >> { "\@" /* handle MismatchedToken signals with default handler */ <<use_def_MT_handler = 1;>> } ( <<;>> /* MR9 Removed unreferenced variable "tok" */ { <<not=0;>> "\~" <<not=1;>> } element[not, first_on_line, use_def_MT_handler] > [node] <<if ( node!=NULL && node->ntype!=nAction ) first_on_line = 0;>> << if ( $2.left!=NULL ) { g = Cat(g, $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 *)$2.left)->p1; tk->elnum = e_num; set_orel(e_num, &elems); } else if ( node->ntype==nRuleRef ) { RuleRefNode *rn = (RuleRefNode *)((Junction *)$2.left)->p1; rn->elnum = e_num; set_orel(e_num, $rulesrefd); } } } >> )* <<if ( n == 0 ) g = emptyAlt(); $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; >> ; <<CannotContinue=TRUE;>>element_label > [LabelEntry *label] : <<TermEntry *t=NULL; LabelEntry *l=NULL; RuleEntry *r=NULL; char *lab;>> LABEL <<lab = mystrdup(LATEXT(1));>> << 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)); $label = NULL; } else if ( r!=NULL ) { err(eMsg1("label definition clashes with rule definition: '%s'", lab)); $label = 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 */ $label = l; } else { err(eMsg1("label definitions must be unique per rule: '%s'", lab)); $label = NULL; } } >> ":" ;element[int not, int first_on_line, int use_def_MT_handler] > [Node *node] : << 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 */ $node = NULL; >> {element_label>[label]} ( TokenTerm << term = (TermEntry *) hash_get(Tname, LATEXT(1)); if ( term==NULL && UserDefdTokens ) { err("implicit token definition not allowed with #tokdefs"); $$.left = $$.right = NULL; } else { $$ = buildToken(LATEXT(1)); p=((TokNode *)((Junction *)$$.left)->p1); term = (TermEntry *) hash_get(Tname, LATEXT(1)); require( term!= NULL, "hash table mechanism is broken"); p->tclass = term->tclass; p->complement = $not; if ( label!=NULL ) { p->el_label = label->str; label->elem = (Node *)p; } } >> { ".." ( QuotedTerm <<if ( p!=NULL ) setUpperRange(p, LATEXT(1));>> | TokenTerm <<if ( p!=NULL ) setUpperRange(p, LATEXT(1));>> ) } << if ( p!=NULL && (p->upper_range!=0 || p->tclass || $not) ) list_add(&MetaTokenNodes, (void *)p); >> ( "^" <<if ( p!=NULL ) p->astnode=ASTroot;>> | <<if ( p!=NULL ) p->astnode=ASTchild;>> | "!" <<if ( p!=NULL ) p->astnode=ASTexclude;>> ) { "\@" <<local_use_def_MT_handler = 1;>> } << if ( p!=NULL && $first_on_line ) { CurAltStart = (Junction *)$$.left; altAdd(CurAltStart); /* MR7 */ p->altstart = CurAltStart; } if ( p!=NULL ) p->use_def_MT_handler = $use_def_MT_handler || local_use_def_MT_handler; $node = (Node *)p; >> | QuotedTerm << term = (TermEntry *) hash_get(Texpr, LATEXT(1)); if ( term==NULL && UserDefdTokens ) { err("implicit token definition not allowed with #tokdefs"); $$.left = $$.right = NULL; } else { $$ = buildToken(LATEXT(1)); p=((TokNode *)((Junction *)$$.left)->p1); p->complement = $not; if ( label!=NULL ) { p->el_label = label->str; label->elem = (Node *)p; } } >> { ".." ( QuotedTerm <<if ( p!=NULL ) setUpperRange(p, LATEXT(1));>> | TokenTerm <<if ( p!=NULL ) setUpperRange(p, LATEXT(1));>> ) } ( "^" <<if ( p!=NULL ) p->astnode=ASTroot;>> | <<if ( p!=NULL ) p->astnode=ASTchild;>> | "!" <<if ( p!=NULL ) p->astnode=ASTexclude;>> ) { "\@" <<local_use_def_MT_handler = 1;>> } << if ( p!=NULL && (p->upper_range!=0 || p->tclass || $not) ) list_add(&MetaTokenNodes, (void *)p); >> << if ( $first_on_line ) { CurAltStart = (Junction *)$$.left; altAdd(CurAltStart); /* MR7 */ p->altstart = CurAltStart;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -