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
|
||||
*.obj
|
||||
*.exe
|
||||
log
|
||||
log.txt
|
||||
|
||||
# Ignore user specific options #
|
||||
|
||||
|
||||
@@ -14,7 +14,7 @@ namespace LX
|
||||
static std::ofstream actualLog;
|
||||
|
||||
// Opens the log file and assigns it to the log pointer //
|
||||
actualLog.open("log");
|
||||
actualLog.open("log.txt");
|
||||
s_LogFile = &actualLog;
|
||||
|
||||
// Assigns the priority //
|
||||
|
||||
@@ -79,14 +79,13 @@ namespace LX
|
||||
// Handles operations, if it is not currently at an operation goes to ParsePrimary //
|
||||
static std::unique_ptr<AST::Node> ParseOperation(ParserInfo& p)
|
||||
{
|
||||
// Checks if the next token is an operator //
|
||||
// TODO: Add more than just add //
|
||||
if (p.index + 1 < p.len) [[likely]]
|
||||
{
|
||||
if (IsTwoSidedOperator(p.tokens[p.index + 1].type))
|
||||
// Calls down the call stack to either get the left hand side or the node //
|
||||
std::unique_ptr<AST::Node> lhs = ParsePrimary(p);
|
||||
|
||||
// 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))
|
||||
{
|
||||
// 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 //
|
||||
@@ -100,10 +99,9 @@ namespace LX
|
||||
// Returns an AST node as all of the components combined together //
|
||||
return std::make_unique<AST::Operation>(std::move(lhs), op, std::move(rhs));
|
||||
}
|
||||
}
|
||||
|
||||
// Else goes down the call stack //
|
||||
return ParsePrimary(p);
|
||||
// Else it returns the parsed value //
|
||||
return lhs;
|
||||
}
|
||||
|
||||
// Handles return statements, if not calls ParseOperation //
|
||||
|
||||
@@ -7,7 +7,5 @@ func main()
|
||||
{
|
||||
int c = add(1, 2)
|
||||
|
||||
# Test int
|
||||
|
||||
return c
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user