Difference between revisions of "Expression Syntax"
Jump to navigation
Jump to search
Line 51: | Line 51: | ||
== Supported Functions == | == Supported Functions == | ||
[[NairnFEAMPM]] and [[ | The following numeric functions are supported in both [[NairnFEAMPM]] and [[NairnFEAMPMViz]]: | ||
<ul> | <ul> | ||
Line 60: | Line 60: | ||
<li><code>acos()</code> - inverse cosine with result in radians</li> | <li><code>acos()</code> - inverse cosine with result in radians</li> | ||
<li><code>atan()</code> - inverse tangent with result in radians</li> | <li><code>atan()</code> - inverse tangent with result in radians</li> | ||
<li><code>sinh()</code> - hyperbolic sine</li> | |||
<li><code>cosh()</code> - hyperbolic cosine</li> | |||
<li><code>tanh()</code> - hyperbolic tangent</li> | |||
<li><code>exp()</code> - exponential</li> | <li><code>exp()</code> - exponential</li> | ||
<li><code>log()</code> - natural log</li> | <li><code>log()</code> - natural log</li> | ||
<li><code>log10()</code> - log base 10</li> | |||
<li><code>sqrt()</code> - square root</li> | <li><code>sqrt()</code> - square root</li> | ||
<li><code>abs()</code> - absolute value</li> | <li><code>abs()</code> - absolute value</li> | ||
Line 68: | Line 72: | ||
</ul> | </ul> | ||
[[NairnFEAMPM]] | The following numeric functions are support only in [[NairnFEAMPM]]: | ||
<ul> | <ul> | ||
<li><code>sign()</code> - 1 if argument is positive or 0 if it is negative</li> | <li><code>sign()</code> - 1 if argument is positive or 0 if it is negative</li> | ||
<li><code>erf()</code> - error function.</li> | <li><code>erf()</code> - error function.</li> | ||
Line 80: | Line 80: | ||
</ul> | </ul> | ||
[[NairnFEAMPM]] | The following string functions are support only in [[NairnFEAMPM]]: | ||
<ul> | <ul> |
Revision as of 18:51, 29 August 2013
The scripting language allows expressions to do calculations with variables.
Expression Definition
An expression combines any number of numbers, strings, variables, and functions with operators. An expression evaluates to a numeric or string value. The general, recursive definition of an expression is:
[EXPRESSION] = [sign] [ATOMIC] [op] [ATOMIC] [op] [ATOMIC] ... [op] [ATOMIC]
where
- [sign] is an optional leading sign of + or -
- [op] are operators that determine how the [ATOMIC]'s are combined. The options are:
- + for addition
- - for subtraction
- * for multiplication
- / for division
- ^ for raising to a power
- & for string concatenation
- [ATOMIC] are the elements that are combined. The possible atomics are:
- An unsigned number (23, 2.234, 3e2, 4.56e-3, ...)
- A variable (such as #varname, #x[2], #z[#i][#j], etc.) and the value of the variable is used. The variable must have been previously defined.
- Text in quotes ("some text") and the value is the text after the quotes are removed.
- Unquoted text and the value is all the text between the operators after all spaces have been removed. To include spaces in text [ATOMIC]'s, the text must be quoted.
- Another expression in parenthesis or ([EXPRESSION]) and the value of the [ATOMIC] is the value of the included expression.
- A function of an expression (such as sin([EXPRESSION])) and the value of the [ATOMIC] is the value of the function applied to the value of the expression. The allowed functions are listed below.
- An "at" expression beginning in an @ sign and containing specific items separated by periods, such as "@key.TopLeft.x" to evaluate to the x value of the keypoint named TopLeft.
- The available "at" expressions are defined elsewhere (for example, see Keypoint Command and Path Command).
- Any of the period-delimited items can be a variable (such as @key.#kname.x) and the contents of #kname will replace that item in the expression.
- Variables used as items can only be a single variable and not an expression. They also cannot be an array variable with a variable index (e.g., it can be#n[3] but cannot be #n[#i]). Hint: if you need to index an array with a variable, you can define simple variable first (e.g., #ni=#n[#i]) and then use that in an expression (e.g., @key.#ni.y).
Supported Functions
The following numeric functions are supported in both NairnFEAMPM and NairnFEAMPMViz:
sin()
- sine of argument in radianscos()
- cosine of argument in radianstan()
- tangent of argument in radiansasin()
- inverse sine with result in radiansacos()
- inverse cosine with result in radiansatan()
- inverse tangent with result in radianssinh()
- hyperbolic sinecosh()
- hyperbolic cosinetanh()
- hyperbolic tangentexp()
- exponentiallog()
- natural loglog10()
- log base 10sqrt()
- square rootabs()
- absolute valueint()
- integer partrand()
- a random number between 0 and the argument.
The following numeric functions are support only in NairnFEAMPM:
sign()
- 1 if argument is positive or 0 if it is negativeerf()
- error function.erfc()
- error function complement.
The following string functions are support only in NairnFEAMPM:
length()
- number of characters in a string.words()
- number of words in a string.firstWord()
- first word in a string.lastWord()
- last word in a string.removeFirstWord()
- string with first word removed.removeLastWord()
- string with last word removed.chars(c1\c2\string)
- returns charactersc1
toc2
ofstring
(the first character is character 1).c1
defaults to 1 if omitted (or less than 0) andc2
defaults to length ofstring
(if omitted or larger). Thuschar(c1\string)
gets character 1 to the end andchar(\c2\string)
gets character 1 throughc2
.word(w1\string)
- returns wordw1
ofstring
. Ifw1
is less than 1 or greater then number of words instring
, an empty string is returned.offset(s1\c1\string)
- returns offset of strings1
in string at or after characterc1
(the first character is character 1) or returns 0 if strings1
is not found. c1 can be omitted to finds1
any place instring
. The search is case insensitive.replace(s1\s2\string)
- returns string where all occurrences of strings1
instring
are replaced with strings2
.s2
may be omitted to delete all occurrences of strings1
.upperCase()
- convert string to upper case.lowerCase()
- convert string to lower case.titleCase()
- convert to string with capitalized words.
NairnFEAMPMViz only supports min(), max(), floor(), ceil(), neg()
Notes
- An assignment command can be combined with an operator as in
#x [op] = [EXPRESSION]
which is equivalent to
#x = #x [op] ([EXPRESSION])
provided the variable is already a defined variable. It is an error if the variable has not previously been defined.