Implements if, elseif and else statements
All checks were successful
continuous-integration/drone/push Build is passing
All checks were successful
continuous-integration/drone/push Build is passing
This commit is contained in:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user