[c203b8]: doc / html / krb_syntax / index.html Maximize Restore History

Download this file

index.html    247 lines (233 with data), 12.0 kB

  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
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en">
<head>
<title>KRB Syntax</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<link rel="stylesheet" href="../stylesheets/pyke.css" type="text/css" />
</head>
<body>
<table id="page-table">
<thead class="head">
<tr id="header1"><th id="header" colspan="3">
&nbsp;
</th></tr>
<tr id="header2">
<th id="crumb-left"></th>
<th id="crumb-line">
<div id="nav">
<ul>
<li><a href="../index.html">Home</a></li>
<li>&gt;</li>
<li>KRB Syntax</li>
</ul>
</div>
</th>
<th id="crumb-right"></th>
</tr>
</thead>
<tbody id="body">
<tr id="body-tr">
<td id="left-nav">
<div id="left-nav-div">
<div class="title-nav"><a href="../index.html">Home</a></div><div class="nav-branch">
<div class="normal-nav"><a href="../overview/index.html">Overview</a></div>
<div class="normal-nav"><a href="../installing_pyke.html">Installing Pyke</a></div>
<div class="normal-nav"><a href="../using_pyke.html">Using Pyke</a></div>
<div class="title-nav"><a href="index.html">KRB Syntax</a></div><div class="nav-branch">
<div class="normal-nav"><a href="fc_rule.html">Fc_rule</a></div>
<div class="normal-nav"><a href="bc_rule.html">Bc_rule</a></div>
<div class="normal-nav"><a href="pattern.html">Pattern</a></div>
<div class="normal-nav"><a href="compound_premise.html">Compound Premise</a></div>
<div class="normal-nav"><a href="python_premise.html">Python Premise</a></div>
</div>
<div class="normal-nav"><a href="../examples.html">Examples</a></div>
<div class="normal-nav"><a href="../logic_tricks.html">Logic Tricks</a></div>
<div class="normal-nav"><a href="../PyCon2008-paper.html">PyCon 2008 Paper</a></div>
</div>
</div>
<div id="icons">
<div id="project-page">
<a href="http://sourceforge.net/projects/pyke/">Pyke Project Page</a>
</div>
Please Make a Donation:<br />
<a href="http://sourceforge.net/donate/index.php?group_id=207724">
<img src="http://images.sourceforge.net/images/project-support.jpg"
width="88" height="32" border="0"
alt="Support This Project" /> </a> <br /><br />
Hosted by: <br />
<!-- <a href="http://sourceforge.net"><img src="http://sflogo.sourceforge.net/sflogo.php?group_id=207724&amp;type=3" width="125" height="37" border="0" alt="SourceForge.net Logo" /></a> -->
<a href="http://sourceforge.net"><img src="http://sflogo.sourceforge.net/sflogo.php?group_id=207724&amp;type=4" width="125" height="37" border="0" alt="SourceForge.net Logo" /></a>
</div>
</td>
<td id="main-td">
<div id="main">
<a name="startcontent" id="startcontent"></a>
<div class="document" id="krb-syntax">
<h1 class="title">KRB Syntax</h1>
<p>This section describes the syntax for defining <a class="reference" href="../overview/rules/index.html">rules</a> in the KRB files.</p>
<div class="section">
<h1><a id="legend" name="legend">Legend</a></h1>
<p>To describe this syntax, the following punctuation is used:</p>
<dl class="docutils">
<dt>'<em>any_chars</em>'</dt>
<dd>required punctuation or keyword: <em>any_chars</em></dd>
<dt><em>a</em> | <em>b</em></dt>
<dd>alternation: <em>a</em> or <em>b</em></dd>
<dt>[<em>a</em>]</dt>
<dd>optional <em>a</em></dd>
<dt>{<em>a</em>}</dt>
<dd>one or more <em>a</em>'s. If <em>a</em> ends in a comma, the last comma is optional.</dd>
<dt>NL</dt>
<dd>means one or more newlines</dd>
</dl>
</div>
<div class="section">
<h1><a id="lexical-structure" name="lexical-structure">Lexical Structure</a></h1>
<p>The KRB lexical structure is much like python. Like python, indenting is
significant. It uses the same commenting, line continuation and literal
formats for strings and numbers (except complex numbers). It also uses the
same rules for forming identifiers.</p>
<p>The two notable exceptions to python conventions are:</p>
<ol class="arabic simple">
<li>Identifiers may be used as strings, without requiring quotes.<ul>
<li><tt class="docutils literal"><span class="pre">foobar</span></tt> is the same as <tt class="docutils literal"><span class="pre">'foobar'</span></tt></li>
</ul>
</li>
<li>Singleton tuples do not require a trailing comma.<ul>
<li><tt class="docutils literal"><span class="pre">(1)</span></tt> is the same as <tt class="docutils literal"><span class="pre">(1,)</span></tt></li>
</ul>
</li>
</ol>
</div>
<div class="section">
<h1><a id="keywords" name="keywords">Keywords</a></h1>
<table border="1" class="docutils">
<colgroup>
<col width="31%" />
<col width="38%" />
<col width="31%" />
</colgroup>
<tbody valign="top">
<tr><td>as</td>
<td>foreach</td>
<td>taking</td>
</tr>
<tr><td>assert</td>
<td>in</td>
<td>True</td>
</tr>
<tr><td>bc_extras</td>
<td>None</td>
<td>use</td>
</tr>
<tr><td>check</td>
<td>plan_extras</td>
<td>when</td>
</tr>
<tr><td>extending</td>
<td>python</td>
<td>with</td>
</tr>
<tr><td>False</td>
<td>step</td>
<td>without</td>
</tr>
<tr><td>fc_extras</td>
<td>&nbsp;</td>
<td>&nbsp;</td>
</tr>
</tbody>
</table>
</div>
<div class="section">
<h1><a id="syntax-of-the-entire-krb-file" name="syntax-of-the-entire-krb-file">Syntax of the Entire KRB File</a></h1>
<pre class="literal-block">
file ::= [NL]
['extending' IDENTIFIER ['without' {IDENTIFIER,}] NL]
[{fc_rule}
['fc_extras' NL INDENT
{&lt;python_statement&gt; NL}
DEINDENT]]
[{bc_rule}
['bc_extras' NL INDENT
{&lt;python_statement&gt; NL}
DEINDENT]
['plan_extras' NL INDENT
{&lt;python_statement&gt; NL}
DEINDENT]]
</pre>
<p>The KRB file has three optional parts. It must contain at least one <a class="reference" href="../overview/rules/index.html">rule</a>
(either <a class="reference" href="../overview/rules/forward_chaining.html">forward-chaining</a> or <a class="reference" href="../overview/rules/backward_chaining.html">backward-chaining</a>).</p>
<p>The filename (minus the .krb extension) is the name of the <a class="reference" href="../overview/knowledge_bases/rule_bases.html">rule base</a>.
This must be a legal python identifier.</p>
<div class="section">
<h2><a id="extending-clause" name="extending-clause">Extending clause</a></h2>
<p>The optional <tt class="docutils literal"><span class="pre">extending</span></tt> clause, if used, is the first line of the file.
This defines the parent <a class="reference" href="../overview/knowledge_bases/rule_bases.html">rule base</a> that this <a class="reference" href="../overview/knowledge_bases/rule_bases.html">rule base</a> <a class="reference" href="../overview/knowledge_bases/rule_bases.html#rule-base-inheritance">inherits</a> from.
It may also specify a list of <a class="reference" href="../overview/rules/backward_chaining.html">backward-chaining</a> goal names to be excluded
from this inheritance.</p>
</div>
<div class="section">
<h2><a id="forward-chaining-section" name="forward-chaining-section">Forward-Chaining Section</a></h2>
<p>If the krb file contains any <a class="reference" href="../overview/rules/forward_chaining.html">forward-chaining</a> <a class="reference" href="../overview/rules/index.html">rules</a>, a python source file
will be created named &lt;rb_name&gt;_fc.py, where &lt;rb_name&gt; is the <a class="reference" href="../overview/knowledge_bases/rule_bases.html">rule base</a>
name.</p>
<p>The syntax of a <a class="reference" href="../overview/rules/forward_chaining.html">forward-chaining</a> <a class="reference" href="../overview/rules/index.html">rule</a> (<a class="reference" href="fc_rule.html">fc_rule</a>) is defined <a class="reference" href="fc_rule.html">elsewhere</a>.</p>
<p>The <tt class="docutils literal"><span class="pre">fc_extras</span></tt> can only be used if there are <a class="reference" href="../overview/rules/forward_chaining.html">forward-chaining</a> <a class="reference" href="../overview/rules/index.html">rules</a>.
This allows you to add other python code (for example, <tt class="docutils literal"><span class="pre">import</span></tt> statements)
to the generated python source file.</p>
</div>
<div class="section">
<h2><a id="backward-chaining-section" name="backward-chaining-section">Backward-Chaining Section</a></h2>
<p>If the krb file contains any <a class="reference" href="../overview/rules/backward_chaining.html">backward-chaining</a> <a class="reference" href="../overview/rules/index.html">rules</a>, a python source file
will be created named &lt;rb_name&gt;_bc.py, where &lt;rb_name&gt; is the <a class="reference" href="../overview/knowledge_bases/rule_bases.html">rule base</a>
name.</p>
<p>The syntax of a <a class="reference" href="../overview/rules/backward_chaining.html">backward-chaining</a> <a class="reference" href="../overview/rules/index.html">rule</a> (<a class="reference" href="bc_rule.html">bc_rule</a>) is defined <a class="reference" href="bc_rule.html">elsewhere</a>.</p>
<p>The <tt class="docutils literal"><span class="pre">bc_extras</span></tt> can only be used if there are <a class="reference" href="../overview/rules/backward_chaining.html">backward-chaining</a> <a class="reference" href="../overview/rules/index.html">rules</a>.
This allows you to add other python code (for example, <tt class="docutils literal"><span class="pre">import</span></tt> statements)
to the generated python source file.</p>
<p>In addition, if any of the <a class="reference" href="../overview/rules/backward_chaining.html">backward-chaining</a> <a class="reference" href="../overview/rules/index.html">rules</a> have <a class="reference" href="../overview/plans.html">plan</a> code (for
example, a <tt class="docutils literal"><span class="pre">with</span></tt> clause or subgoals in the <tt class="docutils literal"><span class="pre">when</span></tt> clause that produce
<a class="reference" href="../overview/plans.html">plans</a>), a python source file will be created name &lt;rb_name&gt;_plans.py, where
&lt;rb_name&gt; is the <a class="reference" href="../overview/knowledge_bases/rule_bases.html">rule base</a> name.</p>
<p>You use the <tt class="docutils literal"><span class="pre">plan_extras</span></tt> to include arbitrary python code in this plans
file.</p>
</div>
</div>
</div>
<!-- <div id="return-to-top">
<a href="#">Return to Top</a>
</div>
-->
</div>
</td>
<td id="right-nav">
<div id="right-nav-div">
<h3>More:</h3>
<div class="right-item"><a href="fc_rule.html">Fc_rule Syntax</a><p>The syntax of a forward-chaining rule.</p>
</div>
<div class="right-item"><a href="bc_rule.html">Bc_rule Syntax</a><p>The syntax of a backward-chaining rule.</p>
</div>
<div class="right-item"><a href="pattern.html">Pattern Syntax</a><p>The syntax of a pattern used to match data values.</p>
</div>
<div class="right-item"><a href="compound_premise.html">Compound Premise Syntax</a><p>The syntax of compound premises.</p>
</div>
<div class="right-item"><a href="python_premise.html">Python Premise Syntax</a><p>The syntax of a python premise.</p>
</div>
</div>
</td>
</tr>
</tbody>
<tfoot id="foot">
<tr id="foot2">
<td id="copyright" colspan="3">
Copyright &copy; 2007 Bruce Frederiksen
</td>
</tr>
</tfoot>
</table>
<div id="last-modified">
Page last modified Sat, Jun 07 2008.
</div>
</body>
</html>