Expressions in the Rice

Expressions

The expression is an element that returns the address of the instance at the code. The combination of the expression and operator will constitute a new expression.

For example,

int i = 45;

The literal of the right side is an expression that returns the address of the int type instance with a value of 45.

int j = i + 55;

The arithmetic expression of the right side is an expression that returns the address of the int type instance with a value of 100. The arithmetic expression is made of the combining of an expression(variable reference), addition operator, and expression(literal).

Operators

Operators are a symbol to specify the operation.

List and priorities

Expression is processed along the operator precedence.

The following is the list of the expressions, and its priority.

1 | ||

() | x(y) | method call operator |

new | new int() | new operator |

this | this | this operator |

2 | ||

. | x.y | dot operator |

+ | +x | unary + operator |

- | -x | unary - operator |

! | !x | logical negation operator |

3 | ||

* | x * y | multiplication operator |

/ | x / y | division operator |

% | x % y | remainder operator |

4 | ||

+ | x + y | addition operator |

- | x - y | subtraction operator |

5 | ||

< | x < y | less than operator |

<= | x <= y | less than or equal operator |

> | x > y | greater than operator |

>= | x >= y | greater than or equal operator |

6 | ||

== | x == y | value equality operator |

!= | x != y | value inequality operator |

$$ | x $$ y | reference equality operator |

!$ | x !$ y | reference inequality operator |

7 | ||

& | x & y | logical AND operator |

8 | ||

| | x | y | logical OR operator |

The lower number is the high priority. Namely, it will be evaluated first.

Changing the evaluation order

Expression that enclosed by parentheses is evaluated with priority.

method call operator

The method call operator run the specified code with the method name and argument. The argument is zero or more expressions separated by commas in parentheses. It is passed to the method at the start of execution.

new operator

The new operator run the specified fitter with the class name and argument, and return an address of the new instance. The argument is zero or more expressions separated by commas in parentheses. It is passed to the fitter at the start of execution.

this operator

The this operator refers to the current instance of the class.

dot operator

The dot operator provide to member access of the instance returned by the expression of left side.

unary + operator

The unary + operator returns an address of the new instance that has an same value. The type of the instance that is returned by the right side expression must be the int, long, or real.

unary - operator

The unary - operator returns an address of the new instance that has an inverted sign. The type of the instance that is returned by the right side expression must be the int, long, or real.

logical negation operator

The logical negation operator returns an address of the new instance that has an inverted boolean value. The type of the instance that is returned by the right side expression must be the bool.

arithmetic operation

Binary operators "* /% + -" are called as the arithmetic operators. Type of both sides of the operators must be the int, long, or real.

Exceptionally, the implicit type conversion is carried out in arithmetic operations. Namely, the int, long, and real type will allow to mix in arithmetic operations.

A result of the operation depends on the type of operands. The result will be a real if there is a real in the operands. The result will be a long if there is not a real and there is a long. The other result will be the int.

multiplication operator

The multiplication operator returns an address of the new instance that has the multiplied value of the operand. When the result value is out of the range of result type, an exception will be thrown.

division operator

The division operator returns an address of the new instance that has the division value of the operand. When the result value is out of the range of result type, an exception will be thrown.

remainder operator

The remainder operator returns an address of the new instance that has the remainder value of the operand. When the result value is out of the range of result type, an exception will be thrown.

addition operator

The addition operator returns an address of the new instance that has the addition value of the operand. When the result value is out of the range of result type, an exception will be thrown.

subtraction operator

The subtraction operator returns an address of the new instance that has the subtraction value of the operand. When the result value is out of the range of result type, an exception will be thrown.

concatenation operator

When the type of both sides operand is the string, binary operators + is called as the concatenation operator. Concatenation operator returns the address of the new instance of string type that is the concatenation of operands.

relational operator

Binary operators "<,<=,>,>=" are called as the relational operators. The type of operands of the relationship operator must be the same. In addition, Those types must be the int, long, or real.(Changed in Ver 1.0.1.2) The operand type of the relational operator must be int, long or real. These can be mixed in relational operation. A result type of the operation is the bool.

less than operator

If the left side operand is less than the right side, the operator returns true. Otherwise returns false.

less than or equal operator

If the left side operand is less than or equal to the right side, the operator returns true. Otherwise returns false.

greater than operator

If the left side operand is greater than the right side, the operator returns true. Otherwise returns false.

greater than or equal operator

If the left side operand is greater than or equal to the right side, the operator returns true. Otherwise returns false.

value comparison operator

Binary operators "==,!=" are called as the value comparison operators. The type of operands of the value comparison operator must be the same. In addition, Those types must be the int, long, real, string, or real.(Changed in Ver 1.0.1.2) When the operand type of the value comparison operator is string or bool, the types of the left and right operands must be the same. When the operand type is int, long or real, they can be mixed in the value comparison operation. A result type of the operation is the bool.

value equality operator

If the value of left side operand is the same as right side, the operator returns true. Otherwise returns false.

value inequality operator

If the value of left side operand is different from right side, the operator returns true. Otherwise returns false.

reference comparison operator

Binary operators "$$,!$" are called as the reference comparison operators. There is no limit to the type of operands. A result type of the operation is the bool.

reference equality operator

If the left side operand refer the same instance as right side, the operator returns true. Otherwise returns false.

reference inequality operator

If the left side operand do not refer the same instance as right side, the operator returns true. Otherwise returns false.

logical operator

Binary operators "$$,!$" are called as the logical operators. The type of operands of the logical operator must be the bool. A result type of the operation is the bool.

logical AND operator

If the both operands are the true, the operator returns true. Otherwise returns false.

logical OR operator

If the either operand is the true, the operator returns true. Otherwise returns false.

Copyright © Rice All rights reserved.