リストの入力記号で文法規則をコールする。
phrase/2 は、リストにリストされた入力記号で文法規則 項 をコールする。
項 項 リスト 記号のリスト
polish(Stack, Result) -->
[X], {integer(X)}, polish([X|Stack], Result).
polish([Y,X|Stack], Result) -->
[(+)], {Z is X+Y}, polish([Z|Stack], Result).
polish([Y,X|Stack], Result) -->
[(-)], {Z is X-Y}, polish([Z|Stack], Result).
polish([Z], Z) -->
[].
main(X) :-
phrase(polish([], Result), [2,3,(+),1,(-)]),
println(['result = ', Result]).
成功して、"result = 4"を出す。
この述語は、ISO-Prolog 標準には含まれない。