Préparation pour test intermediaire

- Analyseur lexical OK
- Analyseur syntaxyque OK
This commit is contained in:
2016-02-09 15:45:20 +01:00
parent 3b5b693f67
commit 755d2b6140
63 changed files with 8847 additions and 49 deletions

View File

@@ -14,6 +14,7 @@
void openSection ( const char * section ); void openSection ( const char * section );
void closeSection ( const char * section ); void closeSection ( const char * section );
void elementConsome ();
void syntaxError (void); void syntaxError (void);
void syntaxErrorMsg( const char * msg ); void syntaxErrorMsg( const char * msg );
void programme (void); void programme (void);

View File

@@ -210,16 +210,6 @@ void nom_token( int token, char *nom, char *valeur ) {
else if(token == FIN) strcpy(valeur, "FIN"); else if(token == FIN) strcpy(valeur, "FIN");
else if(token == VIRGULE) strcpy(valeur, "VIRGULE"); else if(token == VIRGULE) strcpy(valeur, "VIRGULE");
else if(token == SI) strcpy(valeur, "SI");
else if(token == ALORS) strcpy(valeur, "ALORS");
else if(token == SINON) strcpy(valeur, "SINON");
else if(token == TANTQUE) strcpy(valeur, "TANTQUE");
else if(token == FAIRE) strcpy(valeur, "FAIRE");
else if(token == ENTIER) strcpy(valeur, "ENTIER");
else if(token == RETOUR) strcpy(valeur, "RETOUR");
else if(token == LIRE) strcpy(valeur, "LIRE");
else if(token == ECRIRE) strcpy(valeur, "ECRIRE");
else if( token == ID_VAR ) { else if( token == ID_VAR ) {
strcpy( nom, "id_variable" ); strcpy( nom, "id_variable" );
strcpy( valeur, yytext ); strcpy( valeur, yytext );

View File

@@ -1,15 +1,23 @@
#include "analyseur_syntaxyque.h" #include "analyseur_syntaxyque.h"
int uniteCourante; int uniteCourante;
int afficheSyntaxyque = 1;
extern char yytext[100]; extern char yytext[100];
extern int nb_ligne; extern int nb_ligne;
void openSection( const char * section ) { void openSection( const char * section ) {
affiche_balise_ouvrante( section, 1 ); affiche_balise_ouvrante( section, afficheSyntaxyque );
} }
void closeSection( const char * section ) { void closeSection( const char * section ) {
affiche_balise_fermante( section, 1 ); affiche_balise_fermante( section, afficheSyntaxyque );
}
void elementConsome () {
char token[128];
char nom[128];
nom_token( uniteCourante, nom, token );
affiche_element(nom, token, afficheSyntaxyque);
} }
void syntaxError() void syntaxError()
@@ -36,7 +44,7 @@ void syntaxErrorMsg( const char * msg )
void programme() { void programme() {
openSection( __func__ ); openSection( __func__ );
if( est_premier( _optDecVariables_, uniteCourante ) ) { if( est_premier( _optDecVariables_, uniteCourante ) || est_premier( _listeDecFonctions_, uniteCourante )) {
optDecVariables(); optDecVariables();
listeDecFonctions(); listeDecFonctions();
} else { } else {
@@ -54,6 +62,7 @@ void optDecVariables() {
listeDecVariables(); listeDecVariables();
if( uniteCourante == POINT_VIRGULE ) { if( uniteCourante == POINT_VIRGULE ) {
elementConsome();
uniteCourante = yylex(); uniteCourante = yylex();
} else { } else {
syntaxErrorMsg( "';' été attendu" ); syntaxErrorMsg( "';' été attendu" );
@@ -82,6 +91,7 @@ void listeDecVariablesBis() {
openSection( __func__ ); openSection( __func__ );
if( uniteCourante == VIRGULE ) { if( uniteCourante == VIRGULE ) {
elementConsome();
uniteCourante = yylex(); uniteCourante = yylex();
declarationVariable(); declarationVariable();
@@ -97,9 +107,11 @@ void declarationVariable() {
openSection( __func__ ); openSection( __func__ );
if( uniteCourante == ENTIER ) { if( uniteCourante == ENTIER ) {
elementConsome();
uniteCourante = yylex(); uniteCourante = yylex();
if( uniteCourante == ID_VAR ) { if( uniteCourante == ID_VAR ) {
elementConsome();
uniteCourante = yylex(); uniteCourante = yylex();
optTailleTableau(); optTailleTableau();
@@ -117,12 +129,15 @@ void optTailleTableau() {
openSection( __func__ ); openSection( __func__ );
if( uniteCourante == CROCHET_OUVRANT ) { if( uniteCourante == CROCHET_OUVRANT ) {
elementConsome();
uniteCourante = yylex(); uniteCourante = yylex();
if( uniteCourante == NOMBRE ) { if( uniteCourante == NOMBRE ) {
elementConsome();
uniteCourante = yylex(); uniteCourante = yylex();
if( uniteCourante == CROCHET_FERMANT ) { if( uniteCourante == CROCHET_FERMANT ) {
elementConsome();
uniteCourante = yylex(); uniteCourante = yylex();
} else { } else {
syntaxErrorMsg( "']' été attendu" ); syntaxErrorMsg( "']' été attendu" );
@@ -155,6 +170,7 @@ void declarationFonction() {
openSection( __func__ ); openSection( __func__ );
if( uniteCourante == ID_FCT ) { if( uniteCourante == ID_FCT ) {
elementConsome();
uniteCourante = yylex(); uniteCourante = yylex();
listeParam(); listeParam();
@@ -171,11 +187,13 @@ void listeParam() {
openSection( __func__ ); openSection( __func__ );
if( uniteCourante == PARENTHESE_OUVRANTE ) { if( uniteCourante == PARENTHESE_OUVRANTE ) {
elementConsome();
uniteCourante = yylex(); uniteCourante = yylex();
optListeDecVariables(); optListeDecVariables();
if( uniteCourante == PARENTHESE_FERMANTE ) { if( uniteCourante == PARENTHESE_FERMANTE ) {
elementConsome();
uniteCourante = yylex(); uniteCourante = yylex();
} else { } else {
syntaxErrorMsg( "')' été attendu" ); syntaxErrorMsg( "')' été attendu" );
@@ -232,11 +250,13 @@ void instructionAffect() {
var(); var();
if( uniteCourante == EGAL ) { if( uniteCourante == EGAL ) {
elementConsome();
uniteCourante = yylex(); uniteCourante = yylex();
expression(); expression();
if( uniteCourante == POINT_VIRGULE ) { if( uniteCourante == POINT_VIRGULE ) {
elementConsome();
uniteCourante = yylex(); uniteCourante = yylex();
} else { } else {
syntaxErrorMsg( "';' été attendu" ); syntaxErrorMsg( "';' été attendu" );
@@ -255,11 +275,13 @@ void instructionBloc() {
openSection( __func__ ); openSection( __func__ );
if( uniteCourante == ACCOLADE_OUVRANTE ) { if( uniteCourante == ACCOLADE_OUVRANTE ) {
elementConsome();
uniteCourante = yylex(); uniteCourante = yylex();
listeInstructions(); listeInstructions();
if( uniteCourante == ACCOLADE_FERMANTE ) { if( uniteCourante == ACCOLADE_FERMANTE ) {
elementConsome();
uniteCourante = yylex(); uniteCourante = yylex();
} else { } else {
syntaxErrorMsg( "'}' été attendu" ); syntaxErrorMsg( "'}' été attendu" );
@@ -288,11 +310,13 @@ void instructionSi() {
openSection( __func__ ); openSection( __func__ );
if( uniteCourante == SI ) { if( uniteCourante == SI ) {
elementConsome();
uniteCourante = yylex(); uniteCourante = yylex();
expression(); expression();
if( uniteCourante == ALORS ) { if( uniteCourante == ALORS ) {
elementConsome();
uniteCourante = yylex(); uniteCourante = yylex();
instructionBloc(); instructionBloc();
@@ -311,6 +335,7 @@ void optSinon() {
openSection( __func__ ); openSection( __func__ );
if( uniteCourante == SINON ) { if( uniteCourante == SINON ) {
elementConsome();
uniteCourante = yylex(); uniteCourante = yylex();
instructionBloc(); instructionBloc();
@@ -325,11 +350,13 @@ void instructionTantque() {
openSection( __func__ ); openSection( __func__ );
if( uniteCourante == TANTQUE ) { if( uniteCourante == TANTQUE ) {
elementConsome();
uniteCourante = yylex(); uniteCourante = yylex();
expression(); expression();
if( uniteCourante == FAIRE ) { if( uniteCourante == FAIRE ) {
elementConsome();
uniteCourante = yylex(); uniteCourante = yylex();
instructionBloc(); instructionBloc();
@@ -350,6 +377,7 @@ void instructionAppel() {
appelFct(); appelFct();
if( uniteCourante == POINT_VIRGULE ) { if( uniteCourante == POINT_VIRGULE ) {
elementConsome();
uniteCourante = yylex(); uniteCourante = yylex();
} else { } else {
syntaxErrorMsg( "';' été attendu" ); syntaxErrorMsg( "';' été attendu" );
@@ -365,11 +393,13 @@ void instructionRetour() {
openSection( __func__ ); openSection( __func__ );
if( uniteCourante == RETOUR ) { if( uniteCourante == RETOUR ) {
elementConsome();
uniteCourante = yylex(); uniteCourante = yylex();
expression(); expression();
if( uniteCourante == POINT_VIRGULE ) { if( uniteCourante == POINT_VIRGULE ) {
elementConsome();
uniteCourante = yylex(); uniteCourante = yylex();
} else { } else {
syntaxErrorMsg( "';' été attendu" ); syntaxErrorMsg( "';' été attendu" );
@@ -385,17 +415,21 @@ void instructionEcriture() {
openSection( __func__ ); openSection( __func__ );
if( uniteCourante == ECRIRE ) { if( uniteCourante == ECRIRE ) {
elementConsome();
uniteCourante = yylex(); uniteCourante = yylex();
if( uniteCourante == PARENTHESE_OUVRANTE ) { if( uniteCourante == PARENTHESE_OUVRANTE ) {
elementConsome();
uniteCourante = yylex(); uniteCourante = yylex();
expression(); expression();
if( uniteCourante == PARENTHESE_FERMANTE ) { if( uniteCourante == PARENTHESE_FERMANTE ) {
elementConsome();
uniteCourante = yylex(); uniteCourante = yylex();
if( uniteCourante == POINT_VIRGULE ) { if( uniteCourante == POINT_VIRGULE ) {
elementConsome();
uniteCourante = yylex(); uniteCourante = yylex();
} else { } else {
syntaxErrorMsg( "';' été attendu" ); syntaxErrorMsg( "';' été attendu" );
@@ -417,6 +451,7 @@ void instructionVide() {
openSection( __func__ ); openSection( __func__ );
if( uniteCourante == POINT_VIRGULE ) { if( uniteCourante == POINT_VIRGULE ) {
elementConsome();
uniteCourante = yylex(); uniteCourante = yylex();
} else { } else {
syntaxErrorMsg( "';' été attendu" ); syntaxErrorMsg( "';' été attendu" );
@@ -442,6 +477,7 @@ void expressionBis() {
openSection( __func__ ); openSection( __func__ );
if( uniteCourante == OU ) { if( uniteCourante == OU ) {
elementConsome();
uniteCourante = yylex(); uniteCourante = yylex();
conjonction(); conjonction();
@@ -470,6 +506,7 @@ void conjonctionBis() {
openSection( __func__ ); openSection( __func__ );
if( uniteCourante == ET ) { if( uniteCourante == ET ) {
elementConsome();
uniteCourante = yylex(); uniteCourante = yylex();
negation(); negation();
@@ -485,6 +522,7 @@ void negation() {
openSection( __func__ ); openSection( __func__ );
if( uniteCourante == NON ) { if( uniteCourante == NON ) {
elementConsome();
uniteCourante = yylex(); uniteCourante = yylex();
comparaison(); comparaison();
@@ -513,7 +551,14 @@ void comparaison() {
void comparaisonBis() { void comparaisonBis() {
openSection( __func__ ); openSection( __func__ );
if( uniteCourante == EGAL || uniteCourante == INFERIEUR) { if( uniteCourante == EGAL) {
elementConsome();
uniteCourante = yylex();
expArith();
comparaisonBis();
} else if( uniteCourante == INFERIEUR) {
elementConsome();
uniteCourante = yylex(); uniteCourante = yylex();
expArith(); expArith();
@@ -542,7 +587,14 @@ void expArith()
void expArithBis() { void expArithBis() {
openSection( __func__ ); openSection( __func__ );
if( uniteCourante == PLUS || uniteCourante == MOINS) { if( uniteCourante == PLUS ) {
elementConsome();
uniteCourante = yylex();
terme();
expArithBis();
} else if( uniteCourante == MOINS) {
elementConsome();
uniteCourante = yylex(); uniteCourante = yylex();
terme(); terme();
@@ -570,7 +622,14 @@ void terme() {
void termeBis() { void termeBis() {
openSection( __func__ ); openSection( __func__ );
if( uniteCourante == FOIS || uniteCourante == DIVISE ) { if( uniteCourante == FOIS ) {
elementConsome();
uniteCourante = yylex();
facteur();
termeBis();
} else if( uniteCourante == DIVISE) {
elementConsome();
uniteCourante = yylex(); uniteCourante = yylex();
facteur(); facteur();
@@ -586,28 +645,34 @@ void facteur() {
openSection( __func__ ); openSection( __func__ );
if( uniteCourante == PARENTHESE_OUVRANTE ) { if( uniteCourante == PARENTHESE_OUVRANTE ) {
elementConsome();
uniteCourante = yylex(); uniteCourante = yylex();
expression(); expression();
if( uniteCourante == PARENTHESE_FERMANTE ) { if( uniteCourante == PARENTHESE_FERMANTE ) {
elementConsome();
uniteCourante = yylex(); uniteCourante = yylex();
} else { } else {
syntaxErrorMsg( "')' été attendu" ); syntaxErrorMsg( "')' été attendu" );
} }
} else if( uniteCourante == NOMBRE ) { } else if( uniteCourante == NOMBRE ) {
elementConsome();
uniteCourante = yylex(); uniteCourante = yylex();
} else if( est_premier( _appelFct_, uniteCourante ) ) { } else if( est_premier( _appelFct_, uniteCourante ) ) {
appelFct(); appelFct();
} else if( est_premier( _var_, uniteCourante ) ) { } else if( est_premier( _var_, uniteCourante ) ) {
var(); var();
} else if( uniteCourante == LIRE ) { } else if( uniteCourante == LIRE ) {
elementConsome();
uniteCourante = yylex(); uniteCourante = yylex();
if( uniteCourante == PARENTHESE_OUVRANTE ) { if( uniteCourante == PARENTHESE_OUVRANTE ) {
elementConsome();
uniteCourante = yylex(); uniteCourante = yylex();
if( uniteCourante == PARENTHESE_FERMANTE ) { if( uniteCourante == PARENTHESE_FERMANTE ) {
elementConsome();
uniteCourante = yylex(); uniteCourante = yylex();
} else { } else {
syntaxErrorMsg( "')' été attendu" ); syntaxErrorMsg( "')' été attendu" );
@@ -626,6 +691,7 @@ void var() {
openSection( __func__ ); openSection( __func__ );
if( uniteCourante == ID_VAR ) { if( uniteCourante == ID_VAR ) {
elementConsome();
uniteCourante = yylex(); uniteCourante = yylex();
optIndice(); optIndice();
@@ -640,11 +706,13 @@ void optIndice() {
openSection( __func__ ); openSection( __func__ );
if( uniteCourante == CROCHET_OUVRANT ) { if( uniteCourante == CROCHET_OUVRANT ) {
elementConsome();
uniteCourante = yylex(); uniteCourante = yylex();
expression(); expression();
if( uniteCourante == CROCHET_FERMANT ) { if( uniteCourante == CROCHET_FERMANT ) {
elementConsome();
uniteCourante = yylex(); uniteCourante = yylex();
} else { } else {
syntaxErrorMsg( "']' été attendu" ); syntaxErrorMsg( "']' été attendu" );
@@ -660,14 +728,17 @@ void appelFct() {
openSection( __func__ ); openSection( __func__ );
if( uniteCourante == ID_FCT ) { if( uniteCourante == ID_FCT ) {
elementConsome();
uniteCourante = yylex(); uniteCourante = yylex();
if( uniteCourante == PARENTHESE_OUVRANTE ) { if( uniteCourante == PARENTHESE_OUVRANTE ) {
elementConsome();
uniteCourante = yylex(); uniteCourante = yylex();
listeExpressions(); listeExpressions();
if( uniteCourante == PARENTHESE_FERMANTE ) { if( uniteCourante == PARENTHESE_FERMANTE ) {
elementConsome();
uniteCourante = yylex(); uniteCourante = yylex();
} else { } else {
syntaxErrorMsg( "')' été attendu" ); syntaxErrorMsg( "')' été attendu" );
@@ -699,6 +770,7 @@ void listeExpressionsBis() {
openSection( __func__ ); openSection( __func__ );
if( uniteCourante == VIRGULE ) { if( uniteCourante == VIRGULE ) {
elementConsome();
uniteCourante = yylex(); uniteCourante = yylex();
expression(); expression();

View File

@@ -11,23 +11,26 @@ FILE *yyin;
int main(int argc, char **argv) { int main(int argc, char **argv) {
yyin = fopen(argv[1], "r"); yyin = fopen(argv[2], "r");
if(argc == 0 && yyin == NULL){ if(argc < 3 && yyin == NULL){
fprintf(stderr, "impossible d'ouvrir le fichier %s\n", argv[1]); fprintf(stderr, "impossible d'ouvrir le fichier %s\n", argv[2]);
exit(1); exit(1);
} }
//test_yylex_internal(yyin); if (!strcmp(argv[1], "-l")) {
test_yylex_internal(yyin);
} else if (!strcmp(argv[1], "-s")) {
initialise_premiers(); initialise_premiers();
initialise_suivants(); initialise_suivants();
uniteCourante = yylex(); uniteCourante = yylex();
programme(); programme();
uniteCourante = yylex(); } else {
fprintf(stderr, "option Inconue");
}
uniteCourante = yylex();
if(uniteCourante != FIN) { if(uniteCourante != FIN) {
printf("Erreur EOF"); printf("Erreur EOF");
} }

17
test/Makefile Normal file
View File

@@ -0,0 +1,17 @@
CC = gcc
LIBS = -lm
CCFLAGS = -Wall -ggdb
all: compare_arbres_xml
compare_arbres_xml: compare_arbres_xml.c analyseur_xml.o
$(CC) $(CCFLAGS) -o compare_arbres_xml compare_arbres_xml.c analyseur_xml.o
analyseur_xml.o: analyseur_xml.c
$(CC) $(CCFLAGS) -c analyseur_xml.c
.PHONY : clean
clean:
- rm -f *.o compare_arbres_xml

View File

@@ -1,6 +0,0 @@
entier $a;
mainmainmainmainmainma()
{
$a = 124zzz;
ecrire($a);
}

323
test/analyseur_xml.c Normal file
View File

@@ -0,0 +1,323 @@
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include"analyseur_xml.h"
/* symboles terminaux */
#define CHEVRON_FERMANT 1
#define DEBUT_BF 2
#define DEBUT_BO 3
#define CHAINE 4
#define FIN 5
#define ISSPACE(a) (a == ' ') || (a == '\n') || (a == '\t')
#define YYTEXT_MAX 100
/* fonctions pour arbre abstrait */
noeud *cree_noeud(char *nom)
{
noeud *n = malloc(sizeof(noeud));
if(n == NULL){
fprintf(stderr, "erreur d'allocation\n");
exit(1);
}
n->nom = nom;
n->premier_fils = NULL;
n->dernier_fils = NULL;
n->suiv = NULL;
return n;
}
noeud *ajoute_fils(noeud *pere, noeud *fils)
{
if(pere->premier_fils == NULL){
pere->premier_fils = pere->dernier_fils = fils;
return pere;
}
pere->dernier_fils->suiv = fils;
pere->dernier_fils = fils;
return pere;
}
void affiche_arbre(noeud *racine){
noeud *n;
printf("<%s> ", racine->nom);
for(n=racine->premier_fils; n!=NULL; n = n->suiv){
affiche_arbre(n);
}
printf("</%s> ", racine->nom);
}
int compare_arbres_rec(noeud *racine1, noeud *racine2, int verbose, int profondeur)
{
noeud *f1, *f2;
int resultat = 1;
int i;
if(verbose){
for(i=0; i<profondeur; i++) printf(" ");
printf("%s <------------> %s\n", racine1->nom, racine2->nom);
}
if(strcmp(racine1->nom, racine2->nom))
return 0;
for(f1 = racine1->premier_fils, f2 = racine2->premier_fils;
f1 && f2 && resultat;
f1 = f1->suiv, f2 = f2->suiv){
resultat = compare_arbres_rec(f1, f2, verbose, profondeur+1);
}
return ((f1 == NULL) && (f2 == NULL) && resultat);
}
int compare_arbres(noeud *racine1, noeud *racine2, int verbose)
{
return compare_arbres_rec(racine1, racine2, verbose, 0);
}
void libere_arbre(noeud *racine)
{
noeud *n;
for(n=racine->premier_fils; n!=NULL; n = n->suiv){
libere_arbre(n);
}
free(racine);
}
/* analyseur lexical */
int DEBUG = 0;
char yytext[YYTEXT_MAX];
int yyleng;
int yylval;
/* Compter les lignes pour afficher les messages d'erreur avec numero ligne */
int nb_ligne;
int cc;
/*******************************************************************************
* Fonction qui ignore les espaces et commentaires.
* Renvoie -1 si arrivé à la fin du fichier, 0 si tout va bien
******************************************************************************/
int mangeEspaces()
{
char c = fgetc(yyin);
while( ISSPACE(c) ) {
if( c == '\n' ) {
nb_ligne++;
}
c = fgetc(yyin);
}
if ( feof(yyin) ) {
return -1;
}
ungetc(c, yyin);
return 0;
}
/*******************************************************************************
* Lit un caractère et le stocke dans le buffer yytext
******************************************************************************/
char lireCar(void)
{
yytext[yyleng++] = fgetc(yyin);
yytext[yyleng] = '\0';
return yytext[yyleng - 1];
}
/*******************************************************************************
* Remet le dernier caractère lu au buffer clavier et enlève du buffer yytext
******************************************************************************/
void delireCar()
{
char c;
c = yytext[yyleng - 1];
yytext[--yyleng] = '\0';
ungetc(c, yyin);
}
/*******************************************************************************
* Fonction principale de l'analyseur lexical, lit les caractères de yyin et
* renvoie les tokens sous forme d'entier. Le code de chaque unité est défini
* dans symboles.h sinon (mot clé, idententifiant, etc.). Pour les tokens de
* type ID_FCT, ID_VAR et NOMBRE la valeur du token est dans yytext, visible
* dans l'analyseur syntaxique.
******************************************************************************/
int inTag = 0;
int yylex(void)
{
char c;
yytext[yyleng = 0] = '\0';
/* Si j'ai trouvé la fin du fichier en lisant des espaces ... */
if( !inTag && mangeEspaces() == -1 ) {
return FIN; /* Renvoie le marqueur de fin d'entrée */
}
c = lireCar();
if(c == '>'){
if(DEBUG) { printf("CHEVRON_FERMANT\n"); }
//inTag = 0;
return CHEVRON_FERMANT;
}
if(c == '<'){
inTag = 1;
c = lireCar();
if(c == '/'){
if(DEBUG) { printf("DEBUT_BF\n"); }
return DEBUT_BF;
}
else{
delireCar();
if(DEBUG) { printf("DEBUT_BO\n"); }
return DEBUT_BO;
}
}
do{
c = lireCar();
inTag = 0;
}while((c!= '<') && (c!= '>') && !feof(yyin) && !(ISSPACE(c)));
delireCar();
if(DEBUG) { printf("CHAINE\n"); }
return CHAINE;
}
/*******************************************************************************
* Fonction auxiliaire appelée par l'analyseur syntaxique tout simplement pour
* afficher des messages d'erreur et l'arbre XML
******************************************************************************/
void nom_token( int token, char *nom, char *valeur ) {
//int i;
strcpy( nom, "symbole" );
if(token == CHEVRON_FERMANT) strcpy( valeur, "CHEVRON_FERMANT");
else if(token == DEBUT_BF) strcpy( valeur, "DEBUT_BF");
else if(token == DEBUT_BO) strcpy( valeur, "DEBUT_BO");
else if(token == CHAINE) strcpy( valeur, "CHAINE");
}
/* analyse syntaxique */
noeud *B(void);
void LB(noeud *pere);
char *BO(void);
char *BF(void);
void LCHAINE(void);
void erreur(char *msg){
fprintf(stderr, "Ligne %d : erreur : %s\n", nb_ligne, msg);
exit(1);
}
/* B -> BO LCHAINE LB LCHAINE BF */
noeud *B(void){
char *nom_bo;
char *nom_bf;
noeud *n;
if(DEBUG) { printf("<B>\n"); }
if(cc == DEBUT_BO){
nom_bo = BO();
n = cree_noeud(nom_bo);
LCHAINE();
LB(n);
LCHAINE();
nom_bf = BF();
if(strcmp(nom_bo, nom_bf)){
fprintf(stderr, "Ligne %d : arbre mal forme: balise ouvrante : \"%s\" balise fermante : \"%s\"\n", nb_ligne, nom_bo, nom_bf);
exit(1);
}
free(nom_bf);
if(DEBUG) { printf("</B>\n"); }
return n;
}
erreur("B");
return NULL;
}
/* LCHAINE -> CHAINE LCHAINE */
/* | */
void LCHAINE(void){
if(cc == CHAINE){
cc = yylex();
LCHAINE();
return;
}
if((cc == DEBUT_BO) ||(cc == DEBUT_BF)){
return;
}
erreur("LCHAINE");
}
/* LB -> B LB
| */
void LB(noeud *pere)
{
noeud *fils = NULL;
if(cc == DEBUT_BO){
fils = B();
ajoute_fils(pere, fils);
LB(pere);
return;
}
if(cc == DEBUT_BF){
return;
}
erreur("LB");
}
/* BO -> DEBUT_BO CHAINE CHEVRON_FERMANT */
char *BO(void)
{
char *nom = NULL;
if(DEBUG) { printf("<BO>\n"); }
if(cc == DEBUT_BO){
cc = yylex();
if(cc == CHAINE){
nom = strdup(yytext);
cc = yylex();
if(cc == CHEVRON_FERMANT){
cc = yylex();
if(DEBUG) { printf("</BO>\n"); }
return nom;
}
}
}
erreur("BO");
return NULL;
}
/* BF -> DEBUT_BF CHAINE CHEVRON_FERMANT */
char *BF(void)
{
char *nom = NULL;
if(cc == DEBUT_BF){
cc = yylex();
if(cc == CHAINE){
nom = strdup(yytext);
cc = yylex();
if(cc == CHEVRON_FERMANT){
cc = yylex();
return nom;
}
}
}
erreur("BF");
return NULL;
}
noeud *analyseur_xml(void)
{
nb_ligne = 0;
cc = yylex();
return B();
}

25
test/analyseur_xml.h Normal file
View File

@@ -0,0 +1,25 @@
#ifndef __ANALYSEUR_XML__
#define __ANALYSEUR_XML__
/* structures de donnees et fonctions pour arbre abstrait */
typedef struct n noeud;
struct n{
char *nom;
struct n *premier_fils;
struct n *dernier_fils;
struct n *suiv;
};
FILE *yyin;
void affiche_arbre(noeud *racine);
int compare_arbres(noeud *racine1, noeud *racine2, int verbose);
void libere_arbre(noeud *r);
/* analyseur */
noeud *analyseur_xml(void);
#endif

BIN
test/compare_arbres_xml Executable file

Binary file not shown.

63
test/compare_arbres_xml.c Normal file
View File

@@ -0,0 +1,63 @@
#include<stdio.h>
#include<stdlib.h>
#include"analyseur_xml.h"
int main(int argc, char *argv[])
{
noeud *racine1;
noeud *racine2;
int resultat;
int verbose;
if((argc != 3) && (argc != 4)){
fprintf(stderr, "usage: %s fichier_xml fichier_xml [v]\n", argv[0]);
exit(1);
}
verbose = (argc == 4);
yyin = fopen(argv[1], "r");
if(yyin == NULL){
fprintf(stderr, "impossible d'ouvrir le fichier %s\n", argv[1]);
exit(1);
}
fprintf(stderr, "analyse du fichier : %s\n", argv[1]);
racine1 = analyseur_xml();
fclose(yyin);
yyin = fopen(argv[2], "r");
if(yyin == NULL){
fprintf(stderr, "impossible d'ouvrir le fichier %s\n", argv[2]);
exit(1);
}
fprintf(stderr, "analyse du fichier : %s\n", argv[2]);
racine2 = analyseur_xml();
fclose(yyin);
/* affiche_arbre(racine1);
printf("\n");
affiche_arbre(racine2);*/
fprintf(stderr, "comparaison des arbres\n");
resultat = compare_arbres(racine1, racine2, verbose);
libere_arbre(racine1);
libere_arbre(racine2);
if(resultat){
printf("arbres egaux\n");
return 0;
}
else{
printf("arbres différents\n");
return 1;
}
}

View File

@@ -1 +0,0 @@
10 * + 5

View File

@@ -1 +0,0 @@
4 + 8 * (5 / 8) - (9 + 4 / 8) * ($var + $vart)

View File

@@ -1 +0,0 @@
(!!!$var & $var) | (10 -4) & 10 < (5/3)

View File

@@ -1 +0,0 @@
(1 + 1) | (2 * 3) & 5

View File

@@ -1 +0,0 @@
(5 + 8) + (9 * 4)

View File

@@ -1 +0,0 @@
4 + 8 * (5 + 6)) + 8

View File

@@ -1 +0,0 @@
4 + $var + 5 * 6

View File

@@ -1 +0,0 @@
12 + 4 * (5 + 10)

View File

@@ -1 +0,0 @@
expression(1,10);

View File

@@ -1 +0,0 @@
test();

View File

113
test/output/affect.synt Normal file
View File

@@ -0,0 +1,113 @@
<programme>
<optDecVariables>
<listeDecVariables>
<declarationVariable>
<mot_clef>entier</mot_clef>
<id_variable>$a</id_variable>
<optTailleTableau>
</optTailleTableau>
</declarationVariable>
<listeDecVariablesBis>
</listeDecVariablesBis>
</listeDecVariables>
<symbole>POINT_VIRGULE</symbole>
</optDecVariables>
<listeDecFonctions>
<declarationFonction>
<id_fonction>main</id_fonction>
<listeParam>
<symbole>PARENTHESE_OUVRANTE</symbole>
<optListeDecVariables>
</optListeDecVariables>
<symbole>PARENTHESE_FERMANTE</symbole>
</listeParam>
<optDecVariables>
</optDecVariables>
<instructionBloc>
<symbole>ACCOLADE_OUVRANTE</symbole>
<listeInstructions>
<instruction>
<instructionAffect>
<var>
<id_variable>$a</id_variable>
<optIndice>
</optIndice>
</var>
<symbole>EGAL</symbole>
<expression>
<conjonction>
<negation>
<comparaison>
<expArith>
<terme>
<facteur>
<nombre>1</nombre>
</facteur>
<termeBis>
</termeBis>
</terme>
<expArithBis>
</expArithBis>
</expArith>
<comparaisonBis>
</comparaisonBis>
</comparaison>
</negation>
<conjonctionBis>
</conjonctionBis>
</conjonction>
<expressionBis>
</expressionBis>
</expression>
<symbole>POINT_VIRGULE</symbole>
</instructionAffect>
</instruction>
<listeInstructions>
<instruction>
<instructionEcriture>
<mot_clef>ecrire</mot_clef>
<symbole>PARENTHESE_OUVRANTE</symbole>
<expression>
<conjonction>
<negation>
<comparaison>
<expArith>
<terme>
<facteur>
<var>
<id_variable>$a</id_variable>
<optIndice>
</optIndice>
</var>
</facteur>
<termeBis>
</termeBis>
</terme>
<expArithBis>
</expArithBis>
</expArith>
<comparaisonBis>
</comparaisonBis>
</comparaison>
</negation>
<conjonctionBis>
</conjonctionBis>
</conjonction>
<expressionBis>
</expressionBis>
</expression>
<symbole>PARENTHESE_FERMANTE</symbole>
<symbole>POINT_VIRGULE</symbole>
</instructionEcriture>
</instruction>
<listeInstructions>
</listeInstructions>
</listeInstructions>
</listeInstructions>
<symbole>ACCOLADE_FERMANTE</symbole>
</instructionBloc>
</declarationFonction>
<listeDecFonctions>
</listeDecFonctions>
</listeDecFonctions>
</programme>

283
test/output/boucle.synt Normal file
View File

@@ -0,0 +1,283 @@
<programme>
<optDecVariables>
<listeDecVariables>
<declarationVariable>
<mot_clef>entier</mot_clef>
<id_variable>$i</id_variable>
<optTailleTableau>
</optTailleTableau>
</declarationVariable>
<listeDecVariablesBis>
<symbole>VIRGULE</symbole>
<declarationVariable>
<mot_clef>entier</mot_clef>
<id_variable>$carre</id_variable>
<optTailleTableau>
</optTailleTableau>
</declarationVariable>
<listeDecVariablesBis>
</listeDecVariablesBis>
</listeDecVariablesBis>
</listeDecVariables>
<symbole>POINT_VIRGULE</symbole>
</optDecVariables>
<listeDecFonctions>
<declarationFonction>
<id_fonction>main</id_fonction>
<listeParam>
<symbole>PARENTHESE_OUVRANTE</symbole>
<optListeDecVariables>
</optListeDecVariables>
<symbole>PARENTHESE_FERMANTE</symbole>
</listeParam>
<optDecVariables>
</optDecVariables>
<instructionBloc>
<symbole>ACCOLADE_OUVRANTE</symbole>
<listeInstructions>
<instruction>
<instructionAffect>
<var>
<id_variable>$i</id_variable>
<optIndice>
</optIndice>
</var>
<symbole>EGAL</symbole>
<expression>
<conjonction>
<negation>
<comparaison>
<expArith>
<terme>
<facteur>
<nombre>0</nombre>
</facteur>
<termeBis>
</termeBis>
</terme>
<expArithBis>
</expArithBis>
</expArith>
<comparaisonBis>
</comparaisonBis>
</comparaison>
</negation>
<conjonctionBis>
</conjonctionBis>
</conjonction>
<expressionBis>
</expressionBis>
</expression>
<symbole>POINT_VIRGULE</symbole>
</instructionAffect>
</instruction>
<listeInstructions>
<instruction>
<instructionTantque>
<mot_clef>tantque</mot_clef>
<expression>
<conjonction>
<negation>
<comparaison>
<expArith>
<terme>
<facteur>
<var>
<id_variable>$i</id_variable>
<optIndice>
</optIndice>
</var>
</facteur>
<termeBis>
</termeBis>
</terme>
<expArithBis>
</expArithBis>
</expArith>
<comparaisonBis>
<symbole>INFERIEUR</symbole>
<expArith>
<terme>
<facteur>
<nombre>10</nombre>
</facteur>
<termeBis>
</termeBis>
</terme>
<expArithBis>
</expArithBis>
</expArith>
<comparaisonBis>
</comparaisonBis>
</comparaisonBis>
</comparaison>
</negation>
<conjonctionBis>
</conjonctionBis>
</conjonction>
<expressionBis>
</expressionBis>
</expression>
<mot_clef>faire</mot_clef>
<instructionBloc>
<symbole>ACCOLADE_OUVRANTE</symbole>
<listeInstructions>
<instruction>
<instructionAffect>
<var>
<id_variable>$carre</id_variable>
<optIndice>
</optIndice>
</var>
<symbole>EGAL</symbole>
<expression>
<conjonction>
<negation>
<comparaison>
<expArith>
<terme>
<facteur>
<var>
<id_variable>$i</id_variable>
<optIndice>
</optIndice>
</var>
</facteur>
<termeBis>
<symbole>FOIS</symbole>
<facteur>
<var>
<id_variable>$i</id_variable>
<optIndice>
</optIndice>
</var>
</facteur>
<termeBis>
</termeBis>
</termeBis>
</terme>
<expArithBis>
</expArithBis>
</expArith>
<comparaisonBis>
</comparaisonBis>
</comparaison>
</negation>
<conjonctionBis>
</conjonctionBis>
</conjonction>
<expressionBis>
</expressionBis>
</expression>
<symbole>POINT_VIRGULE</symbole>
</instructionAffect>
</instruction>
<listeInstructions>
<instruction>
<instructionEcriture>
<mot_clef>ecrire</mot_clef>
<symbole>PARENTHESE_OUVRANTE</symbole>
<expression>
<conjonction>
<negation>
<comparaison>
<expArith>
<terme>
<facteur>
<var>
<id_variable>$carre</id_variable>
<optIndice>
</optIndice>
</var>
</facteur>
<termeBis>
</termeBis>
</terme>
<expArithBis>
</expArithBis>
</expArith>
<comparaisonBis>
</comparaisonBis>
</comparaison>
</negation>
<conjonctionBis>
</conjonctionBis>
</conjonction>
<expressionBis>
</expressionBis>
</expression>
<symbole>PARENTHESE_FERMANTE</symbole>
<symbole>POINT_VIRGULE</symbole>
</instructionEcriture>
</instruction>
<listeInstructions>
<instruction>
<instructionAffect>
<var>
<id_variable>$i</id_variable>
<optIndice>
</optIndice>
</var>
<symbole>EGAL</symbole>
<expression>
<conjonction>
<negation>
<comparaison>
<expArith>
<terme>
<facteur>
<var>
<id_variable>$i</id_variable>
<optIndice>
</optIndice>
</var>
</facteur>
<termeBis>
</termeBis>
</terme>
<expArithBis>
<symbole>PLUS</symbole>
<terme>
<facteur>
<nombre>1</nombre>
</facteur>
<termeBis>
</termeBis>
</terme>
<expArithBis>
</expArithBis>
</expArithBis>
</expArith>
<comparaisonBis>
</comparaisonBis>
</comparaison>
</negation>
<conjonctionBis>
</conjonctionBis>
</conjonction>
<expressionBis>
</expressionBis>
</expression>
<symbole>POINT_VIRGULE</symbole>
</instructionAffect>
</instruction>
<listeInstructions>
</listeInstructions>
</listeInstructions>
</listeInstructions>
</listeInstructions>
<symbole>ACCOLADE_FERMANTE</symbole>
</instructionBloc>
</instructionTantque>
</instruction>
<listeInstructions>
</listeInstructions>
</listeInstructions>
</listeInstructions>
<symbole>ACCOLADE_FERMANTE</symbole>
</instructionBloc>
</declarationFonction>
<listeDecFonctions>
</listeDecFonctions>
</listeDecFonctions>
</programme>

View File

@@ -0,0 +1,77 @@
<programme>
<optDecVariables>
<listeDecVariables>
<declarationVariable>
<mot_clef>entier</mot_clef>
<id_variable>$a</id_variable>
<optTailleTableau>
</optTailleTableau>
</declarationVariable>
<listeDecVariablesBis>
</listeDecVariablesBis>
</listeDecVariables>
<symbole>POINT_VIRGULE</symbole>
</optDecVariables>
<listeDecFonctions>
<declarationFonction>
<id_fonction>main</id_fonction>
<listeParam>
<symbole>PARENTHESE_OUVRANTE</symbole>
<optListeDecVariables>
</optListeDecVariables>
<symbole>PARENTHESE_FERMANTE</symbole>
</listeParam>
<optDecVariables>
</optDecVariables>
<instructionBloc>
<symbole>ACCOLADE_OUVRANTE</symbole>
<listeInstructions>
<instruction>
<instructionEcriture>
<mot_clef>ecrire</mot_clef>
<symbole>PARENTHESE_OUVRANTE</symbole>
<expression>
<conjonction>
<negation>
<comparaison>
<expArith>
<terme>
<facteur>
<nombre>5</nombre>
</facteur>
<termeBis>
<symbole>FOIS</symbole>
<facteur>
<nombre>2</nombre>
</facteur>
<termeBis>
</termeBis>
</termeBis>
</terme>
<expArithBis>
</expArithBis>
</expArith>
<comparaisonBis>
</comparaisonBis>
</comparaison>
</negation>
<conjonctionBis>
</conjonctionBis>
</conjonction>
<expressionBis>
</expressionBis>
</expression>
<symbole>PARENTHESE_FERMANTE</symbole>
<symbole>POINT_VIRGULE</symbole>
</instructionEcriture>
</instruction>
<listeInstructions>
</listeInstructions>
</listeInstructions>
<symbole>ACCOLADE_FERMANTE</symbole>
</instructionBloc>
</declarationFonction>
<listeDecFonctions>
</listeDecFonctions>
</listeDecFonctions>
</programme>

513
test/output/max.synt Normal file
View File

@@ -0,0 +1,513 @@
<programme>
<optDecVariables>
</optDecVariables>
<listeDecFonctions>
<declarationFonction>
<id_fonction>max</id_fonction>
<listeParam>
<symbole>PARENTHESE_OUVRANTE</symbole>
<optListeDecVariables>
<listeDecVariables>
<declarationVariable>
<mot_clef>entier</mot_clef>
<id_variable>$a</id_variable>
<optTailleTableau>
</optTailleTableau>
</declarationVariable>
<listeDecVariablesBis>
<symbole>VIRGULE</symbole>
<declarationVariable>
<mot_clef>entier</mot_clef>
<id_variable>$b</id_variable>
<optTailleTableau>
</optTailleTableau>
</declarationVariable>
<listeDecVariablesBis>
</listeDecVariablesBis>
</listeDecVariablesBis>
</listeDecVariables>
</optListeDecVariables>
<symbole>PARENTHESE_FERMANTE</symbole>
</listeParam>
<optDecVariables>
</optDecVariables>
<instructionBloc>
<symbole>ACCOLADE_OUVRANTE</symbole>
<listeInstructions>
<instruction>
<instructionSi>
<mot_clef>si</mot_clef>
<expression>
<conjonction>
<negation>
<comparaison>
<expArith>
<terme>
<facteur>
<var>
<id_variable>$a</id_variable>
<optIndice>
</optIndice>
</var>
</facteur>
<termeBis>
</termeBis>
</terme>
<expArithBis>
</expArithBis>
</expArith>
<comparaisonBis>
<symbole>INFERIEUR</symbole>
<expArith>
<terme>
<facteur>
<var>
<id_variable>$b</id_variable>
<optIndice>
</optIndice>
</var>
</facteur>
<termeBis>
</termeBis>
</terme>
<expArithBis>
</expArithBis>
</expArith>
<comparaisonBis>
</comparaisonBis>
</comparaisonBis>
</comparaison>
</negation>
<conjonctionBis>
</conjonctionBis>
</conjonction>
<expressionBis>
</expressionBis>
</expression>
<mot_clef>alors</mot_clef>
<instructionBloc>
<symbole>ACCOLADE_OUVRANTE</symbole>
<listeInstructions>
<instruction>
<instructionRetour>
<mot_clef>retour</mot_clef>
<expression>
<conjonction>
<negation>
<comparaison>
<expArith>
<terme>
<facteur>
<var>
<id_variable>$b</id_variable>
<optIndice>
</optIndice>
</var>
</facteur>
<termeBis>
</termeBis>
</terme>
<expArithBis>
</expArithBis>
</expArith>
<comparaisonBis>
</comparaisonBis>
</comparaison>
</negation>
<conjonctionBis>
</conjonctionBis>
</conjonction>
<expressionBis>
</expressionBis>
</expression>
<symbole>POINT_VIRGULE</symbole>
</instructionRetour>
</instruction>
<listeInstructions>
</listeInstructions>
</listeInstructions>
<symbole>ACCOLADE_FERMANTE</symbole>
</instructionBloc>
<optSinon>
</optSinon>
</instructionSi>
</instruction>
<listeInstructions>
<instruction>
<instructionRetour>
<mot_clef>retour</mot_clef>
<expression>
<conjonction>
<negation>
<comparaison>
<expArith>
<terme>
<facteur>
<var>
<id_variable>$a</id_variable>
<optIndice>
</optIndice>
</var>
</facteur>
<termeBis>
</termeBis>
</terme>
<expArithBis>
</expArithBis>
</expArith>
<comparaisonBis>
</comparaisonBis>
</comparaison>
</negation>
<conjonctionBis>
</conjonctionBis>
</conjonction>
<expressionBis>
</expressionBis>
</expression>
<symbole>POINT_VIRGULE</symbole>
</instructionRetour>
</instruction>
<listeInstructions>
</listeInstructions>
</listeInstructions>
</listeInstructions>
<symbole>ACCOLADE_FERMANTE</symbole>
</instructionBloc>
</declarationFonction>
<listeDecFonctions>
<declarationFonction>
<id_fonction>main</id_fonction>
<listeParam>
<symbole>PARENTHESE_OUVRANTE</symbole>
<optListeDecVariables>
</optListeDecVariables>
<symbole>PARENTHESE_FERMANTE</symbole>
</listeParam>
<optDecVariables>
<listeDecVariables>
<declarationVariable>
<mot_clef>entier</mot_clef>
<id_variable>$v_1</id_variable>
<optTailleTableau>
</optTailleTableau>
</declarationVariable>
<listeDecVariablesBis>
<symbole>VIRGULE</symbole>
<declarationVariable>
<mot_clef>entier</mot_clef>
<id_variable>$v_2</id_variable>
<optTailleTableau>
</optTailleTableau>
</declarationVariable>
<listeDecVariablesBis>
</listeDecVariablesBis>
</listeDecVariablesBis>
</listeDecVariables>
<symbole>POINT_VIRGULE</symbole>
</optDecVariables>
<instructionBloc>
<symbole>ACCOLADE_OUVRANTE</symbole>
<listeInstructions>
<instruction>
<instructionAffect>
<var>
<id_variable>$v_1</id_variable>
<optIndice>
</optIndice>
</var>
<symbole>EGAL</symbole>
<expression>
<conjonction>
<negation>
<comparaison>
<expArith>
<terme>
<facteur>
<mot_clef>lire</mot_clef>
<symbole>PARENTHESE_OUVRANTE</symbole>
<symbole>PARENTHESE_FERMANTE</symbole>
</facteur>
<termeBis>
</termeBis>
</terme>
<expArithBis>
</expArithBis>
</expArith>
<comparaisonBis>
</comparaisonBis>
</comparaison>
</negation>
<conjonctionBis>
</conjonctionBis>
</conjonction>
<expressionBis>
</expressionBis>
</expression>
<symbole>POINT_VIRGULE</symbole>
</instructionAffect>
</instruction>
<listeInstructions>
<instruction>
<instructionAffect>
<var>
<id_variable>$v_2</id_variable>
<optIndice>
</optIndice>
</var>
<symbole>EGAL</symbole>
<expression>
<conjonction>
<negation>
<comparaison>
<expArith>
<terme>
<facteur>
<mot_clef>lire</mot_clef>
<symbole>PARENTHESE_OUVRANTE</symbole>
<symbole>PARENTHESE_FERMANTE</symbole>
</facteur>
<termeBis>
</termeBis>
</terme>
<expArithBis>
</expArithBis>
</expArith>
<comparaisonBis>
</comparaisonBis>
</comparaison>
</negation>
<conjonctionBis>
</conjonctionBis>
</conjonction>
<expressionBis>
</expressionBis>
</expression>
<symbole>POINT_VIRGULE</symbole>
</instructionAffect>
</instruction>
<listeInstructions>
<instruction>
<instructionSi>
<mot_clef>si</mot_clef>
<expression>
<conjonction>
<negation>
<comparaison>
<expArith>
<terme>
<facteur>
<appelFct>
<id_fonction>max</id_fonction>
<symbole>PARENTHESE_OUVRANTE</symbole>
<listeExpressions>
<expression>
<conjonction>
<negation>
<comparaison>
<expArith>
<terme>
<facteur>
<var>
<id_variable>$v_1</id_variable>
<optIndice>
</optIndice>
</var>
</facteur>
<termeBis>
</termeBis>
</terme>
<expArithBis>
</expArithBis>
</expArith>
<comparaisonBis>
</comparaisonBis>
</comparaison>
</negation>
<conjonctionBis>
</conjonctionBis>
</conjonction>
<expressionBis>
</expressionBis>
</expression>
<listeExpressionsBis>
<symbole>VIRGULE</symbole>
<expression>
<conjonction>
<negation>
<comparaison>
<expArith>
<terme>
<facteur>
<var>
<id_variable>$v_2</id_variable>
<optIndice>
</optIndice>
</var>
</facteur>
<termeBis>
</termeBis>
</terme>
<expArithBis>
</expArithBis>
</expArith>
<comparaisonBis>
</comparaisonBis>
</comparaison>
</negation>
<conjonctionBis>
</conjonctionBis>
</conjonction>
<expressionBis>
</expressionBis>
</expression>
<listeExpressionsBis>
</listeExpressionsBis>
</listeExpressionsBis>
</listeExpressions>
<symbole>PARENTHESE_FERMANTE</symbole>
</appelFct>
</facteur>
<termeBis>
</termeBis>
</terme>
<expArithBis>
</expArithBis>
</expArith>
<comparaisonBis>
<symbole>EGAL</symbole>
<expArith>
<terme>
<facteur>
<var>
<id_variable>$v_1</id_variable>
<optIndice>
</optIndice>
</var>
</facteur>
<termeBis>
</termeBis>
</terme>
<expArithBis>
</expArithBis>
</expArith>
<comparaisonBis>
</comparaisonBis>
</comparaisonBis>
</comparaison>
</negation>
<conjonctionBis>
</conjonctionBis>
</conjonction>
<expressionBis>
</expressionBis>
</expression>
<mot_clef>alors</mot_clef>
<instructionBloc>
<symbole>ACCOLADE_OUVRANTE</symbole>
<listeInstructions>
<instruction>
<instructionEcriture>
<mot_clef>ecrire</mot_clef>
<symbole>PARENTHESE_OUVRANTE</symbole>
<expression>
<conjonction>
<negation>
<comparaison>
<expArith>
<terme>
<facteur>
<var>
<id_variable>$v_1</id_variable>
<optIndice>
</optIndice>
</var>
</facteur>
<termeBis>
</termeBis>
</terme>
<expArithBis>
</expArithBis>
</expArith>
<comparaisonBis>
</comparaisonBis>
</comparaison>
</negation>
<conjonctionBis>
</conjonctionBis>
</conjonction>
<expressionBis>
</expressionBis>
</expression>
<symbole>PARENTHESE_FERMANTE</symbole>
<symbole>POINT_VIRGULE</symbole>
</instructionEcriture>
</instruction>
<listeInstructions>
</listeInstructions>
</listeInstructions>
<symbole>ACCOLADE_FERMANTE</symbole>
</instructionBloc>
<optSinon>
<mot_clef>sinon</mot_clef>
<instructionBloc>
<symbole>ACCOLADE_OUVRANTE</symbole>
<listeInstructions>
<instruction>
<instructionEcriture>
<mot_clef>ecrire</mot_clef>
<symbole>PARENTHESE_OUVRANTE</symbole>
<expression>
<conjonction>
<negation>
<comparaison>
<expArith>
<terme>
<facteur>
<var>
<id_variable>$v_2</id_variable>
<optIndice>
</optIndice>
</var>
</facteur>
<termeBis>
</termeBis>
</terme>
<expArithBis>
</expArithBis>
</expArith>
<comparaisonBis>
</comparaisonBis>
</comparaison>
</negation>
<conjonctionBis>
</conjonctionBis>
</conjonction>
<expressionBis>
</expressionBis>
</expression>
<symbole>PARENTHESE_FERMANTE</symbole>
<symbole>POINT_VIRGULE</symbole>
</instructionEcriture>
</instruction>
<listeInstructions>
</listeInstructions>
</listeInstructions>
<symbole>ACCOLADE_FERMANTE</symbole>
</instructionBloc>
</optSinon>
</instructionSi>
</instruction>
<listeInstructions>
</listeInstructions>
</listeInstructions>
</listeInstructions>
</listeInstructions>
<symbole>ACCOLADE_FERMANTE</symbole>
</instructionBloc>
</declarationFonction>
<listeDecFonctions>
</listeDecFonctions>
</listeDecFonctions>
</listeDecFonctions>
</programme>

2146
test/output/tri.synt Normal file

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,23 @@
<prog>
<l_dec>
<varDec>$a</varDec>
</l_dec>
<l_dec>
<foncDec>
main
<l_instr>
<instr_affect>
<var_simple>$a</var_simple>
<intExp>1</intExp>
</instr_affect>
<l_instr>
<instr_ecrire>
<varExp>
<var_simple>$a</var_simple>
</varExp>
</instr_ecrire>
</l_instr>
</l_instr>
</foncDec>
</l_dec>
</prog>

View File

@@ -0,0 +1,63 @@
<prog>
<l_dec>
<varDec>$i</varDec>
<l_dec>
<varDec>$carre</varDec>
</l_dec>
</l_dec>
<l_dec>
<foncDec>
main
<l_instr>
<instr_affect>
<var_simple>$i</var_simple>
<intExp>0</intExp>
</instr_affect>
<l_instr>
<instr_tantque>
<opExp>
inf
<varExp>
<var_simple>$i</var_simple>
</varExp>
<intExp>10</intExp>
</opExp>
<l_instr>
<instr_affect>
<var_simple>$carre</var_simple>
<opExp>
fois
<varExp>
<var_simple>$i</var_simple>
</varExp>
<varExp>
<var_simple>$i</var_simple>
</varExp>
</opExp>
</instr_affect>
<l_instr>
<instr_ecrire>
<varExp>
<var_simple>$carre</var_simple>
</varExp>
</instr_ecrire>
<l_instr>
<instr_affect>
<var_simple>$i</var_simple>
<opExp>
plus
<varExp>
<var_simple>$i</var_simple>
</varExp>
<intExp>1</intExp>
</opExp>
</instr_affect>
</l_instr>
</l_instr>
</l_instr>
</instr_tantque>
</l_instr>
</l_instr>
</foncDec>
</l_dec>
</prog>

View File

@@ -0,0 +1,19 @@
<prog>
<l_dec>
<varDec>$a</varDec>
</l_dec>
<l_dec>
<foncDec>
main
<l_instr>
<instr_ecrire>
<opExp>
fois
<intExp>5</intExp>
<intExp>2</intExp>
</opExp>
</instr_ecrire>
</l_instr>
</foncDec>
</l_dec>
</prog>

106
test/ref-asynt/max.asynt Normal file
View File

@@ -0,0 +1,106 @@
<prog>
<l_dec>
<foncDec>
max
<l_dec>
<varDec>$a</varDec>
<l_dec>
<varDec>$b</varDec>
</l_dec>
</l_dec>
<l_instr>
<instr_si>
<opExp>
inf
<varExp>
<var_simple>$a</var_simple>
</varExp>
<varExp>
<var_simple>$b</var_simple>
</varExp>
</opExp>
<l_instr>
<instr_retour>
<varExp>
<var_simple>$b</var_simple>
</varExp>
</instr_retour>
</l_instr>
</instr_si>
<l_instr>
<instr_retour>
<varExp>
<var_simple>$a</var_simple>
</varExp>
</instr_retour>
</l_instr>
</l_instr>
</foncDec>
<l_dec>
<foncDec>
main
<l_dec>
<varDec>$v_1</varDec>
<l_dec>
<varDec>$v_2</varDec>
</l_dec>
</l_dec>
<l_instr>
<instr_affect>
<var_simple>$v_1</var_simple>
<lireExp>
</lireExp>
</instr_affect>
<l_instr>
<instr_affect>
<var_simple>$v_2</var_simple>
<lireExp>
</lireExp>
</instr_affect>
<l_instr>
<instr_si>
<opExp>
egal
<appelExp>
<appel>
max
<l_exp>
<varExp>
<var_simple>$v_1</var_simple>
</varExp>
<l_exp>
<varExp>
<var_simple>$v_2</var_simple>
</varExp>
<l_exp>
</l_exp>
</l_exp>
</l_exp>
</appel>
</appelExp>
<varExp>
<var_simple>$v_1</var_simple>
</varExp>
</opExp>
<l_instr>
<instr_ecrire>
<varExp>
<var_simple>$v_1</var_simple>
</varExp>
</instr_ecrire>
</l_instr>
<l_instr>
<instr_ecrire>
<varExp>
<var_simple>$v_2</var_simple>
</varExp>
</instr_ecrire>
</l_instr>
</instr_si>
</l_instr>
</l_instr>
</l_instr>
</foncDec>
</l_dec>
</l_dec>
</prog>

418
test/ref-asynt/tri.asynt Normal file
View File

@@ -0,0 +1,418 @@
<prog>
<l_dec>
<tabDec>$tab[10]</tabDec>
</l_dec>
<l_dec>
<foncDec>
initialiser
<l_instr>
<instr_affect>
<var_indicee>
<var_base_tableau>$tab</var_base_tableau>
<intExp>0</intExp>
</var_indicee>
<intExp>8</intExp>
</instr_affect>
<l_instr>
<instr_affect>
<var_indicee>
<var_base_tableau>$tab</var_base_tableau>
<intExp>1</intExp>
</var_indicee>
<intExp>6</intExp>
</instr_affect>
<l_instr>
<instr_affect>
<var_indicee>
<var_base_tableau>$tab</var_base_tableau>
<intExp>2</intExp>
</var_indicee>
<intExp>9</intExp>
</instr_affect>
<l_instr>
<instr_affect>
<var_indicee>
<var_base_tableau>$tab</var_base_tableau>
<intExp>3</intExp>
</var_indicee>
<intExp>9</intExp>
</instr_affect>
<l_instr>
<instr_affect>
<var_indicee>
<var_base_tableau>$tab</var_base_tableau>
<intExp>4</intExp>
</var_indicee>
<intExp>4</intExp>
</instr_affect>
<l_instr>
<instr_affect>
<var_indicee>
<var_base_tableau>$tab</var_base_tableau>
<intExp>5</intExp>
</var_indicee>
<intExp>2</intExp>
</instr_affect>
<l_instr>
<instr_affect>
<var_indicee>
<var_base_tableau>$tab</var_base_tableau>
<intExp>6</intExp>
</var_indicee>
<intExp>3</intExp>
</instr_affect>
<l_instr>
<instr_affect>
<var_indicee>
<var_base_tableau>$tab</var_base_tableau>
<intExp>7</intExp>
</var_indicee>
<intExp>1</intExp>
</instr_affect>
<l_instr>
<instr_affect>
<var_indicee>
<var_base_tableau>$tab</var_base_tableau>
<intExp>8</intExp>
</var_indicee>
<intExp>4</intExp>
</instr_affect>
<l_instr>
<instr_affect>
<var_indicee>
<var_base_tableau>$tab</var_base_tableau>
<intExp>9</intExp>
</var_indicee>
<intExp>5</intExp>
</instr_affect>
</l_instr>
</l_instr>
</l_instr>
</l_instr>
</l_instr>
</l_instr>
</l_instr>
</l_instr>
</l_instr>
</l_instr>
</foncDec>
<l_dec>
<foncDec>
afficher
<l_dec>
<varDec>$n</varDec>
</l_dec>
<l_dec>
<varDec>$i</varDec>
</l_dec>
<l_instr>
<instr_affect>
<var_simple>$i</var_simple>
<intExp>0</intExp>
</instr_affect>
<l_instr>
<instr_tantque>
<opExp>
inf
<varExp>
<var_simple>$i</var_simple>
</varExp>
<varExp>
<var_simple>$n</var_simple>
</varExp>
</opExp>
<l_instr>
<instr_ecrire>
<varExp>
<var_indicee>
<var_base_tableau>$tab</var_base_tableau>
<varExp>
<var_simple>$i</var_simple>
</varExp>
</var_indicee>
</varExp>
</instr_ecrire>
<l_instr>
<instr_affect>
<var_simple>$i</var_simple>
<opExp>
plus
<varExp>
<var_simple>$i</var_simple>
</varExp>
<intExp>1</intExp>
</opExp>
</instr_affect>
</l_instr>
</l_instr>
</instr_tantque>
<l_instr>
<instr_ecrire>
<intExp>0</intExp>
</instr_ecrire>
</l_instr>
</l_instr>
</l_instr>
</foncDec>
<l_dec>
<foncDec>
echanger
<l_dec>
<varDec>$i</varDec>
<l_dec>
<varDec>$j</varDec>
</l_dec>
</l_dec>
<l_dec>
<varDec>$temp</varDec>
</l_dec>
<l_instr>
<instr_affect>
<var_simple>$temp</var_simple>
<varExp>
<var_indicee>
<var_base_tableau>$tab</var_base_tableau>
<varExp>
<var_simple>$j</var_simple>
</varExp>
</var_indicee>
</varExp>
</instr_affect>
<l_instr>
<instr_affect>
<var_indicee>
<var_base_tableau>$tab</var_base_tableau>
<varExp>
<var_simple>$j</var_simple>
</varExp>
</var_indicee>
<varExp>
<var_indicee>
<var_base_tableau>$tab</var_base_tableau>
<varExp>
<var_simple>$i</var_simple>
</varExp>
</var_indicee>
</varExp>
</instr_affect>
<l_instr>
<instr_affect>
<var_indicee>
<var_base_tableau>$tab</var_base_tableau>
<varExp>
<var_simple>$i</var_simple>
</varExp>
</var_indicee>
<varExp>
<var_simple>$temp</var_simple>
</varExp>
</instr_affect>
</l_instr>
</l_instr>
</l_instr>
</foncDec>
<l_dec>
<foncDec>
trier
<l_dec>
<varDec>$n</varDec>
</l_dec>
<l_dec>
<varDec>$echange</varDec>
<l_dec>
<varDec>$j</varDec>
<l_dec>
<varDec>$m</varDec>
</l_dec>
</l_dec>
</l_dec>
<l_instr>
<instr_affect>
<var_simple>$m</var_simple>
<varExp>
<var_simple>$n</var_simple>
</varExp>
</instr_affect>
<l_instr>
<instr_affect>
<var_simple>$echange</var_simple>
<intExp>1</intExp>
</instr_affect>
<l_instr>
<instr_tantque>
<opExp>
egal
<varExp>
<var_simple>$echange</var_simple>
</varExp>
<intExp>1</intExp>
</opExp>
<l_instr>
<instr_affect>
<var_simple>$echange</var_simple>
<intExp>0</intExp>
</instr_affect>
<l_instr>
<instr_affect>
<var_simple>$j</var_simple>
<intExp>0</intExp>
</instr_affect>
<l_instr>
<instr_tantque>
<opExp>
inf
<varExp>
<var_simple>$j</var_simple>
</varExp>
<opExp>
moins
<varExp>
<var_simple>$m</var_simple>
</varExp>
<intExp>1</intExp>
</opExp>
</opExp>
<l_instr>
<instr_si>
<opExp>
inf
<varExp>
<var_indicee>
<var_base_tableau>$tab</var_base_tableau>
<opExp>
plus
<varExp>
<var_simple>$j</var_simple>
</varExp>
<intExp>1</intExp>
</opExp>
</var_indicee>
</varExp>
<varExp>
<var_indicee>
<var_base_tableau>$tab</var_base_tableau>
<varExp>
<var_simple>$j</var_simple>
</varExp>
</var_indicee>
</varExp>
</opExp>
<l_instr>
<instr_appel>
<appel>
echanger
<l_exp>
<varExp>
<var_simple>$j</var_simple>
</varExp>
<l_exp>
<opExp>
plus
<varExp>
<var_simple>$j</var_simple>
</varExp>
<intExp>1</intExp>
</opExp>
<l_exp>
</l_exp>
</l_exp>
</l_exp>
</appel>
</instr_appel>
<l_instr>
<instr_affect>
<var_simple>$echange</var_simple>
<intExp>1</intExp>
</instr_affect>
</l_instr>
</l_instr>
</instr_si>
<l_instr>
<instr_affect>
<var_simple>$j</var_simple>
<opExp>
plus
<varExp>
<var_simple>$j</var_simple>
</varExp>
<intExp>1</intExp>
</opExp>
</instr_affect>
</l_instr>
</l_instr>
</instr_tantque>
<l_instr>
<instr_affect>
<var_simple>$m</var_simple>
<opExp>
moins
<varExp>
<var_simple>$m</var_simple>
</varExp>
<intExp>1</intExp>
</opExp>
</instr_affect>
</l_instr>
</l_instr>
</l_instr>
</l_instr>
</instr_tantque>
</l_instr>
</l_instr>
</l_instr>
</foncDec>
<l_dec>
<foncDec>
main
<l_instr>
<instr_appel>
<appel>
initialiser
<l_exp>
</l_exp>
</appel>
</instr_appel>
<l_instr>
<instr_appel>
<appel>
afficher
<l_exp>
<intExp>10</intExp>
<l_exp>
</l_exp>
</l_exp>
</appel>
</instr_appel>
<l_instr>
<instr_appel>
<appel>
trier
<l_exp>
<intExp>10</intExp>
<l_exp>
</l_exp>
</l_exp>
</appel>
</instr_appel>
<l_instr>
<instr_appel>
<appel>
afficher
<l_exp>
<intExp>10</intExp>
<l_exp>
</l_exp>
</l_exp>
</appel>
</instr_appel>
</l_instr>
</l_instr>
</l_instr>
</l_instr>
</foncDec>
</l_dec>
</l_dec>
</l_dec>
</l_dec>
</l_dec>
</prog>

View File

@@ -7,7 +7,7 @@ main id_fonction main
{ symbole ACCOLADE_OUVRANTE { symbole ACCOLADE_OUVRANTE
$a id_variable $a $a id_variable $a
= symbole EGAL = symbole EGAL
5 nombre 5 1 nombre 1
; symbole POINT_VIRGULE ; symbole POINT_VIRGULE
ecrire mot_clef ecrire ecrire mot_clef ecrire
( symbole PARENTHESE_OUVRANTE ( symbole PARENTHESE_OUVRANTE
@@ -15,8 +15,4 @@ $a id_variable $a
) symbole PARENTHESE_FERMANTE ) symbole PARENTHESE_FERMANTE
; symbole POINT_VIRGULE ; symbole POINT_VIRGULE
} symbole ACCOLADE_FERMANTE } symbole ACCOLADE_FERMANTE
$extra id_variable $extra
= symbole EGAL
0 nombre 0
; symbole POINT_VIRGULE
symbole FIN symbole FIN

40
test/ref-lex/boucle.lex Normal file
View File

@@ -0,0 +1,40 @@
entier mot_clef entier
$i id_variable $i
, symbole VIRGULE
entier mot_clef entier
$carre id_variable $carre
; symbole POINT_VIRGULE
main id_fonction main
( symbole PARENTHESE_OUVRANTE
) symbole PARENTHESE_FERMANTE
{ symbole ACCOLADE_OUVRANTE
$i id_variable $i
= symbole EGAL
0 nombre 0
; symbole POINT_VIRGULE
tantque mot_clef tantque
$i id_variable $i
< symbole INFERIEUR
10 nombre 10
faire mot_clef faire
{ symbole ACCOLADE_OUVRANTE
$carre id_variable $carre
= symbole EGAL
$i id_variable $i
* symbole FOIS
$i id_variable $i
; symbole POINT_VIRGULE
ecrire mot_clef ecrire
( symbole PARENTHESE_OUVRANTE
$carre id_variable $carre
) symbole PARENTHESE_FERMANTE
; symbole POINT_VIRGULE
$i id_variable $i
= symbole EGAL
$i id_variable $i
+ symbole PLUS
1 nombre 1
; symbole POINT_VIRGULE
} symbole ACCOLADE_FERMANTE
} symbole ACCOLADE_FERMANTE
symbole FIN

View File

@@ -0,0 +1,16 @@
entier mot_clef entier
$a id_variable $a
; symbole POINT_VIRGULE
main id_fonction main
( symbole PARENTHESE_OUVRANTE
) symbole PARENTHESE_FERMANTE
{ symbole ACCOLADE_OUVRANTE
ecrire mot_clef ecrire
( symbole PARENTHESE_OUVRANTE
5 nombre 5
* symbole FOIS
2 nombre 2
) symbole PARENTHESE_FERMANTE
; symbole POINT_VIRGULE
} symbole ACCOLADE_FERMANTE
symbole FIN

72
test/ref-lex/max.lex Normal file
View File

@@ -0,0 +1,72 @@
max id_fonction max
( symbole PARENTHESE_OUVRANTE
entier mot_clef entier
$a id_variable $a
, symbole VIRGULE
entier mot_clef entier
$b id_variable $b
) symbole PARENTHESE_FERMANTE
{ symbole ACCOLADE_OUVRANTE
si mot_clef si
$a id_variable $a
< symbole INFERIEUR
$b id_variable $b
alors mot_clef alors
{ symbole ACCOLADE_OUVRANTE
retour mot_clef retour
$b id_variable $b
; symbole POINT_VIRGULE
} symbole ACCOLADE_FERMANTE
retour mot_clef retour
$a id_variable $a
; symbole POINT_VIRGULE
} symbole ACCOLADE_FERMANTE
main id_fonction main
( symbole PARENTHESE_OUVRANTE
) symbole PARENTHESE_FERMANTE
entier mot_clef entier
$v_1 id_variable $v_1
, symbole VIRGULE
entier mot_clef entier
$v_2 id_variable $v_2
; symbole POINT_VIRGULE
{ symbole ACCOLADE_OUVRANTE
$v_1 id_variable $v_1
= symbole EGAL
lire mot_clef lire
( symbole PARENTHESE_OUVRANTE
) symbole PARENTHESE_FERMANTE
; symbole POINT_VIRGULE
$v_2 id_variable $v_2
= symbole EGAL
lire mot_clef lire
( symbole PARENTHESE_OUVRANTE
) symbole PARENTHESE_FERMANTE
; symbole POINT_VIRGULE
si mot_clef si
max id_fonction max
( symbole PARENTHESE_OUVRANTE
$v_1 id_variable $v_1
, symbole VIRGULE
$v_2 id_variable $v_2
) symbole PARENTHESE_FERMANTE
= symbole EGAL
$v_1 id_variable $v_1
alors mot_clef alors
{ symbole ACCOLADE_OUVRANTE
ecrire mot_clef ecrire
( symbole PARENTHESE_OUVRANTE
$v_1 id_variable $v_1
) symbole PARENTHESE_FERMANTE
; symbole POINT_VIRGULE
} symbole ACCOLADE_FERMANTE
sinon mot_clef sinon
{ symbole ACCOLADE_OUVRANTE
ecrire mot_clef ecrire
( symbole PARENTHESE_OUVRANTE
$v_2 id_variable $v_2
) symbole PARENTHESE_FERMANTE
; symbole POINT_VIRGULE
} symbole ACCOLADE_FERMANTE
} symbole ACCOLADE_FERMANTE
symbole FIN

271
test/ref-lex/tri.lex Normal file
View File

@@ -0,0 +1,271 @@
entier mot_clef entier
$tab id_variable $tab
[ symbole CROCHET_OUVRANT
10 nombre 10
] symbole CROCHET_FERMANT
; symbole POINT_VIRGULE
initialiser id_fonction initialiser
( symbole PARENTHESE_OUVRANTE
) symbole PARENTHESE_FERMANTE
{ symbole ACCOLADE_OUVRANTE
$tab id_variable $tab
[ symbole CROCHET_OUVRANT
0 nombre 0
] symbole CROCHET_FERMANT
= symbole EGAL
8 nombre 8
; symbole POINT_VIRGULE
$tab id_variable $tab
[ symbole CROCHET_OUVRANT
1 nombre 1
] symbole CROCHET_FERMANT
= symbole EGAL
6 nombre 6
; symbole POINT_VIRGULE
$tab id_variable $tab
[ symbole CROCHET_OUVRANT
2 nombre 2
] symbole CROCHET_FERMANT
= symbole EGAL
9 nombre 9
; symbole POINT_VIRGULE
$tab id_variable $tab
[ symbole CROCHET_OUVRANT
3 nombre 3
] symbole CROCHET_FERMANT
= symbole EGAL
9 nombre 9
; symbole POINT_VIRGULE
$tab id_variable $tab
[ symbole CROCHET_OUVRANT
4 nombre 4
] symbole CROCHET_FERMANT
= symbole EGAL
4 nombre 4
; symbole POINT_VIRGULE
$tab id_variable $tab
[ symbole CROCHET_OUVRANT
5 nombre 5
] symbole CROCHET_FERMANT
= symbole EGAL
2 nombre 2
; symbole POINT_VIRGULE
$tab id_variable $tab
[ symbole CROCHET_OUVRANT
6 nombre 6
] symbole CROCHET_FERMANT
= symbole EGAL
3 nombre 3
; symbole POINT_VIRGULE
$tab id_variable $tab
[ symbole CROCHET_OUVRANT
7 nombre 7
] symbole CROCHET_FERMANT
= symbole EGAL
1 nombre 1
; symbole POINT_VIRGULE
$tab id_variable $tab
[ symbole CROCHET_OUVRANT
8 nombre 8
] symbole CROCHET_FERMANT
= symbole EGAL
4 nombre 4
; symbole POINT_VIRGULE
$tab id_variable $tab
[ symbole CROCHET_OUVRANT
9 nombre 9
] symbole CROCHET_FERMANT
= symbole EGAL
5 nombre 5
; symbole POINT_VIRGULE
} symbole ACCOLADE_FERMANTE
afficher id_fonction afficher
( symbole PARENTHESE_OUVRANTE
entier mot_clef entier
$n id_variable $n
) symbole PARENTHESE_FERMANTE
entier mot_clef entier
$i id_variable $i
; symbole POINT_VIRGULE
{ symbole ACCOLADE_OUVRANTE
$i id_variable $i
= symbole EGAL
0 nombre 0
; symbole POINT_VIRGULE
tantque mot_clef tantque
$i id_variable $i
< symbole INFERIEUR
$n id_variable $n
faire mot_clef faire
{ symbole ACCOLADE_OUVRANTE
ecrire mot_clef ecrire
( symbole PARENTHESE_OUVRANTE
$tab id_variable $tab
[ symbole CROCHET_OUVRANT
$i id_variable $i
] symbole CROCHET_FERMANT
) symbole PARENTHESE_FERMANTE
; symbole POINT_VIRGULE
$i id_variable $i
= symbole EGAL
$i id_variable $i
+ symbole PLUS
1 nombre 1
; symbole POINT_VIRGULE
} symbole ACCOLADE_FERMANTE
ecrire mot_clef ecrire
( symbole PARENTHESE_OUVRANTE
0 nombre 0
) symbole PARENTHESE_FERMANTE
; symbole POINT_VIRGULE
} symbole ACCOLADE_FERMANTE
echanger id_fonction echanger
( symbole PARENTHESE_OUVRANTE
entier mot_clef entier
$i id_variable $i
, symbole VIRGULE
entier mot_clef entier
$j id_variable $j
) symbole PARENTHESE_FERMANTE
entier mot_clef entier
$temp id_variable $temp
; symbole POINT_VIRGULE
{ symbole ACCOLADE_OUVRANTE
$temp id_variable $temp
= symbole EGAL
$tab id_variable $tab
[ symbole CROCHET_OUVRANT
$j id_variable $j
] symbole CROCHET_FERMANT
; symbole POINT_VIRGULE
$tab id_variable $tab
[ symbole CROCHET_OUVRANT
$j id_variable $j
] symbole CROCHET_FERMANT
= symbole EGAL
$tab id_variable $tab
[ symbole CROCHET_OUVRANT
$i id_variable $i
] symbole CROCHET_FERMANT
; symbole POINT_VIRGULE
$tab id_variable $tab
[ symbole CROCHET_OUVRANT
$i id_variable $i
] symbole CROCHET_FERMANT
= symbole EGAL
$temp id_variable $temp
; symbole POINT_VIRGULE
} symbole ACCOLADE_FERMANTE
trier id_fonction trier
( symbole PARENTHESE_OUVRANTE
entier mot_clef entier
$n id_variable $n
) symbole PARENTHESE_FERMANTE
entier mot_clef entier
$echange id_variable $echange
, symbole VIRGULE
entier mot_clef entier
$j id_variable $j
, symbole VIRGULE
entier mot_clef entier
$m id_variable $m
; symbole POINT_VIRGULE
{ symbole ACCOLADE_OUVRANTE
$m id_variable $m
= symbole EGAL
$n id_variable $n
; symbole POINT_VIRGULE
$echange id_variable $echange
= symbole EGAL
1 nombre 1
; symbole POINT_VIRGULE
tantque mot_clef tantque
$echange id_variable $echange
= symbole EGAL
1 nombre 1
faire mot_clef faire
{ symbole ACCOLADE_OUVRANTE
$echange id_variable $echange
= symbole EGAL
0 nombre 0
; symbole POINT_VIRGULE
$j id_variable $j
= symbole EGAL
0 nombre 0
; symbole POINT_VIRGULE
tantque mot_clef tantque
$j id_variable $j
< symbole INFERIEUR
$m id_variable $m
- symbole MOINS
1 nombre 1
faire mot_clef faire
{ symbole ACCOLADE_OUVRANTE
si mot_clef si
$tab id_variable $tab
[ symbole CROCHET_OUVRANT
$j id_variable $j
+ symbole PLUS
1 nombre 1
] symbole CROCHET_FERMANT
< symbole INFERIEUR
$tab id_variable $tab
[ symbole CROCHET_OUVRANT
$j id_variable $j
] symbole CROCHET_FERMANT
alors mot_clef alors
{ symbole ACCOLADE_OUVRANTE
echanger id_fonction echanger
( symbole PARENTHESE_OUVRANTE
$j id_variable $j
, symbole VIRGULE
$j id_variable $j
+ symbole PLUS
1 nombre 1
) symbole PARENTHESE_FERMANTE
; symbole POINT_VIRGULE
$echange id_variable $echange
= symbole EGAL
1 nombre 1
; symbole POINT_VIRGULE
} symbole ACCOLADE_FERMANTE
$j id_variable $j
= symbole EGAL
$j id_variable $j
+ symbole PLUS
1 nombre 1
; symbole POINT_VIRGULE
} symbole ACCOLADE_FERMANTE
$m id_variable $m
= symbole EGAL
$m id_variable $m
- symbole MOINS
1 nombre 1
; symbole POINT_VIRGULE
} symbole ACCOLADE_FERMANTE
} symbole ACCOLADE_FERMANTE
main id_fonction main
( symbole PARENTHESE_OUVRANTE
) symbole PARENTHESE_FERMANTE
{ symbole ACCOLADE_OUVRANTE
initialiser id_fonction initialiser
( symbole PARENTHESE_OUVRANTE
) symbole PARENTHESE_FERMANTE
; symbole POINT_VIRGULE
afficher id_fonction afficher
( symbole PARENTHESE_OUVRANTE
10 nombre 10
) symbole PARENTHESE_FERMANTE
; symbole POINT_VIRGULE
trier id_fonction trier
( symbole PARENTHESE_OUVRANTE
10 nombre 10
) symbole PARENTHESE_FERMANTE
; symbole POINT_VIRGULE
afficher id_fonction afficher
( symbole PARENTHESE_OUVRANTE
10 nombre 10
) symbole PARENTHESE_FERMANTE
; symbole POINT_VIRGULE
} symbole ACCOLADE_FERMANTE
symbole FIN

35
test/ref-mips/affect.mips Normal file
View File

@@ -0,0 +1,35 @@
.data
$a: .space 4
.text
__start:
jal main
li $v0, 10
syscall # stoppe l'execution du processus
main:
subi $sp, $sp, 4 # empile registre
sw $fp, 0($sp)
move $fp, $sp # nouvelle valeur de $fp
subi $sp, $sp, 4 # empile registre
sw $ra, 0($sp)
li $t0, 1
subi $sp, $sp, 4 # empile registre
sw $t0, 0($sp)
lw $t1, 0($sp) # depile vers registre
addi $sp, $sp, 4
sw $t1, $a # stocke variable
lw $t1, $a # lit variable dans $t1
subi $sp, $sp, 4 # empile registre
sw $t1, 0($sp)
lw $a0, 0($sp) # depile vers registre
addi $sp, $sp, 4
li $v0, 1
syscall # ecriture
li $a0, '\n'
li $v0, 11
syscall # ecrire char
lw $ra, 0($sp) # depile vers registre
addi $sp, $sp, 4
lw $fp, 0($sp) # depile vers registre
addi $sp, $sp, 4
jr $ra

91
test/ref-mips/boucle.mips Normal file
View File

@@ -0,0 +1,91 @@
.data
$i: .space 4
$carre: .space 4
.text
__start:
jal main
li $v0, 10
syscall # stoppe l'execution du processus
main:
subi $sp, $sp, 4 # empile registre
sw $fp, 0($sp)
move $fp, $sp # nouvelle valeur de $fp
subi $sp, $sp, 4 # empile registre
sw $ra, 0($sp)
li $t0, 0
subi $sp, $sp, 4 # empile registre
sw $t0, 0($sp)
lw $t1, 0($sp) # depile vers registre
addi $sp, $sp, 4
sw $t1, $i # stocke variable
e0:
lw $t1, $i # lit variable dans $t1
subi $sp, $sp, 4 # empile registre
sw $t1, 0($sp)
li $t0, 10
subi $sp, $sp, 4 # empile registre
sw $t0, 0($sp)
lw $t1, 0($sp) # depile vers registre
addi $sp, $sp, 4
lw $t0, 0($sp) # depile vers registre
addi $sp, $sp, 4
li $t2, -1 # inf
blt $t0, $t1, e2
li $t2, 0
e2:
subi $sp, $sp, 4 # empile registre
sw $t2, 0($sp)
lw $t0, 0($sp) # depile vers registre
addi $sp, $sp, 4
beq $t0, $zero, e1
lw $t1, $i # lit variable dans $t1
subi $sp, $sp, 4 # empile registre
sw $t1, 0($sp)
lw $t1, $i # lit variable dans $t1
subi $sp, $sp, 4 # empile registre
sw $t1, 0($sp)
lw $t1, 0($sp) # depile vers registre
addi $sp, $sp, 4
lw $t0, 0($sp) # depile vers registre
addi $sp, $sp, 4
mult $t0, $t1
mflo $t2
subi $sp, $sp, 4 # empile registre
sw $t2, 0($sp)
lw $t1, 0($sp) # depile vers registre
addi $sp, $sp, 4
sw $t1, $carre # stocke variable
lw $t1, $carre # lit variable dans $t1
subi $sp, $sp, 4 # empile registre
sw $t1, 0($sp)
lw $a0, 0($sp) # depile vers registre
addi $sp, $sp, 4
li $v0, 1
syscall # ecriture
li $a0, '\n'
li $v0, 11
syscall # ecrire char
lw $t1, $i # lit variable dans $t1
subi $sp, $sp, 4 # empile registre
sw $t1, 0($sp)
li $t0, 1
subi $sp, $sp, 4 # empile registre
sw $t0, 0($sp)
lw $t1, 0($sp) # depile vers registre
addi $sp, $sp, 4
lw $t0, 0($sp) # depile vers registre
addi $sp, $sp, 4
add $t2, $t0, $t1
subi $sp, $sp, 4 # empile registre
sw $t2, 0($sp)
lw $t1, 0($sp) # depile vers registre
addi $sp, $sp, 4
sw $t1, $i # stocke variable
j e0
e1:
lw $ra, 0($sp) # depile vers registre
addi $sp, $sp, 4
lw $fp, 0($sp) # depile vers registre
addi $sp, $sp, 4
jr $ra

View File

@@ -0,0 +1,40 @@
.data
$a: .space 4
.text
__start:
jal main
li $v0, 10
syscall # stoppe l'execution du processus
main:
subi $sp, $sp, 4 # empile registre
sw $fp, 0($sp)
move $fp, $sp # nouvelle valeur de $fp
subi $sp, $sp, 4 # empile registre
sw $ra, 0($sp)
li $t0, 5
subi $sp, $sp, 4 # empile registre
sw $t0, 0($sp)
li $t0, 2
subi $sp, $sp, 4 # empile registre
sw $t0, 0($sp)
lw $t1, 0($sp) # depile vers registre
addi $sp, $sp, 4
lw $t0, 0($sp) # depile vers registre
addi $sp, $sp, 4
mult $t0, $t1
mflo $t2
subi $sp, $sp, 4 # empile registre
sw $t2, 0($sp)
lw $a0, 0($sp) # depile vers registre
addi $sp, $sp, 4
li $v0, 1
syscall # ecriture
li $a0, '\n'
li $v0, 11
syscall # ecrire char
lw $ra, 0($sp) # depile vers registre
addi $sp, $sp, 4
lw $fp, 0($sp) # depile vers registre
addi $sp, $sp, 4
jr $ra

137
test/ref-mips/max.mips Normal file
View File

@@ -0,0 +1,137 @@
.data
.text
__start:
jal main
li $v0, 10
syscall # stoppe l'execution du processus
max:
subi $sp, $sp, 4 # empile registre
sw $fp, 0($sp)
move $fp, $sp # nouvelle valeur de $fp
subi $sp, $sp, 4 # empile registre
sw $ra, 0($sp)
lw $t1, 8($fp) # lit variable dans $t1
subi $sp, $sp, 4 # empile registre
sw $t1, 0($sp)
lw $t1, 4($fp) # lit variable dans $t1
subi $sp, $sp, 4 # empile registre
sw $t1, 0($sp)
lw $t1, 0($sp) # depile vers registre
addi $sp, $sp, 4
lw $t0, 0($sp) # depile vers registre
addi $sp, $sp, 4
li $t2, -1 # inf
blt $t0, $t1, e2
li $t2, 0
e2:
subi $sp, $sp, 4 # empile registre
sw $t2, 0($sp)
lw $t0, 0($sp) # depile vers registre
addi $sp, $sp, 4
beq $t0, $zero, e1
lw $t1, 4($fp) # lit variable dans $t1
subi $sp, $sp, 4 # empile registre
sw $t1, 0($sp)
lw $t0, 0($sp) # depile vers registre
addi $sp, $sp, 4
sw $t0, 12($fp) # ecriture de la valeur de retour
lw $ra, 0($sp) # depile vers registre
addi $sp, $sp, 4
lw $fp, 0($sp) # depile vers registre
addi $sp, $sp, 4
jr $ra
e1:
lw $t1, 8($fp) # lit variable dans $t1
subi $sp, $sp, 4 # empile registre
sw $t1, 0($sp)
lw $t0, 0($sp) # depile vers registre
addi $sp, $sp, 4
sw $t0, 12($fp) # ecriture de la valeur de retour
lw $ra, 0($sp) # depile vers registre
addi $sp, $sp, 4
lw $fp, 0($sp) # depile vers registre
addi $sp, $sp, 4
jr $ra
lw $ra, 0($sp) # depile vers registre
addi $sp, $sp, 4
lw $fp, 0($sp) # depile vers registre
addi $sp, $sp, 4
jr $ra
main:
subi $sp, $sp, 4 # empile registre
sw $fp, 0($sp)
move $fp, $sp # nouvelle valeur de $fp
subi $sp, $sp, 4 # empile registre
sw $ra, 0($sp)
subi $sp, $sp, 8 # allocation variables locales
li $v0, 5
syscall # lecture
subi $sp, $sp, 4 # empile registre
sw $v0, 0($sp)
lw $t1, 0($sp) # depile vers registre
addi $sp, $sp, 4
sw $t1, -8($fp) # stocke variable
li $v0, 5
syscall # lecture
subi $sp, $sp, 4 # empile registre
sw $v0, 0($sp)
lw $t1, 0($sp) # depile vers registre
addi $sp, $sp, 4
sw $t1, -12($fp) # stocke variable
subi $sp, $sp, 4 # allocation valeur de retour
# empile arg 0
lw $t1, -8($fp) # lit variable dans $t1
subi $sp, $sp, 4 # empile registre
sw $t1, 0($sp)
# empile arg 1
lw $t1, -12($fp) # lit variable dans $t1
subi $sp, $sp, 4 # empile registre
sw $t1, 0($sp)
jal max
addi $sp, $sp, 8 # desallocation parametres
lw $t1, -8($fp) # lit variable dans $t1
subi $sp, $sp, 4 # empile registre
sw $t1, 0($sp)
lw $t1, 0($sp) # depile vers registre
addi $sp, $sp, 4
lw $t0, 0($sp) # depile vers registre
addi $sp, $sp, 4
li $t2, -1 # egal
beq $t0, $t1, e5
li $t2, 0
e5:
subi $sp, $sp, 4 # empile registre
sw $t2, 0($sp)
lw $t0, 0($sp) # depile vers registre
addi $sp, $sp, 4
beq $t0, $zero, e3
lw $t1, -8($fp) # lit variable dans $t1
subi $sp, $sp, 4 # empile registre
sw $t1, 0($sp)
lw $a0, 0($sp) # depile vers registre
addi $sp, $sp, 4
li $v0, 1
syscall # ecriture
li $a0, '\n'
li $v0, 11
syscall # ecrire char
j e4
e3:
lw $t1, -12($fp) # lit variable dans $t1
subi $sp, $sp, 4 # empile registre
sw $t1, 0($sp)
lw $a0, 0($sp) # depile vers registre
addi $sp, $sp, 4
li $v0, 1
syscall # ecriture
li $a0, '\n'
li $v0, 11
syscall # ecrire char
e4:
addi $sp, $sp, 8 # desallocation variables locales
lw $ra, 0($sp) # depile vers registre
addi $sp, $sp, 4
lw $fp, 0($sp) # depile vers registre
addi $sp, $sp, 4
jr $ra

525
test/ref-mips/tri.mips Normal file
View File

@@ -0,0 +1,525 @@
.data
$tab: .space 40
.text
__start:
jal main
li $v0, 10
syscall # stoppe l'execution du processus
initialiser:
subi $sp, $sp, 4 # empile registre
sw $fp, 0($sp)
move $fp, $sp # nouvelle valeur de $fp
subi $sp, $sp, 4 # empile registre
sw $ra, 0($sp)
li $t0, 8
subi $sp, $sp, 4 # empile registre
sw $t0, 0($sp)
li $t0, 0
subi $sp, $sp, 4 # empile registre
sw $t0, 0($sp)
lw $t0, 0($sp) # depile vers registre
addi $sp, $sp, 4
add $t0, $t0, $t0
add $t0, $t0, $t0
lw $t1, 0($sp) # depile vers registre
addi $sp, $sp, 4
sw $t1, $tab($t0) # stocke variable
li $t0, 6
subi $sp, $sp, 4 # empile registre
sw $t0, 0($sp)
li $t0, 1
subi $sp, $sp, 4 # empile registre
sw $t0, 0($sp)
lw $t0, 0($sp) # depile vers registre
addi $sp, $sp, 4
add $t0, $t0, $t0
add $t0, $t0, $t0
lw $t1, 0($sp) # depile vers registre
addi $sp, $sp, 4
sw $t1, $tab($t0) # stocke variable
li $t0, 9
subi $sp, $sp, 4 # empile registre
sw $t0, 0($sp)
li $t0, 2
subi $sp, $sp, 4 # empile registre
sw $t0, 0($sp)
lw $t0, 0($sp) # depile vers registre
addi $sp, $sp, 4
add $t0, $t0, $t0
add $t0, $t0, $t0
lw $t1, 0($sp) # depile vers registre
addi $sp, $sp, 4
sw $t1, $tab($t0) # stocke variable
li $t0, 9
subi $sp, $sp, 4 # empile registre
sw $t0, 0($sp)
li $t0, 3
subi $sp, $sp, 4 # empile registre
sw $t0, 0($sp)
lw $t0, 0($sp) # depile vers registre
addi $sp, $sp, 4
add $t0, $t0, $t0
add $t0, $t0, $t0
lw $t1, 0($sp) # depile vers registre
addi $sp, $sp, 4
sw $t1, $tab($t0) # stocke variable
li $t0, 4
subi $sp, $sp, 4 # empile registre
sw $t0, 0($sp)
li $t0, 4
subi $sp, $sp, 4 # empile registre
sw $t0, 0($sp)
lw $t0, 0($sp) # depile vers registre
addi $sp, $sp, 4
add $t0, $t0, $t0
add $t0, $t0, $t0
lw $t1, 0($sp) # depile vers registre
addi $sp, $sp, 4
sw $t1, $tab($t0) # stocke variable
li $t0, 2
subi $sp, $sp, 4 # empile registre
sw $t0, 0($sp)
li $t0, 5
subi $sp, $sp, 4 # empile registre
sw $t0, 0($sp)
lw $t0, 0($sp) # depile vers registre
addi $sp, $sp, 4
add $t0, $t0, $t0
add $t0, $t0, $t0
lw $t1, 0($sp) # depile vers registre
addi $sp, $sp, 4
sw $t1, $tab($t0) # stocke variable
li $t0, 3
subi $sp, $sp, 4 # empile registre
sw $t0, 0($sp)
li $t0, 6
subi $sp, $sp, 4 # empile registre
sw $t0, 0($sp)
lw $t0, 0($sp) # depile vers registre
addi $sp, $sp, 4
add $t0, $t0, $t0
add $t0, $t0, $t0
lw $t1, 0($sp) # depile vers registre
addi $sp, $sp, 4
sw $t1, $tab($t0) # stocke variable
li $t0, 1
subi $sp, $sp, 4 # empile registre
sw $t0, 0($sp)
li $t0, 7
subi $sp, $sp, 4 # empile registre
sw $t0, 0($sp)
lw $t0, 0($sp) # depile vers registre
addi $sp, $sp, 4
add $t0, $t0, $t0
add $t0, $t0, $t0
lw $t1, 0($sp) # depile vers registre
addi $sp, $sp, 4
sw $t1, $tab($t0) # stocke variable
li $t0, 4
subi $sp, $sp, 4 # empile registre
sw $t0, 0($sp)
li $t0, 8
subi $sp, $sp, 4 # empile registre
sw $t0, 0($sp)
lw $t0, 0($sp) # depile vers registre
addi $sp, $sp, 4
add $t0, $t0, $t0
add $t0, $t0, $t0
lw $t1, 0($sp) # depile vers registre
addi $sp, $sp, 4
sw $t1, $tab($t0) # stocke variable
li $t0, 5
subi $sp, $sp, 4 # empile registre
sw $t0, 0($sp)
li $t0, 9
subi $sp, $sp, 4 # empile registre
sw $t0, 0($sp)
lw $t0, 0($sp) # depile vers registre
addi $sp, $sp, 4
add $t0, $t0, $t0
add $t0, $t0, $t0
lw $t1, 0($sp) # depile vers registre
addi $sp, $sp, 4
sw $t1, $tab($t0) # stocke variable
lw $ra, 0($sp) # depile vers registre
addi $sp, $sp, 4
lw $fp, 0($sp) # depile vers registre
addi $sp, $sp, 4
jr $ra
afficher:
subi $sp, $sp, 4 # empile registre
sw $fp, 0($sp)
move $fp, $sp # nouvelle valeur de $fp
subi $sp, $sp, 4 # empile registre
sw $ra, 0($sp)
subi $sp, $sp, 4 # allocation variables locales
li $t0, 0
subi $sp, $sp, 4 # empile registre
sw $t0, 0($sp)
lw $t1, 0($sp) # depile vers registre
addi $sp, $sp, 4
sw $t1, -8($fp) # stocke variable
e0:
lw $t1, -8($fp) # lit variable dans $t1
subi $sp, $sp, 4 # empile registre
sw $t1, 0($sp)
lw $t1, 4($fp) # lit variable dans $t1
subi $sp, $sp, 4 # empile registre
sw $t1, 0($sp)
lw $t1, 0($sp) # depile vers registre
addi $sp, $sp, 4
lw $t0, 0($sp) # depile vers registre
addi $sp, $sp, 4
li $t2, -1 # inf
blt $t0, $t1, e2
li $t2, 0
e2:
subi $sp, $sp, 4 # empile registre
sw $t2, 0($sp)
lw $t0, 0($sp) # depile vers registre
addi $sp, $sp, 4
beq $t0, $zero, e1
lw $t1, -8($fp) # lit variable dans $t1
subi $sp, $sp, 4 # empile registre
sw $t1, 0($sp)
lw $t0, 0($sp) # depile vers registre
addi $sp, $sp, 4
add $t0, $t0, $t0
add $t0, $t0, $t0
lw $t1, $tab($t0) # lit variable dans $t1
subi $sp, $sp, 4 # empile registre
sw $t1, 0($sp)
lw $a0, 0($sp) # depile vers registre
addi $sp, $sp, 4
li $v0, 1
syscall # ecriture
li $a0, '\n'
li $v0, 11
syscall # ecrire char
lw $t1, -8($fp) # lit variable dans $t1
subi $sp, $sp, 4 # empile registre
sw $t1, 0($sp)
li $t0, 1
subi $sp, $sp, 4 # empile registre
sw $t0, 0($sp)
lw $t1, 0($sp) # depile vers registre
addi $sp, $sp, 4
lw $t0, 0($sp) # depile vers registre
addi $sp, $sp, 4
add $t2, $t0, $t1
subi $sp, $sp, 4 # empile registre
sw $t2, 0($sp)
lw $t1, 0($sp) # depile vers registre
addi $sp, $sp, 4
sw $t1, -8($fp) # stocke variable
j e0
e1:
li $t0, 0
subi $sp, $sp, 4 # empile registre
sw $t0, 0($sp)
lw $a0, 0($sp) # depile vers registre
addi $sp, $sp, 4
li $v0, 1
syscall # ecriture
li $a0, '\n'
li $v0, 11
syscall # ecrire char
addi $sp, $sp, 4 # desallocation variables locales
lw $ra, 0($sp) # depile vers registre
addi $sp, $sp, 4
lw $fp, 0($sp) # depile vers registre
addi $sp, $sp, 4
jr $ra
echanger:
subi $sp, $sp, 4 # empile registre
sw $fp, 0($sp)
move $fp, $sp # nouvelle valeur de $fp
subi $sp, $sp, 4 # empile registre
sw $ra, 0($sp)
subi $sp, $sp, 4 # allocation variables locales
lw $t1, 4($fp) # lit variable dans $t1
subi $sp, $sp, 4 # empile registre
sw $t1, 0($sp)
lw $t0, 0($sp) # depile vers registre
addi $sp, $sp, 4
add $t0, $t0, $t0
add $t0, $t0, $t0
lw $t1, $tab($t0) # lit variable dans $t1
subi $sp, $sp, 4 # empile registre
sw $t1, 0($sp)
lw $t1, 0($sp) # depile vers registre
addi $sp, $sp, 4
sw $t1, -8($fp) # stocke variable
lw $t1, 8($fp) # lit variable dans $t1
subi $sp, $sp, 4 # empile registre
sw $t1, 0($sp)
lw $t0, 0($sp) # depile vers registre
addi $sp, $sp, 4
add $t0, $t0, $t0
add $t0, $t0, $t0
lw $t1, $tab($t0) # lit variable dans $t1
subi $sp, $sp, 4 # empile registre
sw $t1, 0($sp)
lw $t1, 4($fp) # lit variable dans $t1
subi $sp, $sp, 4 # empile registre
sw $t1, 0($sp)
lw $t0, 0($sp) # depile vers registre
addi $sp, $sp, 4
add $t0, $t0, $t0
add $t0, $t0, $t0
lw $t1, 0($sp) # depile vers registre
addi $sp, $sp, 4
sw $t1, $tab($t0) # stocke variable
lw $t1, -8($fp) # lit variable dans $t1
subi $sp, $sp, 4 # empile registre
sw $t1, 0($sp)
lw $t1, 8($fp) # lit variable dans $t1
subi $sp, $sp, 4 # empile registre
sw $t1, 0($sp)
lw $t0, 0($sp) # depile vers registre
addi $sp, $sp, 4
add $t0, $t0, $t0
add $t0, $t0, $t0
lw $t1, 0($sp) # depile vers registre
addi $sp, $sp, 4
sw $t1, $tab($t0) # stocke variable
addi $sp, $sp, 4 # desallocation variables locales
lw $ra, 0($sp) # depile vers registre
addi $sp, $sp, 4
lw $fp, 0($sp) # depile vers registre
addi $sp, $sp, 4
jr $ra
trier:
subi $sp, $sp, 4 # empile registre
sw $fp, 0($sp)
move $fp, $sp # nouvelle valeur de $fp
subi $sp, $sp, 4 # empile registre
sw $ra, 0($sp)
subi $sp, $sp, 12 # allocation variables locales
lw $t1, 4($fp) # lit variable dans $t1
subi $sp, $sp, 4 # empile registre
sw $t1, 0($sp)
lw $t1, 0($sp) # depile vers registre
addi $sp, $sp, 4
sw $t1, -16($fp) # stocke variable
li $t0, 1
subi $sp, $sp, 4 # empile registre
sw $t0, 0($sp)
lw $t1, 0($sp) # depile vers registre
addi $sp, $sp, 4
sw $t1, -8($fp) # stocke variable
e3:
lw $t1, -8($fp) # lit variable dans $t1
subi $sp, $sp, 4 # empile registre
sw $t1, 0($sp)
li $t0, 1
subi $sp, $sp, 4 # empile registre
sw $t0, 0($sp)
lw $t1, 0($sp) # depile vers registre
addi $sp, $sp, 4
lw $t0, 0($sp) # depile vers registre
addi $sp, $sp, 4
li $t2, -1 # egal
beq $t0, $t1, e5
li $t2, 0
e5:
subi $sp, $sp, 4 # empile registre
sw $t2, 0($sp)
lw $t0, 0($sp) # depile vers registre
addi $sp, $sp, 4
beq $t0, $zero, e4
li $t0, 0
subi $sp, $sp, 4 # empile registre
sw $t0, 0($sp)
lw $t1, 0($sp) # depile vers registre
addi $sp, $sp, 4
sw $t1, -8($fp) # stocke variable
li $t0, 0
subi $sp, $sp, 4 # empile registre
sw $t0, 0($sp)
lw $t1, 0($sp) # depile vers registre
addi $sp, $sp, 4
sw $t1, -12($fp) # stocke variable
e6:
lw $t1, -12($fp) # lit variable dans $t1
subi $sp, $sp, 4 # empile registre
sw $t1, 0($sp)
lw $t1, -16($fp) # lit variable dans $t1
subi $sp, $sp, 4 # empile registre
sw $t1, 0($sp)
li $t0, 1
subi $sp, $sp, 4 # empile registre
sw $t0, 0($sp)
lw $t1, 0($sp) # depile vers registre
addi $sp, $sp, 4
lw $t0, 0($sp) # depile vers registre
addi $sp, $sp, 4
sub $t2, $t0, $t1
subi $sp, $sp, 4 # empile registre
sw $t2, 0($sp)
lw $t1, 0($sp) # depile vers registre
addi $sp, $sp, 4
lw $t0, 0($sp) # depile vers registre
addi $sp, $sp, 4
li $t2, -1 # inf
blt $t0, $t1, e8
li $t2, 0
e8:
subi $sp, $sp, 4 # empile registre
sw $t2, 0($sp)
lw $t0, 0($sp) # depile vers registre
addi $sp, $sp, 4
beq $t0, $zero, e7
lw $t1, -12($fp) # lit variable dans $t1
subi $sp, $sp, 4 # empile registre
sw $t1, 0($sp)
li $t0, 1
subi $sp, $sp, 4 # empile registre
sw $t0, 0($sp)
lw $t1, 0($sp) # depile vers registre
addi $sp, $sp, 4
lw $t0, 0($sp) # depile vers registre
addi $sp, $sp, 4
add $t2, $t0, $t1
subi $sp, $sp, 4 # empile registre
sw $t2, 0($sp)
lw $t0, 0($sp) # depile vers registre
addi $sp, $sp, 4
add $t0, $t0, $t0
add $t0, $t0, $t0
lw $t1, $tab($t0) # lit variable dans $t1
subi $sp, $sp, 4 # empile registre
sw $t1, 0($sp)
lw $t1, -12($fp) # lit variable dans $t1
subi $sp, $sp, 4 # empile registre
sw $t1, 0($sp)
lw $t0, 0($sp) # depile vers registre
addi $sp, $sp, 4
add $t0, $t0, $t0
add $t0, $t0, $t0
lw $t1, $tab($t0) # lit variable dans $t1
subi $sp, $sp, 4 # empile registre
sw $t1, 0($sp)
lw $t1, 0($sp) # depile vers registre
addi $sp, $sp, 4
lw $t0, 0($sp) # depile vers registre
addi $sp, $sp, 4
li $t2, -1 # inf
blt $t0, $t1, e11
li $t2, 0
e11:
subi $sp, $sp, 4 # empile registre
sw $t2, 0($sp)
lw $t0, 0($sp) # depile vers registre
addi $sp, $sp, 4
beq $t0, $zero, e10
subi $sp, $sp, 4 # allocation valeur de retour
# empile arg 0
lw $t1, -12($fp) # lit variable dans $t1
subi $sp, $sp, 4 # empile registre
sw $t1, 0($sp)
# empile arg 1
lw $t1, -12($fp) # lit variable dans $t1
subi $sp, $sp, 4 # empile registre
sw $t1, 0($sp)
li $t0, 1
subi $sp, $sp, 4 # empile registre
sw $t0, 0($sp)
lw $t1, 0($sp) # depile vers registre
addi $sp, $sp, 4
lw $t0, 0($sp) # depile vers registre
addi $sp, $sp, 4
add $t2, $t0, $t1
subi $sp, $sp, 4 # empile registre
sw $t2, 0($sp)
jal echanger
addi $sp, $sp, 8 # desallocation parametres
addi $sp, $sp, 4 # valeur de retour ignoree
li $t0, 1
subi $sp, $sp, 4 # empile registre
sw $t0, 0($sp)
lw $t1, 0($sp) # depile vers registre
addi $sp, $sp, 4
sw $t1, -8($fp) # stocke variable
e10:
lw $t1, -12($fp) # lit variable dans $t1
subi $sp, $sp, 4 # empile registre
sw $t1, 0($sp)
li $t0, 1
subi $sp, $sp, 4 # empile registre
sw $t0, 0($sp)
lw $t1, 0($sp) # depile vers registre
addi $sp, $sp, 4
lw $t0, 0($sp) # depile vers registre
addi $sp, $sp, 4
add $t2, $t0, $t1
subi $sp, $sp, 4 # empile registre
sw $t2, 0($sp)
lw $t1, 0($sp) # depile vers registre
addi $sp, $sp, 4
sw $t1, -12($fp) # stocke variable
j e6
e7:
lw $t1, -16($fp) # lit variable dans $t1
subi $sp, $sp, 4 # empile registre
sw $t1, 0($sp)
li $t0, 1
subi $sp, $sp, 4 # empile registre
sw $t0, 0($sp)
lw $t1, 0($sp) # depile vers registre
addi $sp, $sp, 4
lw $t0, 0($sp) # depile vers registre
addi $sp, $sp, 4
sub $t2, $t0, $t1
subi $sp, $sp, 4 # empile registre
sw $t2, 0($sp)
lw $t1, 0($sp) # depile vers registre
addi $sp, $sp, 4
sw $t1, -16($fp) # stocke variable
j e3
e4:
addi $sp, $sp, 12 # desallocation variables locales
lw $ra, 0($sp) # depile vers registre
addi $sp, $sp, 4
lw $fp, 0($sp) # depile vers registre
addi $sp, $sp, 4
jr $ra
main:
subi $sp, $sp, 4 # empile registre
sw $fp, 0($sp)
move $fp, $sp # nouvelle valeur de $fp
subi $sp, $sp, 4 # empile registre
sw $ra, 0($sp)
subi $sp, $sp, 4 # allocation valeur de retour
jal initialiser
addi $sp, $sp, 4 # valeur de retour ignoree
subi $sp, $sp, 4 # allocation valeur de retour
# empile arg 0
li $t0, 10
subi $sp, $sp, 4 # empile registre
sw $t0, 0($sp)
jal afficher
addi $sp, $sp, 4 # desallocation parametres
addi $sp, $sp, 4 # valeur de retour ignoree
subi $sp, $sp, 4 # allocation valeur de retour
# empile arg 0
li $t0, 10
subi $sp, $sp, 4 # empile registre
sw $t0, 0($sp)
jal trier
addi $sp, $sp, 4 # desallocation parametres
addi $sp, $sp, 4 # valeur de retour ignoree
subi $sp, $sp, 4 # allocation valeur de retour
# empile arg 0
li $t0, 10
subi $sp, $sp, 4 # empile registre
sw $t0, 0($sp)
jal afficher
addi $sp, $sp, 4 # desallocation parametres
addi $sp, $sp, 4 # valeur de retour ignoree
lw $ra, 0($sp) # depile vers registre
addi $sp, $sp, 4
lw $fp, 0($sp) # depile vers registre
addi $sp, $sp, 4
jr $ra

113
test/ref-synt/affect.synt Normal file
View File

@@ -0,0 +1,113 @@
<programme>
<optDecVariables>
<listeDecVariables>
<declarationVariable>
<mot_clef>entier</mot_clef>
<id_variable>$a</id_variable>
<optTailleTableau>
</optTailleTableau>
</declarationVariable>
<listeDecVariablesBis>
</listeDecVariablesBis>
</listeDecVariables>
<symbole>POINT_VIRGULE</symbole>
</optDecVariables>
<listeDecFonctions>
<declarationFonction>
<id_fonction>main</id_fonction>
<listeParam>
<symbole>PARENTHESE_OUVRANTE</symbole>
<optListeDecVariables>
</optListeDecVariables>
<symbole>PARENTHESE_FERMANTE</symbole>
</listeParam>
<optDecVariables>
</optDecVariables>
<instructionBloc>
<symbole>ACCOLADE_OUVRANTE</symbole>
<listeInstructions>
<instruction>
<instructionAffect>
<var>
<id_variable>$a</id_variable>
<optIndice>
</optIndice>
</var>
<symbole>EGAL</symbole>
<expression>
<conjonction>
<negation>
<comparaison>
<expArith>
<terme>
<facteur>
<nombre>1</nombre>
</facteur>
<termeBis>
</termeBis>
</terme>
<expArithBis>
</expArithBis>
</expArith>
<comparaisonBis>
</comparaisonBis>
</comparaison>
</negation>
<conjonctionBis>
</conjonctionBis>
</conjonction>
<expressionBis>
</expressionBis>
</expression>
<symbole>POINT_VIRGULE</symbole>
</instructionAffect>
</instruction>
<listeInstructions>
<instruction>
<instructionEcriture>
<mot_clef>ecrire</mot_clef>
<symbole>PARENTHESE_OUVRANTE</symbole>
<expression>
<conjonction>
<negation>
<comparaison>
<expArith>
<terme>
<facteur>
<var>
<id_variable>$a</id_variable>
<optIndice>
</optIndice>
</var>
</facteur>
<termeBis>
</termeBis>
</terme>
<expArithBis>
</expArithBis>
</expArith>
<comparaisonBis>
</comparaisonBis>
</comparaison>
</negation>
<conjonctionBis>
</conjonctionBis>
</conjonction>
<expressionBis>
</expressionBis>
</expression>
<symbole>PARENTHESE_FERMANTE</symbole>
<symbole>POINT_VIRGULE</symbole>
</instructionEcriture>
</instruction>
<listeInstructions>
</listeInstructions>
</listeInstructions>
</listeInstructions>
<symbole>ACCOLADE_FERMANTE</symbole>
</instructionBloc>
</declarationFonction>
<listeDecFonctions>
</listeDecFonctions>
</listeDecFonctions>
</programme>

283
test/ref-synt/boucle.synt Normal file
View File

@@ -0,0 +1,283 @@
<programme>
<optDecVariables>
<listeDecVariables>
<declarationVariable>
<mot_clef>entier</mot_clef>
<id_variable>$i</id_variable>
<optTailleTableau>
</optTailleTableau>
</declarationVariable>
<listeDecVariablesBis>
<symbole>VIRGULE</symbole>
<declarationVariable>
<mot_clef>entier</mot_clef>
<id_variable>$carre</id_variable>
<optTailleTableau>
</optTailleTableau>
</declarationVariable>
<listeDecVariablesBis>
</listeDecVariablesBis>
</listeDecVariablesBis>
</listeDecVariables>
<symbole>POINT_VIRGULE</symbole>
</optDecVariables>
<listeDecFonctions>
<declarationFonction>
<id_fonction>main</id_fonction>
<listeParam>
<symbole>PARENTHESE_OUVRANTE</symbole>
<optListeDecVariables>
</optListeDecVariables>
<symbole>PARENTHESE_FERMANTE</symbole>
</listeParam>
<optDecVariables>
</optDecVariables>
<instructionBloc>
<symbole>ACCOLADE_OUVRANTE</symbole>
<listeInstructions>
<instruction>
<instructionAffect>
<var>
<id_variable>$i</id_variable>
<optIndice>
</optIndice>
</var>
<symbole>EGAL</symbole>
<expression>
<conjonction>
<negation>
<comparaison>
<expArith>
<terme>
<facteur>
<nombre>0</nombre>
</facteur>
<termeBis>
</termeBis>
</terme>
<expArithBis>
</expArithBis>
</expArith>
<comparaisonBis>
</comparaisonBis>
</comparaison>
</negation>
<conjonctionBis>
</conjonctionBis>
</conjonction>
<expressionBis>
</expressionBis>
</expression>
<symbole>POINT_VIRGULE</symbole>
</instructionAffect>
</instruction>
<listeInstructions>
<instruction>
<instructionTantque>
<mot_clef>tantque</mot_clef>
<expression>
<conjonction>
<negation>
<comparaison>
<expArith>
<terme>
<facteur>
<var>
<id_variable>$i</id_variable>
<optIndice>
</optIndice>
</var>
</facteur>
<termeBis>
</termeBis>
</terme>
<expArithBis>
</expArithBis>
</expArith>
<comparaisonBis>
<symbole>INFERIEUR</symbole>
<expArith>
<terme>
<facteur>
<nombre>10</nombre>
</facteur>
<termeBis>
</termeBis>
</terme>
<expArithBis>
</expArithBis>
</expArith>
<comparaisonBis>
</comparaisonBis>
</comparaisonBis>
</comparaison>
</negation>
<conjonctionBis>
</conjonctionBis>
</conjonction>
<expressionBis>
</expressionBis>
</expression>
<mot_clef>faire</mot_clef>
<instructionBloc>
<symbole>ACCOLADE_OUVRANTE</symbole>
<listeInstructions>
<instruction>
<instructionAffect>
<var>
<id_variable>$carre</id_variable>
<optIndice>
</optIndice>
</var>
<symbole>EGAL</symbole>
<expression>
<conjonction>
<negation>
<comparaison>
<expArith>
<terme>
<facteur>
<var>
<id_variable>$i</id_variable>
<optIndice>
</optIndice>
</var>
</facteur>
<termeBis>
<symbole>FOIS</symbole>
<facteur>
<var>
<id_variable>$i</id_variable>
<optIndice>
</optIndice>
</var>
</facteur>
<termeBis>
</termeBis>
</termeBis>
</terme>
<expArithBis>
</expArithBis>
</expArith>
<comparaisonBis>
</comparaisonBis>
</comparaison>
</negation>
<conjonctionBis>
</conjonctionBis>
</conjonction>
<expressionBis>
</expressionBis>
</expression>
<symbole>POINT_VIRGULE</symbole>
</instructionAffect>
</instruction>
<listeInstructions>
<instruction>
<instructionEcriture>
<mot_clef>ecrire</mot_clef>
<symbole>PARENTHESE_OUVRANTE</symbole>
<expression>
<conjonction>
<negation>
<comparaison>
<expArith>
<terme>
<facteur>
<var>
<id_variable>$carre</id_variable>
<optIndice>
</optIndice>
</var>
</facteur>
<termeBis>
</termeBis>
</terme>
<expArithBis>
</expArithBis>
</expArith>
<comparaisonBis>
</comparaisonBis>
</comparaison>
</negation>
<conjonctionBis>
</conjonctionBis>
</conjonction>
<expressionBis>
</expressionBis>
</expression>
<symbole>PARENTHESE_FERMANTE</symbole>
<symbole>POINT_VIRGULE</symbole>
</instructionEcriture>
</instruction>
<listeInstructions>
<instruction>
<instructionAffect>
<var>
<id_variable>$i</id_variable>
<optIndice>
</optIndice>
</var>
<symbole>EGAL</symbole>
<expression>
<conjonction>
<negation>
<comparaison>
<expArith>
<terme>
<facteur>
<var>
<id_variable>$i</id_variable>
<optIndice>
</optIndice>
</var>
</facteur>
<termeBis>
</termeBis>
</terme>
<expArithBis>
<symbole>PLUS</symbole>
<terme>
<facteur>
<nombre>1</nombre>
</facteur>
<termeBis>
</termeBis>
</terme>
<expArithBis>
</expArithBis>
</expArithBis>
</expArith>
<comparaisonBis>
</comparaisonBis>
</comparaison>
</negation>
<conjonctionBis>
</conjonctionBis>
</conjonction>
<expressionBis>
</expressionBis>
</expression>
<symbole>POINT_VIRGULE</symbole>
</instructionAffect>
</instruction>
<listeInstructions>
</listeInstructions>
</listeInstructions>
</listeInstructions>
</listeInstructions>
<symbole>ACCOLADE_FERMANTE</symbole>
</instructionBloc>
</instructionTantque>
</instruction>
<listeInstructions>
</listeInstructions>
</listeInstructions>
</listeInstructions>
<symbole>ACCOLADE_FERMANTE</symbole>
</instructionBloc>
</declarationFonction>
<listeDecFonctions>
</listeDecFonctions>
</listeDecFonctions>
</programme>

View File

@@ -0,0 +1,77 @@
<programme>
<optDecVariables>
<listeDecVariables>
<declarationVariable>
<mot_clef>entier</mot_clef>
<id_variable>$a</id_variable>
<optTailleTableau>
</optTailleTableau>
</declarationVariable>
<listeDecVariablesBis>
</listeDecVariablesBis>
</listeDecVariables>
<symbole>POINT_VIRGULE</symbole>
</optDecVariables>
<listeDecFonctions>
<declarationFonction>
<id_fonction>main</id_fonction>
<listeParam>
<symbole>PARENTHESE_OUVRANTE</symbole>
<optListeDecVariables>
</optListeDecVariables>
<symbole>PARENTHESE_FERMANTE</symbole>
</listeParam>
<optDecVariables>
</optDecVariables>
<instructionBloc>
<symbole>ACCOLADE_OUVRANTE</symbole>
<listeInstructions>
<instruction>
<instructionEcriture>
<mot_clef>ecrire</mot_clef>
<symbole>PARENTHESE_OUVRANTE</symbole>
<expression>
<conjonction>
<negation>
<comparaison>
<expArith>
<terme>
<facteur>
<nombre>5</nombre>
</facteur>
<termeBis>
<symbole>FOIS</symbole>
<facteur>
<nombre>2</nombre>
</facteur>
<termeBis>
</termeBis>
</termeBis>
</terme>
<expArithBis>
</expArithBis>
</expArith>
<comparaisonBis>
</comparaisonBis>
</comparaison>
</negation>
<conjonctionBis>
</conjonctionBis>
</conjonction>
<expressionBis>
</expressionBis>
</expression>
<symbole>PARENTHESE_FERMANTE</symbole>
<symbole>POINT_VIRGULE</symbole>
</instructionEcriture>
</instruction>
<listeInstructions>
</listeInstructions>
</listeInstructions>
<symbole>ACCOLADE_FERMANTE</symbole>
</instructionBloc>
</declarationFonction>
<listeDecFonctions>
</listeDecFonctions>
</listeDecFonctions>
</programme>

513
test/ref-synt/max.synt Normal file
View File

@@ -0,0 +1,513 @@
<programme>
<optDecVariables>
</optDecVariables>
<listeDecFonctions>
<declarationFonction>
<id_fonction>max</id_fonction>
<listeParam>
<symbole>PARENTHESE_OUVRANTE</symbole>
<optListeDecVariables>
<listeDecVariables>
<declarationVariable>
<mot_clef>entier</mot_clef>
<id_variable>$a</id_variable>
<optTailleTableau>
</optTailleTableau>
</declarationVariable>
<listeDecVariablesBis>
<symbole>VIRGULE</symbole>
<declarationVariable>
<mot_clef>entier</mot_clef>
<id_variable>$b</id_variable>
<optTailleTableau>
</optTailleTableau>
</declarationVariable>
<listeDecVariablesBis>
</listeDecVariablesBis>
</listeDecVariablesBis>
</listeDecVariables>
</optListeDecVariables>
<symbole>PARENTHESE_FERMANTE</symbole>
</listeParam>
<optDecVariables>
</optDecVariables>
<instructionBloc>
<symbole>ACCOLADE_OUVRANTE</symbole>
<listeInstructions>
<instruction>
<instructionSi>
<mot_clef>si</mot_clef>
<expression>
<conjonction>
<negation>
<comparaison>
<expArith>
<terme>
<facteur>
<var>
<id_variable>$a</id_variable>
<optIndice>
</optIndice>
</var>
</facteur>
<termeBis>
</termeBis>
</terme>
<expArithBis>
</expArithBis>
</expArith>
<comparaisonBis>
<symbole>INFERIEUR</symbole>
<expArith>
<terme>
<facteur>
<var>
<id_variable>$b</id_variable>
<optIndice>
</optIndice>
</var>
</facteur>
<termeBis>
</termeBis>
</terme>
<expArithBis>
</expArithBis>
</expArith>
<comparaisonBis>
</comparaisonBis>
</comparaisonBis>
</comparaison>
</negation>
<conjonctionBis>
</conjonctionBis>
</conjonction>
<expressionBis>
</expressionBis>
</expression>
<mot_clef>alors</mot_clef>
<instructionBloc>
<symbole>ACCOLADE_OUVRANTE</symbole>
<listeInstructions>
<instruction>
<instructionRetour>
<mot_clef>retour</mot_clef>
<expression>
<conjonction>
<negation>
<comparaison>
<expArith>
<terme>
<facteur>
<var>
<id_variable>$b</id_variable>
<optIndice>
</optIndice>
</var>
</facteur>
<termeBis>
</termeBis>
</terme>
<expArithBis>
</expArithBis>
</expArith>
<comparaisonBis>
</comparaisonBis>
</comparaison>
</negation>
<conjonctionBis>
</conjonctionBis>
</conjonction>
<expressionBis>
</expressionBis>
</expression>
<symbole>POINT_VIRGULE</symbole>
</instructionRetour>
</instruction>
<listeInstructions>
</listeInstructions>
</listeInstructions>
<symbole>ACCOLADE_FERMANTE</symbole>
</instructionBloc>
<optSinon>
</optSinon>
</instructionSi>
</instruction>
<listeInstructions>
<instruction>
<instructionRetour>
<mot_clef>retour</mot_clef>
<expression>
<conjonction>
<negation>
<comparaison>
<expArith>
<terme>
<facteur>
<var>
<id_variable>$a</id_variable>
<optIndice>
</optIndice>
</var>
</facteur>
<termeBis>
</termeBis>
</terme>
<expArithBis>
</expArithBis>
</expArith>
<comparaisonBis>
</comparaisonBis>
</comparaison>
</negation>
<conjonctionBis>
</conjonctionBis>
</conjonction>
<expressionBis>
</expressionBis>
</expression>
<symbole>POINT_VIRGULE</symbole>
</instructionRetour>
</instruction>
<listeInstructions>
</listeInstructions>
</listeInstructions>
</listeInstructions>
<symbole>ACCOLADE_FERMANTE</symbole>
</instructionBloc>
</declarationFonction>
<listeDecFonctions>
<declarationFonction>
<id_fonction>main</id_fonction>
<listeParam>
<symbole>PARENTHESE_OUVRANTE</symbole>
<optListeDecVariables>
</optListeDecVariables>
<symbole>PARENTHESE_FERMANTE</symbole>
</listeParam>
<optDecVariables>
<listeDecVariables>
<declarationVariable>
<mot_clef>entier</mot_clef>
<id_variable>$v_1</id_variable>
<optTailleTableau>
</optTailleTableau>
</declarationVariable>
<listeDecVariablesBis>
<symbole>VIRGULE</symbole>
<declarationVariable>
<mot_clef>entier</mot_clef>
<id_variable>$v_2</id_variable>
<optTailleTableau>
</optTailleTableau>
</declarationVariable>
<listeDecVariablesBis>
</listeDecVariablesBis>
</listeDecVariablesBis>
</listeDecVariables>
<symbole>POINT_VIRGULE</symbole>
</optDecVariables>
<instructionBloc>
<symbole>ACCOLADE_OUVRANTE</symbole>
<listeInstructions>
<instruction>
<instructionAffect>
<var>
<id_variable>$v_1</id_variable>
<optIndice>
</optIndice>
</var>
<symbole>EGAL</symbole>
<expression>
<conjonction>
<negation>
<comparaison>
<expArith>
<terme>
<facteur>
<mot_clef>lire</mot_clef>
<symbole>PARENTHESE_OUVRANTE</symbole>
<symbole>PARENTHESE_FERMANTE</symbole>
</facteur>
<termeBis>
</termeBis>
</terme>
<expArithBis>
</expArithBis>
</expArith>
<comparaisonBis>
</comparaisonBis>
</comparaison>
</negation>
<conjonctionBis>
</conjonctionBis>
</conjonction>
<expressionBis>
</expressionBis>
</expression>
<symbole>POINT_VIRGULE</symbole>
</instructionAffect>
</instruction>
<listeInstructions>
<instruction>
<instructionAffect>
<var>
<id_variable>$v_2</id_variable>
<optIndice>
</optIndice>
</var>
<symbole>EGAL</symbole>
<expression>
<conjonction>
<negation>
<comparaison>
<expArith>
<terme>
<facteur>
<mot_clef>lire</mot_clef>
<symbole>PARENTHESE_OUVRANTE</symbole>
<symbole>PARENTHESE_FERMANTE</symbole>
</facteur>
<termeBis>
</termeBis>
</terme>
<expArithBis>
</expArithBis>
</expArith>
<comparaisonBis>
</comparaisonBis>
</comparaison>
</negation>
<conjonctionBis>
</conjonctionBis>
</conjonction>
<expressionBis>
</expressionBis>
</expression>
<symbole>POINT_VIRGULE</symbole>
</instructionAffect>
</instruction>
<listeInstructions>
<instruction>
<instructionSi>
<mot_clef>si</mot_clef>
<expression>
<conjonction>
<negation>
<comparaison>
<expArith>
<terme>
<facteur>
<appelFct>
<id_fonction>max</id_fonction>
<symbole>PARENTHESE_OUVRANTE</symbole>
<listeExpressions>
<expression>
<conjonction>
<negation>
<comparaison>
<expArith>
<terme>
<facteur>
<var>
<id_variable>$v_1</id_variable>
<optIndice>
</optIndice>
</var>
</facteur>
<termeBis>
</termeBis>
</terme>
<expArithBis>
</expArithBis>
</expArith>
<comparaisonBis>
</comparaisonBis>
</comparaison>
</negation>
<conjonctionBis>
</conjonctionBis>
</conjonction>
<expressionBis>
</expressionBis>
</expression>
<listeExpressionsBis>
<symbole>VIRGULE</symbole>
<expression>
<conjonction>
<negation>
<comparaison>
<expArith>
<terme>
<facteur>
<var>
<id_variable>$v_2</id_variable>
<optIndice>
</optIndice>
</var>
</facteur>
<termeBis>
</termeBis>
</terme>
<expArithBis>
</expArithBis>
</expArith>
<comparaisonBis>
</comparaisonBis>
</comparaison>
</negation>
<conjonctionBis>
</conjonctionBis>
</conjonction>
<expressionBis>
</expressionBis>
</expression>
<listeExpressionsBis>
</listeExpressionsBis>
</listeExpressionsBis>
</listeExpressions>
<symbole>PARENTHESE_FERMANTE</symbole>
</appelFct>
</facteur>
<termeBis>
</termeBis>
</terme>
<expArithBis>
</expArithBis>
</expArith>
<comparaisonBis>
<symbole>EGAL</symbole>
<expArith>
<terme>
<facteur>
<var>
<id_variable>$v_1</id_variable>
<optIndice>
</optIndice>
</var>
</facteur>
<termeBis>
</termeBis>
</terme>
<expArithBis>
</expArithBis>
</expArith>
<comparaisonBis>
</comparaisonBis>
</comparaisonBis>
</comparaison>
</negation>
<conjonctionBis>
</conjonctionBis>
</conjonction>
<expressionBis>
</expressionBis>
</expression>
<mot_clef>alors</mot_clef>
<instructionBloc>
<symbole>ACCOLADE_OUVRANTE</symbole>
<listeInstructions>
<instruction>
<instructionEcriture>
<mot_clef>ecrire</mot_clef>
<symbole>PARENTHESE_OUVRANTE</symbole>
<expression>
<conjonction>
<negation>
<comparaison>
<expArith>
<terme>
<facteur>
<var>
<id_variable>$v_1</id_variable>
<optIndice>
</optIndice>
</var>
</facteur>
<termeBis>
</termeBis>
</terme>
<expArithBis>
</expArithBis>
</expArith>
<comparaisonBis>
</comparaisonBis>
</comparaison>
</negation>
<conjonctionBis>
</conjonctionBis>
</conjonction>
<expressionBis>
</expressionBis>
</expression>
<symbole>PARENTHESE_FERMANTE</symbole>
<symbole>POINT_VIRGULE</symbole>
</instructionEcriture>
</instruction>
<listeInstructions>
</listeInstructions>
</listeInstructions>
<symbole>ACCOLADE_FERMANTE</symbole>
</instructionBloc>
<optSinon>
<mot_clef>sinon</mot_clef>
<instructionBloc>
<symbole>ACCOLADE_OUVRANTE</symbole>
<listeInstructions>
<instruction>
<instructionEcriture>
<mot_clef>ecrire</mot_clef>
<symbole>PARENTHESE_OUVRANTE</symbole>
<expression>
<conjonction>
<negation>
<comparaison>
<expArith>
<terme>
<facteur>
<var>
<id_variable>$v_2</id_variable>
<optIndice>
</optIndice>
</var>
</facteur>
<termeBis>
</termeBis>
</terme>
<expArithBis>
</expArithBis>
</expArith>
<comparaisonBis>
</comparaisonBis>
</comparaison>
</negation>
<conjonctionBis>
</conjonctionBis>
</conjonction>
<expressionBis>
</expressionBis>
</expression>
<symbole>PARENTHESE_FERMANTE</symbole>
<symbole>POINT_VIRGULE</symbole>
</instructionEcriture>
</instruction>
<listeInstructions>
</listeInstructions>
</listeInstructions>
<symbole>ACCOLADE_FERMANTE</symbole>
</instructionBloc>
</optSinon>
</instructionSi>
</instruction>
<listeInstructions>
</listeInstructions>
</listeInstructions>
</listeInstructions>
</listeInstructions>
<symbole>ACCOLADE_FERMANTE</symbole>
</instructionBloc>
</declarationFonction>
<listeDecFonctions>
</listeDecFonctions>
</listeDecFonctions>
</listeDecFonctions>
</programme>

2146
test/ref-synt/tri.synt Normal file

File diff suppressed because it is too large Load Diff

6
test/ref-tab/affect.tab Normal file
View File

@@ -0,0 +1,6 @@
------------------------------------------
base = 2
sommet = 2
0 $a GLOBALE ENTIER 0 -1
1 main GLOBALE FONCTION 0 0
------------------------------------------

7
test/ref-tab/boucle.tab Normal file
View File

@@ -0,0 +1,7 @@
------------------------------------------
base = 3
sommet = 3
0 $i GLOBALE ENTIER 0 -1
1 $carre GLOBALE ENTIER 4 -1
2 main GLOBALE FONCTION 0 0
------------------------------------------

View File

@@ -0,0 +1,6 @@
------------------------------------------
base = 2
sommet = 2
0 $a GLOBALE ENTIER 0 -1
1 main GLOBALE FONCTION 0 0
------------------------------------------

15
test/ref-tab/max.tab Normal file
View File

@@ -0,0 +1,15 @@
------------------------------------------
base = 1
sommet = 3
0 max GLOBALE FONCTION 0 2
1 $a ARGUMENT ENTIER 0 -1
2 $b ARGUMENT ENTIER 4 -1
------------------------------------------
------------------------------------------
base = 2
sommet = 4
0 max GLOBALE FONCTION 0 2
1 main GLOBALE FONCTION 0 0
2 $v_1 LOCALE ENTIER 0 -1
3 $v_2 LOCALE ENTIER 4 -1
------------------------------------------

49
test/ref-tab/tri.tab Normal file
View File

@@ -0,0 +1,49 @@
------------------------------------------
base = 2
sommet = 2
0 $tab GLOBALE TABLEAU 0 -1
1 initialiser GLOBALE FONCTION 0 0
------------------------------------------
------------------------------------------
base = 3
sommet = 5
0 $tab GLOBALE TABLEAU 0 -1
1 initialiser GLOBALE FONCTION 0 0
2 afficher GLOBALE FONCTION 0 1
3 $n ARGUMENT ENTIER 0 -1
4 $i LOCALE ENTIER 0 -1
------------------------------------------
------------------------------------------
base = 4
sommet = 7
0 $tab GLOBALE TABLEAU 0 -1
1 initialiser GLOBALE FONCTION 0 0
2 afficher GLOBALE FONCTION 0 1
3 echanger GLOBALE FONCTION 0 2
4 $i ARGUMENT ENTIER 0 -1
5 $j ARGUMENT ENTIER 4 -1
6 $temp LOCALE ENTIER 0 -1
------------------------------------------
------------------------------------------
base = 5
sommet = 9
0 $tab GLOBALE TABLEAU 0 -1
1 initialiser GLOBALE FONCTION 0 0
2 afficher GLOBALE FONCTION 0 1
3 echanger GLOBALE FONCTION 0 2
4 trier GLOBALE FONCTION 0 1
5 $n ARGUMENT ENTIER 0 -1
6 $echange LOCALE ENTIER 0 -1
7 $j LOCALE ENTIER 4 -1
8 $m LOCALE ENTIER 8 -1
------------------------------------------
------------------------------------------
base = 6
sommet = 6
0 $tab GLOBALE TABLEAU 0 -1
1 initialiser GLOBALE FONCTION 0 0
2 afficher GLOBALE FONCTION 0 1
3 echanger GLOBALE FONCTION 0 2
4 trier GLOBALE FONCTION 0 1
5 main GLOBALE FONCTION 0 0
------------------------------------------

121
test/testAll.sh Executable file
View File

@@ -0,0 +1,121 @@
#!/bin/bash
################################################################################
# Script d'évaluation automatique des compilateurs du projet.
# Compile le programme source et compare avec la référence.
# Comprend analyse lexicale, syntaxique, arbre abstrait, table des symboles et
# code MIPS.
################################################################################
# MODIFIEZ LES VARIABLES CI-DESSOUS AVEC LE CHEMIN/OPTIONS DE VOTRE COMPILATEUR
MYCOMPILO="../compilateur-l"
MYCOMPILOLEX="${MYCOMPILO} -l"
MYCOMPILOSYNT="${MYCOMPILO} -s"
#MYCOMPILOASYNT="${MYCOMPILO} -a"
#MYCOMPILOTAB="${MYCOMPILO} -t"
#MYCOMPILOMIPS="${MYCOMPILO} -m"
################################################################################
XMLDIFF="./compare_arbres_xml"
REGDIFF="diff -q -w"
EXITONFAIL=1
declare -A testname
testname["lex"]="Analyse lexicale"
testname["synt"]="Analyse syntaxique"
testname["asynt"]="Arbre abstrait"
testname["tab"]="Table des symboles"
testname["mips"]="Code machine MIPS"
################################################################################
function diff_prog() {
diffprog=$1
input=$2
suffix=$3
echo -e "\033[35m > ${testname[${suffix}]} (.${suffix})\033[0m"
if [ -f ref-${suffix}/$input.${suffix} ]; then
${diffprog} output/${input}.${suffix} ref-${suffix}/${input}.${suffix} 2> /dev/null
if [ $? != 0 ]; then
echo -e "\033[31mTEST ${testname[${suffix}]} ÉCHOUÉ\033[0m"
echo -e "Pour connaître les différences, exécutez :"
echo -e " ${diffprog} output/${input}.${suffix} ref-${suffix}/${input}.${suffix}"
if [ $EXITONFAIL = 1 ]; then exit 1; fi
else
echo -e "\033[32mTEST ${testname[${suffix}]} OK\033[0m"
fi
else
echo -e "\033[34mRéférence ref-${suffix}/${input}.${suffix} absente\033[0m"
fi
}
################################################################################
function test_fichier_ok() {
input=$1
echo -e "\n\033[4m ---- Test input/$input.l ----\033[0m"
if [ -f input/$input.l ]; then
echo -e "\033[35m > Reconnaissance (accepte l'entrée)\033[0m"
${MYCOMPILOSYNT} input/$input.l > output/$input.synt
if [ $? != 0 ]; then
echo -e "\033[31mTEST Reconnaissance ÉCHOUÉ\033[0m"
echo -e "Le programme $input.l n'a pas été compilé correctement"
if [ $EXITONFAIL = 1 ]; then exit 1; fi
else
echo -e "\033[32mTEST Reconnaissance OK\033[0m"
fi
${MYCOMPILOLEX} input/$input.l > output/$input.lex
diff_prog "${REGDIFF}" $input lex
diff_prog ${XMLDIFF} $input synt
#${MYCOMPILOASYNT} input/$input.l > output/$input.asynt
#diff_prog ${XMLDIFF} $input asynt
#${MYCOMPILOTAB} input/$input.l > output/$input.tab
#diff_prog "${REGDIFF}" $input tab
#${MYCOMPILOMIPS} input/$input.l > output/$input.mips
#diff_prog "${REGDIFF}" $input mips
else
echo -e "\033[31minput/$input.l non trouvé\033[0m"
echo -e "\033[31mTest impossible\033[0m"
fi
}
################################################################################
function test_fichier_fail() {
input=$1
echo -e "\n\033[4m ---- Test input/$input.l ----\033[0m"
${MYCOMPILO} input/$input.l > output/$input.synt.xml
if [ $? = 0 ]; then
echo -e "\033[31mTEST REJET ÉCHOUÉ\033[0m"
echo -e "Le programme $input.l a été accepté alors qu'il aurait dû être rejeté"
if [ $EXITONFAIL = 1 ]; then exit 1; fi
else
echo -e "\033[32mTEST REJET OK\033[0m"
fi
}
################################################################################
mkdir -p output
make
echo -e "Votre compilateur : ${MYCOMPILO}"
if [ ! -f ${MYCOMPILO} ]; then
echo -e "\033[31mCompilateur introuvable"
echo -e "Modifiez la variable MYCOMPILO avant de lancer l'éval\033[0m"
exit 1
fi
echo -e "\033[1m\n>> 1) Tests connus OK\033[0m"
test_fichier_ok affect
test_fichier_ok boucle
test_fichier_ok expression
test_fichier_ok max
test_fichier_ok tri
echo -e "\033[1m\n>> 1) Tests connus FAIL\033[0m"
test_fichier_fail affect-err