Using Caché Basic
Lexical Structure
[Home] [Back] [Next]
InterSystems: The power behind what matters   
Class Reference   
Search:    

Lexical structure is the set of fundamental rules that govern the behavior of a programming language. This chapter describes the lexical structure of Caché Basic.

a.foo = 10
A.foo = 20
PrintLn "a = " & a.foo
PrintLn "A = " & A.foo
 
Case Sensitivity
Statement, function and operator names are not case-sensitive in Basic:
PrintLn "Hello"
PRINTLN "Hello"
println "Hello" 
 
Variable names are case-sensitive:
a = 10
A = 20
PrintLn "a = " & a
PrintLn "A = " & A
 
Object identifiers (class, method, and property names) are not case-sensitive, but must be locally unique as if they were case-sensitive (in other words, you cannot have a Person and a PERSON class):
person = OpenId Sample.Person(1)
PrintLn person.Name
' PrintLn person.name  ' Error
 
White Space and Line Continuation
Basic ignores spaces and tabs that appear between tokens. A token is either a function name, variable name, number, or a keyword. White space cannot appear within a token.
A newline indicates the end of a Basic code statement. The underscore character (_) is the line continuation indicator. To continue a statement on the next line, end the first line with a space character followed by an underscore. The underscore must be the last character of the line; a space or comment is not permitted after the line continuation character.
Comments
Comments in Basic are line oriented and start with either the Rem statement or the apostrophe ('). The comment is always until the end of the line and everything within the comment is ignored:
' This is a comment
Literals
Literals appear within the program and represent a data value. A literal can be a constant (vbMonday).
The following example prints a variety of literals :
PrintLn "This is a String" 'String literal
PrintLn 1234 ' Integer literal
PrintLn 123.4 ' Numeric literal
PrintLn true
PrintLn vbMonday
 
Identifiers and Variables
An identifier is a name and can be used to name variables, functions, classes, and so on.
A variable is a named storage location that can contain data that can be modified during program execution. Each variable has a name that uniquely identifies it within its level of scope. There are three types of variables: local variables, process-private global variables, and global variables. For detailed definitions of these three types of variables, refer to the Variables chapter of Using Caché ObjectScript.
Variable names are case-sensitive. Variable names may be of any length, but must be unique within the first 31 characters (exclusive of prefix characters). Variables can have multiple levels of subscripts. For details on variable naming conventions in Caché Basic, refer to the Variables chapter of this manual.
Labels
Within Caché Basic code you can define a label as follows:
labelOne:
    ' some code
labelTwo:
    ' some more code
A label is a valid identifier followed by a colon (:). Label names are case-sensitive. A label name can begin with either a letter or a percent (%) character; the other characters in the label name must be letters or numbers. A label can be of any length, but only the first 31 characters are meaningful. A label can have the same name as a variable or a reserved word, though this is not recommended.
A label must be the first item on a program line. A label does not have to begin at column 1, although this is generally recommended. You can specify more than one label on the same program line, separating these labels with a blank space.
Following all labels on a program line, you can specify one or more commands on the same line; multiple commands on the same program line are separated by a colon character. Following all labels and commands on a program line, you can specify a comment. For example, the following is a valid line of Caché Basic code:
label1: label2: Set x="text" : Println x ' my comment
 
Labels are used by the Goto statement and the On Error Goto statement, which are documented in the Caché Basic Reference. Refer to the Error Handling chapter of this manual for additional information on the On Error Goto statement.
Reserved Words
Within Caché Basic there are a number of reserved words that cannot be used as local variable names or function names.
You can find the list of reserved words in the Caché Basic Reference.