On Mar 28, 2007, at 4:58 PM, James Maes wrote:
We are in the middle of looking at Jess for use in an in-house
embedded application. One of the things that I am trying to get
working is a way to integrate the jess .clp files that we are
creating into our build system. In particular we want to be able
to validate the syntax of a jess file without “running” it.
Well, that's a little tricky because Jess uses very late binding for
a lot of things; it's a functional language, after all, and most of
the knowledge of the arguments that functions can take is in the
functions themselves. In other words, Jess generally can't tell if a
function is being passed too many arguments without running the
function. Furthermore, the meaning of later code can depend on the
execution of earlier code -- i.e., a rule that uses a template
created by a call to defclass won't parse if the defclass is never
executed.
But the gross syntax -- especially that of special forms like rules
-- is indeed handled by the parser. The parser can parse expressions
without executing function calls: jess.Jesp has the method
public Object parseExpression(Context context, boolean
executeFuncalls) throws JessException;
and what you can do is basically call this in a loop after creating
your Jesp object, passing "false" for the second argument.
Eventually, it will return either the object jess.Funcall.EOF, or it
will throw an exception if there was a syntax error. It won't execute
any function calls it sees.
One problem with this technique is that it won't evaluate ANY
function calls, including defclass calls, nested batch calls, require
calls, and other things that. You could look at the objects returned
and execute them as appropriate in your loop, but that could be tricky.
The JessDE does something different. It also uses the Jess parser to
syntax check code in the editor. It can't ignore certain functions
that affect the outcome of a parse, but it must ignore calls to all
other functions. You don't want "exit" to get called inside Eclipse!
So what it does is create a Rete instance and substitute dummy
Userfunctions for most of the functions in the engine, leaving only
those that are necessary. For the JessDE, the necessary ones are:
defclass
batch
do-backward-chaining
import
load-function
load-package
require
require*
provide
set-current-module
All the other ones are replaced by a dummy function that just returns
a generic value.
Finally, have a look at the ArgumentChecker API of the Jesp class.
You can implement instances of the ArgumentChecker interface and
register them with a Jesp instance. Your ArgumentChecker will get a
chance to check the arguments passed to a named function at parse time.
---------------------------------------------------------
Ernest Friedman-Hill
Advanced Software Research Phone: (925) 294-2154
Sandia National Labs FAX: (925) 294-2234
PO Box 969, MS 9012 [EMAIL PROTECTED]
Livermore, CA 94550 http://www.jessrules.com
--------------------------------------------------------------------
To unsubscribe, send the words 'unsubscribe jess-users [EMAIL PROTECTED]'
in the BODY of a message to [EMAIL PROTECTED], NOT to the list
(use your own address!) List problems? Notify [EMAIL PROTECTED]
--------------------------------------------------------------------