Implemented grammer loading
This commit is contained in:
@@ -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
31
include/ParseRule.h
Normal 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
32
include/Parser.h
Normal 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
26
include/StringReader.h
Normal 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
23
include/Symbol.h
Normal 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
|
||||
Reference in New Issue
Block a user