-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathdcg1_3.pl
54 lines (45 loc) · 1.31 KB
/
dcg1_3.pl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
%% %%%%%%
% restart prolog to clear out 1_2 before running this
%
beep_boop --> anything, beep(Suffix), anything, boop(Suffix), anything.
beep(X) -->
"beep",
suffix(X).
boop(X) -->
"boop",
suffix(X).
suffix([H|T]) -->
[H],
{
code_type(H, digit)
},
suffix(T).
suffix([]) --> []. % must be 2nd suffix clause, or the digits wind up in anything
% At bottom for efficiency. At the top, would match beep first
anything --> [].
anything --> [_], anything.
% A subtlety here. "foo 7 beep1 bar boop14 fdds" is part of the language
%
try_beep_boop :- member(X, [
`sdfdsbeep24sldfkboop14dfk`,
`sdfdsbeep24sldfkbeep14dfk`,
`beepboop`,
`beep`,
`beep2boop`,
` beep boop`]),
( phrase(beep_boop, X)
-> format('\"~s\" is a beepboop~n', [X])
; format('\"~s\" is not~n', [X])
),
fail.
try_beep_boop.
%% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% ; works for alternatives
article_phrase --> ("a" ; "an"),
" ",
noun.
noun --> "book".
noun --> "car".
%
% Look at all solutions
try_article_phrase :- phrase(article_phrase, X),format('~s~n', [X]).