/*
 * Created on 2004/12/14
 *
 */

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Stack;


/**
 * 足し算と引き算の式を評価し二進木を表示するプログラム
 * (擬似コード対応版)
 *
 * @author rocky
 * @version 2005/1/13
 */
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();
        
        //式を評価する
        Node root = expression();
        
        //木構造を表示する
        displayTree(root);
        
    }
    
    /****************************************************
     * 式の評価関連
     ****************************************************/    

    /**
     * 式を評価する
     */
    public Node expression(){
        
        Node node = term();
        gettoken();
        while(currentChar == '+'||currentChar == '-'){
            char operator = currentChar;
            node = makeTree(operator,node,term());
            gettoken();
        }
        
        return node;
    }
    
    /**
     * 項を評価する
     */
    public Node term(){
        
        Node node = factor();        
        return node;
    }
    
    /**
     * 因子を評価する
     */
    public Node factor(){

        gettoken();
        Node node = makeLeaf(currentChar);
        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.1 2005/01/13 03:18:51 rintaro Exp $
 */
class Node{
    
    public char element;
    public Node leftChild;
    public Node rightChild;
}