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
//------------------------------------------
#include <vector>
#include <list>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <fstream>
#include <complex>
#include <math.h>

using namespace std;

//conversion
//------------------------------------------
inline long toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
inline long toLong(string s) {long v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}

//math
//-------------------------------------------
template<class T> inline T sqr(T x) {return x*x;}

//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef pair<long, long> PLL;
typedef long long LL;
//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())

//repetition
//------------------------------------------
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)

//constant
//--------------------------------------------

//clear memory
#define CLR(a) memset((a), 0 ,sizeof(a))

const long double EPS = 1e-12;
const int INF = 10000;


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

C++: #include <iostream>
#include <stack>
using namespace std;
void startstack(stack<int> &st){
  st.empty();
  st.push(0);
}
void clear(string &tmp){
  int j;
  do{
    for(j=0;tmp[j];j++);
    if(tmp[--j]=='.') break;
  }while(getline(cin,tmp));
}
int main(){
  int i,j;
  stack<int> st;
  string tmp;
  startstack(st);
  getline(cin,tmp);
  while(tmp!="."){
    for(i=0;tmp[i];i++){
      if(tmp[i]=='('||tmp[i]=='['){
	st.push(tmp[i]);
      }
      if(tmp[i]==']'){
	if(st.top()=='[') st.pop();
	else {startstack(st);
	  cout <<"no\n";
	  clear(tmp);
	  break;}
      }
      if(tmp[i]==')'){
	if(st.top()=='(') st.pop();
	else {startstack(st);
	  clear(tmp);
	  cout <<"no\n";
	  break;
	}
      }
      if(tmp[i]=='.'){
	if(st.top()==0) {cout <<"yes\n";
	  startstack(st);}
	else {
	  cout <<"no\n";
	  startstack(st);
	  break;}
      }
    }
    getline(cin,tmp);
  }
      return 0;
}

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

using namespace std;

int main(){

	string str;

	while(1){
		getline(cin,str);
		stack<int> data;
		if(str.at(0)=='.')break;

		int flag=0;
	
		for(int i=0;i<str.size();i++){

		if(str.at(i) =='('){
			data.push(1);
		}

		if(str.at(i) == '['){
			data.push(2);
		}

		if(str.at(i) ==')'){
			if(data.size()==0){
				cout<<"no"<<endl;
				flag=1;
			}
			else if(data.top() != 1){
				cout<<"no"<<endl;
				flag=1;
			}
			else{
				data.pop();
			}
		}
		if(str.at(i) == ']'){
			if(data.size()==0){
				cout<<"no"<<endl;
				flag=1;
			}
			else if(data.top() != 2){
				cout<<"no"<<endl;
				flag=1;
			}
			else{
				data.pop();
			}
		}

		if(flag==1)break;
		}

		if(flag==1)continue;

		if(data.size()!=0){
			cout<<"no"<<endl;
			continue;
		}

		cout<<"yes"<<endl;
	}

	return 0;
}

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

using namespace std;

int main(void){
  string s;
  stack<char> str;

  while(getline(cin,s) && s!="."){
    bool flag = true;
    string ch;
    for(int i=0;i<s.size();i++)
      if(s[i]=='{' || s[i]=='(' || s[i]=='}' || s[i]==')')ch+=s[i];

    for(int i=0;i<ch.length();i++){
      
      if(str.empty() || ch[i]=='(' || ch[i]=='{')str.push(ch[i]);
      else if(ch[i]==')' && str.top()=='(')str.pop();
      else if(ch[i]=='}' && str.top()=='}')str.pop();
      else {
	flag = false;
	break;
      }
    }

    cout << (flag && str.empty()?"YES":"NO") << endl;

  }

  return 0;
}

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

#define rep(i,a) for(int i = 0 ; i < a ; i ++)
int main(void){
  string s;
  while(getline(cin,s),s!="."){
    int c,b;
    c = b = 0;
   // cout<<s.size()<<" "<<s<<endl;
    string n = "";
    bool f = true;
    rep(i,s.size()){
     // cout<<s[i];
      if(s[i] == '(')c++;
      if(s[i] == ')'){
        c--;
        if(c < b){
          f = false;
          break;
        }
        //cout<<"c"<<c<<" "<<b<<endl;
//        cout<<i<<" "<<s[i]<<" "<<c<<" "<<b<<endl;
      }
      if(s[i] == '[')b++;
      if(s[i] == ']'){
        b--;
        if(c < b){
//          cout<<c<<" "<<b<<endl;
          f = false;
          break;
        }
        //cout<<"b"<<c<<" "<<b<<endl;
         
        
      }
      //cout<<b<<" "<<c<<endl;
      if(b<0 || c<0){
        f = false;
        break;
      }
    }
    cout<<(f?"yes":"no")<<endl;
    //cout<<s<<endl;
  }
}

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

int main (){

	string a;
	bool IsOk = true; int LeftKakko = 0; int LeftKulo = 0; bool b = false; bool IsFinish = false;
	vector<int> v;
	while (cin >> a){
		if (IsFinish==true&&a == "."){
			if (b == false){
				b = true;
			}
			else{
				return 0;
			}
		}else{
			b = false;
			IsFinish = false;
		}
		for (unsigned int i = 0; i < a.length(); ++i){
			if (a[i] == 40){//(
				LeftKakko++;
				v.push_back(1);
			}
			else if (a[i] == 41){//)
				if (LeftKakko == 0||v.back()!=1){
					IsOk = false;
				}
				else{
					LeftKakko--;
					v.pop_back();
				}
			}
			else if (a[i] == 91){//[
				LeftKulo++;
				v.push_back(0);
			}
			else if (a[i] == 93){//]
				if (LeftKulo == 0||v.back()!=0){
					IsOk = false;
				}
				else{
					LeftKulo--;
					v.pop_back();
				}
			}
			else if (a[i] == 46){//.
				if (LeftKakko != 0 || LeftKulo != 0||v.empty()==false){
					IsOk = false;
				}
				if (IsOk == true){
					cout << "yes"<<endl;
				}
				else{
					cout << "no"<<endl;
				}
				IsOk = true; LeftKakko = 0; LeftKulo = 0; v.clear(); IsFinish = true;
			}
		}
	}
	return 0;
}