Tcl 脚本中错误的静态检测 [英] Static detection of errors in Tcl scripts

查看:31
本文介绍了Tcl 脚本中错误的静态检测的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经开发了一些代码,但我在 Linux 机器上遇到了 Tcl 解释器的错误标记问题.

I have developed some code, and I'm facing problem with error flagging of the Tcl interpreter on a Linux machine.

#!/usr/bin/tclsh
if {1} {
  puts "abc1"
} elseif {} {
  puts "abc2" 
}

上述代码在进入"elseif"条件之前不会标记错误elseif 条件.有什么办法可以检查这种无意中出现的拼写错误.

The above code is not flagging error for "elseif" condition until it get into the elseif condition. Is there any way to check this kind of typo error done unintentionally.

推荐答案

为了详细说明 Donal 的回答,Tcl 在编译时不会发现错误,因为在一般情况下它无法完成,在 if 之前执行的任何代码都可能已重新定义if 命令,所以它可能是有效的,确定是否是这种情况的唯一方法是运行代码(即这是停机问题)

To elaborate on Donal's answer, Tcl does not find errors at compile time because in the general case it cannot be done, any code executed before the if might have redefined the if command, so it could be valid, the only way to determine if this is the case is to run the code (i.e. this is the halting problem)

考虑这个脚本:

gets stdin input
if {$input == "fail"} {
  rename if if_
  proc if {arg1 arg2 arg3} {
    puts "ha ha"
  }
}
if {1} { puts "success"}

很明显,如果不运行程序,就不可能静态地确定 if {1} 行是否具有正确数量的参数

clearly it is impossible to statically determine if the if {1} line has the right number of arguments without running the program

TCL 真的几乎没有语法,编译器无法检查,你能做的最好的事情就是 Lint 风格的警告,这只会在某些情况下准确

TCL really has virtually no syntax, there is nothing a compiler can check, the best you can do is Lint style warnings, which will only be accurate in some cases

这篇关于Tcl 脚本中错误的静态检测的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆