proc cellEval {t ind {n1 {}} {n2 {}} {op {}}} {

	global CellValues CellFormulae Procs
#	We have an expression possibly containing cell addresses!
#	cell addresses are like $B2, $C66
#	we have to translate these into numeric indices

	lassign [split $ind ,] row col

	set form $CellFormulae($ind)

	set stats "sum avg min max cnt"

#	puts stderr "in cellEval:  formula $form"

	set depends ""
	while {![lempty $form]} {
#	if it's a func then it is followed by something in parens.
		set w [lvarpop form]
		if {[lsearch $stats [crange $w 0 2]] >= 0} {
			lassign [expandStat $w] v ilist
#			puts stderr "Got v $v from w $w"
			if {$v == "ERR"} {
				puts stderr "ERROR evaluating expression $w"
				$t tag cell error $ind
				set cellValues($ind) "<ERR>"
				return 0
			}
			append exp "$v "
			lvarcat depends $ilist
			continue
		}
#	if it's not a func then it's a constant or cell ref
		if {[cindex $w 0] == "\$"} {
			if {[string first . $w] < 0} {
			set rc [cellIndex [crange $w 1 end]]
			set v $CellValues($rc)
			lappend depends $rc
			} else {
			puts stderr "ERROR range without stat func: $w"
			$t tag cell error $ind
                        set cellValues($ind) "<ERR>"
                        return 0
#			lassign [cellIndex [crange $w 1 end]] i1 i2
#			set v "\{[$t get $i1 $i2]\}"
			}
			append exp "$v "
		} else {
			append exp "$w "
		}
	}

	set err [catch {eval set val \[expr \{$exp \} \] } res]

	if {$err} {
		puts stderr "ERROR evaluating expression $form"
		puts stderr "      $exp"
		$t tag cell error $ind
		set CellValues($ind) "<ERR>"
		return 0
	} else {
		set CellValues($ind) $val
		$t tag cell formula $ind
		foreach d $depends {
			set cmd "cellEval $t $ind"
			if {![info exists Procs($d)]} {
				lappend Procs($d) $cmd
#				puts stderr "$ind depends on $d, trace $d"
			} else {
				if {[lsearch $Procs($d) $cmd] < 0} {
					lappend Procs($d) $cmd
#					puts stderr "$ind depends on $d, trace $d"
				}
			}
			if {[trace vinfo CellValues($d)] == ""} {
				trace variable CellValues($d) w "cellChange $d"
			}
		}
		return 1
	}
}

