All Downloads are FREE. Search and download functionalities are using the official Maven repository.

net.hasor.dataql.domain.parser.DataQL.html Maven / Gradle / Ivy

There is a newer version: 4.2.5
Show newest version



    BNF for DataQL.jj


BNF for DataQL.jj

TOKENS

// ------------------------------------------------------------------------------------------------
/* Ignore Comments */
<DEFAULT> SKIP : {
" "
| "\t"
| "\n"
| "\r"
| "\f"
}

   
<DEFAULT> SPECIAL : {
<C_SINGLE_COMMENT: "//" (~["\n","\r","\f"])* <EOL>>
| <C_MULTILINE_COMMENT: "/*" (~[])* "*/">
| <EOL: "\n" | "\r" | "\f">
}

   
/* Number */
<DEFAULT> TOKEN : {
<#ZERO: "0">
| <#SYMBOL: ["+","-"]>
| <#DIGIT: ["0"-"9"]>
| <INTEGER_NUM: (<SYMBOL>)? (<DIGIT>)+>
| <HEX_NUM: <ZERO> ["x","X"] (["0"-"9","a"-"f","A"-"F"])+>
| <OCTAL_NUM: <ZERO> ["o","O"] (["0"-"7"])+>
| <BINARY_NUM: <ZERO> ["b","B"] (["0"-"7"])+>
| <DECIMAL_NUM: (<SYMBOL>)? (<DIGIT>)+ ("." (<DIGIT>)*)? (["e","E"] (<SYMBOL>)? (<DIGIT>)+)?>
}

   
/* key words */
<DEFAULT> TOKEN : {
<IF: "if">
| <ELSEIF: "elseif">
| <ELSE: "else">
| <END: "end">
| <RETURN: "return">
| <THROW: "throw">
| <EXIT: "exit">
| <VAR: "var">
| <LAMBDA: "lambda">
| <TRUE: "true">
| <FALSE: "false">
| <NULL: "null">
| <OPTION: "option">
}

   
/* OPERATORS */
<DEFAULT> TOKEN : {
<COMMA: ",">
| <COLON: ":">
| <QUEM: "?">
| <SEMI: ";">
| <ASS: "=">
| <QUOTE_SINGLE: "\'">
| <QUOTE_DOUBLE: "\"">
| <OPAR: "(">
| <CPAR: ")">
| <OBRA: "[">
| <CBRA: "]">
| <OCBR: "{">
| <OCBREXT: ["@","#","$","%","&"] <OCBR>>
| <CCBR: "}">
| <BANG: "!">
| <PLUS: "+">
| <MINUS: "-">
| <STAR: "*">
| <SLASH: "/">
| <REM: "%">
| <ALI: "\\">
| <GT: ">">
| <GE: ">=">
| <LT: "<">
| <LE: "<=">
| <EQ: "==">
| <NE: "!=">
| <BIT_AND: "&">
| <BIT_OR: "|">
| <XOR: "^">
| <LSHIFT: "<<">
| <RSIGNEDSHIFT: ">>">
| <RUNSIGNEDSHIFT: ">>>">
| <SC_OR: "||">
| <SC_AND: "&&">
}

   
/* IDENTIFIERS */
<DEFAULT> TOKEN : {
<#LETTER: ["$","A"-"Z","_","a"-"z","\u00aa"-"\u00ad","\u00b5"-"\u00b6","\u00ba"-"\u00bb","\u00c0"-"\u00d6","\u00d8"-"\u00f6","\u00f8"-"\u00ff","\u0100"-"\u1fff","\u3040"-"\u318f","\u3300"-"\u337f","\u3400"-"\u3d2d","\u4e00"-"\u9fff","\uf900"-"\ufaff","\ufb00"-"\ufb06","\ufb13"-"\ufb17","\ufb1f"-"\ufb28","\ufb2a"-"\ufb36","\ufb38"-"\ufb3e","\ufb40"-"\ufb41","\ufb43"-"\ufb44","\ufb46"-"\ufb4f","\ufb50"-"\ufdd7","\ufdf0"-"\ufdfd","\ufe70"-"\ufefc","\uff1f"-"\uff3a","\uff3f"-"\uff5e","\uff61"-"\uffbe","\uffc2"-"\uffc7","\uffca"-"\uffcf","\uffd2"-"\uffd7","\uffda"-"\uffdc"]>
| <#STR_UNICODE: "\\u" (["0"-"9","a"-"f","A"-"F"]){4}>
| <#STR_DOUBLE_BODY: ~["\"","\\","\r","\n","\f","\t"] | "\\" ["r","n","f","t","\\","b","\"","\'"]>
| <STR_DOUBLE_QUOTED: <QUOTE_DOUBLE> (<STR_DOUBLE_BODY>)* <QUOTE_DOUBLE>>
| <#STR_SINGLE_BODY: ~["\'","\\","\r","\n","\f","\t"] | "\\" ["r","n","f","t","\\","b","\"","\'"]>
| <STR_SINGLE_QUOTED: <QUOTE_SINGLE> (<STR_SINGLE_BODY>)* <QUOTE_SINGLE>>
| <STR_EMPTY: "\"\"" | "\'\'">
| <#IDENTIFIER_S: <LETTER> (["0"-"9"] | <LETTER>)*>
| <#IDENTIFIER_A: ("[" (["0"-"9"])+ "]")+>
| <IDENTIFIER: <IDENTIFIER_S> ("." <IDENTIFIER_S> | <IDENTIFIER_A>)*>
}

   

NON-TERMINALS

//-----------------------------------------------------------------------------

// .标识符
identifier ::= ( ( <IDENTIFIER> ) | ( <OCBREXT> <IDENTIFIER> <CCBR> ) )
// .带引号的字符串
stringValue ::= ( ( <STR_DOUBLE_QUOTED> ) | ( <STR_SINGLE_QUOTED> ) | ( <STR_EMPTY> ) )
// .空值
nullValue ::= <NULL>
// .布尔
booleanValue ::= ( <TRUE> )
| ( <FALSE> )
// .数字
numberValue ::= ( ( <DECIMAL_NUM> ) | ( <INTEGER_NUM> ) | ( <HEX_NUM> ) | ( <OCTAL_NUM> ) | ( <BINARY_NUM> ) )
// .列表:[ ... ]
list ::= ( ( <OBRA> <CBRA> ) | ( <OBRA> expression ( <COMMA> expression )* <CBRA> ) )
// .对象:
object ::= ( ( <OCBR> <CCBR> ) | ( <OCBR> stringValue ( <COLON> expression )? ( <COMMA> stringValue ( <COLON> expression )? )* <CCBR> ) )
//-----------------------------------------------------------------------------

// .表达式 =   表达式 or 表达式 + 运算符
expression ::= ( <OPAR> expression <CPAR> ( extExpression )? )
| ( unaryExpression )
| ( basicValue ( extExpression )? )
unaryExpression ::= ( <BANG> | <MINUS> ) basicValue
extExpression ::= ( ( dyadicExpression ) | ( ternaryExpression ) )
dyadicExpression ::= ( <PLUS> | <MINUS> | <STAR> | <SLASH> | <REM> | <ALI> | <GT> | <GE> | <LT> | <LE> | <EQ> | <NE> | <BIT_AND> | <BIT_OR> | <XOR> | <LSHIFT> | <RSIGNEDSHIFT> | <RUNSIGNEDSHIFT> | <SC_OR> | <SC_AND> ) expression
ternaryExpression ::= <QUEM> expression <COLON> expression
// .值
basicValue ::= ( ( primitiveValue ) | ( ( identifier ( funCall )? ) ) | ( list ) | ( object ) )
primitiveValue ::= ( stringValue )
| ( nullValue )
| ( booleanValue )
| ( numberValue )
//-----------------------------------------------------------------------------
// .函数参数
callerParamItem ::= ( ( lambdaDef ) | ( expression ) )
// .参数集:(xx , xx , xx)
callerParamSet ::= ( ( <OPAR> ( ( <CPAR> ) | ( callerParamItem ( <COMMA> callerParamItem )* <CPAR> ) ) ( "->" stringValue )? ) | ( "->" ( stringValue )? ) )
// .函数调用
funCall ::= callerParamSet ( ( "~" ) | ( list ) | ( object ) )
// .Lambda函数: lambda : (obj,obj2) -> {}
lambdaDef ::= <LAMBDA> ":" <OPAR> ( <IDENTIFIER> )? ( <COMMA> <IDENTIFIER> )* <CPAR> "->" ( ( <OCBR> blockSet <CCBR> ) | ( block ) )
//-----------------------------------------------------------------------------
// .函数
varBlock ::= <VAR> identifier <ASS> ( ( lambdaDef ) | ( expression ) )
// .反回
returnBlock ::= <RETURN> expression
// .判断
ifBlock ::= <IF> <OPAR> expression <CPAR> blockSet ( <ELSEIF> <OPAR> expression <CPAR> blockSet )* ( <ELSE> blockSet )? <END>
// .异常 or 中断
breakBlock ::= ( ( <EXIT> ) | ( <THROW> ) ) ( ( breakBlockStatus expression ) | ( expression ) )
breakBlockStatus ::= numberValue <COMMA>
// .选项指令
optionBlock ::= <OPTION> identifier <ASS> primitiveValue
// .指令
block ::= ( ( varBlock ) | ( ifBlock ) | ( returnBlock ) | ( breakBlock ) )
// .块
blockSet ::= ( block ( <SEMI> )? )*
// 入口
rootBlock ::= ( optionBlock ( <SEMI> )? )* blockSet <EOF>




© 2015 - 2025 Weber Informatics LLC | Privacy Policy