48c48,49 < This TR is an extension to the ISO/IEC 13211--1 Prolog standard, adopting a similar structure. In particular, this TR adds new subclauses to, or modifies existing subclauses of ISO/IEC 13211--1. --- > This TR is an extension to the ISO/IEC 13211--1 Prolog standard, adopting a similar structure. In particular, this TR adds new sections and subsections to, or modifies existing sections of ISO/IEC 13211--1. > 107d107 < \item A Reference implementation. 115c115 < NOTE --- The limitations, expressed in clause 1, Scope, of ISO/IEC 13211--1:1995 apply to this TR. --- > NOTE --- The limitations, expressed in section 1, Scope, of ISO/IEC 13211--1:1995 apply to this TR. 134c134 < \textsl{For the purposes of this TR, the following Definitions are added to the ones specified in ISO/IEC 13211--1:} --- > \textsl{For the purposes of this TR, the following definitions are added to the ones specified in ISO/IEC 13211--1:} 138,139d137 < \paragraph{alternative:} A compound term with principal functor \code{(;)/2} or with principal functor \code{('|')} with each argument being a body (of a grammar-rule). < 142c140 < \paragraph{clause-term:} A read-term \code{T.} in Prolog text where \code{T} does not have principal functor \code{(:-)/1} nor principal functor \code{(-->)/2.} (This definition replaces subclause 3.33 of ISO/IEC 13211--1). --- > \paragraph{clause-term:} A read-term \code{T.} in Prolog text where \code{T} does not have principal functor \code{(:-)/1} nor principal functor \code{(-->)/2.} (This definition replaces section 3.33 of ISO/IEC 13211--1). 146,149c144,145 < \paragraph{cover,a terminal-sequence by a non-terminal (resp. a body) :} A < terminal sequence is covered by a non-terminal (resp. a body) if the non-terminal < (resp. the body) generates the terminal sequence. Alternatively if the non-terminal (resp. body) < parses the terminal sequence. --- > \paragraph{cover, a terminal-sequence by a non-terminal resp. a body:} A terminal sequence is covered by a non-terminal resp. a body if the non-terminal resp. the body generates the terminal sequence, > respectively parses the terminal sequence. 153c149 < \paragraph{expansion (of a grammar-rule):} The preparation for execution (cf. ISO/IEC 13211--1, subclause 7.5.1) of a grammar rule. --- > \paragraph{expansion (of a grammar-rule):} The preparation for execution (cf. ISO/IEC 13211--1, section 7.5.1) of a grammar rule. 157c153,155 < \paragraph{generating (wrt. a definite clause grammar):} Producing terminal-sequences of that definite clause grammar, obeying semicontexts, if any. --- > \paragraph{generating (wrt. a definite clause grammar):} Producing terminal-sequences of that definite clause grammar, obeying right-hand-contexts, if any. > > \paragraph{grammar-body-alternative:} A compound term with principal functor \code{(;)/2} or with principal functor \code{('|')} with each argument being a body (of a grammar-rule). 161c159,161 < \paragraph{grammar-body-element:} A grammar-body-cut (the atom \code{!}), or a grammar-goal, or a non-terminal, or a terminal-sequence. --- > \paragraph{grammar-body-element:} A grammar-body-cut (the atom \code{!}), or a grammar-body-goal, or a non-terminal, or a terminal-sequence. > > \paragraph{grammar-body-goal:} A compound term with principal functor \code{\{\}/1} whose argument is a goal. 167c167 < \paragraph{grammar-goal:} A compound term with principal functor \code{\{\}/1} whose argument is a goal. --- > \paragraph{grammar-body-terminals:} A terminal-sequence. 171c171 < \paragraph{grammar-rule-body:} The second argument of a grammar-rule. A grammar-body-sequence, or an alternative, or a grammar-body-not, or a grammar-body-element. --- > \paragraph{grammar-rule-body:} The second argument of a grammar-rule. A grammar-body-sequence, or a grammar-body-alternative, or a grammar-body-not, or a grammar-body-element. 173,174c173,175 < % the next definition is changed JPEH. < \paragraph{grammar-rule-head:}\label{defGrammarRuleHead} The first argument of a grammar-rule. --- > \paragraph{grammar-rule-term:} A read-term \code{T.} where \code{T} is a grammar-rule. > > \paragraph{head (of a grammar-rule):}\label{defGrammarRuleHead} The first argument of a grammar-rule. 177c178 < second argument is a semicontext (cf Definition \ref{defSemiContext}). --- > second argument is a right hand context (cf definition \ref{defRightHandContext}). 183c184 < \paragraph{non-terminal indicator:}\label{defNonTerminalInd} A compound term \code{A//N} where \code{A} is an atom and \code{N} is a non-negative integer, denoting one particular non-terminal (cf \ref{ssection:nonterminalIndicator}). --- > \paragraph{non-terminal indicator:} A compound term \code{A//N} where \code{A} is an atom and \code{N} is a non-negative integer, denoting one particular non-terminal (cf \ref{ssection:nonterminalIndicator}). 185c186 < \paragraph{parsing (wrt. a definite clause grammar):} Successively accepting or consuming terminal-sequences, assigning them to corresponding non-terminals and obeying semicontexts, if any. --- > \paragraph{parsing (wrt. a definite clause grammar):} Successively accepting or consuming terminal-sequences, assigning them to corresponding non-terminals and obeying right-hand-contexts, if any. 189c190 < \paragraph{semicontext:}\label{defSemiContext} A terminal-sequence occurring as optional second argument of a grammar-rule-head, constraining parsing (respectively generation) by this grammar rule. --- > \paragraph{right-hand-context:}\label{defRightHandContext} A terminal-sequence occurring as optional second argument of a grammar-rule-head, constraining parsing, respectively generation, by this grammar rule. 196c197,199 < \paragraph{terminal-sequence:}\label{defTerminalSequence} A list (cf. ISO/IEC 13211--1, subclauses 3.99, 6.3.5 and 6.3.1.3) whose first argument, if any, is a terminal (of a grammar), and the second argument, if any, is a terminal-sequence. --- > \paragraph{terminal-sequence:}\label{defTerminalSequence} A list (cf. ISO/IEC 13211--1, sections 3.99, 6.3.5 and 6.3.1.3) whose first argument, if any, is a terminal (of a grammar), and the second argument, if any, is a terminal-sequence. > > \paragraph{terminal-sequence, comprehensive:} Terminal sequence containing a (possibly empty) prefix covered (cf. Definition 3.4) by a grammar-rule-body, i.e. accepted resp. generated by \code{phrase/3} (cf \ref{sssection:phraseSpecification}) . 198c201 < \paragraph{terminal-sequence, comprehensive:} Terminal sequence containing a (possibly empty) prefix covered (cf. Definition 3.5) by a grammar-rule-body, i.e. accepted resp. generated by \code{phrase/3} (cf \ref{sssection:phraseSpecification}) . --- > % Klaus: I think it's better to mention phrase/3, because the definition was un-understandable else. Removed the i.e. clause in the next defi. 200c203 < \paragraph{terminal-sequence, remaining:} Rest of comprehensive terminal-sequence without the leading terminal-sequence covered (cf. Definition 3.5) by a grammar-rule-body. --- > \paragraph{terminal-sequence, remaining:} Rest of comprehensive terminal-sequence without the leading terminal-sequence covered (cf. Definition 3.4) by a grammar-rule-body. 204d206 < \newpage 244c246 < NOTE --- This extends the corresponding subclause of ISO/IEC 13211--1. --- > NOTE --- This extends corresponding section of ISO/IEC 13211--1. 260c262 < \textsl{The corresponding subclause in the ISO/IEC 13211--1 Prolog standard is modified as follows:}\\ --- > \textsl{The corresponding section in the ISO/IEC 13211--1 Prolog standard is modified as follows:}\\ 268c270 < \textsl{The corresponding subclause in the ISO/IEC 13211--1 Prolog standard is modified as follows:}\\ --- > \textsl{The corresponding section in the ISO/IEC 13211--1 Prolog standard is modified as follows:}\\ 284c286 < \textsl{Please see subclause \ref{ssection:grammarRuleOperator} for the new predefined operators that this TR adds to the ISO/IEC 13211--1 Prolog standard.} --- > \textsl{Please see subsection \ref{ssection:grammarRuleOperator} for the new predefined operators that this TR adds to the ISO/IEC 13211--1 Prolog standard.} 301c303 < \textsl{The text near the end of this subclause in the ISO/IEC 13211--1 Prolog standard is modified as follows:}\\ --- > \textsl{The text near the end of this section in the ISO/IEC 13211--1 Prolog standard is modified as follows:}\\ 317c319 < \textsl{The following subclause extends, with the specified number, the corresponding ISO/IEC 13211--1 subclause.} --- > \textsl{The following subsection extends, with the specified number, the corresponding ISO/IEC 13211--1 section.} 329c331 < \textsl{The first paragraph of this subclause on ISO/IEC 13211--1 is modified as follows:}\\ --- > \textsl{The first paragraph of this section on ISO/IEC 13211--1 is modified as follows:}\\ 337c339 < \textsl{The corresponding subclause in the ISO/IEC 13211--1 is modified as follows:}\\ --- > \textsl{The corresponding section in the ISO/IEC 13211--1 is modified as follows:}\\ 376c378 < \textsl{The corresponding subclause in the ISO/IEC 13211--1 is modified as follows:}\\ --- > \textsl{The corresponding section in the ISO/IEC 13211--1 is modified as follows:}\\ 388c390 < NOTE --- Subclauses 7.5 and 7.6 define how clauses become part of the database.\\ --- > NOTE --- Subsections 7.5 and 7.6 define how clauses become part of the database.\\ 391c393 < \textsl{The following subclause modifies, with the specified number, the corresponding ISO/IEC 13211--1 subclause:} --- > \textsl{The following subsection modifies, with the specified number, the corresponding ISO/IEC 13211--1 section:} 409c411 < NOTE --- Subclause \ref{section:logicalExpansion} of this TR defines how a grammar rule in Prolog text is expanded into an equivalent clause when Prolog text is prepared for execution. --- > NOTE --- Section \ref{section:logicalExpansion} of this TR defines how a grammar rule in Prolog text is expanded into an equivalent clause when Prolog text is prepared for execution. 412c414 < \paragraph{Semicontexts} ~\\ --- > \paragraph{Right-hand contexts} ~\\ 415c417 < ~ & \code{semicontext term =} & \code{term}\\ --- > ~ & \code{right hand context term =} & \code{term}\\ 418c420 < Condition: & semicontext term is a list\\ --- > Condition: & Rright hand context term is a list\\ 420c422 < ~ & \code{semicontext =} & \code{semicontext term}\\ --- > ~ & \code{right hand context =} & \code{right hand context term}\\ 426,428c428,430 < NOTE --- Subclause \ref{section:logicalExpansion} of this TR, \code{dcg\_rule/4}, first clause, defines how a semicontext in a grammar rule is expanded when Prolog text is prepared for execution. < % Modified JPEH. < % Accepted and corrected KD --- > NOTE --- Section \ref{section:logicalExpansion} of this TR, rule \%02\% and rule \%04\%, defines how a right hand context in a grammar rule is expanded when Prolog text is prepared for execution. > > 434c436 < Extend the operator table of subclause 6.3.4.4 of ISO/IEC 13211--1 as follows: \\ --- > Extend the operator table of section 6.3.4.4 of ISO/IEC 13211--1 as follows: \\ 447c449 < NOTE --- The operator \code{(-->)/2}, specified in subclause 6.3.4.4 of the ISO/IEC 13211--1 Prolog standard, is used as the principal functor of grammar rules. --- > NOTE --- The operator \code{(-->)/2}, specified in section 6.3.4.4 of the ISO/IEC 13211--1 Prolog standard, is used as the principal functor of grammar rules. 454c456 < \textsl{The following subclause extends, with the specified number, the corresponding ISO/IEC 13211--1 subclause:} --- > \textsl{The following subsection extends, with the specified number, the corresponding ISO/IEC 13211--1 section:} 467c469 < subclause 7.4.2 of the ISO/IEC 13211--1 Prolog standard. --- > section 7.4.2 of the ISO/IEC 13211--1 Prolog standard. 473c475 < of subclause 6.24 of ISO/IEC 13211-2:2000. --- > of section 6.24 of ISO/IEC 13211-2:2000. 481c483 < \textsl{The following subclause extends subclauses 6.8 and 7.2.2 of ISO/IEC 13211--2 Prolog Modules:} --- > \textsl{The following subsection extends sections 6.8 and 7.2.2 of ISO/IEC 13211--2 Prolog Modules:} 485c487 < The following property is added to the list of predicate properties of subclause 6.8 --- > The following property is added to the list of predicate properties of section 6.8 489c491 < \item \code{expanded\_from(A//N)} --- The predicate resp. callable with predicate indicator \code{A/(N+2)} results from the expansion of a grammar rule with non-terminal indicator \code{A//N}, (cf. Definition 3.18 and subclause \ref{ssection:nonterminalIndicator}). --- > \item \code{expanded\_from(A//N)} --- The predicate resp. callable with predicate indicator \code{A/(N+2)} results from the expansion of a grammar rule with non-terminal indicator \code{A//N} 492,493d493 < \medskip < 495c495 < NOTE --- a predicate property is the second argument of the built-in predicate \code{predicate\_property(Callable, Property)}, cf. subclause 6.8 of ISO/IEC 13211--2.\\ --- > NOTE --- a predicate property is the second argument of the built-in predicate \code{predicate\_property(Callable, Property)}, cf. section 6.8 of ISO/IEC 13211--2.\\ 503a504 > 514c515 < NOTE --- In the context of a grammar rule, \textsl{terminals} represent tokens of some language, and \textsl{non-terminals} represent sequences of tokens (see, respectively, Definitions 3.23 and 3.17). --- > NOTE --- In the context of a grammar rule, \textsl{terminals} represent tokens of some language, and \textsl{non-terminals} represent sequences of tokens (see, respectively, definitions 3.19 and 3.25). 518c519 < flag "double\_quotes" has value "chars"; see subclauses 6.3.7 and 6.4.6 of ISO/IEC 13211--1. --- > flag "double\_quotes" has value "chars"; see sections 6.3.7 and 6.4.6 of ISO/IEC 13211--1. 576c577 < where \code{GRHead}, the head(of a grammar rule) (cf. Definition 3.15), can be rewritten by \code{GRBody}, its body(of a grammar rule) (cf. Definition 3.14). The head and the body of grammar rules are constructed from \textsl{non-terminals}, \textsl{terminals} and \textsl{control constructs}. The head(of a grammar rule) is a non-terminal or the conjunction of a non-terminal and, following, a terminal-sequence (a \textsl{semicontext}, see \ref{sssection:rightHandcontext}): --- > where \code{GRHead}, the head(of a grammar rule) (cf. Definition 3.16), can be rewritten by \code{GRBody}, its body(of a grammar rule) (cf. Definition 3.1). The head and the body of grammar rules are constructed from \textsl{non-terminals}, \textsl{terminals} and \textsl{control constructs}. The head(of a grammar rule) is a non-terminal or the conjunction of a non-terminal and, following, a terminal-sequence (a \textsl{right-hand-context}, see \ref{sssection:rightHandcontext}): 581c582 < NonTerminal, SemiContext --> GRBody. \end{verbatim} --- > NonTerminal, RightHandContext --> GRBody. \end{verbatim} 586c587 < The control constructs that may be used in a body are described in subclause \ref{ssection:controlConstructs}. An empty body is represented by an empty terminal sequence: --- > The control constructs that may be used in a body are described in subsection \ref{ssection:controlConstructs}. An empty body is represented by an empty terminal sequence: 595c596 < \subsubsection{Semicontexts} --- > \subsubsection{Right-hand-contexts} 605c606 < A \textsl{semicontext} is a terminal-sequence (see \ref{defTerminalSequence}), as an optional second argument of the head of a grammar rule (see \ref{defGrammarRuleHead}). A semicontext contains terminals that are prefixed to the remaining terminal-sequence after successful application of the grammar rule. --- > A \textsl{right-hand-context} is a terminal-sequence (see \ref{defTerminalSequence}), as an optional second argument of the head of a grammar rule (see \ref{defGrammarRuleHead}). A right-hand-context contains terminals that are prefixed to the remaining terminal-sequence after successful application of the grammar rule. 633c634 < Another example may be a small grammar rule with semicontext: --- > Another example may be a small grammar rule with right-hand-context: 665,666c666,667 < 1\hspace{1.5em} In case of parsing, as soon as \code{phrase2} and \code{phrase3} have successfully parsed the comprehensive terminal-sequence (input list), the terminal \code{word} is prefixed to the remaining terminal-sequence. \code{word} is then the first terminal to be consumed in further parsing after \code{phrase1}. Thus further parsing is constrained by the semicontext.\\ < % process from path JPEH March 28th Simplified second sentence. JPEH --- > 1\hspace{1.5em} In case of parsing, as soon as \code{phrase2} and \code{phrase3} have successfully parsed the comprehensive terminal-sequence (input list), the terminal \code{word} is prefixed to the remaining terminal-sequence. \code{word} is then the first terminal to be consumed in further parsing after \code{phrase1}. Thus the path of further parsing is constrained by the right-hand-context.\\ > % process from path JPEH 670,676c671,673 < 2\hspace{1.5em} The concepts \textsl{comprehensive terminal-sequence} resp. \textsl{remaining terminal-sequence} are often called \textsl{input list} resp. \textsl{output list}. This is misleading, because it only considers the case of parsing using a grammar. There a terminal list shall be parsed wrt. non-terminals, and there will be a remainder after the parsing step. The inverse case, generating sentences by expanding grammars, where the comprehensive terminal-sequence is the real output list, is ignored by such wording.\\ < % Above par modified JPEH also March 2014 < % KD In former versions of the Draft (by Paulo) only the concepts of input list and output list were used. < % The meaning was that during parsing a nonterminal consumes some terminals from the (larger) input list, < % and there remains a (smaller) output list, subject to following parsing. But for generating it is the opposite, < % there the output is larger (i.e. contains more terminals) than the input list. The wording input list and < % output list is very colloquial, therefore shall be a clarification here. --- > 2\hspace{1.5em} The concepts \textsl{comprehensive terminal-sequence} resp. \textsl{remaining terminal-sequence} are often named \textsl{input list} resp. \textsl{output list}. This is misleading, because it only considers the case of parsing using a grammar. There a terminal list shall be parsed wrt. non-terminals, and there will be a remainder after the parsing step. The inverse case, generating sentences by expanding grammars, where the comprehensive terminal-sequence is the real output list, is ignored by such wording.\\ > % Above par modified JPEH > % KD OK 712c709 < 4\hspace{1.5em} It should be noted that \code{phrase/2} (cf \ref{sssection:bootstrappedPredicates}) cannot succeed when applied to a grammar rule, whose head contains a non empty semicontext, as in the case above.\\ --- > 4\hspace{1.5em} It should be noted that \code{phrase/2} (cf \ref{sssection:bootstrappedPredicates}) cannot succeed when applied to a grammar rule, whose head contains a non empty right-hand context, as in the case above.\\ 717c714 < 5 \hspace{1.5em} Some processors allow a cut in the semicontext; e.g.\\ --- > 5 \hspace{1.5em} Some processors allow a cut in the right-hand context; e.g.\\ 722c719 < Thus this TR does not permit a cut in the semicontext. --- > Thus this TR does not permit a cut in the right hand context. 744c741 < 2\hspace{1.5em}The concept of non-terminal indicator is similar to the concept of \textsl{predicate indicator} defined in subclauses 3.131 and 7.1.6.6 of the ISO/IEC 13211--1 Prolog. Non-terminal indicators may be used in exception terms thrown when processing or using grammar rules. In addition, non-terminal indicators may appear at some places, where a predicate indicator as defined in ISO/IEC 13211--1 can appear. See \ref{sssection:prologDirectives}. Furthermore non-terminal indicators may be used in a predicate property (cf. subsection \ref{ssection:predicateProperties}). In particular, using non-terminal indicators in predicate directives allows the details of the expansion of grammar rules into Prolog clauses to be abstracted. --- > 2\hspace{1.5em}The concept of non-terminal indicator is similar to the concept of \textsl{predicate indicator} defined in sections 3.131 and 7.1.6.6 of the ISO/IEC 13211--1 Prolog. Non-terminal indicators may be used in exception terms thrown when processing or using grammar rules. In addition, non-terminal indicators may appear at some places, where a predicate indicator as defined in ISO/IEC 13211--1 can appear. See \ref{sssection:prologDirectives}. Furthermore non-terminal indicators may be used in a predicate property (cf. subsection \ref{ssection:predicateProperties}). In particular, using non-terminal indicators in predicate directives allows the details of the expansion of grammar rules into Prolog clauses to be abstracted. 778,779d774 < \begin{comment} < % was decided on Istanbul conference. Contents should occur in 7.15.7 793,794c788,789 < \code{\{\}/1} is a functor of a \code{grammar-goal} \{prolog\_goal\} (cf. Definition 3.12). After expansion < \code{prolog\_goal} is unchanged and is handled as a ordinary prolog goal according to subclause 7.7 of ISO/IEC 13211-1 Prolog.\\ --- > \code{\{\}/1} is a functor of a \code{grammar-body-goal} \{prolog\_goal\} (cf. Definition 3.10). After expansion > \code{prolog\_goal} is unchanged and is handled as a ordinary prolog goal according to section 7.7 of ISO/IEC 13211-1 Prolog.\\ 798c793 < NOTE --- The ISO/IEC 13211--1 Prolog standard defines, in subclause 6.3.6, a \textsl{curly bracketed term} as a compound term with principal functor \code{'\{\}'/1}, whose argument may also be expressed by enclosing its argument in curly brackets. --- > NOTE --- The ISO/IEC 13211--1 Prolog standard defines, in section 6.3.6, a \textsl{curly bracketed term} as a compound term with principal functor \code{'\{\}'/1}, whose argument may also be expressed by enclosing its argument in curly brackets. 817d811 < \end{comment} 824,825d817 < < 827c819 < This subclause describes the meaning of special non-terminals which are part of grammar rules: \\ --- > This subsection describes the meaning of special non-terminals which are part of grammar rules: \\ 829,830c821 < < \medskip\noindent --- > \noindent 836d826 < \code{\{\}//1}\\ 838c828 < \code{phrase//1} \\ --- > \code{\{\}//1}\\ 840,841c830,832 < \code{!//0}, and\\ < \code{(->)//2} in an \code{if-then-else}.\\ --- > \code{!//0}\\ > \code{(->)//2} in an \code{if-then-else}, and\\ > \code{phrase//1}. \\ 843,844c834,835 < % moved to here. JPEH < % agreed. KD --- > \medskip > \medskip 846,849c837,838 < Expansion of grammar control constructs is not simply a replacement by Prolog control constructs. < For every grammar control construct there is a formal definition in the formal definition of \code{phrase/3} in subclause \ref{section:logicalExpansion}. < The correspondence between the following subclauses and the corresponding formal definitions is given by the < principal functor of the first argument of the clauses of predicate \code{dcg\_cbody/4} in subclause \ref{section:logicalExpansion}.\\ --- > After preparation for execution of Grammar Rules, named ``Grammar Rule expansion'' or ``expansion'' for short, these non-terminals, with exception of phrase//1, result in control constructs, respectively built-in predicates of ISO/IEC 13211-1 Prolog. \\ > Expansion of grammar control constructs is not simply a replacement by Prolog control constructs. \\ 853,855c842,843 < After preparation for execution of Grammar Rules, named ``Grammar Rule expansion'' or ``expansion'' for short, these non-terminals, with exception of phrase//1, result in control constructs, respectively built-in predicates of ISO/IEC 13211-1 Prolog. \\ < Grammar Rule expansion is defined by describing it wrt. the built-in predicate \code{phrase/3} < (see subclauses \ref{sssection:phraseSpecification} and \ref{section:logicalExpansion}).\\ --- > Logical expansion is defined by describing it wrt. the built-in predicate \code{phrase/3} > (see \ref{section:logicalExpansion} and \ref{sssection:phraseSpecification}) 856a845,847 > Execution of this predicate serves two goals: Firstly the final expansion(of a grammar rule) (cf. definition 3.6), > when this has not taken place earlier, i.e. preparation for execution of its body and arguments; > thereafter, secondly, the execution of the resulting Prolog goals. \\ 857a849,852 > \medskip > \noindent > From the parsing viewpoint \code{phrase(NT, S)} is true when the terminal sequence \code{S} is covered (cf. Definition 3.4) by the non-terminal \code{NT}. Or, from the generation viewpoint it is true when > \code{NT} generates \code{S}. 860c855,858 < Subclause \ref{section:logicalExpansion}, "Prolog Definition of phrase/3", provides a reference implementation that further defines the semantics of expansion.\\ --- > Section \ref{section:logicalExpansion}, "Prolog Definition of Phrase/3", provides a reference implementation that further defines the semantics of expansion.\\ > \noindent > The numbering of the Prolog clauses of the procedure \code{dcg\_cbody/4} for the grammar control constructs of this section 10, starting with \%071\%, > is partially synchronized with the following subsection numbers. 863c861 < The following subclauses explicate the linkages between the terminal sequences upon expansion of the control constructs. --- > In particular this subsection explicates the linkages between the terminal sequences upon expansion of the control constructs. 870c868 < In \code{phrase([ ], S0, S)} the expansion result of the grammar control construct \code{empty terminal sequence} --- > The expansion result of the grammar control construct \code{empty terminal sequence} 872c870 < remaining terminal sequence \code{S} with the comprehensive terminal sequence \code{S0}, --- > remaining terminal sequence with the comprehensive terminal sequence, 873a872,873 > For a formal description of expansion of this form see section \ref{section:logicalExpansion}, clause \%071\%. > 879a880 > For a formal description of expansion of this form see section \ref{section:logicalExpansion}, clause \%072\%. 885c886 < In the body of a grammar-rule the non-terminal \code{(',')//2} acts as principal functor of a \code{grammar-body-sequence} (cf. Definition 3.11) --- > In the body of a grammar-rule the non-terminal \code{(',')//2} acts as principal functor of a \code{grammar-body-sequence} (cf. Definition 3.12) 888c889,890 < a conjunction wrt. subclause 7.8.5 of ISO/IEC 13211-1 Prolog, which results from expansion of \code{(',')//2}. \\ --- > a conjunction wrt. section 7.8.5 of ISO/IEC 13211-1 Prolog, which results from expansion of \code{(',')//2}. \\ > For a formal description of expansion of this form see section \ref{section:logicalExpansion}, clause \%073\%. 893c895 < expanded grammar-rule-head and a semicontext; --- > expanded grammar-rule-head and a right-hand-context; 900,901c902,903 < In the body of a grammar rule \code{(;)//2} acts as principal functor of a \\ \code{alternative}. (cf. Definition 3.1) with a first grammar body GBFirst and a second grammar body GBSecond. < Each of them is subject to subsequent separate expansion - GBFirst first, and then GBSecond. The alternative is expanded to the disjunction \code{(;)/2} wrt. subclause 7.8.6 of ISO/IEC 13211-1 Prolog. --- > In the body of a grammar rule \code{(;)//2} acts as principal functor of a \\ \code{grammar-body-alternative}. (cf. definition 3.8) with a first grammar body GBFirst and a second grammar body GBSecond. > Each of them is subject to subsequent separate expansion - GBFirst first, and then GBSecond. The grammar-body-alternative is expanded to the disjunction \code{(;)/2} wrt. section 7.8.6 of ISO/IEC 13211-1 Prolog. 902a905 > For a formal description of expansion of this form see section \ref{section:logicalExpansion}, clause \%074\%. 906c909 < NOTE --- The effect of comma and semicolon, \code{(',')//2}, \code{(;)//2}, may be understood best by application of \code{write\_canonical/1} (see subclause 8.14.2.5 of ISO/IEC 13211--1) on a grammar rule, containing them:\\ --- > NOTE --- The effect of comma and semicolon, \code{(',')//2}, \code{(;)//2}, may be understood best by application of \code{write\_canonical/1} (see section 8.14.2.5 of ISO/IEC 13211--1) on a grammar rule, containing them:\\ 931,942d933 < \end{verbatim} < \end{quote} < < \subsubsection{\code{->//2} -- if-then-else} < < \label{sssection:ifThenElse} < < \noindent < \code{(;)//2} (cf. \ref{sssection:alternative}) serves two different functions depending on whether or not its first argument is a compound term < with functor \code{(->)//2}.\ < See \ref{sssection:alternative} for the use of \code{(;)//2} for \code{alternative}, when < the first argument of \code{(;)//2} is not a \code{(->)//2}.\ 944,949d934 < \vspace{1em} < \noindent < The grammar control construct \code{(;)//2} has as arguments a grammar body GBFirst and a second grammar body GBSecond. < If the principal functor of GBFirst is \code{(->)//2} with arguments GBIf and GBThen, then the < grammar rule bodies GBIf, GBThen, and GBSecond are subject to separate expansion to < GBIfExpanded, GBThenExpanded and GBSecondExpanded, respectively.\\ 951,965c936,937 < \medskip < \noindent < The result of expansion is an if-then-else < (cf subclause 7.8.8 of ISO/IEC 13211-1), resulting from expansion of \code{(;)//2}, \\ < with the if-then construct \code{->(GBIfExpanded, GBThenExpanded)} as first, < and \code{GBSecondExpanded} as second argument. < < \medskip < \noindent < < \begin{comment} < \medskip < \noindent < There shall be no use of \code{(->)//2} in grammar rules except in the first argument of an alternative as described above. < \end{comment} --- > \end{verbatim} > \end{quote} 970c942 < for an alternative. See subclause \ref{sssection:alternative}. --- > for a grammar-body-alternative. See subsection \ref{sssection:alternative}. 976,978c948 < used for "if-then-else", as \code{('|')//2} shall not be used for "if-then-else". See subclause \ref{sssection:ifThenElse}. < < \subsubsection{\code{\{\}//1} -- grammar-body-goal} --- > used for "if-then-else", as \code{('|')//2} shall not be used for "if-then-else". See subsection \ref{sssection:ifThenElse}. 982,985c952 < The non-terminal \code{\{G\}}, with \code{G} a Prolog goal, according to ISO/IEC 13211-1:1995, can stand at any place of a non-terminal inside a grammar-rule-body. After expansion the < braces are omitted, the goal G is unchanged. On execution G is executed like any Prolog goal. \\ < \noindent < If {G} immediately contains a cut ('!'), this is handled like a grammar-body-cut (cf. \ref{ssection:grammarCut}). --- > For a formal description of expansion of this form see section \ref{section:logicalExpansion}, clause \%075\%. 1009a977,979 > \medskip > \noindent > For a formal description of expansion of \code{call//1} see section \ref{section:logicalExpansion}, clause \%076\%. 1031,1032d1000 < < \subsubsection{\code{phrase//1}} 1034c1002 < % modified JPEH --- > \subsubsection{\code{\{\}//1} -- grammar-body-goal} 1036,1041d1003 < \noindent < \code{phrase//1} is a grammar-built-in predicate for using the built-in predicate \code{phrase/3}. < < \medskip < \noindent < Expanding, i.e. preparing for execution of the non-terminal 1043a1006,1014 > \noindent > The non-terminal \code{\{G\}}, with \code{G} a Prolog goal, according to ISO/IEC 13211-1:1995, can stand at any place of a non-terminal inside a grammar-rule-body. After expansion the > braces are omitted, the goal G is unchanged. On execution G is executed like any Prolog goal. \\ > \noindent > If {G} immediately contains a cut ('!'), this is handled like a grammar-body-cut (cf. \ref{ssection:grammarCut}). \\ > \noindent > For a formal description of expansion of \code{(\{G\}//1} see section \ref{section:logicalExpansion}, clause \%077\%. > > \subsubsection{\code{($\backslash$+)//1} -- grammar-body-not} 1045,1047d1015 < \code{phrase//1} < < \medskip 1049,1051c1017,1019 < with argument < < \medskip --- > In the body of a grammar rule \code{($\backslash$+)//1} is expanded to the principal functor \code{($\backslash$+)/1} of a \code{grammar-body-not} (cf. Definition 3.11) > This functor \code{($\backslash$+)/1} is applied to the expanded argument of the > \code{grammar-body-not}. If the resulting goal succeeds the expanded rule does not change the comprehensive terminal sequence.\\ 1053c1021,1022 < \code{G} --- > \noindent > For a formal description of expansion of \code{($\backslash$+)//1} see section \ref{section:logicalExpansion}, clause \%078\%. 1057c1026 < shall result in a goal for the built-in predicate --- > Implementations conforming to this TR shall not define or use a predicate \code{($\backslash$+)/3}. \\ 1059d1027 < \medskip 1061,1063d1028 < \code{phrase/3} < < \medskip 1065c1030 < with first argument \code{G}. --- > NOTE --- The effect of \code{($\backslash$+)//1} can be seen in the following example.\\ 1067d1031 < \medskip 1069c1033,1048 < For a definition of the built-in predicate \code{phrase/3} see subclause \ref{sssection:phraseSpecification}.\\ --- > The grammar rule > > \begin{quote} > \begin{verbatim} > a --> \+ b. > \end{verbatim} > \end{quote} > > \noindent > may be expanded to: > > \begin{quote} > \begin{verbatim} > a(S0, S) :- \+ b(S0, _), S0 = S. > \end{verbatim} > \end{quote} 1075c1054 < In the body of a grammar rule \code{!//0} is a \code{grammar-body-cut}. After expansion the grammar-body-cut becomes the control construct cut, \code{!/0}, as in subclause 7.8.4 of ISO/IEC 13211-1 Prolog.\ --- > In the body of a grammar rule \code{!//0} is a \code{grammar-body-cut}. After expansion the grammar-body-cut becomes the control construct cut, \code{!/0}, as in section 7.8.4 of ISO/IEC 13211-1 Prolog.\ 1076a1056 > For a formal description of expansion of \code{!//0} see section \ref{section:logicalExpansion}, clause \%079\%. 1082c1062,1064 < \subsubsection{\code{($\backslash$+)//1} -- grammar-body-not} --- > \subsubsection{\code{(;)//2} and \code{->//2} -- if-then-else} > > \label{sssection:ifThenElse} 1085,1087c1067,1070 < In the body of a grammar rule \code{($\backslash$+)//1} is expanded to the principal functor \code{($\backslash$+)/1} of a \code{grammar-body-not} (cf. Definition 3.10) < This functor \code{($\backslash$+)/1} is applied to the expanded argument of the < \code{grammar-body-not}. If the resulting goal succeeds the expanded rule does not change the comprehensive terminal sequence.\\ --- > \code{(;)//2} serves two different functions depending on whether or not its first argument is a compound term > with functor \code{(->)/2}.\ > See \ref{sssection:alternative} for the use of \code{(;)//2} for \code{alternative}, when > the first argument of \code{(;)//2} is not a \code{(->)/2}.\ 1089,1091c1072,1084 < %\noindent < %For a formal description of expansion of \code{($\backslash$+)//1} see subclause \ref{section:logicalExpansion}, clause \%078\%. < % omit JPEH --- > \vspace{1em} > \noindent > The grammar control construct \code{(;)//2} shall have as arguments a grammar body GBFirst and a second grammar body GBSecond. > The principal functor of GBFirst is \code{(->)/2} with arguments GBIf and GBThen. In this if-then-else form the > grammar rule bodies GBIf, GBThen, and GBSecond are subject to > separate expansion to GBIfExpanded, GBThenExpanded and GBSecondExpanded, respectively.\\ > \medskip > > The result of expansion is an if-then-else \code{(;)/2} > (cf section 7.8.8 of ISO/IEC 13211-1), resulting from expansion > of \code{(;)//2}, with the if-then construct > \code{->(GBIfExpanded, GBThenExpanded)} as first, > and \code{GBSecondExpanded} as second argument. 1095c1088 < Implementations conforming to this TR shall not define or use a predicate \code{($\backslash$+)/3}. \\ --- > For a formal description of expansion of if-then-else see section \ref{section:logicalExpansion}, clause \%074\% and \%0710\%. 1096a1090,1096 > \begin{comment} > \medskip > \noindent > There shall be no use of \code{(->)//2} in grammar rules except in the first argument of an alternative as described above. > \end{comment} > > \subsubsection{\code{phrase//1}} 1099c1099,1106 < NOTE --- The effect of \code{($\backslash$+)//1} can be seen in the following example.\\ --- > \code{phrase//1} is not included in the allowed constructs of the body (of a grammar-rule). It is designed > as grammar-built-in predicate for using the built-in predicate \code{phrase/3}. > > Expanding, i.e. preparing for execution of the non-terminal > > \medskip > > \code{phrase//1} 1100a1108 > \medskip 1102c1110,1112 < The grammar rule --- > with argument > > \medskip 1104,1108c1114 < \begin{quote} < \begin{verbatim} < a --> \+ b. < \end{verbatim} < \end{quote} --- > \code{G} 1109a1116 > \medskip 1111c1118 < may be expanded to: --- > shall result in a goal for the built-in predicate 1113,1117c1120,1132 < \begin{quote} < \begin{verbatim} < a(S0, S) :- \+ b(S0, _), S0 = S. < \end{verbatim} < \end{quote} --- > \medskip > > \code{phrase/3} > > \medskip > \noindent > with first argument \code{G}. > > \medskip > \noindent > For a definition of the built-in predicate \code{phrase/3} see section \ref{sssection:phraseSpecification}.\\ > > \medskip 1134,1135c1149,1150 < as specified in subclause 7.7.7 of ISO/IEC 13211--1, then the error term as specified < in subclause 7.7.7b of ISO/IEC 13211--1 when the flag \code{unknown} is set to \code{error} --- > as specified in section 7.7.7 of ISO/IEC 13211--1, then the error term as specified > in section 7.7.7b of ISO/IEC 13211--1 when the flag \code{unknown} is set to \code{error} 1164c1179 < 2\hspace{1.5em}Parsing resp. generating of terminal sequences using grammar rules is defined in subclause \ref{sssection:phraseSpecification}. Grammar rules are expanded there into Prolog clauses during preparation for execution, which maps the parsing or generating with a grammar-rule-body into executing a goal given a sequence of predicate clauses. See subclause 7.7 of ISO/IEC 13211--1 for details. --- > 2\hspace{1.5em}Parsing resp. generating of terminal sequences using grammar rules is defined in subsection \ref{sssection:phraseSpecification}. Grammar rules are expanded there into Prolog clauses during preparation for execution, which maps the parsing or generating with a grammar-rule-body into executing a goal given a sequence of predicate clauses. See section 7.7 of ISO/IEC 13211--1 for details. 1183,1189c1198 < \code{phrase(GRBody, S0, S)} is true iff \code{S0} either unifies with the concatenation of the grammar-body-sequence of \code{GRBody}, if any, (cf. Definition 3.11) with the remaining terminal-sequence \code{S}, or with the concatenation of a terminal-sequence resulting from generation by the non-terminal, if any, of \code{GRBody} w.r.t. the current Grammar rules with the remaining terminal-sequence \code{S}.\\ < < \medskip < \noindent < Execution of the predicate \code{phrase/3} serves two goals: Firstly the final expansion(of a grammar rule) (cf. Definition 3.7), < when this has not taken place earlier, i.e. preparation for execution of its body and arguments; < thereafter, secondly, the execution of the resulting Prolog goals. \\ --- > \code{phrase(GRBody, S0, S)} is true iff \code{S0} either unifies with the concatenation of the grammar-body-sequence of \code{GRBody}, if any, (cf. Definition 3.12) with the remaining terminal-sequence \code{S}, or with the concatenation of a terminal-sequence resulting from generation by the non-terminal, if any, of \code{GRBody} w.r.t. the current Grammar rules with the remaining terminal-sequence \code{S}.\\ 1196c1205 < NOTE 2 --- The simple grammar of example 7.14.1.1 may be prepared here for execution.\\ --- > NOTE 2 --- The simple grammar of example 7.14.1.1 may be prepared for execution.\\ 1197a1207 > \medskip 1208a1219 > \medskip 1210c1221 < \code{phrase(noun\_phrase, [the, dog, barks], [barks])} is true.\ --- > \code{phrase(noun\_phrase, [the, dog, barks], [barks])} is true.\\ 1214c1225 < If the non-terminal of \code{GRBody}, if any, is followed by a semicontext (cf. Definition 3.21), then the semicontext shall be prefixed to the remaining terminal sequence after having been parsed resp. generated wrt. the non-terminal of \code{GRBody}.\\ --- > If the non-terminal of \code{GRBody}, if any, is followed by a right-hand-context (cf. Definition 3.23), then the right-hand-context shall be prefixed to the remaining terminal sequence after having been parsed resp. generated wrt. the non-terminal of \code{GRBody}.\\ 1216c1227 < Procedurally, \code{phrase(GRBody, S0, S)} is executed by calling the Prolog goal corresponding to the expansion of the grammar-rule-body \code{GRBody}, given the terminal-sequences \code{S0} and \code{S}, according to the logical expansion of grammar rules described in subclause \ref{section:logicalExpansion}. See in particular the clauses for \code{dcg\_rule/4}.\\ --- > Procedurally, \code{phrase(GRBody, S0, S)} is executed by calling the Prolog goal corresponding to the expansion of the grammar-rule-body \code{GRBody}, given the terminal-sequences \code{S0} and \code{S}, according to the logical expansion of grammar rules described in section \ref{section:logicalExpansion}. See in particular the clauses for \code{dcg\_rule/4}.\\ 1219c1230 < \code{phrase(GRBody, S0, S)} shall be steadfast (cf. 3.22) in its third argument S. --- > \code{phrase(GRBody, S0, S)} shall be steadfast in its third argument S (cf. Definition 3.24). 1260d1270 < 1302d1311 < \noindent 1304d1312 < 1307a1316 > 1310a1320 > 1311a1322 > | ?- phrase(sentence, [the, girl, likes, the, boy, today]). 1313d1323 < | ?- phrase(sentence, [the, girl, likes, the, boy, today]). 1316c1326,1327 < | ?- phrase(sentence, [the, girl, likes]). --- > | ?- phrase(sentence, [the, girl, likes]). > 1327a1339 > 1328a1341 > 1330a1344 > 1360c1374 < NOTE --- The predicate \code{term\_expansion/2} is described in subclause \ref{sssection:termExpansion}. --- > NOTE --- The predicate \code{term\_expansion/2} is described in subsection \ref{sssection:termExpansion}. 1498,1499d1511 < % JPEH I changed the reference numbers to match the subclauses. < 1501,1502c1513,1516 < % To avoid name clashes, if there exists already a phrase/3 in the processor: < % the functor "phrase/3" may be replaced by "iso_phrase/3" or else. --- > % To avoid name clashes: if phrase/3 exists already on the processor, > % the word "phrase" may be replaced by "iso_phrase" or else at two places. > % Missing prerequisite definitions as append/3 shall be defined by > % the "Prolog Prologue" (ISO/IEC JTC1 SC22 WG17 N235) 1506,1507d1519 < % This program uses append/3 as defined in the "Prolog Prologue": < % The "Prolog Prologue" is ISO/IEC JTC1 SC22 WG17 N235 1508a1521 > %01% 1513c1526,1528 < % Expands a DCG rule into a Prolog rule, when no error condition applies. --- > %02% > % dcg_rule(DCGrule, S0, S, Expansion). > % Translates a DCG rule into a Prolog rule, when no error condition applies. 1515c1530 < dcg_rule(( NonTerminal, Terminals --> GRBody ), ( Head :- Body )) :- --- > dcg_rule((NonTerminal, Terminals --> GRBody), S0, S, (Head :- Body)) :- 1519,1521c1534,1537 < Body = ( Goal1, Goal2 ). < dcg_rule(( NonTerminal --> GRBody ), ( Head :- Body )) :- < NonTerminal \= ( _, _ ), --- > Body = (Goal1, Goal2). > > dcg_rule((NonTerminal --> GRBody), S0, S, (Head :- Body)) :- > NonTerminal \= (_,_), 1524a1541,1543 > %03% > % translates a grammar goal non-terminal: > 1529a1549,1551 > %04% > % translates a terminal-sequence: > 1532a1555,1557 > %05% > % translates a grammar-rule-body: > 1535a1561 > 1539a1566 > 1543c1570 < NonTerminal \= ( _ -> _ ), --- > NonTerminal \= (_->_), 1546,1559c1573,1582 < % The following constructs in a grammar rule body < % are defined in the corresponding subclauses. < < 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 --- > %06% > dcg_constr([]). > dcg_constr([_|_]). > dcg_constr((_,_)). > dcg_constr((_;_)). > dcg_constr((_'|'_)). > dcg_constr(call(_)). > dcg_constr({_}). > dcg_constr(\+_). > dcg_constr(!). 1561,1562c1584,1585 < % The principal functor of the first argument indicates < % the construct to be expanded. --- > %071% > dcg_cbody([], S0, S, (S0=S)). 1564c1587 < dcg_cbody([], S0, S, S0 = S ). --- > %072% 1567c1590,1592 < dcg_cbody(( GRFirst, GRSecond ), S0, S, ( First, Second )) :- --- > > %073% > dcg_cbody(( GRFirst , GRSecond ), S0, S, ( First, Second )) :- 1569a1595,1596 > > %074% 1571,1572c1598,1599 < \+ subsumes_term(( _ -> _ ),GREither), < dcg_body(GREither, S0, S, Either), --- > subsumes_term((_->_),GREither), > dcg_cbody(GREither, S0, S, Either), 1573a1601,1602 > > 1575,1576c1604,1605 < subsumes_term(( _ -> _ ),GREither), < dcg_cbody(GREither, S0, S, Either), --- > \+ subsumes_term((_->_),GREither), > dcg_body(GREither, S0, S, Either), 1577a1607,1608 > > %075% 1581c1612,1613 < dcg_cbody({Goal}, S0, S, ( Goal, S0 = S )). --- > > %076% 1583,1584c1615,1620 < dcg_cbody(phrase(Body), S0, S, phrase(Body, S0, S)). < dcg_cbody(\+ GRBody, S0, S, ( \+ Goal, S0 = S )) :- --- > > %077% > dcg_cbody({Goal}, S0, S, (Goal, S0 = S)). > > %078% > dcg_cbody(\+ GRBody, S0, S, (\+ Goal, S0 = S)) :- 1586c1622,1626 < dcg_cbody(!, S0, S, ( !, S0 = S )). --- > > %079% > dcg_cbody(!, S0, S, (!, S0 = S)). > > %0710% 1589a1630 > 1590a1632 >