-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinterIMP.c
More file actions
51 lines (48 loc) · 1.17 KB
/
interIMP.c
File metadata and controls
51 lines (48 loc) · 1.17 KB
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
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "utils/interIMP.h"
#include "iimp.tab.h"
char *strdup(const char *s);
int traitement(ENV *e,noeud *n){
if (!n) return 0;
switch(n->type){
case I:
return n->data.valeur;
case V:
return valch(*e,n->data.id);
case If:
traitement(e,n->fils_gauche);
traitement(e,n->fils_droit);
return 0;
case El:
if(traitement(e,n->fils_gauche))
traitement(e,n->fils_droit);
return 0;
case Th:
if(!traitement(e,n->fils_gauche))
traitement(e,n->fils_droit);
return 0;
case Wh:
while(traitement(e,n->fils_gauche))
traitement(e,n->fils_droit);
return 0;
case Af:
initenv(e,n->fils_gauche->data.id);
return affect(*e, n->fils_gauche->data.id, traitement(e,n->fils_droit));
case Se:
traitement(e,n->fils_gauche);
return traitement(e,n->fils_droit);
case Pl:
case Mo:
case Mu:
return eval(n->type, traitement(e, n->fils_gauche), traitement(e, n->fils_droit));
}
return 0;
}
int start(ENV *e,noeud* n){
int res = traitement(e,n);
ecrire_env(*e);
libererArbre(n);
return res;
}