public static <V> ScopeTree<V> createTree(ArrayList<Operation> code, TreeParser<V> parser) {
		ScopeTree<V> tree = null;
		ArrayList<Operation> a = new ArrayList<>();
		int depth = 0;
		for (Operation op : code) {
			if (op.op==OpType.BEGIN) {
				depth++;
				if (depth==1) {
					if (tree==null) {
						tree = new ScopeTree<>(parser.parse(a));
					} else {
						tree.addLine(parser.parse(a));
					}
					a = new ArrayList<>();
				} else {
					a.add(op);
				}
			} else if (op.op==OpType.END) {
				depth--;
				if (depth==0) {
					if (tree==null) {
						tree = createTree(a,parser);
					} else {
						tree.addBlock(createTree(a,parser));
					}
					a = new ArrayList<>();
				} else {
					a.add(op);
				}
			} else {
				a.add(op);
			}
		}
		
		if (tree==null) {
			tree = new ScopeTree<>(parser.parse(a));
		} else {
			tree.addLine(parser.parse(a));
		}
		return tree;
	}