Browse Source

On a rien foutu

Faure Paul 3 years ago
parent
commit
e34720da2c
5 changed files with 53 additions and 45 deletions
  1. 18
    38
      Lex_Yacc/as.y
  2. 0
    0
      Symboles/tab_instruc.c
  3. 5
    0
      Symboles/tab_instruc.h
  4. 25
    6
      Symboles/table_symboles.c
  5. 5
    1
      Symboles/table_symboles.h

+ 18
- 38
Lex_Yacc/as.y View File

@@ -7,9 +7,14 @@
7 7
 #include <stdio.h> 
8 8
 #include <string.h>
9 9
 #include <stdlib.h>
10
+#define TAILLE 1024
10 11
 
11 12
 int addr = 0;
12 13
 
14
+enum type_t type_courant;
15
+int * tab_instruc = malloc(sizeof(int)*TAILLE);
16
+int index_instruc = 0;
17
+
13 18
 %}
14 19
 
15 20
 %token tMAIN
@@ -46,7 +51,7 @@ Main : tINT tMAIN tOBRACE Params tCBRACE Body { print(pile);  printf("addr = %d\
46 51
 
47 52
 Params : { printf("Sans Params\n"); } ;
48 53
 Params : Param SuiteParams ;
49
-Param : tINT tID { printf("Prametre : %s\n", $2); };
54
+Param : DeclType tID { printf("Prametre : %s\n", $2); };
50 55
 SuiteParams : tCOMA Param SuiteParams ;
51 56
 SuiteParams : ;
52 57
 
@@ -100,43 +105,18 @@ E : tNOT E { printf("!\n"); };
100 105
 
101 106
 
102 107
 //Créer un champ isConst dans la table des symboles
103
-Decl : tCONST tINT tID SuiteDeclConst { int init = ($3 != -1); 
104
- if (init){
105
-    int val = *$2;
106
-    printf("AFC %ld %d",addr,val);
107
- }
108
-struct symbole_t symbole = {$2, addr, INT, init};
109
-push(symbole, pile); 
110
-addr++;} ;
111
-SuiteDeclConst : tCOMA tID SuiteDecl { $$=$3; int init = ($3 != -1); 
112
- if (init){
113
-    int val = *$2;
114
-    printf("AFC %ld %d",addr,val);
115
- }
116
-struct symbole_t symbole = {$2, addr, INT, init}; push(symbole, pile); addr++;};
117
-SuiteDeclConst : tEQ E tPV { $$=$2; };
118
-SuiteDeclConst : tPV { $$=$2; };
119
-
120
-Decl : tINT tID SuiteDecl { int init = ($3 != -1);
121
- if (init){
122
-    int val = *$2;
123
-    printf("AFC %ld %d",addr,val);
124
- }
125
- struct symbole_t symbole = {$2, addr, INT, init}; 
126
-push(symbole, pile); 
127
-addr++;} ;
128
-SuiteDecl : tCOMA tID SuiteDecl
129
- { $$=$3; 
130
- int init = ($3 != -1);
131
- if (init){
132
-    int val = *$2;
133
-    printf("AFC %ld %d",addr,val);
134
- }
135
- struct symbole_t symbole = {$2, addr, INT, init};
136
- push(symbole, pile); 
137
- addr++;};
138
-SuiteDecl : tEQ E tPV { $$=$2;};
139
-SuiteDecl : tPV { $$=$2; };
108
+Decl : tCONST DeclType SuiteDeclConst { } ;
109
+SuiteDeclConst : tCOMA tID SuiteDeclConst ;
110
+SuiteDeclConst : tEQ E tPV { };
111
+SuiteDeclConst : tPV { };
112
+
113
+
114
+DeclType : tINT {type_courant = INT;} ;
115
+Decl : DeclType Decl SuiteDecl { } ;
116
+Decl : tID {push($1, 0, type_courant);};
117
+Decl : tID tEQ E {push($1,1, type_courant);} ;
118
+SuiteDecl : tCOMA Decl SuiteDecl { };
119
+SuiteDecl : tPV { };
140 120
 
141 121
 Invocation : tPRINTF tOBRACE  tID tCBRACE { printf("Appel de printf sur %s\n", $3); } ;
142 122
 

+ 0
- 0
Symboles/tab_instruc.c View File


+ 5
- 0
Symboles/tab_instruc.h View File

@@ -0,0 +1,5 @@
1
+
2
+enum instructions_t {ADD,SUB}
3
+
4
+
5
+void add_operation(struct instructions_t inst, int * argv, int argv);

+ 25
- 6
Symboles/table_symboles.c View File

@@ -31,6 +31,8 @@ Opérations possible :
31 31
 #include <string.h>
32 32
 #include <stdio.h>
33 33
 
34
+int last_addr = 0;
35
+
34 36
 struct element_t {
35 37
 	struct symbole_t symbole;
36 38
 	struct element_t * suivant;
@@ -40,6 +42,8 @@ struct pile_t {
40 42
 	int taille;
41 43
 	struct element_t * first;
42 44
 };
45
+*
46
+struct pile_t * pile;
43 47
 
44 48
 char * type_to_string(enum type_t type) {
45 49
 	if (type == INT) {
@@ -51,9 +55,9 @@ char * type_to_string(enum type_t type) {
51 55
 
52 56
 void print_symbole(struct symbole_t symbole) {
53 57
     if (symbole.initialized) {
54
-		printf("\t\t{nom:%s, adresse:%p, type:%s, initialized:OUI}\n", symbole.nom, (void *)(symbole.adresse), type_to_string(symbole.type));
58
+		printf("\t\t{nom:%s, adresse:%p, type:%s, initialized:OUI, profondeur : %d}\n", symbole.nom, (void *)(symbole.adresse), type_to_string(symbole.type), symbole.profondeur);
55 59
 	} else {
56
-		printf("\t\t{nom:%s, adresse:%p, type:%s, initialized:NON}\n", symbole.nom, (void *)(symbole.adresse), type_to_string(symbole.type));
60
+		printf("\t\t{nom:%s, adresse:%p, type:%s, initialized:NON, profondeur : %d}\n", symbole.nom, (void *)(symbole.adresse), type_to_string(symbole.type),symbole.profondeur);
57 61
 	}
58 62
 }
59 63
 
@@ -63,7 +67,7 @@ void init (void) {
63 67
 	pile->taille = 0;
64 68
 }
65 69
 
66
-void push(struct symbole_t symbole, struct pile_t * pile) {
70
+void push(char * nom, int isInit, enum type_t type) {
67 71
 	struct element_t * aux = malloc(sizeof(struct element_t));
68 72
 	aux->symbole = symbole;
69 73
 	aux->suivant = pile->first;
@@ -71,7 +75,7 @@ void push(struct symbole_t symbole, struct pile_t * pile) {
71 75
 	pile->taille++;
72 76
 }
73 77
 
74
-struct symbole_t pop(struct pile_t * pile) {
78
+struct symbole_t pop() {
75 79
 	struct symbole_t retour = {"", 0, UNKNOWN, 0};
76 80
 	struct element_t * aux;
77 81
 	if (pile->taille > 0) {
@@ -84,7 +88,7 @@ struct symbole_t pop(struct pile_t * pile) {
84 88
 	return retour;
85 89
 }
86 90
 		
87
-char status(char * nom, struct pile_t * pile) {
91
+char status(char * nom) {
88 92
 	char retour = 0;
89 93
 	struct element_t * aux = pile->first;
90 94
 	int i;
@@ -103,7 +107,22 @@ char status(char * nom, struct pile_t * pile) {
103 107
 	return retour;
104 108
 }
105 109
 
106
-void print(struct pile_t * pile) {
110
+struct symbole_t * getVariable(char * nom){
111
+	struct symbole_t * retour = NULL;
112
+	struct element_t * aux = pile->first;
113
+	int i;
114
+	for (i=0; i < pile->taille; i++) {
115
+		if (!strcmp(nom, aux->symbole.nom)) {
116
+		    retour = element_t;
117
+			break;
118
+		} else {
119
+			aux = aux->suivant;
120
+		}
121
+	}
122
+	return retour;
123
+}
124
+
125
+void print() {
107 126
 	printf("Affichage de la Table des Symboles\n\tSize : %d\n\tContenu : \n", pile->taille);
108 127
 	struct element_t * aux = pile->first;
109 128
 	int i;

+ 5
- 1
Symboles/table_symboles.h View File

@@ -28,17 +28,21 @@ Opérations possible :
28 28
 #include <stdint.h>
29 29
 
30 30
 enum type_t {UNKNOWN, INT};
31
+int taille_types[] = {-1, 4};
32
+
33
+char * tab_instructions[2] = {"ADD %d %d", "SUB %d %d"}
31 34
 
32 35
 struct symbole_t {
33 36
 	char nom[30];
34 37
 	uintptr_t adresse;
35 38
 	enum type_t type;
36 39
 	char initialized;
40
+    int profondeur;
37 41
 };
38 42
 
39 43
 void print_symbole(struct symbole_t symbole);
40 44
 
41
-struct pile_t * pile;
45
+int profondeur = 0;
42 46
 
43 47
 void init(void);
44 48
 void push(struct symbole_t symbole, struct pile_t * pile);

Loading…
Cancel
Save