⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 myreg.h

📁 我的一个利用有限状态机的正则表达式的实现。
💻 H
字号:
#ifndef MY_REG_H
#define MY_REG_H

#include "myafx.h"
#include "myset.h"
#include "MyHash.h"
#include "reg_charset.h"
#include "dstate.h"


struct RegExpNode;
struct RegExpNodeSet;

/*
    Node of the syntax tree of regular expression
*/
REG_EXPORT typedef struct RegExpNode {
    
    REG_CHAR_TYPE type;
    RegExpNode* parent;
    RegExpNode* left;
    RegExpNode* right;
    int nullable;

	char* input;
	int input_count;
	int input_size;

	int sub_re_no;    
    // The first set and last set will not be used
    // when the set contains only the node itself
    // the node point to it self, iff the node is REG_TEXT
    SET* first_set;
    SET* last_set;
	// only char node have follow set
	SET* follow_set;
    
} REG_NODE;

REG_EXPORT typedef struct RegDFA {

	DSTATE** dstates;
	size_t count;
	size_t space_size;
	HASH_TABLE* hash_table;

} REG_DFA;

/*
    Interpreter
    Keep related info about interpretation.
    Every regular expression is complied into an instance of interpreter    
*/
REG_EXPORT typedef struct RegInterpreter {
  
    char* txt;      // regular expression text
    char* rpos;     // read pos
    char* end;      // end of the string
	int sub_re_count; // number of sub regular exp
	int curr_sub_re_no; // current sub regular exp id
    size_t len;     // number of charactors in the text    
    REG_NODE* root;  // the root of the regular expression syntax tree   
    REG_NODE* nodes;    // node pool
    size_t node_pool_size;  // size of the node pool
    size_t node_count;  // number of nodes in the pool

	REG_DFA* dfa; // dfa for reg exp

	SET_FACTORY* factory;  //tempspace and 
    
} REG_INTERP;


REG_EXPORT REG_INTERP* CompileReg( const char* text );
REG_EXPORT int MatchReg( REG_INTERP* inter, char* text );
REG_EXPORT ReleaseReg( REG_INTERP* inter );


// REG_EXPORT REG_CHAR_TYPE REG_CHAR_SET[];


REG_EXPORT void PrintNode( REG_NODE* n );

#endif

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -