All pastes #345334 Raw Edit

Miscellany

public text v1 · immutable
·published 2007-02-08 12:52 UTC
rendered paste body

fun parenthesised(text) = parenthesised'(explode(text))


and curlybraces x para  = if para=[] then false else case (hd(para)) of
#"{" => curlybraces (curlybraces x) (tl(para)) 
| #"[" => brackets (curlybraces x) (tl(para)) 
| #"(" => parantheses (curlybraces x) (tl(para)) 
| #"]" => false
| #")" => false
| #"}" => x (tl(para))
| _ => curlybraces x (tl(para))

and brackets x para = if para=[] then false else case (hd(para)) of
#"{" => curlybraces (brackets x) (tl(para)) 
| #"[" => brackets (brackets x) (tl(para)) 
| #"(" => parantheses (brackets x) (tl(para)) 
| #"]" => x (tl(para))
| #")" => false
| #"}" => false
| _ => brackets x (tl(para))

and parantheses x para = if para=[] then false else case (hd(para)) of
#"{" => curlybraces (parantheses x) (tl(para)) 
| #"[" => brackets (parantheses x) (tl(para)) 
| #"(" => parantheses (parantheses x) (tl(para)) 
| #"]" => false
| #")" => x (tl(para))
| #"}" => false
| _ => parantheses x (tl(para)) 

and parenthesised'(para) = if para=[] then true else case (hd(para)) of
#"{" => curlybraces parenthesised' (tl(para)) 
| #"[" => brackets parenthesised' (tl(para)) 
| #"(" => parantheses parenthesised' (tl(para)) 
| #"]" => false
| #")" => false
| #"}" => false
| _ => parenthesised'(tl(para))