This repository has been archived by the owner on Feb 1, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathmain.c
115 lines (95 loc) · 2.4 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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
/**
* Predmet: IFJ / IAL
* Projekt: Implementace interpretu imperativniho jazyka IFJ13
* Tym: 099
* Varianta: a/2/I
* Soubor: main.c
* Autori: Vlcek Michael <[email protected]>
* Svacek Radim <[email protected]>
* Blanco Roman <[email protected]>
* Micka Vojtech <[email protected]>
* Wolfert Richard <[email protected]>
*/
#include "scanner.h"
#include "inc_func.h"
#include "interpret.h"
#include <stdbool.h>
#include <stdlib.h>
#include <stdio.h>
#define FILE_ERR 99
int main(int argc, char *argv[]){
tInstList GlobalInstList;
listInit(&GlobalInstList); // inicializace seznamu
t_stItemV VTableRoot;
stInitV(&VTableRoot);
t_stItemF FTableRoot;
if(stInitF(&FTableRoot,&VTableRoot) != RET_OK) {
stDisposeF(&FTableRoot);
stDisposeV(&VTableRoot);
listDestroy(&GlobalInstList);
return RET_ERR;
}
if(argc!=2){
fprintf(stderr,"Neplatny pocet parametru\n");
stDisposeF(&FTableRoot);
stDisposeV(&VTableRoot);
listDestroy(&GlobalInstList);
return FILE_ERR;
}
else{
if((f = fopen (argv[1], "r"))==NULL){
fprintf(stderr,"Nepodarilo se otevrit soubor\n");
stDisposeF(&FTableRoot);
stDisposeV(&VTableRoot);
listDestroy(&GlobalInstList);
return FILE_ERR;
}
}
int result;
result = parse(&VTableRoot,&FTableRoot,&GlobalInstList);
if (result == SYNT_OK)
result = interpret(VTableRoot,&GlobalInstList);
listDestroy(&GlobalInstList);
stDisposeF(&FTableRoot);
stDisposeV(&VTableRoot);
fclose(f);
switch (result)
{
case SYNT_OK:
return 0;
break;
case SEM_ERR_MISS_PAR:
fprintf(stderr,"Semanticka Chyba, chybajuce parametre\n");
return 4;
case SEM_ERR_UNDEF:
fprintf(stderr,"Semanticka Chyba, nedefinovana premenna\n");
return 5;
case SEM_ERR_NULL_DIV:
fprintf(stderr,"Semanticka Chyba, Delenie nulou\n");
return 10;
case SEM_ERR_RETYPE:
fprintf(stderr,"Semanticka Chyba, Chyba pretypovania\n");
return 11;
case SEM_ERR_ARITH:
fprintf(stderr,"Semanticka Chyba, Chyba v aritmetickej operacii\n");
return 12;
case SEM_ERR_OTHER:
fprintf(stderr,"Semanticka Chyba, Ina chyba\n");
return 13;
case SYNT_ERR:
fprintf(stderr,"Syntakticka chyba!!!\n");
return 2;
break;
case LEX_ERR:
fprintf(stderr,"Lexikalna Chyba!!!\n");
return 1;
break;
case RET_ERR:
fprintf(stderr,"Vnutorna chyba prekladaca!!!\n");
return 99;
case SEM_ERR:
fprintf(stderr,"Semanticka chyba v programe\n");
return 3;
}
return 0;
}