70:- system_module( '$_grammar', [
!/2,
82 (
'|')
/4], [
'$do_error'/2]).
97prolog
:'$translate_rule'(
Rule, (
NH :- B) )
:-
99 '$yap_strip_module'(
SM:Rule,
M0, (
LP-->RP) ),
100 t_head(
LP,
NH0,
NGs,
S,
SR, (
LP-->SM:RP)),
101 '$yap_strip_module'(
M0:NH0,
M,
NH1 ),
102 (
M == SM -> NH = NH1 ; NH = M:NH1 ),
104 t_body(
RP,
_, last,
S,
SR,
B1)
106 t_body((
RP,{
NGs}),
_, last,
S,
SR,
B1)
109t_head(
V,
_,
_,
_,
_,
G0)
:- var(
V),
var,
110 '$do_error'(instantiation_error,
G0).
111t_head((
H,
List),
NH,
NGs,
S,
S1,
G0)
:- t_head,
112 t_hgoal(
H,
NH,
S,
SR,
G0),
113 t_hlist(
List,
S1,
SR,
NGs,
G0).
114t_head(
H,
NH,
_,
S,
SR,
G0)
:-
115 t_hgoal(
H,
NH,
S,
SR,
G0).
117t_hgoal(
V,
_,
_,
_,
G0)
:- var(
V),
var,
118 '$do_error'(instantiation_error,
G0).
119t_hgoal(
M:H,
M:NH,
S,
SR,
G0)
:- t_hgoal,
120 t_hgoal(
H,
NH,
S,
SR,
G0).
121t_hgoal(
H,
NH,
S,
SR,
_)
:-
122 dcg_extend([
S,
SR],
H,
NH).
124t_hlist(
V,
_,
_,
_,
G0)
:- var(
V),
var,
125 '$do_error'(instantiation_error,
G0).
126t_hlist([],
_,
_, true,
_).
127t_hlist(
String,
S0,
SR,
SF,
G0)
:- string(
String),
string,
128 string_codes(
String,
X ),
129 t_hlist(
X,
S0,
SR,
SF,
G0).
130t_hlist([
H],
S0,
SR, (
'C'(
SR,
H,
S0)),
_)
:- t_hlist.
131t_hlist([
H|List],
S0,
SR, (
'C'(
SR,
H,
S1),
G0),
Goal)
:- t_hlist,
132 t_hlist(
List,
S0,
S1,
G0,
Goal).
133t_hlist(
T,
_,
_,
_,
Goal)
:-
134 '$do_error'(type_error(list,
T),
Goal).
143t_body(
Var, filled_in,
_,
S,
S1, phrase(
Var,
S,
S1))
:-
146t_body(!, to_fill, last,
S,
S1, (!,
S1 = S))
:- t_body.
147t_body(!,
_,
_,
S,
S, !)
:- t_body.
148t_body([], to_fill, last,
S,
S1,
S1=S)
:- t_body.
149t_body([],
_,
_,
S,
S, true)
:- t_body.
150t_body(
X,
FilledIn,
Last,
S,
SR,
OS)
:- string(
X),
string,
151 string_codes(
X,
Codes),
152 t_body(
Codes,
FilledIn,
Last,
S,
SR,
OS).
153t_body([
X], filled_in,
_,
S,
SR,
'C'(
S,
X,
SR))
:- t_body.
154t_body([
X|R], filled_in,
Last,
S,
SR, (
'C'(
S,
X,
SR1),
RB))
:- t_body,
155 t_body(
R, filled_in,
Last,
SR1,
SR,
RB).
156t_body({
T}, to_fill, last,
S,
S1, (
T,
S1=S))
:- t_body.
157t_body({
T},
_,
_,
S,
S,
T)
:- t_body.
158t_body((
T,
R),
ToFill,
Last,
S,
SR, (
Tt,
Rt))
:- t_body,
159 t_body(
T,
ToFill, not_last,
S,
SR1,
Tt),
160 t_body(
R,
ToFill,
Last,
SR1,
SR,
Rt).
161t_body((
T->R),
ToFill,
Last,
S,
SR, (
Tt->Rt))
:- t_body,
162 t_body(
T,
ToFill, not_last,
S,
SR1,
Tt),
163 t_body(
R,
ToFill,
Last,
SR1,
SR,
Rt).
164t_body(
\+T,
ToFill,
_,
S,
SR, (
Tt->fail
; S=SR))
:- t_body,
165 t_body(
T,
ToFill, not_last,
S,
_,
Tt).
166t_body((
T;R),
_ToFill,
_,
S,
SR, (
Tt;Rt))
:- t_body,
167 t_body(
T,
_, last,
S,
SR,
Tt),
168 t_body(
R,
_, last,
S,
SR,
Rt).
169t_body((
T|R),
_ToFill,
_,
S,
SR, (
Tt;Rt))
:- t_body,
170 t_body(
T,
_, last,
S,
SR,
Tt),
171 t_body(
R,
_, last,
S,
SR,
Rt).
172t_body(
M:G,
ToFill,
Last,
S,
SR,
M:NG)
:- t_body,
173 t_body(
G,
ToFill,
Last,
S,
SR,
NG).
174t_body(
T, filled_in,
_,
S,
SR,
Tt)
:-
175 dcg_extend([
S,
SR],
T,
Tt).
178dcg_extend(
More,
OldT,
NewT)
:-
180 dcg_extend
:append(
OldL,
More,
NewL),
183t_tidy(
P,
P)
:- var(
P),
var.
184t_tidy((
P1;P2), (
Q1;Q2))
:- t_tidy,
187t_tidy((
P1->P2), (
Q1->Q2))
:- t_tidy,
190t_tidy(((
P1,
P2),
P3),
Q)
:-
191 t_tidy((
P1,(
P2,
P3)),
Q).
192t_tidy((true,
P1),
Q1)
:- t_tidy,
194t_tidy((
P1,true),
Q1)
:- t_tidy,
196t_tidy((
P1,
P2), (
Q1,
Q2))
:- t_tidy,
207t_tidy
:'C'([
X|S],
X,
S).
218'C'
:phrase(
PhraseDef,
WordList)
:-
219 phrase
:phrase(
PhraseDef,
WordList, []).
230 '$do_error'(instantiation_error,phrase(
V,
S0,
S)).
231'$do_error'
:phrase([
H|T],
S0,
S)
:-
234 '$phrase_list'(
T,
S1,
S).
235'$phrase_list'
:phrase([],
S0,
S)
:-
241'$phrase_list'([],
S,
S).
242'$phrase_list'([
H|T], [
H|S1],
S0)
:-
243 '$phrase_list'(
T,
S1,
S0).
245'$phrase_list'
:!(
S,
S).
249:[](
H,
T,
S0,
S)
:- :append([
H|T],
S,
S0).
251append
:'.'(
H,
T,
S0,
S)
:-
254append
:{}(
Goal,
S0,
S)
:-
259 t_body((
A,
B),
_, last,
S0,
S,
Goal),
262'$execute'
:';'(
A,
B,
S0,
S)
:-
263 t_body((
A;B),
_, last,
S0,
S,
Goal),
266'$execute'
:(
'|'(
A,
B,
S0,
S))
:-
267 t_body((
A|B),
_, last,
S0,
S,
Goal),
270'$execute'
:'->'(
A,
B,
S0,
S)
:-
271 t_body((
A->B),
_, last,
S0,
S,
Goal),
274'$execute'
:'\\+'(
A,
S0,
S)
:-
275 t_body(
\+ A,
_, last,
S0,
S,
Goal),
278:-
'$new_multifile'( goal_expansion(
_,
_), prolog).
279:-
'$mk_dynamic'( prolog
:goal_expansion(
_,
_)).
281'$c_built_in_phrase'(
NT,
Xs0,
Xs,
Mod,
NewGoal)
:-
283 catch(prolog
:'$translate_rule'(
284 (pseudo_nt
--> Mod:NT),
Rule),
286 (
\+ '$harmless_dcgexception'(
Pat),
287 throw(error(
Pat,
ImplDep))
290 Rule = (
pseudo_nt(
Xs0c,
Xsc)
:- NewGoal0),
293 \+ '$contains_illegal_dcgnt'(
NT),
294 '$contains_illegal_dcgnt',
295 (
var(
Xsc),
Xsc \== Xs0c
296 -> Xs = Xsc,
NewGoal1 = NewGoal0
297 ; NewGoal1 = (
NewGoal0,
Xsc = Xs)
302 ; (
Xs0 = Xs0c,
NewGoal1 )
= NewGoal2
304 '$yap_strip_module'(
Mod:NewGoal2,
M,
NewGoal3),
305 (
nonvar(
NewGoal3)
-> NewGoal = M:NewGoal3
307 var(
M)
-> NewGoal = '$execute_wo_mod'(
NewGoal3,
M)
309 NewGoal = '$execute_in_mod'(
NewGoal3,
M)
312do_c_built_in(
'C'(
A,
B,
C),
_,
_, (
A=[
B|C]))
:- do_c_built_in.
314do_c_built_in(phrase(
NT,
Xs0,
Xs),
Mod,
_,
NewGoal)
:-
316 '$c_built_in_phrase'(
NT,
Xs0,
Xs,
Mod,
NewGoal).
318do_c_built_in(phrase(
NT,
Xs),
Mod,
_,
NewGoal)
:-
320 '$c_built_in_phrase'(
NT,
Xs, [],
Mod,
NewGoal).
326catch( : Goal,+ Exception,+ Action)
append(? List1,? List2,? List3)