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<algorithm>
#include<vector>
#include<string>
using namespace std;

char x;
vector<string> ans;
vector<char> stk;
int main(){
	bool ok = true;
	while(~scanf("%c", &x)){
		if(x == '.'){
			if(!stk.empty())ok = false;
			if(ok)ans.push_back("yes");
			else ans.push_back("no");
			ok = true;
			stk.clear();
		}
		if(x == '('){
			stk.push_back(x);
		}
		if(x == '['){
			stk.push_back(x);
		}
		if(x == ')'){
			if(!stk.empty() && stk.back() == '(')stk.pop_back();
			else ok = false;
		}
		if(x == ']'){
			if(!stk.empty() && stk.back() == '[')stk.pop_back();
			else ok = false;
		}
	}
	ans.pop_back();
	for(int i = 0;i < ans.size();i++)cout << ans[i] << 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&&s.empty()) cout<<"yes"<<en
        else cout<<"no"<<en
          break;
      }
    }
  }
  RE
}

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

int main(){
    char s[108];
    vector<int> stack;
    cin.getline(s, 101);
    while(s[0] != '.' && s[1] != '\0'){
        int rnd = 0, box = 0, no = 0;
        for(int i = 0; i < sizeof(s); i++){
            if(s[i] == '(') stack.push_back(0);
            if(s[i] == '[') stack.push_back(1);
            if(s[i] == ')'){
                if(stack.back() != 0){
                    no = 1;
                    break;
                }
                stack.pop_back();
            }
            if(s[i] == ']'){
                if(stack.back() != 1){
                    no = 1;
                    break;
                }
                stack.pop_back();
            }
            if(s[i] == '\0') break;
        }
        if(no == 0 && rnd == 0 && box == 0){
            printf("yes\n");
        } else {
            printf("no\n");
        }
        cin.getline(s, 101);
    }
}

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

using namespace std;
using ll = long long;

#define all(c) (c).begin(), (c).end()
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define pb(e) push_back(e)
#define mp(a, b) make_pair(a, b)
#define fr first
#define sc second

const ll INF = 1e9;
const ll MOD = 1e9 + 7;
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};

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

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<int> a;
  int i=0,j=0;
  while(getline(cin,s)){
    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(i == 0){
      break;
    }
    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;
}

C++: #include <iostream>
#include <cstdio>
#include <vector>
#include <cmath>
#include <cstring>
#include <numeric>
#include <algorithm>
#include <functional>
#include <array>
#include <map>
#include <queue>
#include <limits.h>
#include <set>
#include <bitset>
#include <stack>
#include <cstdlib>
#define REP(i,n) for(int i = 0; n > i; i++)
#define MOD 1000000007
using namespace std;
typedef vector<int> Ivec;
typedef pair<int, int> pii;
typedef long long int ll;
char str[101];
map<char, char> kako = { {'(',')'},{'[',']'} };
int is_balanced(int s) {
	for (int i = s+1; strlen(str) > i; i++) {
		if (str[i] == '(' || str[i] == '[') {
			i = is_balanced(i)+1;
			if (i == 0) return -1;
		}
		if (str[i] == ')' || str[i] == ']') {
			if(str[i] != kako[str[s]])
				return -1;
			else {
				return i;
			}
		}
	}
	return -1;
}

int main() {
	while (1) {
		memset(str, 0, sizeof(str));
		for(int i = 0; ;i++) {
			scanf("%c", &str[i]);
			if (str[i] == '.') break;
		}
		scanf("%*c");
		if (!strcmp(str, "."))
			return 0;
		bool f = true;
		REP(i, strlen(str)) {
			if (str[i] == '(' || str[i] == '[') {
				i = is_balanced(i)+1;
				if (i == 0) {
					printf("no\n");
					f = false;
					break;
				}
			}
		}
		if (f) printf("yes\n");
	}

	return 0;
}