Please enable JavaScript to view this site.

A-Shell Reference

Navigation: A-Shell BASIC (ASB) > Expressions

Constants and Literals

Scroll Prev Top Next More

Updated March 2019

Constants are values fixed at compile time and thus immutable during execution. As with all ASB expressions, they come in two fundamental types: string and numeric. Each of these may be created or expressed in various ways as detailed below.

Numeric Literals

These come in the following flavors:

Decimal values (integer or floating point), with optional leading minus sign. Note that the decimal point character is the (American-style) period; commas are not allowed, nor is scientific/exponential notation. Examples:

Decimal values (integer or floating point), with optional leading minus sign and optional trailing base-10 exponent suffix or "L" suffix. In most cases, these constants are stored in the compiled program as floating point values (up to 11 significant digits). The exceptions are that any integer constant with an explicit "L" suffix and any hex or octal value representing more than 32 bits will be stored as 48 bit integers; see History below.  Examples:

25                 ! Good:  decimal integer

-2.3               ! Good: negative decimal floating point

2.3-               ! Illegal: trailing unary minus sign not allowed

12345.67           ! Good: positive decimal floating point

12,345.67          ! Illegal: commas not allowed

1.234E5            ! Good: positive exp notation (e.g. 123400)

98765e-3           ! Good: negative exp notation (e.g. 98.765)

12345678923L       ! Good: L suffix for 48 bit integer

 

Note that although the decimal separator character may be swapped via the LDF file (see LANGUAGE), this only affects the interpretation of numeric expressions input as data at run time; the compiler always uses (requires) the American-style decimal point (period).

Hexadecimal and octal values are denoted with a leading "&h" or "&o" (case sensitive), respectively; e.g.

&h01c8             ! Good: hex 01c4 (456 decimal)

&hFF               ! Good: hex FF (255 decimal)

&o100              ! Good: octal 100 (64 decimal)

&H100              ! Bad: &H not recognized (must be lower case)

&O100              ! Bad: &O not recognized (must be lower case)

&habc12341234L     ! Good: hex abc12341234 stored as 48 bit integer

&hFFABCD5678       ! Good: hex FFABCD5678 48 bit integer (L implied)

 

Single-byte ASCII values are denoted by enclosing the ASCII character in single-quotes, e.g.

A = 'A'            ! Good: ASCII A (65 decimal); same as A = 65

Note that the hex and octal notation described above is also recognized by the various forms of INPUT statements, DATA, and GDI print directives. The ASCII byte notation, however, is not.

String Literals

A string literal consists of text enclosed in quotes, e.g.

"Smiley O'Reilly"

To include a quote character (ASCII value 34) within a string literal, use two of them together, as in these assignments:

TOOL$ = "6"" Wrench"                ! 6" Wrench

GOV$ = "Edmund G. ""Jerry"" Brown"  ! Edmund G. "Jerry" Brown

There is no syntax for embedding control characters or escape sequences directly within literal strings. Instead, such strings must be built using a combination of concatenation and the CHR$(x) function, e.g.:

   ONE'TWO$ = "Buckle" + chr(13)  + chr(10) + "my shoe."     ! (CRLF embedded in middle of string)

Note that the above statement only contains two true string constants, i.e. the literals "Buckle" and "my shoe.". Although the chr() functions are run time operations (not true constants), when given constant (literal numeric) arguments, e.g. chr(13), the result is effectively a constant because there are no variable elements subject to change according to run time logic. The same can be said of the overall expression (three concatenations and two string functions).

Also note that string literals may appear in a variety of auxiliary contexts (e.g. input files, CSV files, DATA statements, tab functions, etc.) where they may or may not need to be quoted. Typically the rule is that quoting is optional except when the string contains problematic characters (e.g. control characters, quotes, delimiters, etc.), in which case quoting is mandatory. See related topics WRITECD, INPUT CSV, Xcall STRTOK, INSTR().

Defined Symbols

These are created by the DEFINE statement and are treated by the compiler equivalently to literal string or numeric constants, depending on whether the symbol name ends in a dollar sign, e.g.:

DEFINE FREEDOM_FRIES$ = "French Fries"    ! define string constant

define FF_COUNT = 25                      ! define numeric constant

? FF_COUNT;FREEDOM_FRIES$;" per serving"  ! this statement compiles to same RUN code...

? 25;"French Fries";" per serving"        ! ...as this statement

 

Symbol names have the same form and syntactic rules as variable names, but to help make them easily identified in source code, a common convention is to use all upper case characters and one or more underlines, as in the examples above.

Defined symbols were not implemented in the original AlphaBASIC. This forced programmers to either use variables or literals as pseudo-symbol workarounds, neither of which was a very satisfactory solution—the former due to the possibility of the variable being changed at run time, the latter due to the lack of clarity in the meaning of the literals in the source code.

Modern ASB programs typically make extensive use of defined symbols, often starting with ++include ashinc: which defines hundreds of symbols relevant to common A-Shell functions, subroutines and other resources.

Defined symbols require the /X:2 compiler switch.

Symbols can also be defined via command line arguments passed to the compiler; see Compiler Symbol Definitions.

Auto-Defined Symbols

These are equivalent to defined symbols (see above) except that they are automatically pre-defined by the compiler. See Auto-Defined Symbols for details.

Compiler Functions

Compiler functions such as .OFFSIZ$, .OFFSET, and .SIZEOF are converted to literals by the compiler.

See Also

History

2016 October, A-Shell 6.4.1533, compiler edit 789:  Automatically treat hex and octal literals as 48 bit if larger than 32 bit. Otherwise store the literal as a floating point unless the L suffix is explicit.

2016 June, A-Shell 6.4.1515, compiler edit 763:  L suffix introduced for 48 bit integer contants

2010 February, A-Shell 5.1.1176:  Hex and octal literals supported in data (INPUT, DATA statements)

2005 March, A-Shell 4.0(923), compiler edit 289:  Added support for octal, hex, and ascii literals