Projects > GC Project > compilation.h

Home | Projects | Links

 

GC PROJECT

  

compilation.h    compilation_defs.h    exp_info.h    GCMainDialog.h    on_apply.h    setaxis.h

Download gc.exe (1.63 MB)        Download VC++ 8.0 Project (54.1 KB RAR Archive)        GC Help


 

#ifndef COMPILATION_H

#define COMPILATION_H

 

//COMPILATION IS A CLSS THAT DOES THE CONVERSION OF A

//CSTRING ENTERED BY USER INTO AN EXPRESSION TREE AND

//ITS MAINTENANCE

 

class compilation{

 

private:

            //"Quality control" flag:

            bool all_correct;

            //This list is filled during tokenization:

            LIST<CString> t_formula;

            //This list is filled with recognised expinfo nodes:

            LIST<expinfo> ei_list;

public:

            //The string, as entered by user:

    CString formula;

            //Top of 'compilation' tree:

    expinfo * top;

            //Returns the f(x) at a certain x:

    double calculate(const double &);

private:

            //pointers to 'expinfo' nodes that are variables (x)

            //are also contained in separate list, so the 'x' values can be

            //quickly switched during graph drawing:

            LIST<expinfo*> var_list;

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

private:

            //Compilation starts with raw CString, and creates

            //list of 'expinfo' nodes:

            void compile(CString &);

 

            //Aux functions that assist 'compile()':

            bool char_check(CString & );

            void separate(CString & );

            void tokenize(CString & str,LIST<CString> & str_t);

 

            //Aux functions for 'build()'

            void do_binary (expinfo *, STACK<expinfo *> & );

            void do_unary (expinfo *, STACK<expinfo *> & );

 

            //Converts a list of CStrings into a list of 'expinfo'

            bool translate (LIST<CString> & , LIST<expinfo> & );

           

            //Connects 'expinfo' nodes to their children

            // (the most complex operation):

            expinfo * build (LIST<expinfo> &, int &);

 

            //Build the list of variables (see 'var_list'):

            void find_vars();

    void fill_vars(const double &); //works together with calculate()

   

public:

            compilation(CString Formula):all_correct(0),top(0) {compile(Formula);}

            ~compilation(){}

 

};

//========================================================================================

 

void compilation::compile(CString & f){

 

            all_correct=1;

    formula=f;

            all_correct=char_check(formula);

            if(all_correct)

            {         

                        formula.Trim();

                        separate(formula);

                        tokenize(formula,t_formula);

                        all_correct=translate(t_formula, ei_list);

            }         

           

            if(all_correct){int i=1;top=build(ei_list,i);find_vars();}

    if(!all_correct) top=0;

 

};

//========================================================================================

void compilation::find_vars(){

            int i=1;

            while(i<=ei_list.getsize()){

                        if(ei_list[i].op==VAR) var_list.atb(&ei_list[i]);

                        ++i;

            }

}

//========================================================================================

void compilation::fill_vars(const double & var_value){

                        lnode<expinfo *> * current=var_list.first;

                        while(current){current->value->nv=var_value;current=current->next;}

            }

 

//========================================================================================

double compilation::calculate(const double & val){

    fill_vars(val);

    return (top->*top->p_calc)();

}

 

 

#include "compilation_defs.h"

#endif

 


compilation.h    compilation_defs.h    exp_info.h    GCMainDialog.h    on_apply.h    setaxis.h

Download gc.exe (1.63 MB)        Download VC++ 8.0 Project (54.1 KB RAR Archive)        GC Help

 

Get WinRAR

 

 

Copyright © Yuri Bulankov 2002

 

Bugs/Comments: code@compilerabuse.com

Copyright (C) 2001-2006 Yuri Bulankov. All rights reserved.