This version of the Help is no longer updated. See JMP.com/help for the latest version.

.
Scripting Guide > JSL Building Blocks > JSL Syntax Rules
Publication date: 07/30/2020

JSL Syntax Rules

All scripting and programming languages have their own syntax rules. JSL looks familiar if you have programmed in languages such as C and Java. However, rules for punctuation and spaces differ in JSL.

The following sections describe JSL syntax rules for the following basic components of the language.

Value Separators

Words in JSL are separated by parentheses, commas, semicolons, spaces, and various operators (such as +, –, and so on). This section describes the rules for using these separators and delimiters in JSL.

Commas

A comma separates items, such as items in a list, rows in a matrix, or arguments to a function.

my list = {1, 2, 3};
your list = List( 4, 5, 6) ;
my matrix = [3 2 1, 0 -1 -2];
If( Y < 20, X = Y );
Table Box( String Col Box( "Age", a ) );

Note: To glue a sequence of commands into a single argument inside a function, separate each sequence with a semicolon. See Semicolons.

Parentheses

Parentheses have several purposes in JSL:

Parentheses group operations in an expression. The following parentheses group the operations in the If() expression.

y = 10;
If(
	Y < 20, X = Y,
	X = 20
);

Parentheses delimit arguments to a function. In the following example, parentheses enclose the argument to the Open() function.

Open( "$SAMPLE_DATA/Big Class.jmp" );

Parentheses also mark the end of a function name, even when arguments are not needed. For example, the Pi function has no arguments. However, the parentheses are required so that JMP can identify Pi as a function.

Pi();

Note: Be careful that parentheses match. Every ( needs a ), or errors result.

The script editor can match fences (parentheses, brackets, and braces). Press CTRL-] (COMMAND-b on macOS) with your cursor in any part of a script. The editor searches for fences, highlighting the text between the first set of opening and closing fences that it finds. Repeat this process to highlight the next-higher fence. See Match Parentheses, Brackets, and Braces in the Scripting Tools section for an example.

Semicolons

Expressions separated by a semicolon are evaluated in succession, returning the result of the last expression. In the following code, 0 is assigned to the variable i and then 2 is assigned the variable j.

i = 0;
j = 2;

You can also use semicolons to join arguments that are separated by commas as shown in the following If() expression.

If( x < 5, y = 3; z++; );

The semicolon in other languages is used as an expression terminator character. In JSL, the semicolon is a signal to continue because more commands might follow. For more information about separating expressions with semicolons, see Alternatives for Gluing Expressions Together.

Semicolons at the end of a script or at the end of a line of arguments are harmless, so you can also think of semicolons as terminating characters. Trailing semicolons are allowed at the end of a script stream and after a closing parenthesis or closing curly brace. In fact, terminating each complete JSL expression with a semicolon helps avoid errors when you copy and paste small scripts into a larger one.

The semicolon is equivalent to the Glue() function. See Operators for more information about semicolons and Glue().

Double Quotes

Double quotes enclose text strings. Anything inside double quotes is taken literally, including spaces and upper- or lower-case; nothing is evaluated. If you have "Pi() ^ 2" (inside double quotes), it is just a sequence of characters, not a value close to ten.

You do have to be a careful with text strings. Extra spaces and punctuation do affect the output, because text strings inside double quotes are used literally, exactly as you enter them.

To have double quotes inside a quoted string, precede each quotation mark with the escape sequence \! (backslash-bang). For example, run the following script and look at the title of the window:

New Window( "\!"Hello\!" is a quoted string.",
	Text Box( Char( Repeat( "*", 70 ) ) )
);

Table 5.1 Escape Sequences for Quoted Strings

\!b

blank

\!t

tab

\!r

carriage return only

\!n

linefeed (newline) only

\!N

inserts line breaking characters appropriate for the host environment1

\!f

formfeed (page break)

\!0

null character

Note: The null character is dangerous to use, because it is typically treated as the end of the string. Be sure to type the number zero, not the letter O.

\!\

backslash

\!"

double quotation mark


1 On macOS, this escape sequence is CR (carriage return character, hexadecimal ‘0D’). On Windows, this sequence is CR LF (carriage return followed by a linefeed, hexadecimal ‘0D0A’).


Sometimes, long passages require a lot of escaped characters. In these cases, use the notation \[...]\ and everything between the brackets does not need or support escape sequences. Here is an example where \[...]\ is used inside a double-quoted string.

jslPhrase = "The JSL to do this is :\[
	a = "hello";
	b = a|| " world.";
	Show(b);
	]\ and you use the Submit command to run it.";

Spaces

JSL allows whitespace characters inside names; spaces, tabs, returns, and blank lines inside or between JSL words are ignored. This is because most JSL words come from the user interface, and most of those commands have spaces in them. For example, the JSL expression for the Fit Model platform is Fit Model() or FitModel().

Spaces inside an operator or between digits in a single number are not allowed. In these cases, the script generates errors. For example, you cannot put spaces between the two plus signs in i++ (i+ +) or in numbers (4 3 is not the same as 43).

Note: Why does JSL allow whitespace characters inside names? For one reason, the names of commands and options match the equivalent commands in JMP menus and windows. Another reason is that data table column names often include spaces.

Want more information? Have questions? Get answers in the JMP User Community (community.jmp.com).