Пример #1
0
/**
 * Detect token Expression
 * @param state
 * @param token
 * @return 
 */
int scpiLex_ProgramExpression(lex_state_t * state, scpi_token_t * token) {
    token->ptr = state->pos;

    if (!iseos(state) && ischr(state, '(')) {
        state->pos++;
        skipProgramExpression(state);

        if (!iseos(state) && ischr(state, ')')) {
            state->pos++;
            token->len = state->pos - token->ptr;
        } else {
            token->len = 0;
        }
    }

    if ((token->len > 0)) {
        token->type = SCPI_TOKEN_PROGRAM_EXPRESSION;
    } else {
        token->type = SCPI_TOKEN_UNKNOWN;
        state->pos = token->ptr;
        token->len = 0;
    }

    return token->len;
}
Пример #2
0
/**
 * Skip slash or dot
 * @param state
 * @return 
 */
static int skipSlashDot(lex_state_t * state) {
    if (!iseos(state) && (ischr(state, '/') | ischr(state, '.'))) {
        state->pos++;
        return SKIP_OK;
    } else {
        return SKIP_NONE;
    }
}
Пример #3
0
static void skipQuoteProgramData(lex_state_t * state, char quote) {
    while (!iseos(state)) {
        if (isascii7bit(state->pos[0]) && !ischr(state, quote)) {
            state->pos++;
        } else if (ischr(state, quote)) {
            state->pos++;
            if (!iseos(state) && ischr(state, quote)) {
                state->pos++;
            } else {
                state->pos--;
                break;
            }
        }
    }
}
Пример #4
0
/**
 * Skip colon
 * @param state
 * @return 
 */
static int skipColon(lex_state_t * state) {
    if (!iseos(state) && ischr(state, ':')) {
        state->pos++;
        return SKIP_OK;
    } else {
        return SKIP_NONE;
    }
}
Пример #5
0
/**
 * Skip exact character chr or nothing
 * @param state
 * @param chr
 * @return 
 */
static int skipChr(lex_state_t * state, char chr) {
    if (!iseos(state) && ischr(state, chr)) {
        state->pos++;
        return SKIP_OK;
    } else {
        return SKIP_NONE;
    }
}
Пример #6
0
/**
 * Detect token String data
 * @param state
 * @param token
 * @return 
 */
int scpiLex_StringProgramData(lex_state_t * state, scpi_token_t * token) {
    token->ptr = state->pos;

    if (!iseos(state)) {
        if (ischr(state, '"')) {
            state->pos++;
            token->type = SCPI_TOKEN_DOUBLE_QUOTE_PROGRAM_DATA;
            skipDoubleQuoteProgramData(state);
            if (!iseos(state) && ischr(state, '"')) {
                state->pos++;
                token->len = state->pos - token->ptr;
            } else {
                state->pos = token->ptr;
            }
        } else if (ischr(state, '\'')) {
            state->pos++;
            token->type = SCPI_TOKEN_SINGLE_QUOTE_PROGRAM_DATA;
            skipSingleQuoteProgramData(state);
            if (!iseos(state) && ischr(state, '\'')) {
                state->pos++;
                token->len = state->pos - token->ptr;
            } else {
                state->pos = token->ptr;
            }
        }
    }

    token->len = state->pos - token->ptr;

    if ((token->len > 0)) {
        //token->ptr++;
        //token->len -= 2;
    } else {
        token->type = SCPI_TOKEN_UNKNOWN;
        state->pos = token->ptr;
        token->len = 0;
    }

    return token->len > 0 ? token->len : 0;
}
Пример #7
0
/**
 * Skip program mnemonic [a-z][a-z0-9_]*
 * @param state
 * @return 
 */
static int skipProgramMnemonic(lex_state_t * state) {
    const char * startPos = state->pos;
    if (!iseos(state) && isalpha(state->pos[0])) {
        state->pos++;
        while (!iseos(state) && (isalnum(state->pos[0]) || ischr(state, '_'))) {
            state->pos++;
        }
    }

    if (iseos(state)) {
        return (state->pos - startPos) * SKIP_INCOMPLETE;
    } else {
        return (state->pos - startPos) * SKIP_OK;
    }
}
Пример #8
0
bool Cheat::decode(const char *s, unsigned &addr, uint8_t &data, type_t &type) const {
  string t = s;
  strlower(t);

  #define ischr(n) ((n >= '0' && n <= '9') || (n >= 'a' && n <= 'f'))

  if(strlen(t) == 8 || (strlen(t) == 9 && t[6] == ':')) {
    //strip ':'
    if(strlen(t) == 9 && t[6] == ':') t = string() << substr(t, 0, 6) << substr(t, 7);
    //validate input
    for(unsigned i = 0; i < 8; i++) if(!ischr(t[i])) return false;

    type = ProActionReplay;
    unsigned r = strhex((const char*)t);
    addr = r >> 8;
    data = r & 0xff;
    return true;
  } else if(strlen(t) == 9 && t[4] == '-') {
Пример #9
0
/**
 * Detect token "Character program data"
 * @param state
 * @param token
 * @return 
 */
int scpiLex_CharacterProgramData(lex_state_t * state, scpi_token_t * token) {
    token->ptr = state->pos;

    if (!iseos(state) && isalpha(state->pos[0])) {
        state->pos++;
        while (!iseos(state) && (isalnum(state->pos[0]) || ischr(state, '_'))) {
            state->pos++;
        }
    }

    token->len = state->pos - token->ptr;
    if (token->len > 0) {
        token->type = SCPI_TOKEN_PROGRAM_MNEMONIC;
    } else {
        token->type = SCPI_TOKEN_UNKNOWN;
    }

    return token->len;
}