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; } } }
int CheckIfGuidance(char *line,int isLabel) { int i; char *word; i = isLabel ? isLabel + 2 : 0; /* Ignore spaces */ while(isspace(line[i])) i++; if (line[i++]=='.') { word=GetWord(&line[i],' '); if(strcmp(word,"extern")==0) { /* Step over .extern word in line */ i+=7; /* Ignore spaces */ while(isspace(line[i])) i++; HandleExtern(&line[i]); return 1; } else if(strcmp(word,"entry")==0) { i+=6; while(isspace(line[i])) i++; HandleEntry(&line[i],&constInstructionArr[MAX_INSTRUCTION-1]); return 1; } else { printf("Error! in Line %d :%s , illegal command \n", countLine, line); SeconnedPhaseSucess=0; } } else { return 0; } return 0; }
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; } }