public enum DFAType
{
    single_input,
    file_input,
    eval_input,
    decorator,
    decorators,
    decorated,
    async_funcdef,
    funcdef,
    parameters,
    typedargslist,
    tfpdef,
    varargslist,
    vfpdef,
    stmt,
    simple_stmt,
    small_stmt,
    expr_stmt,
    testlist_star_expr,
    augassign,
    del_stmt,
    pass_stmt,
    flow_stmt,
    break_stmt,
    continue_stmt,
    return_stmt,
    yield_stmt,
    raise_stmt,
    import_stmt,
    import_name,
    import_from,
    import_as_name,
    dotted_as_name,
    import_as_names,
    dotted_as_names,
    dotted_name,
    global_stmt,
    nonlocal_stmt,
    assert_stmt,
    compound_stmt,
    async_stmt,
    if_stmt,
    while_stmt,
    for_stmt,
    try_stmt,
    with_stmt,
    with_item,
    except_clause,
    suite,
    test,
    test_nocond,
    lambdef,
    lambdef_nocond,
    or_test,
    and_test,
    not_test,
    comparison,
    comp_op,
    star_expr,
    expr,
    xor_expr,
    and_expr,
    shift_expr,
    arith_expr,
    term,
    factor,
    power,
    atom_expr,
    atom,
    testlist_comp,
    trailer,
    subscriptlist,
    subscript,
    sliceop,
    exprlist,
    testlist,
    dictorsetmaker,
    classdef,
    arglist,
    argument,
    comp_iter,
    comp_for,
    comp_if,
    encoding_decl,
    yield_expr,
    yield_arg,

/* The follow dfa type are copyed from TokState.java */
/* The follow type a used to make analyze easier */

    ENDMARKER,
    NAME,
    NUMBER,
    STRING,
    NEWLINE,
    INDENT,
    DEDENT,
    LPAR,   // (
    RPAR,   // )
    LSQB,   // [
    RSQB,   // ]
    COLON,  // :
    COMMA,  // ,
    SEMI,   // ;
    PLUS,   // +
    MINUS,  // -
    STAR,   // *
    SLASH,  // /
    VBAR,   // |
    AMPER,  // &
    LESS,   // <
    GREATER,    // >
    EQUAL,  // =
    DOT,    // .
    PERCENT,    // %
    BACKQUOTE,
    LBRACE, // {
    RBRACE, // }
    EQEQUAL,    // ==
    NOTEQUAL,   // !=
    LESSEQUAL,  // <=
    GREATEREQUAL,   // >=
    TILDE,  // ~
    CIRCUMFLEX, // ^
    LEFTSHIFT,  // <<
    RIGHTSHIFT, // >>
    DOUBLESTAR, // **
    PLUSEQUAL,  // +=
    MINEQUAL,   // -=
    STAREQUAL,  // *=
    SLASHEQUAL, // /=
    PERCENTEQUAL,   // %=
    AMPEREQUAL, // &=
    VBAREQUAL,  // |=
    CIRCUMFLEXEQUAL,    // ^=
    LEFTSHIFTEQUAL, // <<=
    RIGHTSHIFTEQUAL,    // >>=
    DOUBLESTAREQUAL,    // **=
    DOUBLESLASH,    // \\
    DOUBLESLASHEQUAL,   // \\=
    AT, // @
    ATEQUAL,    // @=
    RARROW, // ->
    ELLIPSIS,   // ...
    OP,
    AWAIT,  // await
    ASYNC,  // async
    ERRORTOKEN,
    N_TOKENS,
} public final class Py
{
    public final static PyNone None = new PyNone();
    public final static PyBoolean True = new PyBoolean(true);
    public final static PyBoolean False = new PyBoolean(false);

    public static String encoding = "utf-8";

    private final static PyLong[] integerCache = new PyLong[Config.NSMALLPOSINTS
            - Config.NSMALLNEGINTS];

    static
    {
        for (int i = 0; i < Config.NSMALLPOSINTS - Config.NSMALLNEGINTS; i++)
        {
            integerCache[i] = new PyLong(Config.NSMALLNEGINTS + i);
        }
    }
    
    public static final PyLong newInteger(int i)
    {
        if(i < Config.NSMALLPOSINTS && i > Config.NSMALLNEGINTS)
        {
            return integerCache[(int)i - Config.NSMALLNEGINTS];
        }
        return new PyLong(i);
    }
    
    public static final PyLong newInteger(long i)
    {
        if(i < Integer.MIN_VALUE || i > Integer.MAX_VALUE)
        {
            return newInteger((int)i);
        }
        else
        {
            return new PyLong(i);
        }
    }
    
    public static PyObject PyNumber_InPlaceOr(PyObject v, PyObject w)
    {
    	return null;
    }
} public class PyBytes extends PyObject
{
    public byte[] bytes;

    public PyBytes(byte[] bytes)
    {
        this.bytes = bytes;
    }

    public PyBytes(String str)
    {
        this.bytes = str.getBytes();
    }

    public PyBytes concat(PyBytes pyBytes)
    {
        byte[] concatedBytes = pyBytes.bytes;
        byte[] newBytes = new byte[bytes.length + concatedBytes.length];
        System.arraycopy(bytes, 0, newBytes, 0, bytes.length);
        System.arraycopy(concatedBytes, 0, newBytes, bytes.length,
                concatedBytes.length);
        return new PyBytes(newBytes);
    }
}
 public class PyComplex extends PyObject
{
    double real;
    double imag;

    public PyComplex(double real, double imag)
    {
        this.real = real;
        this.imag = imag;
    }
}
 public class PyExceptions extends RuntimeException
{
    private static final long serialVersionUID = -5566345378602605958L;

    public static enum ErrorType
    {
        AST_ERROR, 
        PARSER_ERROR, 
        SYSTEM_ERROR, 
        SYMTABLE_ERROR,
        SYNTAX_ERROR
    }

    public Stack<String> map = new Stack<String>();
    public Token tok;

    public PyExceptions()
    {
        super();
    }

    public PyExceptions(String msg)
    {
        super(msg);
        map.push(msg);
    }

    public PyExceptions(String msg, Throwable cause)
    {
        super(msg, cause);
    }

    public PyExceptions(ErrorType type, String msg)
    {
        this(type, msg, 0, 0);
    }
    
    public PyExceptions(ErrorType type, String msg, int lineno, int colOffset)
    {
        super(msg);
        msg += "\nlineno: " + lineno + ", colOffset: " + colOffset; 
        map.push(msg);
    }

    public PyExceptions(String msg, Node n)
    {
        this(null, msg, n);
    }

    public PyExceptions(ErrorType type, String msg, Node n)
    {
        super(msg);
        msg = msg + "\n" + "line: " + n.lineNo + " colOffset: " + n.colOffset
                + "\n" + n.dfaType + " " + n.str;
        map.push(msg);
    }

    public PyExceptions(String msg, Token tok)
    {
        super(msg);
        msg = "line: " + tok.lineNo + "\n"
                + tok.buf.substring(tok.lineStart, tok.lineEnd) + "\n" + msg;
        map.push(msg);
        this.tok = tok;
    }

    public PyExceptions(ErrorType type, String msg, PyObject obj)
    {
        super(msg);
        map.push(msg);
    }

    public String toString()
    {
        String msg = "";
        while (!map.empty())
        {
            msg += map.pop() + "\n";
        }
        return msg;
    }

    public void printStackTrace()
    {
        String msg = "";
        while (!map.empty())
        {
            msg += map.pop() + "\n";
        }
        if(msg.length() > 0)
        {
            System.err.println(msg);
        }
        else
        {
            super.printStackTrace();
        }
    }
} public static enum ErrorType
{
    AST_ERROR, 
    PARSER_ERROR, 
    SYSTEM_ERROR, 
    SYMTABLE_ERROR,
    SYNTAX_ERROR
} public class PyFloat extends PyObject
{
    double num;

    public PyFloat(double num)
    {
        this.num = num;
    }

    public PyFloat(String str)
    {

    }
}
 public class PyLong extends PyObject
{
    private long num;

    public PyLong(long num)
    {
        this.num = num;
    }

    public static PyObject newLong(String str)
    {
        // TODO check the str is too much longer
        if (str.length() <= 1)
        {
            return new PyLong(Long.parseLong((str)));
        }
        try
        {
            if (str.charAt(1) == 'x' || str.charAt(1) == 'X')
            {
                return new PyLong(Long.parseLong(str.substring(2), 16));
            }
            else if (str.charAt(1) == 'b' || str.charAt(1) == 'B')
            {
                return new PyLong(Long.parseLong(str.substring(2), 2));
            }
            else if (str.charAt(1) == 'o' || str.charAt(1) == 'O')
            {
                return new PyLong(Long.parseLong(str.substring(2), 8));
            }
            else
            {
                return new PyLong(Long.parseLong((str)));
            }
        }
        catch (NumberFormatException err)
        {
            //System.out.println(str);
            return new PyNumber(str);
        }
    }

    public long asLong()
    {
        return num;
    }
} public class PyObject
{

}
 public class PyUnicode extends PyObject
{
    String str;

    public PyUnicode(byte[] b, String encode)
    {
        try
        {
            this.str = new String(b, encode);
        }
        catch (UnsupportedEncodingException e)
        {
            // TODO Auto-generated catch block
            e.printStackTrace();
            throw new PyExceptions(ErrorType.SYSTEM_ERROR,
                    "Can't convert bytes to str implicitly");
        }
    }

    public static PyUnicode internFromString(String str)
    {
        return internFromString(str, false);
    }

    public static PyUnicode internFromString(String str, boolean rawmode)
    {
        return new PyUnicode(str, rawmode);
    }

    private PyUnicode(String str, boolean rawmode)
    {
        this.str = str;
        if(!rawmode)
        {
            // FIXME should use faster and more complete method
            this.str.replace("\\n", "\n");
            this.str.replace("\\t", "\t");
            this.str.replace("\\\\", "\\");
        }
    }

    private PyUnicode(PyObject obj)
    {
        // TODO
    }

    public static PyUnicode concat(PyObject left, PyObject right)
    {
        if(!(left instanceof PyUnicode))
        {
            throw new PyExceptions(ErrorType.SYSTEM_ERROR, "transform error",
                    left);
        }

        return ((PyUnicode) left).concat(right);
    }

    public PyUnicode concat(PyObject obj)
    {
        if(!(obj instanceof PyUnicode))
        {
            throw new PyExceptions(ErrorType.SYSTEM_ERROR, "transform error",
                    obj);
        }

        String newStr = this.str + ((PyUnicode) obj).str;
        return internFromString(newStr);

    }

}
import java.util.ArrayList;
import pers.xia.jpython.ast.*;
import pers.xia.jpython.grammar.DFAType;
import pers.xia.jpython.object.Py;
import pers.xia.jpython.object.PyBytes;
import pers.xia.jpython.object.PyComplex;
import pers.xia.jpython.object.PyExceptions;
import pers.xia.jpython.object.PyExceptions.ErrorType;
import pers.xia.jpython.object.PyFloat;
import pers.xia.jpython.object.PyLong;
import pers.xia.jpython.object.PyObject;
import pers.xia.jpython.object.PyUnicode;
package pers.xia.jpython.parser;



public class Ast
{
    private static enum COMP
    {
        COMP_GENEXP, COMP_LISTCOMP, COMP_SETCOMP
    }

    /*
     * Test the node's type is or not the assigened type
     */
    private void REQ(Node n, DFAType type)
    {
        try
        {
            assert(n.dfaType == type);
        }
        catch (PyExceptions e)