{
if (argc<3)
{
- printf("bbs2 <filename.bbs> <cxx|py|js>\n");
+ printf("bbs2 <InputFile.bbs> <OutputFile.[cxx|py|js]> \n");
return 1;
}
// file = fileBase + std::string(".") + extention;
std::string fileBase,path;
- std::string extention( argv[2] );
- fileBase = bbtk::Utilities::ExtractScriptName(argv[1],path);
- std::string file(path+"/"+fileBase+"."+extention);
+//EED 2023-11-15
+// std::string extention( argv[3] );
+// fileBase = bbtk::Utilities::ExtractScriptName(argv[1],path);
+// std::string file(path+"/"+fileBase+"."+extention);
+ std::string file( argv[2] );
printf("file %s \n",file.c_str() );
- if ( extention.compare("cxx")==0)
+ std::string extentionCxx = file.substr( file.length()-3, 3);
+ if ( extentionCxx.compare(".cxx")==0)
{
printf("bbs -> cxx\n");
bbtk::Interpreter::Pointer I = bbtk::Interpreter::New(file);
} // try
} // if cxx
- if ( extention.compare("py")==0)
+ std::string extentionPy = file.substr( file.length()-2, 2);
+ if ( extentionPy.compare("py")==0)
{
printf("bbs -> py\n");
bbtk::InterpreterPython::Pointer I = bbtk::InterpreterPython::New();
I->InterpretFile(argv[1]);
std::vector<std::string> pythonBBTK= ((bbtk::InterpreterPython*)(I.get()))->pythonBBTK ;
FILE *ff=fopen(file.c_str(),"w+");
- fprintf(ff,"\n" );
- fprintf(ff,"from bbtk.bbtkBlackBox import *\n" );
- fprintf(ff,"\n" );
- fprintf(ff,"class %s(ComplexBlackBox):\n",fileBase.c_str() );
- fprintf(ff,"\n" );
- fprintf(ff," def __init__(self, nameBox):\n" );
- fprintf(ff," super().__init__(nameBox)\n" );
- fprintf(ff,"\n" );
- fprintf(ff," def Run(self):\n" );
int i,size=pythonBBTK.size();
for (i=0; i<size;i++)
{
- fprintf(ff," self.%s\n", pythonBBTK[i].c_str() );
+ fprintf(ff,"%s\n", pythonBBTK[i].c_str() );
}// for i
- fprintf(ff," self.Execute()\n" );
fclose(ff);
} catch (bbtk::Exception e) {
e.Print();
} // try
} // if py
- if ( extention.compare("js")==0)
+ std::string extentionJs = file.substr( file.length()-2, 2);
+ if ( extentionJs.compare("js")==0)
{
printf("bbs -> js\n");
bbtk::InterpreterJavaScript::Pointer I = bbtk::InterpreterJavaScript::New();
std::vector<std::string> javascriptBBTK= ((bbtk::InterpreterJavaScript*)(I.get()))->javascriptBBTK ;
FILE *ff=fopen(file.c_str(),"w+");
fprintf(ff,"import * as bbtk from './bbtk.js' \n" );
- fprintf(ff,"export class %s{\n",fileBase.c_str() );
+//clean this code
+// fprintf(ff,"export class %s{\n",fileBase.c_str() );
fprintf(ff," Run(){\n" );
- fprintf(ff," let mCBjs = new bbtk.ComplexBlackBox('%s')\n",fileBase.c_str());
+//clean this code
+// fprintf(ff," let mCBjs = new bbtk.ComplexBlackBox('%s')\n",fileBase.c_str());
int i,size=javascriptBBTK.size();
for (i=0; i<size;i++)
{
std::string boxTypeTmp=boxType;
boxTypeTmp.replace(pos,1,"_");
// ex: mCB.New( bbtkBlackBox.std_ConcatString("Box10") )
- std::string code("New( "+boxTypeTmp+"('"+boxName+"') )");
+ std::string code(" self.New( "+boxTypeTmp+"('"+boxName+"') )");
this->pythonBBTK.push_back(code);
}
//=========================================================================
const std::string &input) // virtual
{
//ex: mCB.Connection( "Box10" , "Out", "Box11", "In")
- std::string code("Connection('"+boxfrom+"','"+output+"','"+boxto+"','"+input+"')");
+ std::string code(" self.Connection('"+boxfrom+"','"+output+"','"+boxto+"','"+input+"')");
this->pythonBBTK.push_back(code);
}
//=========================================================================
//=========================================================================
void InterpreterPython::commandInput(const std::string &name,const std::string &box,const std::string &input,const std::string &help)
{
- std::string code("DECLARE_INPUT('"+name+"','"+box+"."+input+"')");
+ std::string code(" self.DECLARE_INPUT('"+name+"','"+box+"."+input+"')");
this->pythonBBTK.push_back(code);
}
//=========================================================================
//=========================================================================
void InterpreterPython::commandOutput(const std::string &name,const std::string &box,const std::string &output,const std::string &help)
{
- std::string code("DECLARE_OUTPUT('"+name+"','"+box+"."+output+"')");
+ std::string code(" self.DECLARE_OUTPUT('"+name+"','"+box+"."+output+"')");
this->pythonBBTK.push_back(code);
}
//=========================================================================
void InterpreterPython::commandSet(const std::string &box,const std::string &input,const std::string &value) // virtual
{
//ex: mCB.Set("Box10","In2","/hola.mhd")
- std::string code("Set('"+box+"','"+input+"','"+value+"')");
+ std::string code(" self.Set('"+box+"','"+input+"','"+value+"')");
this->pythonBBTK.push_back(code);
}
//=========================================================================
//=========================================================================
void InterpreterPython::commandDefine(const std::string &name,const std::string &pack,const std::string &scriptfilename) // virtual
{
+
+ this->pythonBBTK.push_back(" ");
+ this->pythonBBTK.push_back("from bbtk.bbtkBlackBox import *");
+ this->pythonBBTK.push_back(" ");
+ this->pythonBBTK.push_back("class "+pack+"_"+name+"(ComplexBlackBox):");
+ this->pythonBBTK.push_back(" ");
+ this->pythonBBTK.push_back(" def __init__(self, nameBox):");
+ this->pythonBBTK.push_back(" super().__init__(nameBox)");
+ this->pythonBBTK.push_back(" self.Init()");
+ this->pythonBBTK.push_back(" ");
+ this->pythonBBTK.push_back(" def Init(self):");
+
}
//=========================================================================
void InterpreterPython::commandExec(const std::string &word) // virtual
{
//Ex: mCB.AddToExecutableLst("Box13")
- std::string code("AddToExecutableLst('"+word+"')");
+ std::string code(" self.AddToExecutableLst('"+word+"')");
this->pythonBBTK.push_back(code);
}
//=========================================================================