%type SYMBOL {std::string *} str %type SYMBOL_UC {std::string *} str %type SYMBOL_LC {std::string *} str %type BLOCK {std::string *} str %type CHAR {char} c %type rule {solar::rule_t *} %type rhs {std::pair, std::vector> *} %type action {std::string *} %type symbol {solar::symbol_t *} %type term {solar::symbol_t *} %type varname {std::string *} %header { #include "grammar.hpp" } %extra_arg {__attribute__((unused)) solar::grammar_t *} grammar grammar |=; grammar |= grammar rule(rule) { if (grammar->rules.empty()) { solar::item_t init(""); init.get_rhs().push_back(solar::symbol_t::make_nonterm(rule->item.get_lhs().c_str())); grammar->rules.emplace_back(solar::rule_t {std::move(init), std::vector(), std::string()}); } grammar->rules.push_back(*rule); delete rule; } grammar |= grammar TYPE SYMBOL_LC(nonterm) BLOCK(type) { grammar->nonterm_types.insert(std::make_pair(*nonterm, *type)); delete nonterm; delete type; } grammar |= grammar TYPE term(term) BLOCK(type) varname(name) { grammar->term_types.insert(std::make_pair(*term, std::make_pair(*type, *name))); delete term; delete type; delete name; } grammar |= grammar SOURCE BLOCK(block) { grammar->source_block = *block; delete block; } grammar |= grammar HEADER BLOCK(block) { grammar->header_block = *block; delete block; } grammar |= grammar EXTRA_ARG BLOCK(type) varname(name) { grammar->extra_args.push_back(std::make_pair(*type, *name)); delete type; delete name; } rule |= SYMBOL_LC(lhs) '|' '=' rhs(rhs) action(action) { auto *ret = new solar::rule_t {solar::item_t(*lhs, rhs->first), rhs->second, *action}; delete lhs; delete rhs; delete action; return ret; } rhs |= { return new std::pair, std::vector>(); } rhs |= rhs(rhs) symbol(sym) { rhs->first.push_back(*sym); rhs->second.emplace_back(); delete sym; return rhs; } rhs |= rhs(rhs) symbol(sym) '(' varname(var) ')' { rhs->first.push_back(*sym); rhs->second.push_back(*var); delete sym; delete var; return rhs; } action |= ';' { return new std::string; } action |= BLOCK(v) { return v; } symbol |= term(v) { return v; } symbol |= SYMBOL_LC(v) { solar::symbol_t *ret = new solar::symbol_t(solar::symbol_t::make_nonterm(*v)); delete v; return ret; } term |= SYMBOL_UC(v) { solar::symbol_t *ret = new solar::symbol_t(solar::symbol_t::make_term(*v)); delete v; return ret; } term |= CHAR(v) { return new solar::symbol_t(solar::symbol_t::make_char(v)); } varname |= SYMBOL_LC(v) { return v; } varname |= SYMBOL_UC(v) { return v; } varname |= SYMBOL(v) { return v; }