Website Summary Files Commits Branches @commit @diff @stats
path: root / JSImpl / src / Expression.cpp
diff options
context:
space:
mode:
Commit1df22a637e5c5ac090f7d90c5c666da1b22964d5 (patch)
Author
 martin dobrev <martindobrev0@gmail.com>
2018-09-11 09:38:31 +0300
Committer
 martin dobrev <martindobrev0@gmail.com>
2018-09-11 09:38:31 +0300
Files69b7a527c7f6872c140f4b035929ad60f38cd017 /JSImpl/src/Expression.cpp
IPL-1df22a637e5c5ac090f7d90c5c666da1b22964d5.tar
IPL-1df22a637e5c5ac090f7d90c5c666da1b22964d5.tar.gz
IPL-1df22a637e5c5ac090f7d90c5c666da1b22964d5.zip
Parenteeab42ab1d16b5e3cfafeeffbe6aa8045212134e (diff)
Implement parsing for flow control elements like if, for etc.
1 files changed, 92 insertions, 9 deletions
-rw-r--r--JSImpl/src/Expression.cpp101
diff --git a/JSImpl/src/Expression.cpp b/JSImpl/src/Expression.cpp
index 3bd6612..c96e550 100644
--- a/JSImpl/src/Expression.cpp
+++ b/JSImpl/src/Expression.cpp
@@ -7,13 +7,13 @@ BinaryExpression::BinaryExpression(IPLSharedPtr<Expression> exprLeft, IPLSharedP
, m_Operator(op)
{}
-IPLString BinaryExpression::GetOperatorTypeAsString()
+IPLString BinaryExpression::GetOperatorTypeAsString() const
{
// TODO: Implement
return "Binary";
}
-void BinaryExpression::Print(std::ostream& os)
+void BinaryExpression::Print(std::ostream& os) const
{
os << "{ \n";
os << " Expression Type: Binary" << std::endl;
@@ -34,7 +34,7 @@ UnaryExpression::UnaryExpression(IPLSharedPtr<Expression> expr, TokenType op, bo
{
}
-void UnaryExpression::Print(std::ostream& os)
+void UnaryExpression::Print(std::ostream& os) const
{
os << "{ \n";
os << " Expression Type: Unary" << std::endl;
@@ -46,7 +46,7 @@ void UnaryExpression::Print(std::ostream& os)
os << "\n}\n";
}
-IPLString UnaryExpression::GetOperatorTypeAsString()
+IPLString UnaryExpression::GetOperatorTypeAsString() const
{
switch (m_Operator)
{
@@ -97,7 +97,7 @@ LiteralExpression::LiteralExpression(TokenType type)
}
}
-void LiteralExpression::Print(std::ostream& os)
+void LiteralExpression::Print(std::ostream& os) const
{
os << "{ \n";
os << " Expression Type: Unary" << std::endl;
@@ -129,13 +129,13 @@ void LiteralExpression::Print(std::ostream& os)
os << "\n}\n";
}
-IdentifierExpression::IdentifierExpression(IPLString name, ExpressionPtr value)
+IdentifierExpression::IdentifierExpression(IPLString& name, ExpressionPtr value)
: m_Name(name)
, m_Value(value)
{
}
-void IdentifierExpression::Print(std::ostream& os)
+void IdentifierExpression::Print(std::ostream& os) const
{
os << "{ \n";
os << " Expression Type: Identifier" << std::endl;
@@ -144,7 +144,7 @@ void IdentifierExpression::Print(std::ostream& os)
os << "\n}\n";
}
-void ListExpression::Print(std::ostream& os)
+void ListExpression::Print(std::ostream& os) const
{
os << "{ \n";
os << " Expression Type: List" << std::endl;
@@ -153,4 +153,87 @@ void ListExpression::Print(std::ostream& os)
e->Print(os);
}
os << "\n}\n";
-} \ No newline at end of file
+}
+
+void VariableDefinitionExpression::Print(std::ostream& os) const
+{
+ os << "{ \n";
+ os << " Expression Type: VariableDefinition" << std::endl;
+ os << "Identifier name: " << m_Name << std::endl;
+ m_Value->Print(os);
+ os << "\n}\n";
+}
+
+void BlockStatement::Print(std::ostream& os) const
+{
+ os << "{ \n";
+ os << " Expression Type: BlockStatement" << std::endl;
+ for (auto& e : m_Values)
+ {
+ e->Print(os);
+ }
+ os << "\n}\n";
+}
+
+LabeledStatement::LabeledStatement(IPLString& identifier, ExpressionPtr statement)
+ : m_Identifier(identifier)
+ , m_Statement(statement)
+{
+}
+
+void LabeledStatement::Print(std::ostream& os) const
+{
+ os << "{ Not implemented yet !!}";
+}
+
+IfStatement::IfStatement(ExpressionPtr cond, ExpressionPtr ifStatement, ExpressionPtr elseStatement)
+ : m_Condition(cond)
+ , m_IfStatement(ifStatement)
+ , m_ElseStatement(elseStatement)
+{
+}
+
+void IfStatement::Print(std::ostream& os) const
+{
+ os << "{ Not implemented yet !!}";
+}
+
+SwitchStatement::SwitchStatement(ExpressionPtr cond, IPLVector<Case>& cases, ExpressionPtr defaultCase)
+ : m_Condition(cond)
+ , m_Cases(cases)
+ , m_DefaultCase(defaultCase)
+{
+}
+
+void SwitchStatement::Print(std::ostream& os) const
+{
+ os << "{ Not implemented yet !!}";
+}
+
+WhileStatement::WhileStatement(ExpressionPtr cond, ExpressionPtr body, bool doWhile)
+ : m_Condition(cond)
+ , m_Body(body)
+ , m_DoWhile(doWhile)
+{
+}
+
+
+void WhileStatement::Print(std::ostream& os) const
+{
+ os << "{ Not implemented yet !!}";
+}
+
+ForStatement::ForStatement(ExpressionPtr initialization, ExpressionPtr cond, ExpressionPtr iteration, ExpressionPtr body)
+ : m_Initialization(initialization)
+ , m_Condition(cond)
+ , m_Iteration(iteration)
+ , m_Body(body)
+{
+}
+
+void ForStatement::Print(std::ostream& os) const
+{
+ os << "{ Not implemented yet !!}";
+}
+
+