Dossiers propres
This commit is contained in:
parent
2be358e747
commit
3a4f2e256f
35 changed files with 76 additions and 9325 deletions
9
.gitignore
vendored
Normal file
9
.gitignore
vendored
Normal file
|
@ -0,0 +1,9 @@
|
||||||
|
rondoudou_gcc
|
||||||
|
output.txt
|
||||||
|
Tables/Symboles/*.o
|
||||||
|
Tables/Symboles/test
|
||||||
|
Tables/Instructions/*.o
|
||||||
|
Tables/Instructions/test
|
||||||
|
Lex_Yacc/as.output
|
||||||
|
Lex_Yacc/as.tab.*
|
||||||
|
Lex_Yacc/lex.yy.*
|
Binary file not shown.
|
@ -1,44 +0,0 @@
|
||||||
%{
|
|
||||||
#include "as.tab.h"
|
|
||||||
int yywrap(void){return 1;}
|
|
||||||
%}
|
|
||||||
|
|
||||||
%%
|
|
||||||
|
|
||||||
"main" { return tMAIN ;}
|
|
||||||
"{" { return tOBRACKET;}
|
|
||||||
"}" { return tCBRACKET; }
|
|
||||||
"(" { return tOBRACE; }
|
|
||||||
")" { return tCBRACE; }
|
|
||||||
"const" { return tCONST; }
|
|
||||||
"int" { return tINT; }
|
|
||||||
"printf" { return tPRINTF; } //Degeu mais à degager
|
|
||||||
"if" { return tIF; }
|
|
||||||
"while" { return tWHILE; }
|
|
||||||
"<" { return tLT; }
|
|
||||||
">" { return tGT; }
|
|
||||||
"==" { return tEQCOND; }
|
|
||||||
"&&" { return tAND; }
|
|
||||||
"||" { return tOR; }
|
|
||||||
"else" { return tELSE;}
|
|
||||||
|
|
||||||
|
|
||||||
[0-9]+ { yylval.nombre = atoi(yytext); return tNB; }
|
|
||||||
[0-9]+e[0-9]+ { yylval.nombre = -1; return tNBEXP; } //Renvoyer le token tNB et pas tNBEXP
|
|
||||||
"+" { return tADD; }
|
|
||||||
"-" { return tSUB; }
|
|
||||||
"*" { return tMUL; }
|
|
||||||
"/" { return tDIV; }
|
|
||||||
"=" { return tEQ; }
|
|
||||||
";" { return tPV; }
|
|
||||||
" " {} //Ne pas les retourner à Yacc
|
|
||||||
" " {} //Ne pas les retourner à Yacc
|
|
||||||
"," { return tCOMA; }
|
|
||||||
"/*"[^(*/)]*"*/" { printf("commentaire\n");}
|
|
||||||
"\n" {} //Ne pas les retourner à Yacc
|
|
||||||
[a-zA-Z][a-zA-Z0-9_]* { strcpy(yylval.id, yytext); return tID; }
|
|
||||||
. { return tERROR; }
|
|
||||||
|
|
||||||
%%
|
|
||||||
|
|
||||||
|
|
File diff suppressed because it is too large
Load diff
|
@ -1,101 +0,0 @@
|
||||||
/* A Bison parser, made by GNU Bison 3.0.4. */
|
|
||||||
|
|
||||||
/* Bison interface for Yacc-like parsers in C
|
|
||||||
|
|
||||||
Copyright (C) 1984, 1989-1990, 2000-2015 Free Software Foundation, Inc.
|
|
||||||
|
|
||||||
This program is free software: you can redistribute it and/or modify
|
|
||||||
it under the terms of the GNU General Public License as published by
|
|
||||||
the Free Software Foundation, either version 3 of the License, or
|
|
||||||
(at your option) any later version.
|
|
||||||
|
|
||||||
This program is distributed in the hope that it will be useful,
|
|
||||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
GNU General Public License for more details.
|
|
||||||
|
|
||||||
You should have received a copy of the GNU General Public License
|
|
||||||
along with this program. If not, see <http://www.gnu.org/licenses/>. */
|
|
||||||
|
|
||||||
/* As a special exception, you may create a larger work that contains
|
|
||||||
part or all of the Bison parser skeleton and distribute that work
|
|
||||||
under terms of your choice, so long as that work isn't itself a
|
|
||||||
parser generator using the skeleton or a modified version thereof
|
|
||||||
as a parser skeleton. Alternatively, if you modify or redistribute
|
|
||||||
the parser skeleton itself, you may (at your option) remove this
|
|
||||||
special exception, which will cause the skeleton and the resulting
|
|
||||||
Bison output files to be licensed under the GNU General Public
|
|
||||||
License without this special exception.
|
|
||||||
|
|
||||||
This special exception was added by the Free Software Foundation in
|
|
||||||
version 2.2 of Bison. */
|
|
||||||
|
|
||||||
#ifndef YY_YY_AS_TAB_H_INCLUDED
|
|
||||||
# define YY_YY_AS_TAB_H_INCLUDED
|
|
||||||
/* Debug traces. */
|
|
||||||
#ifndef YYDEBUG
|
|
||||||
# define YYDEBUG 0
|
|
||||||
#endif
|
|
||||||
#if YYDEBUG
|
|
||||||
extern int yydebug;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
/* Token type. */
|
|
||||||
#ifndef YYTOKENTYPE
|
|
||||||
# define YYTOKENTYPE
|
|
||||||
enum yytokentype
|
|
||||||
{
|
|
||||||
tMAIN = 258,
|
|
||||||
tOBRACKET = 259,
|
|
||||||
tCBRACKET = 260,
|
|
||||||
tOBRACE = 261,
|
|
||||||
tCBRACE = 262,
|
|
||||||
tINT = 263,
|
|
||||||
tCONST = 264,
|
|
||||||
tPV = 265,
|
|
||||||
tCOMA = 266,
|
|
||||||
tMUL = 267,
|
|
||||||
tDIV = 268,
|
|
||||||
tADD = 269,
|
|
||||||
tSUB = 270,
|
|
||||||
tEQ = 271,
|
|
||||||
tNB = 272,
|
|
||||||
tNBEXP = 273,
|
|
||||||
tID = 274,
|
|
||||||
tPRINTF = 275,
|
|
||||||
tERROR = 276,
|
|
||||||
tIF = 277,
|
|
||||||
tWHILE = 278,
|
|
||||||
tELSE = 279,
|
|
||||||
tLT = 280,
|
|
||||||
tGT = 281,
|
|
||||||
tEQCOND = 282,
|
|
||||||
tAND = 283,
|
|
||||||
tOR = 284
|
|
||||||
};
|
|
||||||
#endif
|
|
||||||
|
|
||||||
/* Value type. */
|
|
||||||
#if ! defined YYSTYPE && ! defined YYSTYPE_IS_DECLARED
|
|
||||||
|
|
||||||
union YYSTYPE
|
|
||||||
{
|
|
||||||
#line 1 "as.y" /* yacc.c:1909 */
|
|
||||||
|
|
||||||
int nombre;
|
|
||||||
char id[30];
|
|
||||||
|
|
||||||
#line 89 "as.tab.h" /* yacc.c:1909 */
|
|
||||||
};
|
|
||||||
|
|
||||||
typedef union YYSTYPE YYSTYPE;
|
|
||||||
# define YYSTYPE_IS_TRIVIAL 1
|
|
||||||
# define YYSTYPE_IS_DECLARED 1
|
|
||||||
#endif
|
|
||||||
|
|
||||||
|
|
||||||
extern YYSTYPE yylval;
|
|
||||||
|
|
||||||
int yyparse (void);
|
|
||||||
|
|
||||||
#endif /* !YY_YY_AS_TAB_H_INCLUDED */
|
|
|
@ -1,102 +0,0 @@
|
||||||
%union {
|
|
||||||
int nombre;
|
|
||||||
char id[30];
|
|
||||||
}
|
|
||||||
%{
|
|
||||||
#include <stdio.h>
|
|
||||||
%}
|
|
||||||
|
|
||||||
%token tMAIN
|
|
||||||
%token tOBRACKET tCBRACKET
|
|
||||||
%token tOBRACE tCBRACE
|
|
||||||
%token tINT
|
|
||||||
%token tCONST
|
|
||||||
%token tPV tCOMA
|
|
||||||
%token tMUL tDIV tADD tSUB tEQ
|
|
||||||
%token<nombre> tNB tNBEXP
|
|
||||||
%token<id> tID
|
|
||||||
%token tPRINTF
|
|
||||||
%token tERROR
|
|
||||||
%token tIF tWHILE tELSE
|
|
||||||
%token tLT tGT tEQCOND
|
|
||||||
%token tAND tOR
|
|
||||||
|
|
||||||
//%type<nombre> E
|
|
||||||
|
|
||||||
%%
|
|
||||||
|
|
||||||
Main : tINT tMAIN tOBRACE Params tCBRACE Body { printf("Main reconnu\n"); } ;
|
|
||||||
|
|
||||||
Params : { printf("Sans Params\n"); } ;
|
|
||||||
Params : Param SuiteParams ;
|
|
||||||
Param : tINT tID { printf("Prametre : %s\n", $2); };
|
|
||||||
SuiteParams : tCOMA Param SuiteParams ;
|
|
||||||
SuiteParams : ;
|
|
||||||
|
|
||||||
Body : tOBRACKET Instructions tCBRACKET { printf("Body reconnu\n"); } ;
|
|
||||||
|
|
||||||
|
|
||||||
Instructions : Instruction Instructions ;
|
|
||||||
Instructions : ;
|
|
||||||
Instruction : Aff ;
|
|
||||||
Instruction : Decl ;
|
|
||||||
Instruction : Invocation tPV ;
|
|
||||||
Instruction : If;
|
|
||||||
Instruction : While;
|
|
||||||
|
|
||||||
|
|
||||||
If : tIF tOBRACE Cond tCBRACE Body Else { printf("If reconnu\n"); };
|
|
||||||
Else : tELSE If { printf("Else if reconnu\n"); };
|
|
||||||
Else : tELSE Body { printf("Else reconnu\n"); };
|
|
||||||
Else : ;
|
|
||||||
While : tWHILE tOBRACE Cond tCBRACE Body { printf("While reconnu\n"); };
|
|
||||||
|
|
||||||
Cond : E SuiteCond ;
|
|
||||||
SuiteCond : ;
|
|
||||||
SuiteCond : tAND E SuiteCond;
|
|
||||||
SuiteCond : tOR E SuiteCond;
|
|
||||||
|
|
||||||
|
|
||||||
Aff : tID tEQ E tPV { printf("%s prend une valeur\n", $1); } ;
|
|
||||||
|
|
||||||
E : tNB ;
|
|
||||||
E : tNBEXP ;
|
|
||||||
E : tID ;
|
|
||||||
E : E tADD E ;
|
|
||||||
E : E tMUL E ;
|
|
||||||
E : E tSUB E ;
|
|
||||||
E : E tDIV E ;
|
|
||||||
E : Invocation ;
|
|
||||||
E : tOBRACE E tCBRACE ;
|
|
||||||
E : tSUB E ;
|
|
||||||
E : E tEQCOND E;
|
|
||||||
E : E tGT E;
|
|
||||||
E : E tLT E;
|
|
||||||
|
|
||||||
|
|
||||||
Decl : tINT tID SuiteDecl FinDeclaration { printf("Declaration de %s\n", $2); } ;
|
|
||||||
Decl : tCONST tINT tID SuiteDecl tEQ E tPV { printf("Declaration de %s (CONSTANTE)\n", $3); } ;
|
|
||||||
SuiteDecl : tCOMA tID SuiteDecl { printf("Declaration de %s\n", $2); } ;
|
|
||||||
SuiteDecl : ;
|
|
||||||
FinDeclaration : tEQ E tPV { printf("Declaration avec valeur\n"); };
|
|
||||||
FinDeclaration : tPV { printf("Declaration sans valeur\n"); };
|
|
||||||
|
|
||||||
Invocation : tPRINTF tOBRACE tID tCBRACE { printf("Appel de printf sur %s\n", $3); } ;
|
|
||||||
|
|
||||||
/*S : E tPV
|
|
||||||
{ printf("RES: %d\n", $1); }
|
|
||||||
S
|
|
||||||
| { printf("END\n"); }
|
|
||||||
;
|
|
||||||
|
|
||||||
E : E tADD E { $$ = $1 + $3; }
|
|
||||||
| E tSUB E { $$ = $1 - $3; }
|
|
||||||
| tOB E tCB { $$ = $2; }
|
|
||||||
| tNB { $$ = $1; }
|
|
||||||
;*/
|
|
||||||
|
|
||||||
%%
|
|
||||||
#include <stdio.h>
|
|
||||||
void main(void) {
|
|
||||||
yyparse();
|
|
||||||
}
|
|
|
@ -1,5 +0,0 @@
|
||||||
bison -d as.y
|
|
||||||
flex al.lex
|
|
||||||
gcc *.c -ly
|
|
||||||
cat progC | ./a.out
|
|
||||||
|
|
|
@ -1,52 +0,0 @@
|
||||||
les fonctions (avec parametres)
|
|
||||||
le if
|
|
||||||
le while
|
|
||||||
les declarations
|
|
||||||
les affectations
|
|
||||||
les operations arith.
|
|
||||||
le retour de fonction
|
|
||||||
l'invocation de fonctions
|
|
||||||
|
|
||||||
|
|
||||||
C : Fonctions ;
|
|
||||||
Fonctions : Fonction Fonctions | Fonction ;
|
|
||||||
|
|
||||||
Fonction : tInt tID tPO Params tPF Body ;
|
|
||||||
|
|
||||||
Params : | Param SuiteParams ;
|
|
||||||
Param : tInt tID ;
|
|
||||||
|
|
||||||
SuiteParams : tVirgule Param SuiteParams | ;
|
|
||||||
|
|
||||||
// Ps : P Ps | ;
|
|
||||||
// P : tInt tID tVirgule
|
|
||||||
// Ps =>* tInt tID tVirgule tInt tID tVirgule
|
|
||||||
// Ps => P Ps => P P Ps ...
|
|
||||||
|
|
||||||
Body : tAO Instructions tAF ;
|
|
||||||
|
|
||||||
Instructions : Instruction Instructions | ;
|
|
||||||
|
|
||||||
Instruction : Aff | If | While | Return | Decl | Invocation tPV ;
|
|
||||||
|
|
||||||
Aff : tID tEQ E tPV ;
|
|
||||||
|
|
||||||
E : tNB | tID | E tADD E | E tMUL E | E tMINUS E | E tDIV E | Invocation | tPO E tPF | tMINUS E ;
|
|
||||||
|
|
||||||
// E : tID tADD tID | ...
|
|
||||||
|
|
||||||
If : tIF tPO Cond tPF Body ;
|
|
||||||
|
|
||||||
Cond : Cond tAND Cond | Cond tOR Cond | E tEQ2 E | E tINF E | tNOT Cond ;
|
|
||||||
|
|
||||||
Invocation : tID tPO Args tPF ;
|
|
||||||
|
|
||||||
Args : .... cf params
|
|
||||||
|
|
||||||
Return : tRET E tPV ;
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
File diff suppressed because it is too large
Load diff
|
@ -1,17 +0,0 @@
|
||||||
int main(int x, int i){
|
|
||||||
const int a = 4;
|
|
||||||
const int a, b, c = 2 + a - 5 * (7 / 8);
|
|
||||||
printf(coucou);
|
|
||||||
int y = 7e8;
|
|
||||||
int res_2 = x + y;
|
|
||||||
|
|
||||||
if ( (a == 2) && b || c > (7*8)) {
|
|
||||||
}
|
|
||||||
else if (a) {
|
|
||||||
int x = 90;
|
|
||||||
} else {
|
|
||||||
int a = b;
|
|
||||||
}
|
|
||||||
/* SAlut Elies */
|
|
||||||
printf(i);
|
|
||||||
}
|
|
|
@ -1,109 +0,0 @@
|
||||||
/* TABLE DES SYMBOLE DU COMPILATEUR (PILE)
|
|
||||||
|
|
||||||
-----------------------------------------------------
|
|
||||||
| symbole | adresse | type | initialisé |
|
|
||||||
-----------------------------------------------------
|
|
||||||
| | | | |
|
|
||||||
| | | | |
|
|
||||||
| | | | |
|
|
||||||
| i | 0x777756b8 | int | false |
|
|
||||||
| size | 0x777756b8 | int | true |
|
|
||||||
-----------------------------------------------------
|
|
||||||
|
|
||||||
Types pour l'implémentation :
|
|
||||||
- enum type_t : [int]
|
|
||||||
- struct symbole : {
|
|
||||||
char nom[30];
|
|
||||||
uintptr_t adresse;
|
|
||||||
enum type_t type;
|
|
||||||
char initialized;
|
|
||||||
}
|
|
||||||
|
|
||||||
Opérations possible :
|
|
||||||
- init -> pile * -> void
|
|
||||||
- push -> symbole -> pile * -> void
|
|
||||||
- pop -> pile * -> symbole
|
|
||||||
- exist -> pile * -> symbole -> char
|
|
||||||
- initialized -> pile * -> symbole -> char */
|
|
||||||
|
|
||||||
#include "table_symboles.h"
|
|
||||||
#include <stdlib.h>
|
|
||||||
#include <string.h>
|
|
||||||
#include <stdio.h>
|
|
||||||
|
|
||||||
struct element_t {
|
|
||||||
struct symbole_t symbole;
|
|
||||||
struct element_t * suivant;
|
|
||||||
};
|
|
||||||
|
|
||||||
struct pile_t {
|
|
||||||
int taille;
|
|
||||||
struct element_t * first;
|
|
||||||
};
|
|
||||||
|
|
||||||
char * type_to_string(enum type_t type) {
|
|
||||||
if (type == INT) {
|
|
||||||
return "int";
|
|
||||||
} else {
|
|
||||||
return "unknown";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void init(struct pile_t * pile) {
|
|
||||||
pile->first = NULL;
|
|
||||||
pile->taille = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
void push(struct symbole_t symbole, struct pile_t * pile) {
|
|
||||||
struct element_t * aux = malloc(sizeof(struct element_t));
|
|
||||||
aux->symbole = symbole;
|
|
||||||
aux->suivant = pile->first;
|
|
||||||
pile->first = aux;
|
|
||||||
pile->taille++;
|
|
||||||
}
|
|
||||||
|
|
||||||
struct symbole_t pop(struct pile_t * pile) {
|
|
||||||
struct symbole_t retour = {"", 0, UNKNOWN, -1};
|
|
||||||
struct element_t * aux;
|
|
||||||
if (pile->taille > 0) {
|
|
||||||
aux = pile->first;
|
|
||||||
pile->first = pile->first->suivant;
|
|
||||||
retour = aux->symbole;
|
|
||||||
free(aux);
|
|
||||||
pile->taille--;
|
|
||||||
}
|
|
||||||
return retour;
|
|
||||||
}
|
|
||||||
|
|
||||||
char status(char * nom, struct pile_t pile) {
|
|
||||||
char retour = 0;
|
|
||||||
struct element_t * aux = pile.first;
|
|
||||||
int i;
|
|
||||||
for (i=0; i < pile.taille; i++) {
|
|
||||||
if (!strcmp(nom, aux->symbole.nom)) {
|
|
||||||
if (aux->symbole.initialized) {
|
|
||||||
retour = 1;
|
|
||||||
} else {
|
|
||||||
retour = 2;
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
} else {
|
|
||||||
aux = aux->suivant;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return retour;
|
|
||||||
}
|
|
||||||
|
|
||||||
void print(struct pile_t pile) {
|
|
||||||
printf("Affichage de la Table des Symboles\n\tSize : %d\n\tContenu : \n", pile.taille);
|
|
||||||
struct element_t * aux = pile.first;
|
|
||||||
int i;
|
|
||||||
for (i=0; i < pile.taille; i++) {
|
|
||||||
if (aux->symbole.initialized) {
|
|
||||||
printf("\t\t{nom:%s, adresse:%p, type:%s, initialized:OUI}\n", aux->symbole.nom, (void *)(aux->symbole.adresse), type_to_string(aux->symbole.type));
|
|
||||||
} else {
|
|
||||||
printf("\t\t{nom:%s, adresse:%p, type:%s, initialized:NON}\n", aux->symbole.nom, (void *)(aux->symbole.adresse), type_to_string(aux->symbole.type));
|
|
||||||
}
|
|
||||||
aux = aux->suivant;
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,48 +0,0 @@
|
||||||
/* TABLE DES SYMBOLE DU COMPILATEUR (PILE)
|
|
||||||
|
|
||||||
-----------------------------------------------------
|
|
||||||
| symbole | adresse | type | initialisé |
|
|
||||||
-----------------------------------------------------
|
|
||||||
| | | | |
|
|
||||||
| | | | |
|
|
||||||
| | | | |
|
|
||||||
| i | 0x777756b8 | int | false |
|
|
||||||
| size | 0x777756b8 | int | true |
|
|
||||||
-----------------------------------------------------
|
|
||||||
|
|
||||||
Types pour l'implémentation :
|
|
||||||
- enum type_t : [int]
|
|
||||||
- struct symbole : {
|
|
||||||
char nom[30];
|
|
||||||
uintptr_t adresse;
|
|
||||||
enum type_t type;
|
|
||||||
char initialized;
|
|
||||||
}
|
|
||||||
|
|
||||||
Opérations possible :
|
|
||||||
- init -> pile * -> void
|
|
||||||
- push -> symbole -> pile * -> void
|
|
||||||
- pop -> pile * -> symbole
|
|
||||||
- status -> nom -> pile -> char */
|
|
||||||
|
|
||||||
#include <stdint.h>
|
|
||||||
|
|
||||||
enum type_t {UNKNOWN, INT};
|
|
||||||
|
|
||||||
struct symbole_t {
|
|
||||||
char nom[30];
|
|
||||||
uintptr_t adresse;
|
|
||||||
enum type_t type;
|
|
||||||
char initialized;
|
|
||||||
};
|
|
||||||
|
|
||||||
struct pile_t;
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
void init(struct pile_t * pile);
|
|
||||||
void push(struct symbole_t symbole, struct pile_t * pile);
|
|
||||||
struct symbole_t pop(struct pile_t * pile);
|
|
||||||
// renvoi 0 si nom n'existe pas, 2 si nom existe sans etre initialisée, 1 sinon
|
|
||||||
char status(char * nom, struct pile_t pile);
|
|
||||||
void print(struct pile_t pile);
|
|
Binary file not shown.
|
@ -1,15 +1,3 @@
|
||||||
int main(int x, int i){
|
int main(){
|
||||||
const int a = 4;
|
int a = 4;
|
||||||
const int a, b, c = 2 + a - 5 * (7 / 8) + 5;
|
|
||||||
printf(coucou);
|
|
||||||
int y = 7e8;
|
|
||||||
int res_2 = x + y;
|
|
||||||
if ( (a == 2) && b || c > (7*8)) {
|
|
||||||
}
|
|
||||||
else if (a) {
|
|
||||||
int x = 90;
|
|
||||||
} else {
|
|
||||||
int a = b;
|
|
||||||
}
|
|
||||||
printf(i);
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,4 +0,0 @@
|
||||||
int main(int a, int b)
|
|
||||||
{
|
|
||||||
int c;
|
|
||||||
}
|
|
BIN
Lex_Yacc/a.exe
BIN
Lex_Yacc/a.exe
Binary file not shown.
1367
Lex_Yacc/as.output
1367
Lex_Yacc/as.output
File diff suppressed because it is too large
Load diff
1853
Lex_Yacc/as.tab.c
1853
Lex_Yacc/as.tab.c
File diff suppressed because it is too large
Load diff
|
@ -1,105 +0,0 @@
|
||||||
/* A Bison parser, made by GNU Bison 3.5.1. */
|
|
||||||
|
|
||||||
/* Bison interface for Yacc-like parsers in C
|
|
||||||
|
|
||||||
Copyright (C) 1984, 1989-1990, 2000-2015, 2018-2020 Free Software Foundation,
|
|
||||||
Inc.
|
|
||||||
|
|
||||||
This program is free software: you can redistribute it and/or modify
|
|
||||||
it under the terms of the GNU General Public License as published by
|
|
||||||
the Free Software Foundation, either version 3 of the License, or
|
|
||||||
(at your option) any later version.
|
|
||||||
|
|
||||||
This program is distributed in the hope that it will be useful,
|
|
||||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
GNU General Public License for more details.
|
|
||||||
|
|
||||||
You should have received a copy of the GNU General Public License
|
|
||||||
along with this program. If not, see <http://www.gnu.org/licenses/>. */
|
|
||||||
|
|
||||||
/* As a special exception, you may create a larger work that contains
|
|
||||||
part or all of the Bison parser skeleton and distribute that work
|
|
||||||
under terms of your choice, so long as that work isn't itself a
|
|
||||||
parser generator using the skeleton or a modified version thereof
|
|
||||||
as a parser skeleton. Alternatively, if you modify or redistribute
|
|
||||||
the parser skeleton itself, you may (at your option) remove this
|
|
||||||
special exception, which will cause the skeleton and the resulting
|
|
||||||
Bison output files to be licensed under the GNU General Public
|
|
||||||
License without this special exception.
|
|
||||||
|
|
||||||
This special exception was added by the Free Software Foundation in
|
|
||||||
version 2.2 of Bison. */
|
|
||||||
|
|
||||||
/* Undocumented macros, especially those whose name start with YY_,
|
|
||||||
are private implementation details. Do not rely on them. */
|
|
||||||
|
|
||||||
#ifndef YY_YY_AS_TAB_H_INCLUDED
|
|
||||||
# define YY_YY_AS_TAB_H_INCLUDED
|
|
||||||
/* Debug traces. */
|
|
||||||
#ifndef YYDEBUG
|
|
||||||
# define YYDEBUG 1
|
|
||||||
#endif
|
|
||||||
#if YYDEBUG
|
|
||||||
extern int yydebug;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
/* Token type. */
|
|
||||||
#ifndef YYTOKENTYPE
|
|
||||||
# define YYTOKENTYPE
|
|
||||||
enum yytokentype
|
|
||||||
{
|
|
||||||
tMAIN = 258,
|
|
||||||
tOBRACKET = 259,
|
|
||||||
tCBRACKET = 260,
|
|
||||||
tOBRACE = 261,
|
|
||||||
tCBRACE = 262,
|
|
||||||
tINT = 263,
|
|
||||||
tCONST = 264,
|
|
||||||
tPV = 265,
|
|
||||||
tCOMA = 266,
|
|
||||||
tMUL = 267,
|
|
||||||
tDIV = 268,
|
|
||||||
tADD = 269,
|
|
||||||
tSUB = 270,
|
|
||||||
tEQ = 271,
|
|
||||||
tNB = 272,
|
|
||||||
tNBEXP = 273,
|
|
||||||
tID = 274,
|
|
||||||
tPRINTF = 275,
|
|
||||||
tERROR = 276,
|
|
||||||
tIF = 277,
|
|
||||||
tWHILE = 278,
|
|
||||||
tELSE = 279,
|
|
||||||
tLT = 280,
|
|
||||||
tGT = 281,
|
|
||||||
tEQCOND = 282,
|
|
||||||
tAND = 283,
|
|
||||||
tOR = 284,
|
|
||||||
tNOT = 285
|
|
||||||
};
|
|
||||||
#endif
|
|
||||||
|
|
||||||
/* Value type. */
|
|
||||||
#if ! defined YYSTYPE && ! defined YYSTYPE_IS_DECLARED
|
|
||||||
union YYSTYPE
|
|
||||||
{
|
|
||||||
#line 1 "as.y"
|
|
||||||
|
|
||||||
int nombre;
|
|
||||||
char id[30];
|
|
||||||
|
|
||||||
#line 93 "as.tab.h"
|
|
||||||
|
|
||||||
};
|
|
||||||
typedef union YYSTYPE YYSTYPE;
|
|
||||||
# define YYSTYPE_IS_TRIVIAL 1
|
|
||||||
# define YYSTYPE_IS_DECLARED 1
|
|
||||||
#endif
|
|
||||||
|
|
||||||
|
|
||||||
extern YYSTYPE yylval;
|
|
||||||
|
|
||||||
int yyparse (void);
|
|
||||||
|
|
||||||
#endif /* !YY_YY_AS_TAB_H_INCLUDED */
|
|
|
@ -3,11 +3,11 @@
|
||||||
char id[30];
|
char id[30];
|
||||||
}
|
}
|
||||||
%{
|
%{
|
||||||
#include "../Symboles/table_symboles.h"
|
#include "../Tables/Symboles/table_symboles.h"
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include "../Symboles/tab_instruc.h"
|
#include "../Tables/Instructions/tab_instruc.h"
|
||||||
#define TAILLE 1024
|
#define TAILLE 1024
|
||||||
|
|
||||||
enum type_t type_courant;
|
enum type_t type_courant;
|
||||||
|
@ -84,10 +84,10 @@ E : tNB { int addr = allocate_mem_temp_var(INT); add_operation(AFC, addr,$1,0);
|
||||||
|
|
||||||
E : tNBEXP { printf("Nombre exp\n"); int addr = allocate_mem_temp_var(INT); add_operation(AFC, addr,$1,0); $$ = addr;};
|
E : tNBEXP { printf("Nombre exp\n"); int addr = allocate_mem_temp_var(INT); add_operation(AFC, addr,$1,0); $$ = addr;};
|
||||||
E : tID { printf("Id\n"); /*Faire un get_address sur la pile*/};
|
E : tID { printf("Id\n"); /*Faire un get_address sur la pile*/};
|
||||||
E : E tMUL E { printf("Mul\n"); int addr = allocate_mem_temp_var(INT); add_operation(MUL, addr,$1,$2); $$ = addr;};
|
E : E tMUL E { printf("Mul\n"); int addr = allocate_mem_temp_var(INT); add_operation(MUL, addr,$1,$3); $$ = addr;};
|
||||||
E : E tDIV E { printf("Div\n"); int addr = allocate_mem_temp_var(INT); add_operation(DIV, addr,$1,$2); $$ = addr;};
|
E : E tDIV E { printf("Div\n"); int addr = allocate_mem_temp_var(INT); add_operation(DIV, addr,$1,$3); $$ = addr;};
|
||||||
E : E tSUB E { printf("Sub\n"); int addr = allocate_mem_temp_var(INT); add_operation(SOU, addr,$1,$2); $$ = addr;};
|
E : E tSUB E { printf("Sub\n"); int addr = allocate_mem_temp_var(INT); add_operation(SOU, addr,$1,$3); $$ = addr;};
|
||||||
E : E tADD E { printf("Add\n"); int addr = allocate_mem_temp_var(INT); add_operation(ADD, addr,$1,$2); $$ = addr;};
|
E : E tADD E { printf("Add\n"); int addr = allocate_mem_temp_var(INT); add_operation(ADD, addr,$1,$3); $$ = addr;};
|
||||||
E : Invocation { printf("Invoc\n"); int addr = allocate_mem_temp_var(INT); add_operation(AFC, addr,$1,0); $$ = addr;};
|
E : Invocation { printf("Invoc\n"); int addr = allocate_mem_temp_var(INT); add_operation(AFC, addr,$1,0); $$ = addr;};
|
||||||
E : tOBRACE E tCBRACE { printf("Parentheses\n"); $$=$2;};
|
E : tOBRACE E tCBRACE { printf("Parentheses\n"); $$=$2;};
|
||||||
E : tSUB E { printf("Moins\n"); int addr = allocate_mem_temp_var(INT); add_operation(SOU, 0,addr,0); $$ = addr;};
|
E : tSUB E { printf("Moins\n"); int addr = allocate_mem_temp_var(INT); add_operation(SOU, 0,addr,0); $$ = addr;};
|
||||||
|
|
|
@ -1,4 +0,0 @@
|
||||||
bison -d -t as.y -v
|
|
||||||
flex al.lex
|
|
||||||
gcc as.tab.c lex.yy.c ../Symboles/tab_instruc.c ../Symboles/table_symboles.c -ll -o a.exe
|
|
||||||
cat ./ProgC | ./a.exe
|
|
1936
Lex_Yacc/lex.yy.c
1936
Lex_Yacc/lex.yy.c
File diff suppressed because it is too large
Load diff
Binary file not shown.
59
Makefile
Normal file
59
Makefile
Normal file
|
@ -0,0 +1,59 @@
|
||||||
|
default :
|
||||||
|
@echo "Spécifiez une cible"
|
||||||
|
|
||||||
|
clean : clean_Symboles clean_Instructions clean_Lex_Yacc
|
||||||
|
@rm -f rondoudou_gcc
|
||||||
|
@rm -f output.txt
|
||||||
|
|
||||||
|
clean_Symboles:
|
||||||
|
@rm -f Tables/Symboles/*.o
|
||||||
|
@rm -f Tables/Symboles/test
|
||||||
|
|
||||||
|
clean_Instructions:
|
||||||
|
@rm -f Tables/Instructions/*.o
|
||||||
|
@rm -f Tables/Instructions/test
|
||||||
|
|
||||||
|
clean_Lex_Yacc:
|
||||||
|
@rm -f Lex_Yacc/as.output Lex_Yacc/as.tab.* Lex_Yacc/lex.yy.*
|
||||||
|
|
||||||
|
build : clean build_Symboles build_Instructions build_Lex_Yacc
|
||||||
|
gcc Lex_Yacc/as.tab.o Lex_Yacc/lex.yy.o Tables/Instructions/tab_instruc.o Tables/Symboles/table_symboles.o -ll -o rondoudou_gcc
|
||||||
|
|
||||||
|
build_Symboles: clean_Symboles
|
||||||
|
gcc -c Tables/Symboles/table_symboles.c -o Tables/Symboles/table_symboles.o
|
||||||
|
|
||||||
|
build_Instructions: clean_Instructions
|
||||||
|
gcc -c Tables/Instructions/tab_instruc.c -o Tables/Instructions/tab_instruc.o
|
||||||
|
|
||||||
|
build_Lex_Yacc: clean_Lex_Yacc
|
||||||
|
bison -d -t -b Lex_Yacc/as Lex_Yacc/as.y
|
||||||
|
flex -o Lex_Yacc/lex.yy.c Lex_Yacc/al.lex
|
||||||
|
gcc -c Lex_Yacc/as.tab.c -o Lex_Yacc/as.tab.o
|
||||||
|
gcc -c Lex_Yacc/lex.yy.c -o Lex_Yacc/lex.yy.o
|
||||||
|
|
||||||
|
test_Symboles: build_Symboles
|
||||||
|
gcc -c Tables/Symboles/test.c -o Tables/Symboles/test.o
|
||||||
|
gcc Tables/Symboles/test.o Tables/Symboles/table_symboles.o -o Tables/Symboles/test
|
||||||
|
Tables/Symboles/test
|
||||||
|
|
||||||
|
test_Instructions: build_Instructions
|
||||||
|
gcc -c Tables/Instructions/test.c -o Tables/Instructions/test.o
|
||||||
|
gcc Tables/Instructions/test.o Tables/Instructions/tab_instruc.o -o Tables/Instructions/test
|
||||||
|
Tables/Instructions/test
|
||||||
|
|
||||||
|
test: build
|
||||||
|
cat Fichiers_Tests/progC | ./rondoudou_gcc
|
||||||
|
|
||||||
|
edit_Lex_Yacc:
|
||||||
|
pluma Lex_Yacc/al.lex Lex_Yacc/as.y &
|
||||||
|
|
||||||
|
edit_Symboles:
|
||||||
|
pluma Tables/Symboles/table_symboles.c Tables/Symboles/table_symboles.h &
|
||||||
|
|
||||||
|
edit_Instructions:
|
||||||
|
pluma Tables/Instructions/tab_instruc.c Tables/Instructions/tab_instruc.h &
|
||||||
|
|
||||||
|
edit_Progs:
|
||||||
|
pluma Fichiers_Tests/progC &
|
||||||
|
|
||||||
|
edit: edit_Lex_Yacc edit_Symboles edit_Instructions edit_Progs
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Loading…
Reference in a new issue