-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
20 changed files
with
2,307 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
bin/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
CXX = g++ | ||
LD = g++ | ||
CXXFLAGS = -g -std=c++11 -c | ||
LDFLAGS = -g | ||
LDLIBS = | ||
|
||
SRC_DIR = src | ||
BIN_DIR = bin | ||
|
||
EXECUTABLE = $(BIN_DIR)/siyu | ||
|
||
SRCS = $(sort $(wildcard $(SRC_DIR)/*.cpp)) | ||
OBJS = $(addsuffix .o,$(subst $(SRC_DIR),$(BIN_DIR),$(SRCS))) | ||
DEPS = $(addsuffix .d,$(subst $(SRC_DIR),$(BIN_DIR),$(SRCS))) | ||
|
||
.PHONY: all build clean | ||
|
||
all: build | ||
|
||
build: $(EXECUTABLE) | ||
|
||
clean: | ||
rm -rf $(BIN_DIR) | ||
|
||
$(EXECUTABLE): $(OBJS) | ||
$(LD) $(LDFLAGS) -o $@ $(OBJS) $(LDLIBS) | ||
|
||
$(BIN_DIR)/%.o: $(SRC_DIR)/% | ||
$(CXX) $(CXXFLAGS) $< -o $@ | ||
|
||
$(BIN_DIR): | ||
mkdir -p $@ | ||
|
||
$(BIN_DIR)/%.d: $(SRC_DIR)/% $(BIN_DIR) | ||
$(CXX) $(CXXFLAGS) -MM $< -MT '$(@:.d=.o)' -MF $@ | ||
|
||
include $(DEPS) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
#include "finite_automata.h" | ||
|
||
#include <cstdio> | ||
|
||
DFAState::DFAState() : terminal(false) { | ||
return; | ||
} | ||
|
||
DFA::DFA() { | ||
this->root = this->new_state(); | ||
} | ||
|
||
DFAState* DFA::new_state() { | ||
std::unique_ptr<DFAState> state(new DFAState()); | ||
DFAState* ptr = state.get(); | ||
this->id_from_state[ptr] = this->states.size(); | ||
this->states.push_back(std::move(state)); | ||
return ptr; | ||
} | ||
|
||
UInt DFA::id(DFAState* state) { | ||
return this->id_from_state.at(state); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
#ifndef SIYU_FINITE_AUTOMATA_H_INCLUDED | ||
#define SIYU_FINITE_AUTOMATA_H_INCLUDED | ||
|
||
#include <map> | ||
#include <vector> | ||
#include <memory> | ||
#include "global.h" | ||
|
||
class DFAState { | ||
public: | ||
std::map<UInt, DFAState*> next_states; | ||
bool terminal; | ||
DFAState(); | ||
}; | ||
|
||
class DFA { | ||
std::map<DFAState*, UInt> id_from_state; | ||
public: | ||
DFAState* root; | ||
std::vector<std::unique_ptr<DFAState>> states; | ||
|
||
DFA(); | ||
DFAState* new_state(); | ||
UInt id(DFAState*); | ||
}; | ||
|
||
#endif /* SIYU_FINITE_AUTOMATA_H_INCLUDED */ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
#include "global.h" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
#ifndef SIYU_GLOBAL_H_INCLUDED | ||
#define SIYU_GLOBAL_H_INCLUDED | ||
|
||
#include <cstdint> | ||
|
||
typedef int8_t Byte; | ||
typedef uint8_t UByte; | ||
typedef int16_t Short; | ||
typedef uint16_t UShort; | ||
typedef int32_t Int; | ||
typedef uint32_t UInt; | ||
typedef int64_t Long; | ||
typedef uint64_t ULong; | ||
|
||
#endif /* SIYU_GLOBAL_H_INCLUDED */ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
#include <iostream> | ||
#include "regex.h" | ||
|
||
int main() { | ||
std::string str = "abc|def|ghi{3,5}"; | ||
RegexParser parser; | ||
RegexAST* r = parser.parse(str); | ||
RegexASTPrinter printer; | ||
r->accept(&printer); | ||
return 0; | ||
} |
Oops, something went wrong.