Calculator::Token_type Calculator::get_token() { char ch = 0; char ch2 = 0; in >> ch; switch (ch) { case 0: return cur_tok = END; case '+': case '-': case '*': case '/': case '(': case ')': case '=': case '?': case ':': case '&': case '|': case '^': return cur_tok = Token_type(ch); case '<': case '>': case '!': in >> ch2; if (ch2 == '=') return cur_tok = (ch == '>') ? GEQ : ( (ch == '<') ? LEQ : NEQ ); else { in.putback(ch2); return cur_tok = Token_type(ch); } case '0': case '1': case '2': case '3': case '4': case '5': case '6': case '7': case '8': case '9': // case '.': in.putback(ch); in >> cur_value; return cur_tok = NUMBER; case '%': cur_value = *def_value; return cur_tok = NUMBER; default: throw "Unknown token."; } }
void Test_message() { int i; Token *token = test.intprt.token; Token_get(token); for (i=0; Token_type(token) == STRING_token; i++){ if (i >= MAX_REPEAT){ term_error("テストのメッセージが多すぎます。"); } test.message_buf[i] = Test_alloc(strlen(Token_now(token))+1); strcpy(test.message_buf[i], Token_now(token)); Token_get(token); } }
/** * 試験テキスト内の!TEXT後を処理する */ void Test_text() { int i; Token *token = test.intprt.token; Token_get(token); for (i=0; Token_type(token) == STRING_token; i++){ if (i < MAX_TEXT){ test.text_buf[i] = Test_alloc(strlen(Token_now(token))+1); strcpy(test.text_buf[i], Token_now(token)); } else { term_error("練習テキストが多すぎます。"); } Token_get(token); } test.text_no = i; }