From 5f3d78508f0cc7cbdc84ad1dc2bd27eded88436c Mon Sep 17 00:00:00 2001 From: lijie <1713699517@qq.com> Date: Fri, 13 May 2022 10:39:26 +0800 Subject: [PATCH] =?UTF-8?q?ft:=20=E8=BF=90=E7=AE=97=E7=AC=A6=E7=9B=B8?= =?UTF-8?q?=E6=97=A5=E5=BF=97=E6=8F=90=E4=BA=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- include/utComMisc.hrl | 4 ++ src/docs/erlang/erlang运算符.md | 74 ++++++++++++++++++++++++++++++ src/docs/erlang/etsmatch.hrl.md | 21 +++++++++ 3 files changed, 99 insertions(+) create mode 100644 src/docs/erlang/erlang运算符.md create mode 100644 src/docs/erlang/etsmatch.hrl.md diff --git a/include/utComMisc.hrl b/include/utComMisc.hrl index c390a77..d4c1e46 100644 --- a/include/utComMisc.hrl +++ b/include/utComMisc.hrl @@ -1,6 +1,10 @@ %% 三目元算符 -define(IIF(Cond, Then, That), case Cond of true -> Then; _ -> That end). +%% IF-DO表达式 +-define(IF(IFTure, DoThat), (IFTure) andalso DoThat). + + %%汉字unicode编码范围 0x4e00 - 0x9fa5 -define(UNICODE_CHINESE_BEGIN, (4 * 16 * 16 * 16 + 14 * 16 * 16)). -define(UNICODE_CHINESE_END, (9 * 16 * 16 * 16 + 15 * 16 * 16 + 10 * 16 + 5)). diff --git a/src/docs/erlang/erlang运算符.md b/src/docs/erlang/erlang运算符.md new file mode 100644 index 0000000..8eae461 --- /dev/null +++ b/src/docs/erlang/erlang运算符.md @@ -0,0 +1,74 @@ +# Erlang运算符: + + 1、算术运算符: +, -, *, /, div, rem, + + 1、"/", 用于除,但是其结果永远是浮点数, 即不管是否整除 + + 2、div, 除, 取结果的整数部分 + + 3、rem, 取模 + + 2、比较运算符: >, <, >=, =<, ==, =:=, /= , =/= + + 1、=<, 小于等于 + + 2、==, 比较两个值是否相等, eg: 1 == 1.0. 结果为: true + + 3、=:=, 比较两个值是否相等,并且两个对象的类型也必须相等, eg: 1 =:= 1.0. 结果为: false + + 4、/=, 不相等, eg: 1 /= 1.0. 结果为: false + + 5、=/=, 不全等, eg: 1 =/= 1.0,结果为: true + + 3、位运算符:band, bor, bnot, bxor, bsl, bsr + + 1、band, 位与 + + 2、bor, 位或 + + 3、bnot, 位非 + + 4、bxor, 按位异或 + + 5、bsl, 按位左移, eg: 1 bsl 5. %将1左移5位,结果为32 + + 6、bsr, 按位右移 + + 4、逻辑运算符:(运算符两边的表达式都会计算) + + 1、not, 逻辑非 + + 2、and, 逻辑与 + + 3、or, 逻辑或 + + 4、xor, 逻辑异或 + + 5、短路逻辑运算符:(如果前部分能得出结果,就不会计算另一个表达式) + + 1、andalso , X andalso Y, 如果X为true,则会执行Y,如果X为false,则不会计算Y,直接false + + 2、orelse, X orelse Y, 如果X为true,则结果为true,不会计算Y + + 6、运算符优先级: + +# 操作符 结合性 + 1. : + + 2. # + + 3. (一元)+, (一元)-, bnot, not + + 4. /, * , div, rem, band, and 左到右 + + 5. +, -, bor, bxor, bsl, bsr, or, xor + + 6. ++, -- + + 7. ==, /=, =<, <, >=, =:=, =/= 右到左, 即列表的操作,是将左边加到右边 + + 8. andalso + + 9. orelse + + 10. = 右到左 \ No newline at end of file diff --git a/src/docs/erlang/etsmatch.hrl.md b/src/docs/erlang/etsmatch.hrl.md new file mode 100644 index 0000000..57c0e34 --- /dev/null +++ b/src/docs/erlang/etsmatch.hrl.md @@ -0,0 +1,21 @@ +-type matchExpression() :: [ matchFunction(), ... ]. + +-type matchFunction() :: { matchHead(), matchConditions(), matchBody()}. + +-type matchHead() :: matchVariable() | '_' | { matchHeadPart(), ...}. + +-type matchHeadPart() :: term() | matchVariable() | '_'. + +-type matchVariable() :: '$'. + +-type matchConditions() :: [ matchCondition(), ...] | []. + +-type matchCondition() :: { guardFunction() } | { guardFunction(), conditionExpression(), ... }. +-type boolFunction() :: is_atom | is_float | is_integer | is_list | is_number | is_pid | is_port | is_reference | is_tuple | is_map | map_is_key | is_binary | is_function | is_record | 'and' | 'or' | 'not' | 'xor' | 'andalso' | 'orelse'. +-type conditionExpression() :: exprMatchVariable() | { guardFunction() } | { guardFunction(), conditionExpression(), ... } | termConstruct(). +-type exprMatchVariable() :: matchVariable() (bound in the MatchHead) | '$_' | '$$' +-type termConstruct():: {{}} | {{ conditionExpression(), ... }} | [] | [conditionExpression(), ...] | #{} | #{term() => conditionExpression(), ...} | nonCompositeTerm() | constant(). +-type nonCompositeTerm() :: term(). %% (not list or tuple or map) +-type constant() :: {const, term()}. +-type guardFunction() :: boolFunction() | abs | element | hd | length | map_get | map_size | node | round | size | bit_size | tl | trunc | '+' | '-' | '*' | 'div' | 'rem' | 'band' | 'bor' | 'bxor' | 'bnot' | 'bsl' | 'bsr' | '>' | '>=' | '<' | '=<' | '=:=' | '==' | '=/=' | '/=' | self. +-type matchBody() :: [ conditionExpression(), ... ]. \ No newline at end of file