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: "|||">
| <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>)* | "\'" (~["\'"])* "\'"> : {
| <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 ::= bels goals plans

     returns true if achieved the end of file
     returns false if achieved a "{ end }" directive
*/
agent ::= ( directive )* ( belief ( directive )* )* ( initial_goal ( directive )* )* ( plan ( belief )* ( directive )* )* <EOF>
/* Directive

   returns true if the directive is "{ end }", false otherwise
*/
directive ::= "{" ( <TK_BEGIN> pred "}" agent | pred "}" )
/* Beliefs & Rules */
belief ::= literal ( ":-" log_expr )? "."
/* Initial goals */
initial_goal ::= "!" literal "."
/* Plan */
plan ::= ( <TK_LABEL_AT> literal )? trigger ( ":" log_expr )? ( "<-" plan_body )? "."
/* Trigger */
trigger ::= ( "+" | "-" | "^" ) ( ( "!" | "?" ) )? literal
/* Plan body */
plan_body ::= plan_body_term ( ";" )? ( plan_body )?
plan_body_term ::= plan_body_factor ( <TK_POR> plan_body_term )?
plan_body_factor ::= ( stmtIF | stmtFOR | stmtWHILE | body_formula ) ( <TK_PAND> plan_body_factor )?
stmtIF ::= <TK_IF> stmtIFCommon
stmtIFCommon ::= "(" log_expr ")" rule_plan_term ( ( <TK_ELIF> stmtIFCommon | <TK_ELSE> rule_plan_term ) )?
stmtFOR ::= <TK_FOR> "(" log_expr ")" rule_plan_term
stmtWHILE ::= <TK_WHILE> "(" log_expr ")" rule_plan_term
body_formula ::= ( "!" | "!!" | "?" | ( "+" ( ( "+" | "<" | ">" ) )? ) | ( "-" ( "+" )? ) )? ( rule_plan_term | log_expr )
rule_plan_term ::= "{" ( ( <TK_LABEL_AT> pred )? trigger ( ":" log_expr )? ( ( "<-" | ";" ) )? )? ( literal ":-" log_expr )? ( plan_body )? "}"
/* Literal */
literal ::= ( ( ( ( ( <ATOM> | var ) )? "::" )? ( <TK_NEG> )? ( pred | var ) ) | <TK_TRUE> | <TK_FALSE> )
/* Annotated Formulae */
pred ::= ( <ATOM> | <TK_BEGIN> | <TK_END> ) ( "(" terms ")" )? ( list )?
/* List of terms */
terms ::= term ( "," term )*
term ::= ( list | rule_plan_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> log_expr_factor | 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 ) ( ( "<" | "<=" | ">" | ">=" | "==" | "\\==" | "=" | "=.." ) ( 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> | "-" arithm_expr_simple | "+" arithm_expr_simple | "(" log_expr ")" | function )
function ::= literal
var ::= ( <VAR> | <UNNAMEDVAR> ) ( list )?
string ::= <STRING>