2 import java.util.Vector;
5 public class BlockNode extends TreeNode {
6 Vector blockstatements;
8 protected SymbolTable table;
10 public final static int NORMAL=0;
11 public final static int NOBRACES=1;
12 public final static int EXPRLIST=2;
17 blockstatements=new Vector();
18 table=new SymbolTable();
21 public SymbolTable getVarTable() {
25 public void addBlockStatement(BlockStatementNode bsn) {
26 blockstatements.add(bsn);
29 public void addFirstBlockStatement(BlockStatementNode bsn) {
30 blockstatements.insertElementAt(bsn,0);
33 public void addBlockStatementAt(BlockStatementNode bsn, int i) {
34 blockstatements.insertElementAt(bsn,i);
37 public void setStyle(int style) {
42 return blockstatements.size();
45 public BlockStatementNode get(int i) {
46 return (BlockStatementNode) blockstatements.get(i);
49 public String printNode(int indent) {
50 if (printStyle==NORMAL) {
52 for(int i=0; i<blockstatements.size(); i++) {
53 BlockStatementNode bsn=(BlockStatementNode)blockstatements.get(i);
54 st+=printSpace(indent+INDENT)+bsn.printNode(indent+INDENT);
55 if (!((bsn instanceof SubBlockNode)||
56 (bsn instanceof LoopNode)||
57 (bsn instanceof IfStatementNode)))
59 if (bsn instanceof IfStatementNode)
62 st+=printSpace(indent)+"}";
64 } else if (printStyle==NOBRACES) {
66 for(int i=0; i<blockstatements.size(); i++) {
67 BlockStatementNode bsn=(BlockStatementNode)blockstatements.get(i);
68 st+=printSpace(indent)+bsn.printNode(indent);
69 if (!((bsn instanceof SubBlockNode)||
70 (bsn instanceof LoopNode)||
71 (bsn instanceof IfStatementNode)))
75 } else if (printStyle==EXPRLIST) {
77 for(int i=0; i<blockstatements.size(); i++) {
78 BlockStatementNode bsn=(BlockStatementNode)blockstatements.get(i);
80 if ((i+1)!=blockstatements.size())
84 } else throw new Error();
88 return Kind.BlockNode;
91 public void setLabel(String l) {
95 public String getLabel() {