feat add func call and rewrite codes
This commit is contained in:
@@ -105,7 +105,7 @@ enum CSTD_KEYWORD {
|
||||
// END
|
||||
|
||||
// 定义TokenType枚举
|
||||
enum TokenType {
|
||||
typedef enum tok_type {
|
||||
// 处理普通token
|
||||
#define X(str, tok) tok,
|
||||
TOKEN_TABLE
|
||||
@@ -115,9 +115,9 @@ enum TokenType {
|
||||
#define X(name, std, tok) tok,
|
||||
KEYWORD_TABLE
|
||||
#undef X
|
||||
};
|
||||
} tok_type_t;
|
||||
|
||||
struct TokenConstant {
|
||||
typedef struct tok_val {
|
||||
int have;
|
||||
union {
|
||||
char ch;
|
||||
@@ -127,124 +127,31 @@ struct TokenConstant {
|
||||
long long ll;
|
||||
char* str;
|
||||
};
|
||||
};
|
||||
} tok_val_t;
|
||||
|
||||
// "break"
|
||||
// "case"
|
||||
// "char"
|
||||
// "const"
|
||||
// "continue"
|
||||
// "default"
|
||||
// "do"
|
||||
// "double"
|
||||
// "else"
|
||||
// "enum"
|
||||
// "extern"
|
||||
// "float"
|
||||
// "for"
|
||||
// "goto"
|
||||
// "if"
|
||||
// "inline (C99)"
|
||||
// "int"
|
||||
// "long"
|
||||
// "register"
|
||||
// "restrict (C99)"
|
||||
// "return"
|
||||
// "short"
|
||||
// "signed"
|
||||
// "sizeof"
|
||||
// "static"
|
||||
// "struct"
|
||||
// "switch"
|
||||
// "typedef"
|
||||
// "union"
|
||||
// "unsigned"
|
||||
// "void"
|
||||
// "volatile"
|
||||
// "while"
|
||||
typedef struct tok {
|
||||
tok_type_t type;
|
||||
tok_val_t val;
|
||||
} tok_t;
|
||||
|
||||
// alignas (C23)
|
||||
// alignof (C23)
|
||||
// auto
|
||||
// bool (C23)
|
||||
// constexpr (C23)
|
||||
// false (C23)
|
||||
// nullptr (C23)
|
||||
// static_assert (C23)
|
||||
// thread_local (C23)
|
||||
// true (C23)
|
||||
// typeof (C23)
|
||||
// typeof_unqual (C23)
|
||||
// _Alignas (C11)
|
||||
// _Alignof (C11)
|
||||
// _Atomic (C11)
|
||||
// _BitInt (C23)
|
||||
// _Bool (C99)
|
||||
// _Complex (C99)
|
||||
// _Decimal128 (C23)
|
||||
// _Decimal32 (C23)
|
||||
// _Decimal64 (C23)
|
||||
// _Generic (C11)
|
||||
// _Imaginary (C99)
|
||||
// _Noreturn (C11)
|
||||
// _Static_assert (C11)
|
||||
// _Thread_local (C11)
|
||||
typedef struct tok_buf {
|
||||
int cur;
|
||||
int end;
|
||||
int peek;
|
||||
int size;
|
||||
int cap;
|
||||
tok_t* buf;
|
||||
void* stream;
|
||||
void (*gettok)(void* stream, tok_t* token);
|
||||
} tok_buf_t;
|
||||
|
||||
// a = b
|
||||
// a += b
|
||||
// a -= b
|
||||
// a *= b
|
||||
// a /= b
|
||||
// a %= b
|
||||
// a &= b
|
||||
// a |= b
|
||||
// a ^= b
|
||||
// a <<= b
|
||||
// a >>= b
|
||||
|
||||
// ++a
|
||||
// --a
|
||||
// a++
|
||||
// a--
|
||||
|
||||
// +a
|
||||
// -a
|
||||
// a + b
|
||||
// a - b
|
||||
// a * b
|
||||
// a / b
|
||||
// a % b
|
||||
// ~a
|
||||
// a & b
|
||||
// a | b
|
||||
// a ^ b
|
||||
// a << b
|
||||
// a >> b
|
||||
|
||||
// !a
|
||||
// a && b
|
||||
// a || b
|
||||
|
||||
// a == b
|
||||
// a != b
|
||||
// a < b
|
||||
// a > b
|
||||
// a <= b
|
||||
// a >= b
|
||||
|
||||
// a[b]
|
||||
// *a
|
||||
// &a
|
||||
// a->b
|
||||
// a.b
|
||||
|
||||
// a(...)
|
||||
// a, b
|
||||
// (type) a
|
||||
// a ? b : c
|
||||
// sizeof
|
||||
|
||||
// _Alignof
|
||||
// (C11)
|
||||
typedef void(*get_tokbuf_func)(void* stream, tok_t* token);
|
||||
void init_tokbuf(tok_buf_t* tokbuf, void* stream, get_tokbuf_func gettok);
|
||||
tok_t* peek_tok(tok_buf_t* tokbuf);
|
||||
tok_t* pop_tok(tok_buf_t* tokbuf);
|
||||
void flush_peek_tok(tok_buf_t* tokbuf);
|
||||
tok_type_t peek_tok_type(tok_buf_t* tokbuf);
|
||||
int expect_pop_tok(tok_buf_t* tokbuf, tok_type_t type);
|
||||
const char* get_tok_name(tok_type_t type);
|
||||
|
||||
#endif
|
||||
Reference in New Issue
Block a user