summaryrefslogtreecommitdiff
path: root/parex/evaltest.c
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--parex/evaltest.c50
1 files changed, 50 insertions, 0 deletions
diff --git a/parex/evaltest.c b/parex/evaltest.c
new file mode 100644
index 0000000..7e8641e
--- /dev/null
+++ b/parex/evaltest.c
@@ -0,0 +1,50 @@
1/*
2 * EVALTEST.C - part of the EGG system.
3 *
4 * Test program for the expression evaluator.
5 *
6 * By Shawn Hargreaves.
7 */
8
9
10#define USE_CONSOLE
11
12
13#include <stdlib.h>
14#include <stdio.h>
15#include <time.h>
16
17#include "egg.h"
18
19
20
21int main()
22{
23 char buf[256];
24 double result;
25 int error;
26
27 srand(time(NULL));
28
29 printf("\nTest program for the EGG expression evaluator module.\n\nEnter a formula, or a blank line to quit.\n\n\n");
30
31 for (;;) {
32 printf("> ");
33 fflush(stdout);
34
35 if (!fgets(buf, sizeof(buf), stdin) || (!buf[0]))
36 break;
37
38 result = evaluate(buf, &error, NULL);
39
40 if (error)
41 printf("\nError in expression!\n\n\n");
42 else
43 printf("\nevaluate(\"%s\") = %f\n\n\n", buf, result);
44 }
45
46 printf("\n\n");
47
48 return 0;
49}
50