BNF for AS2JavaParser.jj

TOKENS

<DEFAULT> SKIP : {
" "
| "\t"
| "\n"
| "\r"
| <"//" (~["\n","\r"])* ("\n" | "\r" | "\r\n")?>
| <"/*" (~["*"])* "*" ("*" | ~["*","/"] (~["*"])* "*")* "/">
}

   
// Note: i do not why, but vars must be defined before TK_BEGIN and END
<DEFAULT> TOKEN : {
<VAR: <UP_LETTER> (<CHAR>)*>
}

   
<DEFAULT> TOKEN : {
<TK_TRUE: "true">
| <TK_FALSE: "false">
| <TK_NOT: "not">
| <TK_NEG: "~">
| <TK_INTDIV: "div">
| <TK_INTMOD: "mod">
| <TK_BEGIN: "begin">
| <TK_END: "end">
| <TK_LABEL_AT: "@">
| <TK_IF: "if">
| <TK_ELSE: "else">
| <TK_ELIF: "elif">
| <TK_FOR: "for">
| <TK_WHILE: "while">
| <TK_PAND: "|&|">
| <TK_POR: "|||">
| <TK_LEFT_ARROW: "<-">
| <TK_GOAL_CONDITION: "<:">
| <TK_RULE_SEP: ":-">
| <TK_NS_SEP: "::">
| <NUMBER: ["0"-"9"] (["0"-"9"])* | (["0"-"9"])* "." (["0"-"9"])+ (["e","E"] (["+","-"])? (["0"-"9"])+)? | (["0"-"9"])+ ["e","E"] (["+","-"])? (["0"-"9"])+>
| <STRING: "\"" (~["\"","\\","\n","\r"] | "\\" (["n","t","b","r","f","\\","\'","\""] | ["0"-"7"] (["0"-"7"])? | ["0"-"3"] ["0"-"7"] ["0"-"7"]))* "\"">
| <ATOM: (<LC_LETTER> | "." <CHAR>) (<CHAR> | "." <CHAR>)* | "\'" (~["\'"])* "\'">
| <UNNAMEDVARID: "_" (<DIGIT>)+ (<CHAR>)*>
| <UNNAMEDVAR: "_" (<CHAR>)*>
| <CHAR: <LETTER> | <DIGIT> | "_">
| <LETTER: <LC_LETTER> | <UP_LETTER>>
| <LC_LETTER: ["a"-"z"]>
| <UP_LETTER: ["A"-"Z"]>
| <DIGIT: ["0"-"9"]>
}

   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   

NON-TERMINALS

/* 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>