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;

typedef long long ll;


char str[104];

int main(){
    while(1){
        stack<int> st;
        bool judge = true;

        for(int i=0;i<100;i++){
            cin.get(str[i]) ;
            if(str[i]== '\n' && str[i-1]=='.') break;
        }
        if(str[0]=='.')break;
    
        int i=0;
        while(str[i] != '.'){
            if(str[i]=='(' || str[i]=='['){
                st.push(str[i]);
            }else if(!st.empty()){
                if(str[i]==')'){
                    if(st.top() == '('){
                        st.pop();
                    }else{
                        judge = false;
                    }
                }else if(str[i]==']'){
                    if(st.top() == '['){
                        st.pop();
                    }else{
                        judge = false;
                    }
                }
            }else if(st.empty()){
                if(str[i]==')' || str[i]==']') judge = false;
            }
            if(judge==false){
                break;
            }
            i++;
        }
        if(!st.empty()){
            judge = false;
        }
        if(judge){
            printf("yes\n");
        }else{
            printf("no\n");
        }
    }

}

C++: #include <iostream>
#include <string>
#include <sstream>
#include <algorithm>
#include <vector>
#include <utility>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <ctime>
#include <cstdlib>
#include <map>
#include <set>
#include <stack>
#include <queue>
 
using namespace std;
 
#define pb(n)	push_back(n)
#define mp(n,m) make_pair(n,m)
#define fi 	first
#define se 	second
#define all(r) (r).begin(),(r).end()
 
#define REP(i,s,e)	for(int i=(s); i<(e); i++)
#define rep(i,n)	REP(i,0,n)
#define REPE(i,s,e)	for(int i=s; i>e; i--)
#define repe(i,n)	REPE(i,n,-1)


typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
 
typedef vector<vi> vvi;
 
const int IMAX=((1<<30)-1)*2+1;
const int INF=100000000;
const double EPS=1e-10;
//int mod=1000000007
 

int main(){
	string s;
	while(getline(cin,s)){
		if(s==".") break;
		stack<char> st;
		bool flag = true;
		for(char c:s){
			if(c == '(' || c == '[') st.push(c);
			else if(c ==' )' || c == ']') {
				char d = st.top();
				st.pop();
				if(st.empty() || c != d + 1){
					flag =false;
					break;
				}
			} 
		}
		cout<<(flag?"yes":"no")<<endl;
	}
}

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

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

using namespace std;

string s;
int p;

bool check()
{
	bool ret = true;
	while (s[p] != '.' && s[p] != ')' && s[p] != ']')
	{
		char c = s[p++];
		if (c == '(' || c == '[')
		{
			char end = c == '(' ? ')' : ']';
			ret = check();
			if (s[p] == end) p++;
			else ret = false;
		}
		if (!ret) break;
	}
	return ret;
}

bool checkall()
{
	p = 0;
	bool ret = check();
	ret = ret && s[p] == '.';
	return ret;
}

int main()
{
	while(getline(cin, s), s[0] != '.')
	{
		cout << (checkall() ? "yes" : "no") << endl;
	}
}

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

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

const int ma=3e6;
int ispr[ma];

int su[ma];


string in;

void solve(){
  stack<char> st;
  for(auto c:in){
    auto p = string("()[]").find(c);
    if( p == string::npos) continue;
    //cout << p << endl;
    if(p%2==0){
      st.push(c);
      continue;
    }
    
    if(st.empty()){
      cout << "no" << endl;
      return;
    }
    
    char c2 = st.top();
    st.pop();
    
    if(string("()[]").find(c2)+1==p) continue;
    
    cout << "no" << endl;
    return;
  }
  
  if(!st.empty())
    cout << "no" << endl;
  else
    cout << "yes"<< endl;
}

int main(){
  while(getline(cin,in) , in != ".") solve();
  
}

C++: #include <bits/stdc++.h>
using namespace std;
#define N_PRIME 1000000007
#define ll int64_t

void solve(){
    string s;
    getline(cin,s);
    if( s==".")exit(0);
    stack<int> t;
    
    
    for(int i = 0 ; i < s.size() ; i++ ){
        if( s[i] == '(' ){
            t.push(0);
        }else if( s[i] == '[' ){
            t.push(1);
        }else if( s[i] == ')' ){
            if( t.size() == 0 || t.top() != 0 ){
                cout << "no" << endl;
                return ;
            }else{
                t.pop();
            }
        }else if( s[i] == ']' ){
            if( t.size() == 0 || t.top() != 1 ){
                cout << "no" << endl;
                return ;
            }else{
                t.pop();
            }
        }
    }
    
    if( t.size() > 0 ){
        cout << "no" << endl;
    }else{
        cout << "yes"<<endl;
    }
    return ;
}
int main(void){
    while(true)solve();
    return 0;
}

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

typedef long long int ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<pair<int, int> > vii;
#define rrep(i, m, n) for(int (i)=(m); (i)<(n);  (i)++)
#define erep(i, m, n) for(int (i)=(m); (i)<=(n); (i)++)
#define  rep(i, n)    for(int (i)=0; (i)<(n);  (i)++)
#define rrev(i, m, n) for(int (i)=(n)-1; (i)>=(m); (i)--)
#define erev(i, m, n) for(int (i)=(n); (i)>=(m); (i)--)
#define  rev(i, n)    for(int (i)=(n)-1; (i)>=0; (i)--)
#define vrep(i, c)    for(__typeof((c).begin())i=(c).begin(); i!=(c).end(); i++)
#define  ALL(v)       (v).begin(), (v).end()
#define pb            push_back
template<class T, class S> inline pair<T, S> mp(T x, S y){ return make_pair(x, y); }
template<class T, class S> inline bool minup(T& m, S x){ return m>(T)x ? (m=(T)x, true) : false; }
template<class T, class S> inline bool maxup(T& m, S x){ return m<(T)x ? (m=(T)x, true) : false; }

static const int    INF = 1000000000;
static const ll     MOD = 1000000007LL;
static const double EPS = 1E-12;

string s;

int main()
{
  while(getline(cin, s) && s != "."){
    stack<char> st;
    vrep(v, s){
      if(*v == '(' || *v == '[') st.push(*v);
      if(*v == ')' || *v == ']'){
        if(st.empty()){
          st.push('(');
          break;
        }
        if(st.top() == '(' && *v == ')'){ st.pop();  continue; }
        if(st.top() == '[' && *v == ']'){ st.pop();  continue; }
      }
    }
    puts(st.empty() ? "yes" : "no");
  }

  return 0;
}