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++: // 2013/06/20 Tazoe

#include <iostream>
#include <string>
#include <stack>
using namespace std;

int main()
{
	while(true){
		string S;
		getline(cin, S);

		if(S==".")
			break;

		stack<char> stk;

		bool flg = true;
		for(int i=0; i<S.size(); i++){
			if(S[i]=='('||S[i]=='['){
				stk.push(S[i]);
			}
			else if(S[i]==')'){
				if(!stk.empty()&&stk.top()=='('){
					stk.pop();
				}
				else{
					flg = false;
				}
			}
			else if(S[i]==']'){
				if(!stk.empty()&&stk.top()=='['){
					stk.pop();
				}
				else{
					flg = false;
				}
			}

			if(!flg)
				break;
		}

		if(flg&&stk.empty()){
			cout << "yes" << endl;
		}
		else{
			cout << "no" << endl;
		}
	}

	return 0;
}

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

enum { OPEN = 1, CLOSE = 2 };
int bracket[128];
char match[128];

string str;
int idx;

char getc() { return idx < str.size() ? str[idx] : '#'; }
void expr() {
	while(bracket[getc()] == OPEN) {
		const char c = getc();
		++idx;
		expr();
		if(match[c] != getc()) throw "parse error!";
		++idx;
	}
}

bool parse() {
	try {
		idx = 0;
		expr();
		return idx == str.size();
	} catch(const char * s) {
		return false;
	}
}

int main() {
	bracket['('] = bracket['['] = OPEN;
	bracket[')'] = bracket[']'] = CLOSE;
	match['('] = ')';
	match['['] = ']';

	const auto rm = [&](char c) { return !bracket[c]; };
	while(getline(cin, str) && str != ".") {
		str.erase(remove_if(begin(str), end(str), rm), end(str));
		cout << (parse() ? "yes" : "no") << endl;
	}

	return EXIT_SUCCESS;
}

C++: #include <bits/stdc++.h>

using namespace std;
typedef long long ll;

#define rep(i, n) for(int i=0; i<(n); ++i)

bool isBalancedS(const string &s) {
    int cnt = 0;
    rep(i, s.size()) {
        if(s[i] == '[') cnt++;
        if(s[i] == ']') cnt--;
        if(cnt < 0) return false;
    }
    if(cnt > 0) return false;
    return true;
}
bool isBalancedR(const string &s) {
    int cnt = 0;
    rep(i, s.size()) {
        if(s[i] == '(') cnt++;
        if(s[i] == ')') cnt--;
        if(cnt < 0) return false;
    }
    if(cnt > 0) return false;
    return true;
}

bool isBalanced(const string &s) {
    if(!isBalancedS(s)) return false;
    if(!isBalancedR(s)) return false;
    // check substring
    for(int i=0; i<s.size(); ++i) {
        if(s[i] == '(') {
            int len = 0;
            int cnt = 1;
            for(int j=i+1; j<s.size(); ++j, ++len) {
                if(s[j] == '(') cnt++;
                if(s[j] == ')') cnt--;
                if(cnt==0) break;
            }
            if(!isBalancedS(s.substr(i+1, len))) return false;
        } else if(s[i] == '[') {
            int len = 0;
            int cnt = 1;
            for(int j=i+1; j<s.size(); ++j, len++) {
                if(s[j] == '[') cnt++;
                if(s[j] == ']') cnt--;
                if(cnt==0) break;
            }
            if(!isBalancedR(s.substr(i+1, len))) return false;
        }
    }
    return true;
}

int main(void){
    string s;
    while(getline(cin, s) && s!=".") {
        if(isBalanced(s)) cout << "yes" << endl;
        else cout << "no" << endl;
    }
}

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


int main(){
	while(1){
		string s;
		getline(cin,s);
		//cout<<s<<endl;
		if(s[0]=='.')break;
		stack<int> st;
		bool flag = true;
		for(int i=0;i<s.size();i++){
		if(s[i]=='(')st.push(1);
		if(s[i]=='[')st.push(2);
		if(s[i]==')'){
			if(st.empty()|| st.top()!=1) {
				flag = false;
				break;
			}
			else st.pop();
		}
		if(s[i]==']'){
			if(st.empty()|| st.top()!=2) {
				flag = false;
				break;
			}
			else st.pop();
		}


		}
		if(st.size()!=0)flag = false; 
		if(flag) cout<<"yes"<<endl;
		else 	cout<<"no"<<endl;
	}

	return 0;
}

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

int main(){
  stack <char> ch;
  string str;
  while( getline(cin,str) ){
    if( str == "." ) break;
    int i,flag = 0;
    int len = str.size();
    for( i = 0; i < len; i++ ){

      if( str[i] == '(' ) ch.push(str[i]);
      if( ch.empty() ) flag = 1;
      else if( ch.top() == '(' && str[i] == ')' ) ch.pop();

      if( str[i] == '[' ) ch.push(str[i]);
      if( ch.empty() ) flag = 1;
      else if( ch.top() == '[' && str[i] == ']' ) ch.pop();
      
    }

    if( ch.empty() ) flag = 0;

    if( flag == 0 ) cout << "yes" << endl;
    else cout << "no" << endl;

    while(1){
      if( ch.empty() ) break;
      ch.pop();
    }

  }

  return 0;
}

C++: #include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
#define loop(i,s,n) for(int i=s;i<n;i++)
#define all(in) in.begin(), in.end()
#define rep(i,n) for(int i=0;i<n;i++)
#define loop(i,s,n) for(int i=s;i<n;i++)
#define all(in) in.begin(), in.end()
#define MP make_pair
#define INF (sizeof(int) == 4 ? 1e9:1e18)
#define EPS 0.0000000001
using namespace std;
template<class T, class S> void cmin(T &a, const S &b) { if (a > b)a = b; }
template<class T, class S> void cmax(T &a, const S &b) { if (a < b)a = b; }
template<typename Head, typename Value> auto vectors(const Head &head, const Value &v) { return vector<Value>(head, v); }
template<typename Head, typename... Tail> auto vectors(Head x, Tail... tail) { auto inner = vectors(tail...); return vector<decltype(inner)>(x, inner); }
template<class T> void join(T a){int b=0;for(auto itr :a){if(b++!=0)cout << " "; cout << itr;} }
using ll  = long long;
using ld  = long double;
using pii = pair<int,int>;
using piii = pair<int,pii>;
int W,H;
int dx[]={0,0,1,-1}, dy[]={1,-1,0,0};
bool valid(int x,int y){return (0<=x&&x<W)&&(0<=y&&y<H);}
#define int ll
signed main(){
    string s;
    while(getline(cin,s),s!="."){
        bool flag = true;
        stack<char>st;
        rep(i,s.size()){
            if(s[i] == '(' || s[i] == '['){
                st.push(s[i]);
                continue;
            }
            if(s[i] == ')' || s[i] == ']'){
                if(st.empty())flag = false;
                else if(st.top() == '(' && s[i] == ')'){
                    st.pop();
                    continue;
                }else if(st.top() == '[' && s[i] == ']'){
                    st.pop();
                    continue;
                }else flag = false;
            }
        }
        cout << (flag && st.empty() ?  "yes":"no") << endl;
    }
}

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

int main(){
  string str;
  stack<char> s;
  while(1){
    getline(cin,str);
    if(str[0]=='.') break;
    for(int i=0;i<str.size();i++){
      if(str[i]=='[' || str[i]== '(') s.push(str[i]);
      if(s.empty()!=1){
      if( (str[i]==']' && s.top()=='[')||  (str[i]==')'&& s.top()=='('))s.pop();
      }
 else if(str[i]==']' || str[i]==')') s.push(str[i]);

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