Difference between revisions of "Scripting Language Syntax"

From OSUPDOCS
Jump to navigation Jump to search
(Created page with "Both NairnFEAMPM and NairnFEAMPMViz have built-in scripting languages for programmatically setting up calculations. This section describes language syntax and all gene...")
 
Line 56: Line 56:
* <tt>==</tt> : true if <tt>(string1)</tt> is equal to <tt>(string2)</tt> by case-sensitive comparison (<i>i.e.</i>, two equals signs means <i>more</i> equal than one equals sign).
* <tt>==</tt> : true if <tt>(string1)</tt> is equal to <tt>(string2)</tt> by case-sensitive comparison (<i>i.e.</i>, two equals signs means <i>more</i> equal than one equals sign).


==== Options and Notes on Conditionals ====
==== Notes on Conditionals ====


# Some [[Expression Syntax|string functions]] can be used to implement other types of useful string comparisons. For example:
# Some [[Expression Syntax|string functions]] can be used to implement other types of useful string comparisons. For example:

Revision as of 23:23, 28 August 2013

Both NairnFEAMPM and NairnFEAMPMViz have built-in scripting languages for programmatically setting up calculations. This section describes language syntax and all generic commands for programming control.

Language Syntax

This sections describes the syntax of command lines and gives the definitions of variables and expressions.

Conditional Commands

The if, ifStr, ifDef, and ifNDef commands are used to define conditional blocks. The if command is for numeric comparisons; the ifStr commands is for string comparisons; the ifDef and ifNDef commands are to check if variables have been defined. The format of a conditional block is:

if (num1) (op) (num2)
  (block of commands if numeric comparison is true)
    .
else ifStr (string1) (op) (string2)
  (block of commands if string comparison is true)
    .
else if (num1)
  (block of commands if (num1) is not zero)
    .
else ifStr (string1)
  (block of commands if (string1) is not empty)
    .
else ifDef #varName
  (block of commands if #varNam is a defined variable)
    .
else ifNDef #varName
  (block of commands if #varNam is not a defined variable)
    .
else
  (block of commands if no prior condition is true)<br>
endif

where there can be any number of conditionals and each can be of any type. If either arguments to an if conditional are strings instead of numbers, that conditional will automatically be converted to an ifStr command. In other words, there is no need to use ifStr unless you explicit want to compare two strings as strings when they happen to also be valid numbers. The arguments to ifDef and ifNDef must be a single variable name.

Numeric Comparisons

Numerical conditionals compare (num1) to (num2) with the following comparison operators for (op):

  • = or == or ' is ': true if (num1) is equal to (num2).
  • != or <> : true if (num1) is not equal to (num2).
  • > : true if (num1) is greater than (num2).
  • >= : true if (num1) is greater than or equal to (num2).
  • < :true if (num1) is less than (num2).
  • <= : true if (num1) is less than or equal to (num2).

String Comparisons

String conditionals are nearly the same except ordering is alphabetical order instead of numerical order. Furthermore the two "equals" operators provide case-insensitive or case-sensitive comparisons as follows:

  • = or ' is ': true if (string1) is equal to (string2) by case-insensitive comparison.
  • == : true if (string1) is equal to (string2) by case-sensitive comparison (i.e., two equals signs means more equal than one equals sign).

Notes on Conditionals

  1. Some string functions can be used to implement other types of useful string comparisons. For example:
    • if offset(s1\string)>0 - is true if the string contains the string s1.
    • if chars("\"&length(s1)&"\string")=s1 - is true if string starts with the string s1 (case insensitive, use == to make it case sensitive).
    • if chars((length(string)-length(s1)+1)&"\string")=s1 - is true if string ends with the string s1 (case insensitive, use == to make it case sensitive).
  2. When a numeric conditional has only a single number and no comparison operator (such as if (num1)), the conditional is true if the number is not equal to zero. If the number is not zero, the conditional is false.
  3. When a string conditional has only a single string and no comparison operator (such as ifStr (string1)), the conditional is true if the string is not an empty string. If the string has text, the conditional is false.

Repeat Commands

Repeat commands provide looping for repetitive tasks.

  • <a href="repeat.html">Repeat</a> ... <a href="endrepeat.html">EndRepeat</a>: Define a repeat loop.
  • <a href="break.html">Break</a>: Break out of <a href="repeat.html">repeat loop</a>.
  • <a href="breakall.html">BreakAll</a>: Break out of all <a href="repeat.html">repeat loops</a>.
  • <a href="continue.html">Continue</a>: Continue the current <a href="repeat.html">repeat loop</a>.


Subroutine Commands

Subroutines can be defined at the start of the commands and called with optional parameters.

  • <a href="sub.html">Sub</a> ... <a href="endsub.html">EndSub</a>: Define a subroutine.
  • <a href="gosub.html">GoSub</a>: Call a <a href="sub.html">subroutine</a>.
  • <a href="return.html">Return</a>: Return from a <a href="sub.html">subroutine</a>.

Output and Debugging Commands

These commands print output to the lower field in the input commands window or stop an analysis in progress. They are normally for debugging calculation commands.

  • <a href="clear.html">Clear</a>: Clear the output area.
  • <a href="dump.html">Dump</a>: Write all arguments to output area for debugging.
  • <a href="message.html">Message</a>: Write arguments to the message panel.
  • <a href="write.html">Write</a>: Write arguments to output area.
  • <a href="stop.html">Stop</a>: Stop the analysis.

Differences in the NairnFEAMPMViz Scripting Language