school

thing1's amazing school repo
Log | Files | Refs | Submodules | README

vars.c (554B)


      1 #include <string.h>
      2 #include "../global/types.h"
      3 #include "../global/util.h"
      4 #include "../tokenizer/tokenizer.h"
      5 
      6 var *userVars[MAXVARS];
      7 long varCount = 0;
      8 
      9 void newVar(Vdef *definiton, literal *value){
     10 	var *new = CheckedMalloc(sizeof(var));
     11 	new->type = definiton->type;
     12 	new->id = definiton->id;
     13 	new->value = value;
     14 	userVars[varCount] = new;
     15 }
     16 
     17 literal *getVarCalled(char *name){
     18 	for (int i = 0; i < varCount; i++){
     19 		if (strcmp(userVars[i]->id, name)){
     20 			return userVars[i]->value;
     21 		}
     22 	}
     23 	printf("no such variable %s\n", name);
     24 	return NULL;
     25 }