Added var statement
This commit is contained in:
@@ -47,6 +47,52 @@ string StatementFunctionDeclaration::toString(int indent) {
|
|||||||
return value;
|
return value;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
// StatementVarDeclaration
|
||||||
|
StatementVarDeclaration::StatementVarDeclaration(string name, ValueType valueType, shared_ptr<Expression> expression):
|
||||||
|
Statement(StatementKind::VAR_DECLARATION) {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
string StatementVarDeclaration::getName() {
|
||||||
|
return name;
|
||||||
|
}
|
||||||
|
|
||||||
|
ValueType StatementVarDeclaration::getValueType() {
|
||||||
|
return valueType;
|
||||||
|
}
|
||||||
|
|
||||||
|
shared_ptr<Expression> StatementVarDeclaration::getExpression() {
|
||||||
|
return expression;
|
||||||
|
}
|
||||||
|
|
||||||
|
string StatementVarDeclaration::toString(int indent) {
|
||||||
|
string value;
|
||||||
|
for (int ind=0; ind<indent; ind++)
|
||||||
|
value += " ";
|
||||||
|
value += name + "(";
|
||||||
|
switch (valueType) {
|
||||||
|
case ValueType::VOID:
|
||||||
|
value += "VOID";
|
||||||
|
break;
|
||||||
|
case ValueType::BOOL:
|
||||||
|
value += "BOOL";
|
||||||
|
break;
|
||||||
|
case ValueType::SINT32:
|
||||||
|
value += "SINT32";
|
||||||
|
break;
|
||||||
|
case ValueType::REAL32:
|
||||||
|
value += "REAL32";
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
value += "):\n";
|
||||||
|
for (int ind=0; ind<indent+1; ind++)
|
||||||
|
value += " ";
|
||||||
|
value += expression->toString(indent+1);
|
||||||
|
value += "\n";
|
||||||
|
return value;
|
||||||
|
}
|
||||||
|
|
||||||
//
|
//
|
||||||
// StatementBlock
|
// StatementBlock
|
||||||
StatementBlock::StatementBlock(vector<shared_ptr<Statement>> statements):
|
StatementBlock::StatementBlock(vector<shared_ptr<Statement>> statements):
|
||||||
|
|||||||
@@ -45,6 +45,22 @@ public:
|
|||||||
string toString(int indent) override;
|
string toString(int indent) override;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
//
|
||||||
|
// StatementVarDeclaration
|
||||||
|
class StatementVarDeclaration: public Statement {
|
||||||
|
private:
|
||||||
|
string name;
|
||||||
|
ValueType valueType;
|
||||||
|
shared_ptr<Expression> expression;
|
||||||
|
|
||||||
|
public:
|
||||||
|
StatementVarDeclaration(string name, ValueType valueType, shared_ptr<Expression> expression);
|
||||||
|
string getName();
|
||||||
|
ValueType getValueType();
|
||||||
|
shared_ptr<Expression> getExpression();
|
||||||
|
string toString(int indent) override;
|
||||||
|
};
|
||||||
|
|
||||||
//
|
//
|
||||||
// StatementBlock
|
// StatementBlock
|
||||||
class StatementBlock: public Statement {
|
class StatementBlock: public Statement {
|
||||||
|
|||||||
@@ -46,6 +46,7 @@ enum class ExpressionKind {
|
|||||||
|
|
||||||
enum class StatementKind {
|
enum class StatementKind {
|
||||||
FUNCTION_DECLARATION,
|
FUNCTION_DECLARATION,
|
||||||
|
VAR_DECLARATION,
|
||||||
BLOCK,
|
BLOCK,
|
||||||
RETURN,
|
RETURN,
|
||||||
EXPRESSION,
|
EXPRESSION,
|
||||||
|
|||||||
Reference in New Issue
Block a user