/* AgentSpeak Grammar */
|
agent |
::= |
( agent_component )* <EOF> |
agent_component |
::= |
( directive | belief | initial_goal | plan ) |
/* Directive */
|
directive |
::= |
"{" ( <TK_BEGIN> directive_arguments "}" ( agent_component )* "{" <TK_END> "}" | directive_arguments "}" ) |
directive_arguments |
::= |
<ATOM> ( "(" terms ")" )? ( list )? |
/* Beliefs & Rules */
|
belief |
::= |
literal ( <TK_RULE_SEP> log_expr )? "." |
/* Initial goals */
|
initial_goal |
::= |
"!" literal "." |
/* Plan */
|
plan |
::= |
( plan_annotation )? trigger ( ":" log_expr )? ( <TK_GOAL_CONDITION> log_expr )? ( <TK_LEFT_ARROW> plan_body )? "." ( "{" ( plan )* "}" )? |
plan_annotation |
::= |
<TK_LABEL_AT> ( ( <ATOM> | <TK_BEGIN> | <TK_END> ) ( list )? | list ) |
/* Trigger */
|
trigger |
::= |
( "+" | "-" | "^" ) ( ( "!" | "?" ) )? literal |
/* Plan body */
|
plan_body |
::= |
( plan_body_term ( ";" ( plan_body )? )? | statement ( ";" )? ( plan_body )? ) |
plan_body_term |
::= |
plan_body_factor ( <TK_POR> plan_body_term )? |
plan_body_factor |
::= |
body_formula ( <TK_PAND> plan_body_factor )? |
statement |
::= |
( stmtIF | stmtFOR | stmtWHILE ) |
stmtIF |
::= |
<TK_IF> stmtIFCommon |
stmtIFCommon |
::= |
"(" log_expr ")" "{" ( stmt_body )? "}" ( <TK_ELIF> stmtIFCommon | <TK_ELSE> "{" ( stmt_body )? "}" )? |
stmtFOR |
::= |
<TK_FOR> "(" log_expr ")" "{" ( stmt_body )? "}" |
stmtWHILE |
::= |
<TK_WHILE> "(" log_expr ")" "{" ( stmt_body )? "}" |
stmt_body |
::= |
plan_body |
body_formula |
::= |
( ( ( "!" | "!!" ) literal ) | ( ( "?" | "+" ( "+" | "<" | ">" )? | "-" ( "+" | "-" )? )? ( log_expr | "(" plan_body ")" ) ) ) |
rule_plan_term |
::= |
"{" ( ( plan_term_annotation )? trigger ( ":" log_expr )? ( ( ";" ( plan_body )? | <TK_LEFT_ARROW> plan_body ) )? | plan_body ( <TK_RULE_SEP> log_expr )? )? "}" |
plan_term_annotation |
::= |
<TK_LABEL_AT> ( ( <ATOM> | <TK_BEGIN> | <TK_END> ) ( list )? | var | list ) |
/* Literal */
|
literal |
::= |
( ( namespace )? ( <TK_NEG> )? ( pred | var ) | <TK_TRUE> | <TK_FALSE> ) |
namespace |
::= |
( <ATOM> | var )? <TK_NS_SEP> |
/* Annotated Formulae */
|
pred |
::= |
( <ATOM> | <TK_BEGIN> | <TK_END> ) ( "(" terms ")" )? ( list )? |
/* List of terms */
|
terms |
::= |
term ( "," term )* |
term |
::= |
log_expr |
list |
::= |
"[" ( term_in_list ( "," term_in_list )* )? ( "|" ( <VAR> | <UNNAMEDVAR> | list ) )? "]" |
// term_in_list is the same as term, but log_expr/plan_body must be enclosed by "("....")" to avoid problem with |
|
term_in_list |
::= |
( list | arithm_expr | string | rule_plan_term ) |
/* logical expression */
|
log_expr |
::= |
log_expr_trm ( "|" log_expr )? |
log_expr_trm |
::= |
log_expr_factor ( "&" log_expr_trm )? |
log_expr_factor |
::= |
( <TK_NOT> )? rel_expr |
/* relational expression
used in context, body and term
[ ] --> this method returns the VarTerm
| [ ] --> returns the Literal
| [ ] --> returns the ExprTerm
*/
|
rel_expr |
::= |
( arithm_expr | string | list | rule_plan_term ) ( ( "<" | "<=" | ">" | ">=" | "==" | "\\==" | "=" | "=.." ) ( arithm_expr | string | list | rule_plan_term ) )? |
/* arithmetic expression */
|
arithm_expr |
::= |
arithm_expr_trm ( ( "+" | "-" ) arithm_expr_trm )* |
arithm_expr_trm |
::= |
arithm_expr_factor ( ( "*" | "/" | <TK_INTDIV> | <TK_INTMOD> ) arithm_expr_factor )* |
arithm_expr_factor |
::= |
arithm_expr_simple ( ( "**" ) arithm_expr_factor )? |
arithm_expr_simple |
::= |
( "+" | "-" )? ( <NUMBER> | ( "(" log_expr ")" ) | function ) |
function |
::= |
literal |
var |
::= |
( <VAR> | <UNNAMEDVARID> | <UNNAMEDVAR> ) ( list )? |
string |
::= |
<STRING> |