Source code in the editor

The HBasic editor does not store the source code of a HBasic source as a plain ASCII text. Instead it uses a special format with an internal representation for each text line. There were three important reasons to to this. This document describes the format of the source code within the HBasic editor.

Layout of the source code in memory

In HBasic each module (BASIC source compined with GUI description) is stored within a class of type CBasicDocument. This class (source code basic_document.cpp) has a pointer to a memory block that holds the BASIC source code of this module. Within this block each source line is stored between 2 byte that describe the length of the line. This is needed because there are no more carrige return characters or other delimiting signs at the end of a line. At the start and end of the whole source there is an additional byte with content 0xFF. A source code with one text line with a length of 8 Byte would look like the following hex codes when stored in the editor:

0xFF 0x08 <6 Byte line description> 0x08 0xFF

Format of one source line

Each single line of code is made up of the following parts: Valid source code tags All other characters between 0x00..0xFA currently represent ASCII characters.

Flags used in the source line

Each editor line has one flag-byte which will be used to mark special conditions of the source code in the line. This will be used to mark lines that must be parsed in the first compiler phase. In the flag byte the following flags may be used:


Marks the start of a subroutine or method definition. In newer versions this flag is used for all declarations in the source code (SUB, METHOD, CLASS, EVENT...). This is important for the parser which has to recognize all definitions in the first compiler phase. It may become important for the editor if the editor should mark the beginning of a subroutine in a special way or list all subroutines.
Marks the end of a subroutine or other definition.
Marks a line where the parser recognized a syntax error. The advantage of this representation of an error is that moving the source line also moves the error flag. In the error line the error number and column where the error occured will both be stored as a short value in the long value used for debugging in the source line.
This flag is used to mark break lines (lines where the interpreter should stop execution).
Marks the end of a subroutine or other definition.
Marks a line with a dim statement. This is useful for the first parser phase where veriable declarations will be parsed.
Marks a line with an inherit statement. The parser must recognize inherit statements in the first compiler phase.