blocknode.java

来自「一个JAVA编写的简单编译器」· Java 代码 · 共 58 行

JAVA
58
字号
package ast.statement;
// children : all assignment on this account block
public class BlockNode extends ast.statement.StatementNode {
  protected java.util.Vector children;
  
  public BlockNode () {
    children = new java.util.Vector ();
  }
  
  public void codegen () {
    int i = 1;
    for (java.util.Enumeration e = children.elements(); e.hasMoreElements(); ) {
      ast.IJSubNode node = (ast.IJSubNode)e.nextElement ();
      codegen.WriteCode.genComment ("Stat. " + i++);
      node.codegen ();
    }
  }  

  public int getDepth () {
    int depth = 0;
    for (int i = 0; i < children.size(); ++i) {
      ast.IJSubNode n = (ast.IJSubNode)children.elementAt(i);
      int ndepth = n.getDepth() + 1; 
      if (depth < ndepth)
        depth = ndepth;
    }
    return depth;
  }

  public void addChild(ast.IJSubNode n) {
    children.addElement (n);
  }

  public String toString () {
    return "{}";
  }
  public String toString (String prefix) {
    return prefix + "{}";
  }
  public void dump(String prefix) {
    System.out.println(prefix + toString());
    for (int i = 0; i < children.size(); ++i) {
      ast.IJSubNode n = (ast.IJSubNode)children.elementAt(i);
      n.dump(prefix + "  ");
    }
  }
  public String getXMLType () {
    return "block";
  }
  public void genXML (java.io.PrintStream p, String prefix) {
    p.println (prefix + "<block>");
    for (int i = 0; i < children.size(); ++i) {
      ast.IJSubNode n = (ast.IJSubNode)children.elementAt(i);
      n.genXML (p, prefix + "  ");
    }
    p.println (prefix + "</block>");
  }
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?