summaryrefslogtreecommitdiff
path: root/src/runtime/c/utils
diff options
context:
space:
mode:
authorkr.angelov <kr.angelov@gmail.com>2012-03-07 11:00:17 +0000
committerkr.angelov <kr.angelov@gmail.com>2012-03-07 11:00:17 +0000
commita96da3048948389af8938db562a602907b1e0568 (patch)
tree41c479d8db0a66f90afc7a4a2530bf86fc626c74 /src/runtime/c/utils
parentd6c2943ad11bff20e8aa67bdb80510731308e966 (diff)
libpgf: two APIs - one for finding all parse results and another for finding the best parse result
Diffstat (limited to 'src/runtime/c/utils')
-rw-r--r--src/runtime/c/utils/pgf-translate.c80
1 files changed, 44 insertions, 36 deletions
diff --git a/src/runtime/c/utils/pgf-translate.c b/src/runtime/c/utils/pgf-translate.c
index 5c8e45401..751bcf15b 100644
--- a/src/runtime/c/utils/pgf-translate.c
+++ b/src/runtime/c/utils/pgf-translate.c
@@ -136,52 +136,60 @@ int main(int argc, char* argv[]) {
}
tok = strtok(NULL, " \n");
}
-
- // Now begin enumerating the resulting syntax trees
- GuEnum* result = pgf_parse_result(parse, ppool);
- clock_t end = clock();
+ if (robust_mode) {
+ PgfExpr expr = pgf_parse_best_result(parse, ppool);
- double cpu_time_used = ((double) (end - start)) / CLOCKS_PER_SEC;
- printf("%.2f sec\n", cpu_time_used);
-
- while (true) {
- PgfExpr expr = gu_next(result, PgfExpr, ppool);
-
clock_t end = clock();
+
+ double cpu_time_used = ((double) (end - start)) / CLOCKS_PER_SEC;
+ printf("%.2f sec\n", cpu_time_used);
- // The enumerator will return a null variant at the
- // end of the results.
- if (gu_variant_is_null(expr)) {
- break;
- }
- gu_putc(' ', wtr, err);
- // Write out the abstract syntax tree
- pgf_print_expr(expr, 0, wtr, err);
- gu_putc('\n', wtr, err);
-
- if (robust_mode) {
- double cpu_time_used = ((double) (end - start)) / CLOCKS_PER_SEC;
- printf("%.2f sec\n", cpu_time_used);
- break;
+ if (!gu_variant_is_null(expr)) {
+ gu_putc(' ', wtr, err);
+ // Write out the abstract syntax tree
+ pgf_print_expr(expr, 0, wtr, err);
+ gu_putc('\n', wtr, err);
}
+ } else {
+ // Now begin enumerating the resulting syntax trees
+ GuEnum* result = pgf_parse_result(parse, ppool);
+
+ clock_t end = clock();
+
+ double cpu_time_used = ((double) (end - start)) / CLOCKS_PER_SEC;
+ printf("%.2f sec\n", cpu_time_used);
- // Enumerate the concrete syntax trees corresponding
- // to the abstract tree.
- GuEnum* cts = pgf_lzr_concretize(to_concr, expr, ppool);
while (true) {
- PgfCncTree ctree =
- gu_next(cts, PgfCncTree, ppool);
- if (gu_variant_is_null(ctree)) {
+ PgfExpr expr = gu_next(result, PgfExpr, ppool);
+
+ // The enumerator will return a null variant at the
+ // end of the results.
+ if (gu_variant_is_null(expr)) {
break;
}
- gu_puts(" ", wtr, err);
- // Linearize the concrete tree as a simple
- // sequence of strings.
- pgf_lzr_linearize_simple(to_concr , ctree, lin_idx,
- wtr, err);
+ gu_putc(' ', wtr, err);
+ // Write out the abstract syntax tree
+ pgf_print_expr(expr, 0, wtr, err);
gu_putc('\n', wtr, err);
- gu_writer_flush(wtr, err);
+
+ // Enumerate the concrete syntax trees corresponding
+ // to the abstract tree.
+ GuEnum* cts = pgf_lzr_concretize(to_concr, expr, ppool);
+ while (true) {
+ PgfCncTree ctree =
+ gu_next(cts, PgfCncTree, ppool);
+ if (gu_variant_is_null(ctree)) {
+ break;
+ }
+ gu_puts(" ", wtr, err);
+ // Linearize the concrete tree as a simple
+ // sequence of strings.
+ pgf_lzr_linearize_simple(to_concr , ctree, lin_idx,
+ wtr, err);
+ gu_putc('\n', wtr, err);
+ gu_writer_flush(wtr, err);
+ }
}
}
fail_parse: