Home News DOC Class DL Others Cooker
Documents  >  Tutorial  >  Basic elements
The basic elements that make up the Rice program.

Let's learn about the basic elements, 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

First, 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 of three big elements. They are 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 repeat these three elements.

Moreover, comments are ignored at the runtime. Import commands read external files before the runtime. If there is an import command into the file that was read, the import command read 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

The comment is the inserted annotation in source code. It is ignored at the runtime.

The comment can be used in any place of Rice source code. In other words, it can be used at the outside of the class definition and the inside of the class definition.


There are three comment style to the Rice.

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. Also, it must be written in a format that follows the rules.

Named comment will be explained in detail on a separate page.

Import command

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

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

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

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


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

Absolute path specification.

Relative path specification.

Expanded relative path specification.

9:

import "external.88"

9th line of 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 the position of the file from a top hierarchy of the file system.

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

Relative path specification

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

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

Expanded relative path specification

Expanded relative path specification is a method to specify the position of the file from a source file that the import command is located.

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


"@\external.88"

"@@\somewhere\external.88"


Single @ represents a parent directory of the source file that the import command is located.

@@ represents a parent directory of parent directory of the source file that the import command is located.

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


In other words, The @ of the extended relative path specification is the same as the dot of the relative path specification. A reference position of the path is just different.

Expanded relative path specification is a special notation for import instructions. It cannot be used to specify a path other than the import command.

Class definition

Class definition is a set of member definitions that is described between the "class" and the "endclass". It decide 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行目から16行目はクラス定義の例です。

Format

Class definition is the following format.


class class-name

Member definitions

endclass


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

Class definition will be explained in detail on a separate page.

Next
Previous
Copyright © Rice All rights reserved.