Exemple #1
0
/*-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------*/
std::string                     CExprParser::ParseInput     ()
{   /* This is the thing that needs to be different to destroy the hell in m_array->ReEvaluate. But I am too unskilled jedi to do this */
    std::string                 noWhiteSpace = SkipWhiteSpace();
    std::string                 value        = "";
    const CExtendedCell*        help         = NULL;
    
    noWhiteSpace.erase( 0, 1 );
    if ( m_cellsNum == 0 )
        SetCellsInExpr(noWhiteSpace);
    
    for ( register int i = 0; i < m_cellsNum; i++ )
    {
        help = m_parser.m_array->SearchIdx( *(m_cells[i]) );
        
        if (help == NULL)
          value = "0";
        else
          value = help->MyResult();
        
        m_cells[i]->insert( 0, ":" );
        m_cells[i]->insert( m_cells[i]->length(), ":" );
        noWhiteSpace.replace( noWhiteSpace.find( *(m_cells[i]) ), m_cells[i]->length(), value );
    }
    return RPN( ShuntingYard( noWhiteSpace ) );
}
Exemple #2
0
int main(void)
{
    float *total = malloc(sizeof(float));
    char *exp = malloc(1);

    printf("Expression: ");

    unsigned int index = 0;
    exp[index] = (char)getchar();
    while(exp[index] != '\n')
    {
        index++;
        exp = realloc(exp, (index + 1));
        exp[index] = (char)getchar();
    }
    
    if(RPN(exp, total))
    {
        printf("Invalid Expression\n");
    }
    else
    {
        printf("Result: %d\n", (int)*total);
    }

    free(exp);
    free(total);
}
Exemple #3
0
int main(){

	char command[80];
	float *answer = malloc(sizeof(float));

	do{
	
		int i = 0;

		printf("Expression: ");
		
		command[i] = (char)getchar();
		while(i < 80 && command[i] != '\n'){

			i++;
			command[i] = (char)getchar();

		}

		command[i] = '\0';

		if(!strcmp(command, "quit")){break;}
		if(!RPN(command, answer)){

			printf("Result: %d\n\n", (int)*answer);

		}else{

			printf("Invalid Command\n");

		}

	}while(strcmp(command, "quit"));

	free(answer);
}
Exemple #4
0
Parser::Parser(QString input): sourceStr(input)
{
    RPN();
}