Half working stuff

This commit is contained in:
2025-12-20 14:47:24 +11:00
parent 16a406b52f
commit c04e631180
4 changed files with 94 additions and 8 deletions

View File

@@ -20,7 +20,7 @@ namespace HighGround {
namespace Parser {
enum class HGNodeType {
Add, Subtract, Equal, Set, While, If, Value, Identifier, None, Root, CodeBlock, CodeBlockStart, CodeBlockEnd, Puts
Add, Subtract, Equal, Inequal, Set, While, If, Value, Identifier, None, Root, CodeBlock, CodeBlockStart, CodeBlockEnd, Puts
};
enum class HGDataType {
@@ -179,6 +179,20 @@ namespace HighGround {
code.push_back(codeBlock);
break;
}
case HGNodeType::Inequal: {
HGGroundCodeBlock codeBlock;
outputId = "tmp_" + std::to_string(tmpIdIterator++);
GroundInstruction gi = groundCreateInstruction(INEQUAL);
if (children.size() < 2) {
std::cout << "Need more stuff to inequal\n";
}
groundAddReferenceToInstruction(&gi, groundCreateReference(VALREF, children[0].outputId.data()));
groundAddReferenceToInstruction(&gi, groundCreateReference(VALREF, children[1].outputId.data()));
groundAddReferenceToInstruction(&gi, groundCreateReference(DIRREF, outputId.data()));
codeBlock.code.push_back(gi);
code.push_back(codeBlock);
break;
}
case HGNodeType::Puts: {
HGGroundCodeBlock codeBlock;
GroundInstruction gi = groundCreateInstruction(PRINTLN);
@@ -222,9 +236,9 @@ namespace HighGround {
HGGroundCodeBlock codeBlock;
std::string startLabelIdString = "whilestart_" + std::to_string(labelIterator++);
std::string endLabelIdString = "whileend_" + std::to_string(labelIterator);
char* startLabelId = (char*) malloc(sizeof(char) * startLabelIdString.size());
char* startLabelId = (char*) malloc(sizeof(char) * (startLabelIdString.size() + 1));
strcpy(startLabelId, startLabelIdString.data());
char* endLabelId = (char*) malloc(sizeof(char) * endLabelIdString.size());
char* endLabelId = (char*) malloc(sizeof(char) * (endLabelIdString.size() + 1));
strcpy(endLabelId, endLabelIdString.data());
GroundInstruction startLabel = groundCreateInstruction(CREATELABEL);
groundAddReferenceToInstruction(&startLabel, groundCreateReference(LABEL, startLabelId));
@@ -367,6 +381,9 @@ namespace HighGround {
if (in == "==") {
return HGNodeType::Equal;
}
if (in == "!=") {
return HGNodeType::Inequal;
}
if (in == "puts") {
return HGNodeType::Puts;
}
@@ -445,17 +462,31 @@ namespace HighGround {
break;
}
case HGNodeType::Equal: {
HGNode addNode(HGNodeType::Equal);
addNode.addNode(rootNode.children.back());
HGNode equalNode(HGNodeType::Equal);
equalNode.addNode(rootNode.children.back());
rootNode.children.pop_back();
auto tokenopt = consume();
if (tokenopt) {
addNode.addNode(parseOneToken(tokenopt));
equalNode.addNode(parseOneToken(tokenopt));
} else {
std::cout << "FEED ME MORE TOKENS\n";
exit(1);
}
rootNode.addNode(addNode);
rootNode.addNode(equalNode);
break;
}
case HGNodeType::Inequal: {
HGNode inequalNode(HGNodeType::Inequal);
inequalNode.addNode(rootNode.children.back());
rootNode.children.pop_back();
auto tokenopt = consume();
if (tokenopt) {
inequalNode.addNode(parseOneToken(tokenopt));
} else {
std::cout << "FEED ME MORE TOKENS\n";
exit(1);
}
rootNode.addNode(inequalNode);
break;
}
case HGNodeType::Puts: {