parse: reorder nonterm type specifications

This commit is contained in:
Matthias Schiffer 2015-04-18 18:58:59 +02:00
parent 3cab65c9f0
commit 96d6221449

View file

@ -15,6 +15,9 @@ typedef std::pair<std::vector<solar::symbol_t>, vars_t> rhs_t;
} }
%extra_arg {__attribute__((unused)) grammar_t *} grammar
%type SYMBOL {std::string *} str %type SYMBOL {std::string *} str
%destructor SYMBOL delete %destructor SYMBOL delete
@ -33,33 +36,6 @@ typedef std::pair<std::vector<solar::symbol_t>, vars_t> rhs_t;
%type CHAR {unsigned char} c %type CHAR {unsigned char} c
%type namespace {std::vector<std::string> *}
%destructor namespace delete
%type rhs {rhs_t *}
%destructor rhs delete
%type variable {var_t *}
%destructor variable delete
%type action {std::string *}
%destructor action delete
%type symbol {symbol_t *}
%destructor symbol delete
%type term {symbol_t *}
%destructor term delete
%type csymbol {std::string *}
%destructor csymbol delete
%type consume {bool}
%extra_arg {__attribute__((unused)) grammar_t *} grammar
grammar |=; grammar |=;
grammar |= grammar directive; grammar |= grammar directive;
@ -104,6 +80,9 @@ directive |= SYMBOL(lhs) "|=" '(' CHAR(c1) "..." CHAR(c2) ')' ';' {
} }
%type rhs {rhs_t *}
%destructor rhs delete
rhs |= [new rhs_t] rhs |= [new rhs_t]
rhs |= rhs(=rhs) symbol(sym) variable(var) { rhs |= rhs(=rhs) symbol(sym) variable(var) {
@ -123,19 +102,31 @@ rhs |= rhs(=rhs) STRING(str) {
} }
%type variable {var_t *}
%destructor variable delete
variable |= [new var_t] variable |= [new var_t]
variable |= '(' consume(consume) csymbol(var) ')' variable |= '(' consume(consume) csymbol(var) ')'
[new var_t(*var, consume)] [new var_t(*var, consume)]
%type consume {bool}
consume |= [false] consume |= [false]
consume |= '=' [true] consume |= '=' [true]
%type action {std::string *}
%destructor action delete
action |= ';' [new std::string] action |= ';' [new std::string]
action |= BLOCK(=v) [v] action |= BLOCK(=v) [v]
action |= SQBLOCK(v) [new std::string("return " + *v + ";")] action |= SQBLOCK(v) [new std::string("return " + *v + ";")]
%type namespace {std::vector<std::string> *}
%destructor namespace delete
namespace |= csymbol(v) [new std::vector<std::string> {*v}] namespace |= csymbol(v) [new std::vector<std::string> {*v}]
namespace |= namespace(=ns) "::" csymbol(v) { namespace |= namespace(=ns) "::" csymbol(v) {
ns->push_back(*v); ns->push_back(*v);
@ -143,11 +134,22 @@ namespace |= namespace(=ns) "::" csymbol(v) {
} }
%type symbol {symbol_t *}
%destructor symbol delete
symbol |= SYMBOL(v) [new symbol_t(symbol_t::make_nonterm(*v))] symbol |= SYMBOL(v) [new symbol_t(symbol_t::make_nonterm(*v))]
symbol |= term(=v) [v] symbol |= term(=v) [v]
%type term {symbol_t *}
%destructor term delete
term |= SYMBOL_UC(v) [new symbol_t(symbol_t::make_term(*v))] term |= SYMBOL_UC(v) [new symbol_t(symbol_t::make_term(*v))]
term |= CHAR(v) [new symbol_t(symbol_t::make_char(v))] term |= CHAR(v) [new symbol_t(symbol_t::make_char(v))]
%type csymbol {std::string *}
%destructor csymbol delete
csymbol |= SYMBOL_UC(=v) [v] csymbol |= SYMBOL_UC(=v) [v]
csymbol |= SYMBOL(=v) [v] csymbol |= SYMBOL(=v) [v]