switch里边嵌套if可以实现跳转!代码以后附上^_^
if (sl_pp_token_peek_get(&peek, &input)) {
sl_pp_token_peek_destroy(&peek);
return -1;
}
int sl_pp_token_buffer_get(struct sl_pp_token_buffer *buffer,
struct sl_pp_token_info *out)
{
/* Pop from stack first if not empty. */
if (buffer->size) {
*out = buffer->tokens[--buffer->size];
return 0;
}
assert(buffer->context);
return sl_pp_token_get(buffer->context, out);
}
int sl_pp_token_get(struct sl_pp_context *context,
struct sl_pp_token_info *out)
{
int c = _pure_getc(context);
switch (c) {
case ' ':
case '/t':
out->token = SL_PP_WHITESPACE;
break;
case '/n':
out->token = SL_PP_NEWLINE;
break;
case '#':
out->token = SL_PP_HASH;
break;
case ',':
out->token = SL_PP_COMMA;
break;
case ';':
out->token = SL_PP_SEMICOLON;
break;
case '{':
out->token = SL_PP_LBRACE;
break;
case '}':
out->token = SL_PP_RBRACE;
break;
case '(':
out->token = SL_PP_LPAREN;
break;
case ')':
out->token = SL_PP_RPAREN;
break;
case '[':
out->token = SL_PP_LBRACKET;
break;
case ']':
out->token = SL_PP_RBRACKET;
break;
case '.':
{
int c2 = _pure_getc(context);
if (c2 == PURE_ERROR) {
return -1;
}
if (c2 >= '0' && c2 <= '9') {
_pure_ungetc(context, c2);
_pure_ungetc(context, c);
if (_tokenise_number(context, out)) {
return -1;
}
} else {
_pure_ungetc(context, c2);
out->token = SL_PP_DOT;
}
}
break;
case '+':
c = _pure_getc(context);
if (c == PURE_ERROR) {
return -1;
}
if (c == '+') {
out->token = SL_PP_INCREMENT;
} else if (c == '=') {
out->token = SL_PP_ADDASSIGN;
} else {
_pure_ungetc(context, c);
out->token = SL_PP_PLUS;
}
break;
case '-':
c = _pure_getc(context);
if (c == PURE_ERROR) {
return -1;
}
if (c == '-') {
out->token = SL_PP_DECREMENT;
} else if (c == '=') {
out->token = SL_PP_SUBASSIGN;
} else {
_pure_ungetc(context, c);
out->token = SL_PP_MINUS;
}
break;
case '~':
out->token = SL_PP_BITNOT;
break;
case '!':
c = _pure_getc(context);
if (c == PURE_ERROR) {
return -1;
}
if (c == '=') {
out->token = SL_PP_NOTEQUAL;
} else {
_pure_ungetc(context, c);
out->token = SL_PP_NOT;
}
break;
case '*':
c = _pure_getc(context);
if (c == PURE_ERROR) {
return -1;
}
if (c == '=') {
out->token = SL_PP_MULASSIGN;
} else {
_pure_ungetc(context, c);
out->token = SL_PP_STAR;
}
break;
case '/':
c = _pure_getc(context);
if (c == PURE_ERROR) {
return -1;
}
if (c == '=') {
out->token = SL_PP_DIVASSIGN;
} else {
_pure_ungetc(context, c);
out->token = SL_PP_SLASH;
}
break;
case '%':
c = _pure_getc(context);
if (c == PURE_ERROR) {
return -1;
}
if (c == '=') {
out->token = SL_PP_MODASSIGN;
} else {
_pure_ungetc(context, c);
out->token = SL_PP_MODULO;
}
break;
case '<':
c = _pure_getc(context);
if (c == PURE_ERROR) {
return -1;
}
if (c == '<') {
c = _pure_getc(context);
if (c == PURE_ERROR) {
return -1;
}
if (c == '=') {
out->token = SL_PP_LSHIFTASSIGN;
} else {
_pure_ungetc(context, c);
out->token = SL_PP_LSHIFT;
}
} else if (c == '=') {
out->token = SL_PP_LESSEQUAL;
} else {
_pure_ungetc(context, c);
out->token = SL_PP_LESS;
}
break;
case '>':
c = _pure_getc(context);
if (c == PURE_ERROR) {
return -1;
}
if (c == '>') {
c = _pure_getc(context);
if (c == PURE_ERROR) {
return -1;
}
if (c == '=') {
out->token = SL_PP_RSHIFTASSIGN;
} else {
_pure_ungetc(context, c);
out->token = SL_PP_RSHIFT;
}
} else if (c == '=') {
out->token = SL_PP_GREATEREQUAL;
} else {
_pure_ungetc(context, c);
out->token = SL_PP_GREATER;
}
break;
case '=':
c = _pure_getc(context);
if (c == PURE_ERROR) {
return -1;
}
if (c == '=') {
out->token = SL_PP_EQUAL;
} else {
_pure_ungetc(context, c);
out->token = SL_PP_ASSIGN;
}
break;
case '&':
c = _pure_getc(context);
if (c == PURE_ERROR) {
return -1;
}
if (c == '&') {
out->token = SL_PP_AND;
} else if (c == '=') {
out->token = SL_PP_BITANDASSIGN;
} else {
_pure_ungetc(context, c);
out->token = SL_PP_BITAND;
}
break;
case '^':
c = _pure_getc(context);
if (c == PURE_ERROR) {
return -1;
}
if (c == '^') {
out->token = SL_PP_XOR;
} else if (c == '=') {
out->token = SL_PP_BITXORASSIGN;
} else {
_pure_ungetc(context, c);
out->token = SL_PP_BITXOR;
}
break;
case '|':
c = _pure_getc(context);
if (c == PURE_ERROR) {
return -1;
}
if (c == '|') {
out->token = SL_PP_OR;
} else if (c == '=') {
out->token = SL_PP_BITORASSIGN;
} else {
_pure_ungetc(context, c);
out->token = SL_PP_BITOR;
}
break;
case '?':
out->token = SL_PP_QUESTION;
break;
case ':':
out->token = SL_PP_COLON;
break;
case '/0':
out->token = SL_PP_EOF;
break;
case PURE_ERROR:
return -1;
default:
if ((c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z') || c == '_') {
_pure_ungetc(context, c);
if (_tokenise_identifier(context, out)) {
return -1;
}
} else if (c >= '0' && c <= '9') {
_pure_ungetc(context, c);
if (_tokenise_number(context, out)) {
return -1;
}
} else {
out->data.other = c;
out->token = SL_PP_OTHER;
}
}
return 0;
}