The basic elements that make up the Rice program.

Let's learn about comments, import commands, and class definitions that make up the Rice program.

These three elements are the largest components of Rice. The Rice script is written by repeating these elements.


Table of contents:


Sample code

Comment

Import command

Class definition

Sample code

We will show the sample code.

1:

/*--------------------------------------------------------------------

2:

sample code

3:

This is a multi-line comment.

4:

----------------------------------------------------------------------*/

5:

// This is a single-line comment.

6:

/**Named**----------------------------- This is a named comment.

7:

It is a body of named comment.

8:

----------------------------------------------------------------------*/

9:

import "external.88"

10:

11:

class main

12:

open method void start()

13:

endmethod

14:

open method void end()

15:

endmethod

16:

endclass

The sample code is composed with comment, import command, and class definition.


1 to 8th lines are comments.

9th line is an import command.

11th line or later are the class definition.


Rice program will be made up repeating them.

Moreover, comments are ignored at the runtime. Import commands expand external files before the runtime. If there is an import command in the source that was expanded, the import command expand the file further.

As a result, only class definitions will remain at the runtime of the program.

Please note that only comments and import commands can exist outside of the class definition. Both do not have a direct impact at the runtime.

Elements, like the global variable, outside of the class definition that have a direct impact at the runtime do not exist in the Rice language.

Comment

Comments are the inserted annotation in source code. They can be used anywhere in the Rice source code and are ignored at run time.


There are three comment style.

Multi-line comment

Single-line comment

Named comment

Multi-line comment

1:

/*--------------------------------------------------------------------

2:

sample code

3:

This is a multi-line comment.

4:

----------------------------------------------------------------------*/

1 to 4th line of the sample code is an example of the multi-line comment.

Text between /* and */ is ignored at run time. You can comment on multiple lines because you can also use a new line character in the comment.

Single-line comment

5:

// This is a single-line comment.

5th line of the sample code is an example of the single-line comment.

Text between // and the end of the line is ignored at run time.

Named comment

6:

/**Named**----------------------------- This is a named comment.

7:

It is a body of named comment.

8:

----------------------------------------------------------------------*/

6 to 7th line of the sample code is an example of the named comment.

Text between /** and */ is ignored at run time. You can comment on multiple lines because you can also use a new line character in the comment.

Named comment allows you to programmatically refer to the content of the comment.

Import command

Import command is a feature to describe by dividing the source files.

Import command will expand a specified source file to the position of the import command. If there is an import command in the expanded source file, it repeat the same process.

A string that is followed to the "import" keyword specifies the path to the file that you want to expand.

Import commands can be used freely at the outside of class definition.


There are three way to specify the path in the import command.

Absolute path specification.

Relative path specification.

Expanded relative path specification.

9:

import "external.88"

9th line in the sample code is an example of import command.

The external.88 is specified by the relative path specification. The contents of external.88 are expanded at this location.

Absolute path specification

Absolute path specification is a method to specify a path from the top hierarchy of the file system.

This is standard method to specify a path in the Windows. Description will be omitted.

Relative path specification

Relative path specification is a method to specify a path from the current directory.

This is standard method to specify a path in the Windows. Description will be omitted.

Expanded relative path specification

Expanded relative path specification is a method to specify a path from the current source file.

In the expanded relative path specification, the @ is a symbol for the specification.


"@\external.88"

"@@\somewhere\external.88"


Single @ represents a directory which the current source file has been put.

@@ represents a parent directory of the directory which the current source file has been put.

You can repeat the @@. For example, "@@\@@\..." represents a parent directory of a parent directory.


Usage of The @ is the same as the dot . A reference position is just different.

Expanded relative path specification is a special notation for import commends. It cannot be used to specify a path other than import commands.

Class definition

Class definition is a set of member definitions that is described between the "class" and the "endclass" keyword. It decides statuses and behaviours of the class.

11:

class main

12:

open method void start()

13:

endmethod

14:

open method void end()

15:

endmethod

16:

endclass

11 to 16th line of the sample code is an example of the class definition.

Format

Class definition is:


class class-name

Member definitions

endclass


Class definition begins with the "class" keyword, a name of the class is specified, ends with the "endclass" keyword after member definitions.

Copyright © Rice All rights reserved.