-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathglobal.h
57 lines (43 loc) · 1.8 KB
/
global.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
#ifndef GLOBAL_H_
#define GLOBAL_H_
#include <stdlib.h>
#include <stdio.h>
extern const struct variable_type type_integer;
extern const struct variable_type type_real;
extern int memOffset;
#define DEBUG(msg) (fprintf(stderr, "%s(%d): %s\n", __FILE__, __LINE__, msg))
typedef enum symtab_EntryType {INTEGER, REAL, BOOL, PROC, NOP, ARR, FUNC, PROG, PRG_PARA}
symtabEntryType;
typedef struct a_symtabEntry{
char * name;
symtabEntryType type;
symtabEntryType internType;
int offset;
int line;
int index1;
int index2;
struct a_symtabEntry * vater;
int parameter;
int number;
float value;
struct a_symtabEntry * next;
} symtabEntry;
/*
* Variable type definitions
*/
// Memory needed by an int or a real, is added every time a variable is entered into the symbol table
#define SIZE_INT 4
#define SIZE_REAL 8
struct variable_type {
size_t size; /* size of an instance of the variable(in bytes) */
symtabEntryType symtabType; /* type of the variable in the symbol table */
};
void getSymbolTypePrintout(symtabEntryType type, char * writeIn);
void writeSymboltable (symtabEntry * Symboltable, FILE * outputFile);
// Symbol table manipulation functions
symtabEntry* addSymboltableEntry (symtabEntry** Symboltable,char * name,symtabEntryType type,symtabEntryType internType,int offset,int line,int index1,int index2,symtabEntry * vater,int parameter);
symtabEntry* getSymboltableEntry(symtabEntry* Symboltable, char* name, symtabEntry* father);
symtabEntry* getSymboltableEntryInScope(symtabEntry *symbolTable, symtabEntry *context, const char* name);
symtabEntry* addVarToSymtab(symtabEntry** symbolTable, char* name, const struct variable_type* type, symtabEntry* father);
symtabEntry* getTempVariable(symtabEntry** symbolTable, const struct variable_type* type, symtabEntry* father);
#endif /*GLOBAL_H_*/