-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathparse.c
More file actions
42 lines (29 loc) · 697 Bytes
/
parse.c
File metadata and controls
42 lines (29 loc) · 697 Bytes
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
#include "parse.h"
#include <stdlib.h>
#include "lex.h"
#include "grammar.c"
static void *parser = NULL;
static void parse(int tok, SToken *tok_data)
{
Parse(parser, tok, tok_data);
}
int steady_parse_file(const char *filename)
{
FILE *file = fopen(filename, "r");
if(!file)
{
fprintf(stderr, "could not open file for reading\n");
return 0;
}
fseek(file, 0, SEEK_END);
size_t length = ftell(file);
rewind(file);
char *source = malloc(length);
fread(source, 1, length, file);
parser = ParseAlloc(malloc);
steady_lex(source, length, parse);
ParseFree(parser, free);
free(source);
fclose(file);
return 1;
}