[Up] [Contents] [Index] [Summary]
The following is a very simple example going through all the steps
outlined above. It provides an arithmetic expression evaluator. We will
call the application calc and define it in the files calc.c
and calc.pl
. The Prolog file is simple:
calc(Atom) :-
term_to_atom(Expr, Atom),
A is Expr,
write(A),
nl.
The C-part of the application parses the command-line options,
initialises the Prolog engine, locates the calc/1 predicate and calls
it. The coder is in figure 10.
#include
#include
PL_extension PL_extensions [] =
{
/*{ "name", arity, function, PL_FA_ },*/
{ NULL, 0, NULL, 0 } /* terminating line */
};
#define MAXLINE 1024
int
main(int argc, char **argv, char **env)
{ char expression[MAXLINE];
char *e = expression;
char *program = argv[0];
char *plav[2];
int n;
/* combine all the arguments in a single string */
for(n=1; n
Figure 10 : C-source for the calc application
The application is now created using the following command-line:
% plld -o calc calc.c calc.pl
The following indicates the usage of the application:
% calc pi/2
1.5708