import java.io.*;
import java.util.Scanner;

public class LinZScan
{
	BufferedReader source;
	int state;
	public int attribVal;

	// Tokens
	public static final int EOF = 10;
	public static final int NUM = 11;
	public static final int PLUS = 12;
	public static final int TIMES = 13;
	public static final int MINUS = 14;
	public static final int LBRACE = 15;
	public static final int RBRACE = 16;
	// Names
	static String[] names = {"EOF","NUM","PLUS","TIMES",
						"MINUS","LBRACE","RBRACE"};

	public LinZScan(String s)
	{
		 source = new BufferedReader(new StringReader(s));
	}

	boolean isZDigit(char c)
	{
		return "o|/-\\".contains(""+c);
	}

	int zValue(char c)
	{
		return "o|/-\\".indexOf(c);
	}

	int getToken() throws java.io.IOException
	{
		state = 0;
		while(true)
		{
			int c1 = source.read();
			if (c1 < 0)
			{
				if (state == 1)
				{
					return NUM;
				}
				else
				{
					return EOF;
				}
			}
			char c = (char)c1;
			switch(state)
			{
				case 0: if (isZDigit(c))
						{
							attribVal = zValue(c);
							state = 1;
							source.mark(1);
						}
						else if (c == '>')
						{
							state = 2;
						}
						else if (c == '+')
						{
							state = 3;
						}
						else if (c == '=')
						{
							state = 4;
						}
						else
						{
							state = 0;
							System.out.println("unexpected character: " + c);
						}
						break;
				case 1: if (isZDigit(c))
						{
							attribVal = attribVal*5 + zValue(c);
							// stay in state 1
							source.mark(1);
						}
						else
						{
							source.reset(); // Put back the extra character
							return NUM; // Numeric value in attribVal
						}
						break;
				case 2: if (c == '=')
						{
							return PLUS;
						}
						else if (c == '#')
						{
							return TIMES;
						}
						else if (c == '>')
						{
							return MINUS;
						}
						else
						{
							state = 0;
							System.out.println("unexpected character: " + c);
						}
						break;
				case 3: if (c == '=')
						{
							return LBRACE;
						}
						else
						{
							state = 0;
							System.out.println("unexpected character: " + c);
						}
						break;
				case 4: if (c == '+')
						{
							return RBRACE;
						}
						else
						{
							state = 0;
							System.out.println("unexpected character: " + c);
						}
						break;
			}
		}
	}

	public static void main(String[] args)
	{
		int tok = 0;

		Scanner kb = new Scanner(System.in);
		System.out.print("Enter LinearZ expression: ");
		String expr = kb.nextLine();
		LinZScan scan = new LinZScan(expr);
		//int count = 0;
		do
		{
			try
			{
				tok = scan.getToken();
			} catch(IOException e){
				System.out.println("IO error");
			}
			System.out.println(names[tok-10]);
			if (tok == NUM)
				System.out.println("value: "+scan.attribVal);
			//if (++count > 10)
			//	break;
		} while (tok != EOF);


	}
}
