Implemented grammer loading

This commit is contained in:
Nathan Braswell
2013-05-20 19:34:15 -04:00
parent 46d59ac595
commit d2698cf203
11 changed files with 342 additions and 4 deletions

View File

@@ -3,7 +3,7 @@
#ifndef NULL
#define NULL 0
#endif NULL
#endif
#include <vector>
#include <string>
@@ -37,4 +37,4 @@ class NodeTree {
std::vector<NodeTree*> children;
};
#endif //NODETREE_H
#endif

31
include/ParseRule.h Normal file
View File

@@ -0,0 +1,31 @@
#ifndef PARSERULE_H
#define PARSERULE_H
#ifndef NULL
#define NULL 0
#endif
#include "Symbol.h"
#include <vector>
#include <string>
#include <iostream>
class ParseRule {
public:
ParseRule();
~ParseRule();
void setLeftHandle(Symbol* leftHandle);
void appendToRight(Symbol* appendee);
std::string toString();
private:
int pointerIndex;
Symbol* leftHandle;
std::vector<Symbol*> rightSide;
};
#endif

32
include/Parser.h Normal file
View File

@@ -0,0 +1,32 @@
#ifndef PARSER_H
#define PARSER_H
#ifndef NULL
#define NULL 0
#endif
#include "ParseRule.h"
#include "Symbol.h"
#include "StringReader.h"
#include <map>
#include <vector>
#include <string>
#include <iostream>
class Parser {
public:
Parser();
~Parser();
void loadGrammer(std::string grammerInputString);
std::string grammerToString();
private:
StringReader reader;
std::map<std::string, Symbol*> symbols;
std::vector<ParseRule*> loadedGrammer;
Symbol* getOrAddSymbol(std::string symbolString, bool isTerminal);
};
#endif

26
include/StringReader.h Normal file
View File

@@ -0,0 +1,26 @@
#ifndef StringReader_H
#define StringReader_H
#include <vector>
#include <string>
#include <iostream>
class StringReader
{
public:
StringReader();
StringReader(std::string inputString);
virtual ~StringReader();
void setString(std::string inputString);
std::string word(bool truncateEnd = true);
std::string line(bool truncateEnd = true);
std::string getTokens(std::vector<std::string> get_chars, bool truncateEnd = true);
std::string truncateEnd(std::string to_truncate);
protected:
private:
std::string rd_string;
int str_pos;
bool end_reached;
};
#endif

23
include/Symbol.h Normal file
View File

@@ -0,0 +1,23 @@
#ifndef SYMBOL_H
#define SYMBOL_H
#ifndef NULL
#define NULL 0
#endif
#include <vector>
#include <string>
class Symbol {
public:
Symbol(std::string name, bool isTerminal);
~Symbol();
std::string toString();
private:
std::string name;
bool isTerminal;
};
#endif