:- module(_,_).
% :- use_package(sr/bfall).

%% * Parsing: adding some syntax - using strings
%    -------------------------------------------

myphrase(H,C) :-
    article(H,CA), spaces(CA,CS1),
    noun(CS1,CN),  spaces(CN,CS2),
    verb(CS2,C).


% Reminder: strings "..." are lists of characters 
% i.e., X = "the"  means X = [0't,0'h,0'e], i.e., X = [116,104,101]
% || is for string like | for lists, i.e., 
% what follows is the tail of the list.

article( "a"   || T, T).
% Translates to  article( [ 97|T], T).
% i.e.,          article( [0'a|T], T).
article( "the" || T, T).
% Translates to  article( [0't,0'h,0'e|T], T).


spaces( " "    || T, T).
spaces( " "    || Y, T) :- spaces(Y, T).

noun( "car"    || T, T).
noun( "plane"  || T, T).

verb( "flies"  || T, T).
verb( "drives" || T, T).

% Try:
% ?- myphrase("the plane flies", []).
% ?- myphrase("the plane", []).
% ?- myphrase(S, []).

% ?- set_prolog_flag(write_strings, on).
% ?- myphrase(S, []).

% Try also uncommenting :- use_pakage(sr/bfall).
% above and, again:
% ?- myphrase(S, []).
