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 <vector>
#include <list>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <algorithm>
#include <sstream>
#include <iostream>
#include <string>

using namespace std;

int main() {

	vector<string> s;
	
	while (1) {
		string ss;
		getline(cin, ss);
		if (ss == ".") break;

		int a[2] = {};
		bool flag = true;

		stack<int> st;
	
		for (int j = 0; j < ss.length(); j++) {

			if (ss[j] == '(') st.push(0),a[0]++;
			if (ss[j] == ')') {
				if (st.empty() || st.top() != 0 ) {
					flag = false;
					break;
				}
				else st.pop(),a[0]--;
			}
			if (ss[j] == '[') st.push(1),a[1]++;
			if (ss[j] == ']') {
				if (st.empty() || st.top() != 1) {
					flag = false;
					break;
				}
				else st.pop(), a[1]--;
			}
		}
		if (a[0] != 0 || a[1] != 0) flag = false;

		if (flag) cout << "yes" << endl;
		else cout << "no" << endl;

	}

	return 0;
}

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

#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,j) FOR(i,0,j)
#define mp std::make_pair

const int INF = 1 << 24;
const int dx[8] = {0, 0, 1, -1, 1, 1, -1, -1}, dy[8] = {1, -1, 0, 0, 1, -1, 1, -1};

typedef unsigned long long ull;
typedef std::pair<int,int> P;

bool doesBalance(std::string s){
    std::stack<char> stack;
    REP(i, s.size()){
        if(s[i] == '(' || s[i] == '['){
            stack.push(s[i]);
        }else if(s[i] == ')'){
            if(stack.empty() || stack.top() != '('){return false;}
            stack.pop();
        }else if(s[i] == ']'){
            if(stack.empty() || stack.top() != '['){return false;}
            stack.pop();
        }
    }

    return stack.empty();
}

int main(){
    std::string s;
    while(std::getline(std::cin, s), s != "."){
        if(doesBalance(s)){puts("yes");}
        else{puts("no");}
    }
}

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

typedef std::int_fast32_t  s32;
typedef std::uint_fast32_t u32;
typedef std::int_fast64_t  s64;
typedef std::uint_fast64_t u64;

typedef std::pair<int, int> P;

char str[128];
int i;

bool L0(void) {
  while( not ( str[i] == '(' or str[i] == ')' or str[i] == '[' or str[i] == ']' or str[i] == '\0' ) ) i += 1;
  return true;
}

bool L1(void) {
  if( str[i] == '\0' ) return true;

  bool res = L0();

  if( str[i] == '\0' ) return true;
  if( str[i] == ')' ) return false;
  if( str[i] == ']' ) return false;

  if( str[i] == '(' ) {
    i += 1;
    res = L1();
    if( str[i] != ')' ) return false;
  }
  if( str[i] == '[' ) {
    i += 1;
    res = L1();
    if( str[i] != ']' ) return false;
  }
  i += 1;
  return L1();
}
  
int main(void) {
  
  for(;;) {
    std::string s;
    std::getline(std::cin, s);
    if( s == "." ) break;

    strcpy(str, s.c_str());
    i = 0;

    std::cout << ( L1() ? "yes" : "no" ) << std::endl;
  }
  
  return 0;
}

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

int main(void){

  string s;
  while(getline(cin,s)){
    if(s==".")break;

    stack<char>st;
    for(int i=0;i<s.size();i++){
      if(s[i]=='(' || s[i]=='[')st.push(s[i]);
      else if(((s[i]==')' || s[i]==']') && st.empty()) ||
	      (s[i]==')' && st.top()=='[') ||
	      (s[i]==']' && st.top()=='(')){
	cout << "no" << endl;
	goto end;
      }
      else if(s[i]==')' || s[i]==']')st.pop();
    }
    cout << "yes" << endl;
  end:;
  }
  
  return 0;
}

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

int main() {
	string str;
	stack<char>br;
	while (getline(cin, str), str != ".") {
		int flag = false;
		while (br.empty() != true) br.pop();
		for (int i = 0; i < str.size(); i++) {
			if (str[i] == '(' || str[i] == '[') br.push(str[i]), flag = true;
			else if (str[i] == ')') {
				if (br.empty()) {
					br.push('@');
					break;
				}
				else if ('(' == br.top())br.pop();
			}
			else if (str[i] == ']') {
				if (br.empty()) {
					br.push('@');
					break;
				}
				else if ('[' == br.top())br.pop();
			}
		}
		if (br.empty() && flag) cout << "yes" << endl;
		else cout << "no" << endl;
	}
}

C++: #include <stdio.h>
int main(){
  int i,ib;
  char a,s[100];
  while(1){
    i=0;
    scanf("%c",&a);
    if(a=='.')break;
    else if(a=='('){
      s[i]='(';
      i++;
    }else if(a==')'){
      s[i]=')';
      i++;
    }else if(a=='['){
      s[i]='[';
      i++;
    }else if(a==']'){
      s[i]=']';
      i++;
    }
    while(1){
      scanf("%c",&a);
      if(a=='.'){
	if(i==0){
	  printf("Yes\n");
	  break;
	}else {
	  printf("No\n");
	  break;
	}
      }else if(a=='('){
	s[i]='(';
	i++;
      }else if(a==')'){
	if(s[i-1]=='('){
	  i--;
	}
      }else if(a=='['){
	s[i]='[';
	i++;
      }else if(a==']'){
	if(s[i-1]=='['){
	  i--;
	}
      }
    }
    scanf("%c",&a);
  }
  return 0;
}

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

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

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

int si = 0;
string S;
bool parse(char c)
{
  bool ans = true;
  for(; si < S.length(); si++)
  {
    if(S[si] == c)
      return true;
    switch(S[si])
    {
      case '(':
        si++;
        ans &= parse(')');
        break;
      case '[':
        si++;
        ans &= parse(']');
        break;
    }
  }
  return false;
}

int main()
{
loop:
  si = 0;
  getline(cin, S);
  if(S == ".")
    return 0;
  cout << (parse('.') ? "yes" : "no") << endl;
  goto loop;
}