Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Tcl debugging

Status
Not open for further replies.

prashhiit

Programmer
Sep 6, 2011
3
set x 1
if {$x == 1} {
puts "x=1"
} else {
jsfdlkdsjfh
}


Hello All,

In the above code, there is a Syntax error in the 'else' part. If I run this in tclsh, I don't get any error. Unlike c/C++, tclsh does not give all syntax errors in the script. Since, x=1 if condition is always satisfied so it never enters into else part.

My Question is "How can I get syntax error in the 'else' part. What should I do to get all Syntax errors in my Tcl Script."


Please suggest me


Thanks
Prashanth
 
There's only a "syntax error" because you haven't defined a procedure called "jsfdlkdsjfh". How is the interpreter supposed to know that?

_________________
Bob Rashkin
 
Hi


That is what my question. I don't get any error even if "jsfdlkdsjfh" procedure is not defined. What should I do to get error message "procedure not defined".


Please also consider this case

set x 1
if {$x ==1 } {
puts "x=1"
} else {
set x "End double quote is missing
}


in the 'else' part, end double quote is missed. When I run this code, I don't get any syntax error.


 
You don't get any error because your procedures doesn't execute the [highlight]else-blocks[/highlight].

When you change the first procedure so it executes the [highlight]else-block[/highlight], for example to:
Code:
[highlight]set x 10[/highlight]
if {$x == 1} {
  puts "x=1"
} else {
  jsfdlkdsjfh
}
the you will get this error
Code:
C:\_mikrom\Work>tclsh85 prashhiit01.tcl
[highlight]invalid command name "jsfdlkdsjfh"[/highlight]
    while executing
"jsfdlkdsjfh"
    invoked from within
"if {$x == 1} {
  puts "x=1"
} else {
  jsfdlkdsjfh
}"
    (file "prashhiit01.tcl" line 2)
When you change the second procedure so it executes the [highlight]else-block[/highlight], for example to:
Code:
[highlight]set x 10[/highlight]
if {$x ==1 } {
  puts "x=1"
} else {
  set x "End double quote is missing
}
the you will get this error
Code:
C:\_mikrom\Work>tclsh85 prashhiit02.tcl
[highlight]missing "[/highlight]
    while executing
"set x "End double quote is missing
"
    invoked from within
"if {$x ==1 } {
  puts "x=1"
} else {
  set x "End double quote is missing
}"
    (file "prashhiit02.tcl" line 2)
In both cases, the error description says clearly what's wrong.
 
Yes, It throws error message only when it enters into else block.

This is not the case in C/C++.


Is there any Tcl debugger which displays all syntax errors in a block even if it does not enter into that particular block.


Please let me know

Thanks
Prashanth
 
Tcl is interpreted language in difference to C which is compiled language, therefore the behaviour is different.
 
prashhiit said:
Is there any Tcl debugger which displays all syntax errors in a block even if it does not enter into that particular block.
It's not debugging, but syntax checking. Try to google for [highlight]tcl syntax checker[/highlight]

I tried Nagelfar - A Tcl Syntax checker, which has found all errors you posted:
Code:
Checking file prashhiit01.tcl
prashhiit01.tcl: Line   5: W Unknown command "jsfdlkdsjfh"
Checking file prashhiit02.tcl
prashhiit02.tcl: Line   5: E Could not complete statement.
                             One double quote would complete the first line
                             One double quote would complete the script body at line 6.
Done (E/W/N: 1/1/0)

Maybe there are some (commercial) IDEs for Tcl development with a build in syntax checker...
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top