NAME
Soar::Production::Parser::PRDGrammar - P::RD grammar for Soar productions
VERSION
version 1.122830
SYNOPSIS
use Soar::Production::Parser::PRDGrammar;
use Parse::RecDescent;
my $parser = Parse::RecDescent->new($Soar::Production::Parser::PRDGrammar::GRAMMAR);
$parser->parse($some_text);
DESCRIPTION
This module holds one string: a Parse::RecDescent
grammar for parsing Soar productions.
NAME
Soar::Production::Parser::PRDGrammar - Parse::RecDescent
grammar for parsing Soar productions.
BNF Grammar from the Soar Manual
The following is a description of a grammar describing Soar productions, from the Soar manual. Note also that a /(;\s*)?\#/ (pound sign optionally preceded by semi-colon and white space) indicates an end-of-line comment. Soar does not have multi-line comments.
Grammar of Soar productions
A grammar for Soar productions is:
<soar-production> ::= sp "{" <production-name> [<documentation>] [<flags>]
<condition-side> --> <action-side> "}"
<documentation> ::= """ [<string>] """
<flags> ::= ":" (o-support | i-support | chunk | default)
Grammar for Condition Side
I have modified the grammar below from the original to account for the fact that an instance of <state-imp-cond> is not required to start the LHS, and may actually occur anywhere inside of it.
Below is a grammar for the condition sides of productions:
<condition-side> ::= <cond>+
<cond> ::= <positive_cond> | "-" <positive_cond>
<positive_cond> ::= <state-imp-cond> | <conds_for_one_id> | "{" <cond>+ "}"
<state-imp-cond> ::= "(" (state | impasse) [<id_test>] <attr_value_tests>+ ")"
<conds_for_one_id> ::= "(" [(state|impasse)] <id_test> <attr_value_tests>+ ")"
<id_test> ::= <test>
<attr_value_tests> ::= ["-"] "^" <attr_test> ("." <attr_test>)* <value_test>*
<attr_test> ::= <test>
<value_test> ::= <test> ["+"] | <conds_for_one_id> ["+"]
<test> ::= <conjunctive_test> | <simple_test>
<conjunctive_test> ::= "{" <simple_test>+ "}"
<simple_test> ::= <disjunction_test> | <relational_test>
<disjunction_test> ::= "<<" <constant>+ ">>"
<relational_test> ::= [<relation>] <single_test>
<relation> ::= "<>" | "<" | ">" | "<=" | ">=" | "=" | "<=>"
<single_test> ::= <variable> | <constant>
<variable> ::= "<" <sym_constant> ">"
<constant> ::= <sym_constant> | <int_constant> | <float_constant>
Notes on the Condition Side
In an <id_test>, only a <variable> may be used in a <single_test>.
Grammar for Action Side
Below is a grammar for the action sides of productions:
<rhs> ::= <rhs_action>*
<rhs_action> ::= "(" <variable> <attr_value_make>+ ")" | <func_call>
<func_call> ::= "(" <func_name> <rhs_value>* ")"
<func_name> ::= <sym_constant> | "+" | "-" | "*" | "/"
<rhs_value> ::= <constant> | <func_call> | <variable>
<attr_value_make> ::= "^" <variable_or_sym_constant> ("." <variable_or_sym_constant>)* <value_make>+
<variable_or_sym_constant> ::= <variable> | <sym_constant>
<value_make> ::= <rhs_value> <preference_specifier>*
<preference-specifier> ::= <unary-preference> [","]
| <unary-or-binary-preference> [","]
| <unary-or-binary-preference> <rhs_value> [","]
<unary-pref> ::= "+" | "-" | "!" | "~" | "@"
<unary-or-binary-pref> ::= ">" | "=" | "<" | "&"
CAVEATS
This grammar does not check for the semantic correctness of a production. For example, the following parses just fine:
sp {foo
(state)
-->
(<s> ^foo <a>)
}
Whereas the real Soar parser gives us an error, saying that <lt>s<gt> is not connected to the LHS in any way.
BUGS
This may belong in the realm of semantic verification, but for now it is considered a known bug. In Soar, numbers cannot be used to name a working memory element unless they are quoted. This is not yet implemented in this grammar, and thus the following is accepted, even though Soar would reject it:
sp {bad-numbers
(state <s> ^string.2.string)
-->
}
SEE ALSO
The documentation for Soar is located at https://code.google.com/p/soar/
AUTHOR
Nathan Glenn <garfieldnate@gmail.com>
COPYRIGHT AND LICENSE
This software is copyright (c) 2012 by Nathan Glenn.
This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.