mirror of
https://github.com/PashaBibko/LX.git
synced 2026-04-03 17:39:02 +00:00
Fixed a couple of issues with operations
This commit is contained in:
2
.gitignore
vendored
2
.gitignore
vendored
@@ -13,7 +13,7 @@ obj/
|
|||||||
*.ll
|
*.ll
|
||||||
*.obj
|
*.obj
|
||||||
*.exe
|
*.exe
|
||||||
log
|
log.txt
|
||||||
|
|
||||||
# Ignore user specific options #
|
# Ignore user specific options #
|
||||||
|
|
||||||
|
|||||||
@@ -14,7 +14,7 @@ namespace LX
|
|||||||
static std::ofstream actualLog;
|
static std::ofstream actualLog;
|
||||||
|
|
||||||
// Opens the log file and assigns it to the log pointer //
|
// Opens the log file and assigns it to the log pointer //
|
||||||
actualLog.open("log");
|
actualLog.open("log.txt");
|
||||||
s_LogFile = &actualLog;
|
s_LogFile = &actualLog;
|
||||||
|
|
||||||
// Assigns the priority //
|
// Assigns the priority //
|
||||||
|
|||||||
@@ -79,31 +79,29 @@ namespace LX
|
|||||||
// Handles operations, if it is not currently at an operation goes to ParsePrimary //
|
// Handles operations, if it is not currently at an operation goes to ParsePrimary //
|
||||||
static std::unique_ptr<AST::Node> ParseOperation(ParserInfo& p)
|
static std::unique_ptr<AST::Node> ParseOperation(ParserInfo& p)
|
||||||
{
|
{
|
||||||
// Checks if the next token is an operator //
|
// Calls down the call stack to either get the left hand side or the node //
|
||||||
// TODO: Add more than just add //
|
std::unique_ptr<AST::Node> lhs = ParsePrimary(p);
|
||||||
if (p.index + 1 < p.len) [[likely]]
|
|
||||||
|
// If the next token is an operator it means the previously parsed data is the left side of the equation //
|
||||||
|
if (IsTwoSidedOperator(p.tokens[p.index].type))
|
||||||
{
|
{
|
||||||
if (IsTwoSidedOperator(p.tokens[p.index + 1].type))
|
// Parses the left hand side of the operation //
|
||||||
{
|
ThrowIf<UnexpectedToken>(lhs == nullptr, Token::UNDEFINED, p.tokens[p.index - 1], "value", p);
|
||||||
// Parses the left hand side of the operation //
|
|
||||||
std::unique_ptr<AST::Node> lhs = ParsePrimary(p);
|
|
||||||
ThrowIf<UnexpectedToken>(lhs == nullptr, Token::UNDEFINED, p.tokens[p.index - 1], "value", p);
|
|
||||||
|
|
||||||
// Stores the operator to pass into the AST node //
|
// Stores the operator to pass into the AST node //
|
||||||
Token::TokenType op = p.tokens[p.index].type;
|
Token::TokenType op = p.tokens[p.index].type;
|
||||||
p.index++;
|
p.index++;
|
||||||
|
|
||||||
// Parses the right hand of the operation //
|
// Parses the right hand of the operation //
|
||||||
std::unique_ptr<AST::Node> rhs = ParseOperation(p);
|
std::unique_ptr<AST::Node> rhs = ParseOperation(p);
|
||||||
ThrowIf<UnexpectedToken>(rhs == nullptr, Token::UNDEFINED, p.tokens[p.index - 1], "value", p);
|
ThrowIf<UnexpectedToken>(rhs == nullptr, Token::UNDEFINED, p.tokens[p.index - 1], "value", p);
|
||||||
|
|
||||||
// Returns an AST node as all of the components combined together //
|
// Returns an AST node as all of the components combined together //
|
||||||
return std::make_unique<AST::Operation>(std::move(lhs), op, std::move(rhs));
|
return std::make_unique<AST::Operation>(std::move(lhs), op, std::move(rhs));
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Else goes down the call stack //
|
// Else it returns the parsed value //
|
||||||
return ParsePrimary(p);
|
return lhs;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Handles return statements, if not calls ParseOperation //
|
// Handles return statements, if not calls ParseOperation //
|
||||||
|
|||||||
@@ -7,7 +7,5 @@ func main()
|
|||||||
{
|
{
|
||||||
int c = add(1, 2)
|
int c = add(1, 2)
|
||||||
|
|
||||||
# Test int
|
|
||||||
|
|
||||||
return c
|
return c
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user