Ignore:
Timestamp:
Nov 5, 2017, 11:52:18 AM (20 months ago)
Author:
cameron
Message:

Utility functions for regular expression transformations

File:
1 edited

Legend:

Unmodified
Added
Removed
  • icGREP/icgrep-devel/icgrep/re/re_rep.cpp

    r5646 r5725  
    9393}
    9494
     95RE * unrollFirst(Rep * rep) {
     96    RE * e = rep->getRE();
     97    auto lb = rep->getLB();
     98    auto ub = rep->getUB();
     99    if (ub == 0) return makeAlt();  // Can't unroll - return unmatchable regexp.
     100    // Unroll one copy of the loop and simplify.
     101    RE * reduced = makeRep(e, lb == 0 ? lb : lb - 1, ub == Rep::UNBOUNDED_REP ? ub : ub - 1);
     102    RE * unrolled = makeSeq({e, reduced});
     103    if (lb == 0) return makeAlt({makeSeq(), unrolled});
     104    else return unrolled;
    95105}
     106RE * unrollLast(Rep * rep) {
     107    RE * e = rep->getRE();
     108    auto lb = rep->getLB();
     109    auto ub = rep->getUB();
     110    if (ub == 0) return makeAlt();  // Can't unroll - return unmatchable regexp.
     111    // Unroll one copy of the loop and simplify.
     112    RE * reduced = makeRep(e, lb == 0 ? lb : lb - 1, ub == Rep::UNBOUNDED_REP ? ub : ub - 1);
     113    RE * unrolled = makeSeq({reduced, e});
     114    if (lb == 0) return makeAlt({makeSeq(), unrolled});
     115    else return unrolled;
     116}
     117}
Note: See TracChangeset for help on using the changeset viewer.