Language: C++

#include <bits/stdc++.h>
using namespace std;

#define rep(i,x,y) for(int i=(x);i<(y);++i)
#define debug(x) #x << "=" << (x)

#ifdef DEBUG
#define _GLIBCXX_DEBUG
#define dump(x) std::cerr << debug(x) << " (L:" << __LINE__ << ")" << std::endl
#else
#define dump(x)
#endif

typedef long long int ll;
typedef pair<int,int> pii;
//template<typename T> using vec=std::vector<T>;

const int inf=1<<30;
const long long int infll=1LL<<58;
const double eps=1e-9;
const int dx[]={1,0,-1,0},dy[]={0,1,0,-1};

template <typename T> ostream &operator<<(ostream &os, const vector<T> &vec){
    os << "[";
    for (const auto &v : vec) {
    	os << v << ",";
    }
    os << "]";
    return os;
}

typedef string::const_iterator state;

int expression(state&);

int number(state &begin){
    int res=0;
    while(isdigit(*begin)){
        res*=10;
        res+=*begin-'0';
        ++begin;
    }
    return res;
}

int factor(state &begin){
    if(*begin=='(' or *begin=='['){
        begin++;
        const int res=expression(begin);
        begin++;
        return res;
    }else return number(begin);
}

int expression(state &begin){
    int res=factor(begin);
    if(res==inf) return inf;
    while(true){
        if(*begin=='+'){
            ++begin;
            res+=expression(begin);
        }else if(*begin=='-'){
            ++begin;
            res-=expression(begin);
        }else if(*begin=='*'){
            ++begin;
            res*=expression(begin);
        }else if(*begin=='/'){
            ++begin;
            const int tmp=expression(begin);
            if(tmp==0) return inf;
            res/=tmp;
        }else break;
    }
    return res;
}

void solve(){
    while(true){
        string str;
        cin >> str;
        if(str=="#") return;

        const int cnt=0;
        for(const auto ch:str) if(ch=='+' or ch=='-' or ch=='*' or ch=='/') ++cnt;

        set<int> res;
        function<void(const string,const int,const stack<char>,bool)> rec=[&](const string s,const int idx,const stack<char> stk,bool f){
            if(idx==s.size()){
                if(!stk.size()){
                    string s_=s;
                    dump(s_);
                    state begin=s_.begin();
                    const int res_=expression(begin);
                    if(res_!=inf) res.insert(res_);
                    dump(res_);
                }
                return;
            }
            if(s[idx]=='('){
                auto stk_=stk;
                stk_.push('(');
                rec(s,idx+1,stk_,f);
                return;
            }
            if(s[idx]==')'){
                if(!stk.size() or stk.top()!='(') return;
                auto stk_=stk;
                stk_.pop();
                rec(s,idx+1,stk_,f);
                return;
            }
            if(stk.size()<cnt and isdigit(s[idx]) and (!idx or !isdigit(s[idx-1]))){
                auto stk_=stk;
                stk_.push('[');
                auto s_=s;
                s_.insert(idx,"[");
                rec(s_,idx,stk_,false);
            }
            if(f and (idx+1==s.size() or (isdigit(s[idx]) and !isdigit(s[idx+1])))){
                if(!stk.size() or stk.top()!='['){
                    rec(s,idx+1,stk,f);
                    return;
                }
                auto stk_=stk;
                auto s_=s;
                stk_.pop();
                if(idx+1==s.size()) s_+="]";
                else s_.insert(idx+1,"]");
                rec(s_,idx+1,stk_,false);
            }
            if(s[idx]=='+' or s[idx]=='-' or s[idx]=='*' or s[idx]=='/') rec(s,idx+1,stk,true);
            else rec(s,idx+1,stk,f);
        };
        rec(str,0,stack<char>(),false);
        cout << res.size() << endl;
    }
}

int main(){
    std::ios::sync_with_stdio(false);
    std::cin.tie(0);
    cout << fixed << setprecision(8);
    solve();
    return 0;
}

Compiler output:
a.cc: In function 'void solve()':
a.cc:85:79: error: increment of read-only variable 'cnt'
   85 |         for(const auto ch:str) if(ch=='+' or ch=='-' or ch=='*' or ch=='/') ++cnt;
      |                                                                               ^~~