1

Implement part of the AST structure

This commit is contained in:
2023-03-21 14:33:15 +01:00
parent d6dc3f3af4
commit 6993388645
4 changed files with 65 additions and 0 deletions

15
src/ast/nodes/RegNode.cpp Normal file
View File

@ -0,0 +1,15 @@
//
// Created by christoph on 21.03.23.
//
#include "RegNode.h"
RegNode::RegNode(uint8_t reg) : reg(reg) {}
auto RegNode::compile() const -> uint8_t {
if (reg > 0b110) {
throw "Compile Error: Invalid Register!";
}
return reg;
}

22
src/ast/nodes/RegNode.h Normal file
View File

@ -0,0 +1,22 @@
//
// Created by christoph on 21.03.23.
//
#ifndef LOGISIMASSEMBLER_REGNODE_H
#define LOGISIMASSEMBLER_REGNODE_H
#include "../Node.h"
class RegNode : public Node {
public:
RegNode(uint8_t reg);
~RegNode() override = default;
[[nodiscard]] auto compile() const -> uint8_t override;
private:
uint8_t reg;
};
#endif //LOGISIMASSEMBLER_REGNODE_H

View File

@ -0,0 +1,9 @@
//
// Created by christoph on 21.03.23.
//
#include "RootNode.h"
auto RootNode::compile() const -> uint8_t {
return 0;
}

19
src/ast/nodes/RootNode.h Normal file
View File

@ -0,0 +1,19 @@
//
// Created by christoph on 21.03.23.
//
#ifndef LOGISIMASSEMBLER_ROOTNODE_H
#define LOGISIMASSEMBLER_ROOTNODE_H
#include "../Node.h"
class RootNode : public Node {
public:
RootNode() = default;
~RootNode() override = default;
[[nodiscard]] auto compile() const -> uint8_t override;
};
#endif //LOGISIMASSEMBLER_ROOTNODE_H