From 2cf9f81b89786f2fd205069a6ae80a31e81896f1 Mon Sep 17 00:00:00 2001 From: Philipp Gildein Date: Tue, 18 Sep 2007 16:04:45 +0200 Subject: [PATCH] Initial commit - Added Parser class which parses the cmdline and will later parse the script files - Added ParserException class which is used to throw errors --- .gitignore | 2 ++ Makefile | 4 ++++ include/Parser.hpp | 31 ++++++++++++++++++++++++++++ include/ParserException.hpp | 29 +++++++++++++++++++++++++++ src/Parser.cpp | 49 +++++++++++++++++++++++++++++++++++++++++++++ src/main.cpp | 39 ++++++++++++++++++++++++++++++++++++ 6 files changed, 154 insertions(+) create mode 100644 .gitignore create mode 100644 Makefile create mode 100644 include/Parser.hpp create mode 100644 include/ParserException.hpp create mode 100644 src/Parser.cpp create mode 100644 src/main.cpp diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..5dca8a1 --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +*.o +mire diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..a7b30ed --- /dev/null +++ b/Makefile @@ -0,0 +1,4 @@ +all: + g++ -c src/main.cpp -Iinclude + g++ -c src/Parser.cpp -Iinclude + g++ -o mire main.o Parser.o diff --git a/include/Parser.hpp b/include/Parser.hpp new file mode 100644 index 0000000..7dcc95e --- /dev/null +++ b/include/Parser.hpp @@ -0,0 +1,31 @@ +/** + * Mire - The Scripting Language + * + * File: Parser.hpp + * Author: Philipp Gildein + * Last-Modified: 18.09.2007 + */ + +#ifndef __MIRE_PARSER_HPP__ +#define __MIRE_PARSER_HPP__ + +#include + +namespace mire +{ + + class Parser + { + public: + Parser(void); + ~Parser(void); + + void parseCmdLine(int argc, char** argv); + void parseFile(const std::string &filename); + protected: + //Syntax *mSyntax; + }; + +} + +#endif diff --git a/include/ParserException.hpp b/include/ParserException.hpp new file mode 100644 index 0000000..374421a --- /dev/null +++ b/include/ParserException.hpp @@ -0,0 +1,29 @@ +/** + * Mire - The Scripting Language + * + * File: ParserException.hpp + * Author: Philipp Gildein + * Last-Modified: 18.09.2007 + */ + +#ifndef __MIRE_PARSER_EXCEPTION_HPP__ +#define __MIRE_PARSER_EXCEPTION_HPP__ + +#include + +namespace mire +{ + class ParserException : public std::exception + { + public: + ParserException(const std::string &msg) : std::exception(), mMsg(msg) { } + virtual ~ParserException(void) throw() { } + + virtual std::string what(void) { return mMsg; } + protected: + std::string mMsg; + + }; +} + +#endif diff --git a/src/Parser.cpp b/src/Parser.cpp new file mode 100644 index 0000000..121525a --- /dev/null +++ b/src/Parser.cpp @@ -0,0 +1,49 @@ +/** + * Mire - The Scripting Language + * + * File: Parser.cpp + * Author: Philipp Gildein + * Last-Modified: 18.09.2007 + */ + +#include "Parser.hpp" +#include "ParserException.hpp" + +#include +#include + +namespace mire +{ + + Parser::Parser() + { + //mSyntax = new Syntax(); + } + + Parser::~Parser() + { + //delete mSyntax; + } + + void Parser::parseCmdLine(int argc, char** argv) + { + for (int i = 1; i < argc; ++i) + { + if (strcmp(argv[i], "--help") == 0) + std::cout << "To be implemented\n"; + else if (strcmp(argv[i], "-w") == 0) + std::cout << "To be implemented\n"; // Turn on all warnings + else + parseFile(argv[i]); + } + } + + void Parser::parseFile(const std::string &filename) + { + std::ifstream file; + file.open(filename.c_str(), std::ios::in); + if (!file.is_open()) + throw mire::ParserException("File couldn't be found"); + } + +} diff --git a/src/main.cpp b/src/main.cpp new file mode 100644 index 0000000..68a075d --- /dev/null +++ b/src/main.cpp @@ -0,0 +1,39 @@ +/** + * Mire - The Scripting Language + * + * File: main.cpp + * Author: Philipp Gildein + * Last-Modified: 18.09.2007 + */ + +#include +#include + +#include "Parser.hpp" +#include "ParserException.hpp" + +#define Error(x) { std::cerr << "Error: " << x << "\n"; exit(-1); } + +int main(int argc, char* argv[]) +{ + // Check if a file got specified + if (argc < 2) + Error("No scriptfile supplied"); + + mire::Parser *p = 0; + try + { + p = new mire::Parser(); + p->parseCmdLine(argc, argv); + delete p; + p = 0; + } + catch (mire::ParserException &e) + { + std::cerr << "Error: " << e.what() << "\n"; + if (p) + delete p; + } + + return 0; +} -- 2.11.4.GIT