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 <string>
#include <stack>

using namespace std;

namespace Solver {

    string s;
    inline bool Read() {
        getline(cin, s);
        return s != ".";
    }

    inline void Work() {
        stack<char> stk;
        bool ok = true;
        for (int i = 0; i < s.length(); i++) {
            if (s[i] == '(' || s[i] == '[') {
                stk.push(s[i]);
            } else if (s[i] == ']') {
                if (stk.empty() || stk.top() != '[') {
                    ok = false;
                } else {
                    stk.pop();
                }
            } else if (s[i] == ')') {
                if (stk.empty() || stk.top() != '(') {
                    ok = false;
                } else {
                    stk.pop();
                }
            }
        }

        if (stk.empty() && ok) cout << "yes" << endl;
        else cout << "no" << endl;
    }

    inline void Solve() {
         while(Read()) Work();
    }
}

int main() {
    Solver::Solve();
}

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


string str;
int idx;
char c;

bool next(){
	if(idx < str.length()){
		c = str[idx++];
		return true;
	}else{
		return false;
	}
}

bool recur(){
	while(1){
		if(c == '('){
			if(!next()) return false;
			if(!recur()) return false;
			if(c != ')') return false;
		}else if(c == '['){
			if(!next()) return false;
			if(!recur()) return false;
			if(c != ']') return false;

		}else if(c == ')' || c == ']'){
			return true;
		}

		if(!next()) return true;
	}
}

int main(){
	while(getline(cin, str), str != "."){
		idx = 0;
		next();
		cout << (recur() && idx == str.length() ? "yes" : "no") << endl;

	}
}

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

int len=0;
void solve()
{
	stack<char>s;
	char c;
	int x=0;
	while(true)
	{
		c=getchar();
		if(c=='.')
		{
			if(len==0)break;
			if(x==0)cout<<"yes"<<endl;
			else cout<<"no"<<endl;		
			len=0;
			x=0;
			while(!s.empty())
			{
				s.pop();
			}
			continue;	
		}
		if(c=='\n')continue;
		len++;
		
		if(c=='(')
		{
			x++;
			s.push(c);
		}
		else if(c=='[')
		{
			x++;
			s.push(c);
		}
		else if(c==')')
		{
			x++;
			while(!s.empty())
			{
				if(s.top()=='(')
				{
					x-=2;
					s.pop();
					break;
				}
				s.pop();
			}
		}
		else if(c==']')
		{
			x++;
			while(!s.empty())
			{
				if(s.top()=='[')
				{
					x-=2;
					s.pop();
					break;
				}
				s.pop();
			}
		}
		else
		{
			s.push(c);
		}
	}
}

int main()
{
	solve();
	return 0;
}

C++: #include <iostream>
#include <cstdio>
#include <stack>
using namespace std;
string s;
bool ischar(char c){
	if('a'<=c && c<='z') return true;
	if('A'<=c && c<='Z') return true;
	if(c==' ') return true;
	return false;
}
bool solve(){
	stack<int> st;
	for(int i=0;i<s.size();i++){
		if(ischar(s[i])) continue;
		if(s[i]=='(') st.push(0);
		if(s[i]=='[') st.push(1);
		if(s[i]==')'){
			if(st.empty()) return 0;
			int s=st.top();
			st.pop();
			if(s==1) return 0;
		}
		if(s[i]==']'){
			if(st.empty()) return 0;
			int s=st.top();
			st.pop();
			if(s==0) return 0;
		}
		if(s[i]=='.'){
			if(st.empty()) return 1;
			else return 0;
		}
	}
	return 1;
}
int main(){
	while(true){
		getline(cin,s);
		if(s[0]=='.') break;
		if(solve()) printf("yes\n");
		else printf("no\n");
	}
	return 0;
}

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

bool issame(char a,char b){
     if(a=='(')return b==')';
     if(a=='[')return b==']';
}

int main(){
     while(1){
	  string str;
	  getline(cin,str);
	  if(str[0]=='.')return 0;
	  char in;
	  stack<char> sta;
	  bool iscorrect=true;
	  int count=0;
	  while(in=str[count],in!='.'){
	       //cout<<in;
	       if(in=='('||in=='['){
		    sta.push(in);
		    //cout<<in<<endl;
	       }else if(in==')'||in==']'){
		    if(sta.empty()){
			 iscorrect=false;
			 break;
		    }
		    if(!issame(sta.top(),in)){
			 iscorrect=false;
			 break;
		    }
		    sta.pop();
	       }
	       count++;
	  }
	  cout<<((iscorrect&&sta.empty())? "yes":"no")<<endl;
     }
}

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

int main(){
    char s[108];
    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] == '(') rnd++;
            if(s[i] == '[') box++;
            if(s[i] == ')') rnd--;
            if(s[i] == ']') box--;
            if(s[i] == '\0') break;
            if(rnd < 0 || box < 0){
                no = 1;
                break;
            }
        }
        if(no == 0 && rnd == 0 && box == 0){
            printf("yes\n");
        } else {
            printf("no\n");
        }
        cin.getline(s, 101);
    }
}

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

char c[101];

int main(){
while(1){	
	
	cin.getline(c, sizeof(c));
	//cout << "debug = " << c;
	if(c[0] == '.') break;
	
	int rl=0, rr=0, gl=0, gr=0;
	bool flag = true;
	int i = 0;
	while(c[i] != '.'){
		if(c[i] == '(') rl++;
		else if(c[i] == ')') rr++;
		else if(c[i] == '[') gl++;
		else if(c[i] == ']') gr++;
		
		//check!
		if(rl < rr) flag = false;
		if(gl < gr) flag = false;
		i++;
	}
	//check!
	if(rl != rr) flag = false;
	if(gl != gr) flag = false;
	
	if(flag) cout << "yes" << endl;
	else cout << "no" << endl;
	
}//end
	return 0;
}

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

int n;
char buf[11451419];

int main() {
  while (1) {
    fgets(buf, sizeof(buf), stdin);
    if (buf[0] == '.') return 0;

    stack<char> q;
    bool ans = true;

    n = strlen(buf);
    for (int i=0; i<n; i++) {
      char c = buf[i];
      if (c == '(' || c == '[') {
        q.push(c);
      } else if (c == ')') {
        if (q.empty()) ans = false;
        else {
          if (q.top() != '(') ans = false;
          q.pop();
        }
      } else if (c == ']') {
        if (q.empty()) ans = false;
        else {
          if (q.top() != '[') ans = false;
          q.pop();
        }
      }
    }

    if (!q.empty()) ans = false;

    if (!ans) puts("no");
    else puts("yes");
  }
}