KRB Syntax
This section describes the syntax for defining rules in the KRB files.
Legend
To describe this syntax, the following punctuation is used:
- 'any_chars'
- required punctuation or keyword: any_chars
- a | b
- alternation: a or b
- [a]
- optional a
- {a}
- one or more a's. If a ends in a comma, the last comma is optional.
- NL
- means one or more newlines
Lexical Structure
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.
The two notable exceptions to python conventions are:
- Identifiers may be used as strings, without requiring quotes.
- foobar is the same as 'foobar'
- Singleton tuples do not require a trailing comma.
- (1) is the same as (1,)
Keywords
as | foreach | taking |
assert | in | True |
bc_extras | None | use |
check | plan_extras | when |
extending | python | with |
False | step | without |
fc_extras |
Syntax of the Entire KRB File
file ::= [NL] ['extending' IDENTIFIER ['without' {IDENTIFIER,}] NL] [{fc_rule} ['fc_extras' NL INDENT {<python_statement> NL} DEINDENT]] [{bc_rule} ['bc_extras' NL INDENT {<python_statement> NL} DEINDENT] ['plan_extras' NL INDENT {<python_statement> NL} DEINDENT]]
The KRB file has three optional parts. It must contain at least one rule (either forward-chaining or backward-chaining).
The filename (minus the .krb extension) is the name of the rule base. This must be a legal python identifier.
Extending clause
The optional extending clause, if used, is the first line of the file. This defines the parent rule base that this rule base inherits from. It may also specify a list of backward-chaining goal names to be excluded from this inheritance.
Forward-Chaining Section
If the krb file contains any forward-chaining rules, a python source file will be created named <rb_name>_fc.py, where <rb_name> is the rule base name.
The syntax of a forward-chaining rule (fc_rule) is defined elsewhere.
The fc_extras can only be used if there are forward-chaining rules. This allows you to add other python code (for example, import statements) to the generated python source file.
Backward-Chaining Section
If the krb file contains any backward-chaining rules, a python source file will be created named <rb_name>_bc.py, where <rb_name> is the rule base name.
The syntax of a backward-chaining rule (bc_rule) is defined elsewhere.
The bc_extras can only be used if there are backward-chaining rules. This allows you to add other python code (for example, import statements) to the generated python source file.
In addition, if any of the backward-chaining rules have plan code (for example, a with clause or subgoals in the when clause that produce plans), a python source file will be created name <rb_name>_plans.py, where <rb_name> is the rule base name.
You use the plan_extras to include arbitrary python code in this plans file.