Skip to content

Commit

Permalink
Merge branch 'master' of github.com:H4311/Projet-Grammaire-Langages
Browse files Browse the repository at this point in the history
  • Loading branch information
DanielBaudry committed Apr 25, 2012
2 parents 72db2d3 + dd9a6c9 commit d28f927
Show file tree
Hide file tree
Showing 53 changed files with 814 additions and 144 deletions.
8 changes: 0 additions & 8 deletions AnalyseurDTD/makefile

This file was deleted.

2 changes: 1 addition & 1 deletion Main.cpp
Expand Up @@ -5,7 +5,7 @@
#include <fstream>

#include "xml/xml_processor.h"
#include "AnalyseurDTD/dtd.h"
#include "dtd/dtd.h"

using namespace std;
namespace po = boost::program_options;
Expand Down
8 changes: 8 additions & 0 deletions calc/calc.lex
Expand Up @@ -25,3 +25,11 @@ ident [a-zA-Z]+
. { cout << "Caractère inattendu : " << yytext << endl; }

%%

extern void yyparse(double*);

void parse(double* d)
{
yyparse(d);
yylex_destroy();
}
9 changes: 6 additions & 3 deletions calc/calc.y
Expand Up @@ -42,23 +42,26 @@ expr : DOUBLE { $$ = $1; }
| expr FOIS expr { $$ = $1 * $3; }
| expr SLASH expr { $$ = $1 / $3; }
| PAR_OUV expr PAR_FER { $$ = $2; }
| VAR { $$ = variables[$1]; }
| VAR EGAL expr { $$ = (variables[string($1)] = $3); }
| VAR { $$ = variables[$1]; free($1);}
| VAR EGAL expr { $$ = (variables[string($1)] = $3); free($1);}
;

%%
# include <iostream>
# include <map>
using namespace std;

extern void parse(double*);

int main(void) {
double * d = new double;

cout << "Entrez des expressions littérales simples (a=3, 4+7*8,...) "
<< "puis appuyez sur Ctrl+D pour évaluer. Pour arrêter, entrez 0"
<< "(ou arrangez vous pour que le résultat fasse 0 ^^.";
do {
yyparse(d);
// yyparse(d);
parse(d);
cout << "Valeur calculée : " << *d << endl;
} while (*d != 0);
delete d;
Expand Down
File renamed without changes.
4 changes: 4 additions & 0 deletions dtd/Element.cpp
Expand Up @@ -22,4 +22,8 @@ namespace dtd {
return content->getRegex();
}

std::string Element::getName() {
return name;
}

}
1 change: 1 addition & 0 deletions dtd/Element.hpp
Expand Up @@ -15,6 +15,7 @@ namespace dtd {
virtual ~Element();
virtual std::ostream& put(std::ostream& out);
virtual std::string getRegex();
std::string getName();

protected:
std::string name;
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
14 changes: 10 additions & 4 deletions dtd/makefile
@@ -1,22 +1,28 @@
CXX = g++
LD = g++
EXE = dtd
OBJ = Document.o Declaration.o Attribute.o Element.o ContentSpec.o Children.o ChoiceSeq.o Choice.o Seq.o Name.o
OBJ = Document.o Declaration.o Attribute.o Element.o ContentSpec.o Children.o ChoiceSeq.o Choice.o Seq.o Name.o TestPut.o
CXXFLAGS = -g
LDFLAGS =

all: dtd
all: dtd analyseDTD

analyseDTD: *.l *.y makefile
flex -P dtd dtd.l
bison -p dtd --debug --verbose --defines=dtd.tab.h dtd.y
g++ -g -DYYDEBUG=1 -c lex.dtd.c dtd.tab.c

dtd: $(OBJ)
# $(LD) -o $(EXE) $^ $(LDFLAGS)
$(LD) -o $(EXE) $^ $(LDFLAGS)
rm TestPut.o

%.o: %.cpp %.hpp
$(CXX) -o $@ -c $< $(CXXFLAGS)

.PHONY: clean

clean:
rm -f *.o
-rm -rf *.tab.c lex.*.c *.tab.h *.output *.o

mrproper: clean
rm -f $(EXE)
File renamed without changes.
8 changes: 4 additions & 4 deletions makefile
Expand Up @@ -4,10 +4,10 @@ EXEC_NAME = main
INCLUDES =
LIBS = -lboost_program_options
OBJ_FILES = Main.o
OBJ_FILES_DEP = xml/*.o AnalyseurDTD/*.o xsl/*.o
OBJ_FILES_DEP = xml/*.o dtd/*.o # xsl/*.o

XML_REP = xml/
DTD_REP = AnalyseurDTD/
DTD_REP = dtd/
XSL_REP = xsl/

all: $(EXEC_NAME)
Expand All @@ -17,15 +17,15 @@ all: $(EXEC_NAME)
clean:
make clean -C $(XML_REP)
make clean -C $(DTD_REP)
make clean -C $(XSL_REP)
# make clean -C $(XSL_REP)
rm $(EXEC_NAME) $(OBJ_FILES)

rebuild: clean all

$(EXEC_NAME): $(OBJ_FILES)
make -C $(XML_REP)
make -C $(DTD_REP)
make -C $(XSL_REP)
# make -C $(XSL_REP)
$(CXX) -o $(EXEC_NAME) $(OBJ_FILES) $(OBJ_FILES_DEP) $(LIBS)

%.o: %.cpp
Expand Down
29 changes: 0 additions & 29 deletions makefile~

This file was deleted.

11 changes: 11 additions & 0 deletions tests/jlgp/Test.h
@@ -0,0 +1,11 @@
#include<cstdio>
#include "Content.cpp"
#include "Data.cpp"
#include "EmptyElement.cpp"
#include "Comment.cpp"
#include "Element.cpp"

#define name(namespace,nom) make_pair(namespace,nom)
#define new_Element(str) new xml::Element(name("",str))
#define new_EmptyElement(str) new xml::EmptyElement(name("",str))
#define Att(AttName,AttVal) make_pair(AttName,AttVal)
12 changes: 12 additions & 0 deletions tests/jlgp/main.cpp
@@ -0,0 +1,12 @@
#include "mainTest1.cpp"
#include "mainTest2.cpp"
#include "mainTest3.cpp"
#include "mainTest4.cpp"

int main(){
mainTest1();
mainTest2();
mainTest3();
mainTest4();
return 0;
}
87 changes: 87 additions & 0 deletions tests/jlgp/mainTest1.cpp
@@ -0,0 +1,87 @@
#include "Test.h"

string getStrP1();
string getStrP2();

int mainTest1(){
freopen("test1.xml","w",stdout);
xml::Element* rapport = new_Element("rapport");

//Elements de rapport
xml::Element* titreRapport = new_Element("titre");
xml::Element* auteur = new_Element("auteur");
xml::Element* resume = new_Element("resume");
xml::Element* chapitre = new_Element("chapitre");

//Elements de titre
xml::Data* titreD = new xml::Data("Réaliser un compilateur");
titreRapport->getChildren().push_back(titreD);

//Elements auteur
xml::Element* prenom = new_Element("prenom");
xml::Data* prenomD = new xml::Data("Nino");
prenom->getChildren().push_back(prenomD);

xml::Element* nom = new_Element("nom");
xml::Data* nomD = new xml::Data("Silverio");
nom->getChildren().push_back(nomD);

auteur->getChildren().push_back(prenom);
auteur->getChildren().push_back(nom);

//Elements resume
xml::Data* resumeD = new xml::Data("Ceci est un extrait du livre \"Réaliser un compilateur: \nles outils Lex et Yacc\" de Nino Silverio");
resume->getChildren().push_back(resumeD);

//Elements chapitre
xml::Element* titreChapitre = new_Element("titre");
xml::Data* titreChapitreD = new xml::Data("Introduction : concepts de base");
xml::Element* section1 = new_Element("section");
xml::Element* section2 = new_Element("section");
xml::Element* titreSection1 = new_Element("titre");
xml::Data* titreSection1D = new xml::Data("Fonctions et structure d'un compilateur");
xml::Element* titreSection2 = new_Element("titre");
xml::Data* titreSection2D = new xml::Data("Réalisation d'un compilateur");
xml::Element* pSection1 = new_Element("p");
xml::Element* pSection2 = new_Element("p");
xml::Data* pSection1D = new xml::Data(getStrP1());
xml::Data* pSection2D = new xml::Data(getStrP2());

pSection1->getChildren().push_back(pSection1D);
titreSection1->getChildren().push_back(titreSection1D);
section1->getChildren().push_back(titreSection1);
section1->getChildren().push_back(pSection1);

pSection2->getChildren().push_back(pSection2D);
section2->getChildren().push_back(titreSection2);
titreSection2->getChildren().push_back(titreSection2D);
section2->getChildren().push_back(pSection2);

titreChapitre->getChildren().push_back(titreChapitreD);
chapitre->getChildren().push_back(titreChapitre);
chapitre->getChildren().push_back(section1);
chapitre->getChildren().push_back(section2);

//getChildren().push_back Rapport
rapport->getChildren().push_back(titreRapport);
rapport->getChildren().push_back(auteur);
rapport->getChildren().push_back(resume);
rapport->getChildren().push_back(chapitre);

//Document document(doctype);
//document.getChildren().push_back(rapport);
cout<<rapport;
fclose (stdout);

delete rapport;
return 0;
}

string getStrP1(){
return "Tout programme rédigé dans un langage de programmation de haut niveau tel que Pascal ou C ne peut être exécuté par un ordinateur que s'il est traduit en instructions exécutables par l'ordinateur, généralement des instruction en langage machine. L'ordinateur qui doit exécuter le programme ainsi traduit est appelé machine cible.";
}

string getStrP2(){
return "Comme l'écriture d'un compilateur est une tâche fort complexe, le programmateur a tout intérêt à travailler en utilisant un langage de programmation de haut niveau.";
}

79 changes: 79 additions & 0 deletions tests/jlgp/mainTest2.cpp
@@ -0,0 +1,79 @@
//#include "Test.h"

string getStrP1();
string getStrP2();

int mainTest2(){
freopen("test2.xml","w",stdout);
//Doctype doctype("rapport","rap1.dtd");
xml::Element* rapport = new_Element("rapport");

//Elements de rapport
xml::Element* titreRapport = new_Element("titre");
xml::Element* auteur = new_Element("auteur");
xml::Element* resume = new_Element("resume");
xml::Element* chapitre = new_Element("chapitre");

//Elements de titre
xml::Data* titreD = new xml::Data("Réaliser un compilateur");
titreRapport->getChildren().push_back(titreD);

//Elements auteur
xml::Element* prenom = new_Element("prenom");
xml::Data* prenomD = new xml::Data("Nino");
prenom->getChildren().push_back(prenomD);

xml::Element* nom = new_Element("nom");
xml::Data* nomD = new xml::Data("Silverio");
nom->getChildren().push_back(nomD);

auteur->getChildren().push_back(prenom);
auteur->getChildren().push_back(nom);

//Elements resume
xml::Data* resumeD = new xml::Data("Ceci est un extrait du livre \"Réaliser un compilateur: \nles outils Lex et Yacc\" de Nino Silverio");
resume->getChildren().push_back(resumeD);

//Elements chapitre
xml::Element* section1 = new_Element("section");
xml::Element* section2 = new_Element("section");
xml::Element* pSection1 = new_Element("p");
xml::Element* pSection2 = new_Element("p");
xml::Data* pSection1D = new xml::Data(getStrP1());
xml::Data* pSection2D = new xml::Data(getStrP2());

pSection1->getChildren().push_back(pSection1D);
//section1->AddAttribute(Att("titre","Fonctions et structure d'un compilateur"));
AttList attPSection1;
attPSection1.push_back(Att("titre","Fonctions et structure d'un compilateur"));
section1->SetAttList(&attPSection1);
section1->getChildren().push_back(pSection1);

pSection2->getChildren().push_back(pSection2D);
//section2->AddAttribute(Att("titre","Réalisation d'un compilateur"));
AttList attPSection2;
attPSection2.push_back(Att("titre","Réalisation d'un compilateur"));
section2->SetAttList(&attPSection2);
section2->getChildren().push_back(pSection2);

//chapitre->AddAttribute(Att("titre","Introduction: concepts de base"));
AttList attChapitre;
attChapitre.push_back(Att("titre","Introduction: concepts de base"));
chapitre->SetAttList(&attChapitre);
chapitre->getChildren().push_back(section1);
chapitre->getChildren().push_back(section2);

//getChildren().push_back Rapport
rapport->getChildren().push_back(titreRapport);
rapport->getChildren().push_back(auteur);
rapport->getChildren().push_back(resume);
rapport->getChildren().push_back(chapitre);

//xml::Document document(doctype);
//xml::document.getChildren().push_back(rapport);
cout<<rapport;
fclose (stdout);

delete rapport;
return 0;
}

0 comments on commit d28f927

Please sign in to comment.