In this Topic Hide
An expression is a sequence of variable names, constants, operators and functions that can be evaluated to yield a result. Expressions are required by four commands: Let, Curve, Plot and Show and they are also used in braced substitutions) and if statements, while statements and for statements. This section describes expression syntax and how they are evaluated.
operators. Available operators are:
+ - * / ^ % |
< > == <= >= |
AND, OR, NOT, |
&& || ! |
& |
When calculating an expression like 3+4*5, the 4 is multiplied by 5 first then added to 3. The multiplication operator - '*' - is said to have higher precedence then the addition operator - '+'. The following lists all the operators in order of precedence:
( ) [ ] |
Unary - + NOT ! |
^ |
* / % |
+ - |
< > <= >= == |
AND && |
OR || |
& |
= |
, |
Functions are central to SIMetrix scripts. All functions return a value and take zero or more arguments. The sqrt function for example takes a single argument and returns its square root. So:
Let x = sqrt(16) |
Functions are of the form:
function_name( [ argument, ...] ) |
Function taking no arguments:
NetName() |
FFT( vout, 'Hanning') |
A braced substitution is an expression enclosed in curly braces '{' and '}'. When the script interpreter encounters a braced substitution, it evaluates the expression and substitutes the expression and the braces with the result of the evaluation - as if it had been typed in by the user. Braced substitutions are important because, with the exception of Let, Show, Plot and Curve, commands cannot accept expressions as arguments. For example, the Echo command displays in the message window the text following the Echo. If the command Echo x+2 was executed, the message x+2 would be displayed not the result of evaluating x+2. If instead the command was Echo { x+2 } the result of evaluating x+2 would be displayed.
If the expression inside the braces evaluates to a vector each element of the vector will be substituted. Note that the line length for commands is limited (although the limit is large - in excess of 2000 characters) so substituting vectors should be avoided unless it is known that the vector does not have many elements.
Braced substitutions may not be used in the control expression for conditional statements, while loops and for loops. For example, the following is not permitted
if {netname()} < 4.56 then |
let v = {netname()} |
if v < 4.56 then |
These are of the form
[ expression1, expression2, ...] |
Let v = [3, 5, 7] |
Let v = [3, 'Hello', 'World'] |
Let v = ['3', 'Hello', 'World'] |
Most functions and operators expect their arguments to be of a particular type. For example the + operator expects each side to be a numeric (real or complex) type and not a string. Conversely, the & operator which concatenates strings naturally expects a string on each side. The majority of functions also expect a particular type as arguments, although there are some that can accept any type.
In the event that the type presented is wrong, SIMetrix will attempt to convert the value presented to the correct type. To convert a numeric value to a string is straightforward, the value is simply represented in ASCII form to a reasonable precision. When a string is presented but a numeric value is required, the string is treated as if it were an expression and is evaluated. If the evaluation is successful and resolves to the correct type the result is used as the argument to the operator or function. If the evaluation fails for any reason an error message will be displayed.
An alias is a special type of string. Alias strings hold an expression which is always evaluated when used. The simulator outputs some of its data in alias form to save memory and simulation time. For example, the currents into subcircuit pins are calculated by adding the currents of all devices within the subcircuit connected to that pin. If its efficient to do so, this current is not calculated during simulation. Instead the expression to perform that calculation is stored as an alias so that it can be calculated if needed. Aliases may also be created using the MakeAlias command.
|