SlideShare a Scribd company logo
Corporate
Presentation
1
© Radiant Semiconductors Confidential
TCL
Tool Command
Language
Which language Computer understand ?
Machine language consists of binary numbers (0s and 1s), while humans understand high-
level languages, such as English.
Then how will Humans communicate with the
computer ?
We use compilers and interpreters to facilitate communication between humans and
computers.
tcl language ppt to learn the tcl go through it
Difference between Compiler and Interpreter
What is TCL?
•TCL stands for Tool Command Language.
• It was designed by John Ousterhout of the University of California, Berkeley in 1988.
•It's an opensource multi-purpose interpreted powerful dynamic scripting language.
•It aims at providing ability for the programs to interact with other programs.
•TCL is fit for both the smallest and largest programming task.
•Tcl was developed initially for Unix. It was then ported to Windows, DOS, OS/2, and Mac OSX.
•Tcl is much similar to other unix shell languages like Bourne Shell (Sh), the C Shell (csh), the Korn Shell
(sh), and Perl.
•Widely used in various domains in VLSI Design and Verification.
TCL in VLSI
• Front – End Synthesis Tool
• Back-End Placement and Route Tool (PnR)
• Static Timing Analysis Tool (STA)
• Reliability Analysis Tool (EM-IR)
• Scripted Waveform Verification in Analog
• Design for Testability Tool (DFT)
Why Should we learn TCL for VLSI Design
• Efficiency: TCL automation dramatically reduces manual effort, accelerating design processes.
• Accuracy: By automating repetitive tasks, TCL minimizes the risk of human errors, leading to more reliable
designs.
• Flexibility: TCL's versatility adapts to the evolving requirements of VLSI projects, allowing us to quickly
adjust to changing design needs.
• Competitive Edge: TCL proficiency is a vital skill in the VLSI industry, giving you a competitive advantage
in job markets.
Why TCL?
• TCL is not just another programming language; It forms the backbone of VLSI design automation specifically for
Physical Design Engineers. It empowers engineers to automate complex and repetitive tasks, improving efficiency,
accuracy, and productivity in semiconductor design.
• In many EDA [Electronics Design Automation] tools we will use TCL for scripting.
• Simplest syntax
• Cross-platform availability
• Data structure: TCL provides built in data structures such as lists, dictionaries and arrays.
• Control Structures: Use built-in control structures such as if, for, foreach, while, switch etc
• Provides facility for creating GUIs
• Provides enough programmability for complex scripts
• Rapid development
• Open source – Anyone may, without charge, download and inspect the source code to Tcl.
Some key concepts and their importance in VLSI
1. Understanding TCL Variables:
Variables in TCL are essential for storing data, enabling us to manipulate values, strings, and numbers
effortlessly. They are the building blocks of TCL scripts, allowing us to work with data effectively.
2. Mathematical and Boolean Operations:
TCL offers a strong set of mathematical and Boolean operators. These operations are invaluable when dealing
with calculations, comparisons, and logic in VLSI Physical Design.
3. List Management and Manipulation:
Lists are versatile data structures in TCL, and they find applications in various aspects of VLSI, from managing
design constraints to handling simulation scenarios. TCL's list manipulation capabilities are essential for data
organization and analysis.
4. File Handling and Manipulation:
Design Engineers have to work with numerous design files in the VLSI. TCL excels in file manipulation
tasks, making it effortless to read, write, and process files, facilitating data exchange with EDA tools.
5. Variable Manipulation:
TCL's variable manipulation features allow engineers to efficiently modify and adapt data to meet
specific design requirements. This is invaluable when working with design constraints, parameters, and
configurations.
6. Control Statements:
TCL provides a range of control statements like loops and conditional statements. These enable engineers
to create flexible and adaptive scripts, which are critical for automating complex VLSI workflows.
7. Procedures:
In VLSI, scripts must often be modular and reusable. Procedures in TCL allow engineers to encapsulate
functionality into functions, making code more maintainable and promoting code reuse.
8. Array and Dictionary Manipulation:
Arrays and dictionaries are advanced data structures in TCL that prove useful when dealing with complex
data organization and retrieval in VLSI.
9. Regular Expressions:
Regular expressions in TCL are indispensable for pattern matching and text processing. They are valuable in
parsing log files, generating reports, and extracting critical information.
Environment Setup
• To set up your environment for Tcl, you require two software applications available on your
computer:
Text Editor
Tcl Interpreter
Text Editor
• Used to type the program.
Ex: Windows Notepad, OS Edit command, Brief, Epsilon, EMACS, and vim or vi.
• Name and version of a text editor can vary on different operating systems.
• The files you create with your text editor are called source files and contain program source code.
• The source files for Tcl programs are named with the extension ".tcl".
Tcl Interpreter
• A small program that enables you to type Tcl commands and have them executed line by line.
• It stops execution of a tcl file, in case, it encounters an error unlike a compiler that executes fully.
Basic Syntax
• Basic syntax for a Tcl command
command arg1 arg2 …...
• White space to separate command name and its arguments
• Newline or semicolon to terminate a command
• # for a comment
• Tcl is case sensitive
Basic Syntax
Comments
• Comments are like helping text in your Tcl program and the interpreter ignores them.
• Comments can be written using a hash (#) sign in the beginning.
#!/usr/bin/tclsh
# my first program in Tcl
puts "Hello World!"
-> Hello World!
Basic Syntax
First Tcl Program
• All Tcl files will have an extension, i.e., .tcl. So, put the following source code in a test.tcl file.
#!/usr/bin/tclsh
puts "Hello, World!"
• Assuming, Tcl environment is setup correctly; let's run the program after switching to file's directory and then
execute the program using −
• $ tclsh test.tcl
-> Hello, World!
• In Tcl, we use new line or semicolon to terminate the previous line of code. But semicolon is not necessary, if
you are using newline for each command.
Basic Syntax
Comments
• Multiline or block comment is written using 'if' with condition '0'.
• #!/usr/bin/tclsh
• if 0 {
• my first program in Tcl program
• Its very simple
• }
puts "Hello World!"
-> Hello World!
• Inline comments use ;#.
• #!/usr/bin/tclsh
puts "Hello World!" ;# my first print in Tcl program
-> Hello World!
Basic Syntax
Identifiers
• A Tcl identifier is a name used to identify a variable, function, or any other user-defined item.
• An identifier starts with a letter A to Z or a to z or an underscore (_) followed by zero or more letters,
underscores, dollars ($), and digits (0 to 9).
• Tcl does not allow punctuation characters such as @, and % within identifiers.
• Tcl is a case sensitive language. Thus Manpower and manpower are two different identifiers in Tcl.
Basic Syntax
Whitespace in Tcl
• A line containing only whitespace, possibly with a comment, is known as a blank line, and a Tcl interpreter
totally ignores it.
• Whitespace is the term used in Tcl to describe blanks, tabs, newline characters, and comments.
• Whitespace separates one part of a statement from another and enables the interpreter to identify where one
element in a statement, such as puts, ends and the next element begins.
Basic Syntax
#!/usr/bin/tclsh
puts "Hello World!"
• There must be at least one whitespace character (usually a space) between “puts” and "Hello World!" for the
interpreter to be able to distinguish them.
#!/usr/bin/tclsh
puts [expr 3 + 2] ;# print sum of the 3 and 2
-> 5
• No whitespace characters are necessary between 3 and +, or between + and 2; although, you are free to include
some if you wish for the readability purpose.
TCL Commands
• Tcl is a Tool command language, commands are the most vital part of the language.
• Tcl commands are built in-to the language with each having its own predefined function.
•These commands form the reserved words of the language and cannot be used for other variable naming.
• The advantage with these TCL commands is that, you can define your own implementation for any of these
commands to replace the original built-in functionality.
• Each of the TCL commands validates the input and it reduces the work of the interpreter.
• TCL command is actually a list of words, with the first word representing the command to be executed. The
next words represent the arguments. In order to group the words into a single argument, we enclose multiple
words with "" or {}.
Syntax of Tcl command:
commandName {argument1 argument2 ... argumentN}
TCL Commands
Example of TCL command:
 Tcl command with one argument −
puts "Hello, world!"
-> Hello, world!
In the above code, ‘puts’ is the Tcl command and "Hello World" is the argument1.
We have used "" to group two words.
 Tcl command with two arguments −
puts stdout "Hello, world!"
-> Hello, world!
In the above code, ‘puts’ is the Tcl command, ‘stdout’ is argument1, and "Hello World" is argument2.
Here, stdout makes the program to print in the standard output device.
TCL Commands
Command Substitution
Square brackets are used to evaluate the scripts inside the square brackets.
puts [expr 1 + 6 + 9]
-> 16
Variable Substitution
$ is used before the variable name and this returns the contents of the variable.
set a 3
puts $a
-> 3
Backslash Substitution
Commonly called escape sequences; with each backslash, followed by a letter having its own meaning.
puts "HellonWorld"
-> Hello
World
Some other backslash substitution commands are n, t, b etc.
TCL Data Types
• The primitive data-type of Tcl is string and often we can find quotes on Tcl as string only
language.
• These primitive data-types in turn create composite data-types for list and associative
array.
• In Tcl, data-types can represent not only the simple Tcl objects, but also can represent
complex objects such as handles, graphic objects and I/O channels.
TCL Data Types
Simple Tcl Objects
• In Tcl, whether it is an integer number, boolean, floating point number, or a string, when you want to use a
variable, you can directly assign a value to it, there is no step of declaration in Tcl.
• There can be internal representations for these different types of objects. It can transform one data-type to
another when required.
• set myVariable 18
puts $myVariable
-> 18
• If we try to make an arithmetic on the variable, it is automatically turned to an integer.
• set myVariable 18
puts [expr $myVariable + 6 + 9]
-> 33
TCL Data Types
String Representations
• Unlike other languages, in Tcl, you need not include double quotes when it's only a single word.
• set myVariable hello
puts $myVariable
-> hello
• When we want to represent multiple strings, we can use either double quotes or curly braces.
• set myVariable "hello world"
• puts $myVariable
• set myVariable {hello world}
puts $myVariable
-> hello world
hello world
TCL Data Types
List
• List is nothing but a group of elements.
• A group of words either using double quotes or curly braces can be used to represent a simple list.
• set myVariable {red green blue}
• puts [lindex $myVariable 2]
• set myVariable "red green blue"
puts [lindex $myVariable 1]
-> blue
green
TCL Data Types
Associative Arrays
• Associative arrays have an index (key) that is not necessarily an integer.
• It is generally a string that acts like key value pairs.
• set marks(english) 80
• puts $marks(english)
• set marks(mathematics) 90
puts $marks(mathematics)
-> 80
90
TCL Data Types
Handles
• Tcl handles are commonly used to represent files and graphics objects.
• These can include handles to network requests and also other channels like serial port communication, sockets,
or I/O devices.
-> set myfile [open "filename" r]
• In Tcl, there is no concept of variable declaration. Once, a new variable name is encountered, Tcl will define
a new variable.
Variable Naming
• The name of variables can contain any characters and length. You can even have white spaces by enclosing
the variable in curly braces, but it is not preferred.
• The set command is used for assigning value to a variable.
Syntax
set variableName value
set variableA 10
set {variable B} test
puts $variableA
puts ${variable B}
-> 10
test
TCL Variables
Dynamic Typing
•Tcl is a dynamically typed language.
•The value of the variable can be dynamically converted to the required type when required.
• set variableA "10"
• puts $variableA
• set sum [expr $variableA +20];
puts $sum
-> 10
30
TCL Variables
Mathematical Expressions
• The default precision of Tcl is 12 digits. In order to get floating point results, we should add at least a single
decimal digit.
• set variableA "10"
• set result [expr $variableA / 9];
• puts $result
• set result [expr $variableA / 9.0];
• puts $result
• set variableA "10.0"
• set result [expr $variableA / 9];
puts $result
->1
1.1111111111111112
TCL Variables
• An operator is a symbol that tells the compiler to perform specific mathematical or logical
manipulations.
• Tcl language is rich in built-in operators and provides the following types of operators −
1. Arithmetic Operators
2. Relational Operators
3. Logical Operators
4. Bitwise Operators
5. Ternary Operator
TCL Operators
Arithmetic Operators
Following table shows all the arithmetic operators supported by Tcl language. Assume variable ‘A’ holds 10 and
variable ‘B’ holds 20, then −
TCL Operators
Operator Description Example
+ Add two operands A + B will give 30
- Subtracts second operand from
the first
A – B will give -10
* Multiplies both operands A * B will give 200
/ Divides numerator by
denominator
B / A will give 2
% Modulus operator and remainder
of after an integer division
B % A will give 0
Relational Operators
Following table shows all the relational operators supported by TCL language. Assume variable ‘A’ holds 10 and
variable ‘B’ holds 20, then −
TCL Operators
Operator Description Example
== Checks if the values of two operands are equal or not,
if yes then condition becomes true.
(A == B) is not true.
!= Checks if the values of two operands are equal or not,
if values are not equal then condition becomes true.
(A != B) is true.
> Checks if the value of left operand is greater than the
value of right operand, if yes then condition becomes
true.
(A > B) is not true.
< Checks if the value of left operand is less than the
value of right operand, if yes then condition becomes
true.
(A < B) is true.
>= Checks if the value of left operand is greater than or
equal to the value of right operand, if yes then
condition becomes true.
(A >= B) is not true.
<= Checks if the value of left operand is less than or
equal to the value of right operand, if yes then
condition becomes true.
(A <= B) is true.
Logical Operators
Following table shows all the relational operators supported by TCL language. Assume variable ‘A’ holds 1 and
variable ‘B’ holds 0, then −
TCL Operators
Operator Description Example
&& Called Logical AND operator. If both
the operands are non-zero, then
condition becomes true.
(A && B) is false.
|| Called Logical OR Operator. If any of
the two operands is non-zero, then
condition becomes true.
(A || B) is true.
! Called Logical NOT Operator. Use to
reverses the logical state of its
operand. If a condition is true then
Logical NOT operator will make
false.
!(A && B) is true.
Bitwise Operators
Bitwise operator works on bits and perform bit-by-bit operation. The truth tables for &, |, and ^ are as follows −
TCL Operators
p q p & q p | q p ^ q
0 0 0 0 0
0 1 0 1 1
1 1 1 1 0
1 0 0 1 1
Assume if A = 60; and B = 13; now in binary format they will be as follows −
A = 0011 1100
B = 0000 1101
----------------------
A&B = 0000 1100
A|B = 0011 1101
A^B = 0011 0001
The Bitwise operators supported by Tcl language are listed in the following table. Assume variable A holds 60 and variable B holds 13, then −
TCL Operators
Operator Description Example
& Binary AND Operator copies a bit to the result if it exists
in both operands.
(A & B) will give 12, which is 0000 1100
| Binary OR Operator copies a bit if it exists in either
operand.
(A | B) will give 61, which is 0011 1101
^ Binary XOR Operator copies the bit if it is set in one
operand but not both.
(A ^ B) will give 49, which is 0011 0001
<< Binary Left Shift Operator. The left operands value is
moved left by the number of bits specified by the right
operand.
A << 2 will give 240, which is 1111 0000
>> Binary Right Shift Operator. The left operands value is
moved right by the number of bits specified by the right
operand.
A >> 2 will give 15, which is 0000 1111
Ternary Operator
TCL Operators
Operator Description Example
?: Ternary If Condition is true? Then
value X : Otherwise value Y
Following table shows all the relational operators supported by TCL language. Assume variable ‘A’ holds 10 and
variable ‘B’ holds 20, then −
TCL Operators
Operator Description Example
== Checks if the values of two operands are equal or not,
if yes then condition becomes true.
(A == B) is not true.
!= Checks if the values of two operands are equal or not,
if values are not equal then condition becomes true.
(A != B) is true.
> Checks if the value of left operand is greater than the
value of right operand, if yes then condition becomes
true.
(A > B) is not true.
< Checks if the value of left operand is less than the
value of right operand, if yes then condition becomes
true.
(A < B) is true.
>= Checks if the value of left operand is greater than or
equal to the value of right operand, if yes then
condition becomes true.
(A >= B) is not true.
<= Checks if the value of left operand is less than or
equal to the value of right operand, if yes then
condition becomes true.
(A <= B) is true.
Following table shows all the relational operators supported by TCL language. Assume variable ‘A’ holds 10 and
variable ‘B’ holds 20, then −
TCL Operators
Operator Description Example
== Checks if the values of two operands are equal or not,
if yes then condition becomes true.
(A == B) is not true.
!= Checks if the values of two operands are equal or not,
if values are not equal then condition becomes true.
(A != B) is true.
> Checks if the value of left operand is greater than the
value of right operand, if yes then condition becomes
true.
(A > B) is not true.
< Checks if the value of left operand is less than the
value of right operand, if yes then condition becomes
true.
(A < B) is true.
>= Checks if the value of left operand is greater than or
equal to the value of right operand, if yes then
condition becomes true.
(A >= B) is not true.
<= Checks if the value of left operand is less than or
equal to the value of right operand, if yes then
condition becomes true.
(A <= B) is true.
Operators Precedence in TCL
• Operator precedence determines the grouping of terms in an expression.
• This affects how an expression is evaluated.
• Certain operators have higher precedence than others.
• Here, operators with the highest precedence appear at the top of the table, those with the lowest appear at the
bottom.
• Within an expression, higher precedence operators will be evaluated first.
TCL Operators
Operators Precedence in TCL
TCL Operators
Category Operator Associativity
Unary + - Right to Left
Multiplicative * / % Left to Right
Additive + - Left to Right
Shift << >> Left to Right
Relational < <= > >= Left to Right
Bitwise AND & Left to Right
Bitwise XOR ^ Left to Right
Bitwise OR | Left to Right
Logical AND && Left to Right
Logical OR || Left to Right
Ternary ?: Right to Left
• A loop statement allows us to execute a statement or group of statements multiple times.
• Tcl language provides the following types of loops to handle looping requirements:
TCL LOOPS
Loop Type Description
While loop Repeats a statement or group of statements while a
given condition is true. It tests the condition before
executing the loop body.
For loop Executes a sequence of statements multiple times and
abbreviates the code that manages the loop variable.
Nested loops Uses one or more loop inside any another while, for or
do..while loop.
WHILE LOOP
•A while loop statement in Tcl language repeatedly executes a target statement as long as a given condition is
true.
Syntax
while {condition} {
statement(s)
}
Here, statement(s) may be a single statement or a block of statements. The condition may be any expression,
and true is any nonzero value. The loop iterates while the condition is true.
When the condition becomes false, program control passes to the line immediately following the loop.
TCL LOOPS
WHILE LOOP
set a 10
#while loop execution
while { $a < 20 } {
puts "value of a: $a"
incr a
}
Output: value of a: 10
value of a: 11
value of a: 12
value of a: 13
value of a: 14
value of a: 15
TCL LOOPS
FOR LOOP
•A for loop is a repetition control structure that allows you to efficiently write a code that needs to be executed for a specific
number of times.
Syntax
for {initialization} {condition} {increment} {
statement(s);
}
Flow of control in a for loop −
The initialization step is executed first, and only once. This step allows you to declare and initialize any loop control
variables. You are not required to put a statement here, as long as a semicolon appears.
Next, the condition is evaluated. If it is true, the body of the loop is executed. If it is false, the body of the loop does not
execute and flow of control jumps to the next statement just after the for loop.
After the body of the for loop executes, the flow of control jumps back up to the increment statement. This statement allows
you to update any loop control variables. This statement can be left blank, as long as a semicolon appears after the condition.
The condition is now evaluated again. If it is true, the loop executes and the process repeats itself (body of loop, then
TCL LOOPS
FOR LOOP
# for loop execution
for { set a 10} {$a < 20} {incr a} {
puts "value of a: $a"
}
Output
value of a: 10
value of a: 11
value of a: 12
value of a: 13
value of a: 14
value of a: 15
value of a: 16
TCL LOOPS
NESTED LOOP
Tcl allows to use one loop inside another loop.
Syntax
The syntax for a nested for loop statement in Tcl −
for {initialization} {condition} {increment} {
for {initialization} {condition} {increment} {
statement(s);
}
statement(s);
}
The syntax for a nested while loop statement in Tcl language is as follows −
while {condition} {
while {condition} {
statement(s);
}
TCL LOOPS
NESTED LOOP
A nested for loop to find the prime numbers from 2 to 100 −
set j 0;
for {set i 2} {$i<100} {incr i} {
for {set j 2} {$j <= [expr $i/$j] } {incr j} {
if { [expr $i%$j] == 0 } {
break
}
}
if {$j >[expr $i/$j] } {
puts "$i is prime"
}
}
TCL LOOPS
Infinite Loop
• A loop becomes infinite loop if a condition never becomes false.
• The while loop is traditionally used for this purpose.
• By leaving the conditional expression as 1, an endless loop can be made.
while {1} {
puts "This loop will run forever."
}
• When the conditional expression is absent, it is assumed to be true.
• Tcl programmers more commonly use the while {1} construct to signify an infinite loop.
NOTE − You can terminate an infinite loop by pressing Ctrl + C keys.
TCL LOOPS
Loop Control Statements
• Loop control statements change execution from its normal sequence.
• When execution leaves a scope, all automatic objects that were created in that scope are destroyed.
TCL LOOPS
Control Statement Description
Break statement Terminates the loop or switch statement and transfers
execution to the statement immediately following the
loop or switch.
Continue statement Causes the loop to skip the remainder of its body and
immediately retest its condition prior to reiterating.
BREAK STATEMENT
The break statement in Tcl language is used for terminating a loop. When the break statement is encountered inside a loop,
the loop is immediately terminated and program control resumes at the next statement following the loop.
If you are using nested loops (i.e., one loop inside another loop), the break statement will stop the execution of the innermost
loop and start executing the next line of code after the block.
Syntax
break;
TCL LOOPS
BREAK STATEMENT
set a 10
# while loop execution
while {$a < 20 } {
puts "value of a: $a"
incr a
if { $a > 15} {
# terminate the loop using break statement
break
}
}
OUTPUT
value of a: 10
value of a: 11
TCL LOOPS
CONTINUE STATEMENT
The continue statement in Tcl language works somewhat like the break statement. Instead of forcing
termination, however, continue forces the next iteration of the loop to take place, skipping any code in between.
For the for loop, continue statement causes the conditional test and increment portions of the loop to execute.
For the while loop, continue statement passes the program control to the conditional tests.
Syntax
continue;
TCL LOOPS
CONTINUE STATEMENT
set a 10
# do loop execution
while { $a < 20 } {
if { $a == 15} {
#skip the iteration
incr a
continue
}
puts "value of a: $a"
incr a
}
OUTPUT
value of a: 10
value of a: 11
value of a: 12
TCL LOOPS
•The primitive data-type of Tcl is string and often we can find quotes on Tcl as string only language.
•These strings can contain alphanumeric character, just numbers, Boolean, or even binary data.
•Tcl uses 16 bit unicode characters and alphanumeric characters can contain letters including non-Latin
characters, number or punctuation.
•Boolean value can be represented as 1, yes or true for true and 0, no, or false for false.
STRINGS
1. string length: In Tcl, you can find the length of a string using the string length command.
Example:
set my_string "Hello, world!"
set length [string length $my_string]
puts "Length of the string: $length"
2. string reverse: In Tcl, you can reverse a string using the string reverse command.
Example:
set my_string "Hello, world!"
set length [string reverse $my_string]
puts "Length of the string: $length"
STRING COMMAND
3.string compare:
In Tcl, you can compare two strings using the string compare command. The string compare command
compares two strings lexicographically and returns an integer value indicating their relationship.
Example:
set string1 "apple"
set string2 "banana"
# Compare the strings
set result[string compare $string1 $string2]
if {$result == 0} {
puts "The strings are equal."
} elseif {result < 0} {
puts "String 1 comes before String 2."
} else {
puts "String 1 comes after String 2."
STRING COMMAND
4.string index:
In Tcl, you can extract a single character from a string at a specified index using the string index command.
Example:
set my_string "Hello, world!"
# Get the character at index 1 (Tcl uses 0-based indexing)
set character [string index $my_string 0]
puts "Character at index 0: $character"
STRING COMMAND
5.string range:
In Tcl, you can extract a substring from a string using the string range command. This command allows you
to specify a range of characters to extract from the original string.
Example:
# Example string
set my_string "Hello, world!"
# Extract a substring from index 1 to 5
set substring [string range $my_string 1 5]
# Print the substring
puts "Substring from index 1 to 5: $substring"
STRING COMMAND
6.string tolower:
In Tcl, the string tolower command is used to convert all characters in a string to lowercase.
Example:
# Example string
set my_string "Hello, WORLD!"
# Convert the string to lowercase
set lc_string [string tolower $my_string]
# Print the lowercase string
puts "Lowercase string: $lc_string"
STRING COMMAND
7.string toupper:
In Tcl, the string toupper command is used to convert all characters in a string to uppercase.
Example:
# Example string
set my_string "Hello, world!"
# Convert the string to uppercase
set uppercase_string [string toupper $my_string]
# Print the uppercase string
puts "Uppercase string: $uppercase_string"
STRING COMMAND
8.string trim:
In Tcl, the string trim command is used to remove whitespace characters (spaces, tabs, and newlines) from
the beginning and end of a string.
Example:
set my_string " Hello, world! "
# Trim the whitespace from the string
set trimmed_string [string trim $my_string]
# Print the trimmed string
puts "Trimmed string: "$trimmed_string""
STRING COMMAND
9. string trimleft
Trim the left side of the begining of the string.
set a " this is tcl class"
set b [string trimleft $a]
puts $a
puts $b
set a " this is tcl class"
set b [string trimleft $a " "]
puts $a
puts $b
set a "this is tcl class"
set b "this"
set c [string trimleft $a $b]
puts $a
STRING COMMAND
10. string trim right
# trims the right side of the begining of the string.
set a "this is tcl class"
set b "class"
set c [string trimright $a $b]
puts $a
puts $c
11.string first
In Tcl, the string first command is used to find the index of the first occurrence of a substring within a
string.
set my_string "Hello, world!"
set index [string first "world" $my_string]
puts "Index of 'world': $index"
STRING COMMAND
12.string last:
In Tcl, the string last command is used to find the index of the last occurrence of a substring within a string.
Example:
# Example string
set my_string "this is a tcl class tcl class tcl"
# Find the index of the last occurrence of "tcl" in the string
set index [string last "tcl" $my_string]
# Print the index
puts "Index of last 'tcl': $index"
STRING COMMAND
13.string concat:
In Tcl, the string concat command concatenates multiple strings together into a single string. It's
particularly useful when you want to join several strings into one.
Example:
set string1 "Hello"
set string2 ", "
set string3 "world!"
set concatenated_string [concat $string1 $string2 $string3]
puts "Concatenated string: $concatenated_string"
STRING COMMAND
14.string equal:
In Tcl, the string equal command is used to compare two strings to see if they are equal. It returns a
boolean value indicating whether the two strings are equal.
Example:
set string1 "Hello"
set string2 "Hello"
if {[string equal $string1 $string2]} {
puts "The strings are equal"
} else {
puts "The strings are not equal"
}
STRING COMMAND
15.string match:
In Tcl, the string match command is used to perform pattern matching on strings. It compares a string
against a pattern and returns a boolean value indicating whether the string matches the pattern. The
pattern can contain special characters to represent wildcards and character ranges.
Example:
set my_string "hello"
set pattern "he*o"
if {[string match $pattern $my_string]} {
puts "The string matches the pattern"
} else {
puts "The string does not match the pattern"
}
STRING COMMAND
16.string map:
In Tcl, the string map command is used to perform multiple string substitutions within a string based on a
mapping of key-value pairs. It replaces all occurrences of the keys in the string with their corresponding
values.
Example:
set original_string "The quick brown fox jumps over the lazy dog."
set substitution_map {
quick fast
brown red
fox cat
dog rabbit
}
set modified_string [string map $substitution_map $original_string]
puts $modified_string
STRING COMMAND
17. string replace:
In Tcl, the string replace command is used to replace a portion of a string with another string. It allows you
to specify the start index and the number of characters to replace.
Example:
set a "This is TCL class"
puts $a
set b [string replace $a 12 16 "session"]
puts $b
STRING COMMAND
18.string repeat:
In Tcl, the string repeat command is used to create a new string by repeating another string a specified
number of times.
Example:
set repeated_string [string repeat "abc" 3]
puts $repeated_string
STRING COMMAND
19.string format:
In Tcl, the string format command is used to create a formatted string based on a format string and a list of
values.
Example:
set name "Vikram"
set age 30
set country India
set formatted_string [format "Name: %s, Age: %d ,Country:%s" $name $age $country]
puts $formatted_string
STRING COMMAND
• It is used to match the pattern in the text.
• In TCL, regular expression is pattern that describes a set of strings, extract the information, and perfrom
complex text processing tasks.
• regexp command is supporting to match the pattern.
• This command allows to perform various operations such as pattern matching, substitution and splitting on
the strings using regular expression.
Syntax: [regexp "search_pattern $content]
REGULAR EXPRESSION IN TCL
Example:
1) set a "hello world"
if {[regexp "hello" $a]} {
puts "pattern matches"
} else {
puts "pattern not matches"
}
2) set a "HELLO world"
if {[regexp -nocase "hello" $a]} {
puts "pattern matches"
} else {
puts "pattern not matches"
}
REGULAR EXPRESSION IN TCL
List of all the metacharacters, quantifiers and special sequences that can be used in regular expression in TCL:
Meta characters
---------------
.(dot)-->matches any single character except newline.
set string "abcd"
set b [regexp "^a..d$" $string]
puts $b
#output is b=1
REGULAR EXPRESSION IN TCL
set string "I have dog"
if {[regexp "h.e" $string]} {
puts "Match found"
} else {
puts "No Match found"
}
#output is No Match found
|(pipe)-->matches either the pattern on its left or the pattern on its right
set string "I have a dog"
set b [regexp "cat|dog" $string]
puts $b
REGULAR EXPRESSION IN TCL
[...](bracket expression)-->matches any single charcter from the specified set of characters
[^...](negated bracket expression)-->matches any single character not in the specified set of characters
()grouping --> groups multiple pattern together.
(escape)-->escapes a meta character,allowing it to be matched as aliteral character.
{...}(curly braces)-->matches the enclosed pattern exactly.
example:[a-z]{3}
REGULAR EXPRESSION IN TCL
Quantifiers
-----------
*(asterisk)-->matches zero or more occurrances of the preceding character or subexpression.
1) set string "The quick brown fox jump over the lazy dog"
if {[regexp "o*" $string} {
puts "match found"
} else {
puts "no match found"
}
2) set string "The quick brown fox jump over the lazy dog"
set b [regexp "o*" $string]
puts $b
REGULAR EXPRESSION IN TCL
+(plus)-->matches one or more occurances of the preceding character or subexpression
1) set string "The quick brown fox jump over the lazy dog"
set b [regexp "o+" $string]
puts $b
2) set string "The quick brown fox jump over the lazy dog"
if {[regexp "o+" $string]} {
puts "match found"
} else {
puts "no match found"
}
REGULAR EXPRESSION IN TCL
?(question mark)-->matches zero or one occurances of the preceding character or subexpression.
1) set string "The quick brown fox jump over the lazy dog"
set b [regexp "ou?" $string]
puts $b
2) set string "The quick brown fox jump over the lazy dog"
if {[regexp "ou?" $string]} {
puts "match found"
} else {
puts "no match found"
}
REGULAR EXPRESSION IN TCL
{n}(exact quantifiers)-->matches exactly "n" occurances of the preceding characters or sub
expressions
{n,}(minimum quantifier)-->matches at least n occurance of the preceding character or sub
expressions
Example 1:
1) set a {the mentor for funtional_verification2023 is : mohan_kumar_ns}
set b [regexp -nocase {the mentor for [a-z0-9_]+ is : [a-z]+} $a]
puts $b
2) set a {the mentor for physicaldesign_2023 is : chethan_kumar_ns}
set b [regexp -nocase {the mentor for ([a-z0-9_]+) is * :* ([a-z_]+)} $a match1 match2 match3]
puts $b
puts "this will print the whole expression :$match1"
puts "this will print the course_name:$match2"
puts "this will print the mentor_name:$match3"
REGULAR EXPRESSION IN TCL
Example2:
set a {sram :-2500}
set b [regexp -nocase {([a-z]+) :([-0-9]+)} $a m1 m2 m3]
puts $b
puts "the cell_name is:$m2"
puts " the cell_value is:$m3"
Example3:
lassign $argv
set file [open "text1.txt" r]
while {[gets $file line]>=0} {
if {$argv==[lindex $line 0]} {
set b [regexp -nocase {([a-z]+) :([-0-9]+)} $line match match2 match3]
}
}
puts "the value of $argv is : $match3"
REGULAR EXPRESSION IN TCL
x --> Exact match
[a-z] --> any lowercase from a to z.
[A-Z] --> any uppercase from A to Z.
. --> any character
^ --> Begining string should match
$ --> Ending string should match
() --> Add the sequence inside parenthesis to make a RE.
x* --> should match 0 or more occurences of the preceding x
x+ --> should match 1 or more ocuurences of the preceding x
^ --> backlash sequnece to match special charater.
[a-z]* --> should match 0 or more occurence of the preceding x
{digit} --> matchs exactly digit ocuurences.
digit occurrences 0 to 9.
REGULAR EXPRESSION IN TCL
example:4
1.read the VHDL.txt file
2. go through line by line.
3. write the regular expression to capture
all the entity names.
4.
5. write all the entity names into new file(VHDL_enitity.txt)
set fh_read [open "VHDL.txt" r]
set fh_write [open "VHDL_entity.txt" w]
set i 0
while {[gets $fh_read line] >= 0} {
incr i
if {[regexp -nocase { *entity +([a-z_]+) +is} $line match match1]} {
puts "the line number of the enity is:$i and entity name is:$match1"
puts $fh_write "the line number of the enity is:$i and entity name is:$match1"
}
}
REGULAR EXPRESSION IN TCL

More Related Content

PPT
Verilog Tasks and functions
ODP
Inputs of physical design
PDF
Overview of digital design with Verilog HDL
PPTX
Benifits of power factor improvement for industry
PPTX
VERILOG HDL :: Blocking & NON- Blocking assignments
PPTX
Verilog presentation final
PPT
NIOS II Processor.ppt
PDF
Hardware Trojan Attacks on Neural Networks - Joseph Clements - DEF CON 26 CAA...
Verilog Tasks and functions
Inputs of physical design
Overview of digital design with Verilog HDL
Benifits of power factor improvement for industry
VERILOG HDL :: Blocking & NON- Blocking assignments
Verilog presentation final
NIOS II Processor.ppt
Hardware Trojan Attacks on Neural Networks - Joseph Clements - DEF CON 26 CAA...

What's hot (7)

PDF
Day2 Verilog HDL Basic
PPTX
Verilog HDL
PDF
UPF-Based Static Low-Power Verification in Complex Power Structure SoC Design...
PDF
Low Power Clock Distribution Schemes in VLSI Design
PDF
Functions and tasks in verilog
PDF
VLSI Design Final Project - 32 bit ALU
PDF
2011 DDR4 Mini Workshop.pdf
Day2 Verilog HDL Basic
Verilog HDL
UPF-Based Static Low-Power Verification in Complex Power Structure SoC Design...
Low Power Clock Distribution Schemes in VLSI Design
Functions and tasks in verilog
VLSI Design Final Project - 32 bit ALU
2011 DDR4 Mini Workshop.pdf
Ad

Similar to tcl language ppt to learn the tcl go through it (20)

PPTX
PYTHON INTERNSHIP PPT download free.pptx
PPTX
CSharp for Unity - Day 1
PDF
Introduction to OpenSees by Frank McKenna
PPTX
1 August part 1basic SQL Lab PPT FORMAT.pptx
PDF
C som-programmeringssprog-bt
PPT
358 33 powerpoint-slides_1-introduction-c_chapter-1
PPT
8844632.ppt
PDF
IN4308 1
PPTX
Common language runtime clr
PPT
Lecture 01 2017
PPTX
PPTX
Introduction Of C++
PDF
Programing paradigm &amp; implementation
PPTX
UNIT 5 C PROGRAMMING, PROGRAM STRUCTURE
PDF
Programming Languages #devcon2013
PDF
the tcl introduction commands for beginners
PPTX
Xml data transformation
PPTX
Desired language characteristics – Data typing .pptx
PPTX
CS4443 - Modern Programming Language - I Lecture (1)
PYTHON INTERNSHIP PPT download free.pptx
CSharp for Unity - Day 1
Introduction to OpenSees by Frank McKenna
1 August part 1basic SQL Lab PPT FORMAT.pptx
C som-programmeringssprog-bt
358 33 powerpoint-slides_1-introduction-c_chapter-1
8844632.ppt
IN4308 1
Common language runtime clr
Lecture 01 2017
Introduction Of C++
Programing paradigm &amp; implementation
UNIT 5 C PROGRAMMING, PROGRAM STRUCTURE
Programming Languages #devcon2013
the tcl introduction commands for beginners
Xml data transformation
Desired language characteristics – Data typing .pptx
CS4443 - Modern Programming Language - I Lecture (1)
Ad

Recently uploaded (20)

PDF
Building Integrated photovoltaic BIPV_UPV.pdf
PDF
Accuracy of neural networks in brain wave diagnosis of schizophrenia
PPT
Teaching material agriculture food technology
PDF
Machine learning based COVID-19 study performance prediction
PDF
gpt5_lecture_notes_comprehensive_20250812015547.pdf
PPTX
Group 1 Presentation -Planning and Decision Making .pptx
PDF
Electronic commerce courselecture one. Pdf
PPT
“AI and Expert System Decision Support & Business Intelligence Systems”
PDF
Empathic Computing: Creating Shared Understanding
PDF
Dropbox Q2 2025 Financial Results & Investor Presentation
PDF
Build a system with the filesystem maintained by OSTree @ COSCUP 2025
PDF
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf
PDF
Spectral efficient network and resource selection model in 5G networks
PDF
Agricultural_Statistics_at_a_Glance_2022_0.pdf
PDF
Blue Purple Modern Animated Computer Science Presentation.pdf.pdf
PDF
Encapsulation theory and applications.pdf
PPTX
Big Data Technologies - Introduction.pptx
PPTX
Machine Learning_overview_presentation.pptx
PDF
The Rise and Fall of 3GPP – Time for a Sabbatical?
PPTX
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx
Building Integrated photovoltaic BIPV_UPV.pdf
Accuracy of neural networks in brain wave diagnosis of schizophrenia
Teaching material agriculture food technology
Machine learning based COVID-19 study performance prediction
gpt5_lecture_notes_comprehensive_20250812015547.pdf
Group 1 Presentation -Planning and Decision Making .pptx
Electronic commerce courselecture one. Pdf
“AI and Expert System Decision Support & Business Intelligence Systems”
Empathic Computing: Creating Shared Understanding
Dropbox Q2 2025 Financial Results & Investor Presentation
Build a system with the filesystem maintained by OSTree @ COSCUP 2025
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf
Spectral efficient network and resource selection model in 5G networks
Agricultural_Statistics_at_a_Glance_2022_0.pdf
Blue Purple Modern Animated Computer Science Presentation.pdf.pdf
Encapsulation theory and applications.pdf
Big Data Technologies - Introduction.pptx
Machine Learning_overview_presentation.pptx
The Rise and Fall of 3GPP – Time for a Sabbatical?
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx

tcl language ppt to learn the tcl go through it

  • 3. Which language Computer understand ? Machine language consists of binary numbers (0s and 1s), while humans understand high- level languages, such as English. Then how will Humans communicate with the computer ? We use compilers and interpreters to facilitate communication between humans and computers.
  • 5. Difference between Compiler and Interpreter
  • 6. What is TCL? •TCL stands for Tool Command Language. • It was designed by John Ousterhout of the University of California, Berkeley in 1988. •It's an opensource multi-purpose interpreted powerful dynamic scripting language. •It aims at providing ability for the programs to interact with other programs. •TCL is fit for both the smallest and largest programming task. •Tcl was developed initially for Unix. It was then ported to Windows, DOS, OS/2, and Mac OSX. •Tcl is much similar to other unix shell languages like Bourne Shell (Sh), the C Shell (csh), the Korn Shell (sh), and Perl. •Widely used in various domains in VLSI Design and Verification.
  • 7. TCL in VLSI • Front – End Synthesis Tool • Back-End Placement and Route Tool (PnR) • Static Timing Analysis Tool (STA) • Reliability Analysis Tool (EM-IR) • Scripted Waveform Verification in Analog • Design for Testability Tool (DFT)
  • 8. Why Should we learn TCL for VLSI Design • Efficiency: TCL automation dramatically reduces manual effort, accelerating design processes. • Accuracy: By automating repetitive tasks, TCL minimizes the risk of human errors, leading to more reliable designs. • Flexibility: TCL's versatility adapts to the evolving requirements of VLSI projects, allowing us to quickly adjust to changing design needs. • Competitive Edge: TCL proficiency is a vital skill in the VLSI industry, giving you a competitive advantage in job markets.
  • 9. Why TCL? • TCL is not just another programming language; It forms the backbone of VLSI design automation specifically for Physical Design Engineers. It empowers engineers to automate complex and repetitive tasks, improving efficiency, accuracy, and productivity in semiconductor design. • In many EDA [Electronics Design Automation] tools we will use TCL for scripting. • Simplest syntax • Cross-platform availability • Data structure: TCL provides built in data structures such as lists, dictionaries and arrays. • Control Structures: Use built-in control structures such as if, for, foreach, while, switch etc • Provides facility for creating GUIs • Provides enough programmability for complex scripts • Rapid development • Open source – Anyone may, without charge, download and inspect the source code to Tcl.
  • 10. Some key concepts and their importance in VLSI 1. Understanding TCL Variables: Variables in TCL are essential for storing data, enabling us to manipulate values, strings, and numbers effortlessly. They are the building blocks of TCL scripts, allowing us to work with data effectively. 2. Mathematical and Boolean Operations: TCL offers a strong set of mathematical and Boolean operators. These operations are invaluable when dealing with calculations, comparisons, and logic in VLSI Physical Design. 3. List Management and Manipulation: Lists are versatile data structures in TCL, and they find applications in various aspects of VLSI, from managing design constraints to handling simulation scenarios. TCL's list manipulation capabilities are essential for data organization and analysis.
  • 11. 4. File Handling and Manipulation: Design Engineers have to work with numerous design files in the VLSI. TCL excels in file manipulation tasks, making it effortless to read, write, and process files, facilitating data exchange with EDA tools. 5. Variable Manipulation: TCL's variable manipulation features allow engineers to efficiently modify and adapt data to meet specific design requirements. This is invaluable when working with design constraints, parameters, and configurations. 6. Control Statements: TCL provides a range of control statements like loops and conditional statements. These enable engineers to create flexible and adaptive scripts, which are critical for automating complex VLSI workflows.
  • 12. 7. Procedures: In VLSI, scripts must often be modular and reusable. Procedures in TCL allow engineers to encapsulate functionality into functions, making code more maintainable and promoting code reuse. 8. Array and Dictionary Manipulation: Arrays and dictionaries are advanced data structures in TCL that prove useful when dealing with complex data organization and retrieval in VLSI. 9. Regular Expressions: Regular expressions in TCL are indispensable for pattern matching and text processing. They are valuable in parsing log files, generating reports, and extracting critical information.
  • 13. Environment Setup • To set up your environment for Tcl, you require two software applications available on your computer: Text Editor Tcl Interpreter Text Editor • Used to type the program. Ex: Windows Notepad, OS Edit command, Brief, Epsilon, EMACS, and vim or vi. • Name and version of a text editor can vary on different operating systems. • The files you create with your text editor are called source files and contain program source code. • The source files for Tcl programs are named with the extension ".tcl". Tcl Interpreter • A small program that enables you to type Tcl commands and have them executed line by line. • It stops execution of a tcl file, in case, it encounters an error unlike a compiler that executes fully.
  • 14. Basic Syntax • Basic syntax for a Tcl command command arg1 arg2 …... • White space to separate command name and its arguments • Newline or semicolon to terminate a command • # for a comment • Tcl is case sensitive
  • 15. Basic Syntax Comments • Comments are like helping text in your Tcl program and the interpreter ignores them. • Comments can be written using a hash (#) sign in the beginning. #!/usr/bin/tclsh # my first program in Tcl puts "Hello World!" -> Hello World!
  • 16. Basic Syntax First Tcl Program • All Tcl files will have an extension, i.e., .tcl. So, put the following source code in a test.tcl file. #!/usr/bin/tclsh puts "Hello, World!" • Assuming, Tcl environment is setup correctly; let's run the program after switching to file's directory and then execute the program using − • $ tclsh test.tcl -> Hello, World! • In Tcl, we use new line or semicolon to terminate the previous line of code. But semicolon is not necessary, if you are using newline for each command.
  • 17. Basic Syntax Comments • Multiline or block comment is written using 'if' with condition '0'. • #!/usr/bin/tclsh • if 0 { • my first program in Tcl program • Its very simple • } puts "Hello World!" -> Hello World! • Inline comments use ;#. • #!/usr/bin/tclsh puts "Hello World!" ;# my first print in Tcl program -> Hello World!
  • 18. Basic Syntax Identifiers • A Tcl identifier is a name used to identify a variable, function, or any other user-defined item. • An identifier starts with a letter A to Z or a to z or an underscore (_) followed by zero or more letters, underscores, dollars ($), and digits (0 to 9). • Tcl does not allow punctuation characters such as @, and % within identifiers. • Tcl is a case sensitive language. Thus Manpower and manpower are two different identifiers in Tcl.
  • 19. Basic Syntax Whitespace in Tcl • A line containing only whitespace, possibly with a comment, is known as a blank line, and a Tcl interpreter totally ignores it. • Whitespace is the term used in Tcl to describe blanks, tabs, newline characters, and comments. • Whitespace separates one part of a statement from another and enables the interpreter to identify where one element in a statement, such as puts, ends and the next element begins.
  • 20. Basic Syntax #!/usr/bin/tclsh puts "Hello World!" • There must be at least one whitespace character (usually a space) between “puts” and "Hello World!" for the interpreter to be able to distinguish them. #!/usr/bin/tclsh puts [expr 3 + 2] ;# print sum of the 3 and 2 -> 5 • No whitespace characters are necessary between 3 and +, or between + and 2; although, you are free to include some if you wish for the readability purpose.
  • 21. TCL Commands • Tcl is a Tool command language, commands are the most vital part of the language. • Tcl commands are built in-to the language with each having its own predefined function. •These commands form the reserved words of the language and cannot be used for other variable naming. • The advantage with these TCL commands is that, you can define your own implementation for any of these commands to replace the original built-in functionality. • Each of the TCL commands validates the input and it reduces the work of the interpreter. • TCL command is actually a list of words, with the first word representing the command to be executed. The next words represent the arguments. In order to group the words into a single argument, we enclose multiple words with "" or {}. Syntax of Tcl command: commandName {argument1 argument2 ... argumentN}
  • 22. TCL Commands Example of TCL command:  Tcl command with one argument − puts "Hello, world!" -> Hello, world! In the above code, ‘puts’ is the Tcl command and "Hello World" is the argument1. We have used "" to group two words.  Tcl command with two arguments − puts stdout "Hello, world!" -> Hello, world! In the above code, ‘puts’ is the Tcl command, ‘stdout’ is argument1, and "Hello World" is argument2. Here, stdout makes the program to print in the standard output device.
  • 23. TCL Commands Command Substitution Square brackets are used to evaluate the scripts inside the square brackets. puts [expr 1 + 6 + 9] -> 16 Variable Substitution $ is used before the variable name and this returns the contents of the variable. set a 3 puts $a -> 3 Backslash Substitution Commonly called escape sequences; with each backslash, followed by a letter having its own meaning. puts "HellonWorld" -> Hello World Some other backslash substitution commands are n, t, b etc.
  • 24. TCL Data Types • The primitive data-type of Tcl is string and often we can find quotes on Tcl as string only language. • These primitive data-types in turn create composite data-types for list and associative array. • In Tcl, data-types can represent not only the simple Tcl objects, but also can represent complex objects such as handles, graphic objects and I/O channels.
  • 25. TCL Data Types Simple Tcl Objects • In Tcl, whether it is an integer number, boolean, floating point number, or a string, when you want to use a variable, you can directly assign a value to it, there is no step of declaration in Tcl. • There can be internal representations for these different types of objects. It can transform one data-type to another when required. • set myVariable 18 puts $myVariable -> 18 • If we try to make an arithmetic on the variable, it is automatically turned to an integer. • set myVariable 18 puts [expr $myVariable + 6 + 9] -> 33
  • 26. TCL Data Types String Representations • Unlike other languages, in Tcl, you need not include double quotes when it's only a single word. • set myVariable hello puts $myVariable -> hello • When we want to represent multiple strings, we can use either double quotes or curly braces. • set myVariable "hello world" • puts $myVariable • set myVariable {hello world} puts $myVariable -> hello world hello world
  • 27. TCL Data Types List • List is nothing but a group of elements. • A group of words either using double quotes or curly braces can be used to represent a simple list. • set myVariable {red green blue} • puts [lindex $myVariable 2] • set myVariable "red green blue" puts [lindex $myVariable 1] -> blue green
  • 28. TCL Data Types Associative Arrays • Associative arrays have an index (key) that is not necessarily an integer. • It is generally a string that acts like key value pairs. • set marks(english) 80 • puts $marks(english) • set marks(mathematics) 90 puts $marks(mathematics) -> 80 90
  • 29. TCL Data Types Handles • Tcl handles are commonly used to represent files and graphics objects. • These can include handles to network requests and also other channels like serial port communication, sockets, or I/O devices. -> set myfile [open "filename" r]
  • 30. • In Tcl, there is no concept of variable declaration. Once, a new variable name is encountered, Tcl will define a new variable. Variable Naming • The name of variables can contain any characters and length. You can even have white spaces by enclosing the variable in curly braces, but it is not preferred. • The set command is used for assigning value to a variable. Syntax set variableName value set variableA 10 set {variable B} test puts $variableA puts ${variable B} -> 10 test TCL Variables
  • 31. Dynamic Typing •Tcl is a dynamically typed language. •The value of the variable can be dynamically converted to the required type when required. • set variableA "10" • puts $variableA • set sum [expr $variableA +20]; puts $sum -> 10 30 TCL Variables
  • 32. Mathematical Expressions • The default precision of Tcl is 12 digits. In order to get floating point results, we should add at least a single decimal digit. • set variableA "10" • set result [expr $variableA / 9]; • puts $result • set result [expr $variableA / 9.0]; • puts $result • set variableA "10.0" • set result [expr $variableA / 9]; puts $result ->1 1.1111111111111112 TCL Variables
  • 33. • An operator is a symbol that tells the compiler to perform specific mathematical or logical manipulations. • Tcl language is rich in built-in operators and provides the following types of operators − 1. Arithmetic Operators 2. Relational Operators 3. Logical Operators 4. Bitwise Operators 5. Ternary Operator TCL Operators
  • 34. Arithmetic Operators Following table shows all the arithmetic operators supported by Tcl language. Assume variable ‘A’ holds 10 and variable ‘B’ holds 20, then − TCL Operators Operator Description Example + Add two operands A + B will give 30 - Subtracts second operand from the first A – B will give -10 * Multiplies both operands A * B will give 200 / Divides numerator by denominator B / A will give 2 % Modulus operator and remainder of after an integer division B % A will give 0
  • 35. Relational Operators Following table shows all the relational operators supported by TCL language. Assume variable ‘A’ holds 10 and variable ‘B’ holds 20, then − TCL Operators Operator Description Example == Checks if the values of two operands are equal or not, if yes then condition becomes true. (A == B) is not true. != Checks if the values of two operands are equal or not, if values are not equal then condition becomes true. (A != B) is true. > Checks if the value of left operand is greater than the value of right operand, if yes then condition becomes true. (A > B) is not true. < Checks if the value of left operand is less than the value of right operand, if yes then condition becomes true. (A < B) is true. >= Checks if the value of left operand is greater than or equal to the value of right operand, if yes then condition becomes true. (A >= B) is not true. <= Checks if the value of left operand is less than or equal to the value of right operand, if yes then condition becomes true. (A <= B) is true.
  • 36. Logical Operators Following table shows all the relational operators supported by TCL language. Assume variable ‘A’ holds 1 and variable ‘B’ holds 0, then − TCL Operators Operator Description Example && Called Logical AND operator. If both the operands are non-zero, then condition becomes true. (A && B) is false. || Called Logical OR Operator. If any of the two operands is non-zero, then condition becomes true. (A || B) is true. ! Called Logical NOT Operator. Use to reverses the logical state of its operand. If a condition is true then Logical NOT operator will make false. !(A && B) is true.
  • 37. Bitwise Operators Bitwise operator works on bits and perform bit-by-bit operation. The truth tables for &, |, and ^ are as follows − TCL Operators p q p & q p | q p ^ q 0 0 0 0 0 0 1 0 1 1 1 1 1 1 0 1 0 0 1 1
  • 38. Assume if A = 60; and B = 13; now in binary format they will be as follows − A = 0011 1100 B = 0000 1101 ---------------------- A&B = 0000 1100 A|B = 0011 1101 A^B = 0011 0001 The Bitwise operators supported by Tcl language are listed in the following table. Assume variable A holds 60 and variable B holds 13, then − TCL Operators Operator Description Example & Binary AND Operator copies a bit to the result if it exists in both operands. (A & B) will give 12, which is 0000 1100 | Binary OR Operator copies a bit if it exists in either operand. (A | B) will give 61, which is 0011 1101 ^ Binary XOR Operator copies the bit if it is set in one operand but not both. (A ^ B) will give 49, which is 0011 0001 << Binary Left Shift Operator. The left operands value is moved left by the number of bits specified by the right operand. A << 2 will give 240, which is 1111 0000 >> Binary Right Shift Operator. The left operands value is moved right by the number of bits specified by the right operand. A >> 2 will give 15, which is 0000 1111
  • 39. Ternary Operator TCL Operators Operator Description Example ?: Ternary If Condition is true? Then value X : Otherwise value Y
  • 40. Following table shows all the relational operators supported by TCL language. Assume variable ‘A’ holds 10 and variable ‘B’ holds 20, then − TCL Operators Operator Description Example == Checks if the values of two operands are equal or not, if yes then condition becomes true. (A == B) is not true. != Checks if the values of two operands are equal or not, if values are not equal then condition becomes true. (A != B) is true. > Checks if the value of left operand is greater than the value of right operand, if yes then condition becomes true. (A > B) is not true. < Checks if the value of left operand is less than the value of right operand, if yes then condition becomes true. (A < B) is true. >= Checks if the value of left operand is greater than or equal to the value of right operand, if yes then condition becomes true. (A >= B) is not true. <= Checks if the value of left operand is less than or equal to the value of right operand, if yes then condition becomes true. (A <= B) is true.
  • 41. Following table shows all the relational operators supported by TCL language. Assume variable ‘A’ holds 10 and variable ‘B’ holds 20, then − TCL Operators Operator Description Example == Checks if the values of two operands are equal or not, if yes then condition becomes true. (A == B) is not true. != Checks if the values of two operands are equal or not, if values are not equal then condition becomes true. (A != B) is true. > Checks if the value of left operand is greater than the value of right operand, if yes then condition becomes true. (A > B) is not true. < Checks if the value of left operand is less than the value of right operand, if yes then condition becomes true. (A < B) is true. >= Checks if the value of left operand is greater than or equal to the value of right operand, if yes then condition becomes true. (A >= B) is not true. <= Checks if the value of left operand is less than or equal to the value of right operand, if yes then condition becomes true. (A <= B) is true.
  • 42. Operators Precedence in TCL • Operator precedence determines the grouping of terms in an expression. • This affects how an expression is evaluated. • Certain operators have higher precedence than others. • Here, operators with the highest precedence appear at the top of the table, those with the lowest appear at the bottom. • Within an expression, higher precedence operators will be evaluated first. TCL Operators
  • 43. Operators Precedence in TCL TCL Operators Category Operator Associativity Unary + - Right to Left Multiplicative * / % Left to Right Additive + - Left to Right Shift << >> Left to Right Relational < <= > >= Left to Right Bitwise AND & Left to Right Bitwise XOR ^ Left to Right Bitwise OR | Left to Right Logical AND && Left to Right Logical OR || Left to Right Ternary ?: Right to Left
  • 44. • A loop statement allows us to execute a statement or group of statements multiple times. • Tcl language provides the following types of loops to handle looping requirements: TCL LOOPS Loop Type Description While loop Repeats a statement or group of statements while a given condition is true. It tests the condition before executing the loop body. For loop Executes a sequence of statements multiple times and abbreviates the code that manages the loop variable. Nested loops Uses one or more loop inside any another while, for or do..while loop.
  • 45. WHILE LOOP •A while loop statement in Tcl language repeatedly executes a target statement as long as a given condition is true. Syntax while {condition} { statement(s) } Here, statement(s) may be a single statement or a block of statements. The condition may be any expression, and true is any nonzero value. The loop iterates while the condition is true. When the condition becomes false, program control passes to the line immediately following the loop. TCL LOOPS
  • 46. WHILE LOOP set a 10 #while loop execution while { $a < 20 } { puts "value of a: $a" incr a } Output: value of a: 10 value of a: 11 value of a: 12 value of a: 13 value of a: 14 value of a: 15 TCL LOOPS
  • 47. FOR LOOP •A for loop is a repetition control structure that allows you to efficiently write a code that needs to be executed for a specific number of times. Syntax for {initialization} {condition} {increment} { statement(s); } Flow of control in a for loop − The initialization step is executed first, and only once. This step allows you to declare and initialize any loop control variables. You are not required to put a statement here, as long as a semicolon appears. Next, the condition is evaluated. If it is true, the body of the loop is executed. If it is false, the body of the loop does not execute and flow of control jumps to the next statement just after the for loop. After the body of the for loop executes, the flow of control jumps back up to the increment statement. This statement allows you to update any loop control variables. This statement can be left blank, as long as a semicolon appears after the condition. The condition is now evaluated again. If it is true, the loop executes and the process repeats itself (body of loop, then TCL LOOPS
  • 48. FOR LOOP # for loop execution for { set a 10} {$a < 20} {incr a} { puts "value of a: $a" } Output value of a: 10 value of a: 11 value of a: 12 value of a: 13 value of a: 14 value of a: 15 value of a: 16 TCL LOOPS
  • 49. NESTED LOOP Tcl allows to use one loop inside another loop. Syntax The syntax for a nested for loop statement in Tcl − for {initialization} {condition} {increment} { for {initialization} {condition} {increment} { statement(s); } statement(s); } The syntax for a nested while loop statement in Tcl language is as follows − while {condition} { while {condition} { statement(s); } TCL LOOPS
  • 50. NESTED LOOP A nested for loop to find the prime numbers from 2 to 100 − set j 0; for {set i 2} {$i<100} {incr i} { for {set j 2} {$j <= [expr $i/$j] } {incr j} { if { [expr $i%$j] == 0 } { break } } if {$j >[expr $i/$j] } { puts "$i is prime" } } TCL LOOPS
  • 51. Infinite Loop • A loop becomes infinite loop if a condition never becomes false. • The while loop is traditionally used for this purpose. • By leaving the conditional expression as 1, an endless loop can be made. while {1} { puts "This loop will run forever." } • When the conditional expression is absent, it is assumed to be true. • Tcl programmers more commonly use the while {1} construct to signify an infinite loop. NOTE − You can terminate an infinite loop by pressing Ctrl + C keys. TCL LOOPS
  • 52. Loop Control Statements • Loop control statements change execution from its normal sequence. • When execution leaves a scope, all automatic objects that were created in that scope are destroyed. TCL LOOPS Control Statement Description Break statement Terminates the loop or switch statement and transfers execution to the statement immediately following the loop or switch. Continue statement Causes the loop to skip the remainder of its body and immediately retest its condition prior to reiterating.
  • 53. BREAK STATEMENT The break statement in Tcl language is used for terminating a loop. When the break statement is encountered inside a loop, the loop is immediately terminated and program control resumes at the next statement following the loop. If you are using nested loops (i.e., one loop inside another loop), the break statement will stop the execution of the innermost loop and start executing the next line of code after the block. Syntax break; TCL LOOPS
  • 54. BREAK STATEMENT set a 10 # while loop execution while {$a < 20 } { puts "value of a: $a" incr a if { $a > 15} { # terminate the loop using break statement break } } OUTPUT value of a: 10 value of a: 11 TCL LOOPS
  • 55. CONTINUE STATEMENT The continue statement in Tcl language works somewhat like the break statement. Instead of forcing termination, however, continue forces the next iteration of the loop to take place, skipping any code in between. For the for loop, continue statement causes the conditional test and increment portions of the loop to execute. For the while loop, continue statement passes the program control to the conditional tests. Syntax continue; TCL LOOPS
  • 56. CONTINUE STATEMENT set a 10 # do loop execution while { $a < 20 } { if { $a == 15} { #skip the iteration incr a continue } puts "value of a: $a" incr a } OUTPUT value of a: 10 value of a: 11 value of a: 12 TCL LOOPS
  • 57. •The primitive data-type of Tcl is string and often we can find quotes on Tcl as string only language. •These strings can contain alphanumeric character, just numbers, Boolean, or even binary data. •Tcl uses 16 bit unicode characters and alphanumeric characters can contain letters including non-Latin characters, number or punctuation. •Boolean value can be represented as 1, yes or true for true and 0, no, or false for false. STRINGS
  • 58. 1. string length: In Tcl, you can find the length of a string using the string length command. Example: set my_string "Hello, world!" set length [string length $my_string] puts "Length of the string: $length" 2. string reverse: In Tcl, you can reverse a string using the string reverse command. Example: set my_string "Hello, world!" set length [string reverse $my_string] puts "Length of the string: $length" STRING COMMAND
  • 59. 3.string compare: In Tcl, you can compare two strings using the string compare command. The string compare command compares two strings lexicographically and returns an integer value indicating their relationship. Example: set string1 "apple" set string2 "banana" # Compare the strings set result[string compare $string1 $string2] if {$result == 0} { puts "The strings are equal." } elseif {result < 0} { puts "String 1 comes before String 2." } else { puts "String 1 comes after String 2." STRING COMMAND
  • 60. 4.string index: In Tcl, you can extract a single character from a string at a specified index using the string index command. Example: set my_string "Hello, world!" # Get the character at index 1 (Tcl uses 0-based indexing) set character [string index $my_string 0] puts "Character at index 0: $character" STRING COMMAND
  • 61. 5.string range: In Tcl, you can extract a substring from a string using the string range command. This command allows you to specify a range of characters to extract from the original string. Example: # Example string set my_string "Hello, world!" # Extract a substring from index 1 to 5 set substring [string range $my_string 1 5] # Print the substring puts "Substring from index 1 to 5: $substring" STRING COMMAND
  • 62. 6.string tolower: In Tcl, the string tolower command is used to convert all characters in a string to lowercase. Example: # Example string set my_string "Hello, WORLD!" # Convert the string to lowercase set lc_string [string tolower $my_string] # Print the lowercase string puts "Lowercase string: $lc_string" STRING COMMAND
  • 63. 7.string toupper: In Tcl, the string toupper command is used to convert all characters in a string to uppercase. Example: # Example string set my_string "Hello, world!" # Convert the string to uppercase set uppercase_string [string toupper $my_string] # Print the uppercase string puts "Uppercase string: $uppercase_string" STRING COMMAND
  • 64. 8.string trim: In Tcl, the string trim command is used to remove whitespace characters (spaces, tabs, and newlines) from the beginning and end of a string. Example: set my_string " Hello, world! " # Trim the whitespace from the string set trimmed_string [string trim $my_string] # Print the trimmed string puts "Trimmed string: "$trimmed_string"" STRING COMMAND
  • 65. 9. string trimleft Trim the left side of the begining of the string. set a " this is tcl class" set b [string trimleft $a] puts $a puts $b set a " this is tcl class" set b [string trimleft $a " "] puts $a puts $b set a "this is tcl class" set b "this" set c [string trimleft $a $b] puts $a STRING COMMAND
  • 66. 10. string trim right # trims the right side of the begining of the string. set a "this is tcl class" set b "class" set c [string trimright $a $b] puts $a puts $c 11.string first In Tcl, the string first command is used to find the index of the first occurrence of a substring within a string. set my_string "Hello, world!" set index [string first "world" $my_string] puts "Index of 'world': $index" STRING COMMAND
  • 67. 12.string last: In Tcl, the string last command is used to find the index of the last occurrence of a substring within a string. Example: # Example string set my_string "this is a tcl class tcl class tcl" # Find the index of the last occurrence of "tcl" in the string set index [string last "tcl" $my_string] # Print the index puts "Index of last 'tcl': $index" STRING COMMAND
  • 68. 13.string concat: In Tcl, the string concat command concatenates multiple strings together into a single string. It's particularly useful when you want to join several strings into one. Example: set string1 "Hello" set string2 ", " set string3 "world!" set concatenated_string [concat $string1 $string2 $string3] puts "Concatenated string: $concatenated_string" STRING COMMAND
  • 69. 14.string equal: In Tcl, the string equal command is used to compare two strings to see if they are equal. It returns a boolean value indicating whether the two strings are equal. Example: set string1 "Hello" set string2 "Hello" if {[string equal $string1 $string2]} { puts "The strings are equal" } else { puts "The strings are not equal" } STRING COMMAND
  • 70. 15.string match: In Tcl, the string match command is used to perform pattern matching on strings. It compares a string against a pattern and returns a boolean value indicating whether the string matches the pattern. The pattern can contain special characters to represent wildcards and character ranges. Example: set my_string "hello" set pattern "he*o" if {[string match $pattern $my_string]} { puts "The string matches the pattern" } else { puts "The string does not match the pattern" } STRING COMMAND
  • 71. 16.string map: In Tcl, the string map command is used to perform multiple string substitutions within a string based on a mapping of key-value pairs. It replaces all occurrences of the keys in the string with their corresponding values. Example: set original_string "The quick brown fox jumps over the lazy dog." set substitution_map { quick fast brown red fox cat dog rabbit } set modified_string [string map $substitution_map $original_string] puts $modified_string STRING COMMAND
  • 72. 17. string replace: In Tcl, the string replace command is used to replace a portion of a string with another string. It allows you to specify the start index and the number of characters to replace. Example: set a "This is TCL class" puts $a set b [string replace $a 12 16 "session"] puts $b STRING COMMAND
  • 73. 18.string repeat: In Tcl, the string repeat command is used to create a new string by repeating another string a specified number of times. Example: set repeated_string [string repeat "abc" 3] puts $repeated_string STRING COMMAND
  • 74. 19.string format: In Tcl, the string format command is used to create a formatted string based on a format string and a list of values. Example: set name "Vikram" set age 30 set country India set formatted_string [format "Name: %s, Age: %d ,Country:%s" $name $age $country] puts $formatted_string STRING COMMAND
  • 75. • It is used to match the pattern in the text. • In TCL, regular expression is pattern that describes a set of strings, extract the information, and perfrom complex text processing tasks. • regexp command is supporting to match the pattern. • This command allows to perform various operations such as pattern matching, substitution and splitting on the strings using regular expression. Syntax: [regexp "search_pattern $content] REGULAR EXPRESSION IN TCL
  • 76. Example: 1) set a "hello world" if {[regexp "hello" $a]} { puts "pattern matches" } else { puts "pattern not matches" } 2) set a "HELLO world" if {[regexp -nocase "hello" $a]} { puts "pattern matches" } else { puts "pattern not matches" } REGULAR EXPRESSION IN TCL
  • 77. List of all the metacharacters, quantifiers and special sequences that can be used in regular expression in TCL: Meta characters --------------- .(dot)-->matches any single character except newline. set string "abcd" set b [regexp "^a..d$" $string] puts $b #output is b=1 REGULAR EXPRESSION IN TCL
  • 78. set string "I have dog" if {[regexp "h.e" $string]} { puts "Match found" } else { puts "No Match found" } #output is No Match found |(pipe)-->matches either the pattern on its left or the pattern on its right set string "I have a dog" set b [regexp "cat|dog" $string] puts $b REGULAR EXPRESSION IN TCL
  • 79. [...](bracket expression)-->matches any single charcter from the specified set of characters [^...](negated bracket expression)-->matches any single character not in the specified set of characters ()grouping --> groups multiple pattern together. (escape)-->escapes a meta character,allowing it to be matched as aliteral character. {...}(curly braces)-->matches the enclosed pattern exactly. example:[a-z]{3} REGULAR EXPRESSION IN TCL
  • 80. Quantifiers ----------- *(asterisk)-->matches zero or more occurrances of the preceding character or subexpression. 1) set string "The quick brown fox jump over the lazy dog" if {[regexp "o*" $string} { puts "match found" } else { puts "no match found" } 2) set string "The quick brown fox jump over the lazy dog" set b [regexp "o*" $string] puts $b REGULAR EXPRESSION IN TCL
  • 81. +(plus)-->matches one or more occurances of the preceding character or subexpression 1) set string "The quick brown fox jump over the lazy dog" set b [regexp "o+" $string] puts $b 2) set string "The quick brown fox jump over the lazy dog" if {[regexp "o+" $string]} { puts "match found" } else { puts "no match found" } REGULAR EXPRESSION IN TCL
  • 82. ?(question mark)-->matches zero or one occurances of the preceding character or subexpression. 1) set string "The quick brown fox jump over the lazy dog" set b [regexp "ou?" $string] puts $b 2) set string "The quick brown fox jump over the lazy dog" if {[regexp "ou?" $string]} { puts "match found" } else { puts "no match found" } REGULAR EXPRESSION IN TCL
  • 83. {n}(exact quantifiers)-->matches exactly "n" occurances of the preceding characters or sub expressions {n,}(minimum quantifier)-->matches at least n occurance of the preceding character or sub expressions Example 1: 1) set a {the mentor for funtional_verification2023 is : mohan_kumar_ns} set b [regexp -nocase {the mentor for [a-z0-9_]+ is : [a-z]+} $a] puts $b 2) set a {the mentor for physicaldesign_2023 is : chethan_kumar_ns} set b [regexp -nocase {the mentor for ([a-z0-9_]+) is * :* ([a-z_]+)} $a match1 match2 match3] puts $b puts "this will print the whole expression :$match1" puts "this will print the course_name:$match2" puts "this will print the mentor_name:$match3" REGULAR EXPRESSION IN TCL
  • 84. Example2: set a {sram :-2500} set b [regexp -nocase {([a-z]+) :([-0-9]+)} $a m1 m2 m3] puts $b puts "the cell_name is:$m2" puts " the cell_value is:$m3" Example3: lassign $argv set file [open "text1.txt" r] while {[gets $file line]>=0} { if {$argv==[lindex $line 0]} { set b [regexp -nocase {([a-z]+) :([-0-9]+)} $line match match2 match3] } } puts "the value of $argv is : $match3" REGULAR EXPRESSION IN TCL
  • 85. x --> Exact match [a-z] --> any lowercase from a to z. [A-Z] --> any uppercase from A to Z. . --> any character ^ --> Begining string should match $ --> Ending string should match () --> Add the sequence inside parenthesis to make a RE. x* --> should match 0 or more occurences of the preceding x x+ --> should match 1 or more ocuurences of the preceding x ^ --> backlash sequnece to match special charater. [a-z]* --> should match 0 or more occurence of the preceding x {digit} --> matchs exactly digit ocuurences. digit occurrences 0 to 9. REGULAR EXPRESSION IN TCL
  • 86. example:4 1.read the VHDL.txt file 2. go through line by line. 3. write the regular expression to capture all the entity names. 4. 5. write all the entity names into new file(VHDL_enitity.txt) set fh_read [open "VHDL.txt" r] set fh_write [open "VHDL_entity.txt" w] set i 0 while {[gets $fh_read line] >= 0} { incr i if {[regexp -nocase { *entity +([a-z_]+) +is} $line match match1]} { puts "the line number of the enity is:$i and entity name is:$match1" puts $fh_write "the line number of the enity is:$i and entity name is:$match1" } } REGULAR EXPRESSION IN TCL