shared_ptr <GLTF::JSONObject> serializePrimitive(GLTFPrimitive* primitive, void *context) { void** primitiveContext = (void**)context; shared_ptr <GLTF::JSONObject> primitiveObject(new GLTF::JSONObject()); GLTFMesh* mesh = (GLTFMesh*)primitiveContext[0]; primitiveObject->setString("primitive", primitive->getType()); primitiveObject->setString("material", primitive->getMaterialID()); shared_ptr <GLTF::JSONObject> semantics(new GLTF::JSONObject()); primitiveObject->setValue("semantics", semantics); size_t count = primitive->getIndicesInfosCount(); for (size_t j = 0 ; j < count ; j++) { GLTF::Semantic semantic = primitive->getSemanticAtIndex(j); std::string semanticAndSet = GLTFUtils::getStringForSemantic(semantic); unsigned int indexOfSet = 0; if ((semantic != GLTF::POSITION) && (semantic != GLTF::NORMAL)) { indexOfSet = primitive->getIndexOfSetAtIndex(j); semanticAndSet += "_" + GLTFUtils::toString(indexOfSet); } semantics->setString(semanticAndSet, mesh->getMeshAttributesForSemantic(semantic)[indexOfSet]->getID()); } shared_ptr <GLTF::GLTFIndices> uniqueIndices = primitive->getUniqueIndices(); shared_ptr <GLTF::JSONObject> serializedIndices = serializeIndices(uniqueIndices.get(), primitiveContext[1]); primitiveObject->setValue("indices", serializedIndices); return primitiveObject; }
/** * @brief Builds compound semantics from the given list of IDs. * * If @a semanticsIds is of the form <tt>("sem1", "sem2", "sem3")</tt>, then the * resulting compound semantics will be of the form <tt>(sem1, sem2, sem3)</tt>. * This means that when the functions from the Semantics' interface are called, * @c sem1 is asked first, then @c sem2 (if @c sem1 doesn't know the answer) and * so on. * * For every ID in @a semanticsIds, the builder calls SemanticsFactory to obtain * an instance of the requested semantics. If there is no semantics with a given * ID, a warning message is emitted and the semantics is not added. */ ShPtr<CompoundSemantics> CompoundSemanticsBuilder::build( const StringVector &semanticsIds) { ShPtr<CompoundSemantics> compoundSemantics(CompoundSemantics::create()); // Try to instantiate and add all semantics from semanticsIds. for (const auto &id : semanticsIds) { ShPtr<Semantics> semantics(SemanticsFactory::getInstance().createObject(id)); if (semantics) { compoundSemantics->appendSemantics(semantics); } else { printWarningMessage("There is no registered semantics with ID \"", id, "\", skipping."); } } return compoundSemantics; }
std::string tokenpaths::create_analysis(const unsigned char& toa,const std::string& target_language){ std::map<std::string,std::string> related_functors; std::map<std::string,std::map<std::string,std::string> > functors_of_words; unsigned int nr_of_analyses=valid_paths.size(); if(nr_of_analyses==0&&toa==HI_MORPHOLOGY){ logger::singleton()==NULL?(void)0:logger::singleton()->log(0,"There is 1 analysis."); } else{ logger::singleton()==NULL?(void)0:logger::singleton()->log(0,"There are "+std::to_string(nr_of_analyses)+" analyses."); } std::string analysis="{\"analyses\":["; if(nr_of_analyses==0){ analysis+="{"; std::map<std::string,std::vector<lexicon> > words_analyses=lexer::words_analyses(); if(toa&HI_MORPHOLOGY){ analysis+="\"morphology\":["; for(auto&& word_analyses:words_analyses){ analysis+=morphology(word_analyses.second); } if(analysis.back()==',') analysis.pop_back(); analysis+="],"; } if(toa&HI_SYNTAX){ analysis+="\"syntax\":["; analysis+="],"; } if(toa&HI_SEMANTICS){ std::string semantic_analysis="\"semantics\":["; std::vector<std::string> word_forms=lexer::word_forms(); unsigned int id_index=0; for(auto&& word_form:word_forms){ auto&& word_analyses=words_analyses.find(word_form); related_functors.clear(); semantic_analysis+=semantics(word_analyses->second,related_functors,id_index,target_language); functors_of_words.insert(std::make_pair(word_analyses->first,related_functors)); } if(semantic_analysis.back()==',') semantic_analysis.pop_back(); semantic_analysis+="],"; std::string functor_analysis="\"functors\":["; std::string related_semantics="\"related semantics\":["; functor_analysis+=functors(functors_of_words,words_analyses,id_index,related_semantics); if(functor_analysis.back()==',') functor_analysis.pop_back(); functor_analysis+="],"; if(related_semantics.back()==',') related_semantics.pop_back(); related_semantics+="],"; analysis+=semantic_analysis; analysis+=related_semantics; analysis+=functor_analysis; } if(invalid_path_errors.empty()==false){ analysis+="\"errors\":["; unsigned int id=0; for(auto&& error:invalid_path_errors){ analysis+="{\"tokenpath id\":\""+std::to_string(++id)+"\",\"messages\":["+error+"]},"; } if(analysis.back()==',') analysis.pop_back(); analysis+="]"; } if(analysis.back()==',') analysis.pop_back(); analysis+="}"; } else{ for(unsigned int i=0;i<nr_of_analyses;++i){ related_functors.clear(); analysis+="{"; if(toa&HI_MORPHOLOGY){ analysis+="\"morphology\":["+morphology(valid_paths.at(i)); if(analysis.back()==',') analysis.pop_back(); analysis+="],"; } if(toa&HI_SYNTAX){ analysis+="\"syntax\":["; analysis+=syntax(valid_parse_trees.at(i)); analysis+="],"; } if(toa&HI_SEMANTICS){ analysis+="\"semantics\":["+valid_graphs.at(i)->transcript(related_functors,target_language); if(analysis.back()==',') analysis.pop_back(); analysis+="],"; analysis+="\"functors\":["; for(auto&& functor:related_functors){ analysis+="{"; analysis+="\"functor id\":\""+functor.first+"\","; analysis+="\"definition\":\""+functor.second+"\""; analysis+="},"; } if(analysis.back()==',') analysis.pop_back(); analysis+="]"; } if(analysis.back()==',') analysis.pop_back(); analysis+="},"; } if(analysis.back()==',') analysis.pop_back(); } analysis+="]}"; return analysis; }
void semantics(ASTnode* ASTroot){ firstMatrix=1; if(ASTroot==NULL){ return; } int z,noTraverse=0; ASTnode *rows,*l; token bufToken; SymbolTable *tmp; SymbolTableEntryNode *t; int p=0; if(sflag==0){ //first time, main function so create a symbol table for main function sflag=1; S[0]=createSymbolTable(size, NULL, "MAIN");//parentTable of Main is NULL symbolStack=createSymbolStack(); pushSymbolStack(S[0],symbolStack); p=1; counter++; } switch(ASTroot->label){ //Symbol Table creates only in 1, 61, 64 //Symbol table populates in 1:functionDef,31:declarationStmt case 1://make a new symbol table, this would be the scope unless an END is encountered, functionDef InsertSymbolTable(topSymbolStack(symbolStack), ASTroot); S[counter]=createSymbolTable(size, topSymbolStack(symbolStack),ASTroot->array[1]->t.lexeme); pushSymbolStack(S[counter],symbolStack); InsertSymbolTableFun(topSymbolStack(symbolStack), ASTroot);//for input and output arguments of function p=1; counter++; break; case 2://ifstmt S[counter]=createSymbolTable(size, topSymbolStack(symbolStack),"IF"); pushSymbolStack(S[counter],symbolStack); p=1; counter++; break; case 3: noTraverse=1; if(strcmp(topSymbolStack(symbolStack)->symbolTableName,ASTroot->array[0]->t.lexeme)==0){//checking for Recursion semanticError(3,ASTroot->array[0]->t); return; } //check for input parameter list and function signature- input and output tmp=topSymbolStack(symbolStack); while(tmp!=NULL){ z=SearchHashTable(tmp, ASTroot->array[0]->t.lexeme); if(z!=-1) break; else tmp=tmp->parentTable; } if(tmp==NULL){ semanticError(1,ASTroot->t); break; }//declaration of FunId is checked here itself t=findSymbolTableNode(tmp->table[z].next,ASTroot->array[0]->t.lexeme); if(t->type.fid.outputSize!=typeCounter){ semanticError(5,ASTroot->array[0]->t); break; } else{ for(z=0; z<=t->type.fid.outputSize; z++){ if(t->type.fid.output[z]!=type[z]){ semanticError(5,ASTroot->array[0]->t); noTraverse=1; break;//from for } } typeCounter=-1;//successfully implemented. } l=ASTroot->array[1]; for(z=0; z<=t->type.fid.inputSize; z++){ if(l==NULL){ semanticError(5,ASTroot->array[0]->t);//number of output parameters noTraverse=1; break; } if(t->type.fid.input[z]!=findTypeVar(l->array[0])){ semanticError(14,ASTroot->array[0]->t);//type Mismatch noTraverse=1; break; } l=l->array[1]; } break; case 11://else stmt S[counter]=createSymbolTable(size, topSymbolStack(symbolStack),"ELSE"); pushSymbolStack(S[counter],symbolStack); p=1; counter++; break; case 26:if(ASTroot->array[0]->label==67){ t=getSymbolTableNode(ASTroot->array[1]); t->type.id.initialized=1; } case 27: break; case 28: break; //it should not come case 29: break; case 30: break; case 31://declaration stmt InsertSymbolTable(topSymbolStack(symbolStack), ASTroot); return; break; case 51://Assignment noTraverse=1; typeCounter=-1; if(ASTroot->array[1]->label==3){//function call statement if(ASTroot->array[0]->label==54){//single list if(outputCheck1(ASTroot->array[0])==0)//send leaf directly return; //1- it should already have been declared, 2-if so, then it's type should be recorded } else{ //send l if(outputCheck(ASTroot->array[0])==0) return; } semantics(ASTroot->array[1]); } if(ASTroot->array[1]->label==60){//size stmt //1- check if ID is declared, 2- What is the type of ID, 3- Compare with the return type if(!isDeclared(ASTroot->array[1]->array[0])){ semanticError(1,ASTroot->array[1]->array[0]->t); return; } z=findType(ASTroot->array[1]->array[0],0); if(z==57){ if(outputCheck(ASTroot->array[0])==0){//it will populate type of LHS if declared, else returns 0 return; } else{//declared if(!(typeCounter==0&&type[0]==57)) semanticError(6,ASTroot->array[0]->t); return; } } else if(z==58){ if(outputCheck(ASTroot->array[0])==0){//it will populate type of LHS if declared, else returns 0 return; } else{//declared if(!(typeCounter==1&&type[0]==55&&type[1]==55)) semanticError(6,ASTroot->array[0]->t); return; } } else { semanticError(8,ASTroot->array[1]->array[0]->t);//Size contains other that String and Matrix } } if(ASTroot->array[1]->label==37){//Arithmetic Expression l=ASTroot->array[0]; z=findType(l,1); if(l->label==54){ if(z==57){ if(ASTroot->array[1]->array[1]==NULL){ if(ASTroot->array[1]->array[0]->array[1]==NULL){ if(findTypeVar(ASTroot->array[1]->array[0]->array[0])==57){//initialization StringInit(ASTroot->array[0],ASTroot->array[1]->array[0]->array[0]->t.lexeme); return; } } } } else if(z==58){//lhs is matrix firstMatrix=1; if(ASTroot->array[1]->array[1]==NULL){ if(ASTroot->array[1]->array[0]->array[1]==NULL){ if((ASTroot->array[1]->array[0]->array[0]->label)==44){//initialization MatrixInit(ASTroot->array[0],ASTroot->array[1]->array[0]->array[0]); return; } } } } } if(z==-1) break; typeCounter++; type[typeCounter]=z; if((z=findTypeAE(ASTroot->array[1]))!=type[typeCounter]){ bufToken.lineNumber=l->t.lineNumber; semanticError(10,bufToken); break; } //valid Arithmetic expression //debug(); t= getSymbolTableNode(ASTroot->array[0]); t->type.id.initialized=1; typeCounter=-1; } break; case 52://go to case 54 case 54: if(!isDeclared(ASTroot)) semanticError(1,ASTroot->t); break; case 75:// AND case 76:// OR case 77:// LT case 78:// LE case 79:// EQ case 80:// GT case 81:// GE case 82:// NE case 83:// NOTbooleanExpressionSemantics(ASTnode* BE) noTraverse=1; if(booleanExpressionSemantics(ASTroot)==0){ semanticError(10,bufToken); } default: break; }//end of switch int i; if(noTraverse==0){ for( i=0; i<ASTroot->arraySize; i++){ if(ASTroot->array[i]!=NULL){ semantics(ASTroot->array[i]); } } } if(p){ //if popping SymbolTable is a function, then check if it's output parameter are accurately initialised or not tmp=popSymbolStack(symbolStack); if(strcmp(tmp->symbolTableName,"MAIN")!=0&&strcmp(tmp->symbolTableName,"IF")!=0&&strcmp(tmp->symbolTableName,"ELSE")!=0){//it is a function int i; for(i=0; i<tmp->outputParameter; i++){ t=outputParameterInitCheck(tmp,tmp->outputParameterLexeme[i]); if(t->type.id.initialized!=1) { semanticError(13,ASTroot->array[1]->t); break; } } } } }//end of function
int main() { semantics("ª¨ª¨¥Î·}ÀYºV°v¤l"); // »y·N¸ÑªR½d¨Ò 1 semantics("¿ß¦Y³½"); // »y·N¸ÑªR½d¨Ò 2 }