import java.util.Scanner;

/**
 * Parser for simple expressions.
 * 
 * @author Paul Chew
 * 
 * Created for CS211, Sept 2005.
 */
public class SimpleExpressionCodeGenerator {
    
    /**
     * Main program.
     */
    public static void main (String[] args) {
        String code = null;
        Scanner sc = new Scanner(System.in);
        String line = sc.nextLine();
        while (line.length() != 0) {
            System.out.println(line);
            Scanner scanner = new Scanner(line);
            try {
                code = parseE(scanner) + "STOP\n";
                if (scanner.hasNext()) error("Extra token: " + scanner.next());
            } catch (RuntimeException e) {
                code = "ERROR\n";
            }
            System.out.println(code);
            line = sc.nextLine();
        }
        System.out.println("Exiting");
    }
    
    /**
     * Print error message and throw an exception.
     * @param message the error message
     * @throws RuntimeException
     */
    public static void error (String message) {
        System.err.println(message);
        throw new RuntimeException();
    }
    
    /**
     * Check that scanner's next token matches the given string.
     * @param scanner the scanner
     * @param string the String to look for
     */
    public static void check (Scanner scanner, String string) {
        if (!scanner.hasNext()) error("Missing token: " + string);
        String token = scanner.next();
        if (!token.equals(string)) error("Expected " + string + ", but found " + token);
    }
    
    /**
     * Parse E, a simple expression.
     * @param scanner the scanner
     * @return the code for this expression
     */
    public static String parseE (Scanner scanner) {
        if (scanner.hasNextInt()) return "PUSH " + scanner.nextInt() + "\n";
        check(scanner, "(");
        String c1 = parseE(scanner);
        check(scanner, "+");
        String c2 = parseE(scanner);
        check(scanner, ")");
        return c1 + c2 + "ADD\n";
    }
}