RegEx Parser written in Prolog

前端 未结 2 1534
自闭症患者
自闭症患者 2021-01-02 15:19

I\'ve been banging my head against the wall on this homework problem for a few hours now. We have to parse a regular expression with Prolog. For the most part, the predicat

2条回答
  •  执念已碎
    2021-01-02 15:38

    I don't have access to SWI Prolog right now, but here is a guess:

    Try changing

    re_match(star(Rx), List) :- append(List1, List2, List),
                                re_match(Rx, List1),
                                re_match(star(Rx), List2).
    

    to

    re_match(star(Rx), List) :- append([H|List1], List2, List),
                                re_match(Rx, [H|List1]),
                                re_match(star(Rx), List2).
    

    to force re_match to "eat something" when it iterates on the star construct.

提交回复
热议问题