unlogic
Loading...
Searching...
No Matches
Node.h
Go to the documentation of this file.
1#ifndef UNLOGIC_NODE_H
2#define UNLOGIC_NODE_H
3
4#include <map>
5#include <memory>
6#include <ranges>
7#include <stdexcept>
8#include <string>
9#include <vector>
10
11namespace unlogic
12{
13 using Node = std::variant<
14 std::monostate,
15 struct NumericLiteralNode,
16 struct StringLiteralNode,
17 struct VariableNode,
18 struct CallNode,
19 struct AdditionNode,
20 struct SubtractionNode,
21 struct MultiplicationNode,
22 struct DivisionNode,
23 struct PotentiationNode,
25 struct PlotCommandNode,
26 struct ScopedBlockNode,
27 struct ProgramEntryNode
28 >;
29
30 using UniqueNode = std::unique_ptr<Node>;
31
32 template<typename T>
33 struct Literal
34 {
36
37 Literal(T value) : value(std::move(value)) {}
38 virtual ~Literal() = default;
39 };
40
41 struct NumericLiteralNode : Literal<double>
42 {
45 };
46
47 struct StringLiteralNode : Literal<std::string>
48 {
49 StringLiteralNode(std::string value);
51 };
52
54 {
55 std::string identifier;
56
57 VariableNode(std::string identifier);
59 };
60
61 struct CallNode
62 {
63 std::string function_name;
64 std::vector<UniqueNode> arguments;
65
66 CallNode(std::string function_name, std::vector<UniqueNode> arguments);
68 };
69
77
83
89
95
101
107
109 {
110 std::string name;
111 std::vector<std::string> args;
113
114 FunctionDefinitionNode(std::string name, std::vector<std::string> arguments, UniqueNode body);
117 };
118
120 {
121 std::string function_name;
122
123 PlotCommandNode(std::string function_name);
125 };
126
128 {
129 std::vector<UniqueNode> statements;
130
131 ScopedBlockNode(std::vector<UniqueNode> statements);
133 };
134
142
143 template<typename T, typename ...Args>
144 UniqueNode unique_node(Args &&... args)
145 {
146 auto temp = std::make_unique<Node>();
147 temp->emplace<T>(std::forward<Args>(args)...);
148 return std::move(temp);
149 }
150} // namespace unlogic
151
152#endif // UNLOGIC_NODE_H
std::unique_ptr< Node > UniqueNode
Definition Node.h:30
std::variant< std::monostate, struct NumericLiteralNode, struct StringLiteralNode, struct VariableNode, struct CallNode, struct AdditionNode, struct SubtractionNode, struct MultiplicationNode, struct DivisionNode, struct PotentiationNode, struct FunctionDefinitionNode, struct PlotCommandNode, struct ScopedBlockNode, struct ProgramEntryNode > Node
Definition Node.h:28
UniqueNode unique_node(Args &&... args)
Definition Node.h:144
UniqueNode rhs
Definition Node.h:72
UniqueNode lhs
Definition Node.h:72
std::vector< UniqueNode > arguments
Definition Node.h:64
std::string function_name
Definition Node.h:63
std::vector< std::string > args
Definition Node.h:111
Literal(T value)
Definition Node.h:37
virtual ~Literal()=default
std::string function_name
Definition Node.h:121
std::vector< UniqueNode > statements
Definition Node.h:129
std::string identifier
Definition Node.h:55