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);
    if (str == ".") {
      return 0;
    }
    solve();
  }
}

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

int main(){
		string s;
		while(getline(cin, s) and s != "."){
				s = regex_replace(s, regex("[a-zA-Z \\.]"), "");
				while(s!=""){
						string before = s;
						s = regex_replace(s, regex("\\(\\)|\\[\\]"), "");
						if(s==before) break;
				}
				cout << ((s=="")?"yes":"no") << endl;
		}
}

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

using namespace std;

stack<char> a; // ()
stack<char> b; // []
string input;

int main() {
	bool yes;
	while(1) {
		while(!a.empty()) a.pop();
		while(!b.empty()) b.pop();
		yes = true;
		getline(cin,input);
		if (input == ".") break;
		for(int i=0; input[i] != '.'; i++) {
			if(input[i]=='(') a.push(input[i]);
			if(input[i]=='[') b.push(input[i]);
			if(input[i]==')'){
				if(a.empty()) yes = false;
				else a.pop();
			}
			if(input[i]==']'){
				if(b.empty()) yes = false;
				else b.pop();
			}
			//cout << input[i] << ":" << yes << endl;
		}
		if (!a.empty() || !b.empty()) yes = false;
		if (yes) cout << "yes" << endl;
		else cout << "no" << endl;
	}
	return 0;
}

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

int main(){
	string str;
	while(1){
		getline(cin, str);
		if(str==".") break;
		stack<char> B;
		B.push(0);
		bool judge = false;

		for(int i=0;i<str.length();i++){
			if(str[i]=='(' | str[i]=='['){
				B.push(str[i]);
			} else if(str[i]==')'){
				if(B.empty() || B.top()!='(') break;
				else B.pop();
			} else if(str[i]==']'){
				if(B.empty() || B.top()!='[') break;
				else B.pop();
			}
			if(i==str.length()-1) judge = true;
		}
		cout<< ((judge) ? "yes" : "no" )<<endl;
	}

	return 0;
}

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

int main()
{
	stack<int> S;
	string str;
	for(;;)
	{
		getline(cin,str);
		if(str==".")break;
		int n=str.size();
		for(int i=0;i<n;i++)
		{
			if(str[i]=='(')
			{
				S.push(1);
			}
			else if(str[i]=='[')
			{
				S.push(0);
			}
			else if(str[i]==')')
			{
				if(S.top()==1)
				{
					S.pop();
				}
				else
				{
					cout<<"no"<<endl;
					continue;
				}
			}
			else if(str[i]==']')
			{
				if(S.top()==0)
				{
					S.pop();
				}
				else
				{
					cout<<"no"<<endl;
					continue;
				}
			}
		}
		cout<<"yes"<<endl;
	}
	return 0;
}

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

#define int long long

signed main()
{
    string s;
    cin.get();
    while(getline(cin, s), s!=".") {
        stack<int> st;
        int f = 0;
        for(int i=0; i<s.size(); ++i) {
            char c = s[i];
            if(c=='(') st.push(0);
            else if(c=='[') st.push(1);
            else if(c==')') {
                if(st.empty()) {
                    cout << "no" << endl;
                    f++;
                    break;
                }
                if(st.top() == 0) st.pop();
                else {
                    cout << "no" << endl;
                    f++;
                    break;
                }
            }
            else if(c==']') {
                if(st.empty()) {
                    cout << "no" << endl;
                    f++;
                    break;
                }
                if(st.top() == 1) st.pop();
                else {
                    cout << "no" << endl;
                    f++;
                    break;
                }
            }
        }
        if(f==0) cout << "yes" << endl;
    }
    return 0;
}

C++: #include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <cstdio>
#define F(i,n) for(int i=0;i<(int)(n);i++)
#define INF 100000000
#define ll long long

using namespace std;
typedef pair<int, int> P;

int main() {
	char a,b;
	int ans,i,p=0;
	stack<int> s;
	while (1) {
		ans = 0;
		i = 0;
		while (s.size()!=0) {
			s.pop();
		}
		while (1) {
			a = getchar();
			if (a == '\n')a = getchar();
			if (i == 0 && a == '.') {
				p = 1;
				break;
			}
			if (a == '.') {
				if (s.size()!=0 ){
					ans = 1;
					break;
				}
				break;
			}
			if (a == '(')s.push(1);
			if (a == '[')s.push(2);
			if (a == ')') {
				if (s.size() == 0) {
					ans = 1;
					continue;
				}
				if (s.top() == 1) {
					s.pop();
				}
				else {
					ans = 1;
				}
			}
			if (a == ']') {
				if (s.size() == 0) {
					ans = 1;
					continue;
				}
				if (s.top() == 2) {
					s.pop();
				}
				else {
					ans = 1;
				}
			}
			i = 1;

		}
		if (p == 1)break;
		if (ans == 0)cout << "yes" << endl;
		else cout << "no" << endl;
	}
	return 0;
}

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

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