1 Star 0 Fork 14

AI/ftrpc

forked from RonxBulld/ftrpc 
加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
lex.h 1.61 KB
一键复制 编辑 原始数据 按行查看 历史
//
// Created by Rexfield on 2018/4/26.
//
#ifndef FTRPC_LEX_H
#define FTRPC_LEX_H
#include <string>
#include <iostream>
#include <map>
#include <stack>
#include <stdexcept>
#include "symman.h"
typedef unsigned int StringID;
enum TokenEnum
{
TOKEN_EOF = 0,
TOKEN_START = 256,
TOKEN_ID,
TOKEN_INTEGER_LITERAL,
#define TYPE(k) TOKEN_##k,
#define KEYWD(k) TOKEN_##k,
#include "keywords.h"
};
struct token
{
enum TokenEnum type;
const char * literal;
size_t length;
union MultiVal
{
int i;
StringID string;
char c;
TokenID token;
} value;
};
struct lexer_info
{
size_t lineno;
size_t rowno;
};
class LexException : public std::exception
{
private:
std::string msg;
public:
explicit LexException(const std::string &msg) {
this->msg = msg;
std::cerr << this->msg << std::endl;
}
~LexException() throw() {
}
};
class lex
{
private:
size_t iptr = 0;
size_t start_ptr = 0;
size_t maxptr = 0;
void TokenConvert(struct token &Tk);
void IntegerConvert(struct token &Tk);
std::map<std::string, enum TokenEnum> keywdMap;
std::stack<struct token> tokenStack;
std::stack<size_t> ptrStack;
const char *src;
TokenManage *tokenManage;
public:
explicit lex(const char *src, TokenManage *tokenManage);
struct token getToken();
// const std::string &GetString(StringID id);
void pushBack(struct token T);
struct lexer_info getLexerInfo();
void pushPtr();
void popPtr();
};
#endif //FTRPC_LEX_H
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
C++
1
https://gitee.com/xiaoyangge/ftrpc.git
git@gitee.com:xiaoyangge/ftrpc.git
xiaoyangge
ftrpc
ftrpc
master

搜索帮助

0d507c66 1850385 C8b1a773 1850385