## Tcl8.6.17/Tk8.6.17 Documentation > Tcl Commands > Tcl

### Tcl/Tk Applications | Tcl Commands | Tk Commands | [incr Tcl] Package Commands | SQLite3 Package Commands | TDBC Package Commands | tdbc::mysql Package Commands | tdbc::odbc Package Commands | tdbc::postgres Package Commands | tdbc::sqlite3 Package Commands | Thread Package Commands | Tcl C API | Tk C API | [incr Tcl] Package C API | TDBC Package C API

  NAME
    Tcl — 道具命令言語 Tool Command Language
  構文 SYNOPSIS
  説明 DESCRIPTION
  [1] 諸命令 Commands.
  [2] 評価 Evaluation.
  [3] 語 Words.
  [4] 二重引用符 Double quotes.
  [5] 引数展開 Argument expansion.
  [6] 波括弧 Braces.
  [7] 命令置換 Command substitution.
  [8] 変数置換 Variable substitution.
    $name
    $name(index)
    ${name}
  [9] 逆斜線置換 Backslash substitution.
    \a
    \b
    \f
    \n
    \r
    \t
    \v
    \<newline>whiteSpace
    \\
    \ooo
    \x hh
    \u hhhh
    \U hhhhhhhh
  [10] 注釈 Comments.
  [11] 置換の順序 Order of substitution.
  [12] 置換と語の境界 Substitution and word boundaries.
  KEYWORDS

### NAME

Tcl — 道具命令言語 Tool Command Language

### 構文 SYNOPSIS

Tcl 言語構文の要約｡ Summary of Tcl language syntax.

### 説明 DESCRIPTION

次の規則によりTcl 言語の構文と意味論が定義される｡ The following rules define the syntax and semantics of the Tcl language:

[1] 諸命令 Commands.
  Tcl 記述譜は一つ或はそれ以上の命令を含む文字列である｡セミコロンと改行は次に述べる引用の使用法を除き命令の分離記号である｡右角括弧は引用の使用法でない限り､命令置換(下を参照されたい)の命令の終端記号である｡ A Tcl script is a string containing one or more commands. Semi-colons and newlines are command separators unless quoted as described below. Close brackets are command terminators during command substitution (see below) unless quoted.

[2] 評価 Evaluation.
  命令は二つの段階で評価される｡第一､ Tcl 解釈実行機能が命令を語に分離し､下に述べる置換を遂行する｡この置換は全ての命令について同じ方法で行われる｡第二､最初の語は命令を実行すべき命令手続函数の目印になり､命令の全ての語が命令手続函数に送られる｡命令手続函数は整数､変数名､リスト､ Tcl 記述譜の様なそれぞれの語とは､どのように似ていても､それぞれの語の解釈とは独立している｡異なる命令はその語を異なって解釈する｡ A command is evaluated in two steps. First, the Tcl interpreter breaks the command into words and performs substitutions as described below. These substitutions are performed in the same way for all commands. Secondly, the first word is used to locate a command procedure to carry out the command, then all of the words of the command are passed to the command procedure. The command procedure is free to interpret each of its words in any way it likes, such as an integer, variable name, list, or Tcl script. Different commands interpret their words differently.

[3] 語 Words.
  命令の語は空白で区切られる(命令を区切る改行を除く)｡ Words of a command are separated by white space (except for newlines, which are command separators).

[4] 二重引用符 Double quotes.
  もし語の最初の文字が二重引用符 (“"”) であると､その語は次の二重引用符で終る｡もしセミコロンや､右角括弧や､空白(改行を含む)が引用符内に現れると､それらは通常の文字として扱われ､語に含まれる｡命令置換と､変数置換と､逆斜線置換は引用符内の文字に対して､下に述べられた通りに遂行される｡二重引用符は語の部分としては保持されない｡ If the first character of a word is double-quote (“"”) then the word is terminated by the next double-quote character. If semi-colons, close brackets, or white space characters (including newlines) appear between the quotes then they are treated as ordinary characters and included in the word. Command substitution, variable substitution, and backslash substitution are performed on the characters between the quotes as described below. The double-quotes are not retained as part of the word.

[5] 引数展開 Argument expansion.
  もし､語が後に空白を伴わない文字列 “{*}” で始まると､先頭の “{*}” は除去され､語の残りは解析され別々の語として置換される｡置換後､語はリストとして解析される(命令置換､及び変数置換を除く; リストに関して逆斜線置換は通常の如く遂行される､又個別の内部の語は波括弧や二重引用附で括られていても好い)､そしてその中の語が､置換されている命令に追加される｡譬えば､ “cmd a {*}{b [c]} d {*}{$e f {g h}}” は “cmd a b {[c]} d {$e} f {g h}” と等価である｡ If a word starts with the string “{*}” followed by a non-whitespace character, then the leading “{*}” is removed and the rest of the word is parsed and substituted as any other word. After substitution, the word is parsed as a list (without command or variable substitutions; backslash substitutions are performed as is normal for a list and individual internal words may be surrounded by either braces or double-quote characters), and its words are added to the command being substituted. For instance, “cmd a {*}{b [c]} d {*}{$e f {g h}}” is equivalent to “cmd a b {[c]} d {$e} f {g h}”.

[6] 波括弧 Braces.
  もし語の最初の文字が左波括弧 (“{”) であり､規則 [5] が適用されない場合､語は対応する右波括弧 (“}”) で終る｡波括弧は語の中で入子になる: 追加的な左波括弧毎に追加的な右波括弧がなければならない(但し､もし語内の右波括弧､又は左波括弧が逆斜線に引用されている場合は対応する波括弧があるとは数えない)｡下に述べる逆斜線改行置換を除いて､波括弧の間の文字は､置換が起らないし､セミコロン､改行､右角括弧､空白も何かの特定の解釈を受けることはない｡語は､外側の波括弧の間の文字で厳密に構成され､波括弧そのものは含まない｡ If the first character of a word is an open brace (“{”) and rule [5] does not apply, then the word is terminated by the matching close brace (“}”). Braces nest within the word: for each additional open brace there must be an additional close brace (however, if an open brace or close brace within the word is quoted with a backslash then it is not counted in locating the matching close brace). No substitutions are performed on the characters between the braces except for backslash-newline substitutions described below, nor do semi-colons, newlines, close brackets, or white space receive any special interpretation. The word will consist of exactly the characters between the outer braces, not including the braces themselves.

[7] 命令置換 Command substitution.
  もし語が左角括弧 (“[”) を含むと､ Tcl は命令置換を遂行する｡これを行う為に､Tcl 解釈実行機能を再帰的に起動し､左角括弧に続く文字並びを Tcl 記述譜として処理する｡記述譜は命令を幾つ含んでもよく､右角括弧 (“]”) で終らねばならない｡記述譜の結果(即ち､その最終の命令の結果)は､角括弧とその間にある全ての文字のある場所の語に置換される｡一つの語の中に幾つもの命令置換があるかもしれない｡命令置換は波括弧で括られた内側では遂行されない｡ If a word contains an open bracket (“[”) then Tcl performs command substitution. To do this it invokes the Tcl interpreter recursively to process the characters following the open bracket as a Tcl script. The script may contain any number of commands and must be terminated by a close bracket (“]”). The result of the script (i.e. the result of its last command) is substituted into the word in place of the brackets and all of the characters between them. There may be any number of command substitutions in a single word. Command substitution is not performed on words enclosed in braces.

[8] 変数置換 Variable substitution.
  もし､語が次の内のどれか一つの形式が続くドル記号 (“$”) を含む場合､ Tcl は変数置換を遂行する: ドル記号と次の文字並びは変数の値に置換えられる｡変数置換は次の形式のどれか一つの形式をとる: If a word contains a dollar-sign (“$”) followed by one of the forms described below, then Tcl performs variable substitution: the dollar-sign and the following characters are replaced in the word by the value of a variable. Variable substitution may take any of the following forms:

  $name
    name は単純変数の名前である; 名前は一つ或はそれ以上の文字の並びであり､その文字は英字か､数字か､下線か､名前空間の区切り(二つ以上のコロン)のどれかである｡英字と数字は標準的な ASCII 文字のみである(0–9 と A–Z と a–z)｡ Name is the name of a scalar variable; the name is a sequence of one or more characters that are a letter, digit, underscore, or namespace separators (two or more colons). Letters and digits are only the standard ASCII ones (0–9, A–Z and a–z).

  $name(index)
    name は配列変数の名前を与え､ index はその配列内の要素の名前を与える｡name は文字か､数字か､下線か､名前空間の区切りのみを含まねばならないが､空文字列でもよい｡文字と数字は標準的な ASCII 文字のみ(0-9 と A-Z と a-z)である｡命令置換と､変数置換と､逆斜線置換が index の文字並び上で遂行される｡ Name gives the name of an array variable and index gives the name of an element within that array. Name must contain only letters, digits, underscores, and namespace separators, and may be an empty string. Letters and digits are only the standard ASCII ones (0–9, A–Z and a–z). Command substitutions, variable substitutions, and backslash substitutions are performed on the characters of index.

  ${name}
    name は単純変数の名前か配列要素である｡何であれ右波括弧以外は含み得る｡もし name が “arrayName(index)” の形式であって､ arrayName がどのような左括弧文字 “(” や右波括弧文字 “}” も含まず且つ index が右波括弧文字に関わらない何かの文字並びである場合､これは配列要素を指す｡ name の解析ではそれ以上の置換は実施されない｡ Name is the name of a scalar variable or array element. It may contain any characters whatsoever except for close braces. It indicates an array element if name is in the form “arrayName(index)” where arrayName does not contain any open parenthesis characters, “(”, or close brace characters, “}”, and index can be any sequence of characters except for close brace characters. No further substitutions are performed during the parsing of name.

    一つの語内に変数置換が幾つあってもよい｡波括弧の中に括られた語は変数置換は行われない｡　 There may be any number of variable substitutions in a single word. Variable substitution is not performed on words enclosed in braces.

    註意すべきは変数は上に列挙した以外の文字を含み得るが､その場合､その変数を利用する為に他の仕組みを使う必要がある(譬えば､引数一個の形式の set 命令を使用する)｡ Note that variables may contain character sequences other than those listed above, but in that case other mechanisms must be used to access them (e.g., via the set command's single-argument form).

[9] 逆斜線置換 Backslash substitution.
  もし､語内部で逆斜線 (“\”) が現れる場合､逆斜線置換が生じる｡下に述べる場合以外は､全て逆斜線がとれて続く文字並びが通常の文字として扱われ､語内に含まれる｡これにより､特別な処理を起動することなく､語に含まれる二重引用符号､角括弧､ドル符号の様な文字が許容される｡次の表はそれぞれの並びを置換える値に従って特別に処理される逆斜線並びを列挙する｡ If a backslash (“\”) appears within a word then backslash substitution occurs. In all cases but those described below the backslash is dropped and the following character is treated as an ordinary character and included in the word. This allows characters such as double quotes, close brackets, and dollar signs to be included in words without triggering special processing. The following table lists the backslash sequences that are handled specially, along with the value that replaces each sequence.

  \a
    警告音(鐘)(ユニコード U+000007)｡ Audible alert (bell) (Unicode U+000007).

  \b
    逆戻り(ユニコード U+000008)｡ Backspace (Unicode U+000008).

  \f
    改頁(ユニコード U+00000C)｡ Form feed (Unicode U+00000C).

  \n
    改行(ユニコード U+00000A)｡ Newline (Unicode U+00000A).

  \r
    復帰(ユニコード U+00000D)｡ Carriage-return (Unicode U+00000D).

  \t
    表送り(ユニコード U+000009)｡ Tab (Unicode U+000009).

  \v
    縦表送り(ユニコード U+00000B)｡ Vertical tab (Unicode U+00000B).

  \<newline>whiteSpace
    逆斜線と､改行､及びその改行後の全ての空白とタブが､一個の空白文字に置換わる｡この逆斜線並びは風変わりで､命令が実際に解析される前に離れた前方の位置で置換が起る｡これが意味するのは､置換が波括弧の間でさえも起こり､又､結果として生じた空白は波括弧や引用の中でなければ語の区切りとして取り扱われる｡ A single space character replaces the backslash, newline, and all spaces and tabs after the newline. This backslash sequence is unique in that it is replaced in a separate prepass before the command is actually parsed. This means that it will be replaced even when it occurs between braces, and the resulting space will be treated as a word separator if it is not in braces or quotes.

  \\
    逆斜線 (“\”) ｡ Backslash (“\”).

  \ooo
    数字の ooo (数字１個か､２個か３個)は挿入されるユニコード文字の為に 000–377 の範囲の８ビットの八進数の値(即ち､ U+000000–U+0000FF)を与える｡３桁の数字がこの範囲から溢れるか､最大限度に達すると､解析譜はその直前に停止する｡ユニコード文字の上位ビットは 0 になる｡ The digits ooo (one, two, or three of them) give a eight-bit octal value for the Unicode character that will be inserted, in the range 000–377 (i.e., the range U+000000–U+0000FF). The parser will stop just before this range overflows, or when the maximum of three digits is reached. The upper bits of the Unicode character will be 0.

  \x hh
    十六進数の hh (十六進数の一文字か二文字)は挿入されるユニコード文字の八ビット十六進数を与える｡ユニコード文字の上位ビットは 0 になる(即ち､文字は U+000000–U+0000FFの範囲になる)｡ The hexadecimal digits hh (one or two of them) give an eight-bit hexadecimal value for the Unicode character that will be inserted. The upper bits of the Unicode character will be 0 (i.e., the character will be in the range U+000000–U+0000FF).

  \u hhhh
    十六進数の hhhh (数字一個か､二個か､三個か､四個)は挿入されるユニコード文字の十六ビット十六進数の値を与える｡ユニコード文字の上位ビットは 0 になる(即ち､文字は U+000000–U+00FFFFの範囲になる)｡ The hexadecimal digits hhhh (one, two, three, or four of them) give a sixteen-bit hexadecimal value for the Unicode character that will be inserted. The upper bits of the Unicode character will be 0 (i.e., the character will be in the range U+000000–U+00FFFF).

  \U hhhhhhhh
    十六進数 hhhhhhhh (一文字から八文字)は挿入されるユニコード文字の為に２１ビット十六進数値を与え U+0000～U+10FFFF の範囲のユニコード文字になる｡この範囲の桁溢れか､八桁の最大値に達すると､その直前に解析譜は停止する｡ユニコード文字の上位ビットは 0 になる｡ The hexadecimal digits hhhhhhhh (one up to eight of them) give a twenty-one-bit hexadecimal value for the Unicode character that will be inserted, in the range U+000000–U+10FFFF. The parser will stop just before this range overflows, or when the maximum of eight digits is reached. The upper bits of the Unicode character will be 0.

    U+0000～U+10FFFF の範囲は将来の為に予約されている｡ The range U+010000–U+10FFFD is reserved for the future.

  波括弧の中に包まれた語では､上記の逆斜線改行以外は逆斜線置換は実行されない｡ Backslash substitution is not performed on words enclosed in braces, except for backslash-newline as described above.

[10] 注釈 Comments.
  もし Tcl の命令の最初の語の最初の文字がある筈の処に井桁記号 (“#”) が現れる場合､ 井桁記号とそれに続く語は次の改行迄注釈として取り扱われ無視される｡注釈文字は命令の最初の位置に現る時にのみ意味を有する｡ If a hash character (“#”) appears at a point where Tcl is expecting the first character of the first word of a command, then the hash character and the characters that follow it, up through the next newline, are treated as a comment and ignored. The comment character only has significance when it appears at the beginning of a command.

[11] 置換の順序 Order of substitution.
  それぞれの文字は､ Tcl 解釈実行機能により､命令を形成する語として厳格に一度だけ処理される｡譬えば､もし変数置換が起ると､その変数には更なる置換は遂行されない; その値は文言通りに挿入される｡もし､命令置換が起ると､入子になった命令は Tcl 解釈実行機能を再帰的に呼出して完全に処理される; 再帰呼出しを形成する以前の如何なる置換も､入子になった記述譜上の結果への追加的な置換も遂行される事はない｡ Each character is processed exactly once by the Tcl interpreter as part of creating the words of a command. For example, if variable substitution occurs then no further substitutions are performed on the value of the variable; the value is inserted into the word verbatim. If command substitution occurs then the nested command is processed entirely by the recursive call to the Tcl interpreter; no substitutions are performed before making the recursive call and no additional substitutions are performed on the result of the nested script.

  置換は左から右へ行われ､それぞれの置換は次の評価を試みる前に完全に評価される｡従ってこの様な並びでは Substitutions take place from left to right, and each substitution is evaluated completely before attempting to evaluate the next. Thus, a sequence like

      set y [set x 0][incr x][incr x]

  変数 y は常に値 012 に設定される｡ will always set the variable y to the value, 012.

[12] 置換と語の境界 Substitution and word boundaries.
  置換は､規則 [5]内で規定した引数の展開以外では､命令の語の境界には影響を与えない｡譬えば､変数置換の間､縦え変数の値が空白を含んでいても､変数の値全体が､一個の語の部分になる｡ Substitutions do not affect the word boundaries of a command, except for argument expansion as specified in rule [5]. For example, during variable substitution the entire value of the variable becomes part of a single word, even if the variable's value contains spaces.

### KEYWORDS

backslash, command, comment, script, substitution, variable
Copyright © 1993 The Regents of the University of California.
Copyright © 1994-1996 Sun Microsystems, Inc.