parse: rename varname nonterm to csymbol

This commit is contained in:
Matthias Schiffer 2015-04-18 17:58:44 +02:00
parent 4ed7d5a1b2
commit 3818c8c528
2 changed files with 42 additions and 42 deletions

View file

@ -14,11 +14,11 @@ namespace solar {
typedef union parse_symbol_value { typedef union parse_symbol_value {
parse_token_value_t token; parse_token_value_t token;
std::string *symbol_action; std::string *symbol_action;
std::string *symbol_csymbol;
std::vector<std::string> *symbol_namespace; std::vector<std::string> *symbol_namespace;
rhs_t *symbol_rhs; rhs_t *symbol_rhs;
symbol_t *symbol_symbol; symbol_t *symbol_symbol;
symbol_t *symbol_term; symbol_t *symbol_term;
std::string *symbol_varname;
} parse_symbol_value_t; } parse_symbol_value_t;
typedef struct parse_context_state { typedef struct parse_context_state {
@ -845,8 +845,8 @@ static int parse_do_push(parse_context_t *parser, int token, __attribute__((unus
switch (token) { switch (token) {
default: default:
parser->top -= 1; parser->top -= 1;
result.symbol_varname = parse_reduce_27(parser->stack[parser->top + 0].value.token.str, grammar); result.symbol_csymbol = parse_reduce_27(parser->stack[parser->top + 0].value.token.str, grammar);
parser->stack[parser->top].value.symbol_varname = result.symbol_varname; parser->stack[parser->top].value.symbol_csymbol = result.symbol_csymbol;
switch (parser->stack[parser->top].state) { switch (parser->stack[parser->top].state) {
case 44: case 44:
parser->stack[++parser->top].state = 53; parser->stack[++parser->top].state = 53;
@ -861,7 +861,7 @@ static int parse_do_push(parse_context_t *parser, int token, __attribute__((unus
break; break;
case 82: case 82:
parser->stack[++parser->top].state = 87; parser->stack[++parser->top].state = 86;
break; break;
case 85: case 85:
@ -884,8 +884,8 @@ static int parse_do_push(parse_context_t *parser, int token, __attribute__((unus
switch (token) { switch (token) {
default: default:
parser->top -= 1; parser->top -= 1;
result.symbol_varname = parse_reduce_26(parser->stack[parser->top + 0].value.token.str, grammar); result.symbol_csymbol = parse_reduce_26(parser->stack[parser->top + 0].value.token.str, grammar);
parser->stack[parser->top].value.symbol_varname = result.symbol_varname; parser->stack[parser->top].value.symbol_csymbol = result.symbol_csymbol;
switch (parser->stack[parser->top].state) { switch (parser->stack[parser->top].state) {
case 44: case 44:
parser->stack[++parser->top].state = 53; parser->stack[++parser->top].state = 53;
@ -900,7 +900,7 @@ static int parse_do_push(parse_context_t *parser, int token, __attribute__((unus
break; break;
case 82: case 82:
parser->stack[++parser->top].state = 87; parser->stack[++parser->top].state = 86;
break; break;
case 85: case 85:
@ -1030,9 +1030,9 @@ static int parse_do_push(parse_context_t *parser, int token, __attribute__((unus
switch (token) { switch (token) {
default: default:
parser->top -= 5; parser->top -= 5;
result.symbol_rhs = parse_reduce_14(parser->stack[parser->top + 0].value.symbol_rhs, parser->stack[parser->top + 1].value.symbol_symbol, parser->stack[parser->top + 3].value.symbol_varname, grammar); result.symbol_rhs = parse_reduce_14(parser->stack[parser->top + 0].value.symbol_rhs, parser->stack[parser->top + 1].value.symbol_symbol, parser->stack[parser->top + 3].value.symbol_csymbol, grammar);
delete(parser->stack[parser->top + 1].value.symbol_symbol); delete(parser->stack[parser->top + 1].value.symbol_symbol);
delete(parser->stack[parser->top + 3].value.symbol_varname); delete(parser->stack[parser->top + 3].value.symbol_csymbol);
parser->stack[parser->top].value.symbol_rhs = result.symbol_rhs; parser->stack[parser->top].value.symbol_rhs = result.symbol_rhs;
parser->stack[++parser->top].state = 19; parser->stack[++parser->top].state = 19;
} }
@ -1117,10 +1117,10 @@ static int parse_do_push(parse_context_t *parser, int token, __attribute__((unus
switch (token) { switch (token) {
default: default:
parser->top -= 8; parser->top -= 8;
parse_reduce_4(parser->stack[parser->top + 5].value.symbol_term, parser->stack[parser->top + 6].value.token.str, parser->stack[parser->top + 7].value.symbol_varname, grammar); parse_reduce_4(parser->stack[parser->top + 5].value.symbol_term, parser->stack[parser->top + 6].value.token.str, parser->stack[parser->top + 7].value.symbol_csymbol, grammar);
delete(parser->stack[parser->top + 5].value.symbol_term); delete(parser->stack[parser->top + 5].value.symbol_term);
delete(parser->stack[parser->top + 6].value.token.str); delete(parser->stack[parser->top + 6].value.token.str);
delete(parser->stack[parser->top + 7].value.symbol_varname); delete(parser->stack[parser->top + 7].value.symbol_csymbol);
parser->stack[++parser->top].state = 2; parser->stack[++parser->top].state = 2;
} }
break; break;
@ -1129,9 +1129,9 @@ static int parse_do_push(parse_context_t *parser, int token, __attribute__((unus
switch (token) { switch (token) {
default: default:
parser->top -= 6; parser->top -= 6;
result.symbol_rhs = parse_reduce_15(parser->stack[parser->top + 0].value.symbol_rhs, parser->stack[parser->top + 1].value.symbol_symbol, parser->stack[parser->top + 4].value.symbol_varname, grammar); result.symbol_rhs = parse_reduce_15(parser->stack[parser->top + 0].value.symbol_rhs, parser->stack[parser->top + 1].value.symbol_symbol, parser->stack[parser->top + 4].value.symbol_csymbol, grammar);
delete(parser->stack[parser->top + 1].value.symbol_symbol); delete(parser->stack[parser->top + 1].value.symbol_symbol);
delete(parser->stack[parser->top + 4].value.symbol_varname); delete(parser->stack[parser->top + 4].value.symbol_csymbol);
parser->stack[parser->top].value.symbol_rhs = result.symbol_rhs; parser->stack[parser->top].value.symbol_rhs = result.symbol_rhs;
parser->stack[++parser->top].state = 19; parser->stack[++parser->top].state = 19;
} }
@ -1274,6 +1274,17 @@ static int parse_do_push(parse_context_t *parser, int token, __attribute__((unus
break; break;
case 86: case 86:
switch (token) {
default:
parser->top -= 1;
result.symbol_namespace = parse_reduce_20(parser->stack[parser->top + 0].value.symbol_csymbol, grammar);
delete(parser->stack[parser->top + 0].value.symbol_csymbol);
parser->stack[parser->top].value.symbol_namespace = result.symbol_namespace;
parser->stack[++parser->top].state = 87;
}
break;
case 87:
switch (token) { switch (token) {
case ':': case ':':
parser->stack[++parser->top].state = 90; parser->stack[++parser->top].state = 90;
@ -1287,17 +1298,6 @@ static int parse_do_push(parse_context_t *parser, int token, __attribute__((unus
} }
break; break;
case 87:
switch (token) {
default:
parser->top -= 1;
result.symbol_namespace = parse_reduce_20(parser->stack[parser->top + 0].value.symbol_varname, grammar);
delete(parser->stack[parser->top + 0].value.symbol_varname);
parser->stack[parser->top].value.symbol_namespace = result.symbol_namespace;
parser->stack[++parser->top].state = 86;
}
break;
case 88: case 88:
switch (token) { switch (token) {
case TOK_SYMBOL: case TOK_SYMBOL:
@ -1317,9 +1317,9 @@ static int parse_do_push(parse_context_t *parser, int token, __attribute__((unus
switch (token) { switch (token) {
default: default:
parser->top -= 12; parser->top -= 12;
parse_reduce_9(parser->stack[parser->top + 10].value.token.str, parser->stack[parser->top + 11].value.symbol_varname, grammar); parse_reduce_9(parser->stack[parser->top + 10].value.token.str, parser->stack[parser->top + 11].value.symbol_csymbol, grammar);
delete(parser->stack[parser->top + 10].value.token.str); delete(parser->stack[parser->top + 10].value.token.str);
delete(parser->stack[parser->top + 11].value.symbol_varname); delete(parser->stack[parser->top + 11].value.symbol_csymbol);
parser->stack[++parser->top].state = 2; parser->stack[++parser->top].state = 2;
} }
break; break;
@ -1339,9 +1339,9 @@ static int parse_do_push(parse_context_t *parser, int token, __attribute__((unus
switch (token) { switch (token) {
default: default:
parser->top -= 13; parser->top -= 13;
parse_reduce_5(parser->stack[parser->top + 11].value.symbol_symbol, parser->stack[parser->top + 12].value.symbol_varname, grammar); parse_reduce_5(parser->stack[parser->top + 11].value.symbol_symbol, parser->stack[parser->top + 12].value.symbol_csymbol, grammar);
delete(parser->stack[parser->top + 11].value.symbol_symbol); delete(parser->stack[parser->top + 11].value.symbol_symbol);
delete(parser->stack[parser->top + 12].value.symbol_varname); delete(parser->stack[parser->top + 12].value.symbol_csymbol);
parser->stack[++parser->top].state = 2; parser->stack[++parser->top].state = 2;
} }
break; break;
@ -1365,10 +1365,10 @@ static int parse_do_push(parse_context_t *parser, int token, __attribute__((unus
switch (token) { switch (token) {
default: default:
parser->top -= 4; parser->top -= 4;
result.symbol_namespace = parse_reduce_21(parser->stack[parser->top + 0].value.symbol_namespace, parser->stack[parser->top + 3].value.symbol_varname, grammar); result.symbol_namespace = parse_reduce_21(parser->stack[parser->top + 0].value.symbol_namespace, parser->stack[parser->top + 3].value.symbol_csymbol, grammar);
delete(parser->stack[parser->top + 3].value.symbol_varname); delete(parser->stack[parser->top + 3].value.symbol_csymbol);
parser->stack[parser->top].value.symbol_namespace = result.symbol_namespace; parser->stack[parser->top].value.symbol_namespace = result.symbol_namespace;
parser->stack[++parser->top].state = 86; parser->stack[++parser->top].state = 87;
} }
break; break;

View file

@ -47,8 +47,8 @@ typedef std::pair<std::vector<solar::symbol_t>, vars_t> rhs_t;
%type term {symbol_t *} %type term {symbol_t *}
%destructor term delete %destructor term delete
%type varname {std::string *} %type csymbol {std::string *}
%destructor varname delete %destructor csymbol delete
%extra_arg {__attribute__((unused)) grammar_t *} grammar %extra_arg {__attribute__((unused)) grammar_t *} grammar
@ -62,11 +62,11 @@ directive |= "%type" SYMBOL(nonterm) BLOCK(type) {
grammar->nonterm_types.insert(std::make_pair(*nonterm, *type)); grammar->nonterm_types.insert(std::make_pair(*nonterm, *type));
} }
directive |= "%type" term(term) BLOCK(type) varname(name) { directive |= "%type" term(term) BLOCK(type) csymbol(name) {
grammar->term_types.insert(std::make_pair(*term, std::make_pair(*type, *name))); grammar->term_types.insert(std::make_pair(*term, std::make_pair(*type, *name)));
} }
directive |= "%destructor" symbol(sym) varname(name) { directive |= "%destructor" symbol(sym) csymbol(name) {
grammar->destructors.insert(std::make_pair(*sym, *name)); grammar->destructors.insert(std::make_pair(*sym, *name));
} }
@ -82,7 +82,7 @@ directive |= "%header" BLOCK(block) {
grammar->header_block = *block; grammar->header_block = *block;
} }
directive |= "%extra_arg" BLOCK(type) varname(name) { directive |= "%extra_arg" BLOCK(type) csymbol(name) {
grammar->extra_args.push_back(std::make_pair(*type, *name)); grammar->extra_args.push_back(std::make_pair(*type, *name));
} }
@ -107,14 +107,14 @@ rhs |= rhs(=rhs) symbol(sym) {
return rhs; return rhs;
} }
rhs |= rhs(=rhs) symbol(sym) '(' varname(var) ')' { rhs |= rhs(=rhs) symbol(sym) '(' csymbol(var) ')' {
rhs->first.push_back(*sym); rhs->first.push_back(*sym);
rhs->second.emplace_back(*var, true); rhs->second.emplace_back(*var, true);
return rhs; return rhs;
} }
rhs |= rhs(=rhs) symbol(sym) '(' '=' varname(var) ')' { rhs |= rhs(=rhs) symbol(sym) '(' '=' csymbol(var) ')' {
rhs->first.push_back(*sym); rhs->first.push_back(*sym);
rhs->second.emplace_back(*var, false); rhs->second.emplace_back(*var, false);
@ -136,8 +136,8 @@ action |= BLOCK(=v) [v]
action |= SQBLOCK(v) [new std::string("return " + *v + ";")] action |= SQBLOCK(v) [new std::string("return " + *v + ";")]
namespace |= varname(v) [new std::vector<std::string> {*v}] namespace |= csymbol(v) [new std::vector<std::string> {*v}]
namespace |= namespace(=ns) "::" varname(v) { namespace |= namespace(=ns) "::" csymbol(v) {
ns->push_back(*v); ns->push_back(*v);
return ns; return ns;
} }
@ -149,5 +149,5 @@ symbol |= term(=v) [v]
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))]
varname |= SYMBOL_UC(=v) [v] csymbol |= SYMBOL_UC(=v) [v]
varname |= SYMBOL(=v) [v] csymbol |= SYMBOL(=v) [v]