24.03.2013 Views

ModelSim SE User's Manual - Electrical and Computer Engineering

ModelSim SE User's Manual - Electrical and Computer Engineering

ModelSim SE User's Manual - Electrical and Computer Engineering

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

UM-476 20 - Tcl <strong>and</strong> macros (DO files)<br />

if comm<strong>and</strong> syntax<br />

<strong>ModelSim</strong> <strong>SE</strong> User’s <strong>Manual</strong><br />

\xhh The hexadecimal digits hh give the hexadecimal value of the<br />

character. Any number of digits may be present.<br />

Backslash substitution is not performed on words enclosed in braces, except for<br />

backslash-newline as described above.<br />

9 If a hash character ("#") appears at a point where Tcl is expecting the first character of<br />

the first word of a comm<strong>and</strong>, then the hash character <strong>and</strong> the characters that follow it, up<br />

through the next newline, are treated as a comment <strong>and</strong> ignored. The comment character<br />

only has significance when it appears at the beginning of a comm<strong>and</strong>.<br />

10 Each character is processed exactly once by the Tcl interpreter as part of creating the<br />

words of a comm<strong>and</strong>. For example, if variable substitution occurs then no further<br />

substitutions are performed on the value of the variable; the value is inserted into the<br />

word verbatim. If comm<strong>and</strong> substitution occurs then the nested comm<strong>and</strong> is processed<br />

entirely by the recursive call to the Tcl interpreter; no substitutions are performed before<br />

making the recursive call <strong>and</strong> no additional substitutions are performed on the result of<br />

the nested script.<br />

11 Substitutions do not affect the word boundaries of a comm<strong>and</strong>. For example, during<br />

variable substitution the entire value of the variable becomes part of a single word, even<br />

if the variable's value contains spaces.<br />

The Tcl if comm<strong>and</strong> executes scripts conditionally. Note that in the syntax below the "?"<br />

indicates an optional argument.<br />

Syntax<br />

if expr1 ?then? body1 elseif expr2 ?then? body2 elseif ... ?else? ?bodyN?<br />

Description<br />

The if comm<strong>and</strong> evaluates expr1 as an expression. The value of the expression must be a<br />

boolean (a numeric value, where 0 is false <strong>and</strong> anything else is true, or a string value such<br />

as true or yes for true <strong>and</strong> false or no for false); if it is true then body1 is executed by<br />

passing it to the Tcl interpreter. Otherwise expr2 is evaluated as an expression <strong>and</strong> if it is<br />

true then body2 is executed, <strong>and</strong> so on. If none of the expressions evaluates to true then<br />

bodyN is executed. The then <strong>and</strong> else arguments are optional "noise words" to make the<br />

comm<strong>and</strong> easier to read. There may be any number of elseif clauses, including zero. BodyN<br />

may also be omitted as long as else is omitted too. The return value from the comm<strong>and</strong> is<br />

the result of the body script that was executed, or an empty string if none of the expressions<br />

was non-zero <strong>and</strong> there was no bodyN.

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!