Ajout de l'analyse syntaxique des expresion :
- ()
- +
- *
This commit is contained in:
20
header/analyseur_syntaxyque.h
Normal file
20
header/analyseur_syntaxyque.h
Normal file
@@ -0,0 +1,20 @@
|
||||
#ifndef __ANALYSEUR_SYNTAXYQUE__
|
||||
#define __ANALYSEUR_SYNTAXYQUE__
|
||||
|
||||
#include <ctype.h>
|
||||
#include <string.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include "symboles.h"
|
||||
#include "util.h"
|
||||
#include "stdio.h"
|
||||
#include "analyseur_lexical.h"
|
||||
|
||||
void expArith (void);
|
||||
void expArithBis (void);
|
||||
void terme (void);
|
||||
void termeBis (void);
|
||||
void facteur (void);
|
||||
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,74 @@
|
||||
#include "analyseur_syntaxyque.h"
|
||||
|
||||
int uniteCourante;
|
||||
extern char yytext[100];
|
||||
|
||||
|
||||
|
||||
void expArith (void) {
|
||||
affiche_balise_ouvrante("expArith", 1);
|
||||
|
||||
terme();
|
||||
expArithBis();
|
||||
|
||||
affiche_balise_fermante("expArith", 1);
|
||||
}
|
||||
|
||||
void expArithBis (void) {
|
||||
affiche_balise_ouvrante("expArithBis", 1);
|
||||
|
||||
if(uniteCourante == PLUS) {
|
||||
uniteCourante = yylex();
|
||||
affiche_xml_texte(yytext);
|
||||
|
||||
expArith();
|
||||
}
|
||||
|
||||
affiche_balise_fermante("expArithBis", 1);
|
||||
}
|
||||
|
||||
void terme (void) {
|
||||
affiche_balise_ouvrante("terme", 1);
|
||||
|
||||
facteur();
|
||||
termeBis();
|
||||
|
||||
affiche_balise_fermante("terme", 1);
|
||||
}
|
||||
|
||||
void termeBis (void) {
|
||||
affiche_balise_ouvrante("termeBis", 1);
|
||||
|
||||
if(uniteCourante == FOIS) {
|
||||
uniteCourante = yylex();
|
||||
affiche_xml_texte(yytext);
|
||||
|
||||
terme();
|
||||
}
|
||||
|
||||
affiche_balise_fermante("termeBis", 1);
|
||||
}
|
||||
|
||||
void facteur (void) {
|
||||
affiche_balise_ouvrante("facteur", 1);
|
||||
|
||||
if(uniteCourante == PARENTHESE_OUVRANTE) {
|
||||
uniteCourante = yylex();
|
||||
affiche_xml_texte(yytext);
|
||||
|
||||
expArith();
|
||||
|
||||
if(uniteCourante != PARENTHESE_FERMANTE) {
|
||||
printf("Erreur de syntaxe");
|
||||
exit(-1);
|
||||
}
|
||||
} else if(uniteCourante == NOMBRE) {
|
||||
uniteCourante = yylex();
|
||||
affiche_xml_texte(yytext);
|
||||
} else {
|
||||
printf("Erreur de syntaxe");
|
||||
exit(-1);
|
||||
}
|
||||
|
||||
affiche_balise_fermante("facteur", 1);
|
||||
}
|
||||
@@ -1,17 +1,33 @@
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include "analyseur_lexical.h"
|
||||
#include "analyseur_syntaxyque.h"
|
||||
#include "symboles.h"
|
||||
|
||||
extern int uniteCourante;
|
||||
|
||||
char yytext[100];
|
||||
FILE *yyin;
|
||||
|
||||
|
||||
int main(int argc, char **argv) {
|
||||
yyin = fopen(argv[1], "r");
|
||||
if(yyin == NULL){
|
||||
fprintf(stderr, "impossible d'ouvrir le fichier %s\n", argv[1]);
|
||||
exit(1);
|
||||
}
|
||||
test_yylex_internal(yyin);
|
||||
return 0;
|
||||
}
|
||||
yyin = fopen(argv[1], "r");
|
||||
if(yyin == NULL){
|
||||
fprintf(stderr, "impossible d'ouvrir le fichier %s\n", argv[1]);
|
||||
exit(1);
|
||||
}
|
||||
|
||||
// test_yylex_internal(yyin);
|
||||
uniteCourante = yylex();
|
||||
affiche_xml_texte(yytext);
|
||||
|
||||
expArith();
|
||||
|
||||
uniteCourante = yylex();
|
||||
|
||||
if(uniteCourante != FIN) {
|
||||
printf("Erreur EOF");
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
@@ -1,17 +0,0 @@
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include "analyseur_lexical.h"
|
||||
#include "symboles.h"
|
||||
|
||||
char yytext[100];
|
||||
FILE *yyin;
|
||||
|
||||
int main(int argc, char **argv) {
|
||||
yyin = fopen(argv[1], "r");
|
||||
if(yyin == NULL){
|
||||
fprintf(stderr, "impossible d'ouvrir le fichier %s\n", argv[1]);
|
||||
exit(1);
|
||||
}
|
||||
test_yylex_internal(yyin);
|
||||
return 0;
|
||||
}
|
||||
1
test/expressionFaux
Normal file
1
test/expressionFaux
Normal file
@@ -0,0 +1 @@
|
||||
10 * + 5
|
||||
1
test/expressionVrai
Normal file
1
test/expressionVrai
Normal file
@@ -0,0 +1 @@
|
||||
12 + 4 * (5 + 10)
|
||||
Reference in New Issue
Block a user