Compare commits
No commits in common. "master" and "Compilateur_non_securise" have entirely different histories.
master
...
Compilateu
6 changed files with 16 additions and 105 deletions
|
@ -41,7 +41,7 @@ yyerror (char const *s)
|
||||||
"]" { return tCCROCH; } // Token crochet ouvrante
|
"]" { return tCCROCH; } // Token crochet ouvrante
|
||||||
|
|
||||||
"get" { return tGET; } // Token fonction get
|
"get" { return tGET; } // Token fonction get
|
||||||
"print" { return tPRINT; } // Token fonction print
|
"printf" { return tPRINTF; } // Token fonction print
|
||||||
"stop" { return tSTOP; } // Token fonction stop
|
"stop" { return tSTOP; } // Token fonction stop
|
||||||
|
|
||||||
"+" { return tADD; } // Token addition
|
"+" { return tADD; } // Token addition
|
||||||
|
@ -57,8 +57,6 @@ yyerror (char const *s)
|
||||||
[0-9]+ { yylval.nombre = atoi(yytext); return tNB; } // Token nombre au format classique
|
[0-9]+ { yylval.nombre = atoi(yytext); return tNB; } // Token nombre au format classique
|
||||||
[0-9]+e[0-9]+ { yylval.nombre = -1; return tNB; } // Token nombre au format exponentiel
|
[0-9]+e[0-9]+ { yylval.nombre = -1; return tNB; } // Token nombre au format exponentiel
|
||||||
|
|
||||||
["][^"]*["] { strcpy(yylval.str, yytext); return tSTR; }
|
|
||||||
|
|
||||||
[a-zA-Z][a-zA-Z0-9_]* { strcpy(yylval.id, yytext); return tID; } // Chaine de caractère (identifiant variable, fonction..)
|
[a-zA-Z][a-zA-Z0-9_]* { strcpy(yylval.id, yytext); return tID; } // Chaine de caractère (identifiant variable, fonction..)
|
||||||
|
|
||||||
|
|
||||||
|
|
103
Lex_Yacc/as.y
103
Lex_Yacc/as.y
|
@ -10,8 +10,7 @@
|
||||||
%union {
|
%union {
|
||||||
int nombre;
|
int nombre;
|
||||||
struct symbole_t symbole;
|
struct symbole_t symbole;
|
||||||
char id[30];
|
char id[30];
|
||||||
char str[300];
|
|
||||||
struct while_t my_while;
|
struct while_t my_while;
|
||||||
}
|
}
|
||||||
%{
|
%{
|
||||||
|
@ -21,7 +20,6 @@
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include "../Tables/Instructions/tab_instruc.h"
|
#include "../Tables/Instructions/tab_instruc.h"
|
||||||
#define TAILLE 1024
|
#define TAILLE 1024
|
||||||
#define SECURED (1)
|
|
||||||
|
|
||||||
struct type_t type_courant;
|
struct type_t type_courant;
|
||||||
struct type_t return_type_fonc;
|
struct type_t return_type_fonc;
|
||||||
|
@ -46,8 +44,7 @@ int first_etoile = 1;
|
||||||
%token tMUL tDIV tADD tSUB tEQ
|
%token tMUL tDIV tADD tSUB tEQ
|
||||||
%token<nombre> tNB tNBEXP
|
%token<nombre> tNB tNBEXP
|
||||||
%token<id> tID
|
%token<id> tID
|
||||||
%token<str> tSTR
|
%token tPRINTF tGET tSTOP
|
||||||
%token tPRINT tGET tSTOP
|
|
||||||
%token<nombre> tIF tELSE
|
%token<nombre> tIF tELSE
|
||||||
%token<my_while> tWHILE
|
%token<my_while> tWHILE
|
||||||
%token tRETURN
|
%token tRETURN
|
||||||
|
@ -118,88 +115,10 @@ Get : tGET tOBRACE tCBRACE {int addr = push("0_TEMPORARY", 0, integer);
|
||||||
};
|
};
|
||||||
|
|
||||||
// Print, une fonction particulière
|
// Print, une fonction particulière
|
||||||
Print : tPRINT tOBRACE E tCBRACE {add_operation(PRI,$3,0,0); // On ajoute l'instruction PRI
|
Print : tPRINTF tOBRACE E tCBRACE {add_operation(PRI,$3,0,0); // On ajoute l'instruction PRI
|
||||||
pop(); // On supprime la variable temporaire
|
pop(); // On supprime la variable temporaire
|
||||||
};
|
};
|
||||||
|
|
||||||
// Print, une fonction particulière
|
|
||||||
Print : tPRINT tOBRACE tSTR tCBRACE {int i = 0;
|
|
||||||
int decalage = 0;
|
|
||||||
char previous = 'a';
|
|
||||||
while ($3[i] != '\0') {
|
|
||||||
if (previous == '\\' && $3[i] == 'n') {
|
|
||||||
$3[i - decalage - 1] = '\n';
|
|
||||||
previous = 'a';
|
|
||||||
decalage++;
|
|
||||||
} else if (previous == '\\' && $3[i] == '0') {
|
|
||||||
$3[i - decalage - 1] = '\0';
|
|
||||||
previous = 'a';
|
|
||||||
decalage++;
|
|
||||||
} else {
|
|
||||||
$3[i-decalage] = $3[i];
|
|
||||||
previous = $3[i];
|
|
||||||
}
|
|
||||||
i++;
|
|
||||||
}
|
|
||||||
$3[i-decalage] = $3[i];
|
|
||||||
i=0;
|
|
||||||
int termine = $3[i+1] == '"';
|
|
||||||
int addr = push("0_TEMPORARY", 0, integer);
|
|
||||||
while (!termine) {
|
|
||||||
if ($3[i+1] != '"') {
|
|
||||||
add_operation(AFC, addr + i, $3[i+1], 0);
|
|
||||||
} else {
|
|
||||||
termine = 1;
|
|
||||||
}
|
|
||||||
i++;
|
|
||||||
if (!termine && $3[i+1] != '"') {
|
|
||||||
add_operation(AFC, addr + i, $3[i+1], 0);
|
|
||||||
} else {
|
|
||||||
termine = 1;
|
|
||||||
}
|
|
||||||
i++;
|
|
||||||
if (!termine && $3[i+1] != '"') {
|
|
||||||
add_operation(AFC, addr + i, $3[i+1], 0);
|
|
||||||
} else {
|
|
||||||
termine = 1;
|
|
||||||
}
|
|
||||||
i++;
|
|
||||||
if (!termine && $3[i+1] != '"') {
|
|
||||||
add_operation(AFC, addr + i, $3[i+1], 0);
|
|
||||||
} else {
|
|
||||||
termine = 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
i = i - 3;
|
|
||||||
termine = 0;
|
|
||||||
if ($3[i+1] != '"') {
|
|
||||||
add_operation(PRIC, addr + i, 0, 0);
|
|
||||||
} else {
|
|
||||||
termine = 1;
|
|
||||||
}
|
|
||||||
i++;
|
|
||||||
if (!termine && $3[i+1] != '"') {
|
|
||||||
add_operation(PRIC, addr + i, 0, 0);
|
|
||||||
} else {
|
|
||||||
termine = 1;
|
|
||||||
}
|
|
||||||
i++;
|
|
||||||
if (!termine && $3[i+1] != '"') {
|
|
||||||
add_operation(PRIC, addr + i, 0, 0);
|
|
||||||
} else {
|
|
||||||
termine = 1;
|
|
||||||
}
|
|
||||||
i++;
|
|
||||||
if (!termine && $3[i+1] != '"') {
|
|
||||||
add_operation(PRIC, addr + i, 0, 0);
|
|
||||||
} else {
|
|
||||||
termine = 1;
|
|
||||||
}
|
|
||||||
i++;
|
|
||||||
}
|
|
||||||
pop(); // On supprime la variable temporaire
|
|
||||||
};
|
|
||||||
|
|
||||||
// Stop, une fonction particulière
|
// Stop, une fonction particulière
|
||||||
Stop : tSTOP tOBRACE tNB tCBRACE {add_operation(STOP,$3,0,0); // On ajoute juste l'instruction stop
|
Stop : tSTOP tOBRACE tNB tCBRACE {add_operation(STOP,$3,0,0); // On ajoute juste l'instruction stop
|
||||||
};
|
};
|
||||||
|
@ -298,17 +217,11 @@ Instruction : Print tPV;
|
||||||
/*************************************/
|
/*************************************/
|
||||||
/*************************************/
|
/*************************************/
|
||||||
|
|
||||||
Invocation : tID tOBRACE {if (!SECURED) {
|
Invocation : tID tOBRACE {push("0_TEMPORARY_CTX", 0, integer); // On reserve la place du contexte
|
||||||
push("0_TEMPORARY_CTX", 0, integer); // On reserve la place du contexte
|
push("0_TEMPORARY_ADDR_RT", 0, pointer); // On reserve la place de l'adresse de retour
|
||||||
push("0_TEMPORARY_ADDR_RT", 0, pointer); // On reserve la place de l'adresse de retour
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
Params tCBRACE {struct fonction_t fonc = get_fonction($1); // On récupère la fonction
|
Params tCBRACE {struct fonction_t fonc = get_fonction($1); // On récupère la fonction
|
||||||
if (!SECURED) {
|
multiple_pop($4 + 2); // On pop les paramètres de la table des symboles
|
||||||
multiple_pop($4 + 2); // On pop les paramètres de la table des symboles
|
|
||||||
} else {
|
|
||||||
multiple_pop($4); // On pop les paramètres de la table des symboles
|
|
||||||
}
|
|
||||||
add_operation(CALL,fonc.first_instruction_line, get_last_addr(),0); // On écrit le CALL
|
add_operation(CALL,fonc.first_instruction_line, get_last_addr(),0); // On écrit le CALL
|
||||||
// On renvoi l'adresse de la valeur retour de la fonction
|
// On renvoi l'adresse de la valeur retour de la fonction
|
||||||
if (fonc.return_type.pointeur_level > 0 || fonc.return_type.isTab) {
|
if (fonc.return_type.pointeur_level > 0 || fonc.return_type.isTab) {
|
||||||
|
@ -775,6 +688,6 @@ SuiteInitTab : {$$ = 0;
|
||||||
|
|
||||||
%%
|
%%
|
||||||
void main(void) {
|
void main(void) {
|
||||||
init();
|
init();
|
||||||
yyparse();
|
yyparse();
|
||||||
}
|
}
|
||||||
|
|
6
Makefile
6
Makefile
|
@ -7,7 +7,7 @@ default :
|
||||||
### NETTOYAGE ###
|
### NETTOYAGE ###
|
||||||
###########################
|
###########################
|
||||||
clean : clean_Symboles clean_Instructions clean_Lex_Yacc clean_Fonctions
|
clean : clean_Symboles clean_Instructions clean_Lex_Yacc clean_Fonctions
|
||||||
@rm -f compiler
|
@rm -f rondoudou_gcc
|
||||||
@rm -f output.txt
|
@rm -f output.txt
|
||||||
|
|
||||||
clean_Symboles:
|
clean_Symboles:
|
||||||
|
@ -31,7 +31,7 @@ clean_Lex_Yacc:
|
||||||
### COMPILATION ###
|
### COMPILATION ###
|
||||||
###########################
|
###########################
|
||||||
build : clean build_Symboles build_Instructions build_Lex_Yacc build_Fonctions
|
build : clean build_Symboles build_Instructions build_Lex_Yacc build_Fonctions
|
||||||
gcc Lex_Yacc/as.tab.o Lex_Yacc/lex.yy.o Tables/Instructions/tab_instruc.o Tables/Symboles/table_symboles.o Tables/Fonctions/tab_fonctions.o -o compiler
|
gcc Lex_Yacc/as.tab.o Lex_Yacc/lex.yy.o Tables/Instructions/tab_instruc.o Tables/Symboles/table_symboles.o Tables/Fonctions/tab_fonctions.o -ll -o rondoudou_gcc
|
||||||
|
|
||||||
build_Symboles: clean_Symboles
|
build_Symboles: clean_Symboles
|
||||||
gcc -c Tables/Symboles/table_symboles.c -o Tables/Symboles/table_symboles.o
|
gcc -c Tables/Symboles/table_symboles.c -o Tables/Symboles/table_symboles.o
|
||||||
|
@ -69,7 +69,7 @@ test_Fonctions: build_Fonctions
|
||||||
Tables/Fonctions/test
|
Tables/Fonctions/test
|
||||||
|
|
||||||
test: build
|
test: build
|
||||||
cat Fichiers_Tests/progC | ./compiler
|
cat Fichiers_Tests/progC | ./rondoudou_gcc
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
3
README.md
Normal file
3
README.md
Normal file
|
@ -0,0 +1,3 @@
|
||||||
|
# Projet Système Informatique - Elies TALI et Paul FAURE
|
||||||
|
|
||||||
|
Plop
|
|
@ -75,9 +75,6 @@ char * get_asm_line_from_op(struct operation_t op){
|
||||||
case (PRI):
|
case (PRI):
|
||||||
sprintf(buffer,"PRI %d\n",op.arg1);
|
sprintf(buffer,"PRI %d\n",op.arg1);
|
||||||
break;
|
break;
|
||||||
case (PRIC):
|
|
||||||
sprintf(buffer,"PRIC %d\n",op.arg1);
|
|
||||||
break;
|
|
||||||
case (READ):
|
case (READ):
|
||||||
sprintf(buffer,"READ %d %d\n",op.arg1, op.arg2);
|
sprintf(buffer,"READ %d %d\n",op.arg1, op.arg2);
|
||||||
break;
|
break;
|
||||||
|
|
|
@ -8,7 +8,7 @@
|
||||||
|
|
||||||
|
|
||||||
// Liste de codes des instruction
|
// Liste de codes des instruction
|
||||||
enum opcode_t {ADD,MUL,SOU,DIV,COP,AFC,AFCA,JMP,JMF,INF,SUP,EQU,PRI,PRIC,READ,WR,CALL,RET,GET,STOP};
|
enum opcode_t {ADD,MUL,SOU,DIV,COP,AFC,AFCA,JMP,JMF,INF,SUP,EQU,PRI,READ,WR,CALL,RET,GET,STOP};
|
||||||
|
|
||||||
//Ajoute une opération dans la table (à la fin)
|
//Ajoute une opération dans la table (à la fin)
|
||||||
void add_operation(enum opcode_t opcode, int arg1, int arg2, int arg3);
|
void add_operation(enum opcode_t opcode, int arg1, int arg2, int arg3);
|
||||||
|
|
Loading…
Reference in a new issue