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#include <variant>
11
12namespace unlogic
13{
14 using Node = std::variant<
15 std::monostate,
16 struct NumericLiteralNode,
17 struct StringLiteralNode,
18 struct VariableNode,
19 struct CallNode,
20 struct AdditionNode,
21 struct SubtractionNode,
22 struct MultiplicationNode,
23 struct DivisionNode,
24 struct PotentiationNode,
26 struct PlotCommandNode,
27 struct ScopedBlockNode,
28 struct ProgramEntryNode
29 >;
30
31 using UniqueNode = std::unique_ptr<Node>;
32
33 template<typename T>
34 struct Literal
35 {
37
38 Literal(T value) : value(std::move(value)) {}
39 virtual ~Literal() = default;
40 };
41
42 struct NumericLiteralNode : Literal<double>
43 {
46 };
47
48 struct StringLiteralNode : Literal<std::string>
49 {
50 StringLiteralNode(std::string value);
52 };
53
55 {
56 std::string identifier;
57
58 VariableNode(std::string identifier);
60 };
61
62 struct CallNode
63 {
64 std::string function_name;
65 std::vector<UniqueNode> arguments;
66
67 CallNode(std::string function_name, std::vector<UniqueNode> arguments);
69 };
70
78
84
90
96
102
108
110 {
111 std::string name;
112 std::vector<std::string> args;
114
115 FunctionDefinitionNode(std::string name, std::vector<std::string> arguments, UniqueNode body);
118 };
119
121 {
122 std::string function_name;
123
124 PlotCommandNode(std::string function_name);
126 };
127
129 {
130 std::vector<UniqueNode> statements;
131
132 ScopedBlockNode(std::vector<UniqueNode> statements);
134 };
135
143
144 template<typename T, typename ...Args>
145 UniqueNode unique_node(Args &&... args)
146 {
147 auto temp = std::make_unique<Node>();
148 temp->emplace<T>(std::forward<Args>(args)...);
149 return std::move(temp);
150 }
151} // namespace unlogic
152
153#endif // UNLOGIC_NODE_H
std::unique_ptr< Node > UniqueNode
Definition Node.h:31
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:29
UniqueNode unique_node(Args &&... args)
Definition Node.h:145
UniqueNode rhs
Definition Node.h:73
UniqueNode lhs
Definition Node.h:73
std::vector< UniqueNode > arguments
Definition Node.h:65
std::string function_name
Definition Node.h:64
std::vector< std::string > args
Definition Node.h:112
Literal(T value)
Definition Node.h:38
virtual ~Literal()=default
std::string function_name
Definition Node.h:122
std::vector< UniqueNode > statements
Definition Node.h:130
std::string identifier
Definition Node.h:56