1
0
forked from GitHub/gf-core

reuse PgfParser::before instead of the new PgfParser::fetch_state

This commit is contained in:
Krasimir Angelov
2022-10-03 11:51:34 +02:00
parent c15b5271a9
commit 0bc7e8ea2e
2 changed files with 17 additions and 19 deletions

View File

@@ -210,7 +210,6 @@ public:
} }
choice = new Choice(conts, ++parser->last_choice_id, inside_prob); choice = new Choice(conts, ++parser->last_choice_id, inside_prob);
choice->trace(parser->after); choice->trace(parser->after);
parser->after->choices.insert(std::pair<ParseItemConts*,Choice*>(conts, choice)); parser->after->choices.insert(std::pair<ParseItemConts*,Choice*>(conts, choice));
} else { } else {
choice = itr2->second; choice = itr2->second;
@@ -393,14 +392,14 @@ public:
if (choice->items.size() == 1) { if (choice->items.size() == 1) {
prob_t outside_prob = get_prob()-choice->viterbi_prob; prob_t outside_prob = get_prob()-choice->viterbi_prob;
for (auto prod : choice->prods) { for (auto prod : choice->prods) {
parser->fetch_state->queue.push(new ExprItem(choice,prod,outside_prob,u)); parser->before->queue.push(new ExprItem(choice,prod,outside_prob,u));
} }
} else { } else {
for (auto ep : choice->exprs) { for (auto ep : choice->exprs) {
combine(parser,choice->conts,ep.first,ep.second,u); combine(parser,choice->conts,ep.first,ep.second,u);
} }
} }
return parser->fetch_state; return parser->before;
} }
PgfExpr arg = u->emeta(0); PgfExpr arg = u->emeta(0);
@@ -409,7 +408,7 @@ public:
arg_index++; arg_index++;
} }
State *prev = parser->fetch_state; State *prev = parser->before;
parent->exprs.push_back(std::pair<PgfExpr,prob_t>(expr,inside_prob)); parent->exprs.push_back(std::pair<PgfExpr,prob_t>(expr,inside_prob));
for (auto item : parent->items) { for (auto item : parent->items) {
if (item->combine(parser,parent->conts,expr,inside_prob,u)) { if (item->combine(parser,parent->conts,expr,inside_prob,u)) {
@@ -422,7 +421,7 @@ public:
virtual bool combine(PgfParser *parser, ParseItemConts *conts, PgfExpr expr, prob_t prob, PgfUnmarshaller *u) virtual bool combine(PgfParser *parser, ParseItemConts *conts, PgfExpr expr, prob_t prob, PgfUnmarshaller *u)
{ {
parser->fetch_state->queue.push(new ExprItem(this,expr,prob,u)); parser->before->queue.push(new ExprItem(this,expr,prob,u));
return false; return false;
} }
@@ -519,8 +518,8 @@ public:
if (choice->items.size() == 1) { if (choice->items.size() == 1) {
prob_t prob = conts->state->viterbi_prob+inside_prob; prob_t prob = conts->state->viterbi_prob+inside_prob;
for (Production *prod : choice->prods) { for (Production *prod : choice->prods) {
parser->fetch_state->queue.push(new ExprItem(choice, parser->before->queue.push(new ExprItem(choice,
prod, prob+prod->lin->lincat->abscat->prob, u)); prod, prob+prod->lin->lincat->abscat->prob, u););
} }
} else { } else {
for (auto ep : choice->exprs) { for (auto ep : choice->exprs) {
@@ -528,7 +527,7 @@ public:
} }
} }
} }
return parser->fetch_state; return parser->before;
} }
} }
@@ -635,7 +634,6 @@ PgfParser::PgfParser(ref<PgfConcr> concr, ref<PgfConcrLincat> start, PgfText *se
this->last_choice_id = 0; this->last_choice_id = 0;
this->before = NULL; this->before = NULL;
this->after = NULL; this->after = NULL;
this->fetch_state = NULL;
this->m = m; this->m = m;
} }
@@ -710,30 +708,30 @@ void PgfParser::end_matches(PgfTextSpot *end, PgfExn* err)
void PgfParser::prepare() void PgfParser::prepare()
{ {
fetch_state = after; after->queue.push(new MetaItem(after,0,0,NULL));
fetch_state->queue.push(new MetaItem(after,0,0,NULL)); before = after;
} }
PgfExpr PgfParser::fetch(PgfDB *db, PgfUnmarshaller *u, prob_t *prob) PgfExpr PgfParser::fetch(PgfDB *db, PgfUnmarshaller *u, prob_t *prob)
{ {
DB_scope scope(db, READER_SCOPE); DB_scope scope(db, READER_SCOPE);
while (fetch_state != NULL && fetch_state->queue.empty()) { while (before != NULL && before->queue.empty()) {
fetch_state = fetch_state->next; before = before->next;
} }
while (!fetch_state->queue.empty()) { while (!before->queue.empty()) {
Item *item = fetch_state->queue.top(); Item *item = before->queue.top();
fetch_state->queue.pop(); before->queue.pop();
item->trace(after,m); item->trace(after,m);
if (fetch_state->prev == NULL) { if (before->prev == NULL) {
*prob = item->get_prob(); *prob = item->get_prob();
return item->get_expr(u); return item->get_expr(u);
} }
fetch_state = item->proceed(this,u); before = item->proceed(this,u);
} }
return 0; return 0;

View File

@@ -50,7 +50,7 @@ private:
size_t last_choice_id; size_t last_choice_id;
State *before, *after, *fetch_state; State *before, *after;
PgfMarshaller *m; PgfMarshaller *m;
}; };