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.lang.String pnuts_version
           
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 parsed tree with the specified Visitor and Context
static java.lang.Object eval(java.lang.String str)
          Deprecated. Replaced by eval(String, Context)
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()
          Get the depth of evaluation.
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()
           
static java.lang.ClassLoader getClassLoader(Context context)
          get ClassLoader for class access
static Visitor getDefaultVisitor()
           
static boolean isJava2()
           
static boolean isVerbose()
           
static java.lang.Object load(java.io.InputStream in)
          Deprecated. Replaced by load(InputStream, Context)
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)
          Deprecated. Replaced by load(Reader, Context)
static java.lang.Object load(java.io.Reader reader, boolean interactive)
          Deprecated. Replaced by load(Reader, boolean, Context)
static java.lang.Object load(java.io.Reader reader, boolean interactive, Context context)
          This method loads a script
static java.lang.Object load(java.io.Reader reader, Context context)
          This method loads a script
static java.lang.Object load(java.lang.String file)
          Deprecated. Replaced by load(String, Context)
static java.lang.Object load(java.lang.String name, Context context)
          load a script "file" in "context"
static java.lang.Object load(java.net.URL url, Context context)
           
static java.lang.Class loadClass(java.lang.String name)
          Deprecated.  
static java.lang.Class loadClass(java.lang.String name, Context context)
          Loads the class with the specified name.
static java.lang.Object loadFile(java.lang.String file)
          Deprecated. Replaced by loadFile(String, Context)
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)
          Deprecated.  
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, Context context)
          load a script "file" only when the script has not been read.
 java.lang.Object run()
          Deprecated. Replaced by run(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)
           
static void setClassLoader(java.lang.ClassLoader loader, Context context)
          set ClassLoader for class access
static void setLoadPath(java.lang.Object[] paths)
          Deprecated.  
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

pnuts_version

public static final java.lang.String pnuts_version

prompt

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

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()

getDefaultVisitor

public static Visitor getDefaultVisitor()

registerQuantityFactory

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

setClassLoader

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

setClassLoader

public static void setClassLoader(java.lang.ClassLoader loader)

getClassLoader

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

getClassLoader

public static java.lang.ClassLoader getClassLoader()

loadClass

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


loadClass

public static final java.lang.Class loadClass(java.lang.String name,
                                              Context context)
                                       throws java.lang.ClassNotFoundException
Loads the class with the specified name.
Parameters:
name - the class name to be loaded
context - the context in which the class is loaded
Returns:
the loaded class.

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()
Returns:
the current verbose mode

setLoadPath

public static void setLoadPath(java.lang.Object[] paths)
Deprecated.  

set a search path for scripts as an object array Elements of the array should one of the followings.

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)
Returns:
the value of a global variable "str"

get

public static java.lang.Object get(java.lang.String str,
                                   java.lang.String pkg)
Returns:
the value of a variable "str" in the package "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)
Deprecated. Replaced by eval(String, Context)

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
Deprecated. Replaced by loadFile(String, Context)

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
Deprecated. Replaced by load(String, Context)

load a script "file"

load

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

load

public static java.lang.Object load(java.net.URL url,
                                    Context context)

load

public static java.lang.Object load(java.io.InputStream in)
Deprecated. Replaced by load(InputStream, Context)

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)
Deprecated. Replaced by load(Reader, Context)

This method loads a script
Parameters:
reader - the Reader from which the script is loaded

load

public static java.lang.Object load(java.io.Reader reader,
                                    Context context)
This method loads a script
Parameters:
reader - the Reader from which the script is loaded
context - the context in which the script is loaded
Returns:
the result of the last expression

load

public static java.lang.Object load(java.io.Reader reader,
                                    boolean interactive)
Deprecated. Replaced by load(Reader, boolean, Context)

This method loads a script
Parameters:
reader - the Reader from which the script is loaded
interactive - specifies if the execution is in interactive mode.
Returns:
the result of the last expression

load

public static java.lang.Object load(java.io.Reader reader,
                                    boolean interactive,
                                    Context context)
This method loads a script
Parameters:
reader - the Reader from which the script is loaded
interactive - specifies if the execution is in interactive mode.
context - the context in which the script is loaded
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,
                           Context context)
                    throws java.io.FileNotFoundException
load a script "file" only when the script has not been read.

run

public java.lang.Object run()
Deprecated. Replaced by run(Context)

executes a Pnuts object with a new Context
Returns:
the result

run

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

accept

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

evalDepth

public static int evalDepth()
Get the depth of evaluation. This value increases when load(), loadFile(), or eval() is called.

main

public static void main(java.lang.String[] args)
                 throws java.lang.Throwable
Deprecated.