public void addElse(ElseExpression elseExp) { elseBlock = elseExp; }
public IfExpression parseIfExpression() { IfExpression ifExp = new IfExpression(); ElseIfExpression elseIfExp; ElseExpression elseExp; nextTokenIfEquals(Token.TokenValue.IF); nextTokenIfEquals(Token.TokenValue.LPAR); if (currentTokenEquals(Token.TokenValue.RPAR)) { throw new EmptyExpression(lineNumber, colNumber); } ifExp.condition = parseSimpleExpression(); if (ifExp.condition.getExpressionType() != ObjectType.booleanType) { throw new IncompatibleTypesException(lineNumber, colNumber, ObjectType.booleanType, ifExp.condition.getExpressionType()); } nextTokenIfEquals(Token.TokenValue.RPAR); nextTokenIfEquals(Token.TokenValue.LBRACE); //if(e){} if (currentTokenEquals(Token.TokenValue.RBRACE)) { ifExp.body = null; nextToken(); } //if(e){ e } else { ifExp.body = parseExpression(); nextTokenIfEquals(Token.TokenValue.RBRACE); } while (currentTokenEquals(Token.TokenValue.ELSEIF)) { elseIfExp = new ElseIfExpression(); nextToken(); nextTokenIfEquals(Token.TokenValue.LPAR); if (currentTokenEquals(Token.TokenValue.RPAR)) { throw new EmptyExpression(lineNumber, colNumber); } elseIfExp.condition = parseSimpleExpression(); if (elseIfExp.condition.getExpressionType() != ObjectType.booleanType) { throw new IncompatibleTypesException(lineNumber, colNumber, ObjectType.booleanType, elseIfExp.condition.getExpressionType()); } nextTokenIfEquals(Token.TokenValue.RPAR); nextTokenIfEquals(Token.TokenValue.LBRACE); //else if(e){} if (currentTokenEquals(Token.TokenValue.RBRACE)) { elseIfExp.corps = null; nextToken(); } //else if(e){ e } else { elseIfExp.corps = parseExpression(); nextTokenIfEquals(Token.TokenValue.RBRACE); } ifExp.addElseIf(elseIfExp); } if (currentTokenEquals(Token.TokenValue.ELSE)) { elseExp = new ElseExpression(); nextToken(); nextTokenIfEquals(Token.TokenValue.LBRACE); //else{} if (currentTokenEquals(Token.TokenValue.RBRACE)) { elseExp.body = null; nextToken(); } //else{ e } else { elseExp.body = parseExpression(); nextTokenIfEquals(Token.TokenValue.RBRACE); } ifExp.addElse(elseExp); } return ifExp; }