Statements in the Rice

Statements

The statements are one of the things that make up the Rice code. Usually, it expresses some action to be carried out.

In the Rice, There are some single-statement and some compound-statement.

A single-statement is a statement to express some action to be carried out. It always ends with a semicolon.

A compound-statement is a statement to control the flow of execution. It will include other statements, and ends with an appropriate keyword.

Single-statements are:


declaration statement

definition sentence

assignment statement

compound assignment statement

call statement

increment statement

decrement statement

return statement

break statement

continue statement

throw statement


Compound-statements are:


if statement

while statement

fromto statement

keepon statement

each statement

try statement

declaration statement

A declaration statement introduces a variable name to the program, and binds class to the variable name.


class-name identifier ;

A class-name in a declaration statement is almost a simple class name.


int i;

string s;


However, collection classes can specify a class name to hold inside. Collection classes are list, dictionary, queue, and stack.


list{int} listInt;

stack{string} stackString;


A variable that is declared like above can not hold a element other than specified class.

A class that will be held can be nested any number.


list{dictionary{long}} ldl;

stack{queue{list{bool}}} sqlb;

definition statement

A definition statement carry out the declaration and initialization of a variable at the same time.


classname identifier = expression ;


The expression must return the address of the appropriate class instance.

You can define a numeric class with a large range by a numeric class with a small range.


real rr = 10L; // Define real with long.

real rrr = 10; // Define real with int.

long ll = 10; // Define long with int.


In this case, the class on the left side is newly generated based on the right side and defined.

assignment statement

An assignment statement is the assignment of the address that is returned by the expression to the lvalue.


lvalue = expression ;


If the lvalue ends with identifier or field name, the reference of the lvalue will be changed to the address that is returned by the expression.

If the lvalue ends with a setter name, an assignment statement is converted to a setter call, the expression will be an argument. Action of the setter depends on the implementation of the setter.

If the lvalue ends with the [] operator, change the address of the corresponding item in the list class instance referenced by the lvalue to the address returned by the expression.

The expression must return the address of the appropriate class instance.

An assignment of the Rice is not an expression but a statement. It does not return the address of the instance. Thus, it is impossible to repeat the assignment as in several languages.


int i;

int j;

int k;

i = j = k = 10; // Error!


You can assign a numeric class with a small range to a numeric class with a wide range.


real rr;

rr = 10L; // Assigns the long value to the real.

rr = 10; // Assigns the int value to the real.

long ll;

ll = 10; // Assigns the int value to the long.


In this case, a new instance of the lvalue class is created based on the instance returned by the expression, and it is assigned.

compound assignment statement

The compound assignment statement is an abbreviation that performs arithmetic operation and the assignment of the result at the same time.


lvalue *= expression ;

lvalue /= expression ;

lvalue %= expression ;

lvalue += expression ;

lvalue -= expression ;


Each is equivalent to the following assignment statement.


lvalue = left * right ;

lvalue = left / right ;

lvalue = left % right ;

lvalue = left + right ;

lvalue = left - right ;


Arithmetic operations follow the rules of individual operators, and assignment follows the rule of the assignment statement.

call statement

An expression that ends with a method call followed by a semicolon is a call statement.

If a call statement ends with a method call after the dot operator, it call a method of an instance that is returned by the left of the dot.

If there is not a dot operator in a call statement, it call a method of current instance.

increment statement

An expression that ends with a postfix ++ operator followed by a semicolon is a increment statement.

Increments the value of the left of the operator. The value must be int, long, real.

If the operand returns a proxy class, the entity of the proxy is used.


There is no increment statement by the prefix ++ operator.

decrement statement

An expression that ends with a postfix -- operator followed by a semicolon is a decrement statement.

Decrements the value of the left of the operator. The value must be int, long, real.

If the operand returns a proxy class, the entity of the proxy is used.


There is no decrement statement by the prefix -- operator.

return statement

The execution of the subroutine is stoped, and the control is returned to the invoker of the subroutine. If an expression follow after the return, the value of the expression is returned to the invoker as the return value of the subroutine. If there is not an expression after the return, an instance of the void class is returned to the invoker.


return ;

return expression ;


The return class must match the return class of the subroutine definition.

The above subroutine are the fitter, setter, getter, and method. The fitter and setter do not return a value. Thus, using return statement that have an expression at the fitter or setter will occur an error.

break statement

A break statement will move control to the next statement of the nearest loop statement that surround the break statement.


break ;

The above loop statement are the while, fromto, keepon, and each statement.

continue statement

A continue statement will move control to the first statement of the nearest loop statement that surround the continue statement.


continue ;

The above loop statement are the while, fromto, keepon, and each statement.

throw statement

The throw statement throws an instance of the error class to notify that an exception has occurred.

The control goes back in the call history until it finds the closest try statement that surrounds the throw statement.

When a try statement is found, if the try statement has a catch clause, control jumps to the first statement in the catch clause. If there is no catch clause, control jumps to the next of the try statement.

If the try statement is not found, the program ends.


throw ;

throw expression ;

If the throw statement notifies the exception from the catch clause of the try statement, the control goes back in the call history until it finds the try statement that surrounds the try statement.


If the throw statement has no expression, the ExceptionData getter of the thrown instance is an uninitialized proxy class instance.

If the throw statement has an expression, the ExceptionData getter of the thrown instance is a proxy class instance initialized with the expression.

If the expression of the throw statement is __error, __error is re-thrown.

if statement

A if statement is a statement to branch a flow of execution depending on conditions.


if(conditional expression)

statements

elseif(conditional expression)

statements

else

statements

endif


An expression in parentheses of the if clause or elseif clause is a conditional expression. If the conditional expression is true, the statements in its clause is executed. If the conditional expression is false, the same operation is repeated to the next elseif clause.

If the conditional expression returns a number, it evaluates to true if it is nonzero and false if it is zero.

If the conditional expression returns a proxy class, the entity of the proxy is used as the conditional expression.

The elseif clause is able to exist any number in the if statement. If all conditional expression are false and there is a else clause, the statements in the else clause is executed.

The if statement have to end with the endif.

It can use the abbreviation ei instead of endif.

A clause of the if statement generate a scope. Please refer to the manual about the scope.

while statement

A while statement is a statement to control a loop of execution depending on conditions.


while(conditional expression)

statements

endwhile


An expression in parentheses following to the while is a conditional expression. If the conditional expression is true, the control will move to the first statement in while statement. If the conditional expression is false, the control will move to the next of the endwhile.

If the conditional expression returns a number, it evaluates to true if it is nonzero and false if it is zero.

If the conditional expression returns a proxy class, the entity of the proxy is used as the conditional expression.

When the control reaches to the continue statement or endwhile, the control moves to the while, and repeats the execution from the evaluation of the condition expression.

When the control reaches to the break statement, the control moves to the next of the endwhile.

The while statement have to end with the endwhile.

It can use the abbreviation ew instead of endwhile.

A while statement generate a scope. Please refer to the manual about the scope.

If the control reaches to the first statement in the while statement, a while statement automatically defines the reserved variable __count and __index.

__count and __index are variables of int. They are initialized with the number of loops that starts from zero.

__count and __index do not cause the overflow like a normal int. If exceed the maximum value of the int, automatically back to zero.

fromto statement

A fromto statement is a statement to control a loop of execution depending on loop index.


fromto(expression,expression)

statements

endfromto


First expression is a start value of loop index. Scond expression is a end value of loop index.

Both expression have to return int, and these are determined at the beginning of fromto. The values are never changed while the loop.

If the expressions return a proxy class, the entity of the proxy is used as the value.

If the start and end values are equal, the loop is not executed and control will move to the next of endfromto.

If the start value is less than the end value. Loop index increments by 1 for each loop. If the loop index is equal the end value, the control will move to the next of endfromto.

If the start value is greater than the end value. Loop index decrements by 1 for each loop. If the loop index is equal the end value, the control will move to the next of endfromto.

When the control reaches to the continue statement or endfromto, the control moves to the fromto, and repeats the execution from the evaluation of the loop index.

When the control reaches to the break statement, the control moves to the next of the endfromto.

A fromto statement have to end with the endfromto.

It can use the abbreviation eft instead of endfromto.

A fromto statement generate a scope. Please refer to the manual about the scope.

If the control reaches to the first statement in the fromto statement, a fromto statement automatically defines the reserved variables __count and __index.

__count is a variable of int. It is initialized with the number of loops that starts from zero.

__index is a variable of int. It is initialized with the current loop index value.

__count does not cause the overflow like a normal int. If __count has exceeded the maximum value of the int, it will be automatically back to zero.

keepon statement

A keepon statement is a statement to control a loop with the number of times.


keepon(expression)

statements

endkeepon


The expression is the number of times of loop.

The expression have to return int, and it is determined at the beginning of keepon. The value is never changed while the loop.

If the expression returns a proxy class, the entity of the proxy is used as the number of times of loop.

If the number of times is zero or less, the loop is not executed and control will move to the next of the endkeepon.

If the number of times is 1 or more, the loop is executed the number of times. After the execution is finished, control will move to the next of the endkeepon.

When the control reaches to the continue statement or endkeepon, the control moves to the keepon, and repeats the execution.

When the control reaches to the break statement, the control moves to the next of the endkeepon.

A keepon statement have to end with the endkeepon.

It can use the abbreviation eko instead of endkeepon.

A keepon statement generate a scope. Please refer to the manual about the scope.

If the control reaches to the keepon, a keepon statement automatically defines the reserved variables __index and __count.

__index and __count are variables of int. It is initialized with the number of loops that starts from zero.

each statement

A each statement is a statement to control a loop of execution depending on elements of a collection.


each(expression)

statements

endeach


A expression is a specification of a collection, it have to return a list, dictionary, queue, or stack.

If the expression returns a proxy class, the entity of the proxy is used as the specification of a collection.

When the control reaches to the continue statement or endeach, the control moves to the each, and repeats the execution to next element of the collection.

When the control reaches to the break statement, the control moves to the next of the endeach.

An each statement have to end with the endeach.

It can use the abbreviation ee instead of endeach.

A each statement generate a scope. Please refer to the manual about the scope.

If the control reaches to the first statement in the each statement, a each statement automatically defines reserved variables __count and __index. Then, declares __key and __value.

__count and __index are variables of int. They are initialized with the number of loops that starts from zero.

__key is a variable of string. It is initialized with a key of the element if the collection is a dictionary. For other collections, it is an empty string.

__value is initialized with a element of the collection. Class of __value depends on class of the element.

__count and __index do not cause the overflow like a normal int. If exceed the maximum value of the int, automatically back to zero.

try statement

A try statement is a statement to branch a flow of execution depending on exception.


try

statements

catch

statements

endtry


If an exception has occurred in the try clause and a catch clause is exist, the control will move to the first statement in the catch clause. If a catch clause is not exist, the control will move to the next of the endtry.

If an exception did not occur in the try clause, a catch clause is skipped, and the control will move to the next of the endtry.

An try statement have to end with the endtry. The catch clause is optional.

It can use the abbreviation et instead of endtry.

A clause of the try statement generate a scope. Please refer to the manual about the scope.

If the control reaches to the first statement in the catch clause, a try statement automatically defines the reserved variable __error. __error is a variable of the error class.

Copyright © Rice All rights reserved.