Files
compiler-the-translators/tests/sprint2/other/test.c
2025-03-03 14:48:19 -05:00

75 lines
2.6 KiB
C

#include <stdlib.h>
#include <string.h>
#include "symbol_table.h"
int main(void){
char *prim = strdup("primitive");
char *inte = strdup("integer");
SymbolTable * parant = CreateScope(NULL, 1,1);
char *boole = strdup("Boolean");
char *chare = strdup("character");
char *str = strdup("string");
char *arg = strdup("arg");
char *one_to_char = strdup("1 -> character");
char *int_to_int = strdup("integer -> integer");
char *int2int = strdup("int2int");
char *str_to_int = strdup("string -> integer");
char *str2int = strdup("string2int");
char *square = strdup("square");
char *string2int = strdup("string2int");
char *entry = strdup("entry");
char *x = strdup("x");
char *input = strdup("input");
char *expected = strdup("expected");
char *actual = strdup("actual");
char *$_und_type = strdup("$_undefined_type");
char *result = strdup("result");
char *BOO = strdup("BOO");
char *YAZOO = strdup("YAZOO");
CreateEntry(parant, prim, boole);
CreateEntry(parant, prim, chare);
CreateEntry(parant, prim, inte);
CreateEntry(parant, one_to_char, str);
CreateEntry(parant, int_to_int, int2int);
CreateEntry(parant, str_to_int, str2int);
CreateEntry(parant, int2int, square);
CreateEntry(parant, string2int, entry);
SymbolTable * child = CreateScope(parant, 14,14);
CreateEntry(child, inte, x);
SymbolTable * second = CreateScope(parant, 21,15);
CreateEntry(second, str, arg);
CreateEntry(second, inte, input);
CreateEntry(second, inte, expected);
CreateEntry(second, inte, actual);
CreateEntry(second, $_und_type, result);
SymbolTable * third = CreateScope(second, 33,44);
CreateEntry(third, BOO, arg);
CreateEntry(third, YAZOO, input);
TableNode *ret = table_lookup(third, "arg");
printf("%s == %s\n", ret->theName, "arg");
ret = table_lookup(third, "hello");
printf("This should be nil %p != %s\n", ret, "BOO");
ret = look_up(second, "input");
printf("%s == %s\n", ret->theName, "input");
ret = look_up(second, "square");
printf("%s == %s\n", ret->theName, "square");
ret = look_up(second, "spuare");
printf("This should be nil %p == %s\n", ret, "square");
print_symbol_table(parant, stderr);
free(inte);
free(boole);
free(prim);
free(str);
free(chare);
free(arg);
return 0;
}