/// Try and match a given character in the input /// The character is consumed if matched bool Input::matchCh(char ch) { if (peekCh() == ch) { readCh(); return true; } return false; }
bool LogFileWatcher::changed() { if( timer.expired() && filePos != fileSize() ) { bool feof; while( !(feof = file.eof()) && peekCh() != '\n' && bufpos < WATCHER_BUF_SIZE-3 ) { buffer[ bufpos++ ] = getCh(); // ++filePos; } if( !feof ) { if( peekCh() == '\n' ) getCh(); buffer[bufpos++] = '\n'; buffer[bufpos++] = '\0'; return (completeLine = true); } // wait another interval for completed line. timer.reset(interval); } return false; }
/// Read a character from the input char Input::readCh() { char ch = peekCh(); idx++; if (ch == '\n') { lineNo++; colNo = 1; } else { colNo++; } return ch; }
/// Consume whitespace and comments void Input::eatWS() { // Until the end of the whitespace for (;;) { // Consume whitespace characters if (isspace(peekCh())) { readCh(); continue; } // If this is a single-line comment if (matchStr("//")) { // Read until and end of line is reached for (;;) { char ch = readCh(); if (ch == '\n' || ch == '\0') break; } continue; } // If this is a multi-line comment if (matchStr("/*")) { // Read until the end of the comment for (;;) { char ch = readCh(); if (ch == '*' && matchCh('/')) break; } continue; } // This isn't whitespace, stop break; } }
void AsmBuf::relational(Value *val) { Value v2; bool fLabel; orExpr(&v2); fLabel = v2.fLabel; while(1) { switch(nextNonSpaceLF()) { case '<': if (peekCh() == '>') { nextCh(); orExpr(val); v2.value = v2.value != val->value; v2.size = getSizeCh(v2.size, val->size); fLabel = false; } else if (peekCh() == '=') { nextCh(); orExpr(val); v2.value = v2.value <= val->value; v2.size = getSizeCh(v2.size, val->size); fLabel = false; } else if (peekCh() != '<') { orExpr(val); v2.value = v2.value < val->value; v2.size = getSizeCh(v2.size, val->size); fLabel = false; } else { unNextCh(); goto xitLoop; } break; case '>': if (peekCh() == '=') { nextCh(); orExpr(val); v2.value = v2.value >= val->value; v2.size = getSizeCh(v2.size, val->size); fLabel = false; } else if (peekCh() != '>') { orExpr(val); v2.value = v2.value > val->value; v2.size = getSizeCh(v2.size, val->size); fLabel = false; } else { unNextCh(); goto xitLoop; } break; case '=': orExpr(val); v2.value = v2.value == val->value; v2.size = getSizeCh(v2.size, val->size); fLabel = false; break; case '!': if (peekCh() == '=') { nextCh(); orExpr(val); v2.value = v2.value != val->value; v2.size = getSizeCh(v2.size, val->size); fLabel = false; } else { unNextCh(); goto xitLoop; } break; default: unNextCh(); goto xitLoop; } } xitLoop: *val = v2; val->fLabel = fLabel; return; }
String *AsmBuf::getArg() { int Depth = 0; char c; int dqcount = 0, sqcount = 0; String *arg = new String(); skipSpacesLF(); while(1) { c = (char)peekCh(); // Quit loop on newline or end of buffer. if (c < 1 || c == '\n') break; switch (c) { // If quote encountered then scan till closing quote or end of line case '"': arg->add(c); nextCh(); while(1) { c = (char)nextCh(); if (c < 1 || c == '\n') goto EndOfLoop; arg->add(c); if (c == '"') break; } continue; // If quote encountered then scan till closing quote or end of line case '\'': arg->add(c); nextCh(); while(1) { c = (char)nextCh(); if (c < 1 || c == '\n') goto EndOfLoop; arg->add(c); if (c == '\'') break; } continue; case '(': Depth++; break; case ')': if (Depth < 1) // check if we hit the end of the arg Err(E_CPAREN); Depth--; break; case ',': if (Depth == 0) // comma at outermost level means goto EndOfLoop; // end of argument has been found break; // On semicolon scan to end of line without copying characters to arg case ';': goto EndOfLoop; // while(1) { // c = (char)nextCh(); // if (c < 1 || c == '\n') // goto EndOfLoop; // } } arg->add(c); // copy input argument to argstr. nextCh(); } EndOfLoop: if (Depth > 0) Err(E_PAREN); //printf("arg:%s|", arg->buf()); arg->trim(); // get rid of spaces around argument return arg; }