void Parse() { BinopPrecedence['<'] = 10; BinopPrecedence['+'] = 20; BinopPrecedence['-'] = 20; BinopPrecedence['*'] = 40; while(1) { fprintf(stderr, "ready > "); switch (CurTok) { case tok_eof: return; case ';': getNextToken(); break; case tok_def: HandleDefinition(); break; case tok_extern: HandleExtern(); break; default: HandleTopLevelExpr(); break; } } }
/// top ::= definition | external | expression | ';' static void MainLoop() { while (1) { fprintf(stderr, "ready> "); switch (CurTok) { case tok_eof: return; case ';': getNextToken(); break; // ignore top-level semicolons. case tok_def: HandleDefinition(); break; case tok_extern: HandleExtern(); break; default: HandleTopLevelExpression(); break; } } }
void MainLoop() { for (;;) { std::cout << "ready> "; switch(CurTok) { case tok_eof: return; case ';': getNextToken(); break; // ignore at top level case tok_def: HandleDefinition(); break; case tok_extern: HandleExtern(); break; default: HandleTopLevelExpression(); break; } } }
/// top ::= definition | external | expression | 'end' static void MainLoop() { try { while (1) { switch (CurTok) { case -1: cout << "James C++ " << rawcodefile << ":" << endl; cout << "####### success #######" << endl; return; case T_DEF: HandleDefinition(); break; case T_EXTERN: HandleExtern(); break; default: HandleTopLevelExpression(); break; } } } catch (runtime_error e) { if (topfileit == TokenlistCopy.end()) { cout << "Woo " << rawcodefile << "(" << TokenlistCopy.back()->lineIndex << "," << TokenlistCopy.back()->start << ")" << ": "; cout << "Error: " << e.what() << endl; int length = 0; for (auto it : TokenlistCopy) { if (it->lineIndex == TokenlistCopy.back()->lineIndex) { cout << it->value; length += it->value.size(); } } cout << endl; for (int i = 0; i < length; ++i) { if (i == TokenlistCopy.back()->start) { cout << '^'; continue; } if (i >= TokenlistCopy.back()->start && i <= TokenlistCopy.back()->end) cout << '~'; else cout << ' '; } return; } cout << "Woo " << rawcodefile << "(" << (*topfileit)->lineIndex << "," << (*topfileit)->start << ")" << ": "; cout << "Error: " << e.what() << endl; int length = 0; for (auto it : TokenlistCopy) { if (it->lineIndex == (*topfileit)->lineIndex) { cout << it->value; length += it->value.size(); } } cout << endl; for (int i = 0; i < length; ++i) { if (i == (*topfileit)->start) { cout << '^'; continue; } if (i >= (*topfileit)->start && i <= (*topfileit)->end) cout << '~'; else cout << ' '; } return; } }