Syntax: Difference between revisions

From BR Wiki
Jump to navigation Jump to search
Line 76: Line 76:
{{:Comment}}
{{:Comment}}


===Special Syntax Considerations===
===Syntax Diagrams===


Diagrams are used throughout this manual to explain the syntax of Business Rules commands statements and various other syntactical specifications. This chapter explains how to read the conventions, which are used in the diagrams.
Diagrams are used throughout this manual to explain the syntax of Business Rules commands statements and various other syntactical specifications. This chapter explains how to read the conventions, which are used in the diagrams.

Revision as of 21:41, 3 February 2013

Parts Of A Business Rules Statement

Statements (Immediate Mode/Procedure Files)

A typical Business Rules! statement consists of the following:

  1. A line number.
  2. A line label (optional).
  3. A primary keyword.
  4. One or more secondary keywords or phrases along with their associated values (sometimes optional).
  5. One or more "error-cond line-ref" conditions (optional).
  6. Remark or comment (optional).

"Optional" items may be included but are not required.

Notice that the listed elements refer to a typical statement. Some statements consist mainly of a primary keyword RETURN or RETRY for instance, only the line number and optional programmer's remarks or a line label are permitted with these two statements. See the syntax diagrams for each Statement for specific details.

Analysis of an Example Statement

The following formatted Print statement will be used to describe the components of a statement:

00020 BIG: PRINT USING F1: A$,T(5) CONV 00520 ! remarks
00120 is a line number.
BIG is a line label.
PRINT is a primary keyword. Primary keywords specify the type of operation that you wish to perform.
USING F1 is a secondary phrase. This phrase consists of the secondary keyword USING and the line reference F1 (a line label). Secondary keywords and secondary phrases add detail to the instructions in the statement.
A$ and T(5) are references to variables.
CONV 520 is an "error-cond line-ref" specification. It transfers control of the program to line 00520 if a CONV error occurs during execution of line 00120.
! remarks is an optional comment that follows the statement. An exclamation point signals the start of this remark; any comment the programmer wishes to make may follow. Note that certain statement keywords, for example, DATA, do not allow for comments on the same line, in which case comments must be placed on an adjacent line alone.

Each command in a procedure file may be followed by at least one space, an exclamation point (!) and a comment. Business Rules will ignore everything after the exclamation point.

Remarks may also reside on their own line in a procedure file, as follows:

LOAD MENU.BR
! Load the program MENU.BR
RUN

Line labels - Procedure Files

Commands in a procedure file may start with a line label. The label must begin with a colon (:) and may be up to 800 alphabetic, numeric or underscore characters in length (spaces are not allowed). Procedure labels do not have to be followed by a command. Both the following procedure lines are acceptable:

:NEXTRUN
:START PROC MENU

When typed in without a line number and during READY mode, most statements can be executed immediately. Statements without line numbers or labels may also be included in procedure files. Statements used in both these ways may include a comment at the end of the statement.

The comment must be separated from the rest of the statement by at least one space and an exclamation point, or it may be set off with the use of the REM statement.

The following example shows the OPEN (Ope) statement being used in immediate mode:

OPEN #1:"name=test1",Internal,Input,Sequential



Line numbers

Line numbers in Business Rules! are five digit numbers which indicate the flow of the program. Each statement is assigned to a line number located at the beginning of that line.

The "line-num" parameter indicates that you must specify a line number rather than a line label, whereas the "line-ref" parameter allows for either a number or label. For most purposes, using a line label is recommended. Line numbers can be used only in programs (not in procedure files, which require line labels) and must be integers from 1 to 99999.

Every Business Rules! statement that is executed from within a program must be on a line with a line number. Line numbers may range from 00001 to 99999 (commas are not allowed). While a program may theoretically contain up to 99,999 lines, the actual limit depends on the statements used, the amount of memory available, and the release of Business Rules! being used.
It is not necessary to insert zeros before line numbers such as 10 or 4035, since Business Rules! automatically re-lists these numbers as 00010 and 04035.

During editing it is not necessary for line numbers to be in order. Business Rules! will reorder lines based on their line numbers so that code can be developed out of sequence and then cleaned into sequence.

While working with a program, it is often easier to work without line numbers. Lexi is a program which allows you to do so, then lists the line numbers back into your program before running it in BR.

Line number tools include the Auto and Renum commands,

Related external editor features are MyEditBR's refoctoring and Notepad++'s column renumbering.



Line labels - Program files

The Line label is an optional name for a program line. They are accepted at the beginning of all statements following the line number. The label may be from one to 30 alphabetic, numeric or underscore characters in length, but must begin with a letter. Each line label must be unique and immediately followed by a colon. Business Rules allows most statement and command keywords to be used as line labels. In the following statement, "LABEL_SAMPLE:" is a line label:

00900 LABEL_SAMPLE: Rinput #1, Select '2,40,Cr 10,[w]',Attr "[A]": Autoselect$

A line label can then subsequently be used in place of a line number to reference the line from a secondary expression. In the following example, the line label BIG is defined to represent line 120; it is then used as a line reference for the GOTO statement in line 300. (F1 is also a line label):

00120 BIG: Print Using F1: A$,T(5)
o
o
o
00300 GOTO BIG

Line labels are often used to easily refer to form statements:

1100 read #10,using Addressform: Mat Co$,City$,St$,Zc$,Mat Dd$
1110 Addressform: form 3*C 30,C 20,C 2,C 12,Pos 257,10*C 18

For information about the labels that are used in procedures, see Line Label (procedure).



Multiple statements

More than one statement can reside on a line number when the statements are separated by a colon (:). When the statements are separated by both an exclamation point and a colon (!:), Business Rules will list them to separate physical lines, even though they continue to belong to the same line number.



Line Continuation

An !: in Business Rules! code performs a line continuation.

More than one clause (or statement) can reside on a single line when the statements are separated by a colon (:). When the statements are separated by both an exclamation point and a colon (!:), Business Rules will list them to separate physical lines, even though they continue to belong to the same line number. Each portion of a line seperated by an !: is referred to as a sub-line.

Paragraph labels following line continuations are not allowed. However they are allowed following a subline comment out (!), for example:

00010 TOP: ! !:
      Print Newpage



Comments

Business Rules! lines may include a comment after the statement(s). The comment must be separated from the rest of the statement by at least one space and an exclamation point or the REM statement.

The keywords for comments are:

Rem Used to comment out a whole line number, or the remainder of a whole line.
! Used to comment out just one sub-line (see line-continuation), or the remainder of a sub-line. Can be used in a Sort Control File.
Use Not suggested, but preserved for legacy purposes. It is similar to Rem.




Syntax Diagrams

Diagrams are used throughout this manual to explain the syntax of Business Rules commands statements and various other syntactical specifications. This chapter explains how to read the conventions, which are used in the diagrams.

Syntax diagrams provide a road map through a command or statement's syntax. Following the main line of the diagram will eventually bring you to the end of the syntax, although you may wish to take allowable detours to obtain certain features. Syntax diagrams always follow a logical pattern.

If they require you to pass through a particular parameter, then that parameter is required. If they allow you to bypass a particular parameter, then that parameter is optional.

Although all syntax diagrams (whether for a command, statement or other specification) must be read the same way, the actual specification you are working with may be subject to other requirements or options as well. A statement, for example, must always reside on a line with a line number. See the sections at the end of this chapter for information about these additional requirements and options.

The "array-name" parameter is a name representing either a numeric or a string array. For rules regarding these names, see also Variable.

The "BAUD" parameter sets the transmission speed in bits per second. See the OPEN communications statement in the Statements Chapter for details.

The "BORDER=spec" parameter represents an insertable syntax which is used in the OPEN window statement to identify a border type for the window being opened. See the OPEN window statement for additional information and the syntax diagram.

The BUFSIZE parameter specifies the size of the buffer for DOS versions of Business Rules. The default is 2000 bytes, which is low for high-speed data transmission. To avoid losing data with rates of 2400 bps or higher; an increased BUFSIZE is recommended.

In Business Rules, Unix and Linux versions ignore the BUFSIZE parameter, as the operating systems handle the buffering for these versions instead.

"Column" (not to be confused with "columns") is an integer {\b value} from 1 to 80, which indicates a column number on the screen.

"Columns" (not to be confused with "column") is an integer {\b constant}, which indicates the maximum size for the second through seventh dimensions of an array.

Concatenation is the joining of two or more strings. In Business Rules, the ampersand (&) is the concatenation operator. Concatenation may be used in any output or assignment statement to join any number of string expressions.

In the following example, lines 100 and 110 illustrate the concatenation of three strings. Lines 120 and 130 use concatenation and the string functions RTRM$, LTRM$ and RPT$ to print and center X$ on the 80-column screen:

00100 LET LINE$ = A$ & B$ & C$
00110 PRINT RTRM$(CITY$) & ", " & STATE$
00120 LET X$ = RTRM$(LTRM$(X$))
00130 PRINT RPT$(" ",(80-LEN(X$))/2) & X$

The printing and centering in lines 120 and 130 can be performed more efficiently with the CC format specifications as follows:

00140 PRINT USING 150: X$
00150 FORM CC 80

The "corners" parameter is used to specify custom-designed borders for both I/O windows and field help windows. Two characters must be specified for this parameter: the character to be used for the top left corner of the window and the character to be used for the bottom right corner of the window. Business Rules fills in the rest of the characters for you

"Drive" is a DOS-like drive letter, which must be followed by a colon. The drive parameter may specify certain special devices such as a printer or modem.

"Drive-num" is a digit, which indicates a System/23 drive; Business Rules translates it into a DOS drive letter. This parameter may not be specified with a redirection symbol (>) or when a drive letter is specified.

The "error-cond line-ref" parameter is replaced with one or more pairs of specifications. "Error-cond" is a specific error condition and "line-ref" is a line number or line label to which control should be transferred if that error occurs. See the Error Conditions chapter for more information about the various error conditions.

"Field-length" is an integer value, which identifies the number of columns in the specified field. This parameter is required as a part of any numeric format specification except PIC.

"Field-spec" represents an insertable syntax that is used to provide field definitions for the full screen processing statements. For additional information and a syntax diagram, see the Screen I/O chapter.

Filenames

"Filename" is a name consisting of up to eight alphabetic, numeric or underscore characters and an optional period and extension of up to three consecutive letters. Wildcard characters (* and ?) may be used in file names specified with the COPY, DIR, DROP, and FREE commands. Version 3.9 will support long filenames (greater than the 8.3 format) with a variety of alternatives with respect to case sensitivity. Unix defaults to case sensitive, and DOS/Windows defaults to case insensitive. Business Rules! defaults to lower case on all platforms, unless overridden by a FILENAMES configuration statement.

The file name requirements for all types of files are identical. However, one item to be aware of is that procedure files which use an extension of .$$$ will automatically delete themselves after closing. See the Procedures chapter for additional information.

"File-num" is a numeric expression or an integer that equals 255 or any number from zero to 127. A file number matches a logical file to a physical file or device. File numbers are defined in OPEN statements, then used in I/O statements for that file or device.

Two special file numbers which do not require OPEN statements are 0 (for input or output to the screen) and 255 (for output to the printer).

No file numbers are required when INPUT, LINPUT, RINPUT, or PRINT are used for I/O from the keyboard or to the display screen. File-num is always immediately preceded by a pound symbol (#).

The ">file-ref" parameter causes all information which would normally be printed on the screen to be sent to the file specified in the file-ref (see the "file-ref description for information about the correct syntax). One special case is the RUN command in which ">file-ref" redirects printer output to a file. Wherever ">file- ref" is indicated, ">>file-ref" (with two redirection arrows) may also be specified.

Using one redirection arrow causes the screen information to write directly over any contents that currently exist in the specified file. Using two redirection arrows cause the information that would normally go to the screen to be appended to the end of the specified file. The TYPE command with the >>file-ref parameter may thus be used to append a display file to another file. Likewise, the LIST command may be used with >>file-ref to append the contents of a program to another program which has been saved in source.

(Be careful about line numbers when using this technique, as line numbers that are duplicated in the same file will replace one another upon loading from source.)

Fixed-point numbers are numbers with a decimal point in a fixed position.

"Floating point form-spec" represents a format specification from the following group: D, S, or L. These format specifications are fast, but non-portable. See the File I/O chapter for more information.

Floating-point numbers are numbers, which allow the decimal point to "float" to any position. The Business Rules syntax is nEm, where n is a numeric constant indicating the sign and significant digits in the number, E represents base 10, and m is a signed integer representing the power to which 10 is raised.

The largest and smallest numbers available to the system vary according to the hardware and operating system being used. The system function INF can be used to print the largest possible number on any given system; 1/INF generates the smallest number. For all DOS, Unix and Linux versions available at the time of writing, the largest number is 1.000E+307; similarly, the smallest number is 1.000E-307. Some caution should be used in working with numbers near these extremes (e.g., using exponential notation in SORT). Also, for any given combination of hardware and Business Rules, the system infinity function INF and some testing should be combined to determine whether or not intermediate values used in calculations will be truncated.

The "fraction-length" parameter is an integer value that identifies the number of digits contained in the fractional portion of the item to be printed or input. This integer must be preceded by a decimal point.

"Wind-num" is the number of a window file that has been opened by an OPEN window statement. It must be a numeric expression or integer value that equals a value between 1 to 127. No other open file or open window may use the same value. Open windows do not count against the operating system limit on open files.

Wildcard characters (? and *) may be used in file names and extensions in place of alphabetic or numeric characters. They may not be used in drive, path, or directory specifications. They have the following meanings:

? means that any character in that position (including null) is regarded as a match.
* denotes any number of ? characters.


Example
A:VOL\NAME?.*

The above references all files in subdirectory VOL on drive A with a name consisting of NAME followed by any one character, a period, and any extension.

A "var-name" may be either numeric or string. It may be a subscripted or un-subscripted variable, or an array name preceded by MAT. Var-name items are used mainly in various types of input statements to assign values to variables. They typically occur in lists separated by commas.

The "string form-spec" parameter should be replaced with a string format specification from the following group: C, CC, CR, CL, CU, G, GL, GU, V, VL, VU. The specifications that are applicable for a given statement are identified in the parameters text for that statement. See the File I/O chapter for information about individual format specifications.

The CL, CU, GL, GU, VL, and VU specifications are valid only in full screen processing statements (PRINT FIELDS, INPUT FIELDS, and RINPUT FIELD); they cannot be used in either type of FORM statement.


The "string-expr" parameter represents one of several kinds of string elements, including string system functions, string user-defined functions, string constants, and string variables. See the definitions in this chapter for more information about string constants and string variables. See the Functions chapter for more information about string system functions. See the DEF statement discussion for more information about user-defined functions.

In addition to the four elements listed above, string expressions may utilize substring operators (to specify that only a portion of the string be used) and the concatenation operator (to specify that multiple string expressions be combined together). See the definitions for "Substring operation" and "concatenation operation" in this chapter for more information.

The "helpstring" parameter represents an insertable syntax, which is used in the full screen processing statements to specify the user level; window placement and text for field help windows. For additional information and a syntax diagram, see the Screen I/O chapter.

The "increment" parameter is used in the AUTO ATT and RENUM commands. It represents an integer value, which indicates how much the system should increase the numbers from one line number to the next.

The "INPUT" keyword identifies that the file is to be opened so that its data may only be used as input for the program.

The "int" parameter represents an unsigned, positive, non-zero whole number.

The "integer" parameter represents a whole number (no decimal points or fractions allowed). NOTE the difference between "integer" and "int".

The "internal form-spec" parameter should be replaced with a format specification from the following group: B, BL, BH, PD, ZD. See the File I/O chapter for information about individual format specifications.

The "key-length" parameter should be replaced with a number that identifies the number of characters (or columns) in the key.

"Key start-pos" indicates the record position of the first key character for the index.

"Length" is an integer value that sets the maximum length of all elements in the string variable or array.

A line label is an optional name for a program line that is specified immediately after the line number. It must be unique (no other line can be given the same line label), and it must be followed by a colon when it is defined. This line label can then subsequently be used in place of a line number to reference the line from a secondary expression. Business Rules allows most statement and command keywords to be used as line labels.

In the following example, the line label BIG is defined to represent line 120; it is then used as a line reference for the GOTO statement in line 300:

00120 BIG: PRINT USING F1: A$,T(5) CONV
o
o
o
00300 GOTO BIG

For information about the labels that are used in procedures, See the Procedures chapter.

The "line-num" parameter indicates that you must specify a line number rather than a line label. Line numbers can be used only in programs (not in procedure files) and must be integers from 1 to 99999.

The "line-ref" parameter indicates that you can specify either a line number or a line label as a parameter.

"Num-array" indicates that a numeric array name should be specified.

The "num-constant" parameter represents a number consisting mainly of the digits 0-9; other optional elements are a decimal point (.), a minus sign (-) to indicate a negative number, and a plus sign (+) to indicate a positive number (unsigned numbers are assumed to be positive). If a sign is specified, it must precede the digits. Spaces are not allowed in a numeric constant.

Integers, fixed-point numbers and floating point numbers (numbers in exponential notation) are three types of numeric constants. See the following examples:

Number

44
+15.38
-86.34
10,000
Integer

44
n/a
n/a
10000
Fixed Point

44
+15.38
-86.34
10000
Exponential

4.4E+1
1.538E+1
-8.634E+1
1E+4

The "num-expr" parameter represents one of five kinds of numeric elements: conditional expressions, numeric constants, numeric variables, numeric system functions, and numeric user-defined functions. See the definitions in this chapter for more information about conditional expressions, numeric constants and numeric variables. See the Functions chapter for more information about numeric system functions. See the DEF statement discussion for more information about user-defined functions.

"Num-var" is a name that a programmer assigns to a storage location in the computer's memory; it is used for storing a number. Variables are created by being referenced in expressions or by being specified in the DIM statement. When used in numeric expressions, numeric variables can be either subscripted or un-subscripted. When specified in syntax diagrams in this book, however, num-var must be a simple (i.e., un-subscripted) variable name -except when stated otherwise in the "parameters" section for the specific statement.

A numeric variable name can be 1-30 alphanumeric characters and underscores, the first of which must be a letter. Examples of simple numeric variable names include A5, TOTAL, RATE, and EMPLRATE.

The same character sequence may be used as a name for both a variable (scalar) and an array. By adding a $ on the end, the same character sequence may be used for a string variable and a string array. Thus A, MAT A, A$, and MAT A$ all may co-exist in the same program.

Certain words are reserved by Business Rules, and cannot be used as variable names. Note that all words starting with the letters "FN" are reserved, as they are considered user-defined function names. See also Reserved Words.

The "num form-spec" parameter should be replaced with a numeric format specification from the following group: G, GZ, N, or NZ. The specifications, which are applicable for a given statement, are identified in the parameters text for that statement. See the File I/O chapter for information about individual format specifications.

The "OUTIN" keyword indicates that the file is to be opened so that information may move in two directions: both into and out of the data file.

The "OUTPUT" parameter indicates that the file is to be opened so that information may only be output from the program to the file.

"PARITY=spec" is an OPEN communications parameter. The "PARITY" keyword and equal symbol (=) must be followed by one of three replacements for "spec": N (no parity checking), E (even parity) or O (odd parity).

The "path" parameter identifies the sequence of directories to be used. Each directory must be separated by a backslash "\\". When the path does not begin with a backslash, searching begins at the default directory.

The PIC format specification converts a number into characters according to the picture specified. The "pic-spec" parameter is the picture, and consists of one or more characters, which are either insertion characters to be printed as is, or digit identifiers to be replaced with a digit when printed. See the File I/O chapter for information about PIC and individual insertion characters and digit identifiers.

"Row" is an integer value from 1 to the number of rows in the screen or window that indicates a row number

"Rows" (not to be confused with "row") it is an integer constant which indicates the maximum size for the first dimension of an array.

"String-array" indicates that a string array name should be specified. For rules regarding these names, see "string variable" in this chapter.

A string constant is a series of characters enclosed in quotation marks. Each constant may contain from 0 to 250 characters.

Quotation marks are used as delimiters in string constants. They signal the beginning and end of a string. You may use either single or double quotation marks. If the enclosed string contains one kind of quotation mark, however, you must either use the other kind as a delimiter or express the inner quotation mark as a pair. Examples of string constants are:

"Montana"
'Montana'
'The "Big Sky" Country'
"The ""Treasure"" State"

Note that in a "LIST" command single quotes represent case insensitive searching while double quotes represent case sensitive matching.


Quote Processing

Quotation marks suppress the recognition of separators in accordance with the following rules. Standard BR Quote Processing When examining str$ left to right, the first character (and the first character after each separator) is checked to see if is either (') or ("). If it is ether of those then it activates quotation processing which suppresses the recognition of separators until quotation processing is deactivated. The first character thus becomes the governing quote type until quotation processing is deactivated.

The string is copied until it ends or until an odd number of successive occurrences of the governing quote type is encountered. During this processing, two adjacent occurrences of the governing quote character denote an embedded occurrence of the quote character. Examples "abc,def" -> abc,def where the comma is not recognized as a separator and is part of the data abc"def -> abc"def naturally embedded quotes may occur anywhere within a string after the first character "abc"def" -> abcdef" quotation processing is deactivated by the center quote mark "abcdef" -> abcdef normal data "abc'def" -> abc'def the single quote is treated like any other character while double quotes govern 'abc"def' -> abc"def double quotes are treated like any other character while single quotes govern "abc""def" -> abc"def pairs of governing quotes denote a single embedded quote "abc"""def" -> abc"def" the third successive occurence deactivates quote processing

MAT2STR( MAT zzz$, str$ [, sep$ [, flags$]] ) Where flag$ is in the format: [ quote-type ] [ :LTRM ] | [ :TRIM ] | [ :RTRM ] Where quote-type can be Q, QUOTES, ('), or ("), case insensitive. Quote-type denotes that each element should be enclosed in quotation marks. The trim flags denote pre-processing of array elements and the leading colon is only present when quote-type is specified. If Q or QUOTES is specified the BR automatically determines which quote type to apply as follows: The element is scanned left to right for either type of quote character. If a quote character is encountered, then only the next character is examined. If two occurrences of the same quote character are encountered then that character is used to enclose the element. However, if a single occurrence of a quote character is encountered then the element is enclosed in the alternate quote type. If no quote character is encountered then double quotes are applied. Examples Quote Type is Q or QUOTES abcdef -> "abcdef" abc'def -> "abc'def" abc"def -> 'abc"def' abc""def -> "abc""def" 'abcdef -> "'abcdef"

Quote Type is ' ( quote type single ) abcdef -> 'abcdef' 'abcdef -> abcdef' single quotes get doubled when embedded in singles quotes "abcdef -> '"abcdef' leading double quote is treated normally

Quote type double mirrors quote type single. When using MAT2STR on a 2 dimensional array, the first delimiter is used for individual elements and the second delimiter at the end of each row. This principle also applies to three to seven dimensions. Example Given the following two dimensional array zzz$ containing the values-

   1            2
   3            4

The following statements-

   10 Sep$(1)=","
   20 Sep$(2)=hex$("0D0A") ! CRLF
   30 MAT2STR( MAT zzz$, str$, MAT Sep$ )
   40 PRINT str$

Will produce-

   1,2
   3,4