Home About Rice Downloads Documents Others Cooker CookerGX
Documents  >  Tutorial  >  basicelements
The basic elements that make up the Rice program.

Purpose of this chapter.

We will learn about the comment, the import command, and the class definition. Those are the basic elements that make up the Rice program.

The basic elements that make up the Rice program.

So, let's look at the inside of Sample.cook.


Sample.cook is composed of three big element. The elements are the comments, the import command, and the class definition.


6 line from the 1st line are comments.

7th line is an import command.

8th 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.


In other words, Rice program is a set of class definitions.

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.

Like the global variable, the elements 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 two comment style to the Rice.

Multi-line comment

Single-line comment

Multi-line comment

1:

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

2:

Sample.cook

3:

The entry point of this sample program.

4:

The main class has a responsibility to create the user interface and to allocate the event handler.

5:

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

The above code is a example of the multi-line comments. It is 5 lines from the 1st line of the Sample.cook.

Like above example, the multi-line comments in Rice programs start with /* and terminates with */.

Single-line comment

1:

// Import Circle class.

2:

import "@\Circle.88" // Circle.88 file is in a same directory that contains Sample.cook.

The above code is a example of the single-line comments. It is 2 lines from the 6th line of the Sample.cook.

Like above example, the single-line comments in Rice programs start with // and terminates with the end of the line.

import command

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

The import command will expand a source file that is specified at the position of the import command. If there is an import-command into the source file that is expanded, 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 is no limit to the position of the import command.


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

Absolute path specification.

Relative path specification.

Expanded relative path specification.


1:

import "@\Circle.88" // Circle.88 file is in a same directory that contains Sample.cook.

The above code is an example of import command. It is located at the 7th line of the Sample.cook.

In the above example, the Circle.88 has been expanded by the expanded relative path specification. As has been commented, the Circle.88 is located in the same directory as the Sample.cook.

Absolute path specification.

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

In the Windows file system, a drive letter is the top hierarchy, so it'll be as follows.


"C:\Users\YourName\Documents\Rice\souce\Circle.88"


Absolute path specification is standard method to specify the path in the Windows. Description of the details will be omitted.

Relative path specification.

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

In the Windows file system, the dot is a symbol for the relative path specification, so it'll be as follows.


".\Circle.88"

"..\source\Circle.88"


Relative path specification is standard method to specify the path in the Windows. Description of the details will be omitted.

In some situations, you may encounter a problem if you use a relative path specification in the import command.


Let us suppose that Cooker.exe is in the directory A, and Sample.cook is in the directory B.

If you run the Sample.cook from the Cooker after Starting Cooker.exe, the current directory will be A.

If Cooker and .cook files are associated, the Sample.cook can be executed by double-clicking. In this situation, the current directory will be B.


If relative path specification have been used in such situation, There will be a case that The Rice can not find the file.

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 described.

In the expanded relative path specification, the @ is a symbol for the specification, so it'll be as follows.


"@\Circle.88"

"@@\source\Circle.88"


Single @ represents a directory where has the source file that the import command is located.

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

You can repeat the double @. 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.

You can avoid the difference of the current directory by using the expanded relative path specification.

Please note that the expanded relative path specification cannot use in the class definition. This is a special notation for 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.

The format of the class definition.

Class definition is the following format.


class class-name

Member definitions

endclass


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

In some languages, the access level of the class can control by granting the keywords like the public or private.


In contrast, you cannot specify the access level of class in the Rice.

Classes of the Rice are always public. In other words, classes can be used in any location.

Since classes are always public, it is meaningless to specify the access level. Therefore, there is no specification of the access level of the class definition.

Keyword class.

Class definition begins with the class keyword.

"class" cannot used as an identifier because the keywords.

Class name.

Class name is the identifier that is used to identify the class of an instance that is created on the memory. it is required after the class keyword.

It is not possible to redefine the class with the same class name.

The naming rule of the class name is the same as the identifier.

Member definitions.

For member definitions will be described in the next chapter.

Keyword endclass.

Class definition ends with the endclass keyword.

"endclass" cannot used as an identifier because the keywords.

Next
Previous
Copyright © Rice All rights reserved.