TP1 TP2 DONE
已完成TP1和TP2
This commit is contained in:
parent
d34936b229
commit
5dadd23503
15
TP1/analyse_lexicale.c
Normal file
15
TP1/analyse_lexicale.c
Normal file
@ -0,0 +1,15 @@
|
|||||||
|
#include "analyse_lexicale.h"
|
||||||
|
#include "automate.h"
|
||||||
|
#include <stdio.h>
|
||||||
|
|
||||||
|
int main() {
|
||||||
|
FILE *pFile;
|
||||||
|
|
||||||
|
pFile = fopen("fichier.html", "rt"); // ouvre le fichier html
|
||||||
|
if(pFile != NULL){
|
||||||
|
getNextChar(pFile);
|
||||||
|
fclose (pFile);
|
||||||
|
}
|
||||||
|
else printf("Erreur d'ouverture du fichier\n");
|
||||||
|
return 0;
|
||||||
|
}
|
8
TP1/analyse_lexicale.h
Normal file
8
TP1/analyse_lexicale.h
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
#ifndef TP1_ANALYSE_LEXICALE_H
|
||||||
|
#define TP1_ANALYSE_LEXICALE_H
|
||||||
|
|
||||||
|
#endif //TP1_ANALYSE_LEXICALE_H
|
||||||
|
|
||||||
|
char* lectureFile();
|
||||||
|
|
||||||
|
|
BIN
TP1/analyse_lexicale.h.gch
Normal file
BIN
TP1/analyse_lexicale.h.gch
Normal file
Binary file not shown.
61
TP1/automate.c
Normal file
61
TP1/automate.c
Normal file
@ -0,0 +1,61 @@
|
|||||||
|
#include "automate.h"
|
||||||
|
|
||||||
|
enum Etats curEtat = EtatDeb; // initialisation de curEtat
|
||||||
|
char string[20] = ""; // initialisation de string contenant la balise
|
||||||
|
int pos = 0; // initialisation de pos
|
||||||
|
bool tagFermant = false; // initialisation de tagFermant
|
||||||
|
struct Pile *pile=NULL; // initialisation de la pile
|
||||||
|
int error = 0; // initialisation de error
|
||||||
|
|
||||||
|
void changeEtat(char c ){
|
||||||
|
if(pile==NULL){
|
||||||
|
pile = pileInit();
|
||||||
|
} // Création de la pile si elle est NULL
|
||||||
|
switch (curEtat) {
|
||||||
|
case EtatDeb :
|
||||||
|
if (c=='<'){
|
||||||
|
curEtat = EtatBalise;
|
||||||
|
} // si une balise ouvrante est détectée, on passe à l'état suivant
|
||||||
|
break;
|
||||||
|
case EtatBalise :
|
||||||
|
if (c=='/'){
|
||||||
|
tagFermant = true;
|
||||||
|
} // si un / est détecté, on passe le tagFermant à true : signifie qu'on a trouvé le tag fermant du tag dans lequel on se trouve
|
||||||
|
else {
|
||||||
|
if (c == ' ' || c == '>') {
|
||||||
|
if (tagFermant) {
|
||||||
|
char *stringFerm = pilePop(pile); // si on ne détecte pas de / mais un espace ou une balise fermante, et si le tagFermant est à true, on définit un nouveau char stringFerm qui prend la dernière valeur mise dans la pile
|
||||||
|
if (strcmp(stringFerm, string) != 0) {
|
||||||
|
printf("Erreur mauvaise parenthèse fermante à : %s\n", stringFerm);
|
||||||
|
error++;
|
||||||
|
} // si stringFerm et string ne sont pas les mêmes, on détecte une erreur car on ne retrouve pas la bonne parenthèse fermante
|
||||||
|
tagFermant = false;
|
||||||
|
} else {
|
||||||
|
pilePush(pile, string);
|
||||||
|
} // sinon, on stocke string dans la pile
|
||||||
|
memset(string, 0, 20); //vider le tableau
|
||||||
|
pos = 0; // remettre à jour pos
|
||||||
|
curEtat = EtatDeb; // se remettre à l'état initial
|
||||||
|
} else {
|
||||||
|
string[pos] = c;
|
||||||
|
pos++;
|
||||||
|
} // si on a autre chose qu'un espace ou une balise fermante, on ajoute le char dans string à la position pos et on incrémente pos
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void getNextChar(FILE *file){
|
||||||
|
char c;
|
||||||
|
for(c=fgetc(file);!feof(file);c=fgetc(file)){
|
||||||
|
changeEtat(c);
|
||||||
|
} // tant que le fichier n'est pas vide, on attribue à c un caractère du fichier
|
||||||
|
// puis on applique la fonction changeEtat à c
|
||||||
|
printf("Nombre d'erreur dans le fichier : %d\n",error);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
19
TP1/automate.h
Normal file
19
TP1/automate.h
Normal file
@ -0,0 +1,19 @@
|
|||||||
|
#ifndef TP1_AUTOMATE_H
|
||||||
|
#define TP1_AUTOMATE_H
|
||||||
|
|
||||||
|
#endif //TP1_AUTOMATE_H
|
||||||
|
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <string.h>
|
||||||
|
#include <stdbool.h>
|
||||||
|
#include "pile.h"
|
||||||
|
|
||||||
|
enum Etats {
|
||||||
|
EtatDeb,
|
||||||
|
EtatBalise
|
||||||
|
}; // énumération des différents états possibles d'avoir dans la fonction changeEtat
|
||||||
|
|
||||||
|
void changeEtat( char c );
|
||||||
|
void getNextChar(FILE *file);
|
||||||
|
|
||||||
|
|
BIN
TP1/automate.h.gch
Normal file
BIN
TP1/automate.h.gch
Normal file
Binary file not shown.
65
TP1/fichier.html
Normal file
65
TP1/fichier.html
Normal file
@ -0,0 +1,65 @@
|
|||||||
|
<html xmlns="http://www.w3.org/1999/xhtml">
|
||||||
|
<head>
|
||||||
|
<link rel="icon" type="image/gif" href="images/mono_polytech.gif"></link>
|
||||||
|
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"><meta>
|
||||||
|
<meta name="description" content="Polytech'Nantes, Ecole polytechnique de l'Université de Nantes est une grande école d'ingénieurs membre du réseau Polytech"></meta>
|
||||||
|
<meta name="keywords" content="Polytech'Nantes, ecole, ingenieur, polytechnique, ecole polytechnique, genie civil,
|
||||||
|
|
||||||
|
genie electrique, sciences des materiaux, electronique, telecoms, informatique industrielle, informatique,
|
||||||
|
|
||||||
|
logiciels, reseaux, thermique, energetique, ecole d'ingenieurs, universite de Nantes, enseignement superieur, Ireste, Isitem, polytech, reseau polytech" ></meta>
|
||||||
|
<title>Polytech'Nantes, école d'ingénieurs de l'université de Nantes</title>
|
||||||
|
</head>
|
||||||
|
|
||||||
|
<body id="fond">
|
||||||
|
<div class="fond">
|
||||||
|
<img src="images/image_fond.gif" width="1024" height="850"></img>
|
||||||
|
</div>
|
||||||
|
<div class="liens"><a href="http://www.portail.polytech.univ-nantes.fr">Accès intranet</a> <a href="mailto:communication@polytech.univ-nantes.fr">Contact</a> <a href="http://web.polytech.univ-nantes.fr/76349314/1/fiche___pagelibre/&RH=POLYTECH_FR1&RF=POLYTECH_EN1"> </a> <a href="http://web.polytech.univ-nantes.fr/18780232/0/fiche___pagelibre/&RH=POLYTECH_FR1"> </a></div>
|
||||||
|
<div class="acces"><a href="http://web.polytech.univ-nantes.fr/35464617/0/fiche___pagelibre/&RH=1184336171300&RF=1184159169204"><img src="images/bouton_acces.gif" alt="Accédez au site" width="175" height="25" border="0"></img></a></div>
|
||||||
|
<div class="profil" id="lyceen"><a href="http://web.polytech.univ-nantes.fr/80014545/0/fiche___pagelibre/&RH=1183023276707">Lycéen</a></div>
|
||||||
|
<div class="profil" id="etudiant"><a href="http://web.polytech.univ-nantes.fr/80383387/0/fiche___pagelibre/&RH=1183023276707">Etudiant</a></div>
|
||||||
|
<div class="profil" id="salarie"><a href="http://web.polytech.univ-nantes.fr/91733591/0/fiche___pagelibre/&RH=1183023276707">Salarié</a></div>
|
||||||
|
<div class="profil" id="chercheur"><a href="http://web.polytech.univ-nantes.fr/92816685/0/fiche___pagelibre/&RH=1183023276707">Chercheur</a></div>
|
||||||
|
<div class="profil" id="entreprise"><a href="http://web.polytech.univ-nantes.fr/92982625/0/fiche___pagelibre/&RH=POLYTECH_FR1">Entreprise</a></div>
|
||||||
|
<div class="profil" id="journaliste"><a href="http://web.polytech.univ-nantes.fr/94315427/0/fiche___pagelibre/&RH=1184159169204">Journaliste</a></div>
|
||||||
|
<div class="tampon">
|
||||||
|
<table border="0" cellspacing="2px">
|
||||||
|
<tr>
|
||||||
|
<td width="193">
|
||||||
|
<p class="Style2">
|
||||||
|
<a href="#" onclick="window.open('http://www.polytech-reseau.org/demain/', 'demain', 'top=50,left=100,width=880,height=570,scrollbars=no,status=no,resizable=no,menubar=no,toolbar=no,location=no,directories=no');" ><span class="Style6">Rentrée 2009 : nouvelle identité Polytech</span><img border="0" src="images/gif-anime-lien-minisite-web.gif" width="183" height="61"></img></a>
|
||||||
|
</p>
|
||||||
|
</td>
|
||||||
|
<td> </td>
|
||||||
|
<td width="150" class="Style7">
|
||||||
|
<p align="center">
|
||||||
|
<a href="http://web.polytech.univ-nantes.fr/1253527039381/0/fiche___actualite/&RH=1191503131326">En 2010 :<br></br>Polytech'Nantes fête ses 10 ans</a>
|
||||||
|
</p>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
</table>
|
||||||
|
</div>
|
||||||
|
<div class="actu">
|
||||||
|
<a href="http://web.polytech.univ-nantes.fr/35464617/0/fiche___pagelibre/&RH=1183022332415&RF=1184159169204"></a><a href="http://web.polytech.univ-nantes.fr/97346305/0/fiche___pagelibre/&RH=1184159169204"><img src="images/actualites.gif" alt="Actualités" width="177" height="59" border="0"></img></a>
|
||||||
|
</div>
|
||||||
|
<div class="profil" id="diplome"><a href="http://web.polytech.univ-nantes.fr/15386742/0/fiche___pagelibre/&RH=POLYTECH_FR1">Diplômé</a></div>
|
||||||
|
<div class="plan"><a href="http://web.polytech.univ-nantes.fr/08930057/0/fiche___pagelibre/&RH=POLYTECH_FR1" class="Style1">Plan d'accès</a></div>
|
||||||
|
|
||||||
|
<div class="logos"><a href="http://www.polytech-reseau.org"><img src="images/POLYTECH_RVB.jpg" width="97" height="61" border="0"></img></a><a href="http://www.univ-nantes.fr"> <img src="images/logo_universitenantes.jpg" width="98" height="52" border="0"></img></a></div>
|
||||||
|
|
||||||
|
<div class="partenaires">
|
||||||
|
<table border="0">
|
||||||
|
<tr>
|
||||||
|
<td valign="middle"><a href="http://www.cti-commission.fr/"><img src="images/Log-CTI-quadri.jpg" width="61" height="40" border="0"></img></a></td>
|
||||||
|
<td><a href="http://www.archimede-groupe.org/"><img src="images/archimede.gif" width="164" height="26" border="0"></img></a> </td>
|
||||||
|
<td><a href="http://www.geipi-polytech.org"><img src="images/logo-Geipi-Polytech.jpg" width="101" height="41" border="0"></img></a> </td>
|
||||||
|
<td><a href="http://www.cdefi.fr/"></a> <a href="http://www.cdefi.fr/"><img src="images/membrecdefitailleweb.gif" alt="CDEFI" width="100" height="40" border="0"></img></a></td>
|
||||||
|
<td><a href="http://www.cge.asso.fr/"><img src="images/logo_cge.jpg" width="104" height="41" border="0"></img></a> </td>
|
||||||
|
<td><a href="http://www.cefi.org/CEFINET/ENVIRON/EUROPE/Eurace.htm"><img src="images/eurace.jpg" width="59" height="39" border="0"></img></a> </td>
|
||||||
|
<td><a href="http://www.nplusi.com/"><img src="images/logo_nplusi.gif" width="94" height="47" border="0"></img></a> </td>
|
||||||
|
</tr>
|
||||||
|
</table>
|
||||||
|
</div>
|
||||||
|
</body>
|
||||||
|
</html>
|
35
TP1/pile.c
Normal file
35
TP1/pile.c
Normal file
@ -0,0 +1,35 @@
|
|||||||
|
#include "pile.h"
|
||||||
|
|
||||||
|
struct Pile* pileInit(){
|
||||||
|
struct Pile *pile = malloc(sizeof(*pile));
|
||||||
|
pile->pos = -1;
|
||||||
|
return pile;
|
||||||
|
} // Initialisation de la pile
|
||||||
|
|
||||||
|
|
||||||
|
char* pilePop(struct Pile *pile){
|
||||||
|
if(pile->pos == -1){
|
||||||
|
printf("pilePop : ERROR PILE VIDE");
|
||||||
|
return NULL;
|
||||||
|
} // si pos = -1, cela signifie que la pile est vide, donc on ne peut pas retirer d'éléments de la pile
|
||||||
|
pile->pos--; // on décrémente pos car on va retirer le dernier élément, donc la taille de la pile va diminuer
|
||||||
|
return pile->stack[pile->pos+1]; // on retire le dernier élément
|
||||||
|
}
|
||||||
|
|
||||||
|
void pilePush(struct Pile *pile, char *string){
|
||||||
|
if(pile->pos == TAILLE_PILLE){
|
||||||
|
printf("pilePush : ERROR PILE PLEINE");
|
||||||
|
} // si la taille de la pile est égale à la valeur dans pos, la pile est pleine, on ne peut donc pas ajouter d'éléments dedans
|
||||||
|
else {
|
||||||
|
pile->pos++;
|
||||||
|
strcpy(pile->stack[pile->pos], string);
|
||||||
|
} // sinon, on incrémente pos et on ajoute l'élément demandé grâce à la fonction strcpy
|
||||||
|
}
|
||||||
|
|
||||||
|
char* pileTop(struct Pile *pile){
|
||||||
|
return pile->stack[pile->pos];
|
||||||
|
} // renvoie la dernière valeur de la pile
|
||||||
|
|
||||||
|
int pileSize(struct Pile *pile){
|
||||||
|
return pile->pos;
|
||||||
|
} // retourne la taille actuelle de la pile
|
23
TP1/pile.h
Normal file
23
TP1/pile.h
Normal file
@ -0,0 +1,23 @@
|
|||||||
|
#ifndef TP1_PILE_H
|
||||||
|
#define TP1_PILE_H
|
||||||
|
|
||||||
|
#endif //TP1_PILE_H
|
||||||
|
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <string.h>
|
||||||
|
|
||||||
|
#define TAILLE_PILLE 1024
|
||||||
|
#define TAILLE_CHAINE 1024
|
||||||
|
|
||||||
|
|
||||||
|
struct Pile{
|
||||||
|
char stack[TAILLE_PILLE][TAILLE_CHAINE];
|
||||||
|
int pos;
|
||||||
|
};
|
||||||
|
|
||||||
|
struct Pile* pileInit();
|
||||||
|
char* pilePop(struct Pile *pile);
|
||||||
|
void pilePush(struct Pile *pile, char *string);
|
||||||
|
char* pileTop(struct Pile *pile);
|
||||||
|
int pileSize(struct Pile *pile);
|
BIN
TP1/pile.h.gch
Normal file
BIN
TP1/pile.h.gch
Normal file
Binary file not shown.
BIN
TP2/.DS_Store
vendored
Normal file
BIN
TP2/.DS_Store
vendored
Normal file
Binary file not shown.
BIN
TP2/tableau/main
Executable file
BIN
TP2/tableau/main
Executable file
Binary file not shown.
111
TP2/tableau/main.c
Normal file
111
TP2/tableau/main.c
Normal file
@ -0,0 +1,111 @@
|
|||||||
|
#include <stdio.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <stdbool.h>
|
||||||
|
|
||||||
|
int *InitTab(unsigned int nbVal, int min, int max);
|
||||||
|
bool Verif(int *t, unsigned int nbVal);
|
||||||
|
void MonTri(int *t, unsigned int nbVal);
|
||||||
|
void quickSort(int *t, int left, int right);
|
||||||
|
|
||||||
|
// if true print "true"
|
||||||
|
// if false print "false"
|
||||||
|
void printBool(bool b)
|
||||||
|
{
|
||||||
|
if (b)
|
||||||
|
{
|
||||||
|
printf("\ntrue\n");
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
printf("\nfalse\n");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
int main()
|
||||||
|
{
|
||||||
|
int *t = InitTab(10, 0, 100);
|
||||||
|
printBool(Verif(t, 10));
|
||||||
|
// MonTri(t, 10);
|
||||||
|
quickSort(t, 0, 9);
|
||||||
|
printBool(Verif(t, 10));
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
int *InitTab(unsigned int nbVal, int min, int max)
|
||||||
|
{
|
||||||
|
int *t = (int *)malloc(nbVal * sizeof(int));
|
||||||
|
for (int i = 0; i < nbVal; i++)
|
||||||
|
{
|
||||||
|
t[i] = rand() % (max - min + 1) + min;
|
||||||
|
}
|
||||||
|
return t;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool Verif(int *t, unsigned int nbVal)
|
||||||
|
{
|
||||||
|
bool flg = true;
|
||||||
|
if (nbVal >= 2)
|
||||||
|
{
|
||||||
|
for (int i = 0; i < nbVal - 1 && flg; i++)
|
||||||
|
{
|
||||||
|
if (t[i] > t[i + 1])
|
||||||
|
{
|
||||||
|
flg = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
for (int i = 0; i < nbVal; i++)
|
||||||
|
{
|
||||||
|
printf("%d ", t[i]);
|
||||||
|
}
|
||||||
|
return flg;
|
||||||
|
}
|
||||||
|
|
||||||
|
void MonTri(int *t, unsigned int nbVal)
|
||||||
|
{
|
||||||
|
int i, j, tmp;
|
||||||
|
for (i = 0; i < nbVal; i++)
|
||||||
|
{
|
||||||
|
for (j = i + 1; j < nbVal; j++)
|
||||||
|
{
|
||||||
|
if (t[i] > t[j])
|
||||||
|
{
|
||||||
|
tmp = t[i];
|
||||||
|
t[i] = t[j];
|
||||||
|
t[j] = tmp;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// quick sort
|
||||||
|
void quickSort(int *t, int left, int right)
|
||||||
|
{
|
||||||
|
int i = left, j = right;
|
||||||
|
int tmp;
|
||||||
|
int pivot = t[(left + right) / 2];
|
||||||
|
|
||||||
|
/* partition */
|
||||||
|
while (i <= j)
|
||||||
|
{
|
||||||
|
while (t[i] < pivot)
|
||||||
|
i++;
|
||||||
|
while (t[j] > pivot)
|
||||||
|
j--;
|
||||||
|
if (i <= j)
|
||||||
|
{
|
||||||
|
tmp = t[i];
|
||||||
|
t[i] = t[j];
|
||||||
|
t[j] = tmp;
|
||||||
|
i++;
|
||||||
|
j--;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
/* recursion */
|
||||||
|
if (left < j)
|
||||||
|
quickSort(t, left, j);
|
||||||
|
if (i < right)
|
||||||
|
quickSort(t, i, right);
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user