Parsing numbers with multiple digits in Prolog

后端 未结 3 927
北荒
北荒 2021-01-11 14:41

I have the following simple expression parser:

expr(+(T,E))-->term(T),\"+\",expr(E).
expr(T)-->term(T).

term(*(F,T))-->factor(F),\"*\",term(T).
ter         


        
3条回答
  •  滥情空心
    2021-01-11 15:41

    Can you provide a sample input?

    I think this might work:

    nat(N)-->number(N).
    

    If that fails try:

    nat(N)-->number(N),!.
    

    The ! is a cut it stops the unification. You can read about it in books/tutorials.

提交回复
热议问题