Vous êtes sur la page 1sur 4

TCL working :

Two steps are there in interpreting a TCL Script


- Parsing -Grouping and Substitution
- Execution - command invocation
space/tab is used as word separator
; or newline is used as command seprarator
puts Hi
puts "How are you?"
Also can be written as
puts Hi; puts How are you?
TCL is case sensitive
puts ---- valid
Puts ---- invalid
space should not be given where it is not required as it is also recognized as c
haracter

In grouping stage they are just words


if $, [], and \ are there then only substitution
$ --- variable substitution
[] --- command substitution
\ --- backslash substitution
puts hi
set a 10 set is command a and 10 are arguments.
command is called from library and performs the function set and will execute it
s command
purpose
sequential execution
if first line is problematic it will not proceed to execution. But parsing can b
e done as
it just recognizes the number of words when it does not has substitution
When substitution is invalid
set a 10
puts $a is equivalent to ( a = 10)

if following command is execution


set a 10 30
it will have problem at execution as memory allocation is for one and there are
two values given
so it will reject the command and show error.
set varName ?newValue? minimum one argument max 2 argument the argument in quest
ion mark is
optional argument
set a "10 30"
does not gives error
as they result in grouping
grouping techniques:
""
{} - no substituition can happen
set a 10
set a
set a 20
what ever argument is 10 or "10" is taking as string
# is used to comment in TCL
set a 10; #create a variable
set a; #reading a variable, it reads the value but not prints it
puts [set a]; # set a has output 10 and puts print it
set b [set a]; #
set a 20; # modify variable

#this is a comment; puts hi (when interpreter sees first # it makes all line as
comment hence ignores)
set a 100;
set A 10; has no problem
set B; has problem as the variable is not initialized hence cant read B so error
set a 20;
puts [set a]; #reading
incr
puts $a
incr a ( incr commands takes everything as integer and increments by 1 in defaul
t)
incr variable name ?incrementValue?
incrementValue - optional
default value = +1
it can take any positive and negative integer not zero

set a 10
set b 20
set c a+b; #prints 10+20 not 30

puts $c; # it will just

set a 10 #create a variable (invalid as there is not semicolon command separator


)
set command is used to create, read and modify variable all of

puts $a

Now about \ -- backslash substitution


puts "the value of this computer is $5000" (as $ prefix it will not print as it
interpretes $ prefix as
variable
to negate the function
puts "the value of this computer is \$5000" ( now it will print )
puts {the value of this computer is $5000}
\t - tab space
\b - backspace
\n - new line
\r - carriage return
\a - accoustic beep sound

puts ?-nonewline? ?channelId? string


puts hi
puts hello
output ( by default new line is given)
hi
hello
puts -nonewline hi ( has
puts hello
output (
hihello

- (hiphen) : in TCL flags begin with hiphen

puts hi
standard input/output devices:
stdout - monitor
stderr - monitor
std in - keyboard

puts hi
puts stdout hi (explicitly saying to print on monitor)
puts stderr hi (explicitely saying to print on monitor)
set company Wipro
append company Technologies
puts $company
it prints WiproTechnologies
append company Wipro
append company Technologies
puts $company
it also prints WiproTechnogies (as append also creates a variable)
set company Wipro
append company " "
append company Technologies
puts $company
output: Wipro Technologies
set company Wipro
append company " ""
syntax of append command:
append varName value1 ? value2 value3 .............. value n?
append company " Technologies Bangalore Karnataka

puts { the value of this computer is \t: $5000} it will not put tab as it can no
t substi

Vous aimerez peut-être aussi