The OScript language contains several types of special characters to indicate particular types of text within a script. Special OScript characters are used to indicate the presence of comments and labels, to provide a method of line continuation, and to separate several statements that appear on a single line.
See also: Lexing and Preprocessing
Comments are non-executable statements that help the reader of a script more readily discern its purpose. OScript supports two types of comments: ( // ) and the ( /* ... */ ) pair.
The ( // ) comment character defines a single line comment. It can be used on a line by itself or it can follow another statement. For example:
// this is a whole line comment
Integer x = 55 // this is an end-of-line comment
All characters on the line following the comment character are considered to be part of the comment and are, therefore, ignored by the compiler.
The ( /* ... */ ) pair can be used to define a multiple line comment, although both characters can be placed on a single line also. For example:
/*
this is a
multiple line comment
*/
Integer x = 55 /* this is an end-of-line comment */
All characters following the ( / * ) character and preceding the next ( */ ) character are considered to be part of the comment and are, therefore, ignored by the compiler.
Comments are optional, but they provide a simple and straightforward method of documenting your script.
Labels are non-executable statements that allow you to mark a location in your script to which execution can be branched using the goto control statement. A label:
For example:
String userName
List userData
File myFile = File.Open( "C:\DATAFILE", File.ReadMode )
userName = File.Read( myFile )
if userName = ''
goto error_routine
else
userData[ 1 ] = userName
end
...block of code...
return
error_routine:
echo( 'You did not enter a valid value!' )
The end-of-line character is the default statement delimiter. However, you may need to continue a statement to the next physical line, or want to place more than one statement on a single line.
The continuation character is the back slash ( \ ). For example:
Echo("x", \
"y", \
"z")
The compiler considers this to be one statement, even though it spans three physical lines.
Comments can follow the statement continuation character, but the continuation character must precede the comment, for example:
Echo("x", \
"y", \// this is the proper place for a comment
"z")
The continuation character cannot be used in the middle of a String declaration. For example:
// error in the following statement:
String s = "The quick brown fox \
jumped over the lazy dog."
// error fixed in the following statement:
String s = "The quick brown fox" + \
"jumped over the lazy dog."
Since CS 10.5, the line continuation character becomes optional in many cases where starting a new statement would be syntactically invalid. As such, continuation characters are no longer necessary in the following circumstances:
(
)), braces ({
) and brackets ([
))
)) and braces (}
)The statement terminator is the semicolon ( ; ). For example:
Integer lineCount, recCount
lineCount = 1; recCount = 1 // initialize counters
In the above example, the compiler considers the assignments to be two separate statements even though they are on the same physical line.