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

📄 mal_parser.c

📁 一个内存数据库的源代码这是服务器端还有客户端
💻 C
📖 第 1 页 / 共 5 页
字号:
	}	tpe = getTypeIndex(CURRENT(cntxt), l, -1);	if (tpe < 0) {		parseError(cntxt, "Type identifier expected\n");		return TYPE_void;	}	advance(cntxt, l);	return tpe;}int parseTypeId(Client cntxt, int defaultType){   	int i = TYPE_any, ht, tt, kh = 0, kt = 0;	char *s= CURRENT(cntxt);	if ( strncmp(s, ":bat[", 5) == 0) {		/* parse :bat[:type,:type] */		 advance(cntxt,5);		if( currChar(cntxt) ==':') {			ht = simpleTypeId(cntxt);			kh = typeAlias(cntxt,ht);		} else ht = TYPE_any;		if (currChar(cntxt) != ',') {			parseError(cntxt, "',' expected\n");			return i;		} 		nextChar(cntxt); /* skip , */		skipSpace(cntxt);		if( currChar(cntxt) ==':') {			tt = simpleTypeId(cntxt);			kt = typeAlias(cntxt,tt);		} else tt= TYPE_any;		i = newBatType(ht, tt);		if (kh > 0)			setAnyHeadIndex(i, kh);		if (kt > 0)			setAnyTailIndex(i, kt);		if (currChar(cntxt) != ']')			parseError(cntxt, "']' expected\n");		nextChar(cntxt); /* skip ']' */		skipSpace(cntxt);		return i;	}  	if( (strncmp(s,":bat",4)==0 ||		 strncmp(s,":BAT",4)==0 )  && !idCharacter[(int) s[4]]) {		advance(cntxt,4);		return TYPE_bat;	} 	if( strncmp(s,":col",4)==0 && !idCharacter[(int) s[4]]) {		/* parse default for :col[:any] */		advance(cntxt,4);		return newColType(TYPE_any);	} 	if( currChar(cntxt) ==':'){		ht = simpleTypeId(cntxt);		kt = typeAlias(cntxt,ht);		if( kt > 0)			setAnyTailIndex(ht,kt);		return ht;	} 	parseError(cntxt,"<type identifier> expected\n");	return defaultType;}INLINE int typeElm(Client cntxt, int def){	if (currChar(cntxt) != ':')		return def;	/* no type qualifier */	return parseTypeId(cntxt,def);}#line 727 "/export/scratch0/monet/monet.GNU.64.64.d.14791/MonetDB5/src/mal/mal_parser.mx"intcharCst(Client cntxt, ValPtr cst) {	int i;	str v = CURRENT(cntxt);	if (*v != '\'')		return 0;	cst->vtype = TYPE_chr;	cst->val.cval[1]= 0;	cst->val.cval[2]= 0;	cst->val.cval[3]= 0;	v++;	i = 1;	if (*v == '\\') {		v++; i++;		switch(*v){		case 'n':			cst->val.cval[0]= '\n';			break;		case 'r':			cst->val.cval[0]= '\r';		case 't':			cst->val.cval[0]= '\t';			break;		case '\\':			v++;i++;			cst->val.cval[0]= *v;			break;		default:			if (isdigit(*v)) {				i++; v++;			}			if (isdigit(*v)) {				i++; v++;			}			if (isdigit(*v)) {				i++; v++;			}			cst->val.cval[0]= (char) strtol(v,NULL,0);		}	} else {		cst->val.cval[0]= *v;		v++;	}	if (*v != '\'')		return i+1;	return i+2;}#line 812 "/export/scratch0/monet/monet.GNU.64.64.d.14791/MonetDB5/src/mal/mal_parser.mx"str parseAtom(Client cntxt) {	str modnme = 0,s;	int l, tpe;	char *nxt= CURRENT(cntxt);	if ( (l =idLength(cntxt)) <= 0)		return parseError(cntxt, "atom name expected\n");	/* parse: ATOM id:type */	modnme = putName(nxt, l);	advance(cntxt,l);	if (currChar(cntxt) != ':')		tpe= TYPE_void;	/* no type qualifier */	else tpe = parseTypeId(cntxt, TYPE_int);	s = loadLibrary(modnme);	if (s)		stream_printf(cntxt->fdout, "#WARNING: %s\n", s);	malAtomDefinition(modnme, tpe);	cntxt->nspace = fixModule(cntxt->nspace, modnme);	cntxt->nspace->isAtomModule = TRUE;	#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))){			cntxt->nspace->help = strCopy(cntxt,l);			advance(cntxt,l);		} else {			parseError(cntxt,"<string> expected\n");		}	} else 	if (currChar(cntxt) != ';')		parseError(cntxt,"';' expected\n");	skipToEnd(cntxt);#line 834 "/export/scratch0/monet/monet.GNU.64.64.d.14791/MonetDB5/src/mal/mal_parser.mx"	return "";}str parseModule(Client cntxt) {	str modnme = 0,s;	int l;	char *nxt;	nxt= CURRENT(cntxt);	if ((l = idLength(cntxt)) <= 0)		return parseError(cntxt, "<module path> expected\n");	modnme = putName(nxt, l);	s = loadLibrary(modnme);	if (s)		stream_printf(cntxt->fdout, "#WARNING: %s\n", s);	advance(cntxt,l);	cntxt->nspace = fixModule(cntxt->nspace, modnme);	#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))){			cntxt->nspace->help = strCopy(cntxt,l);			advance(cntxt,l);		} else {			parseError(cntxt,"<string> expected\n");		}	} else 	if (currChar(cntxt) != ';')		parseError(cntxt,"';' expected\n");	skipToEnd(cntxt);#line 854 "/export/scratch0/monet/monet.GNU.64.64.d.14791/MonetDB5/src/mal/mal_parser.mx"	return "";}#line 871 "/export/scratch0/monet/monet.GNU.64.64.d.14791/MonetDB5/src/mal/mal_parser.mx"strparseInclude(Client cntxt){	str modnme = 0,s;	int x;	char *nxt;	if (!MALkeyword(cntxt,"include",7)) 		return 0;	nxt= CURRENT(cntxt);	if ( (x = idLength(cntxt)) >0 ){		modnme= putName(nxt,x);		advance(cntxt,x);	} else	if ( (x = stringLength(cntxt))>0){		modnme= putName(nxt+1,x-1);		advance(cntxt,x);	} else		return parseError(cntxt,"<module name> expected\n");	if (currChar(cntxt) != ';') {		parseError(cntxt,"';' expected\n");		skipToEnd(cntxt);		return "";	}	skipToEnd(cntxt);	s = loadLibrary(modnme);	if (s)		stream_printf(cntxt->fdout, "#WARNING: %s\n", s);	malInclude(cntxt, modnme, 0);	return "";}#line 1182 "/export/scratch0/monet/monet.GNU.64.64.d.14791/MonetDB5/src/mal/mal_parser.mx"MalBlkPtr parseCommandPattern(Client cntxt, int kind){	MalBlkPtr curBlk = 0;	Symbol curPrg = 0;	InstrPtr curInstr=0;	int l;	str fnme=0, modnme=0;	char ch;	int varid=0;	int type= TYPE_void;	#line 933 "/export/scratch0/monet/monet.GNU.64.64.d.14791/MonetDB5/src/mal/mal_parser.mx"	l = operatorLength(cntxt);	if (l == 0)		l = idLength(cntxt);	if (l == 0)		return (MalBlkPtr) parseError(cntxt,				"<identifier> | <operator> expected\n");	fnme= putName( ((char *) CURRENT(cntxt)),l);	advance(cntxt,l);	if (currChar(cntxt) == '.') {		nextChar(cntxt); /* skip '.' */		modnme = fnme;		l= operatorLength(cntxt);		if (l == 0)			l = idLength(cntxt);		if (l == 0)			return (MalBlkPtr) parseError(cntxt,					"<identifier> | <operator> expected\n");		fnme= putName( ((char *) CURRENT(cntxt)),l);		advance(cntxt,l);	} 	/* temporary suspend capturing statements in main block */	if( cntxt->backup && curBlk && curBlk->errors==0) 		GDKfatal("mal_parser: unexpected recursion\n");	cntxt->backup = cntxt->curprg;	cntxt->curprg = newFunction(fnme, kind);	curPrg = cntxt->curprg;		curBlk = curPrg->def;	curBlk->flowfixed= 0;	curBlk->typefixed= 0;	curInstr = getInstrPtr(curBlk,0);	#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 966 "/export/scratch0/monet/monet.GNU.64.64.d.14791/MonetDB5/src/mal/mal_parser.mx"	if (currChar(cntxt) != '(') 		return (MalBlkPtr)parseError(cntxt, "function header '(' expected\n"); 	advance(cntxt,1);	setModuleId(curInstr, modnme?putName(modnme,strlen(modnme)): 			putName(cntxt->nspace->name, strlen(cntxt->nspace->name)));	/* get calling parameters */	ch= currChar(cntxt);	while( ch !=')' && ch && !NL(ch)){		#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( 1){			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);

⌨️ 快捷键说明

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