pnuts.lang
Class Pnuts

java.lang.Object
  |
  +--pnuts.lang.Pnuts

public class Pnuts
extends java.lang.Object
implements java.io.Serializable

"Manager" class for Pnuts interpreter.
"pnuts" command starts from main method of this class.
Annotated reference manual is here.

See Also:
Serialized Form

Field Summary
static java.applet.Applet applet
          If Pnuts starts in applet this variable should be set.
protected static Visitor interpreter
           
static java.lang.String prompt
          "prompt" string for the command shell
protected  SimpleNode startNodes
          parsed scripts
protected  java.lang.Object value
           
 
Constructor Summary
protected Pnuts()
           
protected Pnuts(java.io.Reader reader)
           
protected Pnuts(java.io.Reader reader, boolean interactive, Context context)
          Starts Pnuts interpreter.
 
Method Summary
 java.lang.Object accept(Visitor visitor, Context context)
          traverse the start nodes with the specified Visitor and Context
static java.lang.Object eval(java.lang.String str)
          evaluate "str" in the global package
static java.lang.Object eval(java.lang.String str, Context context)
          evaluate "str" in "context"
static java.lang.Object eval(java.lang.String str, java.lang.String pkg)
          evaluate "str" in package "pkg"
static int evalDepth()
          returns the depth of evaluations
static java.lang.String format(java.lang.Object obj)
          returns a formatted string for obj
static java.lang.Object get(java.lang.String str)
           
static java.lang.Object get(java.lang.String str, java.lang.String pkg)
           
static java.lang.ClassLoader getClassLoader()
          get ClassLoader for class access
static boolean isJava2()
           
static boolean isVerbose()
           
static java.lang.Object load(java.io.InputStream in)
          load a script from InputStream "in"
static java.lang.Object load(java.io.InputStream in, boolean interactive, Context context)
          Load a script from an InputStream in the specified Context.
static java.lang.Object load(java.io.InputStream in, Context context)
          load a script from InputStream "in" in "context"
static java.lang.Object load(java.io.Reader reader)
          load a script from Reader "reader"
static java.lang.Object load(java.io.Reader reader, boolean interactive)
           
static java.lang.Object load(java.io.Reader reader, boolean interactive, Context context)
          Load a script from an Reader in the specified Context.
static java.lang.Object load(java.io.Reader reader, Context context)
          load a script from Reader "reader" in context
static java.lang.Object load(java.lang.String file)
          load a script "file"
static java.lang.Object load(java.lang.String file, Context context)
          load a script "file" in "context"
static java.lang.Class loadClass(java.lang.String name)
           
static java.lang.Object loadFile(java.lang.String file)
          load a local script "file"
static java.lang.Object loadFile(java.lang.String file, Context context)
          load a local script "file" in "context"
static void main(java.lang.String[] args)
          starts the command shell interpreter
static Pnuts parse(java.io.InputStream in)
          parse a script from InputStream and return a Pnuts object
static Pnuts parse(java.io.Reader reader)
          parse a script from Reader and return a Pnuts object
static Pnuts parse(java.lang.String expr)
          parse a script and return a Pnuts object
static void registerQuantityFactory(java.lang.String unit, QuantityFactory factory)
           
static void require(java.lang.String file)
          load a script "file" only when the script has not been read.
 java.lang.Object run()
          executes a Pnuts object with a new Context
 java.lang.Object run(Context context)
          executes a Pnuts object with the specified Context
static void set(java.lang.String str, java.lang.Object val)
          set a value "val" to a global variable "str"
static void set(java.lang.String str, java.lang.Object val, java.lang.String pkg)
          set a value "val" to a variable "str" in package "pkg"
static void setClassLoader(java.lang.ClassLoader loader)
          set ClassLoader for class access
static void setLoadPath(java.lang.Object[] paths)
          set a search path for scripts as an object array Elements of the array should one of the followings.
static void setLoadPath(java.lang.String path)
          set a search path for scripts as a colon-separated String This method remains for compatibility reason.
static void setPrompt(java.lang.String str)
          set a "prompt" string for the command shell
static void setVerbose(boolean b)
          set verbose mode
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

applet

public static java.applet.Applet applet
If Pnuts starts in applet this variable should be set.

prompt

public static java.lang.String prompt
"prompt" string for the command shell

interpreter

protected static Visitor interpreter

startNodes

protected SimpleNode startNodes
parsed scripts

value

protected transient java.lang.Object value
Constructor Detail

Pnuts

protected Pnuts()

Pnuts

protected Pnuts(java.io.Reader reader)
         throws ParseException

Pnuts

protected Pnuts(java.io.Reader reader,
                boolean interactive,
                Context context)
Starts Pnuts interpreter. If interactive is true prompt message and the results of evaluation are printed on the screen.
Method Detail

isJava2

public static final boolean isJava2()

registerQuantityFactory

public static void registerQuantityFactory(java.lang.String unit,
                                           QuantityFactory factory)

setClassLoader

public static void setClassLoader(java.lang.ClassLoader loader)
set ClassLoader for class access
Parameters:
loader - the ClassLoader with which classes are accessed

getClassLoader

public static java.lang.ClassLoader getClassLoader()
get ClassLoader for class access

loadClass

public static final java.lang.Class loadClass(java.lang.String name)
                                       throws java.lang.ClassNotFoundException

setPrompt

public static void setPrompt(java.lang.String str)
set a "prompt" string for the command shell

setVerbose

public static void setVerbose(boolean b)
set verbose mode

isVerbose

public static boolean isVerbose()

setLoadPath

public static void setLoadPath(java.lang.Object[] paths)
set a search path for scripts as an object array Elements of the array should one of the followings. String: base name of resource URL: base name of URL File: base directory

setLoadPath

public static void setLoadPath(java.lang.String path)
set a search path for scripts as a colon-separated String This method remains for compatibility reason. It will be deleted in the future.

format

public static java.lang.String format(java.lang.Object obj)
returns a formatted string for obj

get

public static java.lang.Object get(java.lang.String str)

get

public static java.lang.Object get(java.lang.String str,
                                   java.lang.String pkg)

set

public static void set(java.lang.String str,
                       java.lang.Object val)
set a value "val" to a global variable "str"

set

public static void set(java.lang.String str,
                       java.lang.Object val,
                       java.lang.String pkg)
set a value "val" to a variable "str" in package "pkg"

eval

public static java.lang.Object eval(java.lang.String str,
                                    java.lang.String pkg)
evaluate "str" in package "pkg"

eval

public static java.lang.Object eval(java.lang.String str)
evaluate "str" in the global package

eval

public static java.lang.Object eval(java.lang.String str,
                                    Context context)
evaluate "str" in "context"

loadFile

public static java.lang.Object loadFile(java.lang.String file)
                                 throws java.io.FileNotFoundException
load a local script "file"

loadFile

public static java.lang.Object loadFile(java.lang.String file,
                                        Context context)
                                 throws java.io.FileNotFoundException
load a local script "file" in "context"

load

public static java.lang.Object load(java.lang.String file)
                             throws java.io.FileNotFoundException
load a script "file"

load

public static java.lang.Object load(java.lang.String file,
                                    Context context)
                             throws java.io.FileNotFoundException
load a script "file" in "context"

load

public static java.lang.Object load(java.io.InputStream in)
load a script from InputStream "in"

load

public static java.lang.Object load(java.io.InputStream in,
                                    Context context)
load a script from InputStream "in" in "context"

load

public static java.lang.Object load(java.io.InputStream in,
                                    boolean interactive,
                                    Context context)
Load a script from an InputStream in the specified Context.
Parameters:
in - an InputStream from which the interpreter reads an input
interactive -
  • When "interactive" is true, the greeting message, the prompt, and the results of evaluations are displayed. When an exception is thrown and not caught by any exception handler, it is caught at the top level of the interpreter, display an error message, and resume the interactive session. If the exception is caught by a handler that is registered at the top level, the result of the handler becomes the return value of the last expression.
  • When "interactive" is false, exceptions are caught at the top level of the interpreter and exits this function. If the exception thrown is caught by a handler that is registered at the top level, the result of the handler becomes the return value of this method.
context - a Context in which the interpretation is taken place.
Returns:
the result of the last expression

load

public static java.lang.Object load(java.io.Reader reader)
load a script from Reader "reader"

load

public static java.lang.Object load(java.io.Reader reader,
                                    Context context)
load a script from Reader "reader" in context

load

public static java.lang.Object load(java.io.Reader reader,
                                    boolean interactive)

load

public static java.lang.Object load(java.io.Reader reader,
                                    boolean interactive,
                                    Context context)
Load a script from an Reader in the specified Context.
Parameters:
reader - an Reader from which the interpreter reads an input
interactive -
  • When "interactive" is true, the greeting message, the prompt, and the results of evaluations are displayed. When an exception is thrown and not caught by any exception handler, it is caught at the top level of the interpreter, display an error message, and resume the interactive session. If the exception is caught by a handler that is registered at the top level, the result of the handler becomes the return value of the last expression.
  • When "interactive" is false, exceptions are caught at the top level of the interpreter and exits this function. If the exception thrown is caught by a handler that is registered at the top level, the result of the handler becomes the return value of this method.
context - a Context in which the interpretation is taken place.
Returns:
the result of the last expression

parse

public static Pnuts parse(java.io.InputStream in)
                   throws ParseException
parse a script from InputStream and return a Pnuts object
Parameters:
in - the InputStream
Returns:
the Pnuts object including a parsed syntax tree
Since:
Pnuts 1.0beta3

parse

public static Pnuts parse(java.io.Reader reader)
                   throws ParseException
parse a script from Reader and return a Pnuts object
Parameters:
reader - the Reader
Returns:
the Pnuts object including a parsed syntax tree
Since:
Pnuts 1.0beta3

parse

public static Pnuts parse(java.lang.String expr)
                   throws ParseException
parse a script and return a Pnuts object
Parameters:
expr - the script
Returns:
the Pnuts object including a parsed syntax tree
Since:
Pnuts 1.0beta3

require

public static void require(java.lang.String file)
                    throws java.io.FileNotFoundException
load a script "file" only when the script has not been read.

run

public java.lang.Object run()
executes a Pnuts object with a new Context
Since:
Pnuts 1.0beta3

run

public java.lang.Object run(Context context)
executes a Pnuts object with the specified Context
Parameters:
context - the Context
Since:
Pnuts 1.0beta3

accept

public java.lang.Object accept(Visitor visitor,
                               Context context)
traverse the start nodes with the specified Visitor and Context
Parameters:
context - the Context
Since:
Pnuts 1.0beta3

evalDepth

public static int evalDepth()
returns the depth of evaluations

main

public static void main(java.lang.String[] args)
                 throws java.lang.Throwable
starts the command shell interpreter