From d168ca8f228348552a9b542b79ac9a22d7f02635 Mon Sep 17 00:00:00 2001 From: sylvain099 Date: Fri, 29 Jan 2016 22:07:40 +0100 Subject: [PATCH 1/2] extension sans fonction a revoir le non --- src/analyseur_syntaxyque.c | 114 ++++++++++++++++++++++++++++++++- src/compilateur-l.c | 2 +- test/expressionNonNoninferieur | 1 + test/expressionOuEt | 1 + 4 files changed, 115 insertions(+), 3 deletions(-) create mode 100644 test/expressionNonNoninferieur create mode 100644 test/expressionOuEt diff --git a/src/analyseur_syntaxyque.c b/src/analyseur_syntaxyque.c index 4ad9189..0e3fd0e 100644 --- a/src/analyseur_syntaxyque.c +++ b/src/analyseur_syntaxyque.c @@ -3,6 +3,104 @@ int uniteCourante; extern char yytext[100]; +void ou(void); +void ouBis(void); +void et(void); +void etBis(void); +void non(void); +void nonBis(void); +void egal(void); +void egalBis(void); +void expArith(void); +void expArithBis(void); +void terme(void); +void termeBis(void); +void facteur(void); + +void ou (void){ + affiche_balise_ouvrante("ou", 1); + + et(); + ouBis(); + + affiche_balise_fermante("ou", 1); +} + +void ouBis(void){ + affiche_balise_ouvrante("ouBis", 1); + + if(uniteCourante == OU){ + uniteCourante = yylex(); + affiche_xml_texte(yytext); + ou(); + } + + affiche_balise_fermante("ouBis", 1); +} + +void et(void){ + affiche_balise_ouvrante("et", 1); + + non(); + etBis(); + + affiche_balise_fermante("et", 1); +} + +void etBis(void){ + affiche_balise_ouvrante("etBis", 1); + + if(uniteCourante == ET){ + uniteCourante = yylex(); + affiche_xml_texte(yytext); + et(); + } + + affiche_balise_fermante("etBis", 1); +} + +void non(void){ + affiche_balise_ouvrante("non", 1); + + egal(); + nonBis(); + + affiche_balise_fermante("non", 1); +} + +void nonBis(void){ + affiche_balise_ouvrante("etBis", 1); + + if(uniteCourante == NON){ + uniteCourante = yylex(); + affiche_xml_texte(yytext); + non(); + } + + affiche_balise_fermante("etBis", 1); +} + +void egal(void){ + affiche_balise_ouvrante("egal", 1); + + expArith(); + egalBis(); + + affiche_balise_fermante("egal", 1); +} + +void egalBis(void){ + affiche_balise_ouvrante("egalBis", 1); + + if(uniteCourante == NON){ + uniteCourante = yylex(); + affiche_xml_texte(yytext); + egal(); + } + + affiche_balise_fermante("egalBis", 1); +} + void expArith (void) { affiche_balise_ouvrante("expArith", 1); @@ -54,7 +152,7 @@ void facteur (void) { uniteCourante = yylex(); affiche_xml_texte(yytext); - expArith(); + ou(); if(uniteCourante != PARENTHESE_FERMANTE) { printf("Erreur de syntaxe"); @@ -69,7 +167,19 @@ void facteur (void) { } else if(uniteCourante == ID_VAR) { uniteCourante = yylex(); affiche_xml_texte(yytext); - } else { + } else if(uniteCourante == CROCHET_OUVRANT){ + uniteCourante = yylex(); + affiche_xml_texte(yytext); + + ou(); + if(uniteCourante != CROCHET_FERMANT) { + printf("Erreur de syntaxe"); + exit(-1); + } + uniteCourante = yylex(); + affiche_xml_texte(yytext); + } + else { printf("Erreur de syntaxe"); exit(-1); } diff --git a/src/compilateur-l.c b/src/compilateur-l.c index 442dadd..db3672c 100644 --- a/src/compilateur-l.c +++ b/src/compilateur-l.c @@ -21,7 +21,7 @@ int main(int argc, char **argv) { uniteCourante = yylex(); affiche_xml_texte(yytext); - expArith(); + ou(); uniteCourante = yylex(); diff --git a/test/expressionNonNoninferieur b/test/expressionNonNoninferieur new file mode 100644 index 0000000..3429cb3 --- /dev/null +++ b/test/expressionNonNoninferieur @@ -0,0 +1 @@ +(!!!var & var) | (10 -4) & 10 < (5/3) \ No newline at end of file diff --git a/test/expressionOuEt b/test/expressionOuEt new file mode 100644 index 0000000..55d3308 --- /dev/null +++ b/test/expressionOuEt @@ -0,0 +1 @@ +(1 + 1) | (2 * 3) & 5 \ No newline at end of file From 1869cca27a2a9e464dc283a4a73fe44ed3bce678 Mon Sep 17 00:00:00 2001 From: sylvain099 Date: Sun, 31 Jan 2016 14:39:09 +0100 Subject: [PATCH 2/2] non rien de rien et les fonctions --- src/analyseur_syntaxyque.c | 60 +++++++++++++++++++++------------- test/expressionNonNoninferieur | 2 +- test/expressionfctargument | 1 + test/expressionfctsimple | 1 + 4 files changed, 41 insertions(+), 23 deletions(-) create mode 100644 test/expressionfctargument create mode 100644 test/expressionfctsimple diff --git a/src/analyseur_syntaxyque.c b/src/analyseur_syntaxyque.c index 0e3fd0e..96b7c87 100644 --- a/src/analyseur_syntaxyque.c +++ b/src/analyseur_syntaxyque.c @@ -3,20 +3,6 @@ int uniteCourante; extern char yytext[100]; -void ou(void); -void ouBis(void); -void et(void); -void etBis(void); -void non(void); -void nonBis(void); -void egal(void); -void egalBis(void); -void expArith(void); -void expArithBis(void); -void terme(void); -void termeBis(void); -void facteur(void); - void ou (void){ affiche_balise_ouvrante("ou", 1); @@ -61,23 +47,21 @@ void etBis(void){ void non(void){ affiche_balise_ouvrante("non", 1); - - egal(); nonBis(); + egal(); affiche_balise_fermante("non", 1); } void nonBis(void){ - affiche_balise_ouvrante("etBis", 1); - + affiche_balise_ouvrante("nonBis", 1); if(uniteCourante == NON){ uniteCourante = yylex(); affiche_xml_texte(yytext); - non(); + nonBis(); } - affiche_balise_fermante("etBis", 1); + affiche_balise_fermante("nonBis", 1); } void egal(void){ @@ -92,7 +76,7 @@ void egal(void){ void egalBis(void){ affiche_balise_ouvrante("egalBis", 1); - if(uniteCourante == NON){ + if(uniteCourante == EGAL || uniteCourante == INFERIEUR){ uniteCourante = yylex(); affiche_xml_texte(yytext); egal(); @@ -178,7 +162,39 @@ void facteur (void) { } uniteCourante = yylex(); affiche_xml_texte(yytext); - } + + } + else if(uniteCourante == ID_FCT){ + uniteCourante = yylex(); + affiche_xml_texte(yytext); + if(uniteCourante != PARENTHESE_OUVRANTE){ + printf("Erreur de syntaxe"); + exit(-1); + } + uniteCourante = yylex(); + affiche_xml_texte(yytext); + if(uniteCourante != PARENTHESE_FERMANTE){ + ou(); + while(uniteCourante == VIRGULE){ + uniteCourante = yylex(); + affiche_xml_texte(yytext); + ou(); + + } + } + if(uniteCourante != PARENTHESE_FERMANTE){ + printf("Erreur de syntaxe"); + exit(-1); + } + uniteCourante = yylex(); + affiche_xml_texte(yytext); + if(uniteCourante != POINT_VIRGULE){ + printf("Erreur de syntaxe"); + exit(-1); + } + uniteCourante = yylex(); + affiche_xml_texte(yytext); + } else { printf("Erreur de syntaxe"); exit(-1); diff --git a/test/expressionNonNoninferieur b/test/expressionNonNoninferieur index 3429cb3..9635fc7 100644 --- a/test/expressionNonNoninferieur +++ b/test/expressionNonNoninferieur @@ -1 +1 @@ -(!!!var & var) | (10 -4) & 10 < (5/3) \ No newline at end of file +(!!!$var & $var) | (10 -4) & 10 < (5/3) \ No newline at end of file diff --git a/test/expressionfctargument b/test/expressionfctargument new file mode 100644 index 0000000..4f13932 --- /dev/null +++ b/test/expressionfctargument @@ -0,0 +1 @@ +expression(1,10); \ No newline at end of file diff --git a/test/expressionfctsimple b/test/expressionfctsimple new file mode 100644 index 0000000..03fed7a --- /dev/null +++ b/test/expressionfctsimple @@ -0,0 +1 @@ +test(); \ No newline at end of file