Variables
This commit is contained in:
39
src/main.cpp
39
src/main.cpp
@@ -255,6 +255,18 @@ namespace HighGround {
|
||||
code.push_back(codeBlock);
|
||||
break;
|
||||
}
|
||||
case HGNodeType::Identifier: {
|
||||
break;
|
||||
}
|
||||
case HGNodeType::Set: {
|
||||
HGGroundCodeBlock codeBlock;
|
||||
GroundInstruction setInstruction = groundCreateInstruction(SET);
|
||||
groundAddReferenceToInstruction(&setInstruction, groundCreateReference(DIRREF, children[0].outputId.data()));
|
||||
groundAddReferenceToInstruction(&setInstruction, groundCreateReference(VALREF, children[1].outputId.data()));
|
||||
codeBlock.code.push_back(setInstruction);
|
||||
code.push_back(codeBlock);
|
||||
break;
|
||||
}
|
||||
default: {}
|
||||
}
|
||||
return code;
|
||||
@@ -349,6 +361,9 @@ namespace HighGround {
|
||||
if (in == "+") {
|
||||
return HGNodeType::Add;
|
||||
}
|
||||
if (in == "=") {
|
||||
return HGNodeType::Set;
|
||||
}
|
||||
if (in == "==") {
|
||||
return HGNodeType::Equal;
|
||||
}
|
||||
@@ -367,7 +382,7 @@ namespace HighGround {
|
||||
if (in == "}") {
|
||||
return HGNodeType::CodeBlockEnd;
|
||||
}
|
||||
return HGNodeType::None;
|
||||
return HGNodeType::Identifier;
|
||||
}
|
||||
|
||||
public:
|
||||
@@ -563,6 +578,28 @@ namespace HighGround {
|
||||
rootNode.addNode(codeBlockNode);
|
||||
break;
|
||||
}
|
||||
case HGNodeType::Identifier: {
|
||||
HGNode idNode(HGNodeType::Identifier);
|
||||
idNode.outputId = token;
|
||||
rootNode.addNode(idNode);
|
||||
break;
|
||||
}
|
||||
case HGNodeType::Set: {
|
||||
HGNode setNode(HGNodeType::Set);
|
||||
setNode.addNode(rootNode.children.back());
|
||||
rootNode.children.pop_back();
|
||||
std::vector<std::string> tokens;
|
||||
while (auto tokenopt = consume()) {
|
||||
if (tokenopt.value() == "\n") {
|
||||
break;
|
||||
}
|
||||
tokens.push_back(tokenopt.value());
|
||||
}
|
||||
auto children = Parser(tokens).parse();
|
||||
setNode.addNode(children.children[0]);
|
||||
rootNode.addNode(setNode);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
return rootNode;
|
||||
|
||||
2
tests/set.hg
Normal file
2
tests/set.hg
Normal file
@@ -0,0 +1,2 @@
|
||||
x = 5
|
||||
puts x
|
||||
Reference in New Issue
Block a user