begin process at 2012 05 27 16:07:42
  Trouver un code source :
 
dans
 
Accueil > 

Code

 > 

Divers

 > EVALUATEUR D'EXPRESSION AVEC VARIABLES INDEXÉES

EVALUATEUR D'EXPRESSION AVEC VARIABLES INDEXÉES


 Information sur la source

Note :
Aucune note
Catégorie :Divers Classé sous :evaluation expression, variable indexées, fonctions Niveau :Initié Date de création :25/09/2010 Vu / téléchargé :2 230 / 97

Auteur : DragonRapide

Ecrire un message privé
Commentaire sur cette source (0)
Ajouter un commentaire et/ou une note

 Description

Voici encore un code d'évaluation d'expressions.

Il s'agit d'une classe de base s'occupant de l'analyse de la chaine de caractère et de la création une pile d'instructions qui peut être exécutée rapidement autant de fois que l'ont veut.
Le principal défaut est de ne pratiquement pas avoir de controle de la syntaxe.
Son intéret est d'avoir un minimum de travail à faire pour évaluer des expressions contenant des constantes, des variables, des variables indexées et des fonction.
La classe de base s'appelle ExpressionBase, un exemple de dérivation est la classe ExpressionArithmetique et le code de test/lancement est le fichier Public.cpp.


Source

  • #include "../StdAfx.h"
  • #include "memory.h"
  • #include "ExpressionBase.h"
  • #define MAX_INSTRUCTION 50
  • static const char* parentheseFermante[] = { ")", NULL};
  • static const char* crochetFermant[] = { "]", NULL};
  • static const char* virguleSeparatrice[] = { ",", NULL};
  • static const char* LOW_PRIORITY_OPERATORS[] = {NULL};
  • static char* HIGH_PRIORITY_OPERATORS[] = {NULL};
  • static char* CONSTANTS_PREFIX = "";
  • static char* CONSTANTS_CONTENT = "";
  • static char* VARIABLES[] = {NULL}; // NULL terminated array of strings
  • static char* INDEXED_VARIABLES[] = {NULL}; // NULL terminated array of strings
  • static char* UNARY_FUNCTIONS[] = {NULL}; // NULL terminated array of strings
  • static char* BINARY_FUNCTIONS[] = {NULL}; // NULL terminated array of strings
  • /**
  • */
  • Expression::Expression(){
  • // ----------
  • instructions = new struct operation *[MAX_INSTRUCTION];
  • instructionFiller = instructions;
  • instructions[ 0] = NULL;
  • lowPriorityOperators = LOW_PRIORITY_OPERATORS;
  • highPriorityOperators = HIGH_PRIORITY_OPERATORS;
  • constantsPrefix = CONSTANTS_PREFIX;
  • constantsContent = CONSTANTS_CONTENT;
  • variables = VARIABLES;
  • indexedVariables = INDEXED_VARIABLES;
  • unaryFunctions = UNARY_FUNCTIONS;
  • binaryFunctions = BINARY_FUNCTIONS;
  • TraceEnabled = FALSE;
  • } // Constructor
  • /**
  • */
  • BOOL Expression::analyse( char* expression){
  • // -------
  • char* char_index;
  • char* position_operateur;
  • const char** operateur;
  • char* buffer;
  • char** symbol_index;
  • int taille_memoire;
  • BOOL result;
  • while( *expression == ' ') expression++;
  • if( *expression == '\0') return TRUE;
  • result = TRUE;
  • // Trouver une addition ou soustraction de niveau 0
  • chercheNiveauZero( expression, lowPriorityOperators, position_operateur, operateur);
  • if( *position_operateur != '\0'){
  • *position_operateur = '\0';
  • analyse( expression);
  • analyse( position_operateur + strlen( *operateur));
  • pushInstruction(
  • LOW_PRIORITY_OPERATOR_CODE_OFFSET + (operateur - lowPriorityOperators),
  • NULL
  • );
  • }else{
  • // Plus que des opérateurs prioritaires
  • if( strchr( constantsPrefix, *expression) != NULL){
  • // Les constantes numériques
  • char_index = expression + 1;
  • while( (*char_index != '\0') && (strchr( constantsContent, *char_index) != NULL)){
  • char_index++;
  • }
  • taille_memoire = (char_index - expression + 1) * sizeof( char);
  • buffer = (char*)malloc( taille_memoire);
  • strncpy_s( buffer, taille_memoire, expression, (char_index - expression));
  • buffer[ char_index - expression] = '\0';
  • pushInstruction( CONSTANT_CODE, buffer);
  • analyse( char_index);
  • }else if( (symbol_index = chercheChaine( expression, variables)) != NULL){
  • // Les variables
  • pushInstruction( VARIABLES_CODE_OFFSET + (symbol_index - variables), NULL);
  • analyse( expression + strlen( *symbol_index));
  • }else if( (symbol_index = chercheChaine( expression, indexedVariables)) != NULL){
  • // Les variables indexées
  • chercheNiveauZero( expression + strlen( *symbol_index) + 1, crochetFermant, position_operateur, operateur);
  • *position_operateur = '\0';
  • analyse( expression + strlen( *symbol_index) + 1);
  • pushInstruction( INDEXED_VARIABLES_CODE_OFFSET + (symbol_index - indexedVariables), NULL);
  • analyse( position_operateur + 1);
  • }else if( *expression == '('){
  • // Gestion des parentheses imbriquées
  • chercheNiveauZero( expression + 1, parentheseFermante, position_operateur, operateur);
  • *position_operateur = '\0';
  • analyse( expression + 1);
  • analyse( position_operateur + 1);
  • }else if( (symbol_index = chercheChaine( expression, highPriorityOperators)) != NULL){
  • // Operateurs prioritaires
  • analyse( expression + strlen( *symbol_index));
  • pushInstruction(
  • HIGH_PRIORITY_OPERATOR_CODE_OFFSET + ( symbol_index - highPriorityOperators),
  • NULL
  • );
  • }else if( (symbol_index = chercheChaine( expression, unaryFunctions)) != NULL){
  • // Fonctions avec un seul argument
  • chercheNiveauZero( expression + strlen( *symbol_index) + 1, parentheseFermante, position_operateur, operateur);
  • *position_operateur = '\0';
  • analyse( expression + strlen( *symbol_index) + 1);
  • pushInstruction( UNARY_FUNCTIONS_CODE_OFFSET + (symbol_index - unaryFunctions), NULL);
  • analyse( position_operateur + 1);
  • }else if( (symbol_index = chercheChaine( expression, binaryFunctions)) != NULL){
  • // Fonctions avec eux arguments
  • chercheNiveauZero( expression + strlen( *symbol_index) + 1, virguleSeparatrice, position_operateur, operateur);
  • *position_operateur = '\0';
  • analyse( expression + strlen( *symbol_index) + 1);
  • expression = position_operateur + 1;
  • chercheNiveauZero( expression, parentheseFermante, position_operateur, operateur);
  • *position_operateur = '\0';
  • analyse( expression);
  • pushInstruction(
  • BINARY_FUNCTIONS_CODE_OFFSET + (symbol_index - binaryFunctions),
  • NULL
  • );
  • analyse( position_operateur + 1);
  • }else{
  • result = FALSE;
  • }
  • }
  • return result;
  • } // analyse()
  • /**
  • */
  • void* Expression::eval(){
  • // ----
  • void* stack[ 50];
  • int stack_size;
  • struct operation ** scan;
  • void* operande_1;
  • void* operande_2;
  • void* resultat;
  • stack_size = 0;
  • scan = instructions;
  • while( *scan != NULL){
  • if( (*scan)->codeOperation == CONSTANT_CODE){
  • // Constante
  • resultat = evalConstant( (*scan)->operande);
  • if( resultat == NULL) return FALSE;
  • stack[ stack_size++] = resultat;
  • }else if( (*scan)->codeOperation < HIGH_PRIORITY_OPERATOR_CODE_OFFSET){
  • // Operateur de faible priorité
  • operande_1 = stack[ stack_size - 2];
  • operande_2 = stack[ stack_size - 1];
  • resultat = evalLowPriorityOperator( (*scan)->codeOperation - LOW_PRIORITY_OPERATOR_CODE_OFFSET, operande_1, operande_2);
  • free( stack[ --stack_size]);
  • free( stack[ --stack_size]);
  • if( resultat == NULL) return FALSE;
  • stack[ stack_size++] = resultat;
  • }else if( (*scan)->codeOperation < VARIABLES_CODE_OFFSET){
  • // Operateur de forte priorité
  • operande_1 = stack[ stack_size - 2];
  • operande_2 = stack[ stack_size - 1];
  • resultat = evalHighPriorityOperator( (*scan)->codeOperation - HIGH_PRIORITY_OPERATOR_CODE_OFFSET, operande_1, operande_2);
  • free( stack[ --stack_size]);
  • free( stack[ --stack_size]);
  • if( resultat == NULL) return FALSE;
  • stack[ stack_size++] = resultat;
  • }else if( (*scan)->codeOperation < INDEXED_VARIABLES_CODE_OFFSET){
  • // Variable
  • resultat = evalVariable( (*scan)->codeOperation - VARIABLES_CODE_OFFSET);
  • if( resultat == NULL) return FALSE;
  • stack[ stack_size++] = resultat;
  • }else if( (*scan)->codeOperation < UNARY_FUNCTIONS_CODE_OFFSET){
  • // Variables indexées
  • operande_1 = stack[ stack_size - 1];
  • resultat = evalIndexedVariable( (*scan)->codeOperation - INDEXED_VARIABLES_CODE_OFFSET, operande_1);
  • free( stack[ --stack_size]);
  • if( resultat == NULL) return FALSE;
  • stack[ stack_size++] = resultat;
  • }else if( (*scan)->codeOperation < BINARY_FUNCTIONS_CODE_OFFSET){
  • // Fonction à un seul argument
  • operande_1 = stack[ stack_size - 1];
  • resultat = evalUnaryFunction( (*scan)->codeOperation - UNARY_FUNCTIONS_CODE_OFFSET, operande_1);
  • free( stack[ --stack_size]);
  • if( resultat == NULL) return FALSE;
  • stack[ stack_size++] = resultat;
  • }else{
  • // Fonction à un deux arguments
  • operande_1 = stack[ stack_size - 2];
  • operande_2 = stack[ stack_size - 1];
  • resultat = evalBinaryFunction( (*scan)->codeOperation - BINARY_FUNCTIONS_CODE_OFFSET, operande_1, operande_2);
  • free( stack[ --stack_size]);
  • free( stack[ --stack_size]);
  • if( resultat == NULL) return FALSE;
  • stack[ stack_size++] = resultat;
  • }
  • scan++;
  • }
  • return (stack_size == 1) ? stack[ 0] : NULL;
  • } // eval()
  • /**
  • */
  • void* Expression::evalConstant( void* donnees){
  • // ------------
  • return NULL;
  • } // evalConstant()
  • /**
  • */
  • void* Expression::evalLowPriorityOperator( int code, void* donnees_1, void* donnees_2){
  • // -----------------------
  • return NULL;
  • } // evalLowPriorityOperator()
  • /**
  • */
  • void* Expression::evalHighPriorityOperator( int code, void* donnees_1, void* donnees_2){
  • // ------------------------
  • return NULL;
  • } // evalHighPriorityOperator()
  • /**
  • */
  • void* Expression::evalVariable( int code){
  • // ------------
  • return NULL;
  • } // evalVariable()
  • /**
  • */
  • void* Expression::evalIndexedVariable( int code, void* donnees){
  • // -------------------
  • return NULL;
  • } // evalIndexedVariable()
  • /**
  • */
  • void* Expression::evalUnaryFunction( int code, void* donnees){
  • // ------------------
  • return NULL;
  • } // evalUnaryFunction()
  • /**
  • */
  • void* Expression::evalBinaryFunction( int code, void* donnees_1, void* donnees_2){
  • // -------------------
  • return NULL;
  • } // evalBinaryFunction()
  • /**
  • * Retourne la position dans la chaine 's' d'un operateur contenu dans 'cibles'.
  • * Rend NULL si il n'existe pas, la position dans 's' et la chaine dans 'cibles'
  • */
  • void Expression::chercheNiveauZero( char* s, const char** cibles, char* &position, const char** &operateur){
  • // -----------------
  • int niveau;
  • position = s;
  • do{
  • if( (*position == '(') || (*position == '[')){
  • niveau = 0;
  • do{
  • if( *position == '(') niveau++;
  • if( *position == '[') niveau++;
  • if( *position == ')') niveau--;
  • if( *position == ']') niveau--;
  • position++;
  • }while( (niveau > 0) && (*position != '\0'));
  • }else{
  • position++;
  • }
  • if( *position != '\0'){
  • operateur = cibles;
  • while(
  • (*operateur != NULL)
  • && ((**operateur != *position) || (strncmp( *operateur, position, strlen( *operateur)) != 0))
  • ){
  • operateur++;
  • }
  • }
  • }while( (*position != '\0') && (*operateur == NULL));
  • } // chercheNiveauZero()
  • /**
  • * Cherche 'liste' la pemière chaine qui est le préfixe de 's'.
  • * Rend NULL si rien trouvé, la chaine dans 'liste' sinon.
  • */
  • char** Expression::chercheChaine( char* s, char** liste){
  • // -------------
  • char** scan;
  • scan = liste;
  • while( *scan != NULL){
  • if( strncmp( s, *scan, strlen( *scan)) == 0) return scan;
  • scan++;
  • }
  • return NULL;
  • } // chercheChaine()
  • /**
  • */
  • void Expression::pushInstruction( int _code_operation, char* _operande){
  • // ---------------
  • if( TraceEnabled){
  • printf( "pushInstruction(): %d, %s\n", _code_operation, _operande);
  • if( (instructionFiller - instructions + 1) >= MAX_INSTRUCTION){
  • printf( "Instruction stack overflow\n");
  • }
  • }
  • *instructionFiller = new( struct operation);
  • (*instructionFiller)->codeOperation = _code_operation;
  • (*instructionFiller)->operande = _operande;
  • instructionFiller++;
  • *instructionFiller = NULL;
  • } // pushInstruction()
  • /**
  • */
  • Expression::~Expression(){
  • // ----------
  • struct operation **scan;
  • if( instructions != NULL){
  • for( scan = instructions; *scan != NULL; scan++){
  • if( (*scan)->operande != NULL) free( (*scan)->operande);
  • free( *scan);
  • }
  • free( instructions);
  • }
  • } // Destructor
  • // ---------------------------------------------------------------------------
#include "../StdAfx.h"

#include "memory.h"

#include "ExpressionBase.h"

#define MAX_INSTRUCTION 50

static const char* parentheseFermante[] = { ")", NULL};
static const char* crochetFermant[] = { "]", NULL};
static const char* virguleSeparatrice[] = { ",", NULL};

static const char* LOW_PRIORITY_OPERATORS[] = {NULL};
static char* HIGH_PRIORITY_OPERATORS[] = {NULL};
static char* CONSTANTS_PREFIX = "";
static char* CONSTANTS_CONTENT = "";
static char* VARIABLES[] = {NULL}; // NULL terminated array of strings
static char* INDEXED_VARIABLES[] = {NULL}; // NULL terminated array of strings
static char* UNARY_FUNCTIONS[] = {NULL}; // NULL terminated array of strings
static char* BINARY_FUNCTIONS[] = {NULL}; // NULL terminated array of strings


/**
 */
Expression::Expression(){
//          ----------
  instructions = new struct operation *[MAX_INSTRUCTION];
  instructionFiller = instructions;
  instructions[ 0] = NULL;

  lowPriorityOperators = LOW_PRIORITY_OPERATORS;
  highPriorityOperators = HIGH_PRIORITY_OPERATORS;
  constantsPrefix = CONSTANTS_PREFIX;
  constantsContent = CONSTANTS_CONTENT;
  variables = VARIABLES;
  indexedVariables = INDEXED_VARIABLES;
  unaryFunctions = UNARY_FUNCTIONS;
  binaryFunctions = BINARY_FUNCTIONS;

  TraceEnabled = FALSE;
}  // Constructor

/**
 */
BOOL Expression::analyse( char* expression){
//               -------
  char* char_index;
  char* position_operateur;
  const char** operateur;
  char* buffer;
  char** symbol_index;
  int taille_memoire;
  BOOL result;

  while( *expression == ' ') expression++;
  if( *expression == '\0') return TRUE;

  result = TRUE;

  // Trouver une addition ou soustraction de niveau 0
  chercheNiveauZero( expression, lowPriorityOperators, position_operateur, operateur);
  if( *position_operateur != '\0'){
	*position_operateur = '\0';
    analyse( expression);
    analyse( position_operateur + strlen( *operateur));
	pushInstruction( 
	  LOW_PRIORITY_OPERATOR_CODE_OFFSET + (operateur - lowPriorityOperators),
	  NULL
	  );
  }else{
    // Plus que des opérateurs prioritaires
	if( strchr( constantsPrefix, *expression) != NULL){
	  // Les constantes numériques
	  char_index = expression + 1;
	  while( (*char_index != '\0') && (strchr( constantsContent, *char_index) != NULL)){
        char_index++;
	  }

	  taille_memoire = (char_index - expression + 1) * sizeof( char);
      buffer = (char*)malloc( taille_memoire);
      strncpy_s( buffer, taille_memoire, expression, (char_index - expression));
	  buffer[ char_index - expression] = '\0';
  	  pushInstruction( CONSTANT_CODE, buffer);

	  analyse( char_index);
	}else if( (symbol_index = chercheChaine( expression, variables)) != NULL){
	  // Les variables
	  pushInstruction( VARIABLES_CODE_OFFSET + (symbol_index - variables), NULL);

	  analyse( expression + strlen( *symbol_index));
	}else if( (symbol_index = chercheChaine( expression, indexedVariables)) != NULL){
	  // Les variables indexées
      chercheNiveauZero( expression + strlen( *symbol_index) + 1, crochetFermant, position_operateur, operateur);
	  *position_operateur = '\0';
	  analyse( expression + strlen( *symbol_index) + 1);
	  pushInstruction( INDEXED_VARIABLES_CODE_OFFSET + (symbol_index - indexedVariables), NULL);

	  analyse( position_operateur + 1);
	}else if( *expression == '('){
	  // Gestion des parentheses imbriquées
      chercheNiveauZero( expression + 1, parentheseFermante, position_operateur, operateur);
	  *position_operateur = '\0';
      analyse( expression + 1);
	  analyse( position_operateur + 1);
    }else if( (symbol_index = chercheChaine( expression, highPriorityOperators)) != NULL){
	  // Operateurs prioritaires
      analyse( expression + strlen( *symbol_index));
	  pushInstruction( 
		HIGH_PRIORITY_OPERATOR_CODE_OFFSET + ( symbol_index - highPriorityOperators),
	    NULL
		);
	}else if( (symbol_index = chercheChaine( expression, unaryFunctions)) != NULL){
	  // Fonctions avec un seul argument
      chercheNiveauZero( expression + strlen( *symbol_index) + 1, parentheseFermante, position_operateur, operateur);
	  *position_operateur = '\0';
	  analyse( expression + strlen( *symbol_index) + 1);
	  pushInstruction( UNARY_FUNCTIONS_CODE_OFFSET + (symbol_index - unaryFunctions), NULL);

	  analyse( position_operateur + 1);
	}else if( (symbol_index = chercheChaine( expression, binaryFunctions)) != NULL){
	  // Fonctions avec eux arguments
      chercheNiveauZero( expression + strlen( *symbol_index) + 1, virguleSeparatrice, position_operateur, operateur);
	  *position_operateur = '\0';
	  analyse( expression + strlen( *symbol_index) + 1);
	  expression = position_operateur + 1;
      chercheNiveauZero( expression, parentheseFermante, position_operateur, operateur);
	  *position_operateur = '\0';
	  analyse( expression);
	  pushInstruction(
	    BINARY_FUNCTIONS_CODE_OFFSET + (symbol_index - binaryFunctions),
		NULL
	  );

	  analyse( position_operateur + 1);
	}else{
      result = FALSE;
	}
  }

  return result;
} // analyse()

/**
 */
void* Expression::eval(){
//                ----
  void* stack[ 50];
  int stack_size;
  struct operation ** scan;
  void* operande_1;
  void* operande_2;
  void* resultat;

  stack_size = 0;
  scan = instructions;
  while( *scan != NULL){
    if( (*scan)->codeOperation == CONSTANT_CODE){
	  // Constante
	  resultat = evalConstant( (*scan)->operande);
	  if( resultat == NULL) return FALSE;
	  stack[ stack_size++] = resultat;
    }else if( (*scan)->codeOperation < HIGH_PRIORITY_OPERATOR_CODE_OFFSET){
	  // Operateur de faible priorité
	  operande_1 = stack[ stack_size - 2];
	  operande_2 = stack[ stack_size - 1];
	  resultat = evalLowPriorityOperator( (*scan)->codeOperation - LOW_PRIORITY_OPERATOR_CODE_OFFSET, operande_1, operande_2); 
	  free( stack[ --stack_size]);
	  free( stack[ --stack_size]);
	  if( resultat == NULL) return FALSE;
	  stack[ stack_size++] = resultat;
    }else if( (*scan)->codeOperation < VARIABLES_CODE_OFFSET){
	  // Operateur de forte priorité
	  operande_1 = stack[ stack_size - 2];
	  operande_2 = stack[ stack_size - 1];
	  resultat = evalHighPriorityOperator( (*scan)->codeOperation - HIGH_PRIORITY_OPERATOR_CODE_OFFSET, operande_1, operande_2); 
	  free( stack[ --stack_size]);
	  free( stack[ --stack_size]);
	  if( resultat == NULL) return FALSE;
	  stack[ stack_size++] = resultat;
    }else if( (*scan)->codeOperation < INDEXED_VARIABLES_CODE_OFFSET){
	  // Variable
	  resultat = evalVariable( (*scan)->codeOperation - VARIABLES_CODE_OFFSET); 
	  if( resultat == NULL) return FALSE;
	  stack[ stack_size++] = resultat;
    }else if( (*scan)->codeOperation < UNARY_FUNCTIONS_CODE_OFFSET){
	  // Variables indexées
	  operande_1 = stack[ stack_size - 1];
	  resultat = evalIndexedVariable( (*scan)->codeOperation - INDEXED_VARIABLES_CODE_OFFSET, operande_1); 
	  free( stack[ --stack_size]);
	  if( resultat == NULL) return FALSE;
	  stack[ stack_size++] = resultat;
    }else if( (*scan)->codeOperation < BINARY_FUNCTIONS_CODE_OFFSET){
	  // Fonction à un seul argument
	  operande_1 = stack[ stack_size - 1];
	  resultat = evalUnaryFunction( (*scan)->codeOperation - UNARY_FUNCTIONS_CODE_OFFSET, operande_1); 
	  free( stack[ --stack_size]);
	  if( resultat == NULL) return FALSE;
	  stack[ stack_size++] = resultat;
	}else{
	  // Fonction à un deux arguments
	  operande_1 = stack[ stack_size - 2];
	  operande_2 = stack[ stack_size - 1];
	  resultat = evalBinaryFunction( (*scan)->codeOperation - BINARY_FUNCTIONS_CODE_OFFSET, operande_1, operande_2); 
	  free( stack[ --stack_size]);
	  free( stack[ --stack_size]);
	  if( resultat == NULL) return FALSE;
	  stack[ stack_size++] = resultat;
	}
	scan++;
  }

  return (stack_size == 1) ? stack[ 0] : NULL;
} // eval()

/**
 */
void* Expression::evalConstant( void* donnees){
//                ------------
  return NULL;
} // evalConstant()

/**
 */
void* Expression::evalLowPriorityOperator( int code, void* donnees_1, void* donnees_2){
//                -----------------------
  return NULL;
} // evalLowPriorityOperator()

/**
 */
void* Expression::evalHighPriorityOperator( int code, void* donnees_1, void* donnees_2){
//                ------------------------
  return NULL;
} // evalHighPriorityOperator()

/**
 */
void* Expression::evalVariable( int code){
//                ------------
  return NULL;
} // evalVariable()

/**
 */
void* Expression::evalIndexedVariable( int code, void* donnees){
//                -------------------
  return NULL;
} // evalIndexedVariable()

/**
 */
void* Expression::evalUnaryFunction( int code, void* donnees){
//                ------------------
  return NULL;
} // evalUnaryFunction()

/**
 */
void* Expression::evalBinaryFunction( int code, void* donnees_1, void* donnees_2){
//                -------------------
  return NULL;
} // evalBinaryFunction()

/**
 * Retourne la position dans la chaine 's' d'un operateur contenu dans 'cibles'.
 * Rend NULL si il n'existe pas, la position dans 's' et la chaine dans 'cibles'
 */
void Expression::chercheNiveauZero( char* s, const char** cibles, char* &position, const char** &operateur){
//               -----------------
  int niveau;

  position = s;
  do{
	if( (*position == '(') || (*position == '[')){
      niveau = 0;
	  do{
	    if( *position == '(') niveau++;
	    if( *position == '[') niveau++;
	    if( *position == ')') niveau--;
	    if( *position == ']') niveau--;
		position++;
	  }while( (niveau > 0) && (*position != '\0'));
	}else{
	  position++;
	}
	if( *position != '\0'){
	  operateur = cibles;
	  while( 
		(*operateur != NULL) 
		&& ((**operateur != *position) || (strncmp( *operateur, position, strlen( *operateur)) != 0))
	  ){
	    operateur++;
	  }
	}
  }while( (*position != '\0') && (*operateur == NULL));
} // chercheNiveauZero()

/**
 * Cherche 'liste' la pemière chaine qui est le préfixe de 's'.
 * Rend NULL si rien trouvé, la chaine dans 'liste' sinon.
 */
char** Expression::chercheChaine( char* s, char** liste){
//                 -------------
  char** scan;

  scan = liste;
  while( *scan != NULL){
	if( strncmp( s, *scan, strlen( *scan)) == 0) return scan;
	scan++;
  }

  return NULL;
} // chercheChaine()

/**
 */
void Expression::pushInstruction( int _code_operation, char* _operande){
//               ---------------

  if( TraceEnabled){
	printf( "pushInstruction(): %d, %s\n", _code_operation, _operande);
	if( (instructionFiller - instructions + 1) >= MAX_INSTRUCTION){
	  printf( "Instruction stack overflow\n");
	}
  }
  *instructionFiller = new( struct operation);
  (*instructionFiller)->codeOperation = _code_operation;
  (*instructionFiller)->operande = _operande;
  instructionFiller++;
  *instructionFiller = NULL;
} // pushInstruction()

/**
 */
Expression::~Expression(){
//           ----------
  struct operation **scan;
  if( instructions != NULL){ 
    for( scan = instructions; *scan != NULL; scan++){
	  if( (*scan)->operande != NULL) free( (*scan)->operande);
  	  free( *scan);
	}

 	free( instructions);
  }
} // Destructor

// ---------------------------------------------------------------------------


 Conclusion

Je vais utiliser cette classe pour d'autres projet, elle va surement évoluer en bien.

 Fichier Zip

Les Membres Club peuvent télécharger directement un fichier contenu dans le zip sans télécharger le zip en entier !

Télécharger le zip


 Sources du même auteur

Source avec Zip RÉGULATEUR EN LOGIQUE FLOUE AVEC SIMULATEUR

 Sources de la même categorie

Source avec Zip KISIEL CD INFO DRIVE par kisiel0147852
Source avec une capture SUPPRESSION DES REDONDANCES DE FICHIERS par cyberntique
Source avec Zip ÉDITEUR DE RECTANGLES EN CONSOLE par seoseo
CONVERSION DE FICHIER EN FICHIER BMP par seoseo
Source avec Zip DETECTEUR EJP par idpro

 Sources en rapport avec celle ci

Source avec Zip Source avec une capture [C++] CLASSE DE GESTION DE FONCTIONS par pop70
Source avec Zip BIBLIOTHEQUE FONCTIONNELLE : OPÉRATIONS, COMPOSITION D'OBJET... par ordiman85
Source avec Zip Source avec une capture BOITE A OUTILS MATHÉMATIQUES POUR L'ALGÈBRE LINÉAIRE ET L'... par BOLLOTD
Source avec une capture [C] BALLES REBONDISSANTES EN SDL par smartties
Source avec une capture EXEMPLE DE POINTEURS DE FONCTION par pop70

Commentaires et avis

Aucun commentaire pour le moment.

 Ajouter un commentaire


Discussions en rapport avec ce code source dans le forum

AIDE: CHERCHE TUTORIEL SUR LES FONCTIONS GRAPHIQUES [ par Mmuller57 ] je CHERCHE un TUTORIEL sur LES FONCTIONS GRAPHIQUES en C++(tracer une ligne, un cercle, un carrée, un rectangle, un polygone et le tout en C++ !). Je liste de fonctions [ par niconico ] quelqu'un aurait-il l'adresse d'un site ou je pourrait trouver la liste des fonctions en C++; ou au moins celles relatives a la creation, modification problèmes liens entre fichiers C et C++ dans un projet Visual C++ 6.0 [ par nico ] J'ai récupéré un projet contenant des fichiers écrits en C. Le fichier "principal" de ce projet également écrit en C fait appel à des fonctions se tro codes C++ pour TAPI et MAPI [ par Francky ] Bonjour,Je recherches des codes sources C++ pour les les fonctions TAPI (téléphone) et fonctions MAPI (mails).Merci d'avance. Comment utiliser InternetOpen(...), CloseHandle(...) et autres fonctions se rapportant au Web ? [ par Tiot Seb ] Salut amis programmeurs sous Visual C++!J'ai besoin, pour un projet de stage, de pouvoir, ouvrir et fermer Internet Explorer. En fait, je dois créer u classes ou juste fonctions ? [ par madVinz ] Salut!Comment choisir entre faire des classes ou juste des fonctions ???merci, @+ <bios.h>aidez moi aussi pour les fonctions geaphiques sous dev c++ 4.0 [ par riderpro ] Voila il me faut &lt;bios.h&gt; pour dev c++ 4.0 sinon je ne peux pas faire mes progs pleas entrz en contact pour coopération Tableau de correspondance des fonctions c++ et de leur fichier #include [ par guguy ] BonjourJ'aimerais savoir s'il serait possible de trouver un tableau de correspondance entre les fonctions c++ et leur fichier #include (ex : cout -&gt Fonctions graphiques de bases [ par Lissyx ] Bonjour, je cherche des fonctions graphiques simple (style tracer un point, une droite, un cercle etc...) pour C++ (sous Win2000Pro, architecture x86 Librairies mathématiques VS matlab [ par devilinside ] Devant coder une interface graphique en visual C++ pour un logiciel de calcul, je suis fort dépourvu.Le code original du coeur de calcul tourne sous m


Nos sponsors


Sondage...

Comparez les prix

CalendriCode

Mai 2012
LMMJVSD
 123456
78910111213
14151617181920
21222324252627
28293031   

Consulter la suite du CalendriCode

A découvrir



 
Développement réalisé par Nicolas SOREL (Nix) avec l'aide de : Cyril DURAND et Emmanuel (EBArtSoft), Merci à Vincent pour ses précieux conseils.
CodeS-SourceS.com© Toute reproduction même partielle est interdite sauf accord écrit du Webmaster
CodeS-SourceS.com© est une marque déposée tous droits réservés

Google Coop CodeS-SourceS Google Coop CodeS-SourceS
Temps d'éxécution de la page : 0,593 sec (4)

Nous contacter | Annoncer sur CodeS-SourceS | Mentions légales