summaryrefslogtreecommitdiff
path: root/parex/evaltest.c
blob: 7e8641e52548b7f6193da5640185d7882df60f51 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
/* 
 *  EVALTEST.C - part of the EGG system.
 *
 *  Test program for the expression evaluator.
 *
 *  By Shawn Hargreaves.
 */


#define USE_CONSOLE


#include <stdlib.h>
#include <stdio.h>
#include <time.h>

#include "egg.h"



int main()
{
   char buf[256];
   double result;
   int error;

   srand(time(NULL));

   printf("\nTest program for the EGG expression evaluator module.\n\nEnter a formula, or a blank line to quit.\n\n\n");

   for (;;) {
      printf("> ");
      fflush(stdout);

      if (!fgets(buf, sizeof(buf), stdin) || (!buf[0]))
	 break;

      result = evaluate(buf, &error, NULL);

      if (error)
	 printf("\nError in expression!\n\n\n");
      else 
	 printf("\nevaluate(\"%s\") = %f\n\n\n", buf, result);
   }

   printf("\n\n");

   return 0;
}