KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > websphinx > workbench > ScriptInterpreter


1 /*
2  * WebSphinx web-crawling toolkit
3  *
4  * Copyright (c) 1998-2002 Carnegie Mellon University. All rights
5  * reserved.
6  *
7  * Redistribution and use in source and binary forms, with or without
8  * modification, are permitted provided that the following conditions
9  * are met:
10  *
11  * 1. Redistributions of source code must retain the above copyright
12  * notice, this list of conditions and the following disclaimer.
13  *
14  * 2. Redistributions in binary form must reproduce the above copyright
15  * notice, this list of conditions and the following disclaimer in
16  * the documentation and/or other materials provided with the
17  * distribution.
18  *
19  * THIS SOFTWARE IS PROVIDED BY CARNEGIE MELLON UNIVERSITY ``AS IS'' AND
20  * ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
21  * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22  * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL CARNEGIE MELLON UNIVERSITY
23  * NOR ITS EMPLOYEES BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
24  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
25  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
26  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
27  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
28  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
29  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30  *
31  */

32
33 package websphinx.workbench;
34
35 public interface ScriptInterpreter {
36     /**
37      * Return name of language this interpreter handles.
38      * @return Language name, such as "Javascript" or "TCL"
39      */

40     public abstract String JavaDoc getLanguage ();
41
42     /**
43      * Evaluate an expression in the script language.
44      * @param expression Expression to evaluate
45      * @exception ScriptException if execution encounters an error
46      */

47     public abstract Object JavaDoc eval (String JavaDoc expression) throws ScriptException;
48
49     /**
50      * Construct a procedure or function.
51      * @param args Argument names
52      * @param body Function body
53      * @return Function object suitable for apply()
54      * @exception ScriptException if execution encounters an error
55      */

56     public abstract Object JavaDoc lambda (String JavaDoc[] args, String JavaDoc body) throws ScriptException;
57
58     /**
59      * Call a procedure or function.
60      * @param func Function object (previously returned by lambda()
61      * @param args Arguments for the function
62      * @exception ScriptException if execution encounters an error
63      */

64     public abstract Object JavaDoc apply (Object JavaDoc func, Object JavaDoc[] args) throws ScriptException;
65
66     /**
67      * Set a variable in the interpreter's global namespace
68      * @param name Name of variable
69      * @param object New value for variable
70      */

71     public abstract void set (String JavaDoc name, Object JavaDoc object);
72
73     /**
74      * Get a variable defined in the interpreter's global
75      * namespace
76      * @param name Name of variable to get
77      * @return Value of variable, or null if not defined
78      */

79     public abstract Object JavaDoc get (String JavaDoc name);
80 }
81
Popular Tags