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++: /* 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();
bool round();
int idx;

string str;

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

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

    return res;
}

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

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

bool edge()
{
    bool res = true;
    while(res && idx < str.length()) {
        if (str[idx] == ']'){
            return true;
        }
        else if (str[idx] == ')') {
            return false;
        }
        else if (str[idx] == '(') {
            idx++;
            res = res && round();
        }
        else if (str[idx] == '['){
            idx++;
            res = res && edge();
        }
        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 <iostream>
#include <string>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <map>
#include <stack>
#include <cmath>
using namespace std;

int main(void)
{
	string str;
	while(getline(cin, str) && str != "."){
		bool flag = true;
		stack<char> st;
		for(int i = 0; i < str.size(); i++){
			if(str[i] == '(' || str[i] == '[') st.push(str[i]);
		
			if(str[i] == ']'){
				if(st.size() != 0 && st.top() == '[') st.pop();
				else { flag = false; break; }
			}
			if(str[i] == ')'){
				if(st.size() != 0 && st.top() == '(') st.pop();
				else { flag = false; break; }
			}
		}
		if(flag) cout << "yes" << endl;
		else cout << "no" << endl;
	}
	return 0;
}

C++: #include"iostream"
#include"fstream"
#include"stack"
#include"string"

using namespace std;

int main(){

	//http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=1173&lang=jp
	
	ifstream fin;
	ofstream fout;

	fin.open("input.txt");
	fout.open("output.txt");

	//http://www.cppll.jp/cppreference/cppstack_details.html
	//empty()関数は現在のスタックが空の時にtrueを返し、そうでないときはfalseを返す 

	string a;

	stack<char> s;
	bool yes = true;

	while (true){
		yes = true;

		getline(cin, a);

		//		cout << a << endl;

		if (a[0] == '.')break;


		for (int i = 0; i < 100; i++){
			if (a[i] == '(' || a[i] == '['){
				s.push(a[i]);
				yes = false;
			}
			if (a[i] == ')' && !s.empty()){
				if (s.top() == '('){
					yes = true;
					s.pop();
				}
				else break;
			}
			if (a[i] == ']' && !s.empty()){
				if (s.top() == '['){
					yes = true;
					s.pop();
				}
				else break;
			}
			//			if (!s.empty())
			//				cout << a[i] << "  :  " << s.top() << "  :  " << yes << endl;
			//			else cout << "topエラー" << endl;

			if (a[i] == '.')break;
		}

		if (yes == true){
			//			cout << "yes" << endl;
			cout << "yes" << endl;
		}
		else{
			//			cout << "no" << endl;
			cout << "no" << endl;
		}
		while (!s.empty())s.pop();
	}
	return 0;
}

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

using namespace std;

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

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

using namespace std;

int main(void){

  string s;
  stack <string> st;
  string::iterator it;
  
  while(1){
    
    cin>>s;
    it=s.end();
    it--;
    if(s.size()==1&&*it=='.')
      break;
  
    for(it=s.begin();it!=s.end();it++){

      if(*it=='('){
	st.push("(");
      }

      else if(*it=='['){
	st.push("[");
      }

      else if(*it==')'){
	if(st.empty())
	  st.push(")");
	
	if(st.top()=="(")
	  st.pop();
	else
	  st.push(")");
      }

      else if(*it==']'){
	if(st.empty())
	  st.push("]");
	
	if(st.top()=="[")
	  st.pop();
	else
	  st.push("]");
      }
    }

    if(st.empty())
      cout <<"yes"<<endl;

    else
      cout <<"no"<<endl;

    while(!st.empty()){
      st.pop();
    }
    
  }
  return 0;

}