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 <iomanip>
#include <sstream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <algorithm>
#include <functional>
#include <utility>

using namespace std;

typedef unsigned int ui;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int,int> PII;

const int INF = INT_MAX / 4;

#define REP( i, m, n ) for ( int i = (int)( m ); i < (int)( n ); i++ )
#define UREP( i, m, n ) for ( ui i = (ui)( m ); i < (ui)( n ); i++ )
#define EACH( v, c ) for ( __typeof( c.front() ) &v : c )

#define ITER( c ) __typeof( (c).begin() )
#define IREP( c, it ) for ( ITER(c) it = c.begin(); it != c.end(); ++it )
#define ALL( c ) (c).begin(), (c).end()
#define RALL( c ) (c).rbegin(), (c).rend()

#define PB( n ) push_back( n )
#define MP( a, b ) make_pair( ( a ), ( b ) )
#define EXIST( c, e ) ( (c).find( e ) != (c).end() )

#define fst first
#define snd second

#define DUMP( x ) cerr << #x << " = " << ( x ) << endl
#define DEBUG( x ) cerr << __FILE__ << ":" << __LINE__ << ": " << #x << " = " << ( x ) << endl

int main()
{
	while ( true )
	{
		bool yes = true, cont = true;;
		char c;
		string line;
		stack<char> st;

		while ( cont )
		{
			getline( cin, line );

			if ( line == "." )
			{
				return 0;
			}

			istringstream iss( line );

			while ( iss >> c )
			{
				if ( c == '.' )
				{
					cont = false;
					break;
				}
				else if ( c == '(' || c == '[' )
				{
					st.push( c );
				}
				else if ( c == ')' || c == ']' )
				{
					int c2 = ( c == ')' ? '(' : '[' );

					if ( !st.empty() && st.top() == c2 )
					{
						st.pop();
					}
					else
					{
						yes = false;
					}
				}
			}
		}

		if ( yes )
		{
			cout << "yes" << endl;
		}
		else
		{
			cout << "no" << endl;
		}
	}				

	return 0;
}

C++: #include<iostream>

using namespace std;

int strin(string);
int brackets(string, int);

int main(void)
{
    int size;
    string str;
    while(1)
    {
        size = 0;
        str = "";
        getline( cin, str );
        size = strin(str);
        if( 0 == size )
        {
            break;
        }
        else
        {
            brackets(str,size);
        }
    }
    return 0;
}

int strin(string str)
{
    int count = 0;
    for( int loop = 0; loop < 100; loop++ )
    {
        if( ( 0x2e == str[loop] ) && ( 0 == loop ) )
        {
            return 0;
        }
        else if( 0x2e == str[loop] )
        {
            break;
        }
        count++;
    }
    return count;
}

int brackets(string str, int size)
{
    int Parenthese = 0;
    int brackets = 0;
    char a;
    for( int loop = 0; loop <= size; loop++ )
    {
        switch(str[loop])
        {
            case 0x28:
                Parenthese++;
                a = str[loop];
                break;
                
            case 0x5B:
                brackets++;
                a = str[loop];
                break;
                
            case 0x29:
                Parenthese--;
                if( 0x5B == a )
                {
                    cout << "no" << endl;
                    return 0;
                }
                break;
                
            case 0x5D:
                brackets--;
                if( 0x28 == a )
                {
                    cout << "no" << endl;
                    return 0;
                }
                break;
                
            default:
                break;
        }
        if( ( 0 > Parenthese ) || ( 0 > brackets ) )
        {
            cout << "no" << endl;
            return 0;
        }
    }
    cout << "yes" << endl;
    
    return 0;
}

C++: #include <iostream>
#include <vector> 
#include <cmath>
#include <algorithm>
#include <set>
#include <map>
#include <cerrno>
#include <stdio.h>
#include <cfenv>
#include <stack>
#include <math.h>
#include <iomanip>
#include <limits>
#include <queue>
#define ll long long int
#define pb push_back
#define mp make_pair

using namespace std;

int main(){

    char s[101];

    while(true){

        fgets(s,102,stdin);

        if(s[0]=='.'){
            break;
        }

        int j=0;

        while(s[j]!='.')j++;

        stack<char> st;

        bool flag = true;

        for(int i=0;i<j;i++){
            if(s[i] == '('){
                st.push('(');
            }
            else if(s[i] == '['){
                st.push('[');
            }
            else if(s[i] == ')'){
                if(st.empty()){
                    flag = false;
                    break;
                }
                else if(st.top()!='('){
                    flag = false;
                    break;
                }
                else{
                    st.pop();
                }
            }
            else if(s[i] == ']'){
                if(st.empty()){
                    flag = false;
                    break;
                }
                else if(st.top()!='['){
                    flag = false;
                    break;
                }
                else{
                    st.pop();
                }
            }
        }
        if(flag){
            if(st.empty()){
                cout << "yes" << endl;
            }
            else{
                cout << "no" << endl;
            }
        }
        else{
            cout << "no" << endl;
        }
    }
    return 0;
}

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

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

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

#define loop(lp) for(int i = 0;i < lp;i++)

using namespace std;       
int main(){
  string s;
  stack<char> a;
  int i=0,j=0;
  while(getline(cin,s)){
    if(s == ".")
      break;
    while(s[i] != '.'){
      
      if(s[i] == '('){
	a.push('(');  
      }else if(s[i] == ')'){
	if(a.size() == 0){
	  j = 1;
	  break;
	}
	if(a.top() == '('){
	  a.pop();  
	}else{
	  j = 1;
	  break;
	}
      }else if(s[i] == '[' ){
	a.push('[');  
      }else if(s[i] == ']'){
	if(a.size() == 0){
	  j = 1;
	  break;
	}
	if(a.top() == '['){
	  a.pop();  
	}else{
	  j = 1;
	  break;
	}
      }
      i++;
    }
    if(a.size() == 0 && j != 1){
	cout <<"yes"<<endl;
      }else{
	cout <<"no"<<endl;   
      }
    i = 0;
    while(a.size() != 0){
      a.pop();
    }
    j = 0;
  }
    
    
    return 0;
}