head 1.18; access; symbols; locks ulrich:1.18; strict; comment @# @; 1.18 date 2024.02.14.10.05.57; author ulrich; state Exp; branches; next 1.17; 1.17 date 2015.04.08.13.32.07; author ulrich; state Exp; branches; next 1.16; 1.16 date 2014.07.28.12.54.43; author ulrich; state Exp; branches; next 1.15; 1.15 date 2014.07.20.09.53.54; author ulrich; state Exp; branches; next 1.14; 1.14 date 2014.07.19.13.18.30; author ulrich; state Exp; branches; next 1.13; 1.13 date 2014.07.19.10.29.56; author ulrich; state Exp; branches; next 1.12; 1.12 date 2014.07.19.10.28.17; author ulrich; state Exp; branches; next 1.11; 1.11 date 2013.09.06.21.47.52; author ulrich; state Exp; branches; next 1.10; 1.10 date 2013.09.06.21.47.05; author ulrich; state Exp; branches; next 1.9; 1.9 date 2013.08.29.09.51.49; author ulrich; state Exp; branches; next 1.8; 1.8 date 2013.08.28.19.18.25; author ulrich; state Exp; branches; next 1.7; 1.7 date 2013.08.28.19.08.12; author ulrich; state Exp; branches; next 1.6; 1.6 date 2012.08.14.10.25.47; author ulrich; state Exp; branches; next 1.5; 1.5 date 2012.08.14.10.16.50; author ulrich; state Exp; branches; next 1.4; 1.4 date 2011.11.26.10.39.52; author ulrich; state Exp; branches; next 1.3; 1.3 date 2011.11.17.21.54.08; author ulrich; state Exp; branches; next 1.2; 1.2 date 2011.11.17.21.53.31; author ulrich; state Exp; branches; next 1.1; 1.1 date 2011.07.13.17.32.19; author ulrich; state Exp; branches; next ; desc @@ 1.18 log @Final version (just comments and spaces modified) @ text @% dcg_rule/2 expands a DCG rule into a Prolog rule, when no error % condition is satisfied. :- op(1105,xfy,'|'). dcg_rule(( NonTerminal, Terminals --> GRBody ), ( Head :- Body )) :- dcg_non_terminal(NonTerminal, S0,S, Head), dcg_body(GRBody, S0,S1, Goal1), dcg_terminals(Terminals, S, S1, Goal2), Body = ( Goal1, Goal2 ). dcg_rule(( NonTerminal --> GRBody ), ( Head :- Body )) :- NonTerminal \= ( _, _ ), dcg_non_terminal(NonTerminal, S0,S, Head), dcg_body(GRBody, S0,S, Body). dcg_non_terminal(NonTerminal, S0,S, Goal) :- NonTerminal =.. NonTerminalU, append(NonTerminalU,[S0,S], GoalU), % as defined in the Prolog prologue Goal =.. GoalU. dcg_terminals(Terminals, S0,S, S0 = List) :- append(Terminals, S, List). dcg_body(Var, S0,S, Body) :- var(Var), Body = phrase(Var, S0,S). dcg_body(GRBody, S0,S, Body) :- nonvar(GRBody), dcg_constr(GRBody), dcg_cbody(GRBody, S0,S, Body). dcg_body(NonTerminal, S0,S, Goal) :- nonvar(NonTerminal), \+ dcg_constr(NonTerminal), NonTerminal \= ( _ -> _ ), NonTerminal \= ( \+ _ ), dcg_non_terminal(NonTerminal, S0,S, Goal). dcg_constr([]). % 7.14.1 dcg_constr([_|_]). % 7.14.2 - terminal sequence dcg_constr(( _, _ )). % 7.14.3 - concatenation dcg_constr(( _ ; _ )). % 7.14.4 - alternative % 7.14.5 - if-then-else dcg_constr(( _'|'_ )). % 7.14.6 - alternative dcg_constr({_}). % 7.14.7 dcg_constr(call(_)). % 7.14.8 dcg_constr(phrase(_)). % 7.14.9 dcg_constr(!). % 7.14.10 % dcg_constr(\+ _). % 7.14.11 - not (existence impl. defined) % dcg_constr((_->_)). % 7.14.12 - if-then (existence impl. defined) dcg_cbody([], S0,S, S0 = S ). dcg_cbody([T|Ts], S0,S, Goal) :- dcg_terminals([T|Ts], S0,S, Goal). dcg_cbody(( GRFirst, GRSecond ), S0,S, ( First, Second )) :- dcg_body(GRFirst, S0,S1, First), dcg_body(GRSecond, S1,S, Second). dcg_cbody(( GREither ; GROr ), S0,S, ( Either ; Or )) :- \+ subsumes_term(( _ -> _ ),GREither), dcg_body(GREither, S0,S, Either), dcg_body(GROr, S0,S, Or). dcg_cbody(( GRCond ; GRElse ), S0,S, ( Cond ; Else )) :- subsumes_term(( _GRIf -> _GRThen ), GRCond), dcg_cbody(GRCond, S0,S, Cond), dcg_body(GRElse, S0,S, Else). dcg_cbody(( GREither '|' GROr ), S0,S, ( Either ; Or )) :- dcg_body(GREither, S0,S, Either), dcg_body(GROr, S0,S, Or). dcg_cbody({Goal}, S0,S, ( Goal, S0 = S )). dcg_cbody(call(Cont), S0,S, call(Cont, S0,S)). dcg_cbody(phrase(Body), S0,S, phrase(Body, S0,S)). dcg_cbody(!, S0,S, ( !, S0 = S )). dcg_cbody(\+ GRBody, S0,S, ( \+ phrase(GRBody,S0,_), S0 = S )). dcg_cbody(( GRIf -> GRThen ), S0,S, ( If -> Then )) :- dcg_body(GRIf, S0,S1, If), dcg_body(GRThen, S1,S, Then). @ 1.17 log @WG17 change - during meeting @ text @d1 3 a5 4 % This program uses append/3 as defined in the Prolog prologue. % Expands a DCG rule into a Prolog rule, when no error condition applies. d7 2 a8 2 dcg_non_terminal(NonTerminal, S0, S, Head), dcg_body(GRBody, S0, S1, Goal1), d13 2 a14 2 dcg_non_terminal(NonTerminal, S0, S, Head), dcg_body(GRBody, S0, S, Body). d16 4 a19 4 dcg_non_terminal(NonTerminal, S0, S, Goal) :- NonTerminal =.. NonTerminalUniv, append(NonTerminalUniv, [S0, S], GoalUniv), Goal =.. GoalUniv. d21 1 a21 1 dcg_terminals(Terminals, S0, S, S0 = List) :- d24 1 a24 1 dcg_body(Var, S0, S, Body) :- d26 2 a27 2 Body = phrase(Var, S0, S). dcg_body(GRBody, S0, S, Body) :- d30 2 a31 2 dcg_cbody(GRBody, S0, S, Body). dcg_body(NonTerminal, S0, S, Goal) :- d36 1 a36 4 dcg_non_terminal(NonTerminal, S0, S, Goal). % The following constructs in a grammar rule body % are defined in the corresponding subclauses. d48 2 a49 5 % dcg_constr(\+ _). % 7.14.11 - not (existence implementation dep.) % dcg_constr((_->_)). % 7.14.12 - if-then (existence implementation dep.) % The principal functor of the first argument indicates % the construct to be expanded. d51 7 a57 7 dcg_cbody([], S0, S, S0 = S ). dcg_cbody([T|Ts], S0, S, Goal) :- dcg_terminals([T|Ts], S0, S, Goal). dcg_cbody(( GRFirst, GRSecond ), S0, S, ( First, Second )) :- dcg_body(GRFirst, S0, S1, First), dcg_body(GRSecond, S1, S, Second). dcg_cbody(( GREither ; GROr ), S0, S, ( Either ; Or )) :- d59 3 a61 3 dcg_body(GREither, S0, S, Either), dcg_body(GROr, S0, S, Or). dcg_cbody(( GRCond ; GRElse ), S0, S, ( Cond ; Else )) :- d63 13 a75 13 dcg_cbody(GRCond, S0, S, Cond), dcg_body(GRElse, S0, S, Else). dcg_cbody(( GREither '|' GROr ), S0, S, ( Either ; Or )) :- dcg_body(GREither, S0, S, Either), dcg_body(GROr, S0, S, Or). dcg_cbody({Goal}, S0, S, ( Goal, S0 = S )). dcg_cbody(call(Cont), S0, S, call(Cont, S0, S)). dcg_cbody(phrase(Body), S0, S, phrase(Body, S0, S)). dcg_cbody(!, S0, S, ( !, S0 = S )). dcg_cbody(\+ GRBody, S0, S, ( \+ phrase(GRBody,S0,_), S0 = S )). dcg_cbody(( GRIf -> GRThen ), S0, S, ( If -> Then )) :- dcg_body(GRIf, S0, S1, If), dcg_body(GRThen, S1, S, Then). @ 1.16 log @Post-meeting correction. @ text @d36 1 d42 12 a53 12 dcg_constr([]). % 7.14.1 dcg_constr([_|_]). % 7.14.2 - terminal sequence dcg_constr(( _, _ )). % 7.14.3 - concatenation dcg_constr(( _ ; _ )). % 7.14.4 - alternative % 7.14.5 - if-then-else dcg_constr(( _ '|' _ )). % 7.14.6 - alternative dcg_constr({_}). % 7.14.7 dcg_constr(call(_)). % 7.14.8 dcg_constr(phrase(_)). % 7.14.9 dcg_constr(!). % 7.14.10 % dcg_constr(\+ _). % 7.14.11 - not (implementation dependent) % dcg_constr((_ -> _)). % 7.14.12 - if-then (implementation dependent) d78 1 a79 1 dcg_cbody(!, S0, S, ( !, S0 = S )). @ 1.15 log @Made variables for if-then-else more explicit. Now mentions the otherwise implementation dependent (->)//2 @ text @d51 2 a52 2 dcg_constr(\+ _). % 7.14.11 % dcg_constr((_ -> _)). % 7.14.12 - if-then (imlementation dependent) d63 4 d68 2 a69 2 \+ subsumes_term(( _GRIf -> _GRThen ), GRCond), dcg_body(GRCond, S0, S, Cond), a70 4 dcg_cbody(( GREither ; GROr ), S0, S, ( Either ; Or )) :- subsumes_term(( _ -> _ ),GREither), dcg_cbody(GREither, S0, S, Either), dcg_body(GROr, S0, S, Or). @ 1.14 log @Numbering back @ text @d52 1 d63 4 a66 4 dcg_cbody(( GREither ; GROr ), S0, S, ( Either ; Or )) :- \+ subsumes_term(( _ -> _ ),GREither), dcg_body(GREither, S0, S, Either), dcg_body(GROr, S0, S, Or). @ 1.13 log @Changed expansion of (\+)//1 @ text @d41 11 a51 11 dcg_constr([]). % 7.15.1 dcg_constr([_|_]). % 7.15.2 - terminal sequence dcg_constr(( _, _ )). % 7.15.3 - concatenation dcg_constr(( _ ; _ )). % 7.15.4 - alternative % 7.15.5 - if-then-else dcg_constr(( _ '|' _ )). % 7.15.6 - alternative dcg_constr({_}). % 7.15.7 dcg_constr(call(_)). % 7.15.8 dcg_constr(phrase(_)). % 7.15.9 dcg_constr(!). % 7.15.10 dcg_constr(\+ _). % 7.15.11 @ 1.12 log @WG17: remove iso_phrase/3 @ text @d41 11 a51 11 dcg_constr([]). % 7.14.1 dcg_constr([_|_]). % 7.14.2 - terminal sequence dcg_constr(( _, _ )). % 7.14.3 - concatenation dcg_constr(( _ ; _ )). % 7.14.4 - alternative % 7.14.5 - if-then-else dcg_constr(( _ '|' _ )). % 7.14.6 - alternative dcg_constr({_}). % 7.14.7 dcg_constr(call(_)). % 7.14.8 dcg_constr(phrase(_)). % 7.14.9 dcg_constr(!). % 7.14.10 dcg_constr(\+ _). % 7.14.11 d76 1 a76 2 dcg_cbody(\+ GRBody, S0, S, ( \+ Goal, S0 = S )) :- dcg_body(GRBody, S0, _, Goal). @ 1.11 log @wording @ text @a4 4 iso_phrase(GRBody, S0, S) :- dcg_body(GRBody, S0, S, Goal), call(Goal). @ 1.10 log @dcg_rule/4 -> dcg_rule/2 many comments removed spacings added @ text @d58 1 a58 1 % the construct to be translated. @ 1.9 log @Added phrase//1 translation @ text @d9 1 a9 2 % dcg_rule(DCGrule, S0, S, Expansion). % Translates a DCG rule into a Prolog rule, when no error condition applies. d11 1 a11 1 dcg_rule((NonTerminal, Terminals --> GRBody), S0, S, (Head :- Body)) :- d15 3 a17 3 Body = (Goal1, Goal2). dcg_rule((NonTerminal --> GRBody), S0, S, (Head :- Body)) :- NonTerminal \= (_,_), a20 2 % translates a grammar goal non-terminal: a25 2 % translates a terminal-sequence: a28 2 % translates a grammar rule body: d39 1 a39 1 NonTerminal \= (_->_), d45 11 a55 11 dcg_constr([]). % 7.14.1 dcg_constr([_|_]). % 7.14.2 - terminal sequence dcg_constr((_,_)). % 7.14.3 - concatenation dcg_constr((_;_)). % 7.14.4 - alternative % 7.14.5 - if-then-else dcg_constr((_'|'_)). % 7.14.6 - alternative dcg_constr({_}). % 7.14.7 dcg_constr(call(_)). % 7.14.8 dcg_constr(phrase(_)). % 7.14.9 dcg_constr(!). % 7.14.10 dcg_constr(\+_). % 7.14.11 d60 1 a60 1 dcg_cbody([], S0, S, (S0=S)). d67 1 a67 1 \+ subsumes_term((_->_),GREither), d71 1 a71 1 subsumes_term((_->_),GREither), d77 1 a77 1 dcg_cbody({Goal}, S0, S, (Goal, S0 = S)). d80 1 a80 1 dcg_cbody(\+ GRBody, S0, S, (\+ Goal, S0 = S)) :- d82 1 a82 1 dcg_cbody(!, S0, S, (!, S0 = S)). a85 2 @ 1.8 log @First dist @ text @d86 1 @ 1.7 log @First preliminary version to reflect Istanbul resolutions @ text @a2 1 a7 1 @ 1.6 log @Jan Burse: JB5: Either mention requirement of Prologue for Prolog or give definition of append/3, to make it selfcontained. @ text @a18 1 d51 14 a64 9 dcg_constr([]). dcg_constr([_|_]). dcg_constr((_,_)). dcg_constr((_;_)). dcg_constr((_'|'_)). dcg_constr(call(_)). dcg_constr({_}). dcg_constr(\+_). dcg_constr(!). d66 2 d76 4 a82 4 dcg_cbody(( GREither ; GROr ), S0, S, ( Either ; Or )) :- \+ subsumes_term((_->_),GREither), dcg_body(GREither, S0, S, Either), dcg_body(GROr, S0, S, Or). d86 1 a87 1 dcg_cbody({Goal}, S0, S, (Goal, S0 = S)). @ 1.5 log @Jan Burse: JB4: op/3 definition for '|' should be seen, to make it selfcontained. @ text @d3 3 @ 1.4 log @Added quotes for SICStus @ text @d1 2 @ 1.3 log @(New) added quotes to make Spec readable by SICStus too @ text @d51 1 a51 1 dcg_constr((_|_)). @ 1.2 log @*** empty log message *** @ text @d72 1 a72 1 dcg_cbody(( GREither | GROr ), S0, S, ( Either ; Or )) :- @ 1.1 log @Initial revision @ text @a9 1 !, d16 1 a35 1 !, d38 1 a39 1 !, d42 1 d44 1 d65 5 @