Euphoria-operators
幸福感-オペレーター
Euphoriaは、変数を操作するための豊富な演算子セットを提供します。 私たちはすべてのEuphoria演算子を次のグループに分けることができます-
- 算術演算子
- 関係演算子
- 論理演算子
- 割り当て演算子
- その他の演算子
算術演算子
算術演算子は、代数で使用されるのと同じ方法で数式で使用されます。 次の表に算術演算子を示します。 整数変数Aが10を保持し、変数Bが20を保持すると仮定します-
リンク:/euphoria/euphoria_arithmatic_operators [例を表示]
Operator | Description | Example |
---|---|---|
+ | Addition - Adds values on either side of the operator | A + B will give 30 |
- | Subtraction - Subtracts right hand operand from left hand operand | A - B will give -10 |
* | Multiplication - Multiplies values on either side of the operator | A* B will give 200 |
/ | Division - Divides left hand operand by right hand operand | B/A will give 2 |
+ | Unary plus - This has no impact on the variable value. | +B gives 20 |
- | Unary minus - This creates a negative value of the given variable. | -B gives -20 |
関係演算子
Euphoria言語でサポートされている関係演算子は次のとおりです。 変数Aが10を保持し、変数Bが20を保持すると仮定します-
リンク:/euphoria/euphoria_relational_operators [例を表示]
Operator | Description | Example |
---|---|---|
= | Checks if the value of two operands are equal or not, if yes then condition becomes true. | (A = B) is not true. |
!= | Checks if the value of two operands are equal or not, if values are not equal then condition becomes true. | (A != B) is true. |
> | Checks if the value of left operand is greater than the value of right operand, if yes then condition becomes true. | (A > B) is not true. |
< | Checks if the value of left operand is less than the value of right operand, if yes then condition becomes true. | (A < B) is true. |
>= | Checks if the value of left operand is greater than or equal to the value of right operand, if yes then condition becomes true. | (A >= B) is not true. |
⇐ | Checks if the value of left operand is less than or equal to the value of right operand, if yes then condition becomes true. | (A ⇐ B) is true. |
論理演算子
次の表に、論理演算子を示します。 ブール変数Aが1を保持し、変数Bが0を保持すると仮定します-
リンク:/euphoria/euphoria_logical_operators [例を表示]
Operator | Description | Example |
---|---|---|
and | Called Logical AND operator. If both the operands are non zero then then condition becomes true. | (A and B) is false. |
or | Called Logical OR Operator. If any of the two operands are non zero then then condition becomes true. | (A or B) is true. |
xor | Called Logical XOR Operator. Condition is true if one of them is true, if both operands are true or false then condition becomes false. | (A xor B) is true. |
not | Called Logical NOT Operator which negates the result. Using this operator, true becomes false and false becomes true | not(B) is true. |
これらの演算子を1または0以外の数値に適用することもできます。 規則は次のとおりです。ゼロはfalseを意味し、ゼロ以外は_true_を意味します。
割り当て演算子
Euphoria言語でサポートされている次の代入演算子があります-
リンク:/euphoria/euphoria_assignment_operators [例を表示]
Operator | Description | Example |
---|---|---|
= | Simple assignment operator, Assigns values from right side operands to left side operand | C = A + B will assigne value of A + B into C |
+= | Add AND assignment operator, It adds right operand to the left operand and assign the result to left operand | C += A is equivalent to C = C + A |
-= | Subtract AND assignment operator, It subtracts right operand from the left operand and assign the result to left operand | C -= A is equivalent to C = C - A |
*= | Multiply AND assignment operator, It multiplies right operand with the left operand and assign the result to left operand | C *= A is equivalent to C = C * A |
/= | Divide AND assignment operator, It divides left operand with the right operand and assign the result to left operand | C/= A is equivalent to C = C/A |
&= | Concatenation operator | C &= {2} is same as C = {C} & {2} |
注-割り当てステートメントで使用される等号記号「=」は演算子ではなく、構文の一部にすぎません。
その他の演算子
Euphoria Languageでサポートされている他の演算子はほとんどありません。
オペレーター
2つのオブジェクトは、「&」演算子を使用して連結できます。 結果は、連結されたオブジェクトの長さの合計に等しい長さのシーケンスです。
たとえば-
#!/home/euphoria-4.0b2/bin/eui
sequence a, b, c
a = {1, 2, 3}
b = {4}
c = {1, 2, 3} & {4}
printf(1, "Value of c[1] %d\n", c[1] )
printf(1, "Value of c[2] %d\n", c[2] )
printf(1, "Value of c[3] %d\n", c[3] )
printf(1, "Value of c[4] %d\n", c[4] )
これは、次の結果を生成します-
Value of c[1] 1
Value of c[2] 2
Value of c[3] 3
Value of c[4] 4
幸福度演算子の優先順位
演算子の優先順位は、式内の用語のグループ化を決定します。 これは、式の評価方法に影響します。 特定の演算子は、他の演算子よりも優先順位が高くなっています。たとえば、乗算演算子は加算演算子よりも優先順位が高くなります。
たとえば、x = 7 + 3 * 2
ここでは、演算子*の優先順位が+より高いため、xには20ではなく13が割り当てられます。
したがって、最初に3 * 2で始まり、7に追加されます。
ここでは、優先順位が最も高い演算子がテーブルの上部に表示され、最も低い演算子が下部に表示されます。 式内では、優先順位の高い演算子が最初に評価されます。
Category | Operator | Associativity |
---|---|---|
Postfix | function/type calls | |
Unary | + - ! not | Right to left |
Multiplicative | */ | Left to right |
Additive | + - | Left to right |
Concatenation | & | Left to right |
Relational | > >= < ⇐ | Left to right |
Equality | = != | Left to right |
Logical AND | and | Left to right |
Logical OR | or | Left to right |
Logical XOR | xor | Left to right |
Comma | , | Left to right |