Language Syntax Overview

Top  Previous  Next

The Emergence BASIC compiler supports an advanced version of the original BASIC language. Throughout this help document we will use the term EBASIC to refer to the Emergence BASIC language and development environment.

An EBASIC source program is a collection of commands, statements, functions and preprocessor directives. The source may be contained in one file or separated among many. Each line in a source file can consist of one or more of the listed elements, a comment, or blank space. Multiple source lines may appear on the same editor line by separating them with a colon ':'. The end of a line of source code is always terminated by a return character.

Source lines may be continued into the next editor line by appending an underscore _ after a comma or white space at the end of a line. Underscores are also allowed to be part of a name or identifier.

Source files need not contain executable statements. For example, you may find it useful to place definitions of variables in one source file and then declare references to these variables in other source files that use them. This technique makes the definitions easy to find and update when necessary. For the same reason, constants, DLL declares, COM interface definitions, and TYPE statements  are often organized into separate files called "include files" or "header files" that can be referenced in source files as required.

 

Identifiers

An identifier is a term used to describe a token, variable name, function name, command, or statement. Identifiers can start with an underscore symbol or a letter. Identifiers can be a maximum of 64 characters in length. An identifier cannot begin with a numeric but can contain any number of alphanumeric symbols after the initial symbol.

Example identifiers:

MyVariable

_Some_Function

LovePotion9

Reserved Words

The built in commands, statements and functions that make up the standard EBASIC command set are considered reserved words and cannot be used as an identifier in your own program. Reserved words are syntax highlighted in the editor to differentiate them from other language elements. Emergence BASIC supports installable command sets that extend the capabilities of the language. The installable command set becomes new reserved words for the language and will be appropriately highlighted in the editor.

 

Commands, Statements and Functions

In this document we will commonly refer to commands, statements and functions. In reality all of them refer to a subroutine in either a command set, external library, DLL, or COM object. EBASIC treats command sets slightly differently than user subroutines or DLL functions.

A command is a subroutine with no parameters and can be used simply by using the name.

A statement is a subroutine with parameters that can generally be used without enclosing the parameters in parenthesis. Statements do not usually return values. Parenthesis are required around a statements parameters if the first parameter of that statement begins with a parenthesis of its own. The exception to this rule is the PRINT statement which neither requires or allows parenthesis surrounding the parameter list.

A function is a subroutine with parameters that returns a value. The parameters must be surrounded by parenthesis.

Examples:

'command
END
'statement
PRINT "Hello"
'function
A$ = STR$(99)
'a statement requiring surrounding parenthesis
LOCATE( (y+5) ,  x )

Parameters for statements or functions are separated by commas.
 

PRINT "HELLO ", "THERE"

A function in a command set is allowed to be used without parenthesis if the return value is ignored, that is to say not assigned to a variable.
 

OPENFILE myfile, "C:\\temp.txt", "W"
error = OPENFILE(myfile, "C:\\temp.txt", "W")

 

Resolving syntax conflicts

For compatibility with other languages parameter-less functions are allowed to be used without parenthesis for simple assignment operations and as an argument to another function if used by itself. For example TIMER is actually a function and the correct syntax for using it would be:
 

i = TIMER( )
PRINT TIMER( )

However the compiler will allow:
 

i = TIMER
PRINT TIMER

When a parameter less function is itself used as an argument to another function or command the compiler may generate a "wrong number of parameters" error.  This commonly occurs if a subtraction operation is performed on the value returned from a parameter less function.
 

' this produces an error
PRINT TIMER-1

The error can be resolved in two ways. Use an empty parenthesis set for the function or surround the parameter less function with parenthesis. The former is the preferred method
 

PRINT TIMER( ) - 1
PRINT (TIMER) - 1

Source comments

Comments will show up as green text in the editor and are ignored by EBASIC.  Comments are great for documenting your code so you can more easily understand what you wrote when you come back to it after a long period of time. The EBASIC compiler supports single line and block comments

Single line comments begin with either a single quote mark or the REM statement
 

REM this is a comment and will be ignored
'this is also a comment

Block comments, sometimes referred to as 'C' style comments begin with a /* character sequence and end with the */ character sequence. Block comments may extend across as many lines as necessary
 

/* this is a very long
comment. all of this will be
ignored by the compiler and is
very convenient when we have
complex code to document */