* File: var.h          Project by: David Hodgdon *

 * Class: ECE476        Instructor: Bruce Land    *         

#ifndef VAR_H
#define VAR_H
#define MAXSTR 30
// pass in variable (with matching identifier), dimension of array, 

// and indices (all three required) and it will tell you if variable is a match

#define ARRAYIDENTCHECK(VAR, NUM, X, Y, Z) ( (NUM==3&&(VAR->i1==X && VAR->i2==Y && VAR->i3==Z)) || (NUM==2 && (VAR->i1==X && VAR->i2==Y)) || (NUM==1 && (VAR->i1==X)) || NUM==0 )
#define ARRAYIDENTSET(VAR, X, Y, Z) {\
enum VarType{Integer=0, Real=1, String=2, IntegerArray=4, RealArray=5, StringArray=6, InvalidType=8};

struct VarDesc{
	enum VarType type;
	char ident[3];		// variable name 

	char i1;		// array index 1

	char i2;		// array index 2

	char i3;		// array index 3

	char* str;		// string if string type

	unsigned char len;	// length if string type 

	int intVal;		// integer value

	float realVal;		// real value

	struct VarDesc* next;  	// pointer to next 

	struct VarDesc* prev;	// pointer to previous

	char isTemp;		// 1=temp, 0=variable

typedef struct VarDesc* Var;

void VarDestroyVar(Var v);
void VarInit();
Var VarNewVar(enum VarType type, char * ident, char i1, char i2, char i3, char isTemp);
Var VarGetVar(char* str, char num, char i1, char i2, char i3, Var head, Var tail, enum VarType varType);
void VarNewStr(Var v, unsigned char size);
void xfree(char * ptr);