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 101

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);
		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] = '\0';
		(*bracketStrIdx)--;
	}
	else
	{
		return 1;
	}
	
	return 0;
}

C++: import java.util.Scanner;
import java.io.*;

/**
 * Created by Reopard on 2014/07/03.
 */
public class Main{
    static Scanner s = new Scanner(System.in);

    public static void main(String[] args)throws IOException{
        InputStreamReader is = new InputStreamReader(System.in);
        BufferedReader br = new BufferedReader(is);
        char[] c = new char[100];
        char tmp;
        boolean flag=true;
        int p = 0;
        String text;
        while(true){
            text = br.readLine();
            p = 0;
            flag=true;
            if(text.equals(".")) break;

            for(int i = 0; i < text.length(); i++){
                tmp = text.charAt(i);

                if(tmp == '('){
                    c[p] = '(';
                    p++;
                }else if(tmp == '['){
                    c[p] = '[';
                    p++;
                }else if(tmp == ')'){
                    if(p > 0 && c[p - 1] == '('){
                        p--;
                    }else{
                        flag=false;
                    }
                }else if(tmp == ']'){
                    if(p > 0 && c[p - 1] == '['){
                        p--;
                    }else{
                        flag=false;
                    }
                }else if(tmp == '.'){
                    if(p == 0 && flag){
                        System.out.println("yes");
                        break;
                    }else{
                        System.out.println("no");
                        break;
                    }
                }
                if(i == text.length() - 1){
                    i = -1;
                    text = br.readLine();
                }
            }

        }
    }
}

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

bool q2(){
    char c;
    bool check = true;
    stack<char> st;
    st.push('0');
    if(scanf("%c",&c) && c == '.')return false;
    while(c != '.'){
        switch(c){
            case '(':
                st.push('(');break;
            case '[':
                st.push('[');break;
            case ')':
                if(st.top()!='('){check=false;break;}
                st.pop();break;
            case ']':
                if(st.top()!='['){check=false;break;}
                st.pop();break;
            default:
                break;
        }
        scanf("%c",&c);
    }
    cout << (check ? "yes" : "no") << '\n';
    scanf("%c",&c);
    return true;
}

int main()
{
    while(q2());
}

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

int main()
{
  string str;

  while (getline(cin,str))
  {
    if ((str.length() == 1) && (str[0] = '.')) return 0;

    int paren = 0;
    int blacket = 0;
    stack<char> p;
    bool flag = true;

    for (int i=0;i<str.length();i++)
    {
      if (str[i] == '(')
      {
        paren++;
        p.push('(');
      }
      else if (str[i] == ')')
      {
        paren--;
        if (paren < 0) { flag = false; break; }
        if (p.top() != '(') { flag = false; break; }
        p.pop();
      }
      else if (str[i] == '[')
      {
        blacket++;
        p.push('[');
      }
      else if (str[i] == ']')
      {
        blacket--;
        if (blacket < 0) { flag = false; break; }
        if (p.top() != '[') { flag = false; break; }
        p.pop();
      }
    }
    if (flag) cout << "yes" << endl;
    else cout << "no" << endl;
  }
}

C++: # include <algorithm>
# include <cassert>
# include <cctype>
# include <cstdio>
# include <cstdlib>
# include <cstring>
# include <cmath>
# include <iostream>
# include <map>
# include <queue>
# include <set>
# include <sstream>
# include <stack>
# include <string>
# include <vector>
# include <iomanip>

# define rep(i, n) for (int i = 0; i < (int)(n); i++)
# define irep(i, n) for (int i = int(n) - 1; i >= 0; i--)
# define FOR(i, m, n) for (int i = int(m); i < (int)(n); i++)

using namespace std;

template <typename T>
void show_all(T t) {
  rep (i, t.size()) {
    rep (j, t[0].size()) {
      cout << t[i][j];
    }
    cout << endl;
  }
}

int main() {
  string sentence;

  while (getline(cin, sentence) && sentence != ".") {
    int position = 0;

    stack<char> a;
    a.push('a');

    rep (i, sentence.size()) {
      if (sentence[i] == '(') a.push(sentence[i]);
      if (sentence[i] == '[') a.push(sentence[i]);

      if (sentence[i] == ')') {
        if ('(' == a.top()) a.pop();
        // else break;
      }
      if (sentence[i] == ']') {
        if ('[' == a.top()) a.pop();
        // else break;
      }
    }

    cout << (a.size() == 1 ? "yes" : "no") << endl;
  }
}