Example #1
0
void EditCommand :: AddSubCmd( const string & ev ) {
	if ( ALib::IsEmpty( ev ) ) {
		CSVTHROW( "Empty value for " << FLAG_EDIT );
	}

	if ( ! isalpha( ev[0] ) ) {			// for now
		CSVTHROW( "Edit sub command missing from " << ev );
	}

	char cmd;
	vector <string> tmp;
	ParseSub( ev, cmd, tmp );
//	for ( unsigned int i = 0; i < tmp.size(); i++ ) {
//		std::cout << "[" << tmp[i] << "]" << std::endl;
//	}

	mSubCmds.push_back ( EditSubCmd( cmd, tmp[0], tmp[1], tmp[2] ) );
}
Example #2
0
NodeStatement* Parser::ParseElement()
{
	if (t.GetValue() == "begin")
		return ParseBlock();
	if (t.GetValue() == "if") 
		return ParseIf();
	if (t.GetValue() == "while")
		return ParseWhile();
	if (t.GetValue() == "repeat")
		return ParseRepeat();
	if (t.GetValue() == "for")
		return ParseFor();
	if (t.GetValue() == "write")
		return ParseWrite(true, false);
	if (t.GetValue() == "writeln")
		return ParseWrite(true, true);
	if (t.GetValue() == "exit")
	{
		t = sc.GetNextToken();
		return new StatementExit(true);
	}
	if (t.GetType() == identifier)
	{
		bool found = false;
		_Table::iterator it = TableStack.Find(t.GetValue(), found);
		if (found)
		{
			if (it->second->IsProc() || it->second->IsFunc())
			{
				t = sc.GetNextToken();
				return ParseSub((SymProc*)it->second);
			}
		}
		return ParseAssignment();
	}
	if (t.GetValue() == "(")
	{
		return ParseAssignment();
	}
	throw Error("Statement error", t);
}
int CUnit3DLoader::ParseSub(CFileHandler& ifs, UnitModel &model,const string& filename,float3 offset,const string& treename)
{
	string s;
	bool inComment=false;

	Animation* curAnim=0;
	int curAnimFrame=0;

	bool firstGeometryPass=false;

	if(geometryModels.find(treename)==geometryModels.end()){
		geometryModels[treename]=new UnitModelGeometry();
		UnitModelGeometry& geometry=*geometryModels[treename];
		firstGeometryPass=true;
		geometry.normalBuffer=0;
		geometry.indexBuffer=0;
		geometry.numIndeces=0;
		geometry.numVerteces=0;
	}
	model.geometry=geometryModels[treename];
	UnitModelGeometry& geometry=*model.geometry;
	
	geometry.radius=1;
	geometry.height=1;
	geometry.isAnimated=false;

	model.texCoordBuffer=0;

	while(ifs.Peek()!=EOF){
		s=GetWord(ifs);
		MakeLow(s);
		if(s[0]=='/' && !inComment){
			if(s[1]=='/'){
				GetLine(ifs);
				continue;
			}
			if(s[1]=='*')
				inComment=true;
		}
		if(inComment){
			for(int a=0;a<s.size()-1;++a)
				if(s[a]=='*' && s[a+1]=='/')
					inComment=false;
			if(inComment)
				continue;
		}
		if(ifs.Eof())
			break;
		while((s.c_str()[0]=='/') || (s.c_str()[0]=='\n')){
			s=GetLine(ifs);
			s=GetWord(ifs);
			MakeLow(s);
			if(ifs.Eof())
				break;
		}
		if(s=="vertex"){
			int num=atoi(GetWord(ifs).c_str());
			float3 v;
			v.x=atof(GetWord(ifs).c_str());
			v.y=atof(GetWord(ifs).c_str());
			v.z=atof(GetWord(ifs).c_str());
			v-=offset;

			if(firstGeometryPass){
				if(curAnim==0){
					while(geometry.vertex.size()<=num){
						geometry.vertex.push_back(float3(0,0,0));
						geometry.vertexNormal.push_back(float3(0,0,0));
					}
					geometry.vertex[num]=v;
				} else {
					AnimFrame* af=&curAnim->frames[curAnimFrame];
					while(af->vertex.size()<=num){
						af->vertex.push_back(float3());
	//					model.vertexNormal.push_back(float3(0,0,0));
					}
					af->vertex[num]=v;
				}
			}
		} else if(s=="quad"){
			Quad q;
			QuadTex qt;
			for(int a=0;a<4;++a)
				q.verteces[a]=atoi(GetWord(ifs).c_str());
			for(int a=0;a<8;++a)
				qt.texPos[0][a]=atof(GetWord(ifs).c_str());
			qt.texName=GetWord(ifs);
			qt.teamTex=atoi(GetWord(ifs).c_str());
			q.normalType=atoi(GetWord(ifs).c_str());
			model.quadTex.push_back(qt);
			if(firstGeometryPass)
				geometry.quad.push_back(q);

		} else if(s=="tri"){
			Tri t;
			TriTex tt;
			for(int a=0;a<3;++a)
				t.verteces[a]=atoi(GetWord(ifs).c_str());
			for(int a=0;a<3;++a){
				tt.texPos[0][a*2]=1-atof(GetWord(ifs).c_str());
				tt.texPos[0][a*2+1]=1-atof(GetWord(ifs).c_str());
			}
			tt.texName=GetWord(ifs);
			tt.teamTex=atoi(GetWord(ifs).c_str());
			t.normalType=atoi(GetWord(ifs).c_str());
			model.triTex.push_back(tt);
			if(firstGeometryPass)
				geometry.tri.push_back(t);

		} else if(s=="propeller"){
			Propeller p;
			for(int a=0;a<3;++a)
				p.pos[a]=atof(GetWord(ifs).c_str());
			p.size=atof(GetWord(ifs).c_str());
			if(firstGeometryPass)
				geometry.propellers.push_back(p);

		} else if(s=="height"){
			geometry.height=atof(GetWord(ifs).c_str());

		} else if(s=="radius"){
			geometry.radius=atof(GetWord(ifs).c_str());

		} else if(s=="subobject"){
			UnitModel* um=new UnitModel;
			model.subModels.push_back(um);
			um->name=GetWord(ifs);
			float3 off,rot;
			for(int a=0;a<3;++a)
				off[a]=atof(GetWord(ifs).c_str());
			for(int a=0;a<3;++a)
				rot[a]=atof(GetWord(ifs).c_str());
			um->team=model.team;

			char c[100];
			sprintf(c,"%s%d",treename.c_str(),model.subModels.size());
			ParseSub(ifs,*um,filename,off,c);

			um->geometry->offset=off;
			um->geometry->rotVector=rot;
		} else if(s=="endsubobject"){
			return 1;

		} else if(s=="animation"){
			string name=GetWord(ifs);
			if(name=="end")
				curAnim=0;
			else{
				if(geometry.animations.find(name)==geometry.animations.end()){
					geometry.animations[name]=new Animation;
				}
				curAnim=geometry.animations[name];
			}
			curAnimFrame=0;
			geometry.isAnimated=true;

		} else if(s=="keyframe"){
			string num=GetWord(ifs);
			if(num=="end"){
				curAnimFrame=0;
			} else {
				curAnimFrame=atoi(num.c_str());
				float length=atoi(GetWord(ifs).c_str())/25.0f*30.0f;
				if(curAnim){
					while(curAnim->frames.size()<=curAnimFrame){
						curAnim->frames.push_back(AnimFrame());
					}
					curAnim->frames[curAnimFrame].length=length;
				}
			}

		} else {
			if(s!="")
				(*info) << "Unknown token " << s.c_str() << " in " << filename.c_str() << "\n";
		}
	}
	return 1;
}
int CUnit3DLoader::Parse(const string& filename, UnitModel &model)
{
	string dir="unitmodels/";
	CFileHandler ifs(dir+filename);
	return ParseSub(ifs,model,filename,float3(0,0,0),model.name);
}
Example #5
0
NodeExpression* Parser::ParseFactor()
{
	NodeExpression* r = NULL;
	if (t.GetValue() == "-" || t.GetValue() == "+" || t.GetValue() == "not")
	{
		string op = t.GetValue();
		t = sc.GetNextToken();
		NodeExpression* _r = ParseFactor();
		r = new NodeUnaryOp(new Symbol(op), _r);
		r->SetType(_r->GetType());
	}
	else
	{
		if (t.GetValue() != "(" && t.GetType() != identifier && t.GetType() != int_const_dec && t.GetType() != float_const)
			throw Error("Syntax error : unexpected \""+t.GetValue()+"\";", t);
		if(t.GetValue() == "(")
		{
			t = sc.GetNextToken();
			r = ParseComparision();
			t = RequireToken(")" , "\")\" expected");
		}
		switch(t.GetType()){
			case int_const_dec : case float_const:
			{
				SymVarConst* _const = new SymVarConst(t.GetValue(), t.GetValue(), NULL);
				if (t.GetType() == int_const_dec)
					_const->SetType((SymType*)mainTable->find("integer")->second);
				else
					_const->SetType((SymType*)mainTable->find("real")->second);
				t = sc.GetNextToken();
				r = new NodeConst(_const);
				r->SetType(_const->GetType());
				return r;
				break;
			}
			case identifier:
			{
				Token t1 = t;
				bool found = false;
				_Table::iterator it = TableStack.Find(t1.GetValue(), found);
				if (!found)
					throw Error("unknown identifier", t);
				t = sc.GetNextToken();
				SymVar* name = (SymVar*)it->second;
				SymType* Type = name->GetType();
				if (t.GetValue() == "(")
				{
					if (!it->second->IsFunc())
						throw Error("unexpected identifier", t);
					if (((SymFunc*)it->second)->IsForward())
						throw Error("undefined forward ("+it->second->GetName()+")", t);
					r = ParseSub((SymFunc*)it->second);
				}
				else
					if(name->GetType()->IsRec() || name->GetType()->IsArr())
					{
						r = new NodeVar(name);
						r->SetType(Type);
						while(name->GetType()->IsRec() || name->GetType()->IsArr())
						{
							SymVar* name2 = name;
							if (name->GetType()->IsRec())
								r = ParseRec(r, name);
							if (name->GetType()->IsArr())
								r = ParseArr(r,name);
							if (name2 == name)
								break;
						}
					}
					else
					{
						if (name->IsConst())
							r = new NodeConst(it->second);
						else
							r = new NodeVar(it->second);
						r->SetType(Type);
					}
				break;
			}
		}
	}
	return r;
}