From 5d211b6ffde5680fa12d16e3747bace30a3e66fc Mon Sep 17 00:00:00 2001 From: Nathanne Isip Date: Sat, 21 Dec 2024 10:02:25 +0800 Subject: [PATCH] Function implementation for parsing lock statements in Parser class. --- src/n8/parser/Parser.cpp | 40 ++++++++++++++++++---------------------- 1 file changed, 18 insertions(+), 22 deletions(-) diff --git a/src/n8/parser/Parser.cpp b/src/n8/parser/Parser.cpp index 7547fbd..4a861ae 100644 --- a/src/n8/parser/Parser.cpp +++ b/src/n8/parser/Parser.cpp @@ -26,6 +26,7 @@ #include #include #include +#include #include #include #include @@ -92,9 +93,6 @@ Token Parser::previous() { Token Parser::peek() { if(this->isAtEnd()) - #ifdef _MSC_VER - # pragma warning(disable : 5272) - #endif throw ParserException( std::make_shared(this->previous()), "Encountered end-of-file." @@ -121,9 +119,6 @@ Token Parser::current() { Token Parser::consume(const std::string& image) { if(this->isAtEnd()) - #ifdef _MSC_VER - # pragma warning(disable : 5272) - #endif throw ParserException( std::make_shared(this->previous()), "Expecting \"" + image + @@ -132,9 +127,6 @@ Token Parser::consume(const std::string& image) { Token token = this->peek(); if(token.getImage() != image) - #ifdef _MSC_VER - # pragma warning(disable : 5272) - #endif throw ParserException( std::make_shared(this->previous()), "Expecting \"" + image + @@ -147,9 +139,6 @@ Token Parser::consume(const std::string& image) { Token Parser::consume(TokenType type) { if(this->isAtEnd()) - #ifdef _MSC_VER - # pragma warning(disable : 5272) - #endif throw ParserException( std::make_shared(this->previous()), "Expecting token type, encountered end-of-code." @@ -157,9 +146,6 @@ Token Parser::consume(TokenType type) { Token token = this->peek(); if(token.getType() != type) - #ifdef _MSC_VER - # pragma warning(disable : 5272) - #endif throw ParserException( std::make_shared(this->current()), "Expecting " + tokenTypeToString(type) + @@ -373,10 +359,6 @@ std::shared_ptr Parser::exprLiteral() { if(!expr) { auto address = this->current(); - - #ifdef _MSC_VER - # pragma warning(disable : 5272) - #endif throw ParserException( std::make_shared(address), "Expecting expression, encountered " + @@ -447,6 +429,21 @@ std::shared_ptr Parser::exprSize() { ); } +std::shared_ptr Parser::exprLock() { + Token address = this->consume("lock"); + this->consume("("); + + Token variable = this->consume(TokenType::IDENTIFIER); + this->consume(")"); + + std::shared_ptr expression = this->expression(); + return std::make_shared( + std::make_shared(address), + std::make_shared(variable), + std::move(expression) + ); +} + std::shared_ptr Parser::exprType() { Token address = this->consume("type"); std::shared_ptr expression = this->expression(); @@ -510,9 +507,6 @@ std::shared_ptr Parser::exprWhen() { } else if(this->isNext("else", TokenType::KEYWORD)) { if(defaultCase) - #ifdef _MSC_VER - # pragma warning(disable : 5272) - #endif throw ParserException( std::make_shared(address), "Cannot have more than one (1) else for when expression." @@ -610,6 +604,8 @@ std::shared_ptr Parser::exprPrimary() { expression = this->exprSize(); else if(this->isNext("parallel", TokenType::KEYWORD)) expression = this->exprParallel(); + else if(this->isNext("lock", TokenType::KEYWORD)) + expression = this->exprLock(); else if(this->isNext("val", TokenType::KEYWORD)) expression = this->exprVal(); else if(this->isNext("[", TokenType::OPERATOR))