Project/app_code/variable.c
void add_lexicon(char name[],KindType k,float f,char *val)
{
	int count;
	int i,l;

	/*IF RUN OUT OF MEMORY,REALLOC*/
	if(Lexicon.count == number_of_token)
		reassign_mem();	
	
	//VAL IS NULL => USE IT AS FLOAT VARIABLE
	if(val == NULL)
	{
		count = Lexicon.count;
		count++;
		//IF NAME ALREADY THERE,JUST CHANGE ITS VALUE
		if(check_var(name)==1)
		{
			i = get_count(name);
			Lexicon.Entry[i].info.val=f;
			Lexicon.Entry[i].str=NULL;
		}
		//ELSE ADD A NEW VARIABLE
		else
		{
			i = count;
			strcpy(Lexicon.Entry[i].name,name);
			Lexicon.Entry[i].info.val = f;
			Lexicon.Entry[i].str = NULL;
			Lexicon.count += 1;
		}
	}
	//ELSE ITS A STRING VARIABLE
	else
	{
		count = Lexicon.count;
		count++;
		if(check_var(name)==1)
		{
			i = get_count(name);
			//free(Lexicon.Entry[i].str);
			l = strlen(val);
			
			Lexicon.Entry[i].str = calloc(l+1,sizeof(char));
			
			strcpy(Lexicon.Entry[i].str,val);
		}

		else
		{
			i = count;
			strcpy(Lexicon.Entry[i].name,name);
			Lexicon.Entry[i].kind = k;
			
			l = strlen(val);
			Lexicon.Entry[i].str = calloc(l+1,sizeof(char));

			strcpy(Lexicon.Entry[i].str,val);
			Lexicon.count += 1;


		}

	}
}
/*---FUNCTION TO ADD VARIABLES IN LEXICON LIST OF VARIABLES---*/
FUNCTION TO ADD VARIABLES IN LEXICON LIST OF VARIABLES
FUNCTION TO ADD VARIABLES IN LEXICON LIST OF VARIABLES
void add_lexicon(char name[],KindType k,float f,char *val)
{
	int count;
	int i,l;
	if(Lexicon.count == number_of_token)
		reassign_mem();	
	if(val == NULL)
	{
		count = Lexicon.count;
		count++;
		if(check_var(name)==1)
		{
			i = get_count(name);
			Lexicon.Entry[i].info.val=f;
			Lexicon.Entry[i].str=NULL;
		}
		else
		{
			i = count;
			strcpy(Lexicon.Entry[i].name,name);
			Lexicon.Entry[i].info.val = f;
			Lexicon.Entry[i].str = NULL;
			Lexicon.count += 1;
		}
	}
	else
	{
		count = Lexicon.count;
		count++;
		if(check_var(name)==1)
		{
			i = get_count(name);
			l = strlen(val);
			Lexicon.Entry[i].str = calloc(l+1,sizeof(char));
			strcpy(Lexicon.Entry[i].str,val);
		}
		else
		{
			i = count;
			strcpy(Lexicon.Entry[i].name,name);
			Lexicon.Entry[i].kind = k;
			l = strlen(val);
			Lexicon.Entry[i].str = calloc(l+1,sizeof(char));
			strcpy(Lexicon.Entry[i].str,val);
			Lexicon.count += 1;
		}
	}
}
void add_lexicon ( char name [ ] , KindType k , float f , char * val ) { int count ; int i , l ; if ( Lexicon . count == number_of_token ) reassign_mem ( ) ; if ( val == NULL ) { count = Lexicon . count ; count ++ ; if ( check_var ( name ) == 1 ) { i = get_count ( name ) ; Lexicon . Entry [ i ] . info . val = f ; Lexicon . Entry [ i ] . str = NULL ; } else { i = count ; strcpy ( Lexicon . Entry [ i ] . name , name ) ; Lexicon . Entry [ i ] . info . val = f ; Lexicon . Entry [ i ] . str = NULL ; Lexicon . count += 1 ; } } else { count = Lexicon . count ; count ++ ; if ( check_var ( name ) == 1 ) { i = get_count ( name ) ; l = strlen ( val ) ; Lexicon . Entry [ i ] . str = calloc ( l + 1 , sizeof ( char ) ) ; strcpy ( Lexicon . Entry [ i ] . str , val ) ; } else { i = count ; strcpy ( Lexicon . Entry [ i ] . name , name ) ; Lexicon . Entry [ i ] . kind = k ; l = strlen ( val ) ; Lexicon . Entry [ i ] . str = calloc ( l + 1 , sizeof ( char ) ) ; strcpy ( Lexicon . Entry [ i ] . str , val ) ; Lexicon . count += 1 ; } } }
FUNCTION TO ADD VARIABLES IN LEXICON LIST OF VARIABLES
FUNCTION TO ADD VARIABLES IN LEXICON LIST OF VARIABLES
/*IF RUN OUT OF MEMORY,REALLOC*/ //VAL IS NULL => USE IT AS FLOAT VARIABLE //IF NAME ALREADY THERE,JUST CHANGE ITS VALUE //ELSE ADD A NEW VARIABLE //ELSE ITS A STRING VARIABLE //free(Lexicon.Entry[i].str);