BNF for ZCompiler.jj

TOKENS

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

   
/**
 * Multiline comment. can contain other multi line comments.
 */
<DEFAULT> TOKEN : {
<COMMENT_END: "*/">
}

   
<DEFAULT> SPECIAL : {
<COMMENT_START: "/*"> : {
}

   
/* OPERATORS & KEYWORDS*/
<DEFAULT> TOKEN : {
<PLUS: "+">
| <INC: "++">
| <DEC: "--">
| <MINUS: "-">
| <MULTIPLY: "*">
| <DIVIDE: "/">
| <MOD: "%">
| <POW: "**">
| <AND: "&&" | "and">
| <CASE_INS: "case-insensitive">
| <MULTI_LINE: "multi-line">
| <SAND: "&">
| <OR: "||" | "or">
| <LIKE: "like">
| <PIPE: "|">
| <GT: ">">
| <LT: "<">
| <LE: "<=">
| <GE: ">=">
| <EQ: "==">
| <NEQ: "!=">
| <XOR: "^">
| <NOT: "!">
| <CONDITION: "?">
| <CLM: ":">
| <EQUAL: "=">
| <SCL: ";">
| <LPAREN: "(">
| <RPAREN: ")">
| <LBRACE: "{">
| <RBRACE: "}">
| <CLBRACKET: "?[">
| <LBRACKET: "[">
| <RBRACKET: "]">
| <COMMA: ",">
| <DOT: ".">
| <CDOT: "?.">
| <CONTEXT: "context">
| <RETURN: "return" | "ret">
| <MEMORY: "memory" | "mem">
| <SLEEP: "sleep">
| <THROW: "throw">
| <FOR: "for">
| <FUNCTION: "function" | "func">
| <DETERMINISTIC: "deterministic" | "det">
| <SYNC: "sync">
| <ASYNC: "async">
| <ARG: "arg">
| <TRUE: "true">
| <FALSE: "false">
| <NULL: "null" | "nill">
| <E: "E">
| <PI: "PI">
| <FIRST: "first">
| <IF: "if">
| <ELSE: "else">
| <SWAP: "<->" | "<=>">
| <USE: "use">
| <DECIMAL: "decimal" | "dec">
}

   
/**
 * Number and String constants 
 */
<DEFAULT> TOKEN : {
<INTEGER: <DECIMAL_LITERAL> (["l","L"])? | <HEX_LITERAL> (["l","L"])? | <OCTAL_LITERAL> (["l","L"])?>
| <#DECIMAL_LITERAL: ["1"-"9"] (["0"-"9"])*>
| <#HEX_LITERAL: "0" ["x","X"] (["0"-"9","a"-"f","A"-"F"])+>
| <#OCTAL_LITERAL: "0" (["0"-"7"])*>
| <FLOATING_POINT: (["0"-"9"])+ "." (["0"-"9"])* (<EXPONENT>)? (["f","F","d","D"])? | "." (["0"-"9"])+ (<EXPONENT>)? (["f","F","d","D"])? | (["0"-"9"])+ <EXPONENT> (["f","F","d","D"])? | (["0"-"9"])+ (<EXPONENT>)? ["f","F","d","D"]>
| <#EXPONENT: ["e","E"] (["+","-"])? (["0"-"9"])+>
| <CHARACTER: "\'" (~["\'","\\","\n","\r"] | "\\" (["n","t","b","r","f","\\","\'","\""] | ["0"-"7"] (["0"-"7"])? | ["0"-"3"] ["0"-"7"] ["0"-"7"])) "\'">
| <STRING: ("\"" | "\'") (~["\"","\\","\n","\r"] | "\\" (["n","t","b","r","f","\\","\'","\""] | ["0"-"7"] (["0"-"7"])? | ["0"-"3"] ["0"-"7"] ["0"-"7"]))* ("\"" | "\'")>
| <MATCHEXP: "`" (~["`","\\","\n","\r"] | "\\" (["n","t","b","r","f","\\","`","\""] | ["0"-"7"] (["0"-"7"])? | ["0"-"3"] ["0"-"7"] ["0"-"7"]))* "`">
}

   
/**
 * ZEL identifiers.
 */
<DEFAULT> TOKEN : {
<ID: <LETTER> (<LETTER> | <DIGIT>)*>
| <#LETTER: ["$","A"-"Z","_","a"-"z","\u00c0"-"\u00d6","\u00d8"-"\u00f6","\u00f8"-"\u00ff","\u0100"-"\u1fff","\u3040"-"\u318f","\u3300"-"\u337f","\u3400"-"\u3d2d","\u4e00"-"\u9fff","\uf900"-"\ufaff"]>
| <#DIGIT: ["0"-"9","\u0660"-"\u0669","\u06f0"-"\u06f9","\u0966"-"\u096f","\u09e6"-"\u09ef","\u0a66"-"\u0a6f","\u0ae6"-"\u0aef","\u0b66"-"\u0b6f","\u0be7"-"\u0bef","\u0c66"-"\u0c6f","\u0ce6"-"\u0cef","\u0d66"-"\u0d6f","\u0e50"-"\u0e59","\u0ed0"-"\u0ed9","\u1040"-"\u1049"]>
}

   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   

NON-TERMINALS

mainprogram ::= program <EOF>
program ::= ( ( ( programBlockStatic ) | ( statement ) ) ( ( <SCL> ( programBlockStatic | statement ) ) | programBlockStatic )* )?
statement ::= operations
| expression
| zreturn
| forStmt
| ifStmt
| ( <SLEEP> expression )
| ( <THROW> expression )
| ( <SYNC> expression )
| ( <USE> <DECIMAL> <INTEGER> )
/**
 * The ZEL for statement, (similar with for from GO):
 *   for i = 0, result = 0; i < breakup; i = i + 1 {
 *    result = result + part[i] 
 *   };
 */
forStmt ::= <FOR> ( ( operations ( <COMMA> operations )* ) <SCL> )? logical ( <SCL> ( operations ( <COMMA> operations )* ) )? programBlockStatic
/**
 * The IF statment. (Similar as in GO):
 *     if v > ma {
 *        ma = v
 *     } else if v < mi {
 *        mi = v
 *     }
 */
ifStmt ::= ( <IF> logical ( programBlockStatic | statement ) ) ( <ELSE> ( programBlockStatic | statement ) )?
programBlockStatic ::= programBlock
/**
 * A zel program block:
 * {
 *  .....
 * }
 */
programBlock ::= <LBRACE> program <RBRACE>
zreturn ::= <RETURN> ( expression )?
/**
 * The ZEL operations:
 *
 * Assignements: x, y, z = {1, 2, 3}; f(x) = 4;
 * Increment: x++
 * Decrement: x--
 * Swap: x <-> y
 *
 */
operations ::= assignement
| swap
| ( assignableExpression ( <INC> | <DEC> ) )
assignement ::= assignableExpression ( <COMMA> assignableExpression )* ( <EQUAL> expression )
swap ::= assignableExpression <SWAP> assignableExpression
assignableExpression ::= ( <ID> ) ( ( params ) | ( ( ( <DOT> <ID> ) | ( <LBRACKET> expression <RBRACKET> ) ) ) )*
expression ::= ternary
/**
 * The ternary operator:
 * a < 0 ? 1 : 2
 */
ternary ::= logical ( ( <CONDITION> ) ternary <CLM> ternary )?
/**
 * Logical operators: AND OR XOR
 */
logical ::= compare ( ( <AND> | <OR> | <XOR> ) compare )*
/**
 * Commparison operatiors: < > <= >= == !=
 */
compare ::= sum ( ( ( <GT> | <LT> | <GE> | <LE> | <EQ> | <NEQ> ) sum ) | ( ( <CASE_INS> )? ( <MULTI_LINE> )? <LIKE> <STRING> ) )*
/**
 * + - operators.
 */
sum ::= term ( ( <PLUS> | <MINUS> ) term )*
/**
 * * / % operators
 */
term ::= exponent ( ( <MULTIPLY> | <DIVIDE> | <MOD> ) exponent )*
/**
 * the exponent operator: ^
 */
exponent ::= unaryPost ( <POW> unaryPost )*
/**
 * Method invocation + dereferencing.
 */
unaryPost ::= unary ( ( params ( <SAND> )? ) | ( <DOT> <ID> ) | ( <CDOT> <ID> ) | ( <LBRACKET> expression <RBRACKET> ) | ( <CLBRACKET> expression <RBRACKET> ) )*
unary ::= ( ( <MINUS> | <NOT> ) element )
| element
element ::= ( constant | ( <ID> ) | sysFunction | ( <FIRST> params ) | <LPAREN> expression <RPAREN> | ( <LBRACE> ( expression ( <COMMA> expression )* )? <RBRACE> ) | ( <PIPE> expression <PIPE> ) )
params ::= <LPAREN> ( expression ( <COMMA> expression )* )? <RPAREN>
constant ::= ( <FLOATING_POINT> | <INTEGER> | <TRUE> | <FALSE> | <CHARACTER> | <NULL> | <STRING> | <MATCHEXP> )
| <E>
| <PI>
| <MEMORY>
parseInteger ::= java code
sysFunction ::= ( <FUNCTION> ( <DETERMINISTIC> )? ( ( <SYNC> ) | ( <ASYNC> ) )? ( <ID> )? ( <LPAREN> ( <ID> ( <COMMA> <ID> )* ) <RPAREN> )? ) ( <EQUAL> )? programBlock