Fixed a bug with compiling more than one check and added another check

This commit is contained in:
Eric-Paul Ickhorn 2023-11-28 15:35:19 +01:00
parent a83770c31d
commit de80fc7b79
2 changed files with 53 additions and 0 deletions

View File

@ -16,6 +16,7 @@ function build_checks() {
cd $check_folder
gcc src/*.c $INVOCATION_PATH/.build/libparcel.a -o check.elf -I $INVOCATION_PATH/code/inc/
cd ..
done
}

View File

@ -0,0 +1,52 @@
#include <parcel.h>
#include <tokenizer.h>
#include <ast.h>
#include <stdio.h>
#include <stdlib.h>
char * load_file(char *path, long *len)
{
FILE *file = fopen(path, "r");
if(file == NULL)
{
printf("Failed opening file at '%s'\n", path);
return NULL;
}
fseek(file, 0, SEEK_END);
long length = ftell(file);
fseek(file, 0, SEEK_SET);
char *content = malloc(length+1);
content[length] = 0x00;
fread(content, 1, length, file);
if(len != NULL)
{
(*len) = length;
}
fclose(file);
return content;
}
int main(int argc, char **argv)
{
if(argc != 2)
{
printf("Usage: %s <filename>\n", argv[0]);
return -1;
}
long len_source;
char *source = load_file(argv[1], &len_source);
if(source == NULL)
{
puts("Stopping due to previous error!");
return -2;
}
pac_tlist_s tokens = pac_tokenize_grammar(source, len_source);
pac_display_tlist(tokens);
return 0;
}