⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 gen.c

📁 本工具提供一个词法分析器和语法分析器的集成开发环境
💻 C
📖 第 1 页 / 共 5 页
字号:
	if ( !GenCC ) gen1("zzEXIT(zztasp%d);\n", BlkLevel);	if ( !GenCC ) gen("}\n");	tabs--;	gen("}\n");}static void#ifdef __USE_PROTOSBLOCK_Preamble( Junction *q )#elseBLOCK_Preamble( q )Junction *q;#endif{	ActionNode *a;	Junction *begin;	BLOCK_Head();	if ( GenCC ) genTokenPointers(q);	if ( GenCC&&GenAST ) genASTPointers(q);	if ( q->jtype == aPlusBlk ) gen("int zzcnt=1;\n");	if ( q->parm != NULL && !q->predparm ) gen1("zzaPush(%s);\n", q->parm)	else if ( !GenCC ) gen("zzMake0;\n");	if ( !GenCC ) gen("{\n");	if ( q->jtype == aLoopBegin ) begin = (Junction *) ((Junction *)q->p1);	else begin = q;	if ( has_guess_block_as_first_item(begin) )	{		gen("zzGUESS_BLOCK\n");	}	if ( q->jtype == aLoopBegin )		a = findImmedAction( ((Junction *)q->p1)->p1 );	/* look at aLoopBlk */	else		a = findImmedAction( q->p1 );	if ( a!=NULL && !a->is_predicate) {		if (!a->noHoist) dumpAction(a->action, output, tabs, a->file, a->line, 1);		a->done = 1;	/* remove action. We have already handled it */	}}void#ifdef __USE_PROTOSgenCombinedPredTreeContextOrig( Predicate *p )#elsegenCombinedPredTreeContextOrig( p )Predicate *p;#endif{	static set *ctx=NULL;		/* genExprSets() is destructive, make copy*/	require(p!=NULL, "can't make context tree for NULL pred tree");#ifdef DBG_PRED	fprintf(stderr, "enter genCombinedPredTreeContextOrig(%s,0x%x) with sets:\n", p->expr, p);	s_fprT(stderr, p->scontext[1]);	fprintf(stderr, "\n");#endif	if ( p->down == NULL )	{/***	if ( p->k>1 && p->tcontext!=NULL ) ***/		if ( p->tcontext!=NULL )		{			_gen("(");			genExprTree(p->tcontext, 1);			_gen(")");		}/***	else if ( p->k==1 && set_deg(p->scontext[1])>0 ) ***/		else if ( set_deg(p->scontext[1])>0 )		{			if ( ctx==NULL ) ctx = (set *)calloc(CLL_k+1, sizeof(set));			require(ctx!=NULL, "ctx cannot allocate");			ctx[0]=empty;			ctx[1]=set_dup(p->scontext[1]);			_gen("(");			genExprSets(&(ctx[0]), p->k);			_gen(")");			set_free(ctx[1]);		}		else if ( p->expr==PRED_AND_LIST || p->expr==PRED_OR_LIST ) {			fatal_internal("pred tree is orphan OR or AND list");		}		else {            if (! HoistPredicateContext) {              _gen(" 1 /* no context: prc is off */ ");            } else {              fatal_internal("pred tree context is empty");            };		}		return;	}/* MR10 - make AND just like OR */	if ( p->expr == PRED_AND_LIST )	{        Predicate *list = p->down;        for (; list!=NULL; list=list->right)        {     	     genCombinedPredTreeContextOrig(list);       		 if ( list->right!=NULL ) _gen("|| /* MR10 was wrong */ ");        };		return;	}	if ( p->expr == PRED_OR_LIST )	{        Predicate *list = p->down;        for (; list!=NULL; list=list->right)        {           genCombinedPredTreeContextOrig(list);           if ( list->right!=NULL ) _gen("||");        };        return;     };	fatal("pred tree is really wacked");}/* [genCombinedPredTreeContext] */void#ifdef __USE_PROTOSgenCombinedPredTreeContext( Predicate *p )#elsegenCombinedPredTreeContext( p )Predicate *p;#endif{  Tree  *t;  int   predDepth=0;  if (0 && ! MR_usingPredNames && ! MRhoisting) {    genCombinedPredTreeContextOrig(p);  } else {/* MR13 */    MR_pred_depth(p,&predDepth);/* MR13 */    if (predDepth == 1) {/* MR13 *//* MR13 */      set   scontext[2];/* MR13 */      scontext[0]=empty;/* MR13 */      scontext[1]=MR_compute_pred_set(p);/* MR13 */      if (set_nil(scontext[1])) {/* MR13 */        _gen(" 1 /* MR12 no context (-prc off) */ ");/* MR13 */      } else {/* MR13 */        _gen("(");/* MR13 */        genExprSets(&scontext[0], 1);/* MR13 */        set_free(scontext[1]);/* MR13 */        _gen(")");/* MR13 */      };    } else {      t=MR_compute_pred_tree_context(p);      if (t == NULL) {        _gen(" 1 /* MR12 no context (-prc off) */ ");      } else {        _gen("(");        genExprTree(t, 1);        Tfree(t);   /* MR10 */        _gen(")");      };    };  };}/* [genPredTreeGate] */void#ifdef __USE_PROTOSgenPredTreeGate( Predicate *p, int in_and_expr )#elsegenPredTreeGate( p, in_and_expr )Predicate *p;int in_and_expr;#endif{	if ( in_and_expr )	{		_gen("!(");		genCombinedPredTreeContext(p);		_gen(")||");		if ( p->down!=NULL ) _gen("\n");	}	else	{		_gen("(");		genCombinedPredTreeContext(p);		_gen(")&&");		if ( p->down!=NULL ) _gen("\n");	}}#ifdef __USE_PROTOSvoid genPredEntry(Predicate *p,int outer)#elsevoid genPredEntry(p,outer)  Predicate     *p;  int           outer;#endif{    int         inverted=0;    Predicate   *q;    int         localOuter=outer;    int         needRP=0;    if (p == NULL) return;    if (p->predEntry != NULL && p->predEntry->predLiteral != NULL) {      if (p->inverted != p->predEntry->pred->inverted) {        _gen("! /* inverted pred */ (");        needRP=1;      } else {        if (!localOuter) _gen("(");        needRP=1;      };      dumpAction(p->predEntry->predLiteral,output,0,p->source->file,p->source->line,0);      if (needRP) _gen(")");      return;    };    inverted=p->inverted;    if (inverted) {      _gen(" ! /* inverted pred */ (");      localOuter=1;    };    if (p->expr == PRED_OR_LIST) {      if (!localOuter) _gen("(");      for (q=p->down; q != NULL ; q=q->right) {        genPredEntry(q,0);        if (q->right != NULL) _gen(" || ");      };      if (!localOuter) _gen(")");    } else if (p->expr == PRED_AND_LIST) {      if (!localOuter) _gen("(");      for (q=p->down; q != NULL ; q=q->right) {        genPredEntry(q,0);        if (q->right != NULL) _gen(" && ");      };      if (!localOuter) _gen(")");    } else {      if (!localOuter) _gen("(");      require (p->source != NULL,"predEntry->source == NULL");      require (p->source->inverted == 0,"dumpPredEntry p->source->inverted != 0");      dumpAction(p->source->action,output,0,p->source->file,p->source->line,0);      if (!localOuter) _gen(")");    };    if (inverted) {        _gen(")");    }}void#ifdef __USE_PROTOSdumpPredAction(ActionNode *anode,                    char *s,FILE *output,int tabs,int file,int line,int final_newline)#elsedumpPredAction(anode,                    s,output,tabs,file,line,final_newline)    ActionNode  *anode;    char        *s;    FILE        *output;    int         tabs;    int         file;    int         line;    int         final_newline;#endif{    PredEntry   *predEntry=anode->predEntry;    int         inverted=anode->inverted;    Predicate   *workPred;    if (predEntry == NULL) {      /* inline predicate literal */      require(inverted == 0,"dumpPredAction action->inverted");  	  dumpAction(s,output,tabs,file,line,final_newline);    } else {      /* a reference to a predicate - possibly with an inverted source */      if (predEntry->predLiteral != NULL) {        if (inverted) _gen("! /* inverted pred */ (");        dumpAction(predEntry->predLiteral,output,0,anode->file,anode->line,0);        if (inverted) _gen(")");      } else {        workPred=predicate_dup(predEntry->pred);        if (inverted) workPred->inverted=!workPred->inverted;        genPredEntry(workPred,1);        predicate_free(workPred);      };    };}/* [genPred] */void#ifdef __USE_PROTOSgenPred(Predicate *p, Node *j,int suppress_sva)#elsegenPred(p,j,suppress_sva)    Predicate   *p;    Node        *j;    int         suppress_sva;#endif{	if ( FoundException && !suppress_sva) {_gen("(_sva=(");}    /* MR11 suppress_sva */	else {_gen("(");}	if ( GenLineInfo && j->file != -1 ) _gen("\n");    if (p->source != NULL && p->source->ampersandPred != NULL) {      if (p->source->ampersandPred->k == 1) {            set     ctx[2];			ctx[0]=empty;			ctx[1]=set_dup(p->source->ampersandPred->scontext[1]);			_gen("(");			genExprSets(&(ctx[0]), p->k);			_gen(") && ");			set_free(ctx[1]);      } else {        _gen("( ");        genExprTree(p->source->ampersandPred->tcontext,1);		_gen(" ) && ");      };    };    dumpPredAction((ActionNode *)p->source,                p->expr, output, 0, -1 /*indicates no line info*/, j->line, 0);	if ( FoundException && !suppress_sva)   /* MR11 suppress_sva */         {_gen("),_sva)");}    /* MR10 - get red of "meant ==" messages */	else {_gen(")");}}void#ifdef __USE_PROTOSMR_distinctORcontextOpt(Predicate *p,Node *j,int in_and_expr)#elseMR_distinctORcontextOpt(p,j,in_and_expr)    Predicate   *p;    Node        *j;    int         in_and_expr;#endif{    Predicate   *q;    _gen(" /* MR10 Distinct OR context optimization */ \n");    if (in_and_expr) {      gen("zzpf=0,\n");      for (q=p->down; q != NULL; q=q->right) {        gen("(  ");        genCombinedPredTreeContext(q);        _gen(" && (zzpf=1, ");        genPred(q,j,0);        _gen("  )) ||\n");      };      gen("!zzpf)");    } else {      require (0,            "MR_distinctORcontextOpt: can't get here when using MR_predSimplify");#if 0**      for (q=p->down; q != NULL; q=q->right) {**        gen("(  ");**        genCombinedPredTreeContext(q);**        _gen(" && ");**        genPred(q,j);**        if (q->right != NULL) {**          _gen("  ) ||\n");**        };**      };**      gen(")");#endif   };}void#ifdef __USE_PROTOSgenPredTreeOrig( Predicate *p, Node *j, int in_and_expr )#elsegenPredTreeOrig( p, j, in_and_expr )Predicate *p;Node *j;int in_and_expr;#endif{/* MR10 */  int     allHaveContext=1;/* MR10 */  int     noneHaveContext=1;/* MR10 */  MR_predContextPresent(p,&allHaveContext,&noneHaveContext);	if ( ! noneHaveContext )                  /* MR10 context guards ignored when -prc off */	{		_gen("(");		genPredTreeGate(p, in_and_expr);	}	/* if leaf node, just gen predicate */	if ( p->down==NULL )	{		genPred(p,j,0);		if ( ! noneHaveContext ) _gen(")");   /* MR10 context guards ignored when -prc off */		return;	}	/* if AND list, do both preds (only two possible) */	if ( p->expr == PRED_AND_LIST )	{#if 0**		_gen("(");**		genPredTreeOrig(p->down, j, 1);**		_gen("&&");**		genPredTreeOrig(p->down->right, j, 1);**		_gen(")");**		if ( ! noneHaveContext ) _gen(")");    /* MR10 context guards ignored when -prc off */**		return;#endif        /* MR11 - make it work with AND with more than two children - like OR */		Predicate *list;		_gen("(");		list = p->down;		for (; list!=NULL; list=list->right)		{			genPredTreeOrig(list, j, 1);			if ( list->right!=NULL ) _gen("&&");		}		_gen(")");		if ( ! noneHaveContext ) _gen(")");    /* MR10 context guards ignored when -prc off */		return;    };	if ( p->expr == PRED_OR_LIST )	{		Predicate *list;		_gen("(");		list = p->down;		for (; list!=NULL; list=list->right)		{			genPredTreeOrig(list, j, 0);			if ( list->right!=NULL ) _gen("||");		}		_gen(")");		if ( ! noneHaveContext ) _gen(")");    /* MR10 context guards ignored when -prc off */		return;	}	fatal_internal("genPredTreeOrig: predicate tree is wacked");}#if 0**   Predicate member dummyPredDepth is no longer used in MR10**     but we might need it again in the future****   if (MRhoisting) {**     if ( !noneHaveContext &&**          ! in_and_expr &&**          p->source != NULL &&**          p->source->dummyPredicateDepth > 0 &&**          p->down == NULL) {** 		_gen("(");** 		genCombinedPredTreeContext(p);** 		_gen("  )\n");** 		return;**     };**   };#endif/* [genPredTree] *//* in_and_expr   what to do if the context is wrong   what to do if the context is correct but the predicate is false   remember: if the context is wrong it's the same as if the             predicate is true as far as enabling an alternative        Consider (AND p q r)        if in an ... && ... expression then you don't want        the entire predicate chain to fail just because the        context for one component is wrong: so return true        Consider (OR p q r)        if in an ... || ... expression then you don't want        the entire predicate chain to succeed just because        the context for one component is correct when the        corresponding test is false: so return false when        the context is correct but the test is false.*/void#ifdef __USE_PROTOS

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -