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 <stack>

using namespace std;

int main(){
	int rk=0, sk=0, len=0;
	char in;
	bool check=false;
	stack<char> st;
	st.push(' ');
	while(true){
		scanf("%c", &in);
		if( in == '\n' ) continue;
		if( in == '.' && len == 0 ) break;
		len++;
		if( in == '(' ){ rk++; st.push('('); }
		if( in == '[' ){ sk++; st.push('['); }
		if( in == ')' ){
			if( --rk < 0 || st.empty() || st.top() != '(' )
				check=true;
			st.pop();
		}
		if( in == ']' ){
			if( --sk < 0 || st.empty() || st.top() != '[' )
				check=true;
			st.pop();
		}
		if( in == '.' ){
			cout << (check?"no":"yes") << endl;
			rk = 0;
			sk = 0;
			len = 0;
			check = false;
			while(st.empty()) st.pop();
			st.push(' ');
		}
	}
	return 0;
}

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

int main(){

  string str,z,x;

  while(1){

    stack < string > a;
    int count = -1,d;
    z = "0";
    a.push("0");
    d = a.size();
    getline(cin,str);

    if(str == ".") break;

    for(int i=0;i<str.size();i++){

      if((a.size() == d && str[i] == ')') || (a.size() == d && str[i] == ']')){
	count = 0;
        break;
      }
      if(str[i] == '('){
	x = str[i];
	a.push(x);
	z = a.top();
      }
      else if(str[i] == '['){
	x = str[i];
	a.push(x);
	z = a.top();
      }
      else if(z == "(" && str[i] == ')'){
	a.pop();
	z = a.top();
      }
      else if(z == "[" && str[i] == ']'){
	a.pop();
	z = a.top();
      }
      else if(z == "(" && str[i] == ']'){
	count = 0;
	break;
      }
      else if(z == "[" && str[i] == ')'){
	count = 0;
	break;
      }
    }
    
    if(count == 0 || a.size() != d) cout << "no" << endl;
    else cout << "yes" << endl;
  }
}

C++: #include <bits/stdc++.h>
using namespace std;
#define int long long
#define Rep(i, N) for(int i = 0; i < N; i++)

signed main()
{
  string S;
  bool izryt = false, flag = true;
  stack < char > st;
  
  while(getline(cin, S), izryt || S != ".") {
    izryt = true;
    Rep(i, S.size()) {
      if(S[i] == '.' && i == (int)S.size() - 1) {
	izryt = false;
      } else if(S[i] == '(' || S[i] == '[') {
	st.push(S[i]);
      } else if(S[i] == ')' || S[i] == ']') {
	if(!st.empty() && (S[i] == ')' && st.top() == '(' || S[i] == ']' && st.top() == '[')) {
	  st.pop();
	} else {
	  flag = false;
	}
      }
    }
    if(!izryt) {
      if(flag && st.empty()) cout << "yes" << endl;
      else cout << "no" << endl;

      while(!st.empty()) {
	st.pop();
      }
      flag = true;
    }
  }

  return 0;
}

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

using namespace std;

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

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

using namespace std;

int main()
{

    char ch;
    bool isSimm;
    string str;

    while(getline(cin, str) && str != ".") {
        isSimm = true;
        stack<char> st;
        for (unsigned long i = 0; i < str.size(); i++) {
            if (str[i] == '[' || str[i] == '(') st.push(str[i]);
            else if (str[i] == ']' || str[i] == ')') {
                if (st.empty()) {
                    isSimm = false;
                    break;
                }
                ch = st.top(); st.pop();
                if ((str[i] == ']' && ch != '[') || (str[i] == ')' && ch != '(')) {
                    isSimm = false;
                    break;
                }
            }
        }

        (isSimm && st.empty()) ? cout << "yes" << endl : cout << "no" << endl;
    }

    return 0;
}

C++: #include<iostream>
#include<vector>
#include<cmath>
#include<iomanip>
#include<string>
using namespace std;

int s(string str, int j) {
    int i = j;
    if (str[i] == '(') {
        while(true) {
            i++;
            if (str[i] == ')') {
                return i;
            } else if (str[i] == '[' || str[i] == '(') {
                i = s(str, i);
                if (i == -1) {
                    return -1;
                }
            } else if (str[i] == ']' || str[i] == '.') {
                return -1;
            }
        }
    } else {
        while(true) {
            i++;
            if (str[i] == ']') {
                return i;
            } else if (str[i] == '[' || str[i] == '(') {
                i = s(str, i);
                if (i == -1) {
                    return -1;
                }
            } else if (str[i] == ')' || str[i] == '.') {
                return -1;
            }
        }
    }
}

int main() {
    while(true) {
        int i;
        int cntr = 0;
        int cntk = 0;
        int result = 0;
        string ch;

        getline(cin, ch);
        for (i = 0; i < 100; i++) {
            if (ch[i] == '(' || ch[i] == '[') {
                result = s(ch, i);
                i = result;
                if (result == -1) {
                    break;
                }
            } else if (ch[i] == ')' || ch[i] == ']') {
                result = -1;
                break;
            } else if (ch[i] == '.') {
                result = 0;
                break;
            }
        }
        if (ch[0] == '.') {
            break;
        } else if (result != -1) {
            cout << "yes" << endl;
        } else {
            cout << "no" << endl;
        }
    }
}