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(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);
        else 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;
        }
        else if (str[idx] == '(') res = res && round(++idx);
        else 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;
        }
        else if (str[idx] == '(') res = res && round(++idx);
        else 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 <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <utility>
#include <cstring>
#include <cmath>
#include <queue>
#include <map>
#include <set>
using namespace std;

#define rep(i,n) for(int i=0; i<n; i++)
#define FOR(i,s,n) for(int i=s; i<n; i++)
#define ALL(x) x.begin(), x.end()
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef vector<int> vi;

int main() {
	string in;
	while(getline(cin, in), in!=".") {
		string stk = "";
		rep(i, in.length()) {
			if( in[i] == '(' ) {
				stk += ')';
			} else if( in[i] == '[' ) {
				stk += ']';
			}
			else if( stk.length()>0 && stk[stk.length()-1] == in[i] ) {
				stk = stk.substr(0, stk.length()-1);
			}
		}
		cout << (stk.length() == 0 ? "yes" : "no") << endl;
	}
	return 0;
}

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

using namespace std;

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

  while(1){
    string v;
    string t;
    end = 0;

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

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

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

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

    for(auto e : t){
      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"){
    }
    else{
      g = "yes";
    }

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

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

using namespace std;

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

  while(getline(cin,s) && s!="."){

    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(ch[i]=='(' || ch[i]=='[')str.push(ch[i]);
      if(ch[i]==')' && str.top()=='(')str.pop();
      if(ch[i]==']' && str.top()==']')str.pop();
    }

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

  }

  return 0;
}

C++: #include<stdio.h>
#include<iostream>
#include<string>
using namespace std;

int main(){

	bool F=true;
while(1){char str[250]={},ch;
	for(int i=1;i<245;i++)
	{scanf("%c",&ch);if(ch==EOF){F=false;break;}
	if(ch=='.')break;
	str[i]=ch;}
	if(F==false)break;
	int ks=0,kl=0,ms=0,ml=0;
	bool f=true;
	for(int i=0;i<200;i++)
	{if(str[i]=='(')ms++;
	else if(str[i]=='[')ks++;
	else if(str[i]==')'){ml++;if(ms==0){f=false;}}//cout<<i<<" ";}
	else if(str[i]==']'){kl++;if(ks==0)f=false;}
	}
	if(f!=false&&ms==ml&&ks==kl)cout<<"yes"<<endl;
	else{cout<<"no"<<endl;//ms<<ml<<ks<<kl<<endl;
	}

}


return 0;
}

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

using namespace std;


string words;

void solve(){
  stack<char> st;
  for(int i = 0; i < words.size();i++){
    if(words[i] == '(' || words[i] == '['){
      st.push(words[i]);
    }else if(words[i] == ')'){
      if(!st.empty()){
        if(st.top() == '('){
          st.pop();
        }else{
          cout << "no" << endl;
          return;
        }
      }else{
        cout << "no" << endl;
        return;
      }
    }else if(words[i] == ']'){
      if(!st.empty()){
        if(st.top() == '['){
          st.pop();
        }else{
          cout << "no" << endl;
          return;
        }
      }else{
        cout << "no" << endl;
        return;
      }
    }
  }
  if(st.empty()) cout << "yes" << endl;
  return;
}




int main(){
  while(true){
    words = "";
    getline(cin , words);
    if(words[0] == '.') break;
    solve();
  }
  return 0;
}

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

int main(){
  string str;
  stack<char> s;
  int f;
  while(1){
    f=0;
    getline(cin,str);

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

    for(int i=0;i<str.size();i++){
      if(str[i]=='(' || str[i]=='[') s.push(str[i]);
      else if(str[i]==')' || str[i]==']'){
	if( s.empty()!=1 && str[i]==')' && s.top()=='(') s.pop();
	else if(s.empty()!=1 && str[i]==']' && s.top()=='[') s.pop();
	else f=1;
		    } 
    }

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