Public feed #602054

piromanas

public cpp v1 · immutable
Raw Edit
·published 2007-07-03 21:26 UTC
rendered paste body
void parser (  list<node *> & input ) {        list<node *>::iterator i = input.begin(), i1, o ;    char const * op [] = {"*","/","-","+"} ;    list<string> operators(op,op+sizeof(op)/sizeof(op[0])) ;    list<string>::iterator str_i = operators.begin() ;    int state = state::binary ;           while ( state != state::quit ) {                                    switch (state) {                                case state::binary :                                         if ( i != input.end() && ((*i)->type == state::value || (*i)->type == state::expression) ) {                                            i1 = i ;                                            ++i ;                                            if ( i != input.end() && ((*i)->type == state::operation || (*i)->type == state::expression) && (*i)->token == *str_i ) {                                                node *o = *i ;                                                ++i ;                                                if ( i != input.end() && ((*i)->type == state::value  || (*i)->type == state::expression) ) {                                                    o->left = *i1 ;                                                    o->right = *i;                                                    o->type = state::expression ;                                                    input.erase(i1) ;                                                    input.erase( find(input.begin(), input.end(), o->right ) ) ;                                                    i = input.begin() ;                                                    state = state::binary ;                                                }                                            }                                        }                                        else if ( i != input.end() ) {                                            state = state::binary ;                                            ++i ;                                        }                                        else if ( i == input.end() && str_i != operators.end() ) {                                            i = input.begin() ;                                            state = state::binary ;                                            ++str_i ;                                                                                    }                                        else                                            state = state::quit ;                                                                                break ;            }        }    }