tepal.c
1.19 KB
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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
#include <stdio.h>
#include <string.h>
#include <malloc.h>
#include <stdlib.h>
#include <stdarg.h>
#include <tepal_pars.h>
#include <expValue.h>
#include <ident.h>
#include <tepal.h>
char * tepalErrMsg[] =
{
"[ERROR] using uninitialized variable: %s\n",
"[ERROR] using array identifier without index: %s\n",
"[ERROR] unknown string operator: %c\n",
"[ERROR] unknown float operator: %c\n"
};
void
exitError (int errNum, ...)
{
va_list ap;
va_start (ap, errNum);
switch (errNum)
{
case ERR_UNDEF_VAR:
fprintf (stderr, tepalErrMsg[errNum], va_arg(ap, char *));
break;
case ERR_NO_INDEX:
fprintf (stderr, tepalErrMsg[errNum], va_arg(ap, char *));
break;
case ERR_STRING_OPERATOR:
fprintf (stderr, tepalErrMsg[errNum], va_arg(ap, int));
break;
case ERR_FLOAT_OPERATOR:
fprintf (stderr, tepalErrMsg[errNum], va_arg(ap, int));
break;
}
va_end (ap);
exit (errNum);
}
void
printExpr (s_expVal * val)
{
switch (expValueGetType (val))
{
case EXP_TYP_INT: printf ("%d", expValueInt (val)); break;
case EXP_TYP_FLOAT: printf ("%f", expValueFloat (val)); break;
case EXP_TYP_STRING:
{
char * v = expValueString (val);
printf (v);
free (v);
}
}
}