本文整理汇总了C++中Translator::translate方法的典型用法代码示例。如果您正苦于以下问题:C++ Translator::translate方法的具体用法?C++ Translator::translate怎么用?C++ Translator::translate使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Translator
的用法示例。
在下文中一共展示了Translator::translate方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: main
int main(int argc, char** argv) {
string impl = "printer";
const char* script = NULL;
for (int32_t i = 1; i < argc; i++) {
if (string(argv[i]) == "-j") {
impl = "jit";
} else {
script = argv[i];
}
}
Translator* translator = Translator::create(impl);
if (translator == 0) {
cout << "TODO: Implement translator factory in translator.cpp!!!!" << endl;
return 1;
}
const char* expr = "double x; double y;"
"x += 8.0; y = 2.0;"
"print('Hello, x=',x,' y=',y,'\n');"
;
bool isDefaultExpr = true;
if (script != NULL) {
expr = loadFile(script);
if (expr == 0) {
printf("Cannot read file: %s\n", script);
return 1;
}
isDefaultExpr = false;
}
Code* code = 0;
Status* translateStatus = translator->translate(expr, &code);
if (translateStatus->isError()) {
uint32_t position = translateStatus->getPosition();
uint32_t line = 0, offset = 0;
positionToLineOffset(expr, position, line, offset);
printf("Cannot translate expression: expression at %d,%d; "
"error '%s'\n",
line, offset,
translateStatus->getError().c_str());
}
if (code != NULL) {
delete code;
}
delete translateStatus;
delete translator;
if (!isDefaultExpr) {
delete [] expr;
}
return 0;
}
示例2: get_frame_info
FrameInfo get_frame_info(const FrameId& frame) {
if (frames.get()) {
return frames->info_for(frame);
} else if (translate) {
return translator.translate(frame);
} else {
return FrameInfo(frame.module, frame.offset);
}
}
示例3: main
int main(int argc, char** argv) {
const char* script = 0;
std::string mode = INTERPRETE;
for (int32_t i = 1; i < argc; i++) {
if (string(argv[i]) == "-d") {
mode = DISASM;
} else if (string(argv[i]) == "-j") {
mode = JIT;
} else {
script = argv[i];
}
}
if (script == 0) {
cout << "Usage: interpreter [-d | -j] <source_file>" << endl;
return WRONG_ARG_COUNT;
}
const char* expr = loadFile(script);
if (expr == 0) {
cout << "Cannot read file: " << script << endl;
return CANNOT_READ_SOURCE;
}
Translator* translator = new BytecodeTranslatorImpl();
Code* code = 0;
Status* translateStatus = translator->translate(expr, &code);
if (translateStatus == 0) {
//todo
} else if (translateStatus->isError()) {
uint32_t position = translateStatus->getPosition();
uint32_t line = 0, offset = 0;
positionToLineOffset(expr, position, line, offset);
cout << "Cannot translate expression: expression at " << line << ", " << offset << "; "
<< "error '" << translateStatus->getError().c_str() << "'" << endl;
} else {
assert(code != 0);
if (mode == DISASM) {
code->disassemble(cout);
} else if (mode == JIT) {
} else {
vector<Var*> t;
code->execute(t);
}
delete code;
}
delete translateStatus;
delete translator;
return 0;
}
示例4: contextMenuEvent
void TwitterWidgetItemMessage::contextMenuEvent(QContextMenuEvent *event) {
QMenu *menu = createStandardContextMenu(event->pos());
menu->addMenu(languagesMenu);
Translator *translator = Translator::getInstance();
QAction *action = menu->exec(event->globalPos());
if (actionLanguage.find(action) != actionLanguage.end()) {
if (actionLanguage[action] == "-") {
setHtml(QwitTools::prepareMessage(message.text, message.account));
} else {
translator->translate(message.text, actionLanguage[action], this);
}
}
delete menu;
}
示例5: main
int main(int argc, char* argv[]){
std::cout << "loading File...\n";
Translator translator;
translator.loadmRNAFromFile("FILE");
translator.translate();
translator.printmRNA();
std::cout << "Partitioning.." << std::endl;
translator.printCodonStrand();
std::cout << "translating.." << std::endl;
translator.printAminoStrand();
return 0;
}
示例6: main
int main(int argc, char **argv) {
string impl = "printer";
const char *script = NULL;
for (int32_t i = 1; i < argc; i++) {
if (string(argv[i]) == "-j") {
impl = "jit";
} else {
script = argv[i];
}
}
Translator *translator = Translator::create(impl);
if (translator == 0) {
return 1;
}
const char *expr = "double x; double y;"
"x += 8.0; y = 2.0;"
"print('Hello, x=',x,' y=',y,'\n');"
;
bool isDefaultExpr = true;
if (script != NULL) {
expr = loadFile(script);
if (expr == 0) {
printf("Cannot read file: %s\n", script);
return 1;
}
isDefaultExpr = false;
}
Code *code = 0;
Status *translateStatus = translator->translate(expr, &code);
if (translateStatus->isError()) {
uint32_t position = translateStatus->getPosition();
uint32_t line = 0, offset = 0;
positionToLineOffset(expr, position, line, offset);
printf("Cannot translate expression: expression at %d,%d; "
"error '%s'\n",
line, offset,
translateStatus->getError().c_str());
} else {
if (true) { return 0; }
assert(code != 0);
vector<Var *> vars;
if (isDefaultExpr) {
Var *xVar = new Var(VT_DOUBLE, "x");
Var *yVar = new Var(VT_DOUBLE, "y");
vars.push_back(xVar);
vars.push_back(yVar);
xVar->setDoubleValue(42.0);
}
Status *execStatus = code->execute(vars);
if (execStatus->isError()) {
printf("Cannot execute expression: error: %s\n",
execStatus->getError().c_str());
} else {
if (isDefaultExpr) {
printf("x evaluated to %f\n", vars[0]->getDoubleValue());
for (uint32_t i = 0; i < vars.size(); i++) {
delete vars[i];
}
}
}
delete code;
delete execStatus;
}
delete translateStatus;
delete translator;
if (!isDefaultExpr) {
delete [] expr;
}
return 0;
}
示例7: main
int main(int argc, char** argv) {
string impl = "intepreter";
const char* script = NULL;
for (int32_t i = 1; i < argc; i++) {
if (string(argv[i]) == "-j") {
impl = "jit";
} if (string(argv[i]) == "-p") {
impl = "intepreter";
} else {
script = argv[i];
}
}
Translator* translator = Translator::create(impl);
if (translator == 0) {
cout << "TODO: Implement translator factory in translator.cpp!!!!" << endl;
return 1;
}
const char* expr ="int a; a = 8; double b; b = 8.0; print(5 > 3);"
"function void add(double x, int t) {"
"print(x);"
"function void addw3(int y)"
"{"
"print(y);"
"};"
"} "
"function void NEW(int y)"
"{"
"print(y);"
"}; add(b, a); b = 7.3;" ;
// const char* expr = "int a; a = 6; int b; b = 3;"
// "function void mprint(int t) { print(b); function void add(int t) { print (b);} }"
// "mprint(b);";
// const char* expr = "int t; t = 4;"
// "function int strlen(int t) native 'strlen'; function int strlen2(int t) native 'strlen2'; strlen2(t); strlen(t);";
// const char* expr = "int a; a = 8; while (5 > 7) { int a; a = 7; print (a); }";
// const char* expr = "int i; i = 0; for (i in -3..4) {"
// "print(i);"
// "}";
// const char* expr = "int a; a = 31; if (a > 0)"
// "{ int a; a = 3; print(a);} "
// "else {int a; a = 4; print(a);}";
// const char* expr =
// "print(12345678, '\n');"
// "print(-1234567890123456, '\n');"
// "print(1.0, '\n');"
// "print(-2.0, '\n');"
// "print(1e8, '\n');"
// "print(1e-8, '');";
// const char * expr = "print('asd' + 'asdsa');";
// const char* expr =
// "function int fact(int n) {\
// if (n < 3) {\
// return n;\
// }\
// return n*fact(n-1) + fact(n-2);\
// }\
// fact(1);";
//const char* expr = "int l; function int add(int a){ return 8;} l = 3; l*add(l); ";
cout << "expr = " << expr <<endl;
bool isDefaultExpr = true;
if (script != NULL) {
expr = loadFile(script);
if (expr == 0) {
printf("Cannot read file: %s\n", script);
return 1;
}
isDefaultExpr = false;
}
Code* code = 0;
Status* translateStatus = translator->translate(expr, &code);
if (translateStatus->isError()) {
uint32_t position = translateStatus->getPosition();
uint32_t line = 0, offset = 0;
positionToLineOffset(expr, position, line, offset);
printf("Cannot translate expression: expression at %d,%d; "
"error '%s'\n",
line, offset,
translateStatus->getErrorCstr());
} else {
if (impl != "intepreter") {
assert(code != 0);
vector<Var*> vars;
if (isDefaultExpr) {
//.........这里部分代码省略.........
示例8: main
int main(int argc, char** argv) {
string impl = "interpreter";
const char* script = NULL;
for (int32_t i = 1; i < argc; i++) {
if (string(argv[i]) == "-j") {
impl = "jit";
} else {
script = argv[i];
}
}
Translator* translator = Translator::create(impl);
if (translator == 0) {
cout << "TODO: Implement translator factory in translator.cpp!!!!" << endl;
return 1;
}
const char* expr =
"function void a(int i) {"
" print(i, '\n');"
"}"
"a(3);";
bool isDefaultExpr = true;
// script = "/home/mrx/Svn/MathVm/mathvm/students/2014/habibulin/2_1/testing/if.mvm";
if (script != NULL) {
expr = loadFile(script);
if (expr == 0) {
printf("Cannot read file: %s\n", script);
return 1;
}
isDefaultExpr = false;
}
Code* code = 0;
Status* translateStatus = translator->translate(expr, &code);
if (translateStatus->isError()) {
uint32_t position = translateStatus->getPosition();
uint32_t line = 0, offset = 0;
positionToLineOffset(expr, position, line, offset);
printf("Cannot translate expression at %d,%d, "
"error: \n%s\n",
line, offset,
translateStatus->getError().c_str());
} else {
BytecodeInterpreter interpreter;
interpreter.interpret(code);
if(interpreter.status().isError()) {
string cause = interpreter.status().errCause();
size_t pos = interpreter.status().errPos();
uint32_t line = 0, offset = 0;
positionToLineOffset(expr, pos, line, offset);
printf("Cannot translate expression at %d,%d, "
"error: \n%s\n",
line, offset,
cause.c_str());
}
DEBUG_MSG("interpretation finished");
}
delete translateStatus;
delete translator;
if(code) {
delete code;
}
if (!isDefaultExpr) {
delete [] expr;
}
return 0;
}