%% -*- prolog -*-

%% this does not work to load file: [29-Nov-2007].
%% because Prolog parses it as: ['-'(29,'-'(Nov,2007))].

%% this works to load file: ['29-Nov-2007'].


%% Append
app([], X, X).
app([E|X], Y, [E|Z]) :- app(X,Y,Z).

%% predefined: append/3


%% Member
mem1(E,[E|_]).
mem1(E,[_|L]) :- mem1(E,L).

%% Member in terms of append
mem(E,L) :- app(_,[E|_],L).

%% predefined: member/2

%% two lists are the same length
same_length([],[]).
same_length([_|L1],[_|L2]) :- same_length(L1,L2).

%% 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,'*','/',' ']).

all_in_sigma([]).
all_in_sigma([C|L]) :- sigma(C), all_in_sigma(L).

comment1(L) :-
	append(['/','*'|_],['*','/'],L),
	all_in_sigma(L).

%% bug: comment1(['/','*','*','/',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]) :-
	%% not_a_star_or_slash(C),
	accepts(c, S).
