/*
 * Created on 2004/12/14
 *
 */

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Stack;


/**
 * 足し算と引き算の式を評価し二進木を表示するプログラム
 * 
 * @author rocky
 * @version $Id: ExpressionTree.java,v 1.2 2004/12/16 05:19:43 rintaro Exp $
 */
public class ExpressionTree {

    public static void main(String[] args) {
        ExpressionTree sample = new ExpressionTree();
        sample.main();
    }
    
    /****************************************************
     * インスタンス変数
     ****************************************************/
    
    private String input = "";//入力された文字列
    private char currentChar;
    private int index = 0;

    /****************************************************
     * メイン
     ****************************************************/
    
    /**
     * 式を評価しに二進木を表示する
     */
    public void main(){
        
        //式の読み込み
        System.out.print("式を入力してください>>");
        input = getString();
        gettoken();
        
        //式を評価する
        Node root = expression();
        
        //木構造を表示する
        displayTree(root);
        
    }
    
    /****************************************************
     * 式の評価関連
     ****************************************************/    

    /**
     * 式を評価する
     */
    public Node expression(){
        
        Node node = term();
        while(currentChar == '+'||currentChar == '-'){
            char operator = currentChar;
            gettoken();
            node = makeTree(operator,node,term());
        }
        
        return node;
    }
    
    /**
     * 項を評価する
     */
    public Node term(){
        
        Node node = factor();        
        return node;
    }
    
    /**
     * 因子を評価する
     */
    public Node factor(){
        
        Node node = makeLeaf(currentChar);
        gettoken();
        return node;
    }
    
    /****************************************************
     * 二進木関連
     ****************************************************/
    
    /**
     * 二進木のノードを作る
     */
    public Node makeTree(char ch,Node leftChild,Node rightChild){
        
        Node node = new Node();
        
        node.element = ch;
        node.leftChild = leftChild;
        node.rightChild = rightChild;
        
        return node;
    }
    
    /**
     * 二進木の葉を作る
     */
    public Node makeLeaf(char ch){
        
        Node node = new Node();
        
        node.element = ch;
        node.leftChild = null;
        node.rightChild = null;
        
        return node;
    }

    /****************************************************
     * 文字入力関連
     ****************************************************/    
 
    /**
     * 入力された文字列を取得する
     */
    public String getString(){
        
        InputStreamReader isr = new InputStreamReader(System.in);
        BufferedReader br = new BufferedReader(isr);
        String s = "";
        try {
            s = br.readLine();
        } catch (IOException e) {
            e.printStackTrace();
        }
        return s;
    }    
    
    /**
     * トークンを切り出す
     */
    public void gettoken(){
        
        if(index > input.length()-1)return;
        currentChar = input.charAt(index++);
    }
    
    /****************************************************
     * 表示関連
     ****************************************************/    

    /**
     * 二分木の内容を表示する
     */
    public static void displayTree(Node root) {
        
        Stack globalStack = new Stack();
        globalStack.push(root);
        int nBlanks = 32;
        boolean isRowEmpty = false;
        System.out
                .println("......................................................");
        while (isRowEmpty == false) {
            Stack localStack = new Stack();
            isRowEmpty = true;

            for (int j = 0; j < nBlanks; j++)
                System.out.print(' ');

            while (globalStack.isEmpty() == false) {
                Node temp = (Node) globalStack.pop();
                if (temp != null) {
                    System.out.print(temp.element);
                    localStack.push(temp.leftChild);
                    localStack.push(temp.rightChild);

                    if (temp.leftChild != null || temp.rightChild != null)
                        isRowEmpty = false;
                } else {
                    System.out.print("--");
                    localStack.push(null);
                    localStack.push(null);
                }
                for (int j = 0; j < nBlanks * 2 - 2; j++)
                    System.out.print(' ');
            }
            System.out.println();
            nBlanks /= 2;
            while (localStack.isEmpty() == false)
                globalStack.push(localStack.pop());
        }
        System.out
                .println("......................................................");
    }
}

/**
 * ノードクラス
 * 
 * @author rocky
 * @version $Id: ExpressionTree.java,v 1.2 2004/12/16 05:19:43 rintaro Exp $
 */
class Node{
    
    public char element;
    public Node leftChild;
    public Node rightChild;
}