Programming Using Tcl Maxwell Created By: Quan Nguyen Created Date: 12/12/2016 TCL Training1.

Slides:



Advertisements
Similar presentations
JavaScript I. JavaScript is an object oriented programming language used to add interactivity to web pages. Different from Java, even though bears some.
Advertisements

CIS 240 Introduction to UNIX Instructor: Sue Sampson.
Macro simple idea of textual substitution useful when you need a group of instructions or directives frequently.
CS252: Systems Programming Ninghui Li Topic 4: Regular Expressions and Lexical Analysis.
Tcl and Otcl Tutorial Part I Internet Computing KUT Youn-Hee Han.
Programming Using Tcl/Tk These slides are based upon u several Tcl/Tk text books u material byDr. Ernest J. Friedman-Hill.
ISBN Regular expressions Mastering Regular Expressions by Jeffrey E. F. Friedl –(on reserve.
NS-2 LAB: TCL Semester A Miriam Allalouf.
Writing Tcl Scripts (cont.) Outline –Variable Scoping –Strings –Eval –File/Channel I/O –Processes –System Info –Errors –Reflection/Debugging –Libraries.
Bash, part 2 Prof. Chris GauthierDickey COMP Unix Tools.
Tcl/TK Tutorial Fan Yang Kristy Hollingshead
Writing Tcl Scripts Outline Goal Reading Syntax Data Types
Tcl/Tk 2 CS 414, Software Engineering I Mark Ardis Rose-Hulman Institute December 5, 2002.
Basic Elements of C++ Chapter 2.
Innovation Intelligence ® 1 Chapter 1: Introduction to TCL.
SYST Web Technologies SYST Web Technologies Lesson 6 – Intro to JavaScript.
Chap 3 – PHP Quick Start COMP RL Professor Mattos.
Tcl and Otcl Tutorial Part II Internet Computing KUT Youn-Hee Han.
CIS 218 Advanced UNIX1 CIS 218 – Advanced UNIX (g)awk.
The Java Programming Language
ASP.NET Programming with C# and SQL Server First Edition Chapter 3 Using Functions, Methods, and Control Structures.
Computer Science 101 Introduction to Programming.
Hello.java Program Output 1 public class Hello { 2 public static void main( String [] args ) 3 { 4 System.out.println( “Hello!" ); 5 } // end method main.
Tcl/TK Tutorial. 2 Learning Tcl/TK What is Tcl/TK? –An interpreted programming language Build on-the-fly commands, procedures Platform-independent Easy.
Copyright © 2010 Certification Partners, LLC -- All Rights Reserved Perl Specialist.
1Computer Sciences Department Princess Nourah bint Abdulrahman University.
Revision Lecture Mauro Jaskelioff. AWK Program Structure AWK programs consists of patterns and procedures Pattern_1 { Procedure_1} Pattern_2 { Procedure_2}
_______________________________________________________________________________________________________________ PHP Bible, 2 nd Edition1  Wiley and the.
Shell Scripting Lab 2 Advanced Operating System Spring Advanced Operating System - Spring Lab 2.
Copyright © 2003 ProsoftTraining. All rights reserved. Perl Fundamentals.
Programming Using Tcl/Tk Week 2 Seree Chinodom
Introduction to Tcl/Tk TraNese Christy U.S. Army Research Laboratory.
XP New Perspectives on XML, 2 nd Edition Tutorial 7 1 TUTORIAL 7 CREATING A COMPUTATIONAL STYLESHEET.
Perl Variables: Array Web Programming1. Review: Perl Variables Scalar ► e.g. $var1 = “Mary”; $var2= 1; ► holds number, character, string Array ► e.g.
Dongsoo S. Kim  Tcl: Tool Command Language Interpreted programming (scripting) language Build on-the-fly commands and procedures Embeddable.
Open Source Server Side Scripting ECA 236 Open Source Server Side Scripting PHP Basics.
Introduction to Programming with Tcl. Introduction Using two languages  C++ for “ data ”  Otcl for control Tcl has been widely used as a scripting language.
2: Basics Basics Programming C# © 2003 DevelopMentor, Inc. 12/1/2003.
Scripting.
Dr. Abdullah Almutairi Spring PHP is a server scripting language, and a powerful tool for making dynamic and interactive Web pages. PHP is a widely-used,
An Introduction To Tcl Scripting John Ousterhout Sun Microsystems Laboratories Tcl/Tk Tutorial, Part II.
TCL/TK Tool Command Language/Tool Kit. What is TCL? u Tool Command Language u An interpreted programming language  Created by John Ousterhout.John Ousterhout.
Perl & TCL Vijay Subramanian, Modified from : perl_basics_06.ppt.
第二章 TCL 語言簡介 報告者:童耀民. 變數 (variable) 和變數替換 (variable substituion) set foo "john" puts "my name is $foo“ set month 2 set day 3 set year 97 set.
COMP075 OS2 Bash Scripting. Scripting? BASH provides access to OS functions, like any OS shell Also like any OS shell, BASH includes the ability to write.
Lecture 3: Getting Started & Input / Output (I/O)
TCL Training Joshi Sravan Kumar K 21-Nov-2011.
Information and Computer Sciences University of Hawaii, Manoa
CGS 3066: Web Programming and Design Spring 2017
Parsing 2 of 4: Scanner and Parsing
Chapter Topics The Basics of a C++ Program Data Types
CS170 – Week 1 Lecture 3: Foundation Ismail abumuhfouz.
Basic Elements of C++.
JavaScript Syntax and Semantics
Server-Side Application and Data Management IT IS 3105 (Spring 2010)
TCL/TK Tool Command Language/Tool Kit.
Basic Elements of C++ Chapter 2.
John Carelli, Instructor Kutztown University
Objectives Insert a script element Write JavaScript comments
Perl Variables: Array Web Programming.
NS-2 LAB: TCL Miriam Allalouf Semester A.
An overview of Java, Data types and variables
slides created by Marty Stepp
PHP.
University of Kurdistan
Quattor Advanced Tutorial, LAL
16 Strings.
Programming Languages and Paradigms
C Language B. DHIVYA 17PCA140 II MCA.
Chengyu Sun California State University, Los Angeles
Presentation transcript:

Programming Using Tcl Maxwell Created By: Quan Nguyen Created Date: 12/12/2016 TCL Training1

What you’ll need u TCL is a scripting language u Start Maxwell and open the Console TCL Training2

Basic TCL 3

Scripts and Commands u Tcl script = –Sequence of commands. –Commands separated by newlines, semi-colons. u Tcl command = –One or more words separated by white space. –First word is command name, others are arguments. –Returns string result. u Examples: set myName Saul puts "My Name is $myName” set class CPSC-481; puts -nonewline $class TCL Training4

Variable Substitution  Syntax: $ varName u Variable name is letters, digits, underscores. u May occur anywhere in a word. Sample commandResult set b 6666 set a bb set a $b66 set a $b+$b+$b set a $b set a $b4 no such variable TCL Training5

Command Substitution u Syntax: [script] u Evaluate script, substitute result. u May occur anywhere within a word. Sample commandResult set b 88 set a [expr $b+2]10 set a "b-3 is [expr $b-3]"b-3 is 5 TCL Training6

Comments u The # is the comment command u Tcl parsing rules apply to comments as well set a 22; set b 33 <- OK # this is a comment <- OK set a 22 # same thing? <- Wrong! set a 22 ;# same thing <- OK TCL Training7

Summary of Tcl Command Syntax u Command: words separated by whitespace u First word is a function, others are arguments u $ causes variable interpolation u [ ] causes command interpolation u “” prevents word breaks u \ escapes special characters u TCL HAS NO GRAMMAR! TCL Training8

Tcl Expressions u Arguments are interpretted as expressions in some commands: expr, if,... Sample commandResult set b 55 expr ($b*4) expr $b <= 20 expr {$b * cos(4)}-3.268… u Some Tcl operators work on strings too (but safer to use the string compare command) set a BillBill expr {$a < "Anne"}0 expr {$a < "Fred"}1 TCL Training9

Lists u Zero or more elements separated by white space: set colors {red green blue} set list1 {} Set list2 [list a b c] Set list3 {1 2 {3 4}} Set list4 [list 1 2 [list 3 4]]  Index start with 0. end means last element u Examples: lindex {a b {c d e} f} 2  c d e lsort {red green blue}  blue green red TCL Training10

11 List Methods Function NameExample lappend lappend {a b} c  a b c lindex lindex {a b c} 1  b llength llength {a b c}  3 lrange lrange {a b c d} 0 2  a b c lsearch lsort lsort –decreasing {a b c}  c b a lreplace TCL Training

String Manipulation u String manipulation commands: split, compare, first, last, index, length, match, toupper, tolower, trim, trimleft, trimright  Note: all indexes start with 0. end means last char  string tolower "THIS" ;# this  string trimleft “XXXXHello” ;# Hello  string index “abcde” 2 ;# c TCL Training12

TCL Training13 regexp regexp exp string ?matchVar? ?sub? ?sub?.any single character ^matches null string at start of string $matches null string at end of string \xmatches the character x [c1-c2]matches any single character (regexp)matches regexp – used for grouping *matches 0 or more of previous atom +matches 1 or more of previous atom ?matches null string or previous atom r1|r2matches r1 or r2

Control Structures u Just commands that take Tcl scripts as arguments. u Commands: ifforswitchbreak foreachwhileevalcontinue TCL Training14

if else set x 2 if {$x < 3} { puts "x is less than 3" } else { puts "x is 3 or more" } TCL Training15

while #list reversal set a {a b c d e} set b "” set i [expr [llength $a] - 1] while {$i >= 0} { lappend b [lindex $a $i] incr i -1 } puts $b TCL Training16

for and foreach for {set i 0} {$i<10} {incr i} { puts $i } foreach color {red green blue} { puts “I like $color” } TCL Training17

switch set pete_count 0 set bob_count 0 set other_count 0 foreach name {Peter Peteee Bobus Me Bobor Bob} { switch -regexp $name { ^Pete* {incr pete_count} ^Bob|^Robert {incr bob_count} default {incr other_count} } puts "$pete_count $bob_count $other_count" TCL Training18

Procedures  proc command defines a procedure: proc decrement {x} { expr $x-1 } u Procedures behave just like built-in commands: decrement 3  2 u Arguments can have default values: proc decrement {x {y 1}} { expr $x-$y } decrement ;# 95 decrement 100 ;# 99 name list of argument names body TCL Training19

Procedures u Procedures can have a variable number of arguments proc sum args { set s 0 foreach i $args { incr s $i } return $s } sum  15 sum  0 TCL Training20

Procedures and Scope u Scoping: local and global variables. –Interpreter knows variables by their name and scope –Each procedure introduces a new scope  global procedure makes a global variable local set outside "I'm outside" set inside "I'm really outside" proc whereAmI {inside} { global outside puts $outside puts $inside } whereAmI "I wonder where I will be " -> I'm outside I wonder where I will be TCL Training21

Tcl File I/O u Tcl file I/O commands: opengetsseekflushglob closereadtellcd fconfigure fblocked fileevent putssourceeofpwdfilename u File commands use 'tokens' to refer to files set f [open "myfile.txt" "r"] => file4 puts $f "Write this text into file" close $f TCL Training22

Tcl File I/O u gets and puts are line oriented set x [gets $f] reads one line of $f into x  read can read specific numbers of bytes read $f 100 => (up to 100 bytes of file $f)  seek, tell, and read can do random-access I/O set f [open "database" "r"] seek $f 1024 read $f 100 => (bytes of file $f) TCL Training23

Error handling u Similar to C++ and Java u catch {command} varName if {[catch {open foo.txt} msg]} { puts $msg } TCL Training24

Time and Date u clock seconds –time in seconds (usu. since 1/1/70) u clock format –convert to string –e.g., clock format $t –format "%a, %B %e %Y %H:%M:%S"  Thu, April :00:56 u clock scan dateString –convert date string to integer TCL Training25

namespace u namespace eval/import/export namespace eval ::savarti::tcl { namespace import ::savarti::example::* proc proc1 {} { puts “proc in namespace” } ::savarti::tcl::proc1 TCL Training26

Tcl Arrays u Tcl arrays are 'associative arrays': index is any string –set foo(fred) 44 ;# 44 –set foo(2) [expr $foo(fred) + 6] ;# 50 –array names foo ;# fred 2 u You can 'fake' 2-D arrays: set A(1,1) 10 set A(1,2) 11 array names A => 1,1 1,2 (commas included in names!) TCL Training27

Maxwell Tcl Reference Manual 28

Overview TCL Training29 namespaceUse db::Database Tcl dm::Data Management Tcl de::Design Editing Tcl gi::Graphical Infrastructure Tcl le::Layout Editing Tcl se::Schematic Editing Tcl

db:: namespace (1) TCL Training30 procUse db::foreach Provides “foreach” loop control for iterating over dbCollections db::addAttr Adds the specified attribute to the given object. db::setAttr Sets the value of the specified attribute of the given objects db::getAttr Returns the value of the specified attribute of the given object. db::listAttrs Returns the attribute names for the given objec db::getCount Returns the number of objects in the specified collection db::getNext Returns the next object in a collection db::destroy Deletes objects

db:: namespace (2) TCL Training31 proc db::getShapesdb::getPrefs db::getTermsdb::createPref db::getViasdb::copyParams db::getInstsdb::createParamDef db::getInstTermsdb::getCallbacks db::getMarkersdb::getParams db::getNetsdb::getParamValue db::getPinsdb::setParamValue db::setInstNamedb::getPrefs db::setMasterdb::createPref

dm:: namespace TCL Training32 proc dm::createCelldm::createLib dm::copyCellsdm::copyLib dm::getCellsdm::getLibs dm::moveCellsdm::moveLib dm::createCellView dm::copyCellViews dm::getCellViews dm::moveCellViews

de:: namespace TCL Training33 proc de::opende::getFigures de::savede::getLayers de::closede::getLPPs de::copyde::setCursor de::createCommand de::startTransaction de::endTransaction de::getActiveContext de::getActiveEditorWindow

gi:: namespace TCL Training34 proc gi::addActionsgi::createRow gi::addMenugi::createTabGroup gi::createActiongi::createTable gi::createBooleanInputgi::createTextInput gi::createColumngi::execDialog gi::createDialoggi::executeAction gi::createFileInputgi::findChild gi::createGroupgi::getCells gi::createLabelgi::getColumns gi::createListInputgi::getDialogs gi::createMenugi::layout gi::createMutexInputgi::prompt gi::createNumberInputgi::setActiveTab

le:: namespace TCL Training35 proc le::alignle::createTerm le::convertToPolygonle::createVia le::copyle::flatten le::createInstle::generateShapes le::createPinle::move le::rotate

se:: namespace TCL Training36 proc se::alignse::createPolygon se::attachTextse::createRectangle se::checkse::createText se::connectWiresse::createWire se::copyse::createWireName se::createInstse::delete se::createLinese::generateSymbol se::createPinse::move