mirror of
https://github.com/PashaBibko/LX.git
synced 2026-04-03 17:39:02 +00:00
Variables can now have an initializer
This commit is contained in:
@@ -129,10 +129,15 @@ namespace LX
|
||||
p.index++; // Skips over Token::ASSIGN
|
||||
|
||||
// Gets the value to be assigned to the variable //
|
||||
std::unique_ptr<AST::Node> defaultVal = ParsePrimary(p);
|
||||
std::unique_ptr<AST::Node> defaultVal = ParseOperation(p);
|
||||
ThrowIf<UnexpectedToken>(defaultVal.get() == nullptr, Token::UNDEFINED, p.tokens[p.index - 1], "value", p);
|
||||
|
||||
return std::make_unique<AST::VariableDeclaration>(name);
|
||||
// Creates a multi-node of the variable creation and assignment //
|
||||
std::unique_ptr<AST::MultiNode> node = std::make_unique<AST::MultiNode>();
|
||||
node->nodes.push_back(std::make_unique<AST::VariableDeclaration>(name));
|
||||
node->nodes.push_back(std::make_unique<AST::VariableAssignment>(name, std::move(defaultVal)));
|
||||
|
||||
return node;
|
||||
}
|
||||
|
||||
// Else goes down the call stack //
|
||||
@@ -236,7 +241,7 @@ namespace LX
|
||||
for (std::unique_ptr<AST::Node>& containedNode : ((AST::MultiNode*)node.get())->nodes)
|
||||
{
|
||||
// Logs the node to the log //
|
||||
node->Log(0);
|
||||
containedNode->Log(0);
|
||||
|
||||
// Adds it to the vector //
|
||||
func.body.push_back(std::move(containedNode));
|
||||
|
||||
@@ -1,8 +1,9 @@
|
||||
func main()
|
||||
{
|
||||
int a = 65465
|
||||
int a
|
||||
a = 5 + 2
|
||||
|
||||
int b = 6
|
||||
int b = 6 + 1
|
||||
|
||||
return a + b
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user