puts command
This commit is contained in:
41
src/main.cpp
41
src/main.cpp
@@ -9,6 +9,8 @@
|
|||||||
#include <optional>
|
#include <optional>
|
||||||
#include <variant>
|
#include <variant>
|
||||||
|
|
||||||
|
#define parseOneToken(token) Parser({token.value()}).parse().children[0]
|
||||||
|
|
||||||
namespace HighGround {
|
namespace HighGround {
|
||||||
|
|
||||||
int tmpIdIterator = 0;
|
int tmpIdIterator = 0;
|
||||||
@@ -16,7 +18,7 @@ namespace HighGround {
|
|||||||
namespace Parser {
|
namespace Parser {
|
||||||
|
|
||||||
enum class HGNodeType {
|
enum class HGNodeType {
|
||||||
Add, Subtract, Equal, Set, While, If, Value, Identifier, None, Root, CodeBlock
|
Add, Subtract, Equal, Set, While, If, Value, Identifier, None, Root, CodeBlock, Puts
|
||||||
};
|
};
|
||||||
|
|
||||||
enum class HGDataType {
|
enum class HGDataType {
|
||||||
@@ -161,9 +163,18 @@ namespace HighGround {
|
|||||||
code.push_back(codeBlock);
|
code.push_back(codeBlock);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
default: {
|
case HGNodeType::Puts: {
|
||||||
std::cout << "Not implemented yet\n";
|
HGGroundCodeBlock codeBlock;
|
||||||
|
GroundInstruction gi = groundCreateInstruction(PRINTLN);
|
||||||
|
if (children.size() < 1) {
|
||||||
|
std::cout << "Need more stuff to puts\n";
|
||||||
|
}
|
||||||
|
groundAddReferenceToInstruction(&gi, groundCreateReference(VALREF, children[0].outputId.data()));
|
||||||
|
codeBlock.code.push_back(gi);
|
||||||
|
code.push_back(codeBlock);
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
|
default: {}
|
||||||
}
|
}
|
||||||
return code;
|
return code;
|
||||||
}
|
}
|
||||||
@@ -257,6 +268,9 @@ namespace HighGround {
|
|||||||
if (in == "+") {
|
if (in == "+") {
|
||||||
return HGNodeType::Add;
|
return HGNodeType::Add;
|
||||||
}
|
}
|
||||||
|
if (in == "puts") {
|
||||||
|
return HGNodeType::Puts;
|
||||||
|
}
|
||||||
return HGNodeType::None;
|
return HGNodeType::None;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -311,13 +325,29 @@ namespace HighGround {
|
|||||||
rootNode.children.pop_back();
|
rootNode.children.pop_back();
|
||||||
auto tokenopt = consume();
|
auto tokenopt = consume();
|
||||||
if (tokenopt) {
|
if (tokenopt) {
|
||||||
addNode.addNode(Parser({tokenopt.value()}).parse().children[0]);
|
addNode.addNode(parseOneToken(tokenopt));
|
||||||
} else {
|
} else {
|
||||||
std::cout << "FEED ME MORE TOKENS\n";
|
std::cout << "FEED ME MORE TOKENS\n";
|
||||||
}
|
}
|
||||||
rootNode.addNode(addNode);
|
rootNode.addNode(addNode);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
case HGNodeType::Puts: {
|
||||||
|
HGNode putsNode(HGNodeType::Puts);
|
||||||
|
std::vector<std::string> tokens;
|
||||||
|
while (auto tokenopt = consume()) {
|
||||||
|
if (tokenopt.value() == "\n") {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
tokens.push_back(tokenopt.value());
|
||||||
|
}
|
||||||
|
auto children = Parser(tokens).parse();
|
||||||
|
for (auto& child : children.children) {
|
||||||
|
putsNode.addNode(child);
|
||||||
|
}
|
||||||
|
rootNode.addNode(putsNode);
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return rootNode;
|
return rootNode;
|
||||||
@@ -332,7 +362,6 @@ namespace HighGround {
|
|||||||
groundAddInstructionToProgram(&gp, inst);
|
groundAddInstructionToProgram(&gp, inst);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
groundAddInstructionToProgram(&gp, groundCreateInstruction(PAUSE));
|
|
||||||
return gp;
|
return gp;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -369,6 +398,7 @@ namespace HighGround {
|
|||||||
char c = copt.value();
|
char c = copt.value();
|
||||||
switch (c) {
|
switch (c) {
|
||||||
// tokens which are not followed by anything
|
// tokens which are not followed by anything
|
||||||
|
case '\n':
|
||||||
case '(':
|
case '(':
|
||||||
case ')':
|
case ')':
|
||||||
case '{':
|
case '{':
|
||||||
@@ -425,7 +455,6 @@ namespace HighGround {
|
|||||||
}
|
}
|
||||||
// tokens which do not need to be included
|
// tokens which do not need to be included
|
||||||
case ' ':
|
case ' ':
|
||||||
case '\n':
|
|
||||||
{
|
{
|
||||||
if (!buf.empty()) {
|
if (!buf.empty()) {
|
||||||
tokens.push_back(buf);
|
tokens.push_back(buf);
|
||||||
|
|||||||
@@ -1 +1,2 @@
|
|||||||
1 + 1
|
puts 1 + 1
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user