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 <iostream>
#include <cstdio>
#include <iomanip>

#include <vector>
#include <map>
#include <set>
#include <queue>
#include <bitset>
#include <stack>
#include <utility>

#include <numeric>
#include <algorithm>
#include <functional>

#include <cctype>

#include <complex>
#include <string>
#include <sstream>

using namespace std;

#define all(c) c.begin(),c.end()
#define rall(c) c.rbegin(),c.rend()
#define rep(i,n) for(unsigned int i=0;i<(n);i++)
#define tr(it,container) for(typeof(container.begin()) it = container.begin(); \
                                                  it != container.end(); ++it)
#define mp(a,b) make_pair((a),(b))

typedef long long ll;
typedef complex<double> P;
const int dx[] = {1,0,-1,0};
const int dy[] = {0,-1,0,1};
const double EPS = 1e-9;
const int days[] = {31,28,31,30,31,30,31,31,30,31,30,31};
const int daysleap[] = {31,29,31,30,31,30,31,31,30,31,30,31};

stringstream ss;

// ([ (([( [ ] ) ( ) (( ))] )) ])
int main(){
    string s;
    while(getline(cin,s) && s != "."){
        string ss;
        stack<char> S;
        bool ok = true;
        for(int i=0;i<s.length();i++){
            switch(s[i]){
                case '(':
                    S.push(')');
                    break;
                case '[':
                    S.push(']');
                    break;
                case ')':
                    if(!S.empty() and S.top() == ')'){
                        S.pop();
                    }else{
                        ok = false;
                    }
                    break;
                case ']':
                    if(!S.empty() and S.top() == ']'){
                        S.pop();
                    }else{
                        ok = false;
                    }
                    break;
            }
        }
        if(ok && S.empty()) cout << "yes" << endl;
        else cout << "no" << endl;
    }
    return 0;
}

C++: #include<bits/stdc++.h>
using namespace std;
main(){
  string s;
  while(getline(cin,s),s!="."){
    stack<char> a;
    int i=0;
    for(;i<s.size();++i){
      if(!(s[i]-'(')||!(s[i]-'['))a.push(s[i]);
      if(s[i]==')')if(a.empty()||a.top()!='(')break;else a.pop();
      if(s[i]==']')if(a.empty()||a.top()!='[')break;else a.pop();
    }cout<<(i!=s.size()||!a.empty()?"no":"yes")<<endl;
  }
}

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

int main()
{
    int tail,c1,c2;
    char str[102];
    int f[102]={0};
    char *s;
    while(true)
    {
        tail=1;
        cin>>str;
        if(str[0]=='.') break;
        s=str;
        c1=0; c2=0;
        for(;!(*s == '.');s++)
       {
            if(*s=='(') f[tail++]=1;
            if(*s=='[') f[tail++]=2;
            if(*s==')') if(!(f[--tail]==1)) break;
            if(*s==']') if(!(f[--tail]==2)) break;
        }
        if(tail==1 && *s == '.') cout<<"yes"<<endl;
        else cout<<"no"<<endl;
    }
    return 0;
}

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

using namespace std;

int main(void){
	string str;

	while(getline(cin,str)){
		
		stack<char> st;
		bool flag=true;
		
		if(str[0]=='.'){
			break;
		}
		
		for(int i=0;i<str.size();i++){
			
			if(str[i]=='.'){
                           break;          
                        }                        

                        if(str[i]=='('|| str[i]=='['){
				st.push(str[i]);
			}
						
			else if(str[i]==')'){
				if(st.empty()){
					flag=false;
				}
				else if('('==st.top()){
					st.pop();
				}
			}
			
			else if(str[i]==']'){
				if(st.empty()){
					flag=false;
				}
				else if('['==st.top()){
					st.pop();
				}
			}
		}
		
		if(flag && st.empty()){
			cout<<"yes"<<endl;
		}
		else{
			cout<<"no"<<endl;
		}

		
	}
}

C++: #include <algorithm>
#include <cmath>
#include <climits>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <fstream>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
#include <cassert>
#include <functional>

using namespace std;

#define LOG(...) printf(__VA_ARGS__)
//#define LOG(...)
#define FOR(i,a,b) for(int i=(int)(a);i<(int)(b);++i)
#define REP(i,n) for(int i=0;i<(int)(n);++i)
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(),(a).rend()
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())
#define RSORT(c) sort((c).rbegin(),(c).rend())
#define CLR(a) memset((a), 0 ,sizeof(a))

typedef long long ll;
typedef unsigned long long ull;
typedef vector<bool> vb;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<vb> vvb;
typedef vector<vi> vvi;
typedef vector<vll> vvll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

const int dx[] = { -1, 0, 1, 0 }; const int dy[] = { 0, 1, 0, -1 };

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