Browse Source

init

canon
Hazel Levine 2 years ago
commit
c4d0197cba
11 changed files with 191 additions and 0 deletions
  1. +26
    -0
      Makefile
  2. BIN
      bin/bfi
  3. BIN
      build/main.o
  4. BIN
      build/parse.o
  5. BIN
      build/read.o
  6. +42
    -0
      src/error.hpp
  7. +33
    -0
      src/main.cpp
  8. +11
    -0
      src/parse.cpp
  9. +25
    -0
      src/parse.hpp
  10. +10
    -0
      src/read.cpp
  11. +44
    -0
      src/read.hpp

+ 26
- 0
Makefile View File

@ -0,0 +1,26 @@
CC := g++ # This is the main compiler
# CC := clang --analyze # and comment out the linker last line for sanity
SRCDIR := src
BUILDDIR := build
TARGET := bin/bfi
SRCEXT := cpp
SOURCES := $(shell find $(SRCDIR) -type f -name *.$(SRCEXT))
OBJECTS := $(patsubst $(SRCDIR)/%,$(BUILDDIR)/%,$(SOURCES:.$(SRCEXT)=.o))
CFLAGS := -g -Wall
LIB := -pthread
INC := -I include
$(TARGET): $(OBJECTS)
@echo " Linking..."
@echo " $(CC) $^ -o $(TARGET) $(LIB)"; $(CC) $^ -o $(TARGET) $(LIB)
$(BUILDDIR)/%.o: $(SRCDIR)/%.$(SRCEXT)
@mkdir -p $(BUILDDIR)
@echo " $(CC) $(CFLAGS) $(INC) -c -o $@ $<"; $(CC) $(CFLAGS) $(INC) -c -o $@ $<
clean:
@echo " Cleaning...";
@echo " $(RM) -r $(BUILDDIR) $(TARGET)"; $(RM) -r $(BUILDDIR) $(TARGET)
.PHONY: clean

BIN
bin/bfi View File


BIN
build/main.o View File


BIN
build/parse.o View File


BIN
build/read.o View File


+ 42
- 0
src/error.hpp View File

@ -0,0 +1,42 @@
#pragma once
#include <exception>
using namespace std;
enum class ErrType {
Success,
BracketMismatch,
NoInput,
Something
};
class ParseExcept: public exception {
public:
ErrType err;
ParseExcept(ErrType e) {
err = e;
}
virtual const char* what() const throw() {
switch(err) {
case ErrType::Success:
return "This should not appear."; // successes should be handled
break;
case ErrType::BracketMismatch:
return "Mismatched bracket";
break;
case ErrType::NoInput:
return "No input given";
break;
case ErrType::Something:
return "Something happened";
break;
default:
break; // this should never happen
}
return "a"; // NOT REACHED
}
};

+ 33
- 0
src/main.cpp View File

@ -0,0 +1,33 @@
#include <iostream>
#include <vector>
#include "error.hpp"
#include "parse.hpp"
#include "read.hpp"
using namespace std;
enum class OpCode {
IncPtr,
DecPtr,
IncByte,
DecByte,
Write,
Read,
LoopBegin,
LoopEnd,
Invalid
};
int main(int argc, char* argv[]) {
std::vector<string> argList;
for (int i = 0; i < argc; i++) {
argList.push_back(argv[i]);
}
Reader r(argList[0]);
//Parser parse("content");
r.printFile();
return 0;
}

+ 11
- 0
src/parse.cpp View File

@ -0,0 +1,11 @@
#include <iostream>
#include <sstream>
#include <string>
#include <vector>
#include "error.hpp"
#include "parse.hpp"
void Parser::printCode() {
cout << code << endl;
}

+ 25
- 0
src/parse.hpp View File

@ -0,0 +1,25 @@
#pragma once
#include <iostream>
#include <sstream>
#include <string>
#include <vector>
#include "error.hpp"
typedef string BFProgram;
class Parser {
public:
Parser(void) {
throw ParseExcept(ErrType::NoInput); // what are you doing??
}
Parser(BFProgram b) {
this->code = b;
}
void printCode();
private:
BFProgram code;
};

+ 10
- 0
src/read.cpp View File

@ -0,0 +1,10 @@
#include <iostream>
#include <sstream>
#include <string>
#include <vector>
#include "read.hpp"
void Reader::printFile() {
cout << contents << endl;
}

+ 44
- 0
src/read.hpp View File

@ -0,0 +1,44 @@
#pragma once
#include <fstream>
#include <iostream>
#include <sstream>
#include <string>
#include "error.hpp"
using namespace std;
class Reader {
public:
Reader(void) {
throw ParseExcept(ErrType::NoInput);
}
Reader(string filename) {
if (filename == "-") { // stdin
for (string line; std::getline(cin, line);) {
contents.append(line);
}
} else {
code.open(filename);
if (!code) {
throw ParseExcept(ErrType::NoInput);
} else {
for (string line; std::getline(code, line);) {
contents.append(line);
}
}
}
}
~Reader(void) {
code.close();
}
void printFile();
private:
ifstream code;
string contents = "";
};

Loading…
Cancel
Save