53 lines
1.1 KiB
C
53 lines
1.1 KiB
C
#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;
|
|
}
|