diff --git a/compile b/compile new file mode 100755 index 0000000..99920a4 --- /dev/null +++ b/compile @@ -0,0 +1,3 @@ +#!/bin/bash + +g++ parser.cpp lexer.cpp main.cpp -o main \ No newline at end of file diff --git a/lexer.cpp b/lexer.cpp new file mode 100644 index 0000000..58146cc --- /dev/null +++ b/lexer.cpp @@ -0,0 +1,30 @@ +#include +#include +#include +#include "lexer.h" + +char c; +FILE* input_file; + +Lexer::Lexer(std::string &file_name) { + input_file = fopen(file_name.c_str(),"r"); + if(input_file == nullptr) { + std::cout << "[Error] Script " << input_file << " could not be read\n"; + exit(1); + } + + c = getc(input_file); + if (c == EOF) { + //do something related to eof here? + fclose(input_file); + } +} + +char nextChar() { + if (c != EOF) { + c = getc(input_file); + } else { + c = EOF; + } + return c; +} \ No newline at end of file diff --git a/lexer.h b/lexer.h new file mode 100644 index 0000000..1109ab2 --- /dev/null +++ b/lexer.h @@ -0,0 +1,14 @@ +#include + +#ifndef LEXER_H +#define LEXER_H + +class Lexer +{ + private: + std::string extension = ".prog"; + public: + Lexer(std::string &file_name); +}; + +#endif \ No newline at end of file diff --git a/main b/main new file mode 100755 index 0000000..9df8f18 Binary files /dev/null and b/main differ diff --git a/main.cpp b/main.cpp new file mode 100644 index 0000000..16cd12a --- /dev/null +++ b/main.cpp @@ -0,0 +1,15 @@ +#include +#include +#include + +#include "lexer.h" + +int main(int argc, char *argv[]) { + if (argc > 1) { + std::string file_name(argv[1]); + Lexer lex(file_name); + } else { + std::cout << "[Error] No input file provided\n"; + } + return 0; +} \ No newline at end of file diff --git a/parser.cpp b/parser.cpp new file mode 100644 index 0000000..b2ee857 --- /dev/null +++ b/parser.cpp @@ -0,0 +1,8 @@ +#include +#include + +#include "parser.h" + +Parser::Parser(std::string input_file) { + +} \ No newline at end of file diff --git a/parser.h b/parser.h new file mode 100644 index 0000000..3ed0240 --- /dev/null +++ b/parser.h @@ -0,0 +1,14 @@ +#include + +#ifndef PARSER_H +#define PARSER_H + +class Parser +{ + private: + + public: + Parser(std::string input_file); +}; + +#endif \ No newline at end of file diff --git a/script.prog b/script.prog new file mode 100644 index 0000000..dd449f8 --- /dev/null +++ b/script.prog @@ -0,0 +1,3 @@ +hello world, this is a lexer test +hello world +Kanye's new name is Ye \ No newline at end of file diff --git a/token.cpp b/token.cpp new file mode 100644 index 0000000..e69de29 diff --git a/token.h b/token.h new file mode 100644 index 0000000..e69de29