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 addFirstBlockStatement(BlockStatementNode bsn) {
28 blockstatements.insertElementAt(bsn,0);
31 public void setStyle(int style) {
36 return blockstatements.size();
39 public BlockStatementNode get(int i) {
40 return (BlockStatementNode) blockstatements.get(i);
43 public String printNode(int indent) {
44 if (printStyle==NORMAL) {
46 for(int i=0; i<blockstatements.size(); i++) {
47 BlockStatementNode bsn=(BlockStatementNode)blockstatements.get(i);
48 st+=printSpace(indent+INDENT)+bsn.printNode(indent+INDENT);
49 if (!((bsn instanceof SubBlockNode)||
50 (bsn instanceof LoopNode)||
51 (bsn instanceof IfStatementNode)))
53 if (bsn instanceof IfStatementNode)
56 st+=printSpace(indent)+"}";
58 } else if (printStyle==NOBRACES) {
60 for(int i=0; i<blockstatements.size(); i++) {
61 BlockStatementNode bsn=(BlockStatementNode)blockstatements.get(i);
62 st+=printSpace(indent)+bsn.printNode(indent);
63 if (!((bsn instanceof SubBlockNode)||
64 (bsn instanceof LoopNode)||
65 (bsn instanceof IfStatementNode)))
69 } else if (printStyle==EXPRLIST) {
71 for(int i=0; i<blockstatements.size(); i++) {
72 BlockStatementNode bsn=(BlockStatementNode)blockstatements.get(i);
74 if ((i+1)!=blockstatements.size())
78 } else throw new Error();
82 return Kind.BlockNode;