diff options
author | Mattias Andrée <maandree@operamail.com> | 2014-11-28 14:53:40 +0100 |
---|---|---|
committer | Mattias Andrée <maandree@operamail.com> | 2014-11-28 14:53:40 +0100 |
commit | c84e0b022321e72282a6664047035300f9a8458f (patch) | |
tree | 57760afa973b4b5088e2cb4b36b88bdb78bc8d5e | |
parent | m + some unordered subseq simplification (diff) | |
download | mds-c84e0b022321e72282a6664047035300f9a8458f.tar.gz mds-c84e0b022321e72282a6664047035300f9a8458f.tar.bz2 mds-c84e0b022321e72282a6664047035300f9a8458f.tar.xz |
mds-kbdc: eliminate unorded subseq:s inside alternations
Signed-off-by: Mattias Andrée <maandree@operamail.com>
-rw-r--r-- | src/mds-kbdc/simplify-tree.c | 24 |
1 files changed, 21 insertions, 3 deletions
diff --git a/src/mds-kbdc/simplify-tree.c b/src/mds-kbdc/simplify-tree.c index 7ca0729..705a9dc 100644 --- a/src/mds-kbdc/simplify-tree.c +++ b/src/mds-kbdc/simplify-tree.c @@ -62,6 +62,15 @@ static mds_kbdc_parsed_t* restrict result; */ static int simplify(mds_kbdc_tree_t* restrict tree); +/** + * Simplify an unordered subsequence-subtree + * + * @param tree The unordered subsequence-subtree + * @return Zero on success, -1 on error + */ +static int simplify_unordered(mds_kbdc_tree_unordered_t* restrict tree); + + /** * Simplify a macro call-subtree @@ -286,7 +295,8 @@ static int simplify_alternation(mds_kbdc_tree_alternation_t* restrict tree) else if (argument->type == MDS_KBDC_TREE_TYPE_ALTERNATION) { /* Alternation nesting. */ - NEW_ERROR(argument, WARNING, "alternation inside alternation is unnessary"); + if (argument->processed != PROCESS_LEVEL) + NEW_ERROR(argument, WARNING, "alternation inside alternation is unnessary"); if (simplify_alternation(&(argument->alternation))) return -1; if (argument->type == MDS_KBDC_TREE_TYPE_ALTERNATION) @@ -309,8 +319,16 @@ static int simplify_alternation(mds_kbdc_tree_alternation_t* restrict tree) } redo = 1; } - - /* TODO unordered (warn: discouraged) */ + else if (argument->type == MDS_KBDC_TREE_TYPE_UNORDERED) + { + /* Nesting unordered subsequence, + simplifies to alternation of ordered subsequence. */ + NEW_ERROR(argument, WARNING, "unorderd subsequence inside alternation is discouraged"); + if (simplify_unordered(&(argument->unordered))) + return -1; + argument->processed = PROCESS_LEVEL; + redo = 1; + } return 0; pfail: |