sigma: some countable set of characters
sigma-star: all finite length string using chars in sigma
epsilon: empty string
language: a subset of sigma-star

Chomsky hierarchy: a hierarchy of language
regular language: described by regular expression
regular automata: described by finite automata
context-free language: described by context-free grammar
context-sensitive language: described by context-sensitive grammar

Regular Expression

Wring Code for Parsing

(*accept: regexp -> string -> bool*)
fun accept r s = match r (String.explore s) (fn [] => true | _ => false_)
(*match: regexp -> char list -> (char list -> bool) -> bool
REQUIRES: k totak
ENSURES: match r cs k -> {
true if exists p, s, s.t. cs ~= p@s and p in L(r) and k(s) |-> true
false otherwise
}
*)
fun match (Char a) [] k = false
| match (Char a) (c::cs') = a = c andalso k cs'
| match One cs k = k cs
| match Zero cs k = false
| match (Times (r1, r2)) cs k = match r1 cs (fn cs' => match r2 cs' k)
| match (Plus (r1, r2)) cs k = match r1 cs k orelse match r2 cs k
| match (Star r) cs k = k cs match r cs (fn cs' => not(cs=cs') andalso match (Star r) cs' k)

try aba in L((a+ab)(a+b))

Prove-oriented debugging

termination: it returns a value for all value and total input