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>

using namespace std;

string str;

int skip(int idx) {
  while (str[idx] != '(' && str[idx] != '[' &&
         str[idx] != ')' && str[idx] != ']' && str[idx] != '.') {
    idx++;
  }
  return idx;
}

char corre(char c) {
  if (c == '[') {return ']';}
  if (c == '(') {return ')';}
}

int inKakko(int idx, char kakko) {
  //fprintf(stderr, "inKakko\n");
  while (true) {
    idx = skip(idx);
    //fprintf(stderr, "%d, %c\n", idx, str[idx]);
    if (str[idx] == '.') {
      return idx;
    } else if (str[idx] == corre(kakko)) {
      //fprintf(stderr, "matched %c\n", kakko);
      return idx + 1;
    } else if (str[idx] == '(' || str[idx] == '[') {
      idx = inKakko(idx + 1, str[idx]);
      if (idx < 0) {
        return -1;
      }
    } else {
      return -1;
    }
  }
}

bool _solve(int idx) {
  while (true) {
    idx = skip(idx);
    //fprintf(stderr, "%d, %c\n", idx, str[idx]);
    switch (str[idx]) {
    case '.':
      return true;
    case '(':
    case '[':
      idx = inKakko(idx + 1, str[idx]);
      //fprintf(stderr, "idx=%d\n", idx);
      if (idx < 0) {
        return false;
      }
      break;
    case ')':
    case ']':
      return false;
    }
    //fprintf(stderr, "e%d, %c\n", idx, str[idx]);
  }
}

void solve() {
  if (_solve(0)) {
    printf("yes\n");
  } else {
    printf("no\n");
  }
}

int main() {
  while (true) {
    getline(cin, str);
    //fprintf(stderr, "start\n");
    if (str == ".") {
      return 0;
    }
    solve();
  }
}

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

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

    stack<char> st;
    bool ok = true;
    for(int i = 0; i < str.length(); i++){
      if(st.empty()){
        if(str[i] == ']' || str[i] == ')'){
          ok = false;
          break;
        }
      }

      if(str[i] == '[' || str[i] == '('){
        st.push(str[i]);
      }else if(str[i] == ')' || str[i] == ']'){
        if((st.top() == '(' && str[i] == ')') || (st.top() == '[' && str[i] == ']')){
          st.pop();
        }else{
          ok = false;
          break;
        }
      }
    }
    cout << (ok ? "yes" : "no") << endl;
  }
}

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

using namespace std;

string str;

int skip(int idx) {
  while (str[idx] != '(' && str[idx] != '[' &&
         str[idx] != ')' && str[idx] != ']' && str[idx] != '.') {
    idx++;
  }
  return idx;
}

char corre(char c) {
  if (c == '[') {return ']';}
  if (c == '(') {return ')';}
}

int inKakko(int idx, char kakko) {
  //fprintf(stderr, "inKakko\n");
  while (true) {
    idx = skip(idx);
    //fprintf(stderr, "%d, %c\n", idx, str[idx]);
    if (str[idx] == '.') {
      return idx;
    } else if (str[idx] == corre(kakko)) {
      //fprintf(stderr, "matched %c\n", kakko);
      return idx + 1;
    } else if (str[idx] == '(' || str[idx] == '[') {
      idx = inKakko(idx + 1, str[idx]);
      if (idx < 0) {
        return -1;
      }
    } else {
      return -1;
    }
  }
}

bool _solve(int idx) {
  while (true) {
    idx = skip(idx);
    //fprintf(stderr, "%d, %c\n", idx, str[idx]);
    switch (str[idx]) {
    case '.':
      return true;
    case '(':
    case '[':
      idx = inKakko(idx + 1, str[idx]);
      //fprintf(stderr, "idx=%d\n", idx);
      if (idx < 0) {
        return false;
      }
      break;
    case ')':
    case ']':
      return false;
    }
    //fprintf(stderr, "e%d, %c\n", idx, str[idx]);
  }
}

void solve() {
  if (_solve(0)) {
    printf("yes\n");
  } else {
    printf("no\n");
  }
}

int main() {
  while (true) {
    getline(cin, str);
    if (str == ".") {
      return 0;
    }
    solve();
  }
}

C++: ///
// File:  1173.cpp
// Author: ymiyamoto
//
// Created on Sun Nov 12 17:50:22 2017
//

#include <cstdint>
#include <iostream>
#include <istream>
#include <stack>

using namespace std;

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

    stack<char> s;
    for (uint32_t i = 0; i < str.size(); i++) {
      if (str[i] == '(') {
        s.push('(');
      } else if (str[i] == ')') {
        if (!s.empty() && s.top() == '(') {
          s.pop();
        } else {
          s.push('*');
          break;
        }
      } else if (str[i] == '[') {
        s.push('[');
      } else if (str[i] == ']') {
        if (!s.empty() && s.top() == '[') {
          s.pop();
        } else {
          s.push('*');
          break;
        }
      }
    }

    if (s.empty()) {
      cout << "yes" << endl;
    } else {
      cout << "no" << endl;
    }
  }

  return 0;
}

C++: #include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define len(v) (int)(v).size()

using namespace std;

int main()
{
    while(1){
        string s;
        getline(cin,s);
        if(s == "."){
            break;
        }
        int a = 0, b = 0;
        stack<int> st;
        bool ok = true;
        rep(i,len(s)){
            if(s[i] == '('){
                a++;
                st.push(0);
            }else if(s[i] == ')'){
                a--;
                if(a < 0 || st.top() == 1){
                    ok = false;
                    break;
                }else{
                    st.pop();
                }
            }else if(s[i] == '['){
                b++;
                st.push(1);
            }else if(s[i] == ']'){
                b--;
                if(b < 0 || st.top() == 0){
                    ok = false;
                    break;
                }else{
                    st.pop();
                }
            }
        }
        if(ok && a == 0 && b == 0){
            cout << "yes\n";
        }else{
            cout << "no\n";
        }
    }
}

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

int main(){
	while(1){
		std::string str;
		char bef;
		int count=0;
		std::getline(std::cin,str);
		if(str==".")break;
		for(int i=0;i<str.size();i++){
			if(str[i]=='('||str[i]=='['){
				count++;
				bef=str[i];
			}else if(str[i]==')'||str[i]==']'){
				count--;
				if(!((str[i]==')'&&bef=='(')||(str[i]==']'&&bef=='['))){
					std::cout<<"no"<<std::endl;
					goto end;
				}
			}
		}
		if(count==0)std::cout<<"yes"<<std::endl;
		else std::cout<<"no"<<std::endl;
		end:;
	}
	return 0;
}