A parser for Tcl scripts and expressions ======================================== Rev 0.10: Initial release The acronym for this extensions is admittedly a bit strained, but the code for this was indeed written some time ago to scratch an itch: "Self-Contained Runtime pArser for Tcl, as Critcl Hack" This extension is as close as one gets to "parsing" Tcl, even though this language has no real syntax (at least not in the BNF sense). There are two commands, both best illustrated with an example: % puts [scratch::parse {set a [c $d(1)]} 0] T {X {L set} {L a} {X {L c} {A d {L 1}}}} % puts [scratch::expr {1 + 2 * $a + [b $c]} 0] B + {B + {L 1} {B * {L 2} {S a}}} {X {L b} {S c}} % In the above, the first example generates a parse tree for a script, whereas the second works on algebraic expressions. The result is a tree of nodes, each a list with a type and arguments. There is also an alternative way to encode the resulting tree, which does not return tokens as strings but as two integers: offset + size: % puts [scratch::parse {set a [c $d(1)]} 1] T {X {L 0 3} {L 4 1} {X {L 7 1} {A 10 1 {L 12 1}}}} % puts [scratch::expr {1 + 2 * $a + [b $c]} 1] B + {B + {L 0 1} {B * {L 4 1} {S 9 1}}} {X {L 14 1} {S 17 1}} %