-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.c
82 lines (64 loc) · 1.81 KB
/
main.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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
/*
============================================================================
Projekt : Implementace interpretu imperativniho jazyka IFJ13
Soubor : main.c
Varianta : a/3/II
Autori : xkovar66 David Kovarik
: xholcn01 Jonas Holcner
: xsychr05 Marek Sychra
: xkaras27 Josef Karasek
: xkralb00 Benjamin Kral
============================================================================
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
//importy vlastnich modulu
#include "garbage.h"
#include "str.h"
#include "error.h"
#include "scanner.h"
#include "ial.h"
#include "builtins.h"
#include "parser.h"
#include "ilist.h"
#include "interpret.h"
int main(int argc, char** argv) {
if (argc != 2) { // ocekavame PRAVE JEDEN argument (+ nazev souboru)
fprintf(stderr, "Nespravny pocet argumentu testovaciho programu.\n");
return -1; //!! predelat na spravnou konstantu
}
FILE * f = fopen(argv[1], "r");
if (f == NULL ) {
fprintf(stderr, "Testovacimu souboru se nepodarilo otevrit soubor s aplikaci.\n");
return internalError();
}
initGarbageCollector();
//nastav soubor, ze ktereho scanner cte
setSourceFile(f);
htable_t* fT;
tIlist iL;
listInit(&iL);
fT = htable_init(HTABLE_SIZE);
htableStack *sS = gcMalloc(sizeof(htableStack));
if (sS == NULL) return internalError();
sS = htable_stack_init();
htable_t *mainTable ;
mainTable = htable_init(HTABLE_SIZE);
htable_stack_push(sS,mainTable);
int result = parse(fT, &iL,sS);
if (result != EOK)
{
fclose(f);
freeGarbage();
return result;
// jinak probehlo vse v poradku, muzeme provadet kod
}
result = (interpret(&iL,fT,sS));
freeGarbage();
fclose(f);
if(result != EOK){
return result;
}
return EOK;
}