1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 | #### http://xlang.link ### calex gramar for xlang ####基础类#### #数字字符和数字字符串 [define] dig =[0~9] number=[$ dig ][$number,] #空格类的字符和字符串 blank=[\x01~\x20] space=[$blank][$space,] #可用英文字母 ch=[A~Z,a~z,_] equ=[=] #16进制字符串 hch=[A~F,a~f,$ dig ] hexc=[$hch][$hexc,] #可用英文字母和数字 char=[$ch,$ dig ] #命名字符串规则 postfix=([$char][$postfix,],) #命名规范-必须以英文字母开头 wd=[$ch][$postfix] ####元素类#### #关键字 strcont=(\\?,<\">?) charscont=(\\?,<\'>?) [meta] #关键字识别 k_space=($space) k_to=to<$char> k_import= import <$char> k_cdecl=cdecl<$char> k_stdcall=stdcall<$char> k_fastcall=fastcall<$char> k_pascal=pascal<$char> k_operator=operator<$char> k_for= for <$char> k_while= while <$char> k_do= do <$char> k_try=try<$char> k_catch=catch<$char> k_if= if <$char> k_break= break <$char> k_continue= continue <$char> k_default=default<$char> k_interface=interface<$char> k_class=class<$char> k_enum=enum<$char> k_package=package<$char> k_static=static<$char> k_const=const<$char> k_throws=throws<$char> k_throw=throw<$char> k_switch=switch<$char> k_case= case <$char> k_else= else <$char> k_return= return <$char> k_new=new<$char> k_include=include<$char> k_using=using<$char> k_require=require<$char> k_finally=finally<$char> k_final=final<$char> k_synchronized_read=synchronized_read<$char> k_synchronized_write=synchronized_write<$char> k_synchronized=synchronized<$char> k_declare=@Declare<$char> k_public=public<$char> k_private=private<$char> k_protected=protected<$char> k_override=override<$char> #十六进制数 hex=0x($hexc)[l,L,] #浮点数 三种形式 0.6f .6f 0.6 识别优先级高于long float=(($number[.]($number,)([e,E][+,-,]($number),)[f,F,]),([.]($number)([e,E][+,-,]($number),)[f,F,]),([.,]($number)([e,E][+,-,]($number))[f,F,]),([.,]($number)([e,E][+,-,]($number),)[f,F])) #长整数 识别优先级高于int longnum=($number)[l,L] #整数 intnum=($number) word=($wd) ####符号类#### colon=[\:] qm=[\?] #注释 comment=[/\**\*/, // *\n] #复合赋值运算 结合性:从右到左 compset_ops=[\>\>=,\<\<=,|=,^=,&=,%=,/=,\*=,-=,+=] #逻辑或运算 logicor_ops=[||] #逻辑与运算 logicand_ops=[&&] #位或运算 bitor_ops=[|] #位异或运算 bitxor_ops=[^] #位并运算 bitand_ops=[&] #等于运算 equals_ops=[==,!=] #位移运算 bitmov_ops=[\<\<] #比较运算 meq=[\>=] leq=[\<=] lc=[\<] rc=[\>] #注解符号 at=[@] #自操作运算 self_ops=[++,--] #一元运算 unary_ops=[!,\~] #加减运算 addsub_ops=[+,-] #乘除取余运算 muldivmod_ops=[\*,/,%] mov=[=] indete=[...] dot=[.] lb=[\(] rb=[\)] ll=[\{] lr=[\}] ls =[\[] rs=[\]] le =[;] comma=[\,] string= "({$strcont},)" chars= '({$charscont},)' [ignore] comment= true k_space= true [syntax] #############################数学运算############################# #复合赋值运算 自右向左 compset_symbol=[$compset_ops,$mov] compset_operation=($normal_object)($compset_symbol)($object) #三元运算 自右向左 binary_expression=($object)($qm)($object)($colon\e:24)($object) #逻辑或运算 logicor_symbol=[$logicor_ops] logicor_operator=($logicand_operation,$logicand_operator) logicor_operation=([$logicor_operation],$logicor_operator)($logicor_symbol)($logicor_operator) #逻辑与运算 logicand_symbol=[$logicand_ops] logicand_operator=($bitor_operation,$bitor_operator) logicand_operation=([$logicand_operation],$logicand_operator)($logicand_symbol)($logicand_operator) #位或运算 bitor_symbol=[$bitor_ops] bitor_operator=($bitxor_operation,$bitxor_operator) bitor_operation=([$bitor_operation],$bitor_operator)($bitor_symbol)($bitor_operator) #位异或运算 bitxor_symbol=[$bitxor_ops] bitxor_operator=($bitand_operation,$bitand_operator) bitxor_operation=([$bitxor_operation],$bitxor_operator)($bitxor_symbol)($bitxor_operator) #位与运算 bitand_symbol=[$bitand_ops] bitand_operator=($equals_operation,$equals_operator) bitand_operation=([$bitand_operation],$bitand_operator)($bitand_symbol)($bitand_operator) #等于运算 equals_symbol=[$equals_ops] equals_operator=($compare_operation,$compare_operator) equals_operation=([$equals_operation],$equals_operator)($equals_symbol)($equals_operator) #比较运算 compare_symbol=[$meq,$rc,$leq,$lc] compare_operator=($bitmov_operation,$bitmov_operator) compare_operation=([$compare_operation],$compare_operator)($compare_symbol)($compare_operator) #位移运算 由于和模板的>>冲突 于是这里改成两个rc bitmov_symbol=[$bitmov_ops,[$rc][$rc]] bitmov_operator=($addsub_operation,$addsub_operator) bitmov_operation=([$bitmov_operation],$bitmov_operator)($bitmov_symbol)($bitmov_operator) #加减法运算 addsub_symbol=[$addsub_ops] addsub_operator=($muldivmod_operation,$muldivmod_operator) addsub_operation=([$addsub_operation],$addsub_operator)($addsub_symbol)($addsub_operator) #乘除取余运算 muldivmod_symbol=[$muldivmod_ops] muldivmod_operator=($unary_operation,$unary_operator) muldivmod_operation=([$muldivmod_operation],$muldivmod_operator)($muldivmod_symbol)($muldivmod_operator) #一元运算 自右向左 unary_symbol=[$unary_ops,$self_ops,$addsub_ops] unary_operator=($normal_object) unary_operation=(($unary_symbol)([$unary_operation],$unary_operator),([$unary_operation],$unary_operator)($self_ops)) #############################语法定义############################# #算子 #顶级元素 常量 const_object=[$hex,$longnum,$intnum,$float,$string,$chars] word_exp=($word) meta_object=[($k_operator)($compset_symbol,$logicor_ops,$logicand_ops,$bitor_ops,$bitxor_ops,$bitand_ops,$equals_ops,$bitmov_symbol,$compare_symbol,$self_ops,$unary_ops,$addsub_ops,$muldivmod_ops,$dot,($ ls )($rs)),($word_exp)] #顶级元素 对象 #静态的取属性表达式 只能用于new 对象的时候使用 static_ownner=([$static_ownner],$template_object,$object_block,$word_exp,$const_object)[$dot]($meta_object) static_element=([$static_element],($static_ownner),$object_block,($word_exp))[$ ls \e:20]($object)[$rs\e:21] template_object=($static_ownner,$object_block,$word_exp)[$lc\e:22]($template_params)[$rc\e:23] new_expression=[$k_new]($template_object,$static_ownner,$object_block,$word_exp)($lb\e:2)($array,)($rb\e:4) array_type=($array_type,$template_object,$static_ownner,$object_block,$word_exp)[$ ls \e:20][$rs\e:21] new_array=([$new_array],$template_object,$static_ownner,$object_block,$word_exp)[$ ls \e:20]($object)[$rs\e:21] newarray_expression=[$k_new]($new_array) array_init_list=[$k_new]($array_type)($init_list) dynamic_ownner=([$dynamic_ownner],$array_init_list,$newarray_expression,$new_expression,$dynamic_element,$static_element,$call_expression,$temporary_class)[$dot]($meta_object) dynamic_element=([$dynamic_element],$call_expression,$dynamic_ownner)[$ ls \e:20]($object)[$rs\e:21] call_expression=($dynamic_ownner,$static_ownner,$meta_object)($lb\e:2)($array,)($rb\e:4) static_type=($array_type,$static_ownner,$template_object,$word_exp) #表达式定义 object_block=($lb\e:2)([$object_block],$array_type,$object)($rb\e:4) cast_object=($object_block)($normal_object) return_expression=($k_return)($object,) throw_expression=($k_throw)($object) # normal_expression=(($synchronized_expression,$if_expression,$fastfor_expression,$fastfor_step_expression,$for_expression,$while_expression,$dowhile_expression,$switch_expression,$exception_expression,$def_variable_state,$ function ),($class,$object,$k_break,$k_continue,$throw_expression,$return_expression)($ le \e:3)) #############################对象定义############################# #语法对象 ##############################集合 #这些是没有任何优先级的 normal_object=($cast_object,$init_list,$call_expression,$dynamic_element,$dynamic_ownner,$temporary_class,$array_init_list,$newarray_expression,$new_expression,$template_object,$static_element,$static_ownner,$object_block,$word_exp,$const_object) #数学运算表达式 这些是带有优先级的 math_object:=($compset_operation,$binary_expression,$logicor_operation,$logicand_operation,$bitor_operation,$bitxor_operation,$bitand_operation,$equals_operation,$compare_operation,$bitmov_operation,$addsub_operation,$muldivmod_operation,$unary_operation) #带括号的对象 object=($math_object,$normal_object) #############################函数运算############################# #调用函数 #参与数学和逻辑运算 # temporary_class=($new_expression)($ll\e:5)($class_body,)($lr\e:6) array=:([$array][$comma],)($object) template_params=([$template_params][$comma],)($static_type) init_list=($ll\e:5)($array)($lr\e:6) #############################特殊表达式############################# #special synchronized_expression=($k_synchronized,$k_synchronized_read,$k_synchronized_write)(($lb\e:2)($static_ownner,$word_exp)($rb\e:4))($ll\e:5)($statements,)($lr\e:6) if_expression=:($k_if)($lb\e:2)($object)($rb\e:4)($statement)(($k_else)($statement),) for_first_expression=[[$for_first_expression][$comma],]($variable_def,$object) for_last_expression=[[$for_last_expression][$comma],]($object) for_in_expression=$object #for表达式 for_expression=($k_for)($lb\e:2)($for_first_expression,)($ le \e:3)($for_in_expression,)($ le \e:3)($for_last_expression,)($rb\e:4)($statement) fastfor_expression=($k_for)($lb\e:2)(($static_type)($word_exp,))($colon\e:24)($object)($rb\e:4)($statement) fastfor_step_expression=($k_for)($lb\e:2)(($static_type)($word_exp,))($mov)($object)($k_to)($object)($rb\e:4)($statement) #while表达式 while_expression=($k_while)($lb\e:2)($object)($rb\e:4)($statement) #dowhile表达式 dowhile_expression=($k_do)($statement)($k_while)($lb\e:2)($object)($rb\e:4)($ le \e:3) #case表达式 case_expression=[$case_expression,](($k_case)($object),$k_default)($colon\e:24)($statements,) #switch表达式 switch_expression=($k_switch)($lb\e:2)($object)($rb\e:4)($ll\e:5)($case_expression)($lr\e:6) #try catch表达式 catch_body=[$catch_body,]($k_catch)($lb\e:2)($object)($word_exp)($rb\e:4)($ll\e:5)($statements,)($lr\e:6) exception_expression=($k_try)($ll\e:5)($statements,)($lr\e:6)($catch_body,)(($k_finally)($ll\e:5)($statements,)($lr\e:6),) #############################语法结构############################# statement=([$ll\e:5]($statements,)[$lr\e:6],$normal_expression) statements=[$statements,]($statement) variable_init=:[$variable_init($comma),]($word_exp)[($mov)($object),] throw_list=:[$throw_list($comma),]($static_type) throw_declare=($k_throws)($throw_list) enum_list=:[$enum_list($comma),]($word_exp\e:18)[($mov)($object),] #变量定义 variable_def=($k_static,)($k_const,)($static_type)($variable_init) def_variable_state=($variable_def)($ le \e:3) #参数定义 params_def=([$params_def][$comma],)($annotate,)($static_type)($word_exp,) #调用本地函数的参数类型 nativeparams_def=([$nativeparams_def][$comma],)((($word_exp)($muldivmod_ops,$bitand_ops,)($word_exp,)),$indete) #include语法 filearray=([$filearray][$comma],)($string) require=($k_require)($lb\e:2)($filearray)($rb\e:4) include=($k_include)($lb\e:2)($filearray)($rb\e:4) package_name=[[$package_name][$dot]($word_exp),($word_exp)] package_array=[[$package_array],]($package_name)[$ le ] using=[$k_using][$ll]($package_array)[$lr][$ le ] #函数定义 function =(($k_final)($k_static),($k_static)($k_final),$k_final,$k_static,$k_cdecl,$k_stdcall,$k_fastcall,$k_pascal,)($static_type)($word_exp)($lb\e:2)($params_def,)($rb\e:4)($k_override,)($throw_declare,)($ll\e:5)($statements,)($lr\e:6) function_ctor=($word_exp)($lb\e:2)($params_def,)($rb\e:4)($throw_declare,)($ll\e:5)($statements,)($lr\e:6) function_ctor_declare=($word_exp)($lb\e:2)($params_def,)($rb\e:4)($throw_declare,)($ le \e:3) operator=(($k_final)($k_static),($k_static)($k_final),$k_final,$k_static,)($static_type)($k_operator)($compset_symbol,$logicor_ops,$logicand_ops,$bitor_ops,$bitxor_ops,$bitand_ops,$equals_ops,$bitmov_symbol,$compare_symbol,$self_ops,$unary_ops,$addsub_ops,$muldivmod_ops,$dot,($ ls )($rs))($lb\e:2)($params_def,)($rb\e:4)($k_override,)($throw_declare,)($ll\e:5)($statements,)($lr\e:6) dispatch=($function_ctor,$function_ctor_declare,$ function ,$operator) baseclass=[$colon\e:24]($domainlimit,)([$lc\e:22]($template_params)[$rc\e:23],$static_type\e:15) baseenum=[$colon\e:24]($domainlimit,)($static_type) nativefunction_def=($static_type)($k_cdecl,$k_stdcall,$k_fastcall,$k_pascal,)($word_exp)($lb\e:2)($nativeparams_def,)($rb\e:4)($ le \e:3) native_import_body=:[$native_import_body,]($nativefunction_def,) native_import=($k_import)($string,)($ll\e:5)($native_import_body,)($lr\e:6)($ le \e:3) #类定义 domainlimit=($k_public,$k_protected,$k_private) class_body=:[$class_body,]($annotate,)($domainlimit,)($dispatch,$interface_dispatch,$native_import,$class,$enum,$interface,$def_variable_state) #包括模板类 class=(($k_final)($k_static),($k_static)($k_final),$k_final,$k_static,)($k_class)($word_exp)([$lc\e:22]($template_params)[$rc\e:23],)($baseclass,)($ll\e:5)($class_body,)($lr\e:6)($ le \e:3) enum=($k_final,)($k_enum)($word_exp)($baseenum,)($ll\e:5)($enum_list,)($lr\e:6)($ le \e:3) baseinterface=[$colon\e:24]($domainlimit,)($static_type) function_declare=(($k_final)($k_static),($k_static)($k_final),$k_final,$k_static,)($static_type)($word_exp)($lb\e:2)($params_def,)($rb\e:4)($throw_declare,)($ le \e:3) operator_declare=(($k_final)($k_static),($k_static)($k_final),$k_final,$k_static,)($static_type)($k_operator)($compset_symbol,$logicor_ops,$logicand_ops,$bitor_ops,$bitxor_ops,$bitand_ops,$equals_ops,$bitmov_symbol,$compare_symbol,$self_ops,$unary_ops,$addsub_ops,$muldivmod_ops,$dot,($ ls )($rs))($lb\e:2)($params_def,)($rb\e:4)($throw_declare,)($ le \e:3) interface_dispatch=($function_declare,$operator_declare,$interface) interface_body=:[$interface_body,]($annotate,)($interface_dispatch) interface=($k_interface)($word_exp)($baseinterface,)($ll\e:5)($interface_body,)($lr\e:6)($ le \e:3) package_body=[$package_body,]($annotate,)($domainlimit,)($package,$class,$enum,$interface) package=[$k_package]($word_exp)[$ll]($package_body,)[$lr][$ le ] declare =($k_declare)($package,$class,$enum,$interface) ### 注解符号 annotate_params=([$annotate_params][$comma],)($word_exp)([$mov]($word_exp,$const_object),) annotateitem=($at)($word_exp)((($lb\e:2)($annotate_params)($rb\e:4)),) annotate=([$annotate],)($annotateitem) #############################语言架构############################# global=:[$global,]($annotate,)($ declare ,$ function ,$using,$include,$require,$native_import,$package,$def_variable_state,$class,$enum,$interface,($object)($ le \e:3)) [scan] scan:=($global,) |