aboutsummaryrefslogtreecommitdiff
path: root/src/parse
diff options
context:
space:
mode:
authorcrupest <crupest@outlook.com>2021-09-11 16:54:06 +0800
committercrupest <crupest@outlook.com>2021-09-11 16:54:06 +0800
commitf6c39185f36070d4e092e4c9d2074b418b8bcf03 (patch)
tree5730d83a4a3960c670eacf597f132820991b1e3a /src/parse
parente6eef2bda79dcf2abde080943cb8f9808941e331 (diff)
downloadcru-f6c39185f36070d4e092e4c9d2074b418b8bcf03.tar.gz
cru-f6c39185f36070d4e092e4c9d2074b418b8bcf03.tar.bz2
cru-f6c39185f36070d4e092e4c9d2074b418b8bcf03.zip
...
Diffstat (limited to 'src/parse')
-rw-r--r--src/parse/Grammar.cpp12
1 files changed, 11 insertions, 1 deletions
diff --git a/src/parse/Grammar.cpp b/src/parse/Grammar.cpp
index 3cf43237..5486542b 100644
--- a/src/parse/Grammar.cpp
+++ b/src/parse/Grammar.cpp
@@ -8,7 +8,15 @@
namespace cru::parse {
Grammar::Grammar() {}
-Grammar::~Grammar() {}
+Grammar::~Grammar() {
+ for (auto symbol : symbols_) {
+ delete symbol;
+ }
+
+ for (auto production : productions_) {
+ delete production;
+ }
+}
Terminal* Grammar::CreateTerminal(String name) {
auto terminal = new Terminal(this, std::move(name));
@@ -86,6 +94,8 @@ Grammar* Grammar::Clone() const {
symbol_map.emplace(old_nonterminal, new_nonterminal);
}
+ g->SetStartSymbol(static_cast<Nonterminal*>(symbol_map[start_symbol_]));
+
for (auto old_production : productions_) {
std::vector<Symbol*> new_right;
std::transform(old_production->GetRight().cbegin(),