Difference between revisions of "Expression Syntax"

From OSUPDOCS
Jump to navigation Jump to search
Line 55: Line 55:


<ul>
<ul>
<li><code>sin()</code> - sine of argument in radians</li>
<li><tt>sin()</tt> - sine of argument in radians</li>
<li><code>cos()</code> - cosine of argument in radians</li>
<li><tt>cos()</tt> - cosine of argument in radians</li>
<li><code>tan()</code> - tangent of argument in radians</li>
<li><tt>tan()</tt> - tangent of argument in radians</li>
<li><code>asin()</code> - inverse sine with result in radians</li>
<li><tt>asin()</tt> - inverse sine with result in radians</li>
<li><code>acos()</code> - inverse cosine with result in radians</li>
<li><tt>acos()</tt> - inverse cosine with result in radians</li>
<li><code>atan()</code> - inverse tangent with result in radians</li>
<li><tt>atan()</tt> - inverse tangent with result in radians</li>
<li><code>sinh()</code> - hyperbolic sine</li>
<li><tt>sinh()</tt> - hyperbolic sine</li>
<li><code>cosh()</code> - hyperbolic cosine</li>
<li><tt>cosh()</tt> - hyperbolic cosine</li>
<li><code>tanh()</code> - hyperbolic tangent</li>
<li><tt>tanh()</tt> - hyperbolic tangent</li>
<li><code>exp()</code> - exponential</li>
<li><tt>exp()</tt> - exponential</li>
<li><code>log()</code> - natural log</li>
<li><tt>log()</tt> - natural log</li>
<li><code>log10()</code> - log base 10</li>
<li><tt>log10()</tt> - log base 10</li>
<li><code>sqrt()</code> - square root</li>
<li><tt>sqrt()</tt> - square root</li>
<li><code>abs()</code> - absolute value</li>
<li><tt>abs()</tt> - absolute value</li>
<li><code>int()</code> - integer part</li>
<li><tt>int()</tt> - integer part</li>
<li><code>sign()</code> - 1 if argument is positive or 0 if it is negative</li>
<li><tt>sign()</tt> - 1 if argument is positive or 0 if it is negative</li>
<li><code>rand()</code> - a random number between 0 and the argument.</li>
<li><tt>rand()</tt> - a random number between 0 and the argument.</li>
</ul>
</ul>


Line 77: Line 77:


<ul>
<ul>
<li><code>erf()</code> - error function.</li>
<li><tt>erf()</tt> - error function.</li>
<li><code>erfc()</code> - error function complement.</li>
<li><tt>erfc()</tt> - error function complement.</li>
</ul>
</ul>


Line 84: Line 84:


<ul>
<ul>
<li><code>length()</code> - number of characters in a string.</li>
<li><tt>length()</tt> - number of characters in a string.</li>
<li><code>words()</code> - number of words in a string.</li>
<li><tt>words()</tt> - number of words in a string.</li>
<li><code>firstWord()</code> - first word in a string.</li>
<li><tt>firstWord()</tt> - first word in a string.</li>
<li><code>lastWord()</code> - last word in a string.</li>
<li><tt>lastWord()</tt> - last word in a string.</li>
<li><code>removeFirstWord()</code> - string with first word removed.</li>
<li><tt>removeFirstWord()</tt> - string with first word removed.</li>
<li><code>removeLastWord()</code> - string with last word removed.</li>
<li><tt>removeLastWord()</tt> - string with last word removed.</li>
<li><code>chars(c1\c2\string)</code> - returns characters <code>c1</code> to <code>c2</code> of <code>string</code> (the first character is character 1). <code>c1</code> defaults to 1 if omitted (or less than 0) and <code>c2</code> defaults to length of <code>string</code> (if omitted or larger). Thus <code>char(c1\string)</code> gets character 1 to the end and <code>char(\c2\string)</code> gets character 1 through <code>c2</code>.</li>
<li><tt>chars(c1\c2\string)</tt> - returns characters <tt>c1</tt> to <tt>c2</tt> of <tt>string</tt> (the first character is character 1). <tt>c1</tt> defaults to 1 if omitted (or less than 0) and <tt>c2</tt> defaults to length of <tt>string</tt> (if omitted or larger). Thus <tt>char(c1\string)</tt> gets character 1 to the end and <tt>char(\c2\tt)</code> gets character 1 through <tt>c2</tt>.</li>
<li><code>word(w1\string)</code> - returns word <code>w1</code> of <code>string</code>. If <code>w1</code> is less than 1 or greater then number of words in <code>string</code>, an empty string is returned.</li>
<li><tt>word(w1\string)</tt> - returns word <tt>w1</tt> of <tt>string</tt>. If <tt>w1</tt> is less than 1 or greater then number of words in <tt>string</tt>, an empty string is returned.</li>
<li><code>offset(s1\c1\string)</code> - returns offset of string <code>s1</code> in string at or after character <code>c1</code> (the first character is character 1) or returns 0 if string <code>s1</code> is not found. c1 can be omitted to find <code>s1</code> any place in <code>string</code>. The search is case insensitive.</li>
<li><tt>offset(s1\c1\string)</tt> - returns offset of string <tt>s1</tt> in string at or after character <tt>c1</tt> (the first character is character 1) or returns 0 if string <tt>s1</tt> is not found. <tt>c1 can</tt> be omitted to find <tt>s1</tt> any place in <code>string</code>. The search is case insensitive.</li>
<li><code>replace(s1\s2\string)</code> - returns string where all occurrences of string <code>s1</code> in <code>string</code> are replaced with string <code>s2</code>. <code>s2</code> may be omitted to delete all occurrences of string <code>s1</code>.</li>
<li><tt>replace(s1\s2\string)</tt> - returns string where all occurrences of string <tt>s1</tt> in <tt>string</tt> are replaced with string <tt>s2</tt>. <tt>s2</tt> may be omitted to delete all occurrences of string <tt>s1</tt>.</li>
<li><code>upperCase()</code> - convert string to upper case.</li>
<li><tt>upperCase()</tt> - convert string to upper case.</li>
<li><code>lowerCase()</code> - convert string to lower case.</li>
<li><tt>lowerCase()</tt> - convert string to lower case.</li>
<li><code>titleCase()</code> - convert to string with capitalized words.</li>
<li><tt>titleCase()</tt> - convert to string with capitalized words.</li>
</ul>
</ul>



Revision as of 11:42, 3 September 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
    When there are multiple operators, the operations are combined with the usual operator precedence of ^ followed by * and / followed by + and -. When there are multiple operators of the same precedence, they are evaluated left to right.
  • [ATOMIC] are the elements that are combined. The possible atomics are:
    • An unsigned number (23, 2.234, 3e2, 4.56e-3, ...). In NairnFEAMPMViz, the number cannot use exponential form (e.g., 4.56e-3) unless the entire expression is that number (e.g., #x=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).
      • "at" expressions are not yet supported in NairnFEAMPMViz

Supported Functions

The following numeric functions are supported in both NairnFEAMPM and NairnFEAMPMViz:

  • sin() - sine of argument in radians
  • cos() - cosine of argument in radians
  • tan() - tangent of argument in radians
  • asin() - inverse sine with result in radians
  • acos() - inverse cosine with result in radians
  • atan() - inverse tangent with result in radians
  • sinh() - hyperbolic sine
  • cosh() - hyperbolic cosine
  • tanh() - hyperbolic tangent
  • exp() - exponential
  • log() - natural log
  • log10() - log base 10
  • sqrt() - square root
  • abs() - absolute value
  • int() - integer part
  • sign() - 1 if argument is positive or 0 if it is negative
  • rand() - a random number between 0 and the argument.

The following numeric functions are supported only in NairnFEAMPM:

  • erf() - error function.
  • erfc() - error function complement.

The following string functions are supported 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 characters c1 to c2 of string (the first character is character 1). c1 defaults to 1 if omitted (or less than 0) and c2 defaults to length of string (if omitted or larger). Thus char(c1\string) gets character 1 to the end and char(\c2\tt) gets character 1 through c2.
  • word(w1\string) - returns word w1 of string. If w1 is less than 1 or greater then number of words in string, an empty string is returned.
  • offset(s1\c1\string) - returns offset of string s1 in string at or after character c1 (the first character is character 1) or returns 0 if string s1 is not found. c1 can be omitted to find s1 any place in string. The search is case insensitive.
  • replace(s1\s2\string) - returns string where all occurrences of string s1 in string are replaced with string s2. s2 may be omitted to delete all occurrences of string s1.
  • upperCase() - convert string to upper case.
  • lowerCase() - convert string to lower case.
  • titleCase() - convert to string with capitalized words.

Notes

  1. 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.