仓颉关键字
关键字 | 关键字 | 关键字 |
---|---|---|
as | abstract | break |
Bool | case | catch |
class | const | continue |
Rune | do | else |
enum | extend | for |
func | false | finally |
foreign | Float16 | Float32 |
Float64 | if | in |
is | init | import |
interface | Int8 | Int16 |
Int32 | Int64 | IntNative |
let | mut | main |
macro | match | Nothing |
open | operator | override |
prop | public | package |
private | protected | quote |
redef | return | spawn |
super | static | struct |
synchronized | try | this |
true | type | throw |
This | unsafe | Unit |
UInt8 | UInt16 | UInt32 |
UInt64 | UIntNative | var |
VArray | where | while |
仓颉操作符
下表列出了仓颉支持的所有操作符的优先级及结合性,其中优先级一栏数值越小,对应操作符的优先级越高。
操作符 | 优先级 | 含义 | 示例 | 结合方向 |
---|---|---|---|---|
@ | 0 | 宏调用 | @id | 右结合 |
. | 1 | 成员访问 | expr.id | 左结合 |
[] | 1 | 索引 | expr[expr] | 左结合 |
() | 1 | 函数调用 | expr(expr) | 左结合 |
++ | 2 | 自增 | var++ | 无 |
– | 2 | 自减 | var– | 无 |
? | 2 | 问号 | expr?.id, expr?[expr], expr?(expr), expr?{expr} | 无 |
! | 3 | 按位求反、逻辑非 | !expr | 右结合 |
- | 3 | 一元负号 | -expr | 右结合 |
** | 4 | 幂运算 | expr ** expr | 右结合 |
*, / | 5 | 乘法,除法 | expr * expr, expr / expr | 左结合 |
% | 5 | 取模 | expr % expr | 左结合 |
+, - | 6 | 加法,减法 | expr + expr, expr - expr | 左结合 |
<< | 7 | 按位左移 | expr << expr | 左结合 |
>> | 7 | 按位右移 | expr >> expr | 左结合 |
.. | 8 | 区间操作符 | expr..expr | 无 |
..= | 8 | 含步长的区间操作符 | expr..=expr | 无 |
< | 9 | 小于 | expr < expr | 无 |
<= | 9 | 小于等于 | expr <= expr | 无 |
> | 9 | 大于 | expr > expr | 无 |
>= | 9 | 大于等于 | expr >= expr | 无 |
is | 9 | 类型检查 | expr is Type | 无 |
as | 9 | 类型转换 | expr as Type | 无 |
== | 10 | 判等 | expr == expr | 无 |
!= | 10 | 判不等 | expr != expr | 无 |
& | 11 | 按位与 | expr & expr | 左结合 |
^ | 12 | 按位异或 | expr ^ expr | 左结合 |
| | 13 | 按位或 | expr | expr | 左结合 |
&& | 14 | 逻辑与 | expr && expr | 左结合 |
| | 15 | 逻辑或 | expr | expr | 左结合 |
?? | 16 | coalescing 操作符 | expr ?? expr | 右结合 |
|> | 17 | pipeline 操作符 | id |> expr | 左结合 |
~> | 17 | composition 操作符 | expr ~> expr | 左结合 |
= | 18 | 赋值 | id = expr | 无 |
**= | 18 | 复合运算符 | id **= expr | 无 |
*= | 18 | 复合运算符 | id *= expr | 无 |
/= | 18 | 复合运算符 | id /= expr | 无 |
%= | 18 | 复合运算符 | id %= expr | 无 |
+= | 18 | 复合运算符 | id += expr | 无 |
-= | 18 | 复合运算符 | id -= expr | 无 |
<<= | 18 | 复合运算符 | id <<= expr | 无 |
>>= | 18 | 复合运算符 | id >>= expr | 无 |
&= | 18 | 复合运算符 | id &= expr | 无 |
^= | 18 | 复合运算符 | id ^= expr | 无 |
|= | 18 | 复合运算符 | id |= expr | 无 |
&&= | 18 | 复合运算符 | id &&= expr | 无 |
|= | 18 | 复合运算符 | id |= expr | 无 |
仓颉操作符函数
下表列出了仓颉支持的所有操作符函数。
操作符函数 | 函数签名 | 示例 |
---|---|---|
[] (索引取值) | operator func [](index1: T1, index2: T2, …): R | this[index1, index2, …] |
[] (索引赋值) | operator func [](index1: T1, index2: T2, …, value!: TN): R | this[index1, index2, …] = value |
() | operator func ()(param1: T1, param2: T2, …): R | this(param1, param2, …) |
! | operator func !(): R | !this |
** | operator func **(other: T): R | this ** other |
* | operator func *(other: T): R | this * other |
/ | operator func /(other: T): R | this / other |
% | operator func %(other: T): R | this % other |
+ | operator func +(other: T): R | this + other |
- | operator func -(other: T): R | this - other |
<< | operator func <<(other: T): R | this << other |
>> | operator func >>(other: T): R | this >> other |
< | operator func <(other: T): R | this < other |
<= | operator func <=(other: T): R | this <= other |
> | operator func >(other: T): R | this > other |
>= | operator func >=(other: T): R | this >= other |
== | operator func ==(other: T): R | this == other |
!= | operator func !=(other: T): R | this != other |
& | operator func &(other: T): R | this & other |
^ | operator func ^(other: T): R | this ^ other |
| | operator func |(other: T): R | this | other |
仓颉TokenKind 类型
1 | public enum TokenKind <: ToString { |