TCL - PowerPoint PPT Presentation

1 / 21
About This Presentation
Title:

TCL

Description:

Backslash Substitution. Order of Substitution. Substitution and word boundaries. Comments ... Rule 8: Backslash Substitution. Similar to how it is used in Java ... – PowerPoint PPT presentation

Number of Views:177
Avg rating:3.0/5.0
Slides: 22
Provided by: csGeor2
Category:
Tags: tcl | backslash

less

Transcript and Presenter's Notes

Title: TCL


1
TCL
  • Tool Command Language

2
About
  • Scripting language
  • Functional, but not completely
  • Imperative
  • Object oriented
  • Logical?
  • Similarities
  • C
  • Shell
  • LISP

3
Syntax Vocabulary
  • Script
  • A string that is a sequence of commands,
    separated by newlines or semicolons.
  • Command
  • A string that is a list of words, separated by
    blanks.
  • Word
  • A string that is a simple word, or one that
    begins with and ends with the matching , or
    one that begins with and ends with the matching
    .

4
Syntax 11 Rules
  • Words
  • Commands
  • Evaluation
  • Double Quotes
  • Braces
  • Command Substitution
  • Variable Substitution
  • Backslash Substitution
  • Order of Substitution
  • Substitution and word boundaries
  • Comments

5
Rule 1 Words
  • Strings
  • Arbitrary in length
  • Consist of nearly any characters
  • Separated by White Space
  • Except when quoted
  • Example
  • set a 3 contains 3 words (set, a, 3)
  • this is one word treated as single word

6
Rule 2 Commands
  • separated by newlines and semicolons.
  • consist of one or more word
  • First word is name of command
  • Successive words are arguments
  • Words can be command with around them
  • Example
  • set variable 3 variable 3
  • expr 3 4 7
  • set variable expr 3 4 variable 7

7
Rule 3 Evaluation
  • Two step command evaluation
  • Breaks command into words
  • Performs substitution
  • Single pass
  • No meaning given yet

8
Rule 4 Double Quotes
  • Special character are treated as ordinary
    characters
  • semicolons, close brackets, white space, etc
  • Double quotes not part of actual word.
  • All types of Substitutions takes place

9
Rule 5 Braces
  • String
  • Anything inside has literal translation
  • Braces not part of the word
  • If braces inside quote, quoting rule applies
  • No substitutions are performed
  • Example
  • set a literal str a literal str
  • set b /non-a b non-literal str

10
Rule 6 Command Substitution
  • If word inside of
  • Evaluated recursively
  • Example
  • set a expr 34 a 347
  • set b expr a incr a b
    7 (7 1) 7 8 15

11
Rule 7 Variable Substitution
  • Variable begin with
  • Variables can be nearly anything
  • Letter, digit, underscore, etc.
  • Example
  • set a expr 11 puts 1 2 a
    1 2 2
  • set 4 3 puts 4 3
  • set two words one put two words
    one
  • set array(0) 3 set i 0 puts
    array(i) 3

12
Rule 8 Backslash Substitution
  • Similar to how it is used in Java
  • Examples
  • puts hello \\ world hello \ world
  • puts price \350 price 3.50
  • \a ltplays a soundgt
  • puts \ \

13
Rule 9 Order of Substitution
  • Processed
  • One at a time
  • Left to right
  • Example
  • set y set x 0incr xincr x y 012

14
Rule 10 Substitution and word boundaries
  • Substitution doesnt effect word bounds
  • Example
  • set a one word put still a still one
    word
  • The solution contains two words still, one
    word

15
Rule 11 Comments
  • Use hash ()
  • Must be at beginning of line
  • Example
  • comment
  • set a comment
  • set a NOT comment

16
Flow of Control
  • If, For, Foreach, While
  • All Commands
  • Similar semantics to C
  • Example
  • If cond scriptA else scriptB

17
Procedures
  • Local scope
  • Customable
  • Helps structure programs
  • Example
  • proc ! n if n 1 then return 1 else
    return expr n ! expr n-1
  • ! 3 3! 3 2 1 6

18
Features
  • proc solve a b return expr a b
  • solve 2 3
  • wrong args should be "solve a b
  • solve 3 2
  • 5

19
Features
  • proc solve a op b return expr a op b
  • solve 1 1
  • 2
  • solve 3 2
  • 1
  • solve 3 gt 1
  • 1 (true)

20
Features
  • rename expr solve
  • solve 3 4
  • 7
  • solve 3 2
  • 1

21
Feature
  • proc do body while expression uplevel
    body while uplevel expr expression
    uplevel body set i 0 do
    puts i incr i while i lt 3
  • 0
  • 1
  • 2
Write a Comment
User Comments (0)
About PowerShow.com