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 <cstdio>
#include <cstring>
#include <cmath>
#include <iostream>
#include <algorithm>
#include <stack>
#include <queue>
#include <vector>
#include <set>
using namespace std;

#define rep(i,n) for(int i=0;i<(n);i++)
#define mp(a,b) make_pair(a,b)
#define pb(a) push_back(a)
#define dbg(x) cout<<#x"="<<x<<endl

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<pii, int> ppi;

#define INF 1000000000

enum {NONE, SQ, RD}; //last bracket (square or round)
bool solve(char *l){
  int idx=0;
  stack<int> st;
  while(true){
    switch(l[idx]){
    case '(':
      st.push(RD);
      break;
    case '[':
      st.push(SQ);
      break;
    case ')':
      if(st.empty() || st.top()!=RD) return false;
      else st.pop();
      break;
    case ']':
      if(st.empty() || st.top()!=SQ) return false;
      else st.pop();
      break;
    case '.':
      if(st.empty()) return true;
      else return false;
      break;
    }
    idx++;      
  }


}

int main(){
  while(true){
    char l[128];
    scanf("%[^\n]", l);
    if(l[0]=='.') break;
    getchar(); // read \n

    if(solve(l)) cout << "yes" << endl;
    else cout << "no" << endl;

  }

}

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

char d[110];

int main() {
  while (1) {
    scanf("%110[^\n]", d);
    if (d[0] == '.') break;
    getchar();
    int stack[100], sNum = 0;
    bool flag = true;
    for (int i = 0; d[i] != '.'; i++) {
      if (d[i] == '(') stack[sNum++] = 0;
      if (d[i] == '[') stack[sNum++] = 1;
      if (d[i] == ')') {
        if (sNum > 0 && stack[sNum - 1] == 0) sNum--;
        else { flag = false; break; }
      }
      if (d[i] == ']') {
        if (sNum > 0 && stack[sNum - 1] == 1) sNum--;
        else { flag = false; break; }
      }
    }
    if (flag && sNum == 0) printf("yes\n");
    else printf("no\n");
  }
}

C++: #include<bits/stdc++.h>
using namespace std;

string str;

int main(){
  while( getline(cin,str) ){
    if( str[0] == '.' ) break;

    stack<char> st;

    for(int i=0;i<(int)str.size();i++){
      if( str[i] == '(' || str[i] == '[' ){
	st.push( str[i] );
      } else if( str[i] == ')' ){
	if( st.empty() ) {
	  st.push(str[i]); break;
	}
	if( st.top() == '(' ) st.pop();
	else break;
      } else if( str[i] == ']' ){
	if( st.empty() ) {
	  st.push(str[i]); break;
	}
	if( st.top() == '[' ) st.pop();
	else break;
      }
    }

    if( st.empty() ) cout << "yes" << endl;
    else cout << "no" << endl;

  }
}

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

bool solve(string s) {
  stack<char> stk;
  for(int i = 0; i != (int)s.size(); ++i) {
    if(s[i] == '[' || s[i] == '(') stk.push(s[i]);
    else if(s[i] == ']') {
      if(stk.empty() || stk.top() != '[') return 0;
      else stk.pop();
    }
    else if(s[i] == ')') {
      if(stk.empty() || stk.top() != ')') return 0;
      else stk.pop();
    }
  }
  return stk.empty();
}

int main() {
  string s;
  while(getline(cin, s) && s != ".") {
    cout << (solve(s) ? "yes" : "no") << endl;
  }
  return 0;
}

C++: #include <bits/stdc++.h>
using namespace std;
string s;
int main(){
	G:
	while(getline(cin,s),s!="."){
		stack<char> p;
		for(int i=0;i<s.length();i++){
			if(s[i]=='('||s[i]=='[')p.push(s[i]);
			if(s[i]==')'){
				if(p.empty()||p.top()!='('){cout<<"no"<<endl;goto G;}
				p.pop();
			}
			if(s[i]==']'){
				if(p.empty()||p.top()!='['){cout<<"no"<<endl;goto G;}
				p.pop();
			}
		}
		cout<<(p.empty()?"yes":"no")<<endl;
	}

}

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

using namespace std;

int main(void){
	char letter[100];
	stack<char>st;
	bool flag;
	while(1){
		flag = false;
		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();
				else{
				cout << "no" << endl;
				flag = true;
				}
			}
			if(letter[i] == ']'){
				if(st.top() == '[')
				st.pop();
				else{
				cout << "no" << endl;
				flag = true;
				}
			}
			}
			i++;
		}
		if(flag == false)
		cout << "yes" << endl;
		while(st.empty() == true)
			st.pop();
	}
	return 0;
}

C++: #include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <stack>
#include <queue>
#include <vector>
#include <string>
#include <map>
#include <set>
#include <algorithm>
#include <functional>
#include <iomanip>
#include <cassert>
// using namespace std;
// #define int long long
#define REP(i,s,n) for (int i = (s); i < (n); ++i)
#define rep(i,n) REP(i,0,n)
#define rrep(i,n) for (int i = n; i >= 0; i--)
#define INF (int)(1e9+7)
#define space " "
#define ENDL "\n"
#define MAXL 100

int vx[] = {1, 0, -1, 0}, vy[] = {0, 1, 0, -1};

inline void init() {
    std::cin.tie(0);
    std::ios::sync_with_stdio(false);
}
// ??¢?????¬??????????????????????????????????????????!!
inline void nextInt(int *a) { scanf("%d", a); }
inline void nextInt(int *a, int *b) { scanf("%d %d", a, b); }
inline void nextInt(int *a, int *b, int *c) { scanf("%d %d %d", a, b, c); }
inline void nextDouble(double *a) { scanf("%lf", a); }
inline void nextDouble(double *a, double *b) { scanf("%lf %lf", a, b); }
inline void nextDouble(double *a, double *b, double *c) { scanf("%lf %lf %lf", a, b, c); }
inline void nextLine(char *c) { scanf("%s", c); getchar();/*?????????????????¨???*/ }
inline std::string nextLine() {
    std::string s = ""; char str[MAXL+1];
    scanf("%s", str); getchar(); /*?????????????????¨???*/
    return s += str;
}
inline void print(double *a, int n = 0) {
    std::cout << std::fixed << std::setprecision(n) << *a << ENDL;
}
inline void print(int a) {
    printf("%d\n", a);
}

/************************End of template*************************/

int main() {
    std::string s;
    bool flag = true;
    std::stack<char> st, ini;

    init();

    while (true) {
        s = "";
        st = ini;
        flag = true;
        std::getline(std::cin, s);
        //std::cout << "[" << s << "]" << ENDL;
        if (s[0] == '.') break;

        rep(i,s.size()) {
            if (s[i] == '(' || s[i] == '[') {
                st.push(s[i]);
            } else if (s[i] == ')') {
                if (st.empty()) {
                    flag = false;
                    break;
                } else if (st.top() == '(') {
                    st.pop();
                } else {
                    flag = false;
                    break;
                }
            } else if (s[i] == ']') {
                if (st.empty()) {
                    flag = false;
                    break;
                } else if (st.top() == '[') {
                    st.pop();
                } else {
                    flag = false;
                    break;
                }
            }
        }
        if (!st.empty()) flag = false;
        if (flag) std::cout << "yes" << ENDL;
        else std::cout << "no" << ENDL;
    }

    return 0;
}