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<stack>
main(){for(char i,f,c,s[101];fgets(s,101,stdin),s[0]-46;){std::stack<int> t;for(f=i=0;c=s[i++],c-46;){if(c==40|c==91)t.push(c);if(c==41|c==93){if(t.size()&&(c==t.top()+1||c==t.top()+2))t.pop();else f=1;}}puts(f&t.size()?"no":"yes");}}

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

int main() {
    string str;

    while (true) {
        getline(cin, str);
        if (str == ".") break;

        int a=0, b=0;
        bool flag=true;
        rep(i, str.size()) {
            if (str[i] == '(') a++;
            else if (str[i] == ')') {
                if (a > 0) a--;
                else {
                    flag=false;
                    break;
                }
            }
            if (str[i] == '[') b++;
            else if (str[i] == ']') {
                if (b > 0) b--;
                else {
                    flag=false;
                    break;
                }
            }
        }

        if (a != 0 or b != 0) flag=false;
        
        cout << (flag ? "yes" : "no") << endl;
    }

}

C++: #include<stdio.h>
#include<string.h>
#include<stack>
int main()
{
	char*p,s[128],*q;
	while(q=fgets(s,128,stdin),*s-'.')
	{
		std::stack<int>c;
		for(p=s;*p;++p)
		{
			if(strchr("[(",*p))c.push(*p);
			if(strchr("])",*p))if(c.empty()||c.top()!=*p-(*p-')'?2:1))q=0;
			else c.pop();
		}
		if(!c.empty())q=0;
		puts(q?"yes":"no");
	}
	return 0;
}

C++: import java.io.InputStreamReader;
import java.io.BufferedReader;
import java.io.IOException;


/**
 * Created by Reopard on 2014/07/03.
 */
public class Main{

    public static void main(String[] args) throws Exception{
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

        char[] c = new char[100];
        char tmp;
        boolean flag=true;
        int p = 0;
        String text;
        while(true){
            text = br.readLine();
            p = 0;
            flag=true;
            if(text.equals(".")) break;

            for(int i = 0; i < text.length(); i++){
                tmp = text.charAt(i);

                if(tmp == '('){
                    c[p] = '(';
                    p++;
                }else if(tmp == '['){
                    c[p] = '[';
                    p++;
                }else if(tmp == ')'){
                    if(p > 0 && c[p - 1] == '('){
                        p--;
                    }else{
                        flag=false;
                    }
                }else if(tmp == ']'){
                    if(p > 0 && c[p - 1] == '['){
                        p--;
                    }else{
                        flag=false;
                    }
                }else if(tmp == '.'){
                    if(p == 0 && flag){
                        System.out.println("yes");
                        break;
                    }else{
                        System.out.println("no");
                        break;
                    }
                }
                if(i == text.length() - 1){
                    i = -1;
                    text = br.readLine();
                }
            }

        }
    }
}

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

int main() {
    while(true) {
        stack<char> cc;
        char c;
        bool success = true;
        string line;
        getline(cin, line);
        if(line == ".") break;
        for(int i = 0; i < line.size(); ++i) {
            c = line[i];
            if(c == '(') cc.push(')');
            if(c == '[') cc.push(']');
            if(c == ')') {
                if(!cc.empty() && cc.top() == ')') cc.pop();
                else success = false;
            }
            if(c == ']') {
                if(!cc.empty() && cc.top() == ']') cc.pop();
                else success = false;
            }
        }
        cout << ((success) ? "yes" : "no") << endl;
    }
    return 0;
}

C++: // clang-format off
#include <bits/stdc++.h>
#define int long long
#define main signed main()
// #define main int main()
#define loop(i, a, n) for (int i = (a); i < (n); i++)
#define rep(i, n) loop(i, 0, n)
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define prec(n) fixed << setprecision(n)
#define stlice(from, to) substr(from, (to) - (from) + 1)
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define fi first
#define se second
using namespace std;
using pii = pair<int, int>;
using vi = vector<int>;
using vd = vector<double>;
using vc = vector<char>;
using vb = vector<bool>;
using vs = vector<string>;
using vpii = vector<pii>;
using vvi = vector<vi>;
using vvb = vector<vb>;
using vvpii = vector<vpii>;
template<typename A> using fn = function<A>;
constexpr int INF = sizeof(int) == sizeof(long long) ? 1000000000000000000LL : 1000000000;
constexpr int MOD = 1000000007;
constexpr double PI = acos(-1);
template<typename A, typename B> bool cmin(A &a, const B &b) { return a > b ? (a = b, true) : false; }
template<typename A, typename B> bool cmax(A &a, const B &b) { return a < b ? (a = b, true) : false; }
constexpr bool odd(const int &n) { return n & 1; }
constexpr bool even(const int &n) { return !odd(n); }
void solve();
main { solve(); return 0; }
// clang-format on

void solve() {
  string s;
  while (getline(cin, s), s != ".") {
    stack<char> t;
    rep(i, s.size()) {
      if (s[i] == '[' || s[i] == '(') t.push(s[i]);
      if (s[i] == ')') {
        if (t.size() && t.top() == '(') {
          t.pop();
        } else {
          cout << "no" << endl;
          goto next;
        }
      }
      if (s[i] == ']') {
        if (t.size() && t.top() == '[') {
          t.pop();
        } else {
          cout << "no" << endl;
          goto next;
        }
      }
    }
    cout << (t.size() ? "no" : "yes") << endl;
  next:;
  }
}

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

int main()
{
	string str, str2;

	cin >> str;

	if (str[str.length() - 1] != '.')
	while (true)
	{
		string tmp;
		cin >> tmp;
		str += tmp;
		if (tmp[tmp.length() - 1] == '.')break;
	}

	while (cin >> str2)
	{
		if (str2[str2.length() - 1] != '.')
		while (true)
		{
			string tmp;
			cin >> tmp;
			str2 += tmp;
			if (tmp[tmp.length() - 1] == '.')break;
		}

		int f = 0;//( 1 [ 2
		bool judg = false;
		int tmp[2] = { 0, 0 };
		int i = 0;
		for (i = 0; i < str.length(); i++)
		{
			char c = str[i];
			if (f == 0){
				if (c == ')' && !tmp[0])break;
				if (c == ']' && !tmp[1])break;
			}
			if (f == 1)
			{
				if (c == ']')break;
				if (c == ')')f = 0;
			}
			if (f == 2)
			{
				if (c == ')')break;
				if (c == ']')f = 0;
			}

			if (c == '('){
				f = 1; tmp[0]++;
			}
			if (c == '['){
				f = 2; tmp[1]++;
			}
			if (c == ')'){
				tmp[0]--;
			}
			if (c == ']'){
				tmp[1]--;
			}
		}
		if (i == str.length())judg = true;
		if (judg)cout << "yes" << endl;
		else cout << "no" << endl;
		str = str2;
	}
	return 0;
}