38 lines
987 B
C
38 lines
987 B
C
#ifndef __SMCC_CC_LEXER_H__
|
|
#define __SMCC_CC_LEXER_H__
|
|
|
|
#include <lib/core.h>
|
|
#include "token.h"
|
|
#ifndef LEXER_MAX_TOKEN_SIZE
|
|
#define LEXER_MAX_TOKEN_SIZE 63
|
|
#endif
|
|
#ifndef LEXER_BUFFER_SIZE
|
|
#define LEXER_BUFFER_SIZE 4095
|
|
#endif
|
|
|
|
typedef int (*lexer_sread_fn)(void *dst_buf, int elem_size, int count, void *stream);
|
|
|
|
typedef struct cc_lexer {
|
|
loc_t loc;
|
|
|
|
char* cur_ptr; // 当前扫描的字符,但是还没有开始扫描
|
|
char* end_ptr; // 缓冲区最后一个字符的下一个位置
|
|
char buffer[LEXER_BUFFER_SIZE+1];
|
|
|
|
lexer_sread_fn sread;
|
|
void* stream;
|
|
|
|
strpool_t* strpool;
|
|
} cc_lexer_t;
|
|
|
|
void init_lexer(cc_lexer_t* lexer, const char* file_name, void* stream,
|
|
lexer_sread_fn sread, strpool_t* strpool);
|
|
|
|
// pure token getter it will included empty token like TOKEN_BLANK
|
|
void get_token(cc_lexer_t* lexer, tok_t* token);
|
|
|
|
// get_token maybe got invalid (with parser as TOKEN_BLANK)
|
|
void get_valid_token(cc_lexer_t* lexer, tok_t* token);
|
|
|
|
#endif
|