Home About Rice Downloads Documents Others Cooker CookerGX
Documents  >  Development  >  ricemanager
Rice language front end.

RiceManager class

I will explain the RiceManager class which becomes the front end of Rice language.

In the following explanation, C# is assumed as the implementation language.

Constructor

First, you need get an instance of the RiceManager class (C#). The RiceManager class has several constructors, but usually it uses a constructor with the path to the Rice source file as its argument.

For example.

RiceManager manager = new RiceManager("c:\.....\example.cook");


The constructor parses the given source file and prepares before starting execution. Preparation before starting execution is the creation and storage of the prototype of the user defined class (Rice).

If the source file is correct as the Rice language grammar, the constructor returns an instance of the RiceManager class. If there is a grammatical problem in the source file, the constructor will throw an exception and exit.

The exception sent by Rice will be explained in a later chapter.


Errors occur frequently in program. Therefore, the constructor must be enclosed in a try-catch statement. Otherwise, error of Rice source causes the application itself to kill.

Executing the program

If the instance of the RiceManager class has be obtained without problems, you can run the Rice program.

The Rice program starts execution by calling the open method of the main class (Rice).


The RiceManager class has three member functions to call the open method of the main class.


public void Run()

public Rtype Invoke(string methodname, Queue<Rtype> argqueue)

public Rtype Invoke(string methodname, Queue<Rtype> argqueue, bool argCheck)

public void Run()

The "public void Run()" member function of the RiceManager class calls the "start()" method of Rice's main class.

The signature of "start()" is "open method void start()". In other words, the start() method takes no arguments and has no return value.

Therefore, the Run() member function also has no arguments and there is no return value.


Errors occur frequently in program. Therefore, the Run() must be enclosed in a try-catch statement. Otherwise, error of Rice source causes the application itself to kill.

public Rtype Invoke(string methodname, Queue<Rtype> argqueue)

The "public Rtype Invoke (string methodname, Queue <Rtype> argqueue)" member function of the RiceManager class calls any open method of Rice's main class.

For example, suppose that Rice's main class has a method called "open method int sample (string str, int index)". To call this sample() method from the application (C#), do as follows.


Queue<Rtype> args = new Queue<Rtype>();

args.Enqueue(new Rstring("example"));

args.Enqueue(new Rint(0));

Rint result = Invoke("sample(string,int)", args);


The first argument of the Invoke() member function specifies the signature of the open method to be called. A signature is a string that method name is followed by the type name of the argument enclosed in parentheses. If there are multiple arguments, those are separated with comma.

The second argument is arguments to pass to the method. It stores instances of the appropriate Rtype derived class in the Queue <Rtype> type in order of the signature arguments.

If there are no arguments, the parentheses are empty. For example, if you call the start() method with the Invoke() member function, the first argument is "start()". In this case, the second argument will pass an empty Queue<Rtype>. Please note that it is not null.

An instance of the Rtype derived class (C#) specified as a return type is returned as a result of the Invoke() member function. If the return value type of the Rice's method to be called is void, Rvoid type is returned.


This Invoke () member function does not consider whether a signature matches an argument or not. It is the programmer's responsibility to provide the correct arguments.


Errors occur frequently in program. Therefore, the Invoke() must be enclosed in a try-catch statement. Otherwise, error of Rice source causes the application itself to kill.

public Rtype Invoke(string methodname, Queue<Rtype> argqueue, bool argCheck)

The "public Rtype Invoke (string methodname, Queue <Rtype> argqueue, bool argCheck)" member function of the RiceManager class calls any open method of Rice's main class.

This member function is a member function with argument check added to "public Rtype Invoke (string methodname, Queue <Rtype> argqueue)". It checks whether the class and order of the second argument are the same as the signature.

Whether the check is executed or not is specified by the third argument of the member function. If the third argument is true, execute the check. If false, the check is not executed.


If the check is executed and the arguments do not match, an Exception type exception is thrown.


Errors occur frequently in program. Therefore, the Invoke() must be enclosed in a try-catch statement. Otherwise, error of Rice source causes the application itself to kill.

Example of use

An example of calling the Rice language in Cooker is shown below.

1:

public static RiceManager Run(string filename, string signature, Queue<Rtype> argqueue) {

2:

List<string> errorMessage = null;

3:

RiceManager rm = null;

4:

try {

5:

rm = new RiceManager(filename); //Create an instance of RiceManager from file name.

6:

rm.Invoke(signature, argqueue); //Execution of specified method.

7:

}

8:

catch(Exception e) {

9:

errorMessage = _makeErrorMessage(e); //Create error messages from an exception.

10:

}

11:

finally {

12:

if(errorMessage != null) {//If error messages exist, it is an error.

13:

MessageManager mm = new MessageManager(errorMessage);

14:

mm.ShowModal(); //Notify the error via dialog.

15:

rm = null; //On error, it returns null.

16:

}

17:

}

18:

return rm;

19:

}

In order to deal with exceptions thrown by RiceManager, the constructor and the Invoke() member function are enclosed in try-catch statements.

The _makeErrorMessage() member function in the catch section create messages to display in the dialog box from the exception.

Next
Previous
Copyright © Rice All rights reserved.