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

📄 mal_parser.c

📁 一个内存数据库的源代码这是服务器端还有客户端
💻 C
📖 第 1 页 / 共 5 页
字号:
			lo= operatorLength(cntxt);			if( lo > 0) 				opname= operatorCopy(cntxt,lo);			else opname= GDKstrdup("");			if((i= cstToken(cntxt,&cst))){				setVarProperty(curBlk,varid, pname, opname, &cst);				advance(cntxt,i);			} else 				setVarProperty(curBlk,varid, pname, NULL, NULL);			GDKfree(pname); 			GDKfree(opname); 		} while( keyphrase1(cntxt,","));		if( !keyphrase1(cntxt,"}") )			/* return (MalBlkPtr) */			parseError(cntxt,"'}' expected\n");	}#line 1085 "/export/scratch0/monet/monet.GNU.64.64.d.14791/MonetDB5/src/mal/mal_parser.mx"		} else {			advance(cntxt,l);			type= typeElm(cntxt,getVarType(curBlk,varid));			if( type != getVarType(curBlk,varid))				parseError(cntxt,"Incompatible argument type\n");			if( isPolymorphic(type) )				setPolymorphic(curInstr,type,TRUE);			setVarType(curBlk,varid,type);			#line 1127 "/export/scratch0/monet/monet.GNU.64.64.d.14791/MonetDB5/src/mal/mal_parser.mx"	if( keyphrase1(cntxt,"{")) {		do {			str pname,opname;			int i,lo;			ValRecord cst;			l = idLength(cntxt);			if(l==0) 				break;			pname= idCopy(cntxt,l);			if( curBlk->var[varid]->props== NULL)				 curBlk->var[varid]->props= newPropertySet();			/* localize value , simplified version */			lo= operatorLength(cntxt);			if( lo > 0) 				opname= operatorCopy(cntxt,lo);			else opname= GDKstrdup("");			if((i= cstToken(cntxt,&cst))){				setVarProperty(curBlk,varid, pname, opname, &cst);				advance(cntxt,i);			} else 				setVarProperty(curBlk,varid, pname, NULL, NULL);			GDKfree(pname); 			GDKfree(opname); 		} while( keyphrase1(cntxt,","));		if( !keyphrase1(cntxt,"}") )			/* return (MalBlkPtr) */			parseError(cntxt,"'}' expected\n");	}#line 1094 "/export/scratch0/monet/monet.GNU.64.64.d.14791/MonetDB5/src/mal/mal_parser.mx"		}	} else if( currChar(cntxt)== ':' ){		type= typeElm(cntxt,TYPE_any);		varid = newTmpVariable(curBlk,type);		if( isPolymorphic(type) )			setPolymorphic(curInstr,type,TRUE);		setVarType(curBlk,varid,type);		#line 1127 "/export/scratch0/monet/monet.GNU.64.64.d.14791/MonetDB5/src/mal/mal_parser.mx"	if( keyphrase1(cntxt,"{")) {		do {			str pname,opname;			int i,lo;			ValRecord cst;			l = idLength(cntxt);			if(l==0) 				break;			pname= idCopy(cntxt,l);			if( curBlk->var[varid]->props== NULL)				 curBlk->var[varid]->props= newPropertySet();			/* localize value , simplified version */			lo= operatorLength(cntxt);			if( lo > 0) 				opname= operatorCopy(cntxt,lo);			else opname= GDKstrdup("");			if((i= cstToken(cntxt,&cst))){				setVarProperty(curBlk,varid, pname, opname, &cst);				advance(cntxt,i);			} else 				setVarProperty(curBlk,varid, pname, NULL, NULL);			GDKfree(pname); 			GDKfree(opname); 		} while( keyphrase1(cntxt,","));		if( !keyphrase1(cntxt,"}") )			/* return (MalBlkPtr) */			parseError(cntxt,"'}' expected\n");	}#line 1102 "/export/scratch0/monet/monet.GNU.64.64.d.14791/MonetDB5/src/mal/mal_parser.mx"	} else 		parseError(cntxt,"argument expected\n");	curInstr= pushArgument(curBlk,curInstr, varid);#line 978 "/export/scratch0/monet/monet.GNU.64.64.d.14791/MonetDB5/src/mal/mal_parser.mx"		/* the last argument may be variable length */		if( MALkeyword(cntxt,"...",3) ){			curInstr->varargs |= VARARGS;			setPolymorphic(curInstr,TYPE_any,FALSE);			break;		}		if ((ch = currChar(cntxt)) != ',') {			if (ch == ')')				break;			return (MalBlkPtr) parseError(cntxt,"',' expected\n");		} else 			nextChar(cntxt); /* skip ',' */		skipSpace(cntxt);		ch = currChar(cntxt);	}	if (currChar(cntxt) != ')') {		freeInstruction(curInstr);		return (MalBlkPtr) parseError(cntxt,"')' expected\n");	}	advance(cntxt,1); /* skip ')' *//*The return type is either a single type or multiple return type structure.We simply keep track of the number of arguments added andduring the final phase reshuffle the return values to the beginning (?)*/	if (currChar(cntxt)== ':'){		type = typeElm(cntxt, TYPE_void);		setPolymorphic(curInstr,type,TRUE);		setVarType(curBlk,curInstr->argv[0],type);		/* we may be confronted by a variable target type list */		if( MALkeyword(cntxt,"...",3) ){			curInstr->varargs |= VARRETS;			setPolymorphic(curInstr,TYPE_any,FALSE);		}				#line 1127 "/export/scratch0/monet/monet.GNU.64.64.d.14791/MonetDB5/src/mal/mal_parser.mx"	if( keyphrase1(cntxt,"{")) {		do {			str pname,opname;			int i,lo;			ValRecord cst;			l = idLength(cntxt);			if(l==0) 				break;			pname= idCopy(cntxt,l);			if( curBlk->var[curInstr->argv[0]]->props== NULL)				 curBlk->var[curInstr->argv[0]]->props= newPropertySet();			/* localize value , simplified version */			lo= operatorLength(cntxt);			if( lo > 0) 				opname= operatorCopy(cntxt,lo);			else opname= GDKstrdup("");			if((i= cstToken(cntxt,&cst))){				setVarProperty(curBlk,curInstr->argv[0], pname, opname, &cst);				advance(cntxt,i);			} else 				setVarProperty(curBlk,curInstr->argv[0], pname, NULL, NULL);			GDKfree(pname); 			GDKfree(opname); 		} while( keyphrase1(cntxt,","));		if( !keyphrase1(cntxt,"}") )			/* return (MalBlkPtr) */			parseError(cntxt,"'}' expected\n");	}#line 1014 "/export/scratch0/monet/monet.GNU.64.64.d.14791/MonetDB5/src/mal/mal_parser.mx"	} else 	if( keyphrase1(cntxt,"(")){ /* deal with compound return */		int retc= curInstr->argc, i1,i2=0;		int maxarg;		int *newarg;		/* parse multi-target result */		/* skipSpace(cntxt);*/		ch= currChar(cntxt);		while( ch !=')' && ch && !NL(ch)){			int varid=0;			int type= TYPE_any;			#line 1071 "/export/scratch0/monet/monet.GNU.64.64.d.14791/MonetDB5/src/mal/mal_parser.mx"	l = idLength(cntxt);	if( l>0) {		varid = findVariableLength(curBlk, CURRENT(cntxt), l);		if( varid < 0){			varid = newVariable(curBlk,idCopy(cntxt,l),TYPE_any);			type= typeElm(cntxt,TYPE_any);			if( isPolymorphic(type) )				setPolymorphic(curInstr,type,TRUE);			setVarType(curBlk,varid,type);			#line 1127 "/export/scratch0/monet/monet.GNU.64.64.d.14791/MonetDB5/src/mal/mal_parser.mx"	if( keyphrase1(cntxt,"{")) {		do {			str pname,opname;			int i,lo;			ValRecord cst;			l = idLength(cntxt);			if(l==0) 				break;			pname= idCopy(cntxt,l);			if( curBlk->var[varid]->props== NULL)				 curBlk->var[varid]->props= newPropertySet();			/* localize value , simplified version */			lo= operatorLength(cntxt);			if( lo > 0) 				opname= operatorCopy(cntxt,lo);			else opname= GDKstrdup("");			if((i= cstToken(cntxt,&cst))){				setVarProperty(curBlk,varid, pname, opname, &cst);				advance(cntxt,i);			} else 				setVarProperty(curBlk,varid, pname, NULL, NULL);			GDKfree(pname); 			GDKfree(opname); 		} while( keyphrase1(cntxt,","));		if( !keyphrase1(cntxt,"}") )			/* return (MalBlkPtr) */			parseError(cntxt,"'}' expected\n");	}#line 1080 "/export/scratch0/monet/monet.GNU.64.64.d.14791/MonetDB5/src/mal/mal_parser.mx"		} else 		if( 0){			parseError(cntxt,"Argument defined twice\n");			typeElm(cntxt,getVarType(curBlk,varid));			#line 1127 "/export/scratch0/monet/monet.GNU.64.64.d.14791/MonetDB5/src/mal/mal_parser.mx"	if( keyphrase1(cntxt,"{")) {		do {			str pname,opname;			int i,lo;			ValRecord cst;			l = idLength(cntxt);			if(l==0) 				break;			pname= idCopy(cntxt,l);			if( curBlk->var[varid]->props== NULL)				 curBlk->var[varid]->props= newPropertySet();			/* localize value , simplified version */			lo= operatorLength(cntxt);			if( lo > 0) 				opname= operatorCopy(cntxt,lo);			else opname= GDKstrdup("");			if((i= cstToken(cntxt,&cst))){				setVarProperty(curBlk,varid, pname, opname, &cst);				advance(cntxt,i);			} else 				setVarProperty(curBlk,varid, pname, NULL, NULL);			GDKfree(pname); 			GDKfree(opname); 		} while( keyphrase1(cntxt,","));		if( !keyphrase1(cntxt,"}") )			/* return (MalBlkPtr) */			parseError(cntxt,"'}' expected\n");	}#line 1085 "/export/scratch0/monet/monet.GNU.64.64.d.14791/MonetDB5/src/mal/mal_parser.mx"		} else {			advance(cntxt,l);			type= typeElm(cntxt,getVarType(curBlk,varid));			if( type != getVarType(curBlk,varid))				parseError(cntxt,"Incompatible argument type\n");			if( isPolymorphic(type) )				setPolymorphic(curInstr,type,TRUE);			setVarType(curBlk,varid,type);			#line 1127 "/export/scratch0/monet/monet.GNU.64.64.d.14791/MonetDB5/src/mal/mal_parser.mx"	if( keyphrase1(cntxt,"{")) {		do {			str pname,opname;			int i,lo;			ValRecord cst;			l = idLength(cntxt);			if(l==0) 				break;			pname= idCopy(cntxt,l);			if( curBlk->var[varid]->props== NULL)				 curBlk->var[varid]->props= newPropertySet();			/* localize value , simplified version */			lo= operatorLength(cntxt);			if( lo > 0) 				opname= operatorCopy(cntxt,lo);			else opname= GDKstrdup("");			if((i= cstToken(cntxt,&cst))){				setVarProperty(curBlk,varid, pname, opname, &cst);				advance(cntxt,i);			} else 				setVarProperty(curBlk,varid, pname, NULL, NULL);			GDKfree(pname); 			GDKfree(opname); 		} while( keyphrase1(cntxt,","));		if( !keyphrase1(cntxt,"}") )			/* return (MalBlkPtr) */			parseError(cntxt,"'}' expected\n");	}#line 1094 "/export/scratch0/monet/monet.GNU.64.64.d.14791/MonetDB5/src/mal/mal_parser.mx"		}	} else if( currChar(cntxt)== ':' ){		type= typeElm(cntxt,TYPE_any);		varid = newTmpVariable(curBlk,type);		if( isPolymorphic(type) )			setPolymorphic(curInstr,type,TRUE);		setVarType(curBlk,varid,type);		#line 1127 "/export/scratch0/monet/monet.GNU.64.64.d.14791/MonetDB5/src/mal/mal_parser.mx"	if( keyphrase1(cntxt,"{")) {		do {			str pname,opname;			int i,lo;			ValRecord cst;			l = idLength(cntxt);			if(l==0) 				break;			pname= idCopy(cntxt,l);			if( curBlk->var[varid]->props== NULL)				 curBlk->var[varid]->props= newPropertySet();			/* localize value , simplified version */			lo= operatorLength(cntxt);			if( lo > 0) 				opname= operatorCopy(cntxt,lo);			else opname= GDKstrdup("");			if((i= cstToken(cntxt,&cst))){				setVarProperty(curBlk,varid, pname, opname, &cst);				advance(cntxt,i);			} else 				setVarProperty(curBlk,varid, pname, NULL, NULL);			GDKfree(pname); 			GDKfree(opname); 		} while( keyphrase1(cntxt,","));		if( !keyphrase1(cntxt,"}") )			/* return (MalBlkPtr) */			parseError(cntxt,"'}' expected\n");	}#line 1102 "/export/scratch0/monet/monet.GNU.64.64.d.14791/MonetDB5/src/mal/mal_parser.mx"	} else 		parseError(cntxt,"argument expected\n");	curInstr= pushArgument(curBlk,curInstr, varid);#line 1026 "/export/scratch0/monet/monet.GNU.64.64.d.14791/MonetDB5/src/mal/mal_parser.mx"			if( (ch=currChar(cntxt)) != ',') {				 if( ch==')') break;				 return (MalBlkPtr) parseError(cntxt, "',' expected\n");			} else {				nextChar(cntxt); /* skip ',' */ 			}			skipSpace(cntxt);			ch = currChar(cntxt);		}		/* re-arrange the parameters, results first*/		maxarg= curInstr->maxarg;		newarg= (int*)GDKmalloc(maxarg*sizeof(int));		for(i1= retc; i1<curInstr->argc; i1++)			newarg[i2++]= curInstr->argv[i1];		curInstr->retc= curInstr->argc-retc;		for(i1= 1; i1<retc; i1++)			newarg[i2++]= curInstr->argv[i1];		curInstr->argc= i2;		for(; i2<maxarg; i2++) newarg[i2]= 0;		for(i1=0; i1<maxarg; i1++) 			curInstr->argv[i1] = newarg[i1];		GDKfree(newarg);		if (currChar(cntxt) != ')') {			freeInstruction(curInstr);			return (MalBlkPtr) parseError(cntxt, "')' expected\n");		}		nextChar(cntxt); /* skip ')' */	} else { /* default */		setVarType(curBlk,0,TYPE_void);	}#line 1256 "/export/scratch0/monet/monet.GNU.64.64.d.14791/MonetDB5/src/mal/mal_parser.mx"	if( MALkeyword(cntxt,"address",7)){		str nme;		int i;		i = idLength(cntxt);		if( i==0){			parseError(cntxt,"<identifier> expected\n");			return 0;		}		nme = idCopy(cntxt,i);		curInstr->fcn = getAddress(cntxt->srcFile, cntxt->nspace->name, nme,0);		skipSpace(cntxt);	}	/* block is terminated at the END statement */	#line 1170 "/export/scratch0/monet/monet.GNU.64.64.d.14791/MonetDB5/src/mal/mal_parser.mx"	if( MALkeyword(cntxt,"comment",7)){		if( (l= stringLength(cntxt))){			curBlk->help = strCopy(cntxt,l);			advance(cntxt,l);		} else {			parseError(cntxt,"<string> expected\n");		}	} else 	if (currChar(cntxt) != ';')		parseError(cntxt,"';' expected\n");	skipToEnd(cntxt);#line 1270 "/export/scratch0/monet/monet.GNU.64.64.d.14791/MonetDB5/src/mal/mal_parser.mx"	return curBlk;}#line 1280 "/export/scratch0/monet/monet.GNU.64.64.d.14791/MonetDB5/src/mal/mal_parser.mx"int parseEnd(Client cntxt){   MalBlkPtr curBlk = 0;	Symbol curPrg = 0;	int l,showit=0;	if( MALkeyword(cntxt,"end",3) ){		curPrg = cntxt->curprg;		curBlk = curPrg->def;   		l = idLength(cntxt);		if(l==0) l= operatorLength(cntxt);				if( strncmp(CURRENT(cntxt), getModuleId(getSignature(curPrg)), l)==0) {			advance(cntxt,l);			skipSpace(cntxt);			if( currChar(cntxt) == '.')				nextChar(cntxt);			skipSpace(cntxt);			l = idLength(cntxt);			if(l==0) l= operatorLength(cntxt);		} 		/* parse fcn */		if( (l== (int)strlen(curPrg->name) &&			 strncmp(CURRENT(cntxt), curPrg->name, l)==0) || l==0) {			/* its ok */		} else {			parseError(cntxt,"non matching end label, overruled\n");		}		pushEndInstruction(curBlk);		insertSymbol(cntxt->nspace, cntxt->curprg);		trimMalBlk(cntxt->curprg->def);		cntxt->blkmode =0;		curBlk->typefixed=0;		chkProgram(cntxt->nspace, cntxt->curprg->def);		if( cntxt->backup){			cntxt->curprg = cntxt->backup;			cntxt->backup = 0;		}		showit= TRUE;		skipToEnd(cntxt);		if(showit && cntxt->listing) 			printFunction(GDKout, curBlk, cntxt->listing);		showErrors();		return 1;	}	return 0;}#line 1361 "/export/scratch0/monet/monet.GNU.64.64.d.14791/MonetDB5/src/mal/mal_parser.mx"void parseAssign(Client cntxt, int cntrl) {   	InstrPtr curInstr;	MalBlkPtr curBlk;	Symbol curPrg;	int i=0, l,type=TYPE_any, varid= -1;	int idx;	str arg=0; 	ValRecord cst;	curPrg = cntxt->curprg;	curBlk = curPrg->def;	curInstr = newInstruction(curBlk, cntrl?cntrl:ASSIGNsymbol);	/* start the parsing by recognition of the lhs of an assignment */	if( currChar(cntxt) == '('){		/* parsing multi-assignment */		advance(cntxt,1);		curInstr->argc=0; /*reset to handle pushArg correctly !! */		curInstr->retc=0;		while( currChar(cntxt)  != ')' && currChar(cntxt)) {

⌨️ 快捷键说明

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