50 lines
1.3 KiB
Java
Executable File
50 lines
1.3 KiB
Java
Executable File
package frontend.ast.block;
|
|
|
|
import java.util.ArrayList;
|
|
|
|
import error.Errors;
|
|
import frontend.ast.Node;
|
|
import frontend.ast.SyntaxType;
|
|
import frontend.lexer.TokenStream;
|
|
import frontend.lexer.TokenType;
|
|
import frontend.ast.token.TokenNode;
|
|
|
|
public class Block extends Node {
|
|
private boolean isFuncBlock;
|
|
|
|
public Block(TokenStream ts) {
|
|
super(SyntaxType.BLOCK, ts);
|
|
isFuncBlock = false;
|
|
}
|
|
|
|
public void parse(Errors errors) {
|
|
TokenNode lbrace = new TokenNode(this.ts);
|
|
addChild(lbrace);
|
|
while (getCurrToken().getType() != TokenType.RBRACE) {
|
|
BlockItem bit = new BlockItem(this.ts);
|
|
bit.parse(errors);
|
|
addChild(bit);
|
|
}
|
|
TokenNode rbrace = new TokenNode(this.ts);
|
|
addChild(rbrace);
|
|
}
|
|
|
|
public ArrayList<BlockItem> getBlockItems() {
|
|
ArrayList<BlockItem> blockItems = new ArrayList<>();
|
|
for (int i = 0; i < getChildren().size(); i++) {
|
|
if (getChild(i) instanceof BlockItem) {
|
|
blockItems.add((BlockItem) getChild(i));
|
|
}
|
|
}
|
|
return blockItems;
|
|
}
|
|
|
|
public boolean isFuncBlock() {
|
|
return isFuncBlock;
|
|
}
|
|
|
|
public void setIsFuncBlock(boolean isFuncBlock) {
|
|
this.isFuncBlock = isFuncBlock;
|
|
}
|
|
}
|