Parser abc

Description

A Prolog program parsing the language a*b*c

Source: The Art of Prolog

Download

Program source code: parser_abc.pl

Listing

:- op(40,xfx,\).
 
        s(As\Xs) :-  a(As\Bs), b(Bs\Cs), c(Cs\Xs).
 
        a(Xs\Ys) :-  connect([a],Xs\Xs1), a(Xs1\Ys).
        a(Xs\Ys) :-  connect([ ],Xs\Ys).
 
        b(Xs\Ys) :-  connect([b],Xs\Xs1), b(Xs1\Ys).
        b(Xs\Ys) :-  connect([ ],Xs\Ys).
 
        c(Xs\Ys) :-  connect([c],Xs\Xs1), c(Xs1\Ys).
        c(Xs\Ys) :-  connect([ ],Xs\Ys).
 
        connect([ ],Xs\Xs).
        connect([W|Ws],[W|Xs]\Ys) :-  connect(Ws,Xs\Ys).
 
%     Program 18.8: A Prolog program parsing the language a*b*c

Comments

pl/prolog/pllib/parser_abc.txt · ostatnio zmienione: 2017/07/17 08:08 (edycja zewnętrzna)
www.chimeric.de Valid CSS Driven by DokuWiki do yourself a favour and use a real browser - get firefox!! Recent changes RSS feed Valid XHTML 1.0