%% -*- prolog -*-

%% Accept language defined by an NFA.

%% Old style C comments.
%% syntax: starts with /*, ends with */, cannot contain
%% a */ inside.
%% Examples: /* Comment */
%%           /* this /* is /* a single /* Comment */

%% Represent "strings" in langauge as Prolog lists.

%% alphabet:

% sigma(C) :- member(C,[a,b,c,'*','/',' ']).
sigma1(C) :- member(C,[a,b,c,' ']).

not_a_star('/').
not_a_star(C) :- sigma1(C).

sigma(C) :- member(C,'*','/').
sigma(C) :- sigma1(C).

comment(S) :- accepts(start, S).

accepts(start, ['/'|S]) :- accepts(sl,S).
accepts(sl,    ['*'|S]) :- accepts(c,S).
accepts(c,     ['*'|S]) :- accepts(st,S).
accepts(c,     [C  |S]) :- not_a_star(C), accepts(c,S).
accepts(st, ['/']).
accepts(st, ['*'|S]) :- accepts(st, S).
accepts(st, [C|S]) :-
	sigma1(C),
	accepts(c, S).

%%% Difference Lists

%% list of three items: a, b, c
%% direct representation: [a,b,c]

%% Idea!  Represent a list of items as the "difference" between two
%% lists in the computer.  Eg difference between
%%   [a,b,c,d,e,f] and [c,d,e,f] is [a,b]
%%   [a,b,c,d] and [c,d] is [a,b]

%% accept list [a,b] represented as difference list:
dlist_ab([a,b|X],X).

%% stupid grammar:
%%  SENT := NOUN VERB EXCL '.'
%%  NOUN := jack, jill
%%  VERB := jumps up, sits
%%  EXCL := blimy, gosh willikers

noun([jack|X],X).
noun([jill|X],X).
verb([jumps,up|X],X).
verb([sits|X],X).
excl([blimey|X],X).
excl([golly,willikers|X],X).
per(['.'|X],X).
per(['!','!','!','!'|X],X).

sent(X,DONE) :- noun(X,V), verb(V,E), excl(E,P), per(P,DONE).

paragraph(P,Q) :- sent(P,Q).			% paragraph can be one sentence, or
paragraph(P,Q) :- sent(P,R), paragraph(R,Q).	% paragraph can be >1 sentence

