added skeleton for parsing

This commit is contained in:
zanostro 2025-12-10 09:26:34 +01:00
parent 1b8115ef23
commit 7c6379c62d
7 changed files with 123 additions and 0 deletions

View file

@ -0,0 +1,2 @@
5
0

View file

@ -0,0 +1,26 @@
#ifndef CODE_H
#define CODE_H
#include <vector>
#include <memory>
#include "node.h"
class Code {
public:
Code() = default;
void addLine(const std::shared_ptr<Node>& line);
const std::vector<std::shared_ptr<Node>>& getLines() const;
const string toString() const;
private:
std::vector<std::shared_ptr<Node>> _lines;
};
#endif // CODE_H

View file

@ -0,0 +1,16 @@
#ifndef MNEMONIC_H
#define MNEMONIC_H
#include <string>
using std::string;
class Mnemonic {
public:
string toString() const;
};
#endif // MNEMONIC_H

View file

@ -0,0 +1,31 @@
#ifndef NODE_H
#define NODE_H
#include <string>
#include <memory>
#include "mnemonic.h"
using std::string;
class Node {
public:
string getLabel() const;
string getComment() const;
std::shared_ptr<Mnemonic> getMnemonic() const;
string toString() const;
protected:
string _label;
std::shared_ptr<Mnemonic> _mnemonic;
string _comment;
};
#endif // NODE_H

View file

@ -0,0 +1,20 @@
#include "code.h"
void Code::addLine(const std::shared_ptr<Node> &line)
{
_lines.emplace_back(line);
}
const std::vector<std::shared_ptr<Node>> &Code::getLines() const
{
return _lines;
}
const string Code::toString() const
{
string result;
for (const auto& line : _lines) {
result += line->toString() + "\n";
}
return result;
}

View file

@ -0,0 +1,6 @@
#include "mnemonic.h"
string Mnemonic::toString() const
{
return string();
}

View file

@ -0,0 +1,22 @@
#include "node.h"
string Node::getLabel() const
{
return _label;
}
string Node::getComment() const
{
return _comment;
}
std::shared_ptr<Mnemonic> Node::getMnemonic() const
{
return _mnemonic;
}
string Node::toString() const
{
return (_label.length() > 0 ? _label + " " : "") + (_mnemonic ? _mnemonic->toString() + " ": "") + "." + _comment;
}