Initial commit of OpenSPARC T2 architecture model.
[OpenSPARC-T2-SAM] / sam-t2 / devtools / v9 / man / man3 / Tcl_ParseCommand.3
CommitLineData
920dae64
AT
1'\"
2'\" Copyright (c) 1997 Sun Microsystems, Inc.
3'\"
4'\" See the file "license.terms" for information on usage and redistribution
5'\" of this file, and for a DISCLAIMER OF ALL WARRANTIES.
6'\"
7'\" RCS: @(#) $Id: ParseCmd.3,v 1.10.2.1 2003/03/19 20:06:50 dgp Exp $
8'\"
9'\" The definitions below are for supplemental macros used in Tcl/Tk
10'\" manual entries.
11'\"
12'\" .AP type name in/out ?indent?
13'\" Start paragraph describing an argument to a library procedure.
14'\" type is type of argument (int, etc.), in/out is either "in", "out",
15'\" or "in/out" to describe whether procedure reads or modifies arg,
16'\" and indent is equivalent to second arg of .IP (shouldn't ever be
17'\" needed; use .AS below instead)
18'\"
19'\" .AS ?type? ?name?
20'\" Give maximum sizes of arguments for setting tab stops. Type and
21'\" name are examples of largest possible arguments that will be passed
22'\" to .AP later. If args are omitted, default tab stops are used.
23'\"
24'\" .BS
25'\" Start box enclosure. From here until next .BE, everything will be
26'\" enclosed in one large box.
27'\"
28'\" .BE
29'\" End of box enclosure.
30'\"
31'\" .CS
32'\" Begin code excerpt.
33'\"
34'\" .CE
35'\" End code excerpt.
36'\"
37'\" .VS ?version? ?br?
38'\" Begin vertical sidebar, for use in marking newly-changed parts
39'\" of man pages. The first argument is ignored and used for recording
40'\" the version when the .VS was added, so that the sidebars can be
41'\" found and removed when they reach a certain age. If another argument
42'\" is present, then a line break is forced before starting the sidebar.
43'\"
44'\" .VE
45'\" End of vertical sidebar.
46'\"
47'\" .DS
48'\" Begin an indented unfilled display.
49'\"
50'\" .DE
51'\" End of indented unfilled display.
52'\"
53'\" .SO
54'\" Start of list of standard options for a Tk widget. The
55'\" options follow on successive lines, in four columns separated
56'\" by tabs.
57'\"
58'\" .SE
59'\" End of list of standard options for a Tk widget.
60'\"
61'\" .OP cmdName dbName dbClass
62'\" Start of description of a specific option. cmdName gives the
63'\" option's name as specified in the class command, dbName gives
64'\" the option's name in the option database, and dbClass gives
65'\" the option's class in the option database.
66'\"
67'\" .UL arg1 arg2
68'\" Print arg1 underlined, then print arg2 normally.
69'\"
70'\" RCS: @(#) $Id: man.macros,v 1.4 2000/08/25 06:18:32 ericm Exp $
71'\"
72'\" # Set up traps and other miscellaneous stuff for Tcl/Tk man pages.
73.if t .wh -1.3i ^B
74.nr ^l \n(.l
75.ad b
76'\" # Start an argument description
77.de AP
78.ie !"\\$4"" .TP \\$4
79.el \{\
80. ie !"\\$2"" .TP \\n()Cu
81. el .TP 15
82.\}
83.ta \\n()Au \\n()Bu
84.ie !"\\$3"" \{\
85\&\\$1 \\fI\\$2\\fP (\\$3)
86.\".b
87.\}
88.el \{\
89.br
90.ie !"\\$2"" \{\
91\&\\$1 \\fI\\$2\\fP
92.\}
93.el \{\
94\&\\fI\\$1\\fP
95.\}
96.\}
97..
98'\" # define tabbing values for .AP
99.de AS
100.nr )A 10n
101.if !"\\$1"" .nr )A \\w'\\$1'u+3n
102.nr )B \\n()Au+15n
103.\"
104.if !"\\$2"" .nr )B \\w'\\$2'u+\\n()Au+3n
105.nr )C \\n()Bu+\\w'(in/out)'u+2n
106..
107.AS Tcl_Interp Tcl_CreateInterp in/out
108'\" # BS - start boxed text
109'\" # ^y = starting y location
110'\" # ^b = 1
111.de BS
112.br
113.mk ^y
114.nr ^b 1u
115.if n .nf
116.if n .ti 0
117.if n \l'\\n(.lu\(ul'
118.if n .fi
119..
120'\" # BE - end boxed text (draw box now)
121.de BE
122.nf
123.ti 0
124.mk ^t
125.ie n \l'\\n(^lu\(ul'
126.el \{\
127.\" Draw four-sided box normally, but don't draw top of
128.\" box if the box started on an earlier page.
129.ie !\\n(^b-1 \{\
130\h'-1.5n'\L'|\\n(^yu-1v'\l'\\n(^lu+3n\(ul'\L'\\n(^tu+1v-\\n(^yu'\l'|0u-1.5n\(ul'
131.\}
132.el \}\
133\h'-1.5n'\L'|\\n(^yu-1v'\h'\\n(^lu+3n'\L'\\n(^tu+1v-\\n(^yu'\l'|0u-1.5n\(ul'
134.\}
135.\}
136.fi
137.br
138.nr ^b 0
139..
140'\" # VS - start vertical sidebar
141'\" # ^Y = starting y location
142'\" # ^v = 1 (for troff; for nroff this doesn't matter)
143.de VS
144.if !"\\$2"" .br
145.mk ^Y
146.ie n 'mc \s12\(br\s0
147.el .nr ^v 1u
148..
149'\" # VE - end of vertical sidebar
150.de VE
151.ie n 'mc
152.el \{\
153.ev 2
154.nf
155.ti 0
156.mk ^t
157\h'|\\n(^lu+3n'\L'|\\n(^Yu-1v\(bv'\v'\\n(^tu+1v-\\n(^Yu'\h'-|\\n(^lu+3n'
158.sp -1
159.fi
160.ev
161.\}
162.nr ^v 0
163..
164'\" # Special macro to handle page bottom: finish off current
165'\" # box/sidebar if in box/sidebar mode, then invoked standard
166'\" # page bottom macro.
167.de ^B
168.ev 2
169'ti 0
170'nf
171.mk ^t
172.if \\n(^b \{\
173.\" Draw three-sided box if this is the box's first page,
174.\" draw two sides but no top otherwise.
175.ie !\\n(^b-1 \h'-1.5n'\L'|\\n(^yu-1v'\l'\\n(^lu+3n\(ul'\L'\\n(^tu+1v-\\n(^yu'\h'|0u'\c
176.el \h'-1.5n'\L'|\\n(^yu-1v'\h'\\n(^lu+3n'\L'\\n(^tu+1v-\\n(^yu'\h'|0u'\c
177.\}
178.if \\n(^v \{\
179.nr ^x \\n(^tu+1v-\\n(^Yu
180\kx\h'-\\nxu'\h'|\\n(^lu+3n'\ky\L'-\\n(^xu'\v'\\n(^xu'\h'|0u'\c
181.\}
182.bp
183'fi
184.ev
185.if \\n(^b \{\
186.mk ^y
187.nr ^b 2
188.\}
189.if \\n(^v \{\
190.mk ^Y
191.\}
192..
193'\" # DS - begin display
194.de DS
195.RS
196.nf
197.sp
198..
199'\" # DE - end display
200.de DE
201.fi
202.RE
203.sp
204..
205'\" # SO - start of list of standard options
206.de SO
207.SH "STANDARD OPTIONS"
208.LP
209.nf
210.ta 5.5c 11c
211.ft B
212..
213'\" # SE - end of list of standard options
214.de SE
215.fi
216.ft R
217.LP
218See the \\fBoptions\\fR manual entry for details on the standard options.
219..
220'\" # OP - start of full description for a single option
221.de OP
222.LP
223.nf
224.ta 4c
225Command-Line Name: \\fB\\$1\\fR
226Database Name: \\fB\\$2\\fR
227Database Class: \\fB\\$3\\fR
228.fi
229.IP
230..
231'\" # CS - begin code excerpt
232.de CS
233.RS
234.nf
235.ta .25i .5i .75i 1i
236..
237'\" # CE - end code excerpt
238.de CE
239.fi
240.RE
241..
242.de UL
243\\$1\l'|0\(ul'\\$2
244..
245.TH Tcl_ParseCommand 3 8.3 Tcl "Tcl Library Procedures"
246.BS
247.SH NAME
248Tcl_ParseCommand, Tcl_ParseExpr, Tcl_ParseBraces, Tcl_ParseQuotedString, Tcl_ParseVarName, Tcl_ParseVar, Tcl_FreeParse, Tcl_EvalTokens, Tcl_EvalTokensStandard \- parse Tcl scripts and expressions
249.SH SYNOPSIS
250.nf
251\fB#include <tcl.h>\fR
252.sp
253int
254\fBTcl_ParseCommand\fR(\fIinterp, string, numBytes, nested, parsePtr\fR)
255.sp
256int
257\fBTcl_ParseExpr\fR(\fIinterp, string, numBytes, parsePtr\fR)
258.sp
259int
260\fBTcl_ParseBraces\fR(\fIinterp, string, numBytes, parsePtr, append, termPtr\fR)
261.sp
262int
263\fBTcl_ParseQuotedString\fR(\fIinterp, string, numBytes, parsePtr, append, termPtr\fR)
264.sp
265int
266\fBTcl_ParseVarName\fR(\fIinterp, string, numBytes, parsePtr, append\fR)
267.sp
268CONST char *
269\fBTcl_ParseVar\fR(\fIinterp, string, termPtr\fR)
270.sp
271\fBTcl_FreeParse\fR(\fIusedParsePtr\fR)
272.sp
273Tcl_Obj *
274\fBTcl_EvalTokens\fR(\fIinterp, tokenPtr, numTokens\fR)
275.sp
276int
277\fBTcl_EvalTokensStandard\fR(\fIinterp, tokenPtr, numTokens\fR)
278.SH ARGUMENTS
279.AS Tcl_Interp *usedParsePtr
280.AP Tcl_Interp *interp out
281For procedures other than \fBTcl_FreeParse\fR, \fBTcl_EvalTokens\fR
282and \fBTcl_EvalTokensStandard\fR, used only for error reporting;
283if NULL, then no error messages are left after errors.
284For \fBTcl_EvalTokens\fR and \fBTcl_EvalTokensStandard\fR,
285determines the context for evaluating the
286script and also is used for error reporting; must not be NULL.
287.AP "CONST char" *string in
288Pointer to first character in string to parse.
289.AP int numBytes in
290Number of bytes in \fIstring\fR, not including any terminating null
291character. If less than 0 then the script consists of all characters
292in \fIstring\fR up to the first null character.
293.AP int nested in
294Non-zero means that the script is part of a command substitution so an
295unquoted close bracket should be treated as a command terminator. If zero,
296close brackets have no special meaning.
297.AP int append in
298Non-zero means that \fI*parsePtr\fR already contains valid tokens; the new
299tokens should be appended to those already present. Zero means that
300\fI*parsePtr\fR is uninitialized; any information in it is ignored.
301This argument is normally 0.
302.AP Tcl_Parse *parsePtr out
303Points to structure to fill in with information about the parsed
304command, expression, variable name, etc.
305Any previous information in this structure
306is ignored, unless \fIappend\fR is non-zero in a call to
307\fBTcl_ParseBraces\fR, \fBTcl_ParseQuotedString\fR,
308or \fBTcl_ParseVarName\fR.
309.AP "CONST char" **termPtr out
310If not NULL, points to a location where
311\fBTcl_ParseBraces\fR, \fBTcl_ParseQuotedString\fR, and
312\fBTcl_ParseVar\fR will store a pointer to the character
313just after the terminating character (the close-brace, the last
314character of the variable name, or the close-quote (respectively))
315if the parse was successful.
316.AP Tcl_Parse *usedParsePtr in
317Points to structure that was filled in by a previous call to
318\fBTcl_ParseCommand\fR, \fBTcl_ParseExpr\fR, \fBTcl_ParseVarName\fR, etc.
319.BE
320
321.SH DESCRIPTION
322.PP
323These procedures parse Tcl commands or portions of Tcl commands such as
324expressions or references to variables.
325Each procedure takes a pointer to a script (or portion thereof)
326and fills in the structure pointed to by \fIparsePtr\fR
327with a collection of tokens describing the information that was parsed.
328The procedures normally return \fBTCL_OK\fR.
329However, if an error occurs then they return \fBTCL_ERROR\fR,
330leave an error message in \fIinterp's\fR result
331(if \fIinterp\fR is not NULL),
332and leave nothing in \fIparsePtr\fR.
333.PP
334\fBTcl_ParseCommand\fR is a procedure that parses Tcl
335scripts. Given a pointer to a script, it
336parses the first command from the script. If the command was parsed
337successfully, \fBTcl_ParseCommand\fR returns \fBTCL_OK\fR and fills in the
338structure pointed to by \fIparsePtr\fR with information about the
339structure of the command (see below for details).
340If an error occurred in parsing the command then
341\fBTCL_ERROR\fR is returned, an error message is left in \fIinterp\fR's
342result, and no information is left at \fI*parsePtr\fR.
343.PP
344\fBTcl_ParseExpr\fR parses Tcl expressions.
345Given a pointer to a script containing an expression,
346\fBTcl_ParseCommand\fR parses the expression.
347If the expression was parsed successfully,
348\fBTcl_ParseExpr\fR returns \fBTCL_OK\fR and fills in the
349structure pointed to by \fIparsePtr\fR with information about the
350structure of the expression (see below for details).
351If an error occurred in parsing the command then
352\fBTCL_ERROR\fR is returned, an error message is left in \fIinterp\fR's
353result, and no information is left at \fI*parsePtr\fR.
354.PP
355\fBTcl_ParseBraces\fR parses a string or command argument
356enclosed in braces such as
357\fB{hello}\fR or \fB{string \\t with \\t tabs}\fR
358from the beginning of its argument \fIstring\fR.
359The first character of \fIstring\fR must be \fB{\fR.
360If the braced string was parsed successfully,
361\fBTcl_ParseBraces\fR returns \fBTCL_OK\fR,
362fills in the structure pointed to by \fIparsePtr\fR
363with information about the structure of the string
364(see below for details),
365and stores a pointer to the character just after the terminating \fB}\fR
366in the location given by \fI*termPtr\fR.
367If an error occurs while parsing the string
368then \fBTCL_ERROR\fR is returned,
369an error message is left in \fIinterp\fR's result,
370and no information is left at \fI*parsePtr\fR or \fI*termPtr\fR.
371.PP
372\fBTcl_ParseQuotedString\fR parses a double-quoted string such as
373\fB"sum is [expr $a+$b]"\fR
374from the beginning of the argument \fIstring\fR.
375The first character of \fIstring\fR must be \fB"\fR.
376If the double-quoted string was parsed successfully,
377\fBTcl_ParseQuotedString\fR returns \fBTCL_OK\fR,
378fills in the structure pointed to by \fIparsePtr\fR
379with information about the structure of the string
380(see below for details),
381and stores a pointer to the character just after the terminating \fB"\fR
382in the location given by \fI*termPtr\fR.
383If an error occurs while parsing the string
384then \fBTCL_ERROR\fR is returned,
385an error message is left in \fIinterp\fR's result,
386and no information is left at \fI*parsePtr\fR or \fI*termPtr\fR.
387.PP
388\fBTcl_ParseVarName\fR parses a Tcl variable reference such as
389\fB$abc\fR or \fB$x([expr $index + 1])\fR from the beginning of its
390\fIstring\fR argument.
391The first character of \fIstring\fR must be \fB$\fR.
392If a variable name was parsed successfully, \fBTcl_ParseVarName\fR
393returns \fBTCL_OK\fR and fills in the structure pointed to by
394\fIparsePtr\fR with information about the structure of the variable name
395(see below for details). If an error
396occurs while parsing the command then \fBTCL_ERROR\fR is returned, an
397error message is left in \fIinterp\fR's result (if \fIinterp\fR isn't
398NULL), and no information is left at \fI*parsePtr\fR.
399.PP
400\fBTcl_ParseVar\fR parse a Tcl variable reference such as \fB$abc\fR
401or \fB$x([expr $index + 1])\fR from the beginning of its \fIstring\fR
402argument. The first character of \fIstring\fR must be \fB$\fR. If
403the variable name is parsed successfully, \fBTcl_ParseVar\fR returns a
404pointer to the string value of the variable. If an error occurs while
405parsing, then NULL is returned and an error message is left in
406\fIinterp\fR's result.
407.PP
408The information left at \fI*parsePtr\fR
409by \fBTcl_ParseCommand\fR, \fBTcl_ParseExpr\fR, \fBTcl_ParseBraces\fR,
410\fBTcl_ParseQuotedString\fR, and \fBTcl_ParseVarName\fR
411may include dynamically allocated memory.
412If these five parsing procedures return \fBTCL_OK\fR
413then the caller must invoke \fBTcl_FreeParse\fR to release
414the storage at \fI*parsePtr\fR.
415These procedures ignore any existing information in
416\fI*parsePtr\fR (unless \fIappend\fR is non-zero),
417so if repeated calls are being made to any of them
418then \fBTcl_FreeParse\fR must be invoked once after each call.
419.PP
420\fBTcl_EvalTokensStandard\fR evaluates a sequence of parse tokens from
421a Tcl_Parse structure. The tokens typically consist
422of all the tokens in a word or all the tokens that make up the index for
423a reference to an array variable. \fBTcl_EvalTokensStandard\fR performs the
424substitutions requested by the tokens and concatenates the
425resulting values.
426The return value from \fBTcl_EvalTokensStandard\fR is a Tcl completion
427code with one of the values \fBTCL_OK\fR, \fBTCL_ERROR\fR,
428\fBTCL_RETURN\fR, \fBTCL_BREAK\fR, or \fBTCL_CONTINUE\fR, or possibly
429some other integer value originating in an extension.
430In addition, a result value or error message is left in \fIinterp\fR's
431result; it can be retrieved using \fBTcl_GetObjResult\fR.
432.PP
433\fBTcl_EvalTokens\fR differs from \fBTcl_EvalTokensStandard\fR only in
434the return convention used: it returns the result in a new Tcl_Obj.
435The reference count of the object returned as result has been
436incremented, so the caller must
437invoke \fBTcl_DecrRefCount\fR when it is finished with the object.
438If an error or other exception occurs while evaluating the tokens
439(such as a reference to a non-existent variable) then the return value
440is NULL and an error message is left in \fIinterp\fR's result. The use
441of \fBTcl_EvalTokens\fR is deprecated.
442
443.SH "TCL_PARSE STRUCTURE"
444.PP
445\fBTcl_ParseCommand\fR, \fBTcl_ParseExpr\fR, \fBTcl_ParseBraces\fR,
446\fBTcl_ParseQuotedString\fR, and \fBTcl_ParseVarName\fR
447return parse information in two data structures, Tcl_Parse and Tcl_Token:
448.CS
449typedef struct Tcl_Parse {
450 CONST char *\fIcommentStart\fR;
451 int \fIcommentSize\fR;
452 CONST char *\fIcommandStart\fR;
453 int \fIcommandSize\fR;
454 int \fInumWords\fR;
455 Tcl_Token *\fItokenPtr\fR;
456 int \fInumTokens\fR;
457 ...
458} Tcl_Parse;
459
460typedef struct Tcl_Token {
461 int \fItype\fR;
462 CONST char *\fIstart\fR;
463 int \fIsize\fR;
464 int \fInumComponents\fR;
465} Tcl_Token;
466.CE
467.PP
468The first five fields of a Tcl_Parse structure
469are filled in only by \fBTcl_ParseCommand\fR.
470These fields are not used by the other parsing procedures.
471.PP
472\fBTcl_ParseCommand\fR fills in a Tcl_Parse structure
473with information that describes one Tcl command and any comments that
474precede the command.
475If there are comments,
476the \fIcommentStart\fR field points to the \fB#\fR character that begins
477the first comment and \fIcommentSize\fR indicates the number of bytes
478in all of the comments preceding the command, including the newline
479character that terminates the last comment.
480If the command is not preceded by any comments, \fIcommentSize\fR is 0.
481\fBTcl_ParseCommand\fR also sets the \fIcommandStart\fR field
482to point to the first character of the first
483word in the command (skipping any comments and leading space) and
484\fIcommandSize\fR gives the total number of bytes in the command,
485including the character pointed to by \fIcommandStart\fR up to and
486including the newline, close bracket, or semicolon character that
487terminates the command. The \fInumWords\fR field gives the
488total number of words in the command.
489.PP
490All parsing procedures set the remaining fields,
491\fItokenPtr\fR and \fInumTokens\fR.
492The \fItokenPtr\fR field points to the first in an array of Tcl_Token
493structures that describe the components of the entity being parsed.
494The \fInumTokens\fR field gives the total number of tokens
495present in the array.
496Each token contains four fields.
497The \fItype\fR field selects one of several token types
498that are described below. The \fIstart\fR field
499points to the first character in the token and the \fIsize\fR field
500gives the total number of characters in the token. Some token types,
501such as \fBTCL_TOKEN_WORD\fR and \fBTCL_TOKEN_VARIABLE\fR, consist of
502several component tokens, which immediately follow the parent token;
503the \fInumComponents\fR field describes how many of these there are.
504The \fItype\fR field has one of the following values:
505.TP 20
506\fBTCL_TOKEN_WORD\fR
507This token ordinarily describes one word of a command
508but it may also describe a quoted or braced string in an expression.
509The token describes a component of the script that is
510the result of concatenating together a sequence of subcomponents,
511each described by a separate subtoken.
512The token starts with the first non-blank
513character of the component (which may be a double-quote or open brace)
514and includes all characters in the component up to but not including the
515space, semicolon, close bracket, close quote, or close brace that
516terminates the component. The \fInumComponents\fR field counts the total
517number of sub-tokens that make up the word, including sub-tokens
518of \fBTCL_TOKEN_VARIABLE\fR and \fBTCL_TOKEN_BS\fR tokens.
519.TP
520\fBTCL_TOKEN_SIMPLE_WORD\fR
521This token has the same meaning as \fBTCL_TOKEN_WORD\fR, except that
522the word is guaranteed to consist of a single \fBTCL_TOKEN_TEXT\fR
523sub-token. The \fInumComponents\fR field is always 1.
524.TP
525\fBTCL_TOKEN_TEXT\fR
526The token describes a range of literal text that is part of a word.
527The \fInumComponents\fR field is always 0.
528.TP
529\fBTCL_TOKEN_BS\fR
530The token describes a backslash sequence such as \fB\en\fR or \fB\e0xa3\fR.
531The \fInumComponents\fR field is always 0.
532.TP
533\fBTCL_TOKEN_COMMAND\fR
534The token describes a command whose result result must be substituted into
535the word. The token includes the square brackets that surround the
536command. The \fInumComponents\fR field is always 0 (the nested command
537is not parsed; call \fBTcl_ParseCommand\fR recursively if you want to
538see its tokens).
539.TP
540\fBTCL_TOKEN_VARIABLE\fR
541The token describes a variable substitution, including the
542\fB$\fR, variable name, and array index (if there is one) up through the
543close parenthesis that terminates the index. This token is followed
544by one or more additional tokens that describe the variable name and
545array index. If \fInumComponents\fR is 1 then the variable is a
546scalar and the next token is a \fBTCL_TOKEN_TEXT\fR token that gives the
547variable name. If \fInumComponents\fR is greater than 1 then the
548variable is an array: the first sub-token is a \fBTCL_TOKEN_TEXT\fR
549token giving the array name and the remaining sub-tokens are
550\fBTCL_TOKEN_TEXT\fR, \fBTCL_TOKEN_BS\fR, \fBTCL_TOKEN_COMMAND\fR, and
551\fBTCL_TOKEN_VARIABLE\fR tokens that must be concatenated to produce the
552array index. The \fInumComponents\fR field includes nested sub-tokens
553that are part of \fBTCL_TOKEN_VARIABLE\fR tokens in the array index.
554.TP
555\fBTCL_TOKEN_SUB_EXPR\fR
556The token describes one subexpression of an expression
557(or an entire expression).
558A subexpression may consist of a value
559such as an integer literal, variable substitution,
560or parenthesized subexpression;
561it may also consist of an operator and its operands.
562The token starts with the first non-blank character of the subexpression
563up to but not including the space, brace, close-paren, or bracket
564that terminates the subexpression.
565This token is followed by one or more additional tokens
566that describe the subexpression.
567If the first sub-token after the \fBTCL_TOKEN_SUB_EXPR\fR token
568is a \fBTCL_TOKEN_OPERATOR\fR token,
569the subexpression consists of an operator and its token operands.
570If the operator has no operands, the subexpression consists of
571just the \fBTCL_TOKEN_OPERATOR\fR token.
572Each operand is described by a \fBTCL_TOKEN_SUB_EXPR\fR token.
573Otherwise, the subexpression is a value described by
574one of the token types \fBTCL_TOKEN_WORD\fR, \fBTCL_TOKEN_TEXT\fR,
575\fBTCL_TOKEN_BS\fR, \fBTCL_TOKEN_COMMAND\fR,
576\fBTCL_TOKEN_VARIABLE\fR, and \fBTCL_TOKEN_SUB_EXPR\fR.
577The \fInumComponents\fR field
578counts the total number of sub-tokens that make up the subexpression;
579this includes the sub-tokens for any nested \fBTCL_TOKEN_SUB_EXPR\fR tokens.
580.TP
581\fBTCL_TOKEN_OPERATOR\fR
582The token describes one operator of an expression
583such as \fB&&\fR or \fBhypot\fR.
584An \fBTCL_TOKEN_OPERATOR\fR token is always preceded by a
585\fBTCL_TOKEN_SUB_EXPR\fR token
586that describes the operator and its operands;
587the \fBTCL_TOKEN_SUB_EXPR\fR token's \fInumComponents\fR field
588can be used to determine the number of operands.
589A binary operator such as \fB*\fR
590is followed by two \fBTCL_TOKEN_SUB_EXPR\fR tokens
591that describe its operands.
592A unary operator like \fB-\fR
593is followed by a single \fBTCL_TOKEN_SUB_EXPR\fR token
594for its operand.
595If the operator is a math function such as \fBlog10\fR,
596the \fBTCL_TOKEN_OPERATOR\fR token will give its name and
597the following \fBTCL_TOKEN_SUB_EXPR\fR tokens will describe
598its operands;
599if there are no operands (as with \fBrand\fR),
600no \fBTCL_TOKEN_SUB_EXPR\fR tokens follow.
601There is one trinary operator, \fB?\fR,
602that appears in if-then-else subexpressions
603such as \fIx\fB?\fIy\fB:\fIz\fR;
604in this case, the \fB?\fR \fBTCL_TOKEN_OPERATOR\fR token
605is followed by three \fBTCL_TOKEN_SUB_EXPR\fR tokens for the operands
606\fIx\fR, \fIy\fR, and \fIz\fR.
607The \fInumComponents\fR field for a \fBTCL_TOKEN_OPERATOR\fR token
608is always 0.
609.PP
610After \fBTcl_ParseCommand\fR returns, the first token pointed to by
611the \fItokenPtr\fR field of the
612Tcl_Parse structure always has type \fBTCL_TOKEN_WORD\fR or
613\fBTCL_TOKEN_SIMPLE_WORD\fR. It is followed by the sub-tokens
614that must be concatenated to produce the value of that word.
615The next token is the \fBTCL_TOKEN_WORD\fR or \fBTCL_TOKEN_SIMPLE_WORD\fR
616token for the second word, followed by sub-tokens for that
617word, and so on until all \fInumWords\fR have been accounted
618for.
619.PP
620After \fBTcl_ParseExpr\fR returns, the first token pointed to by
621the \fItokenPtr\fR field of the
622Tcl_Parse structure always has type \fBTCL_TOKEN_SUB_EXPR\fR.
623It is followed by the sub-tokens that must be evaluated
624to produce the value of the expression.
625Only the token information in the Tcl_Parse structure
626is modified: the \fIcommentStart\fR, \fIcommentSize\fR,
627\fIcommandStart\fR, and \fIcommandSize\fR fields are not modified
628by \fBTcl_ParseExpr\fR.
629.PP
630After \fBTcl_ParseBraces\fR returns,
631the array of tokens pointed to by the \fItokenPtr\fR field of the
632Tcl_Parse structure will contain a single \fBTCL_TOKEN_TEXT\fR token
633if the braced string does not contain any backslash-newlines.
634If the string does contain backslash-newlines,
635the array of tokens will contain one or more
636\fBTCL_TOKEN_TEXT\fR or \fBTCL_TOKEN_BS\fR sub-tokens
637that must be concatenated to produce the value of the string.
638If the braced string was just \fB{}\fR
639(that is, the string was empty),
640the single \fBTCL_TOKEN_TEXT\fR token will have a \fIsize\fR field
641containing zero;
642this ensures that at least one token appears
643to describe the braced string.
644Only the token information in the Tcl_Parse structure
645is modified: the \fIcommentStart\fR, \fIcommentSize\fR,
646\fIcommandStart\fR, and \fIcommandSize\fR fields are not modified
647by \fBTcl_ParseBraces\fR.
648.PP
649After \fBTcl_ParseQuotedString\fR returns,
650the array of tokens pointed to by the \fItokenPtr\fR field of the
651Tcl_Parse structure depends on the contents of the quoted string.
652It will consist of one or more \fBTCL_TOKEN_TEXT\fR, \fBTCL_TOKEN_BS\fR,
653\fBTCL_TOKEN_COMMAND\fR, and \fBTCL_TOKEN_VARIABLE\fR sub-tokens.
654The array always contains at least one token;
655for example, if the argument \fIstring\fR is empty,
656the array returned consists of a single \fBTCL_TOKEN_TEXT\fR token
657with a zero \fIsize\fR field.
658Only the token information in the Tcl_Parse structure
659is modified: the \fIcommentStart\fR, \fIcommentSize\fR,
660\fIcommandStart\fR, and \fIcommandSize\fR fields are not modified.
661.PP
662After \fBTcl_ParseVarName\fR returns, the first token pointed to by
663the \fItokenPtr\fR field of the
664Tcl_Parse structure always has type \fBTCL_TOKEN_VARIABLE\fR. It
665is followed by the sub-tokens that make up the variable name as
666described above. The total length of the variable name is
667contained in the \fIsize\fR field of the first token.
668As in \fBTcl_ParseExpr\fR,
669only the token information in the Tcl_Parse structure
670is modified by \fBTcl_ParseVarName\fR:
671the \fIcommentStart\fR, \fIcommentSize\fR,
672\fIcommandStart\fR, and \fIcommandSize\fR fields are not modified.
673.PP
674All of the character pointers in the
675Tcl_Parse and Tcl_Token structures refer
676to characters in the \fIstring\fR argument passed to
677\fBTcl_ParseCommand\fR, \fBTcl_ParseExpr\fR, \fBTcl_ParseBraces\fR,
678\fBTcl_ParseQuotedString\fR, and \fBTcl_ParseVarName\fR.
679.PP
680There are additional fields in the Tcl_Parse structure after the
681\fInumTokens\fR field, but these are for the private use of
682\fBTcl_ParseCommand\fR, \fBTcl_ParseExpr\fR, \fBTcl_ParseBraces\fR,
683\fBTcl_ParseQuotedString\fR, and \fBTcl_ParseVarName\fR; they should not be
684referenced by code outside of these procedures.
685
686.SH KEYWORDS
687backslash substitution, braces, command, expression, parse, token, variable substitution