本文整理汇总了C++中Interpreter::clear方法的典型用法代码示例。如果您正苦于以下问题:C++ Interpreter::clear方法的具体用法?C++ Interpreter::clear怎么用?C++ Interpreter::clear使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Interpreter
的用法示例。
在下文中一共展示了Interpreter::clear方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: main
int main() {
buildTools();
Tokenizer tokenizer;
char str[1024] = "z=1;p = func(){ z=2;};";
//char str[1024] = "a;c;b = func(a){a=3;c=5;};if(a){b=3;}for(a=0;a<10;a++){b=3;}while(a>3)a--;do{a++;}while(a<10);";
//str[0] = '\0';
//str = "a=1;";
Interpreter interpreter;
ProgramBuilder builder;
int length = 0;
std::vector<Object*> programs;
do {
TokenList list;
tokenizer.tokenize(str, list);
//tokenizer.printList(list);
Object* program = builder.buildProgram(list);
if (program) {
programs.push_back(program);
builder.printProgram(program);
const Object* object = program->firstChild;
bool terminate = interpreter.interprete(program);
if (terminate) {
break;
}
if (object->nextSibling == nullptr) {
if (object->firstChild && object->firstChild->objectType == Tt_value) {
interpreter.printStackTop(builder);
}
}
length = 0;
} else {
if (str[length] == '\0' || (str[length] == '\n' && str[length + 1] == '\0')) {
length = 0;
} else {
length = strlen(str);
str[length] = ' ';
str[length + 1] = '\0';
length++;
}
}
if (length == 0) {
printf(">> ");
} else {
printf(">>>> ");
}
fgets(str + length, sizeof(str), stdin);
} while (feof(stdin) == false);
for (unsigned i = 0; i < programs.size(); i++) {
builder.deleteProgram(programs[i]);
}
builder.clear();
interpreter.clear();
return 0;
}