-
Notifications
You must be signed in to change notification settings - Fork 0
/
asa.h
128 lines (102 loc) · 2.5 KB
/
asa.h
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
116
117
118
119
120
121
122
123
124
125
126
127
128
/*
BOGADO GARCIA Maximino
L3 Informatique
asa.h
*/
#ifndef ASA_H
#define ASA_H
#include <string.h>
#include <stdio.h>
#include <stdlib.h>
#include "ts.h"
typedef enum {typeNb, typeOp, typeId, typeDecl, typeAffect, typeInst, typeTq, typeComp, typeBool, typeNon, typeSi, typeAfficher, typeLire} typeNoeud;
typedef struct {
int val;
} feuilleNb;
typedef struct {
char nom[64];
} feuilleId;
typedef struct {
int ope;
struct asa * noeud[2];
} noeudOp;
typedef struct {
// Un buffer de 3 caracteres pour pouvoir stocker par exemple "!=" et le '\0'
char ope[3];
struct asa * noeud[2];
} noeudComp;
typedef struct {
// Un buffer de 3 caracteres pour pouvoir stocker par exemple "OU" et le '\0'
char ope[3];
struct asa * noeud[2];
} noeudBool;
typedef struct {
struct asa * noeud[2];
} noeudAffect;
typedef struct {
struct asa * noeud;
} noeudAfficher;
typedef struct {
struct asa * noeud;
} noeudLire;
typedef struct {
struct asa * noeud[2];
} noeudTq;
typedef struct {
struct asa * noeud[3];
} noeudSi;
typedef struct {
struct asa * noeud;
int size;
} noeudDecl;
typedef struct {
struct asa *noeud[2];
} noeudInst;
typedef struct {
struct asa * noeud;
} noeudNon;
typedef struct asa{
typeNoeud type;
int ninst;
union {
feuilleNb nb;
feuilleId id;
noeudInst inst;
noeudDecl decl;
noeudAffect affect;
noeudComp comp;
noeudOp op;
noeudTq tq;
noeudBool booleen;
noeudNon non;
noeudSi si;
noeudAfficher afficher;
noeudLire lire;
};
} asa;
// fonction d'erreur utilisée également par Bison
void yyerror(const char * s);
/*
Les fonctions creer_<type> construise un noeud de l'arbre
abstrait du type correspondant et renvoie un pointeur celui-ci
*/
asa * creer_feuilleNb( int value );
asa * creer_noeudOp( int ope, asa * p1, asa * p2 );
asa * creer_feuilleId(char *s);
asa * creer_noeudAffect(asa * p1, asa * p2);
// On prend un char* car il peut y avoir "!=" ">=" et "<="
asa * creer_noeudComp(char *ope, asa * p1, asa * p2);
asa * creer_noeudSi(asa * p1, asa * p2, asa * p3);
asa * creer_noeudBool(char *ope, asa * p1, asa * p2);
asa * creer_noeudNon(asa * p1);
asa * creer_noeudAfficher(asa * p1);
asa * creer_noeudLire(asa * p1);
asa * creer_noeudDecl(asa * p1, int size);
asa * creer_noeudInst(asa * p1, asa * p2);
asa * creer_noeudTq(asa * p1, asa * p2);
void free_asa(asa *p);
// produit du code pour la machine RAM à partir de l'arbre abstrait
// ET de la table de symbole
void codegen(asa *p);
extern ts * tsymb;
#endif