-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathtokens_demo.c
40 lines (38 loc) · 1.05 KB
/
tokens_demo.c
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
#include <stdio.h>
#include <lexer.h>
#include <parser.h>
#include <stringbuffer.h>
#include <string.h>
#include <ast.h>
#include <interpreter.h>
#include <dict.h>
#include <fs.h>
#include <preetyprint.h>
int main(int argc, const char ** argv)
{
//const char *fileName = "../main.pivo";
if(argc != 2)
{
puts(">>>ERROR: Invalid run arguments\nTip: Add filename to firts argument\nExample: ./task3.out ../main.mlua");
return EXIT_FAILURE;
}
const char *fileName = argv[1];
if(!fileExists(fileName)) return EXIT_FAILURE;
int size = getFileSize(fileName);
char input[size + size];
readFileToBuffer(fileName, input, size + size);
input[size] = '\0';
List *tokens = List_new();
if (0 != Lexer_splitTokens(input, tokens))
{
Lexer_clearTokens(tokens);
List_free(tokens);
return EXIT_FAILURE;
}
FILE *fp = fopen("../main_tokens.txt", "w");
Lexer_printTokensToFile(tokens, fp);
fclose(fp);
Lexer_clearTokens(tokens);
List_free(tokens);
return EXIT_SUCCESS;
}