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;
15 blockstatements=new Vector();
16 table=new SymbolTable();
19 public SymbolTable getVarTable() {
23 public void addBlockStatement(BlockStatementNode bsn) {
24 blockstatements.add(bsn);
27 public void setStyle(int style) {
32 return blockstatements.size();
35 public BlockStatementNode get(int i) {
36 return (BlockStatementNode) blockstatements.get(i);
39 public String printNode(int indent) {
40 if (printStyle==NORMAL) {
42 for(int i=0;i<blockstatements.size();i++) {
43 BlockStatementNode bsn=(BlockStatementNode)blockstatements.get(i);
44 st+=printSpace(indent+INDENT)+bsn.printNode(indent+INDENT);
45 if (!((bsn instanceof SubBlockNode)||
46 (bsn instanceof LoopNode)||
47 (bsn instanceof IfStatementNode)))
49 if (bsn instanceof IfStatementNode)
52 st+=printSpace(indent)+"}";
54 } else if (printStyle==NOBRACES) {
56 for(int i=0;i<blockstatements.size();i++) {
57 BlockStatementNode bsn=(BlockStatementNode)blockstatements.get(i);
58 st+=printSpace(indent)+bsn.printNode(indent);
59 if (!((bsn instanceof SubBlockNode)||
60 (bsn instanceof LoopNode)||
61 (bsn instanceof IfStatementNode)))
65 } else if (printStyle==EXPRLIST) {
67 for(int i=0;i<blockstatements.size();i++) {
68 BlockStatementNode bsn=(BlockStatementNode)blockstatements.get(i);
70 if ((i+1)!=blockstatements.size())
74 } else throw new Error();
78 return Kind.BlockNode;