tepal.c 1.19 KB
#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);
			}
	}
}