summaryrefslogtreecommitdiff
path: root/parex/evaltest.c
diff options
context:
space:
mode:
authorMike Buland <eichlan@xagasoft.com>2007-02-17 16:31:55 +0000
committerMike Buland <eichlan@xagasoft.com>2007-02-17 16:31:55 +0000
commit89eeeff54f0b3ce30be5b046fc3899fdeb5ebb40 (patch)
treea4a8fc2e184df736f61c1dea1e8627dd3667b071 /parex/evaltest.c
parent27c626112a7114f9bdc4f7739f9ec05ae9fcbee1 (diff)
downloadlibbu++-89eeeff54f0b3ce30be5b046fc3899fdeb5ebb40.tar.gz
libbu++-89eeeff54f0b3ce30be5b046fc3899fdeb5ebb40.tar.bz2
libbu++-89eeeff54f0b3ce30be5b046fc3899fdeb5ebb40.tar.xz
libbu++-89eeeff54f0b3ce30be5b046fc3899fdeb5ebb40.zip
Tweaked the stream classes, added an example, and the begining of a formula
parser.
Diffstat (limited to 'parex/evaltest.c')
-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