Exemple #1
0
token getToken(fileStruct *files)
{
	token outToken;
    wipeout(&outToken);
	char c,array[2];

	c=fgetc(files->input);
	
    while(c==' '||c=='\t'||c=='\n')
    {
        array[0]=c;
        array[1]='\0';
        strcat(linebuff,array);
        if(c=='\n')
        {
            fprintf(files->lis_file,"%d %s",linenum,linebuff);
            linenum++;
            memset(linebuff,0,sizeof(linebuff));
        }
        c=fgetc(files->input);
    }

    if (c == -1) {
        outToken.actual[0] = ':'; 
        outToken.actual[1] = 'D';
        strcpy(outToken.type, "SCANEOF");
        outToken.number = SCANEOF;
    }
    else if(isalpha(c))
    {
        outToken=process_alpha(c, files);
    }
    else if(isdigit(c))
    {
        outToken=process_num(c,files);
    }
    else if(ispunct(c))
    {
        outToken=process_symbol(c,files);
    }	
    else {
        outToken.actual[0] = c;
        strcpy(outToken.type, "ERROR");
        outToken.number = ERROR;
    }

    fprintf(files->tmp1, "\nTOKEN %s\nTYPE %s\nNUMBER %d\n", outToken.actual, outToken.type, outToken.number);

    return outToken;
}
Exemple #2
0
    subpaving::var process_arith_app(app * t, unsigned depth, mpz & n, mpz & d) {
        SASSERT(m_autil.is_arith_expr(t));

        switch (t->get_decl_kind()) {
        case OP_NUM:
            return process_num(t, depth, n, d);
        case OP_ADD: 
            return process_add(t, depth, n, d);
        case OP_MUL: 
            return process_mul(t, depth, n, d);
        case OP_POWER:
            return process_power(t, depth, n, d);
        case OP_TO_REAL: 
            return process(t->get_arg(0), depth+1, n, d);
        case OP_SUB:
        case OP_UMINUS:
            found_non_simplified();
            break;
        case OP_TO_INT:
        case OP_DIV:
        case OP_IDIV:
        case OP_MOD:
        case OP_REM:
        case OP_IRRATIONAL_ALGEBRAIC_NUM:
            throw default_exception("you must apply arithmetic purifier before internalizing expressions into the subpaving module.");
        case OP_SIN: 
        case OP_COS:
        case OP_TAN:
        case OP_ASIN:
        case OP_ACOS:
        case OP_ATAN:
        case OP_SINH:
        case OP_COSH:
        case OP_TANH:
        case OP_ASINH:
        case OP_ACOSH:
        case OP_ATANH:
            // TODO
            throw default_exception("transcendental and hyperbolic functions are not supported yet.");
        default:
            UNREACHABLE();
        }
        return subpaving::null_var;
    }
void ClientConnection::handle_msg(const std::string &msg) {
	std::vector<std::string> strs;
	boost::split(strs, msg, boost::is_any_of(":\n"));
	std::string cmd = strs[0];
	if (cmd == "num") {
		std::string numStr = strs[1];
		int num = std::stoi(numStr);
		double res = process_num(num);
		std::string resStr = std::to_string(res);
		do_write("ok:" + resStr + "\n", boost::bind(&ClientConnection::on_write_ok, shared_from_this(), _1, _2));
	}
	else if (cmd == "disconnect") {
		do_write("disconnected\n", boost::bind(&ClientConnection::on_write_disconnected, shared_from_this(), _1, _2));
	}
	else {
		std::ostringstream oss;
		oss << "Unexpected msg from client: " << msg;
		throw server_exception(oss.str(), shared_from_this());
	}
}