This repository has been archived on 2023-08-20. You can view files and clone it, but cannot push or open issues or pull requests.
yap-6.3/Logtalk/manuals/refman/grammar.html

688 lines
20 KiB
HTML
Raw Normal View History

<?xml version="1.0" encoding="iso-8859-1"?>
<?xml-stylesheet type="text/css" href="../styles.css" ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en">
<head>
<meta http-equiv="content-type" content="text/html; charset=iso-8859-1" />
<title>Logtalk Grammar</title>
<link rel="stylesheet" href="../styles.css" type="text/css" />
</head>
<body>
<div class="navtop">
<a href="../index.html">contents</a> &gt; <a href="index.html">reference manual</a>
</div>
<h2>Grammar</h2>
<p>
The Logtalk grammar is here described using Backus-Naur Form syntax. Non-terminal symbols in <i>italics</i> have the defintion found in the ISO Prolog Standard. Terminal symbols are represented in a <code>fixed width font</code> and between "".
</p>
<h3>Compilation units<a name="compilation_units"></a></h3>
<blockquote>
<dl>
<dt>entity ::=</dt>
<dd>object |</dd>
<dd>category |</dd>
<dd>protocol</dd>
</dl>
</blockquote>
<h3>Object definition<a name="object_definition"></a></h3>
<blockquote>
<dl>
<dt>object ::=</dt>
<dd>begin_object_directive [object_directives] [clauses] end_object_directive.</dd>
</dl>
<dl>
<dt>begin_object_directive ::=</dt>
<dd>"<code>:- object(</code>" object_identifier [ "<code>,</code>" object_relations] "<code>).</code>"</dd>
</dl>
<dl>
<dt>end_object_directive ::=</dt>
<dd>"<code>:- end_object.</code>"</dd>
</dl>
<dl>
<dt>object_relations ::=</dt>
<dd>prototype_relations |</dd>
<dd>non_prototype_relations</dd>
</dl>
<dl>
<dt>prototype_relations ::=</dt>
<dd>prototype_relation |</dd>
<dd>prototype_relation "<code>,</code>" prototype_relations</dd>
</dl>
<dl>
<dt>prototype_relation ::=</dt>
<dd>implements_protocols |</dd>
<dd>imports_categories |</dd>
<dd>extends_objects</dd>
</dl>
<dl>
<dt>non_prototype_relations ::=</dt>
<dd>non_prototype_relation |</dd>
<dd>non_prototype_relation "<code>,</code>" non_prototype_relations</dd>
</dl>
<dl>
<dt>non_prototype_relation ::=</dt>
<dd>implements_protocols |</dd>
<dd>imports_categories |</dd>
<dd>instantiates_classes |</dd>
<dd>specializes_classes</dd>
</dl>
</blockquote>
<h3>Category definition<a name="category_definition"></a></h3>
<blockquote>
<dl>
<dt>category ::=</dt>
<dd>begin_category_directive [category_directives] [clauses] end_category_directive.</dd>
</dl>
<dl>
<dt>begin_category_directive ::=</dt>
<dd>"<code>:- category(</code>" category_identifier [ "<code>,</code>" implements_protocols] "<code>).</code>"</dd>
</dl>
<dl>
<dt>end_category_directive ::=</dt>
<dd>"<code>:- end_category.</code>"</dd>
</dl>
</blockquote>
<h3>Protocol definition<a name="protocol_definition"></a></h3>
<blockquote>
<dl>
<dt>protocol ::=</dt>
<dd>begin_protocol_directive [protocol_directives] end_protocol_directive.</dd>
</dl>
<dl>
<dt>begin_protocol_directive ::=</dt>
<dd>"<code>:- protocol(</code>" protocol_identifier [ "<code>,</code>" extends_protocols] "<code>).</code>"</dd>
</dl>
<dl>
<dt>end_protocol_directive ::=</dt>
<dd>"<code>:- end_protocol.</code>"</dd>
</dl>
</blockquote>
<h3>Entity relations<a name="entity_relations"></a></h3>
<blockquote>
<dl>
<dt>implements_protocols ::=</dt>
<dd>"<code>implements(</code>" implemented_protocols "<code>)</code>"</dd>
</dl>
<dl>
<dt>extends_protocols ::=</dt>
<dd>"<code>extends(</code>" extended_protocols "<code>)</code>"</dd>
</dl>
<dl>
<dt>imports_categories ::=</dt>
<dd>"<code>imports(</code>" imported_categories "<code>)</code>"</dd>
</dl>
<dl>
<dt>extends_objects ::=</dt>
<dd>"<code>extends(</code>" extended_objects "<code>)</code>"</dd>
</dl>
<dl>
<dt>instantiates_classes ::=</dt>
<dd>"<code>instantiates(</code>" instantiated_objects "<code>)</code>"</dd>
</dl>
<dl>
<dt>specializes_classes ::=</dt>
<dd>"<code>specializes(</code>" specialized_objects "<code>)</code>"</dd>
</dl>
<h4>Implemented protocols<a name="implemented_protocols"></a></h4>
<blockquote>
<dl>
<dt>implemented_protocols ::=</dt>
<dd>implemented_protocol |</dd>
<dd>implemented_protocol_sequence |</dd>
<dd>implemented_protocol_list</dd>
</dl>
<dl>
<dt>implemented_protocol ::=</dt>
<dd>protocol_identifier |</dd>
<dd>scope "<code>::</code>" protocol_identifier</dd>
</dl>
<dl>
<dt>implemented_protocol_sequence ::=</dt>
<dd>implemented_protocol |</dd>
<dd>implemented_protocol "<code>,</code>" implemented_protocol_sequence</dd>
</dl>
<dl>
<dt>implemented_protocol_list ::=</dt>
<dd>"<code>[</code>" implemented_protocol_sequence "<code>]</code>"</dd>
</dl>
</blockquote>
<h4>Extended protocols<a name="extended_protocols"></a></h4>
<blockquote>
<dl>
<dt>extended_protocols ::=</dt>
<dd>extended_protocol |</dd>
<dd>extended_protocol_sequence |</dd>
<dd>extended_protocol_list</dd>
</dl>
<dl>
<dt>extended_protocol ::=</dt>
<dd>protocol_identifier |</dd>
<dd>scope "<code>::</code>" protocol_identifier</dd>
</dl>
<dl>
<dt>extended_protocol_sequence ::=</dt>
<dd>extended_protocol |</dd>
<dd>extended_protocol "<code>,</code>" extended_protocol_sequence</dd>
</dl>
<dl>
<dt>extended_protocol_list ::=</dt>
<dd>"<code>[</code>" extended_protocol_sequence "<code>]</code>"</dd>
</dl>
</blockquote>
<h4>Imported categories<a name="imported_categories"></a></h4>
<blockquote>
<dl>
<dt>imported_categories ::=</dt>
<dd>imported_category |</dd>
<dd>imported_category_sequence |</dd>
<dd>imported_category_list</dd>
</dl>
<dl>
<dt>imported_category ::=</dt>
<dd>category_identifier |</dd>
<dd>scope "<code>::</code>" category_identifier</dd>
</dl>
<dl>
<dt>imported_category_sequence ::=</dt>
<dd>imported_category |</dd>
<dd>imported_category "<code>,</code>" imported_category_sequence</dd>
</dl>
<dl>
<dt>imported_category_list ::=</dt>
<dd>"<code>[</code>" imported_category_sequence "<code>]</code>"</dd>
</dl>
</blockquote>
<h4>Extended objects<a name="extended_objects"></a></h4>
<blockquote>
<dl>
<dt>extended_objects ::=</dt>
<dd>extended_object |</dd>
<dd>extended_object_sequence |</dd>
<dd>extended_object_list</dd>
</dl>
<dl>
<dt>extended_object ::=</dt>
<dd>object_identifier |</dd>
<dd>scope "<code>::</code>" object_identifier</dd>
</dl>
<dl>
<dt>extended_object_sequence ::=</dt>
<dd>extended_object |</dd>
<dd>extended_object "<code>,</code>" extended_object_sequence</dd>
</dl>
<dl>
<dt>extended_object_list ::=</dt>
<dd>"<code>[</code>" extended_object_sequence "<code>]</code>"</dd>
</dl>
</blockquote>
<h4>Instantiated objects<a name="instantiated_objects"></a></h4>
<blockquote>
<dl>
<dt>instantiated_objects ::=</dt>
<dd>instantiated_object |</dd>
<dd>instantiated_object_sequence |</dd>
<dd>instantiated_object_list</dd>
</dl>
<dl>
<dt>instantiated_object ::=</dt>
<dd>object_identifier |</dd>
<dd>scope "<code>::</code>" object_identifier</dd>
</dl>
<dl>
<dt>instantiated_object_sequence ::=</dt>
<dd>instantiated_object</dd>
<dd>instantiated_object "<code>,</code>" instantiated_object_sequence |</dd>
</dl>
<dl>
<dt>instantiated_object_list ::=</dt>
<dd>"<code>[</code>" instantiated_object_sequence "<code>]</code>"</dd>
</dl>
</blockquote>
<h4>Specialized objects<a name="specialized_objects"></a></h4>
<blockquote>
<dl>
<dt>specialized_objects ::=</dt>
<dd>specialized_object |</dd>
<dd>specialized_object_sequence |</dd>
<dd>specialized_object_list</dd>
</dl>
<dl>
<dt>specialized_object ::=</dt>
<dd>object_identifier |</dd>
<dd>scope "<code>::</code>" object_identifier</dd>
</dl>
<dl>
<dt>specialized_object_sequence ::=</dt>
<dd>specialized_object |</dd>
<dd>specialized_object "<code>,</code>" specialized_object_sequence</dd>
</dl>
<dl>
<dt>specialized_object_list ::=</dt>
<dd>"<code>[</code>" specialized_object_sequence "<code>]</code>"</dd>
</dl>
</blockquote>
<h4>Entity scope<a name="scope"></a></h4>
<blockquote>
<dl>
<dt>scope ::=</dt>
<dd>"<code>public</code>" |</dd>
<dd>"<code>protected</code>" |</dd>
<dd>"<code>private</code>"</dd>
</dl>
</blockquote>
</blockquote>
<h3>Entity identifiers<a name="entity_identifiers"></a></h3>
<blockquote>
<dl>
<dt>entity_identifiers ::=</dt>
<dd>entity_identifier |</dd>
<dd>entity_identifier_sequence |</dd>
<dd>entity_identifier_list</dd>
</dl>
<dl>
<dt>entity_identifier ::=</dt>
<dd>object_identifier |</dd>
<dd>protocol_identifier |</dd>
<dd>category_identifier</dd>
</dl>
<dl>
<dt>entity_identifier_sequence ::=</dt>
<dd>entity_identifier |</dd>
<dd>entity_identifier "<code>,</code>" entity_identifier_sequence</dd>
</dl>
<dl>
<dt>entity_identifier_list ::=</dt>
<dd>"<code>[</code>" entity_identifier_sequence "<code>]</code>"</dd>
</dl>
<h4>Object identifiers<a name="object_identifiers"></a></h4>
<blockquote>
<dl>
<dt>object_identifiers ::=</dt>
<dd>object_identifier |</dd>
<dd>object_identifier_sequence |</dd>
<dd>object_identifier_list</dd>
</dl>
<dl>
<dt>object_identifier ::=</dt>
<dd><i>atom</i> |</dd>
<dd><i>compound</i></dd>
</dl>
<dl>
<dt>object_identifier_sequence ::=</dt>
<dd>object_identifier |</dd>
<dd>object_identifier "<code>,</code>" object_identifier_sequence</dd>
</dl>
<dl>
<dt>object_identifier_list ::=</dt>
<dd>"<code>[</code>" object_identifier_sequence "<code>]</code>"</dd>
</dl>
</blockquote>
<h4>Category identifiers<a name="category_identifiers"></a></h4>
<blockquote>
<dl>
<dt>category_identifiers ::=</dt>
<dd>category_identifier |</dd>
<dd>category_identifier_sequence |</dd>
<dd>category_identifier_list</dd>
</dl>
<dl>
<dt>category_identifier ::=</dt>
<dd><i>atom</i></dd>
</dl>
<dl>
<dt>category_identifier_sequence ::=</dt>
<dd>category_identifier |</dd>
<dd>category_identifier "<code>,</code>" category_identifier_sequence</dd>
</dl>
<dl>
<dt>category_identifier_list ::=</dt>
<dd>"<code>[</code>" category_identifier_sequence "<code>]</code>"</dd>
</dl>
</blockquote>
<h4>Protocol identifiers<a name="protocol_identifiers"></a></h4>
<blockquote>
<dl>
<dt>protocol_identifiers ::=</dt>
<dd>protocol_identifier |</dd>
<dd>protocol_identifier_sequence |</dd>
<dd>protocol_identifier_list</dd>
</dl>
<dl>
<dt>protocol_identifier ::=</dt>
<dd><i>atom</i></dd>
</dl>
<dl>
<dt>protocol_identifier_sequence ::=</dt>
<dd>protocol_identifier |</dd>
<dd>protocol_identifier "<code>,</code>" protocol_identifier_sequence</dd>
</dl>
<dl>
<dt>protocol_identifier_list ::=</dt>
<dd>"<code>[</code>" protocol_identifier_sequence "<code>]</code>"</dd>
</dl>
</blockquote>
</blockquote>
<h3>Directives<a name="directives"></a></h3>
<blockquote>
<h4>Object directives<a name="object_directives"></a></h4>
<blockquote>
<dl>
<dt>object_directives ::=</dt>
<dd>object_directive |</dd>
<dd>object_directive object_directives</dd>
</dl>
<dl>
<dt>object_directive ::=</dt>
<dd>"<code>:- initialization(</code>" <i>callable</i> "<code>).</code>" |</dd>
<dd>"<code>:- uses(</code>" object_identifiers "<code>).</code>" |</dd>
<dd>"<code>:- calls(</code>" protocol_identifiers "<code>).</code>" |</dd>
<dd>"<code>:- dynamic.</code>" |</dd>
<dd>"<code>:- info(</code>" info_list "<code>).</code>" |</dd>
<dd>predicate_directives</dd>
</dl>
</blockquote>
<h4>Category directives<a name="category_directives"></a></h4>
<blockquote>
<dl>
<dt>category_directives ::=</dt>
<dd>category_directive |</dd>
<dd>category_directive category_directives</dd>
</dl>
<dl>
<dt>category_directive ::=</dt>
<dd>"<code>:- initialization(</code>" <i>callable</i> "<code>).</code>" |</dd>
<dd>"<code>:- uses(</code>" object_identifiers "<code>).</code>" |</dd>
<dd>"<code>:- calls(</code>" protocol_identifiers "<code>).</code>" |</dd>
<dd>"<code>:- dynamic.</code>" |</dd>
<dd>"<code>:- info(</code>" info_list "<code>).</code>" |</dd>
<dd>predicate_directives</dd>
</dl>
</blockquote>
<h4>Protocol directives<a name="protocol_directives"></a></h4>
<blockquote>
<dl>
<dt>protocol_directives ::=</dt>
<dd>protocol_directive |</dd>
<dd>protocol_directive protocol_directives</dd>
</dl>
<dl>
<dt>protocol_directive ::=</dt>
<dd>"<code>:- initialization(</code>" <i>callable</i> "<code>).</code>" |</dd>
<dd>"<code>:- dynamic.</code>" |</dd>
<dd>"<code>:- info(</code>" info_list "<code>).</code>" |</dd>
<dd>predicate_directives</dd>
</dl>
</blockquote>
<h4>Predicate directives<a name="predicate_directives"></a></h4>
<blockquote>
<dl>
<dt>predicate_directives ::=</dt>
<dd>predicate_directive |</dd>
<dd>predicate_directive predicate_directives</dd>
</dl>
<dl>
<dt>predicate_directive ::=</dt>
<dd>scope_directive |</dd>
<dd>mode_directive |</dd>
<dd>metapredicate_directive |</dd>
<dd>info_directive |</dd>
<dd><i>operator_directive</i> |</dd>
<dd><i>dynamic_directive</i> |</dd>
<dd><i>discontiguous_directive</i></dd>
</dl>
<dl>
<dt>scope_directive ::=</dt>
<dd>"<code>:- public(</code>" predicate_indicator_term "<code>).</code>" |</dd>
<dd>"<code>:- protected(</code>" predicate_indicator_term "<code>).</code>" |</dd>
<dd>"<code>:- private(</code>" predicate_indicator_term "<code>).</code>"</dd>
</dl>
<dl>
<dt>mode_directive ::=</dt>
<dd>"<code>:- mode(</code>" predicate_mode_term "<code>,</code>" number_of_solutions "<code>).</code>"</dd>
</dl>
<dl>
<dt>metapredicate_directive ::=</dt>
<dd>"<code>:- metapredicate(</code>" metapredicate_mode_indicator "<code>).</code>"</dd>
</dl>
<dl>
<dt>info_directive ::=</dt>
<dd>"<code>:- info(</code>" predicate_indicator "<code>,</code>" info_list "<code>).</code>"</dd>
</dl>
<dl>
<dt>predicate_indicator_term ::=</dt>
<dd><i>predicate_indicator</i> |</dd>
<dd>predicate_indicator_sequence |</dd>
<dd>predicate_indicator_list</dd>
</dl>
<dl>
<dt>predicate_indicator_sequence ::=</dt>
<dd><i>predicate_indicator</i> |</dd>
<dd><i>predicate_indicator</i> "<code>,</code>" predicate_indicator_sequence</dd>
</dl>
<dl>
<dt>predicate_indicator_list ::=</dt>
<dd>"<code>[</code>" predicate_indicator_sequence "<code>]</code>"</dd>
</dl>
<dl>
<dt>predicate_mode_term ::=</dt>
<dd><i>atom</i> "<code>(</code>" mode_terms "<code>)</code>"</dd>
</dl>
<dl>
<dt>mode_terms ::=</dt>
<dd>mode_term |</dd>
<dd>mode_term "<code>,</code>" mode_terms</dd>
</dl>
<dl>
<dt>mode_term ::=</dt>
<dd>"<code>@</code>" [type] | "<code>+</code>" [type] | "<code>-</code>" [type] | "<code>?</code>" [type]</dd>
</dl>
<dl>
<dt>metapredicate_mode_indicator ::=</dt>
<dd><i>atom</i> "<code>(</code>" metapredicate_terms "<code>)</code>"</dd>
</dl>
<dl>
<dt>metapredicate_terms ::=</dt>
<dd>metapredicate_term |</dd>
<dd>metapredicate_term "<code>,</code>" metapredicate_terms</dd>
</dl>
<dl>
<dt>metapredicate_term ::=</dt>
<dd>"<code>::</code>" | "<code>*</code>"</dd>
</dl>
<dl>
<dt>type ::=</dt>
<dd>prolog_type | logtalk_type | user_defined_type</dd>
</dl>
<dl>
<dt>prolog_type ::=</dt>
<dd>"<code>term</code>" | "<code>nonvar</code>" | "<code>var</code>" |</dd>
<dd>"<code>compound</code>" | "<code>ground</code>" | "<code>callable</code>" | "<code>list</code>" |</dd>
<dd>"<code>atomic</code>" | "<code>atom</code>" |</dd>
<dd>"<code>number</code>" | "<code>integer</code>" | "<code>float</code>"</dd>
</dl>
<dl>
<dt>logtalk_type ::=</dt>
<dd>"<code>object</code>" | "<code>category</code>" | "<code>protocol</code>" |</dd>
<dd>"<code>event</code>"</dd>
</dl>
<dl>
<dt>user_defined_type ::=</dt>
<dd><i>atom</i> |</dd>
<dd><i>compound</i></dd>
</dl>
<dl>
<dt>number_of_solutions ::=</dt>
<dd>"<code>zero</code>" | "<code>zero_or_one</code>" | "<code>zero_or_more</code>" | "<code>one</code>" | "<code>one_or_more</code>" | "<code>error</code>"</dd>
</dl>
<dl>
<dt>info_list ::=</dt>
<dd>"<code>[]</code>" |</dd>
<dd>"<code>[</code>" info_item "<code>is</code>" <i>nonvar</i> "<code>|</code>" info_list "<code>]</code>"</dd>
</dl>
<dl>
<dt>info_item ::=</dt>
<dd>"<code>comment</code>" | "<code>author</code>" | "<code>version</code>" | "<code>date</code>" | "<code>parnames</code>" |</dd>
<dd>"<code>argnames</code>" | "<code>definition</code>" | "<code>redefinition</code>" | "<code>allocation</code>" |</dd>
<dd><i>atom</i></dd>
</dl>
</blockquote>
</blockquote>
<h3>Clauses and goals<a name="clauses"></a></h3>
<blockquote>
<dl>
<dt>goal ::=</dt>
<dd><i>callable</i> |</dd>
<dd>message_call |</dd>
<dd>external_call |</dd>
</dl>
<dl>
<dt>message_call ::=</dt>
<dd>message_to_object |</dd>
<dd>message_to_self |</dd>
<dd>message_to_super</dd>
</dl>
<dl>
<dt>message_to_object ::=</dt>
<dd>receivers "<code>::</code>" messages</dd>
</dl>
<dl>
<dt>message_to_self ::=</dt>
<dd>"<code>::</code>" messages</dd>
</dl>
<dl>
<dt>message_to_super ::=</dt>
<dd>"<code>^^</code>" message</dd>
</dl>
<dl>
<dt>messages ::=</dt>
<dd>message |</dd>
<dd>"<code>(</code>" message "<code>,</code>" messages "<code>)</code>" |</dd>
<dd>"<code>(</code>" message "<code>;</code>" messages "<code>)</code>"</dd>
</dl>
<dl>
<dt>message ::=</dt>
<dd><i>callable</i> |</dd>
<dd><i>variable</i></dd>
</dl>
<dl>
<dt>receivers ::=</dt>
<dd>receiver |</dd>
<dd>"<code>(</code>" receiver "<code>,</code>" receivers "<code>)</code>" |</dd>
<dd>"<code>(</code>" receiver "<code>;</code>" receivers "<code>)</code>"</dd>
</dl>
<dl>
<dt>receiver ::=</dt>
<dd>object_identifier |</dd>
<dd><i>variable</i></dd>
</dl>
<dl>
<dt>external_call ::=</dt>
<dd>"<code>{</code>" <i>callable</i> "<code>}</code>"</dd>
</dl>
</blockquote>
<h3>Entity properties<a name="entity_properties"></a></h3>
<blockquote>
<dl>
<dt>category_property ::=</dt>
<dd>"<code>static</code>" |</dd>
<dd>"<code>dynamic</code>" |</dd>
<dd>"<code>built_in</code>"</dd>
</dl>
<dl>
<dt>object_property ::=</dt>
<dd>"<code>static</code>" |</dd>
<dd>"<code>dynamic</code>" |</dd>
<dd>"<code>built_in</code>"</dd>
</dl>
<dl>
<dt>protocol_property ::=</dt>
<dd>"<code>static</code>" |</dd>
<dd>"<code>dynamic</code>" |</dd>
<dd>"<code>built_in</code>"</dd>
</dl>
</blockquote>
<h3>Predicate properties<a name="predicate_properties"></a></h3>
<blockquote>
<dl>
<dt>predicate_property ::=</dt>
<dd>"<code>static</code>" |</dd>
<dd>"<code>dynamic</code>" |</dd>
<dd>"<code>private</code>" |</dd>
<dd>"<code>protected</code>" |</dd>
<dd>"<code>public</code>" |</dd>
<dd>"<code>built_in</code>" |</dd>
<dd>"<code>declared_in(</code>" entity_identifier "<code>)</code>" |</dd>
<dd>"<code>defined_in(</code>" object_identifier | category_identifier "<code>)</code>" |</dd>
<dd>"<code>metapredicate(</code>" metapredicate_mode_indicator "<code>)</code>"</dd>
</dl>
</blockquote>
<div class="navbottom">
<a href="index.html">previous</a> | <a href="../glossary.html">glossary</a> | <a href="index.html">next</a>
</div>
<div class="copyright">
Copyright &copy; <a href="mailto:pmoura@logtalk.org">Paulo Moura</a> &mdash; <a href="http://www.logtalk.org">Logtalk.org</a>
</div>
<div class="footer">
<p><span class="bleft"><a href="http://validator.w3.org/check/referer">XHTML</a> + <a href="http://jigsaw.w3.org/css-validator/check/referer">CSS</a></span><span class="bright">Last updated on: December 23, 2003</span></p>
</div>
</body>
</html>