BNF for FlatzincGrammar.jj

TOKENS

/* WHITE SPACE (Always Skipped) */
<DEFAULT> SKIP : {
" "
| "\t"
| "\n"
| "\r"
| "\f"
}

   
/* COMMENTS (Default is Skip) */
<DEFAULT> SPECIAL : {
<SINGLE_LINE_COMMENT: "%" (~["\n","\r"])* ("\n" | "\r" | "\r\n")>
}

   
/* LITERALS */
// string_literal  \"[^"\n]*\"
<DEFAULT> TOKEN : {
<STRING_LITERAL: "\"" (~["\n","\r","\f"])* "\"">
}

   
// int_literal     -?[0-9]+|-?0x[0-9A-Fa-f]+|-?0o[0-7]+
<DEFAULT> TOKEN : {
<INT_LITERAL: (["-"])? (["0"-"9"])+ | (["-"])? "0x" (["0"-"9","A"-"F","a"-"f"])+ | (["-"])? "0o" (["0"-"7"])+>
}

   
//float_literal   -?[0-9]+\.[0-9]+|-?[0-9]+\.[0-9]+[Ee][-+]?[0-9]+|-?[0-9]+[Ee][-+]?[0-9]+
<DEFAULT> TOKEN : {
<FLOAT_LITERAL: ("-")? (["0"-"9"])+ "." (["0"-"9"])+ | ("-")? (["0"-"9"])+ "." (["0"-"9"])+ ("E" | "e") ("-" | "+")? (["0"-"9"])+ | ("-")? (["0"-"9"])+ ("E" | "e") ("-" | "+")? (["0"-"9"])+>
}

   
/* SEPARATORS */
<DEFAULT> TOKEN : {
<SC: ";">
| <COLON: ":">
| <COMMA: ",">
}

   
/* DELIMETERS */
<DEFAULT> TOKEN : {
<LP: "(">
| <RP: ")">
| <LBOX: "[">
| <RBOX: "]">
| <LB: "{">
| <RB: "}">
}

   
/* OPERATORS */
<DEFAULT> TOKEN : {
<ASGN: "=">
}

   
/* Reserved words */
<DEFAULT> TOKEN : {
<ARRAY: "array">
| <BOOL: "bool">
| <CONSTRAINT: "constraint">
| <FALSE: "false">
| <FLOAT: "float">
| <INT: "int">
| <MINIMIZE: "minimize">
| <MAXIMIZE: "maximize">
| <OF: "of">
| <OUTPUT: "output">
| <PREDICATE: "predicate">
| <SATISFY: "satisfy">
| <SET: "set">
| <SHOW: "show">
| <SHOW_COND: "show_cond">
| <SOLVE: "solve">
| <TRUE: "true">
| <VAR: "var">
| <DOTDOT: "..">
| <COLONCOLON: "::">
}

   
/* IDENTIFIER */
// ident           [A-Za-z][A-Za-z0-9_]*
<DEFAULT> TOKEN : {
<IDENT: ["a"-"z","A"-"Z"] (["a"-"z","A"-"Z","0"-"9","_"])*>
}

   

NON-TERMINALS

model ::= pred_decl_items var_decl_items constraint_items model_end <EOF>
pred_decl_items ::= ( pred_decl_item <SC> )*
var_decl_items ::= ( var_decl_item <SC> )*
constraint_items ::= ( constraint_item <SC> )*
model_end ::= solve_item <SC> ( output_item <SC> )?
pred_decl_item ::= <PREDICATE> <IDENT> <LP> pred_decl_args <RP>
var_decl_item ::= <VAR> non_array_ti_expr_tail <COLON> ident_anns ( <ASGN> non_array_flat_expr )?
| non_array_ti_expr_tail <COLON> ident_anns <ASGN> non_array_flat_expr
| <ARRAY> <LBOX> <INT_LITERAL> <DOTDOT> <INT_LITERAL> <RBOX> <OF> array_decl_tail
array_decl_tail ::= non_array_ti_expr_tail <COLON> ident_anns <ASGN> array_literal
| <VAR> non_array_ti_expr_tail <COLON> ident_anns ( <ASGN> array_literal )?
ident_anns ::= <IDENT> annotations
constraint_item ::= <CONSTRAINT> constraint_elem annotations
constraint_elem ::= <IDENT> <LP> flat_exprs <RP>
| variable_expr
solve_item ::= <SOLVE> annotations solve_kind
solve_kind ::= <SATISFY>
| <MINIMIZE> solve_expr
| <MAXIMIZE> solve_expr
output_item ::= <OUTPUT> <LBOX> output_elems <RBOX>
output_elems ::= output_elem ( <COMMA> output_elem )*
output_elem ::= <SHOW> <LP> flat_expr <RP>
| <SHOW_COND> <LP> flat_expr <COMMA> flat_expr <COMMA> flat_expr <RP>
| <STRING_LITERAL>
pred_decl_args ::= pred_decl_arg ( <COMMA> pred_decl_arg )*
pred_decl_arg ::= non_array_ti_expr_tail <COLON> <IDENT>
| <VAR> non_array_ti_expr_tail <COLON> <IDENT>
| <ARRAY> <LBOX> pred_arg_array_index <RBOX> <OF> pred_arg_array_tail <COLON> <IDENT>
pred_arg_array_index ::= <INT>
| <INT_LITERAL> <DOTDOT> <INT_LITERAL>
pred_arg_array_tail ::= non_array_ti_expr_tail
| <VAR> non_array_ti_expr_tail
non_array_ti_expr_tail ::= scalar_ti_expr_tail
| set_ti_expr_tail
scalar_ti_expr_tail ::= bool_ti_expr_tail
| int_ti_expr_tail
| float_ti_expr_tail
bool_ti_expr_tail ::= <BOOL>
int_ti_expr_tail ::= <INT>
| <INT_LITERAL> <DOTDOT> <INT_LITERAL>
| <LB> int_literals <RB>
float_ti_expr_tail ::= <FLOAT>
| <FLOAT_LITERAL> <DOTDOT> <FLOAT_LITERAL>
set_ti_expr_tail ::= <SET> <OF> scalar_ti_expr_tail
ann_exprs ::= ann_expr ( <COMMA> ann_expr )*
ann_expr ::= <IDENT> <LP> ann_exprs <RP>
| flat_expr
flat_exprs ::= flat_expr ( <COMMA> flat_expr )*
flat_expr ::= non_array_flat_expr
| array_literal
non_array_flat_exprs ::= non_array_flat_expr ( <COMMA> non_array_flat_expr )*
non_array_flat_expr ::= set_literal
| scalar_flat_expr
scalar_flat_exprs ::= scalar_flat_expr ( <COMMA> scalar_flat_expr )*
scalar_flat_expr ::= array_access_expr
| <IDENT>
| bool_literal
| <INT_LITERAL>
| <FLOAT_LITERAL>
| <STRING_LITERAL>
int_flat_expr ::= <IDENT>
| array_access_expr
| <INT_LITERAL>
variable_expr ::= <IDENT>
| array_access_expr
solve_expr ::= array_access_expr
| <IDENT> <LP> flat_exprs <RP>
| <IDENT>
array_access_expr ::= <IDENT> <LBOX> int_index_expr <RBOX>
int_index_expr ::= <IDENT>
| <INT_LITERAL>
bool_literal ::= <FALSE>
| <TRUE>
int_literals ::= <INT_LITERAL> ( <COMMA> <INT_LITERAL> )*
set_literal ::= <LB> ( scalar_flat_exprs )? <RB>
| int_flat_expr <DOTDOT> int_flat_expr
array_literal ::= <LBOX> ( non_array_flat_exprs )? <RBOX>
annotations ::= ( <COLONCOLON> annotation )*
annotation ::= <IDENT> <LP> ann_exprs <RP>
| <IDENT> <LP> <LBOX> annotation ( <COMMA> annotation )* <RBOX> <RP>
| <IDENT>