Implements if, elseif and else statements
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
2019-06-08 14:25:15 +02:00
parent f4a3918947
commit e233616b8e
10 changed files with 187 additions and 2 deletions

View File

@@ -16,7 +16,8 @@ enum class ParsedStatementKind{
Expression,
Assignment,
FunctionDeclaration,
Return
Return,
Conditional
};
class ParsedStatement {
@@ -187,4 +188,47 @@ public:
}
};
class ParsedConditionalStatement : public ParsedStatement{
ParsedExpression* _condition;
ParsedStatement* _block;
// This can be either else if or else
ParsedStatement* _elseStatement;
public:
ParsedConditionalStatement(ParsedExpression* condition, ParsedStatement* block, unsigned int start, unsigned int length)
: ParsedStatement(start, length){
_condition = condition;
_block = block;
_elseStatement = nullptr;
}
ParsedConditionalStatement(ParsedExpression* condition, ParsedStatement* block, ParsedStatement* nextStatement, unsigned int start, unsigned int length)
: ParsedStatement(start, length){
_condition = condition;
_block = block;
_elseStatement = nextStatement;
}
~ParsedConditionalStatement() final{
delete _condition;
delete _block;
delete _elseStatement;
}
ParsedStatementKind GetKind() final{
return ParsedStatementKind ::Conditional;
}
ParsedExpression* GetCondition(){
return _condition;
}
ParsedStatement* GetBlock(){
return _block;
}
ParsedStatement* GetElseStatement(){
return _elseStatement;
}
};
#endif //PORYGONLANG_PARSEDSTATEMENT_HPP