Added EOF symbol, making the getTable() saner for ACCEPT and lookahead support in ParseRule
This commit is contained in:
20
include/Lexer.h
Normal file
20
include/Lexer.h
Normal file
@@ -0,0 +1,20 @@
|
||||
#ifndef LEXER_H
|
||||
#define LEXER_H
|
||||
|
||||
#include "util.h"
|
||||
#include "StringReader.h"
|
||||
#include "Symbol.h"
|
||||
|
||||
#include <string>
|
||||
|
||||
class Lexer {
|
||||
public:
|
||||
Lexer();
|
||||
Lexer(std::string inputString);
|
||||
~Lexer();
|
||||
void setInput(std::string inputString);
|
||||
Symbol* next();
|
||||
private:
|
||||
StringReader reader;
|
||||
};
|
||||
#endif
|
||||
@@ -14,7 +14,7 @@
|
||||
class ParseRule {
|
||||
public:
|
||||
ParseRule();
|
||||
ParseRule(Symbol* leftHandle, int pointerIndex, std::vector<Symbol*> &rightSide);
|
||||
ParseRule(Symbol* leftHandle, int pointerIndex, std::vector<Symbol*> &rightSide, Symbol* lookahead = NULL);
|
||||
~ParseRule();
|
||||
|
||||
bool const operator==(const ParseRule &other);
|
||||
@@ -41,6 +41,7 @@ class ParseRule {
|
||||
private:
|
||||
int pointerIndex;
|
||||
Symbol* leftHandle;
|
||||
Symbol* lookahead;
|
||||
std::vector<Symbol*> rightSide;
|
||||
|
||||
};
|
||||
|
||||
@@ -1,16 +1,13 @@
|
||||
#ifndef PARSER_H
|
||||
#define PARSER_H
|
||||
|
||||
#ifndef NULL
|
||||
#define NULL 0
|
||||
#endif
|
||||
|
||||
#include "util.h"
|
||||
#include "ParseRule.h"
|
||||
#include "ParseAction.h"
|
||||
#include "Symbol.h"
|
||||
#include "State.h"
|
||||
#include "StringReader.h"
|
||||
#include "Lexer.h"
|
||||
#include "NodeTree.h"
|
||||
|
||||
#include <map>
|
||||
@@ -32,7 +29,7 @@ class Parser {
|
||||
std::string stateSetToString();
|
||||
void addToTable(State* fromState, Symbol* tranSymbol, ParseAction* action);
|
||||
ParseAction* getTable(int state, Symbol* token);
|
||||
NodeTree* parseInput(std::string inputString);
|
||||
NodeTree* parseInput(Lexer* lexer);
|
||||
|
||||
std::string grammerToString();
|
||||
std::string grammerToDOT();
|
||||
|
||||
@@ -1,6 +1,10 @@
|
||||
#ifndef UTIL_H
|
||||
#define UTIL_H
|
||||
|
||||
#ifndef NULL
|
||||
#define NULL 0
|
||||
#endif
|
||||
|
||||
#include <string>
|
||||
#include <sstream>
|
||||
|
||||
|
||||
Reference in New Issue
Block a user