]> ocean-lang.org Git - ocean/commitdiff
parsergen: fix return of final result.
authorNeilBrown <neilb@suse.de>
Sun, 15 Jun 2014 07:59:27 +0000 (17:59 +1000)
committerNeilBrown <neilb@suse.de>
Sun, 15 Jun 2014 07:59:27 +0000 (17:59 +1000)
We cannot really shift the final result onto the stack, because
there is not 'goto' for '$eof' in that final state.

So if the shift() fails, hold onto the result and ultimately return it.
This means we don't need to pop it off the stack at the end.

Signed-off-by: NeilBrown <neil@brown.name>
csrc/parsergen.mdc

index fbb561cfe7f2a796927474df4f08cad1225fda09..47cbfc2e48c641ebf49c081ff95346110561cb02 100644 (file)
@@ -2629,6 +2629,7 @@ since the last state which could have been at the start of a line.
                        }
                        if (states[p.next.state].reduce_prod >= 0) {
                                void **body;
+                               void *res;
                                int prod = states[p.next.state].reduce_prod;
                                int size = states[p.next.state].reduce_size;
                                int bufsize;
@@ -2641,10 +2642,13 @@ since the last state which could have been at the start of a line.
                                bufsize = do_reduce(prod, body, config, buf);
 
                                pop(&p, size, do_free);
-                               shift(&p, memdup(buf, bufsize), states);
+                               res = memdup(buf, bufsize);
                                memset(buf, 0, bufsize);
-                               if (prod == 0)
+                               if (!shift(&p, res, states)) {
+                                       if (prod != 0) abort();
                                        accepted = 1;
+                                       ret = res;
+                               }
                                continue;
                        }
                        if (tk->num == TK_out) {
@@ -2691,10 +2695,7 @@ since the last state which could have been at the start of a line.
                                break;
                }
                free(tk);
-               if (accepted)
-                       ret = p.asn_stack[0];
-               else
-                       pop(&p, p.tos, do_free);
+               pop(&p, p.tos, do_free);
                free(p.asn_stack);
                free(p.stack);
                return ret;