Initial commit
This commit is contained in:
32
src/parser.c
Normal file
32
src/parser.c
Normal file
@@ -0,0 +1,32 @@
|
||||
#include "parser.h"
|
||||
#include "types.h"
|
||||
#include "lexer.h"
|
||||
#include <stdio.h>
|
||||
|
||||
GroundProgram createGroundProgram() {
|
||||
GroundProgram gp;
|
||||
gp.size = 0;
|
||||
return gp;
|
||||
}
|
||||
|
||||
void addInstructionToProgram(GroundProgram* gp, GroundInstruction instruction) {
|
||||
gp->size++;
|
||||
GroundInstruction* ptr = realloc(gp->instructions, gp->size * sizeof(GroundInstruction));
|
||||
if (ptr == NULL) {
|
||||
perror("Couldn't allocate memory for instruction");
|
||||
exit(1);
|
||||
}
|
||||
gp->instructions = ptr;
|
||||
gp->instructions[gp->size - 1] = instruction;
|
||||
}
|
||||
|
||||
void freeGroundProgram(GroundProgram* gp) {
|
||||
for (int i = 0; i < gp->size; i++) {
|
||||
freeGroundInstruction(&gp->instructions[i]);
|
||||
}
|
||||
}
|
||||
|
||||
GroundProgram parseFile(LexedFile file) {
|
||||
GroundProgram gp;
|
||||
return gp;
|
||||
}
|
||||
Reference in New Issue
Block a user