How to get the AST of a regular expression string?

后端 未结 3 1779
长情又很酷
长情又很酷 2020-12-28 17:51

How can I get the abstract syntax tree (AST) of a regular expression (in C++)?

For example,

 (XYZ)|(123)

should yield a tree of:<

3条回答
  •  借酒劲吻你
    2020-12-28 18:01

    boost::regex seems to have a hand-written recursive-descent parser in basic_regex_parser.hpp. Even though it feels awfully like re-inventing the wheel, you are probably faster when writing up the grammar in boost::spirit yourself, especially with the multitude of regex formats around.

提交回复
热议问题