1

Implement AST Observer and AST printer

This commit is contained in:
2023-03-21 14:33:56 +01:00
parent 306e631e64
commit e2a4ebecf3
6 changed files with 123 additions and 0 deletions

View File

@ -0,0 +1,23 @@
//
// Created by christoph on 21.03.23.
//
#include <iostream>
#include "PrintObserver.h"
PrintObserver::PrintObserver(const Node &node) : PrefixObserver(node) {}
void PrintObserver::action(const Node &node) {
// Print a simple indent guide
std::string depth_padding(depth * 2, '|');
if (depth > 0) {
for (uint32_t i = 0; i < depth_padding.length(); ++i) {
if (i % 2 == 1) {
depth_padding[i] = ' ';
}
}
depth_padding[(depth * 2) - 1] = '-';
}
std::cout << depth_padding << typeid(node).name() << std::endl;
}

View File

@ -0,0 +1,20 @@
//
// Created by christoph on 21.03.23.
//
#ifndef LOGISIMASSEMBLER_PRINTOBSERVER_H
#define LOGISIMASSEMBLER_PRINTOBSERVER_H
#include "../ast/PrefixObserver.h"
class PrintObserver : public PrefixObserver {
public:
PrintObserver(const Node &node);
~PrintObserver() override = default;
protected:
void action(const Node &node) override;
};
#endif //LOGISIMASSEMBLER_PRINTOBSERVER_H