Reg Module
signature REG
structure Reg :> REG
This module defines the abstract type of regular expressions.
datatype concr
= EmptyStr
| EmptySet
| Sym of Sym.sym
| Closure of concr
| Concat of concr * concr
| Union of concr * concr
type reg
val fromConcr : concr -> reg
val toConcr : reg -> concr
val inputFromLabToks : (int * Lex.tok) list -> reg * (int * Lex.tok) list
val fromString : string -> reg
val input : string -> reg
val toPP : reg -> PP.pp
val toString : reg -> string
val output : string * reg -> unit
val validPath : reg * int list -> bool
val height : reg -> int
val size : reg -> int
val numLeaves : reg -> int
val select : reg * int list -> reg
val update : reg * int list * reg -> reg
val maximumLengthPath : reg -> int list
val validLeafPath : reg * int list -> bool
val emptyStr : reg
val emptySet : reg
val fromSym : Sym.sym -> reg
val closure : reg -> reg
val concat : reg * reg -> reg
val union : reg * reg -> reg
val isEmptyStr : reg -> bool
val isEmptySet : reg -> bool
val isSym : reg -> bool
val isClosure : reg -> bool
val isConcat : reg -> bool
val isUnion : reg -> bool
val compare : reg Sort.total_ordering
val equal : reg * reg -> bool
val fromStr : Str.str -> reg
val power : reg * int -> reg
val alphabet : reg -> Sym.sym Set.set
val split : reg -> Str.str * reg option
val genConcat : reg list -> reg
val genUnion : reg list -> reg
val rightConcat : reg * reg -> reg
val rightUnion : reg * reg -> reg
val concatsToList : reg -> reg list
val unionsToList : reg -> reg list
val sortUnions : reg -> reg
val allSym : Sym.sym Set.set -> reg
val allStr : Sym.sym Set.set -> reg
val fromStrSet : Str.str Set.set -> reg
type cc
val ccToList : cc -> int list
val singCC : int -> cc
val unionCC : cc * cc -> cc
val succCC : cc -> cc
val cc : reg -> cc
val compareCC : cc Sort.total_ordering
val numConcats : reg -> int
val numSyms : reg -> int
val standardized : reg -> bool
val compareComplexity : reg * reg -> order
val compareComplexityTotal : reg Sort.total_ordering
val weaklySimplified : reg -> bool
val weaklySimplify : reg -> reg
val toStrSetOpt : reg -> Str.str Set.set option
val toStrSet : reg -> Str.str Set.set
val hasEmp : reg -> bool
val hasSym : Sym.sym * reg -> bool
val obviousSubset : reg * reg -> bool
val localSimplificationRelations : reg * reg -> order
val locallySimplified : (reg * reg -> bool) -> reg -> bool
val locallySimplifyTrace : int option * (reg * reg -> bool) -> reg -> bool * reg
val locallySimplify : int option * (reg * reg -> bool) -> reg -> bool * reg
val globallySimplified : (reg * reg -> bool) -> reg -> bool
val globallySimplifyTrace : int option * (reg * reg -> bool) -> reg -> bool * reg
val globallySimplify : int option * (reg * reg -> bool) -> reg -> bool * reg
val renameAlphabet : reg * SymRel.sym_rel -> reg
val rev : reg -> reg
val prefix : reg -> reg
val jforlanNew : unit -> reg
val jforlanEdit : reg -> reg
val jforlanValidate : string -> unit
val jforlanPretty : string -> unit
datatype concr
= EmptyStr
| EmptySet
| Sym of Sym.sym
| Closure of concr
| Concat of concr * concr
| Union of concr * concr
EmptyStr is %, EmptySet is $, and, for all symbols a, Sym a is the one node tree whose label is a. For all regular expressions reg, Closure reg is the tree whose root node is labeled by "*" and whose only child is reg. And, for all regular expressions reg1 and reg2: Concat(reg1, reg2) is the tree whose root node is labeled by "@", with left child reg1 and right child reg2; and Union(reg1, reg2) is the tree whose root node is labeled by "+", with left child reg1 and right child reg2.
type reg
concr.
fromConcr concr
concr.
toConcr reg
reg.
inputFromLabToks lts
lts, consuming as much of lts as possible, and returning the pair of that regular expression and the rest of lts. Issues an error message if this can't be done. The labeled token list that is returned will never begin with "+" (Lex.Plus) or "(" (Lex.OpenPar). Either such a token will be consumed in the process of parsing a bigger regular expression, or an error will occur during the attempt to do so.
fromString s
s.
input fil
fil.
toPP reg
reg.
toString reg
reg to a string.
output reg
reg to the file named by fil.
validPath(reg, ns)
ns is a valid path for reg.
height reg
reg.
size reg
reg.
numLeaves reg
reg.
select(reg, ns)
reg pointed to by ns. Issues an error message if ns isn't a valid path for reg.
update(reg, ns, reg')
reg pointed to by ns with reg'. Issues an error message if ns isn't valid for reg.
maximumLengthPath reg
reg.
validLeafPath(reg, ns)
ns is a valid path for reg that points to a leaf of reg, i.e., to a subtree with no children.
emptyStr
EmptyStr.
emptySet
EmptySet.
fromSym a
Sym a.
closure reg
Closure reg.
concat(reg1, reg2)
Concat(reg1, reg2).
union(reg1, reg2)
Union(reg1, reg2).
isEmptyStr reg
reg is EmptyStr.
isEmptySet reg
reg is EmptySet.
isSym reg
reg is a symbol.
isClosure reg
reg is a closure.
isConcat reg
reg is a concatenation.
isUnion reg
reg is a union.
compare(reg1, reg2)
local
fun kind EmptyStr = 0
| kind EmptySet = 1
| kind (Sym _) = 2
| kind (Closure _) = 3
| kind (Concat _) = 4
| kind (Union _) = 5
in
fun compare(reg, reg') =
case Int.compare(kind reg, kind reg') of
LESS => LESS
| EQUAL =>
(case (reg, reg') of
(Sym a, Sym a') =>
Sym.compare(a, a')
| (Closure reg, Closure reg') =>
compare(reg, reg')
| (Concat(reg1, reg2), Concat(reg1', reg2')) =>
(case compare(reg1, reg1') of
LESS => LESS
| EQUAL => compare(reg2, reg2')
| GREATER => GREATER)
| (Union(reg1, reg2), Union(reg1', reg2')) =>
(case compare(reg1, reg1') of
LESS => LESS
| EQUAL => compare(reg2, reg2')
| GREATER => GREATER)
| _ => EQUAL)
| GREATER => GREATER
end
equal(reg1, reg2)
reg1 and reg2 are equal.
fromStr x
x. It's implemented by:
fun fromStr nil = EmptyStr
| fromStr [b] = Sym b
| fromStr (b :: bs) = Concat(Sym b, fromStr bs)
power(reg, n)
reg to the power n. Issues an error message if n is negative.
alphabet reg
reg.
split
local
fun splt (Sym a) = ([a], NONE)
| splt (Concat(Sym a, reg)) =
let val (bs, regOpt) = splt reg
in (a :: bs, regOpt) end
| splt reg = (nil, SOME reg)
in
fun split EmptyStr = (nil, NONE)
| split reg = splt reg
end
genConcat
fun genConcat nil = EmptyStr
| genConcat [reg] = reg
| genConcat (reg :: regs) = Concat(reg, genConcat regs)
genUnion
fun genUnion nil = EmptySet
| genUnion [reg] = reg
| genUnion (reg :: regs) = Union(reg, genUnion regs)
rightConcat
fun rightConcat(Concat(reg1, reg2), reg3) =
Concat(reg1, rightConcat(reg2, reg3))
| rightConcat(reg1, reg2) = Concat(reg1, reg2)
rightUnion
fun rightUnion(Union(reg1, reg2), reg3) =
Union(reg1, rightUnion(reg2, reg3))
| rightUnion(reg1, reg2) = Union(reg1, reg2)
concatsToList
fun concatsToList (Concat(reg1, reg2)) = reg1 :: concatsToList reg2
| concatsToList reg = [reg]
unionsToList
fun unionsToList (Union(reg1, reg2)) = reg1 :: unionsToList reg2
| unionsToList reg = [reg]
sortUnions reg
genUnion regs, where regs is the result of sorting (using compare) unionsToList
reg into strictly ascending order (no duplicates).
allSym bs
bs.
allStr bs
bs.
fromStrSet xs
genUnion(map fromStr (Set.toList xs))
type cc
ccToList cc
cc.
singCC n
[n], if n is non-negative. Issues an error message, if n is negative.
unionCC(cc1, cc2)
cc1 and cc2.
succCC cc
cc.
cc reg
reg.
compareCC(cc1, cc2)
cc1 and cc2 in the total ordering on closure complexities.
numConcats reg
reg.
numSyms reg
reg.
standardized reg
reg is standardized.
compareComplexity(reg1, reg2)
reg1 and reg2: LESS means reg1 is strictly simpler (less complex) than reg2; EQUAL means reg1 and reg2 are equally simple/complex; and GREATER means reg1 is more complex (less simple) than reg2.
compareComplexityTotal(reg1, reg2)
case compareComplexity(reg1, reg2) of
LESS => LESS
| EQUAL => compare(reg1, reg2)
| GREATER => GREATER
weaklySimplified reg
reg is weakly simplified.
weaklySimplify reg
reg.
toStrSetOpt reg
SOME of the language generated by reg, if this language is finite, and NONE, if this language is infinite.
toStrSet reg
reg. Issues an error message if the language generated by reg is infinite.
hasEmp reg
reg generates the empty string.
hasSym(a, reg)
reg generates [a].
obviousSubset(reg1, reg2)
reg1 is obviously a subset of reg2.
localSimplificationRelations(reg1, reg2)
LESS if reg1 is related to reg2 in the local simplification well-ordering;
EQUAL if reg1 is related to reg2 in the local simplification equivalence relation; and
GREATER if reg2 is related to reg1 in the local simplification well-ordering.
locallySimplified sub reg
sub is a conservative approximation to subset testing, then locallySimplified tests whether reg is locallySimplified with respect to sub.
locallySimplifyTrace (NONE, sub) reg
sub is a conservative approximation to subset testing, then locallySimplifyTrace returns the pair (true, reg'), where reg' is the local simplification of reg with respect to sub. locallySimplifyTrace issues a series of tracing messages, explaining its operation.
locallySimplifyTrace (SOME n, sub) reg
sub is a conservative approximation to subset testing, then locallySimplifyTrace returns the pair (full, reg'), where reg' is the local simplification of reg with respect to sub, except that—at each recursive call of its principal function—it considers at most n structural reorganizations of its argument, and full will be true iff all structural reorganizations of reg' were considered, so that reg' is locally simplified. locallySimplifyTrace issues a series of tracing messages, explaining its operation. Issues an error message if n isn't at least 1.
locallySimplify
locallySimplifyTrace, except that no tracing messages are issued.
globallySimplified sub reg
sub is a conservative approximation to subset testing, then globallySimplified tests whether reg is globally simplified with respect to sub.
globallySimplifyTrace (NONE, sub) reg
sub is a conservative approximation to subset testing, then globallySimplifyTrace returns the pair (true, reg'), where reg' is the global simplification of reg with respect to sub. globallySimplifyTrace issues a series of tracing messages, explaining its operation.
globallySimplifyTrace (SOME n, sub) reg
sub is a conservative approximation to subset testing, then globallySimplifyTrace returns the pair (full, reg'), where reg' is the global simplification of reg with respect to sub, except it curtails its search after considering n candidates, and full is true iff all candidates were considered, and so reg' is globally simplified. globallySimplifyTrace issues a series of tracing messages, explaining its operation. Issues an error message if n isn't at least 1.
globallySimplify
globallySimplifyTrace except that no tracing messages are issued.
renameAlphabet(reg, rel)
reg using the bijection rel. Issues an error message if rel is not a bijection from a superset of the alphabet of reg to some set.
rev reg
reg.
prefix reg
reg.
jforlanNew()
jforlanEdit reg
reg, and returning the resulting regular expression that the user commits. Issues an error message if the user aborts, instead.
jforlanValidate
jforlanPretty
Forlan Version 4.15
Copyright © 2022 Alley Stoughton