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 <stdio.h>
#include <string.h>

#define MAX_STR_LEN 102

int CheckBracket(char *bracketStr, int *bracketStrIdx, char inputStr);

int main()
{
	char inputStr[MAX_STR_LEN]   = {'\0'};		// Array for input string
	int  inputStrLen = 0;						// Length of input string
	char bracketStr[MAX_STR_LEN] = {'\0'};		// Array for keep left-bracket
	int  bracketStrIdx = 0;						// Index of "bracketStr"
	char compareBracket = '\0';					// Valiable of select bracket to compare
	int  falseFlg = 0;							// Flag of sign false
	int  i = 0;									// Loop valiable
	
	do{
		// Initialize parameter.
		for(i = 0; i < MAX_STR_LEN; i++)
		{
			inputStr[i]    = '\0';
			bracketStr[i]  = '\0';
		}
		bracketStrIdx  = 0;
		compareBracket = '\0';
		falseFlg       = 0;
		
		// Input string.
//		printf("Input string >> ");
		fgets(inputStr, MAX_STR_LEN, stdin);
//		puts(inputStr);
		inputStrLen = strlen(inputStr);
		
		// If input string is '.' only, end.
		if('.' == inputStr[0])
		{
			break;
		}
		
		// Check to match bracket.
		for(i = 0; i < inputStrLen; i++)
		{
			switch(inputStr[i])
			{
			// If inputStr[i] is left-bracket, connect to "bracketStr".
			case '(':
			case '[':
				bracketStr[bracketStrIdx] = inputStr[i];
				bracketStrIdx++;
				break;
				
			// If inputStr[i] is right-bracket, Check to match bracket.
			case ')':
			case ']':
				falseFlg = CheckBracket(bracketStr, &bracketStrIdx, inputStr[i]);
				break;
				
			case '.':
				// If bracketStr is not empty, falseFlg is 1.
				if(0 != bracketStrIdx)
				{
					falseFlg = 1;
				}
				break;
			default:
				break;
			}
			
			if(1 == falseFlg)
			{
				break;
			}
		}
		
		// Disp result.
		if(0 == falseFlg)
		{
			printf("yes\n");
		}
		else
		{
			printf("no\n");
		}
	}while(1);
	
	return 0;
}

// CheckBracket
// Function  : Check to match bracket.
// Param[in] : char *bracketStr, int *bracketStrIdx, char inputStr
// Param[out]: 0(true) or 1(false)
// Global    : 
int CheckBracket(char *bracketStr, int *bracketStrIdx, char inputStr)
{
	char compareBracket = '\0';
	
	// If left-bracket is empty, falseFlg is 1.
	if(0 == *bracketStrIdx)
	{
		return 1;
	}
	
	// Select the compare bracket.
	if(')' == inputStr)
	{
		compareBracket = '(';
	}
	else
	{
		compareBracket = '[';
	}
	
	// Check to match bracket.
	if(compareBracket == bracketStr[(*bracketStrIdx) - 1])
	{
		bracketStr[(*bracketStrIdx) - 1] = '\0';
		(*bracketStrIdx)--;
	}
	else
	{
		return 1;
	}
	
	return 0;
}

// Test sting
/* ------------------------------------------------------------------------
So when I die (the [first] I will see in (heaven) is a score list).   yes
[ first in ] ( first out ).                                           yes
Half Moon tonight (At least it is better than no Moon at all].        no
A rope may form )( a trail in a maze.                                 no
Help( I[m being held prisoner in a fortune cookie factory)].          no
([ (([( [ ] ) ( ) (( ))] )) ]).                                       yes
 .                                                                    yes
.                                                                     
------------------------------------------------------------------------ */

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

using namespace std;

int main(void){
	char letter[100];
	stack<char>st;
	while(1){
		fgets(letter, 100, stdin);
		if(letter[0] == '.') break;
		int i = 0;
		while(1){
			if(letter[i] == '.') break;
			if(letter[i] == '(' || letter[i] == '[')
			st.push(letter[i]);
			if(st.empty() == false){
			if(letter[i] == ')'){
				if(st.top() == '(')
				st.pop();
			}
			if(letter[i] == ']'){
				if(st.top() == '[')
				st.pop();
			}
			}
			i++;
		}
		if(st.empty())
		cout << "yes" << endl;
		else
		cout << "no" << endl;
		for(int i = 0; i < st.size(); i++)
			st.pop();
	}
	return 0;
}

C++: #include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <functional>
#include <numeric>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <utility>
#include <sstream>
#include <complex>

using namespace std;

#define FOR(i,a,b) for(long long i=(a);i<(b);i++)
#define REP(i,N) for(long long i=0;i<(N);i++)
#define ALL(s) (s).begin(),(s).end()
#define fi first
#define se second

#define PI acos(-1.0)
#define INF 1000000007
#define EPS 1e-10

typedef long long ll;
typedef pair<ll, ll> P;
typedef pair<double, double> PD;
typedef pair<string, ll> PS;
typedef vector<ll> V;
typedef pair<P, char> PC;

string s;

int main(){
	while (getline(cin, s)){
		if (s == ".")break;
		bool f = 1, g = 0;
		vector<char> vc;
		vc.clear();
		REP(i, s.size()){
			if (s[i] == '('){
				vc.push_back(s[i]);
			}
			if (s[i] == '['){
				vc.push_back(s[i]);
			}
			if (s[i] == ')'){
				if (!vc.empty()){
					if (vc[vc.size() - 1] == '[')f = 0;
					else vc.pop_back();
				}
				else f = 0;
			}
			if (s[i] == ']'){
				if (!vc.empty()){
					if (vc[vc.size() - 1] == '(')f = 0;
					else vc.pop_back();
				}
				else f = 0;
			}
		}
		if ((vc.empty()&&g)||(vc.empty() && f))cout << "yes" << endl; 
		else cout << "no" << endl;
	}
}

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

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

C++: #include <iostream>
#include <cstdio>
#include <algorithm>
#include <string>
#include <cstring>
#include <cctype>
#include <cmath>
#include <stack>
#include <queue>
#include <vector>
#include <set>
#include <map>
#include <list>
#include <stdio.h>
#include <string.h>
#include <cstdlib>
#include <math.h>
#include <bitset>
#define INF 2000000000
using namespace std;
int dx[4]={1,0,-1,0},dy[4]={0,1,0,-1};
#define ll long long
#define PL pair<long long, long long>
#define PR pair<int,int>
#define mk make_pair
#define en endl;
#define WHITE 0
#define BLACK 2
#define GRAY 1
#define RE return 0;

#define int ll

// the balance of the world

signed main(){
  while(1){
    stack<char> s;
    string str;
    getline(cin, str);
    if(str==".") break;
    
    bool ans=1;
    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()) ans=0;
        else if(str[i]==']'&&s.top()=='['){
          s.pop();
        }else if(str[i]==')'&&s.top()=='('){
          s.pop();
        }else{
          ans=0;
        }
      }else if(str[i]=='.'){
        if(ans) cout<<"yes"<<en
        else cout<<"no"<<en
          break;
      }
    }
  }
  RE
}