http://parsing-techniques.duguying.net/ (中文版)
https://swtch.com/~rsc/regexp/
https://blog.csdn.net/maxners/article/category/7381272 (中文版)
DFA的应用:简单bool表达式解析的例子
/********************************************************* DFA "{uint1}&({uint2}|{uint3})" => "_&(_|_)" ---'{'--> (S_templat) (S_cmp_unit) <--'}'--- *********************************************************/ bool init(const std::string& orign_expr_str) { enum class ECharStatus { templat = 1, cmp_unit = 2 }; std::string ret_template_expr; std::vector<std::pair<size_t, std::string>> ret_cmp_unit_pair_list; std::string cmp_uint_str; ECharStatus status = ECharStatus::templat; for (const char& c : orign_expr_str) { switch (c) { case '{': { if (status == ECharStatus::cmp_unit) return false; status = ECharStatus::cmp_unit; } break; case '}': { if (status == ECharStatus::templat) return false; status = ECharStatus::templat; ret_template_expr.push_back('_'); ret_cmp_unit_pair_list.push_back(std::make_pair(ret_template_expr.size() - 1, cmp_uint_str)); cmp_uint_str.clear(); } break; default: { if (status == ECharStatus::templat) ret_template_expr.push_back(c); if (status == ECharStatus::cmp_unit) cmp_uint_str.push_back(c); } break; } } if (!cmp_uint_str.empty() || status != ECharStatus::templat) return false; return true; }