Go: package main

import (
	"bufio"
	"fmt"
	"os"
)

var sc = bufio.NewScanner(os.Stdin)

func nextString() string {
	sc.Scan()
	return sc.Text()
}

func main() {
	sc.Buffer(make([]byte, 0), 1000000009)

	for {
		var s string
		s = nextString()
		if s == "." {
			break
		}
		var st []byte
		is_valid := true

		for _, value := range s {
			if value == '(' {
				st = append(st, byte(value))
			}
			if value == '[' {
				st = append(st, byte(value))
			}
			if value == ')' {
				if len(st) == 0 || st[len(st)-1] != '(' {
					is_valid = false
					break
				} else {
					st = st[:len(st)-1]
				}
			}
			if value == ']' {
				if len(st) == 0 || st[len(st)-1] != '[' {
					is_valid = false
					break
				} else {
					st = st[:len(st)-1]
				}
			}
		}
		if len(st) != 0 {
			is_valid = false
		}
		if is_valid {
			fmt.Println("yes")
		} else {
			fmt.Println("no")
		}
	}
}

C++: 

#include <iostream>
#include <cmath>
#include <vector>
#include <string>
#include <map>
#include <algorithm>
#include <tuple>
#include <set>
#include <stack>


using namespace std;
using ll = long long;
using ull = unsigned long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vl = vector<ll>;
using pii = pair<int, int>;
using vpii = vector<pii>;
#define out(S) cout<<(S)<<endl;
#define REP(i,b) for(size_t i=0;i<(b);i++)
#define rREP(i,b) for(int i=(b)-1;i>=0;i--)
#define FOR(i,a,b) for(size_t i=(a);i<(b);i++)
#define rFOR(i,a,b) for(int i=(a)-1;i>=(b);i--)
#define Foreach(item,collection) for(auto item:collection)
#define mod(i) ((i) % (ll)(1e9 + 7))
ll modpow(ll i, ll j) { ll tmp = 1; while (j) { if (j % 2)tmp = mod(tmp*i); i = mod(i*i); j /= 2; }return tmp; }
#define divmod(a,b) (mod(a * modpow((ll)b,(ll)(1e9 + 5))))
#define Yes out("Yes")
#define No out("No")
#define NO out("NO")
#define YES out("YES")
#define INF 1e10;
#define ShowAll(collection) for(auto i:collection){out(i);}
#define IfOut(condition,text) if((condition)){out(text);return 0;}
#define IfeOut(condition,itext,etext) if(condition){out(itext);return 0;}else{out(etext);return 0;}
#define Select(collection,condition,result) Foreach(i,collection){result+=condition;}
#define GetAuto(_N,vect) {cin>>_N;vect.resize(_N);REP(i,_N){cin>>vect[i];}}
#define beginend(vec) (vec).begin(),(vec).end()
#define pb(item) push_back(item)
#define removeAll(vec,deleg) auto itr=remove_if(beginend(vec),deleg);vec.erase(itr,vec.end());
void removeAt(string& s, int index) { s.erase(index, 1); }
template<typename T> void removeAt(vector<T>& v, int index) { v.erase(v.begin() + index); }
ll manhattanDistance(ll x1, ll y1, ll x2, ll y2) { return (abs(x2 - x1) + abs(y2 - y1)); }
vector<ll> sieveOfEratosthenes(int max) {ll prime;double sqrtmax = sqrt(max);vector<ll> primeVec, searchVec;FOR(i, 2, max + 1) searchVec.push_back(i);do{prime = searchVec[0];primeVec.push_back(prime);auto itr = remove_if(beginend(searchVec), [=](ll x)->bool {return x%prime == 0; });searchVec.erase(itr, searchVec.end());} while (prime < sqrtmax);primeVec.reserve(primeVec.size() + searchVec.size());primeVec.insert(primeVec.end(), beginend(searchVec));return primeVec;}

int solve(string S) {
	stack<char> st;
	bool f = true;
	Foreach(i, S) {
		if (i == '('||i=='[') st.push(i);
		if (i == ')' || i == ']') {
			if (st.size() == 0) { f = false; break; }
			auto p = st.top();
			if ((i == ')'&&p == '(') || (i == ']'&&p == '[')) st.pop();
			else { f = false; break; }
		}
	}
	IfeOut(st.size() == 0 && f, "yes", "no");
}

int main() {
	char S[105];
	while (cin.getline(S, sizeof(S)))
	{
		if (S[0]=='.'&&S[1]=='\0') break;
		solve(S);
	}
	return 0;
}

C++: #include<iostream>
#include<vector>
#include<string>
#include<algorithm>
using namespace std;

bool check(string &s){
	char st[128],t;
	int sp=0;
	for(int i=0;i<s.size();i++){
		if(s[i]=='('){
			st[sp++]=s[i];
		}else if(s[i]=='['){
			st[sp++]=s[i];
		}else if(s[i]==')'){
			if(sp==0 || st[--sp]!='(')return false;
		}else if(s[i]==']'){
			if(sp==0 || st[--sp]!='[')return false;
		}
	}
	if(sp)return false;
	return true;
}
int main(){
	string s;
	while(1){
		getline(cin,s);
		if(s[0]=='.')break;
		cout<<(check(s)?"yes":"no")<<endl;
	}
	return 0;
}

C++: #include<bits/stdc++.h>
#define _ ios_base::sync_with_stdio(0);cin.tie(0);
#define REP(i,n) for(int i=0;i<(int)(n);i++)

using namespace std;

int main(){ _;
  string s;
  while(getline(std::cin,s),s!="."){
    bool ok=true;
    stack<char> brackets;
    for(char c:s){
      if(c=='['){
	brackets.push('[');
      }else if(c==']'){
	if(!brackets.empty()&&brackets.top()=='[') brackets.pop();
	else{ok=false;break;}
      }
      else if(c=='('){
	brackets.push('(');
      }else if(c==')'){
	if(!brackets.empty()&&brackets.top()=='(') brackets.pop();
	else{ok=false;break;}
      }
    }
    cout<<(ok&&brackets.empty()?"yes":"no")<<endl;
  }
}

C++: #define _USE_MATH_DEFINES
#include <iostream>
#include <fstream>
#include <sstream>
#include <string>
#include <cstring>
#include <vector>
#include <set>
#include <map>
#include <unordered_map>
#include <queue>
#include <deque>
#include <stack>
#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <numeric>
#include <functional>
#include <cctype>
#include <list>
#include <limits>
#include <cassert>
//#include <boost/multiprecision/cpp_int.hpp>



using namespace std;
using Int = long long;
//using namespace boost::multiprecision;

const double EPS = (1e-10);
long long const MOD = 1000000007;

long long mod_pow(long long x, long long n) {
    long long res = 1;
    for(int i = 0;i < 60; i++){
        if(n >> i & 1) res = res * x % MOD;
        x = x * x % MOD;
    }
    return res;
}

template<typename T>
T gcd(T a, T b) {
    return b != 0 ? gcd(b, a % b) : a;
}

template<typename T>
T lcm(T a, T b) {
    return a * b / gcd(a, b);
}

void fastInput() {
    cin.tie(0);
    ios::sync_with_stdio(false);
}


int solve(string S) {
    int maruCnt = 0;
    int kadoCnt = 0;
    int maruCntArray[105] = {0};
    int kadoCntArray[105] = {0};
    stack<int> maruIdx;
    stack<int> kadoIdx;
    int ret = 1;
    for (int i = 0; i < S.length(); i++) {
        if (S[i] == '(') {
            maruIdx.push(i+1);
            maruCnt++;
        }
        if (S[i] == '[') {
            kadoIdx.push(i+1);
            kadoCnt++;
        }
        if (S[i] == ')') {
            if (maruIdx.empty()) {
                ret = 0;
                break;
            }
            if (kadoCntArray[maruIdx.top()] != kadoCntArray[i]) {
                ret = 0;
            }
            maruIdx.pop();
            maruCnt--;
        }
        if (S[i] == ']') {
            if (kadoIdx.empty()) {
                ret = 0;
                break;
            }
            if (maruCntArray[kadoIdx.top()] != maruCntArray[i]) {
                ret = 0;
            }
            kadoIdx.pop();
            kadoCnt--;
        }
        maruCntArray[i+1] = maruCnt;
        kadoCntArray[i+1] = kadoCnt;
    }
    if (!kadoIdx.empty() || !maruIdx.empty() ) ret = 0;
    return ret;
}

int main(void) {
    string S;
    vector<int> ans;
    while (1) {
        getline(cin, S);
        if (S.length() == 1 && S[0] == '.') break;
        ans.push_back(solve(S));
    }
    for (auto &i : ans) {
        if (i) {
            cout << "yes" << endl;
        } else {
            cout << "no" << endl;
        }
    }

}