File tree Expand file tree Collapse file tree 1 file changed +29
-4
lines changed
Expand file tree Collapse file tree 1 file changed +29
-4
lines changed Original file line number Diff line number Diff line change @@ -153,13 +153,38 @@ Grammar::FilterRulesByConsequent(const std::string& arg) {
153153
154154void Grammar::Debug () {
155155 std::cout << " Grammar:\n " ;
156+
157+ std::cout << axiom_ << " -> " ;
158+ const auto & axiom_productions = g_.at (axiom_);
159+ for (size_t i = 0 ; i < axiom_productions.size (); ++i) {
160+ for (const std::string& symbol : axiom_productions[i]) {
161+ std::cout << symbol << " " ;
162+ }
163+ if (i < axiom_productions.size () - 1 ) {
164+ std::cout << " | " ;
165+ }
166+ }
167+ std::cout << " \n " ;
168+
169+ std::vector<std::string> non_terminals;
156170 for (const auto & entry : g_) {
157- std::cout << entry.first << " -> " ;
158- for (const std::vector<std::string>& prod : entry.second ) {
159- for (const std::string& symbol : prod) {
171+ if (entry.first != axiom_) {
172+ non_terminals.push_back (entry.first );
173+ }
174+ }
175+
176+ std::sort (non_terminals.begin (), non_terminals.end ());
177+
178+ for (const std::string& nt : non_terminals) {
179+ std::cout << nt << " -> " ;
180+ const auto & productions = g_.at (nt);
181+ for (size_t i = 0 ; i < productions.size (); ++i) {
182+ for (const std::string& symbol : productions[i]) {
160183 std::cout << symbol << " " ;
161184 }
162- std::cout << " | " ;
185+ if (i < productions.size () - 1 ) {
186+ std::cout << " | " ;
187+ }
163188 }
164189 std::cout << " \n " ;
165190 }
You can’t perform that action at this time.
0 commit comments