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 <bits/stdc++.h>
using namespace std;
int main(){
    stack<char> w;
    string s;
    while(getline(cin,s)){
        int d=0;
        if(s[0]=='.')break;
        for(int i=0;i<s.size();i++){
            if(s[i]=='['||s[i]=='(')w.push(s[i]);
            else if(s[i]==']'){
                if(w.top()=='[')w.pop();
            }
            else if(s[i]==')'){
                if(w.top()=='(')w.pop();
            }
        }
        if(w.empty())cout<<"Yes"<<endl;
        else cout<<"No"<<endl;
    }
}

C++: /* vim:set foldmethod=marker: */
#include <bits/stdc++.h>
using namespace std;

//{{{
#define all(x) (x).begin(),(x).end()
#define REP(i,a,b) for(int i=(int)(a); i<(int)(b); i++)
#define RREP(i,a,b) for(int i=(int)(a); i>=b; i--)
#define rep(i,n) REP(i,0,n)
#define rrep(i,n) RREP(i,n,0)
#define pb(x) push_back(x)
#define mp(x,y) make_pair((x),(y))

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<pii> vp;

#define dump(x) (cerr << #x << "=" << x << endl)
template<class T> ostream& osContainer(ostream& os,T c) { os<<'[';for(decltype(c.begin()) it=c.begin();it!=c.end();it++)os<<*it<<',';os<<']';return os; }
template<class T> ostream& operator<<(ostream& os,const vector<T>& v) { return osContainer(os,v); }
template<class T> ostream& operator<<(ostream& os,const set<T>& s) { return osContainer(os,s); }
template<class T> ostream& operator<<(ostream& os,const multiset<T>& s) { return osContainer(os,s); }
template<class T,class S> ostream& operator<<(ostream& os,const map<T,S>& m) { return osContainer(os,m); }
template<class T,class S> ostream& operator<<(ostream& os,const multimap<T,S>& m) { return osContainer(os,m); }
template<class T1,class T2>
ostream& operator<<(ostream& os, const pair<T1,T2>& p){ os << '(' << p.first << ',' << p.second << ')'; return os; }

const int dx[] = {0,1,0,-1};
const int dy[] = {1,0,-1,0};
//}}}

bool edge(int&);
bool round(int&);

string str;

bool check()
{
    int idx = 0;
    bool res = true;

    while(idx < str.length()) {
        if (str[idx] == '(') res = res && round(++idx);
        if (str[idx] == '[') res = res && edge(++idx);
        idx++;
    }

    return res;
}

bool round(int& idx)
{
    bool res = true;
    while(idx < str.length()) {
        if (str[idx] == ')') return true;
        if (str[idx] == '(') res = res && round(++idx);
        if (str[idx] == '[') res = res && edge(++idx);
        idx++;
    }

    return idx >= str.length() ? false : res;
}

bool edge(int& idx)
{
    bool res = true;
    while(idx < str.length()) {
        if (str[idx] == ']') return true;
        if (str[idx] == '(') res = res && round(++idx);
        if (str[idx] == '[') res = res && edge(++idx);
        idx++;
    }

    return idx >= str.length() ? false : res;
}

void solve()
{
    while(getline(cin, str), !(str[0] == '.' && str.length() == 1)) {
        cout << (check() ? "yes" : "no") << endl;
    }
}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout.setf(ios::fixed);
    cout.precision(12);
    solve();
}

C++: #include<cstdio>
#include<iostream>
#include<stack>
using namespace std;

int main(){
  char ch;
  while(1){
    stack<char> S;
    scanf("%c",&ch);
    if(ch=='.')break;
    int i=0;
    bool flag=0;

    while(1){
      if(i!=0)scanf("%c",&ch);
      if(ch=='.')break;
      
      if(ch=='[') S.push('[');
      else if(ch==']'&&S.size()==0)flag=1;
      else if(ch==']'&&S.top()=='[') S.pop();
      else if(ch==']') S.push(']');
      
      if(ch=='(')S.push('(');
      else if(ch==')'&&S.size()==0)flag=1;
      else if(ch==')'&&S.top()=='(') S.pop();
      else if(ch==')')S.push(')');

      i++;
    }

    if(S.size()==0&&flag!=1) cout<<"yes"<<endl;
    else cout<<"no"<<endl;

    scanf("%c",&ch);
  }
  return 0;
}

C++: #include <iostream>
#include <stack>
#include <string>

using namespace std;

int main() {
  while (true) {
    string s;
    getline(cin, s);
    if (s == ".") break;
    string ans = "yes";
    std::stack<char> st;
    for (int i = 0; i < s.size(); ++i) {
      cout << st.size() << endl;
      if (s[i] == '(') {
        st.push('(');
      } else if (s[i] == '[') {
        st.push('[');
      } else if (s[i] == ')') {
        if (st.empty() || st.top() != '(') {
          ans = "no";
        }
        if (!st.empty()) st.pop();
      } else if (s[i] == ']') {
        if (st.empty() || st.top() != '[') {
          ans = "no";
        }
        if (!st.empty()) st.pop();
      }
    }
    if (st.size() != 0) ans = "no";

    cout << ans << endl;
  }
}

C++: #include<bits/stdc++.h>
using namespace std;
main(){
  ios::sync_with_stdio(false);
  string s;
  while(getline(cin,s),s!="."){
    stack<char> a;
    int i=0;
    for(;i<s.size();++i){
      if(!(s[i]-'(')||!(s[i]-'['))a.push(s[i]);
      if(s[i]==')')if(a.empty()||a.top()!='(')break;else a.pop();
      if(s[i]==']')if(a.empty()||a.top()!='[')break;else a.pop();
    }cout<<(i!=s.size()||!a.empty()?"no":"yes")<<endl;
  }
}

C++: #include <iostream>
#include <string>
#include <algorithm>
#include <stack>

using namespace std;

int main()
{
  int end;
  stack <char> sta;

  while(1){
    string v;
    string l;
    string g;
    end = 0;

    while(1){
      cin>>v;
      l = l+v;

      for(auto s : v){
        if(s == '.'){
          end = 1;
          break;
        }
      }

      if(end == 1){
        break;
      }
    }

    if(l == "."){
      break;
    }

    for(auto e : l){
      if(e == '(' || e == '['){
        sta.push(e);
      }
      else if(e == ')'){
        auto t = sta.top();
        sta.pop();
        if(t != '('){
          g = "no";
          break;
        }
      }
      else if(e == ']'){
        auto t = sta.top();
        sta.pop();
        if(t != '['){
          g = "no";
          break;
        }
      }
    }

    if(g != "no"){
      g = "yes";
    }

    cout<<g<<endl;
  }
  return 0;
}