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<cstring>
#include<vector>
using namespace std;

int main()
{
  char n[200];
  for(;cin.getline(n,sizeof(n));)
    {
      if(n[0]=='.')
	break;
      int a=0;
      int b=0;
      bool check=true;
      char tmp='\0';
       for(int i=0;n[i]!='\0';i++)
	{
	  if(n[i]=='(')
	    {
	      a++;
	      tmp=n[i];
	    }
	  else if(n[i]==')')
	    {
	    a--;
	    if(tmp=='[')
	      check=false;
	    tmp=n[i];
	    }
	  if(a<0)
	    check=false;
	  if(n[i]=='[')
	    {
	      b++;
	      tmp=n[i];
	    }
	  else if(n[i]==']')
	    {
	      b--;
	      if(tmp=='(')
		check=false;
	      tmp=n[i];
	    }
	  if(b<0)
	    check=false;



	  //	  cout<<"n="<<n<<"a="<<a<<"b="<<b<<endl;
	}
      if(a!=0 || b!=0)
	check=false;
      if(check)
	cout<<"yes"<<endl;
      else
	cout<<"no"<<endl;
    }
}

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

int main()
{
	//string tmp;
	char tmp[105];
	while(1)
	{
		//cin>>tmp;
		gets(tmp);
		if(tmp[0]=='.') break;
		else
		{
			bool flag=true;
			stack<char> s;
			for(int i=0;tmp[i]!='.';i++)
			{
				char top=' ';
				if(!s.empty()) top=s.top();
				if(tmp[i]=='('||tmp[i]=='[') s.push(tmp[i]);
				else if(top=='('&&tmp[i]==')') s.pop();
				else if(top=='['&&tmp[i]==']') s.pop();
				else if(tmp[i]==')'||tmp[i]==']') {flag=false; break;}
			}

			if(!s.empty()) flag=false;

			cout<<(flag?"yes":"no")<<endl;
		}
	}
	return 0;
}

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

using namespace std;

#define DEBUG(x) cerr << #x << " = " << x << endl

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

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

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 DECIM8  fixed<<setprecision(8) 
#define SZ(a) int((a).size())
#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
//--------------------------------------------
const double EPS = 1e-10;
const double PI  = acos(-1.0);

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

using namespace std;
string s;
int c=0;
bool balance(void){
  if(c<SZ(s) && s[c]=='('){
    ++c;
    bool flag=balance();
    if(c<SZ(s) && s[c]==')'){
      ++c;
      return flag&&balance();
    }
    else return false;
  }
  if(c<SZ(s) && s[c]=='['){
    ++c;
    bool flag=balance();
    if(c<SZ(s) && s[c]==']'){
      ++c;
      return flag&&balance();
    }
    else return false;
  }
  if(c<SZ(s) && s[c]!='(' && s[c]!=')' && s[c]!='[' && s[c]!=']'){
    ++c;
    return balance();
  }
  return true;
}
int main(void)
{
  for(;;){
    getline(cin,s);
    if(s==".") return 0;
    c=0;
    if(balance()&&c==SZ(s)) cout << "yes" << endl;
    else cout << "no" << endl;
  }
}

C++: 
#include <iostream>
#include <cstdlib>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <stack>
#include <cctype>
#include <complex>
#include <vector>
#include <set>
#include <map>
#include <algorithm>
#include <functional>
#include <cassert>

using namespace std;


bool solve(){
	string str;

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

int main(){
	cout.setf(ios::fixed);
	cout.precision(10);
	solve();

	return 0;
}

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

// Shrotening
#define fst first
#define snd second
#define pb push_back
#define mp std::make_pair

// Loop
#define FOR(i,a,b) for(auto i=(a);i<(b);++i)
#define RFOR(i,a,b) for(auto i=(a);i>=(b);--i)

#define REP(i,a) for(long i=0;i<(a);++i)
#define RREP(i,a) for(long i=(a);i>=0;--i)

#define EACH(i,a) for(auto (i)=(a).begin(),_END=(a).end();i!=_END;++i)
#define REACH(i,a) for(auto (i)=(a).rbegin(),_END=(a).rend();i!=_END;++i)

//Algorithm
#define ALL(a) (a).begin(), a.end()
#define RALL(a) (a).rbegin(), a.rend()
#define EXIST(a,x) ((a).find(x)!=(a).end())
#define SORT(a) std::sort((a).begin(), (a).end())
#define UNIQUE(a) std::sort((a).begin(), a.end()), a.erase(std::unique((a).begin(), a.end()), a.end());
#define SUM(a) std::accumulate((a).begin(), (a).end(), 0);

//Setting
#define OPT std::cin.tie(0);std::ios::sync_with_stdio(false);

//debug message
bool debug = true;
#define MSG(s)   if(debug){std::cout << s << std::endl;}
#define DEBUG(x) if(debug){std::cout << "debug(" << #x << "): " << x << std::endl;}

//alias
typedef long long LL;
typedef std::pair<int,int> PII;

typedef std::vector<char> VC;
typedef std::vector<int>  VI;
typedef std::vector<long> VL;
typedef std::vector<long long> VLL;
typedef std::vector<PII> VPII;

typedef std::vector< VC > VC2;
typedef std::vector< VI > VI2;
typedef std::vector< VL > VL2;
typedef std::vector< VLL > VLL2;

std::string s;
int main() {
    while(std::getline(std::cin, s)) {
        if(s == ".") break;
        
        std::stack<char> stack;
        bool f = true;
        for(auto c: s) {
            if(c == '(' || c == '[') {
                stack.push(c);
            } else if(c == ')' || c == ']') {
                if(stack.empty()) {
                    f = false;
                    break;
                }

                char left = stack.top();
                stack.pop();
                if( (left == '(' && c == ')') || (left == '[' && c == ']') ) {
                    continue;
                } else {
                    f = false;
                    break;
                }
            }
        }

        std::cout << ( (f && stack.empty()) ? "yes" : "no") << std::endl;
    }
}