Technical Capabilities
Having trouble finding what you need?
Get in touch with us, so we can answer your specific questions directly.
Get In Touch

VX/BASIC – OpenVMS BASIC to ANSI C

Overview

VX/BASIC is a source-to-source translator that reads VAX and OpenVMS BASIC and emits ANSI C. It is not an interpreter and not a direct-to-machine-code compiler: the generated C is compiled by the host's own toolchain (gcc, clang, or cl) and linked against the VX/BASIC runtime library, producing a native executable for Linux, Windows, or macOS that keeps VAX BASIC semantics intact.

Because C is used as an intermediate language, the migrated application stays portable and can be maintained, built, and debugged with standard modern tools. Descriptor-based strings, RECORD and MAP memory layout, packed DECIMAL arithmetic, RMS record I/O, and ON ERROR handling are all preserved, so an application behaves the same way after conversion as it did on OpenVMS.

Architecture and translation model

VX/BASIC is a translator plus a linked runtime library. The driver reads a BASIC source file and emits ANSI C; that C is then compiled by the host C compiler and linked against the VX/BASIC runtime (libvxbas) to produce a native executable. The translator and the runtime are decoupled: the runtime is callable from any C program that includes the master runtime header, so a hand-written runtime call produces the same result as a translated statement.

Compilation pipeline

By default the driver runs its preprocessor first, then translates to C. The generated C is ordinary source that any modern toolchain can build and debug:

Input
foo.basVAX BASIC source
01bppExpands %INCLUDE, %IF, and %LET, producing foo.bas.p.
02vxbasicTokenises the intermediate, builds the symbol table, and generates ANSI C as foo.c.
03Host C compilercc, clang, or cl compiles foo.c into foo.o.
04Linkcc -lvxbas -ll -lm links the object with the VX/BASIC runtime and support libraries.
Output
fooNative executable with VAX BASIC semantics intact

The -a option turns off the separate preprocessor pass and lets the translator handle % directives directly; -g and -G collapse the whole pipeline by handing the generated C to the bundled host-compile scripts. Input is normally .bas or .BAS (also .sb for embedded SQL and .bp2 for BASIC-PLUS-2); output is .c by default.

Component map

ComponentRole
Translator driverEntry point, option scan, file open, and the top-level translate loop.
Reserved-word tablesPer-letter keyword tables mapping each BASIC keyword to its code-generation action, C name, and parameter shape.
Expression evaluatorOperator-precedence expression tree covering arithmetic, relational, logical, and concatenation operators.
Statement code generatorsOne action routine per keyword for control flow, OPEN/GET/PUT, PRINT, records, declarations, and structured error handling.
Name manglerRewrites BASIC identifiers (with $, %, ., and ::) into legal C identifiers.
PreprocessorHandles %INCLUDE, %IF/%ELSE, %LET, %VARIANT, and CDD %FROM %CDD extraction.
C runtime libraryDescriptors, RMS record I/O, packed-decimal math, and the error stack, delivered as libvxbas.
Master runtime headerType aliases, statement macros, and runtime prototypes that every generated C file includes.
C as the intermediate language. Because the translator emits readable C rather than opaque binary, the migrated application is portable to any platform with a C compiler and can be inspected, built, and debugged with standard tools. The current line is VX/BASIC V8.6.

Source language coverage

VX/BASIC targets the full VAX and OpenVMS BASIC language. Every keyword maps to a code-generation action in the translator's reserved-word tables. The groups below summarise the statement coverage; the one documented exclusion is the graphics family (see Compatibility).

Statement groups

GroupConstructs
Flow controlIF/THEN/ELSE/END IF, FOR/NEXT/STEP, WHILE, UNTIL, SELECT CASE/CASE/OTHERWISE/END SELECT, GOTO/GO TO, GOSUB/RETURN, ON n GOTO/GOSUB, STOP, END, EXIT, ITERATE, CONTINUE.
SubprogramsSUB/SUBEND/SUBEXIT, FUNCTION/FUNCTIONEND/FUNCTIONEXIT, DEF/DEF*/FNEND, CALL, PROGRAM.
Error handlingON ERROR GOTO, ON ERROR GOTO 0, ON ERROR GO BACK, WHEN ERROR IN / END WHEN, WHEN ERROR USE, HANDLER / END HANDLER, RESUME, RETRY, CAUSE ERROR n.
RMS file I/OOPEN, CLOSE, GET, PUT, FIND, DELETE, UPDATE, READ, WRITE, FIELD, LSET, RSET, RESTORE, UNLOCK, NAME AS, KILL. OPEN ... ORGANIZATION supports sequential, relative, indexed, and virtual.
Terminal I/OPRINT, INPUT, LINPUT, INPUT LINE, INKEY$, MARGIN, NOMARGIN, EXTEND, NOEXTEND, SET.
StorageMAP, REMAP, COMMON/COM, DIM/DIMENSION, FREE, RECORD, RANDOMIZE, WAIT, SLEEP.
Program controlCHAIN, CHANGE, RUN, MAT, MID$ (statement form).

Operator precedence

The expression evaluator preserves BASIC precedence, from highest to lowest:

** / ^ (power)
unary – / + / NOT
* / /
+ / – / & (concat)
relational (= <> < > <= >= EQ NE LT GT LE GE)
AND
OR / XOR
IMP / EQV

Integer bitwise operators (EQV, DIV, IMP, MOD, XOR) are emitted as runtime macros that cast their operands to 32-bit integers, matching VAX BASIC semantics.

Intrinsic functions

Around ninety intrinsic functions are supported, each mapped to a runtime entry point. Representative coverage:

LEFT$
RIGHT$
MID$
SEG$
LEN
INSTR
POS
EDIT$
FORMAT$
NUM$
STRING$
SPACE$
CHR$
ASCII
VAL
TRM$
XLATE$
DATE$
TIME$
INKEY$
ABS
SIN
COS
TAN
ATN
LOG
LOG10
EXP
SQR
INT
FIX
MOD
MAX
MIN
SGN
RND
ERR
ERL
ERT$
RMSSTATUS
VMSSTATUS
STATUS
LBOUND
UBOUND
LOC
SWAP%
GETRFA

Data types and C mapping

Every VAX and OpenVMS BASIC data type maps to a fixed-width ANSI C type sized to match the original storage, so record layouts and arithmetic keep their exact widths after conversion. The table below is the accurate mapping used by the translator.

BASIC typeBitsC type emitted
BYTE8int8_t
WORD16int16_t
LONG32int32_t
INTEGER (default width)32int32_t
QUAD64int64_t
SINGLE32float
DOUBLE64double
GFLOAT64double
HFLOAT128double (converted, with a warning)
DECIMAL(p,q)up to 31 digitspacked-BCD decimal struct
STRING (dynamic)descriptor + dataVMS string descriptor pointer
STRING(n) (fixed)descriptor + nVMS string descriptor pointer (fixed class)
RFA48unsigned char[6] (RMS Record File Address)
ADDRESS64void *
LONG is 32-bit. LONG maps to int32_t, and INTEGER defaults to the same 32-bit width (settable with -ib, -iw, -il or OPTION SIZE). The 64-bit integer type is QUAD, which maps to int64_t. Integer types are signed, matching VAX BASIC integer semantics.

Strings and descriptors

Every BASIC string lives in a VMS string descriptor rather than a bare C buffer. The translator emits a descriptor pointer for each string parameter, and the runtime owns the descriptor pool and performs allocation and release. Both dynamic strings and fixed-length STRING(n) strings are supported, which is what keeps migrated code compatible with VAX BASIC string memory management.

Floating-point note. GFLOAT and HFLOAT are converted to 64-bit double on non-VMS hosts. HFLOAT loses precision in this conversion and the translator emits a warning; there is no native 128-bit H-float on the target platforms.

Records, maps, and parameter passing

RECORD, VARIANT, and MAP are the constructs that make VAX BASIC memory layout exact, and they are the most load-bearing part of a faithful translation. VX/BASIC lowers each of them into C types that reproduce the original byte layout, so a migrated program sees the same bytes at the same offsets as it did on OpenVMS.

RECORD and VARIANT become struct and union

A RECORD becomes a typedef'd C struct. A VARIANT becomes a union, and each CASE within it becomes a nested struct, so overlapping fields share storage exactly as they do under VAX BASIC.

RECORD ACCOUNT_REC
    VARIANT
        CASE
            WORD  BRANCH_ID, PRODUCT_CODE
            LONG  ACCOUNT_NUMBER, BALANCE_CENTS
        CASE
            LONG  RAW_KEY
    END VARIANT
END RECORD

translates to:

typedef struct {
    union {
        struct {
            _Word BRANCH_ID;
            _Word PRODUCT_CODE;
            _Long ACCOUNT_NUMBER;
            _Long BALANCE_CENTS;
        } case1;
        struct {
            _Long RAW_KEY;
        } case2;
    } var1;
} ACCOUNT_REC_2__;

Note that _Word is 2 bytes and _Long is 4 bytes, so the layout is byte-for-byte what VAX BASIC produced.

MAP overlays share one backing store

Several MAP declarations that name the same program section describe the same storage viewed different ways. VX/BASIC emits one struct per declaration and binds all of them to a single backing block, so a write through one view is visible through the others.

MAP (STMT) STRING STMT_RAW = 80
MAP (STMT) LONG STMT_ACCT, STMT_SEQ, STMT_AMOUNT
static struct Tag_MAP_STMT    { char sSTMT_RAW[80]; }                        *MAP_STMT;
static struct Tag_MAP_STMT_1  { _Long pSTMT_ACCT; _Long pSTMT_SEQ; _Long pSTMT_AMOUNT; } *MAP_STMT_1;

union { char data[sizeof(struct Tag_MAP_STMT)]; long align; } STMT;

Vxb_PsectInit_1((void *)&MAP_STMT,   "STMT", & STMT);
Vxb_PsectInit_1((void *)&MAP_STMT_1, "STMT", & STMT);

Both struct pointers are bound to the same STMT byte block, so writing through MAP_STMT_1 and reading through MAP_STMT sees the same bytes. This reproduces VAX BASIC's MAP-overlay memory model exactly. MAP DYNAMIC allocates on first reference and keeps the largest requested size; MAP STATIC becomes a BSS allocation.

Parameter passing

BASIC defaults to calling by reference. VX/BASIC preserves the BY VALUE and BY REF mechanism, passing literals by reference through a constant pool where needed.

EXTERNAL LONG FUNCTION CALC_INTEREST(LONG BY VALUE)
EXTERNAL LONG FUNCTION POST_LEDGER(LONG BY REF)
EXTERNAL LONG FUNCTION AUDIT_ENTRY(LONG)      ! unmarked LONG defaults to BY REF
result = calc_interest(1);          /* BY VALUE: pass the int directly        */
result = post_ledger(LCon(1, 1));   /* BY REF:   pass address of pooled constant */
result = audit_entry(LCon(1, 1));   /* unmarked LONG defaults to BY REF          */

LCon(n, v) writes value v into constant-pool slot n and returns its address, which is how a literal is passed by reference. The LONG result field is a 32-bit integer, consistent with the type mapping above.

Runtime model and error handling

The generated C calls into libvxbas, the VX/BASIC runtime. The runtime provides descriptor-based strings, RMS record I/O, packed-decimal arithmetic, and the error stack. Each BASIC intrinsic maps to a runtime entry point named Vxb_ followed by the routine name; translator-emitted helpers that never appear in user code use the Vxbf_ prefix.

Runtime entryPurpose
Vxbf_initializeMaster program initialisation: dialect selection, argument vector, decimal scale and rounding, and signal handlers.
Vxb_Open / Vxb_Close / Vxb_CloseAllRMS channel open and close.
Vxb_Get / Vxb_Put / Vxb_Find / Vxb_Update / Vxb_DeleteRMS record operations.
Vxb_Print / Vxb_Input / Vxb_LineInput / Vxb_InkeyTerminal I/O.
Vxb_Left / Vxb_Right / Vxb_Mid / Vxb_Instr / Vxb_FormatString intrinsics.
Vxb_Decimal / Vxb_Sum / Vxb_Prod / Vxb_QuoPacked-decimal arithmetic.
Vxb_Err / Vxb_Erl / Vxb_Ert / Vxb_RmsStatus / Vxb_VmsStatusError introspection.
Vxbf_OnError_GoTo / Vxbf_Resume / Vxbf_RetryON ERROR and RESUME machinery.

The runtime exposes just under two hundred distinct entry points. It is ordinary C, so the same runtime call a translated program makes can be called directly from hand-written C that includes the runtime header.

Error handling

VX/BASIC preserves VAX BASIC error semantics so a migrated program behaves identically when it hits an error. ON ERROR GOTO is lowered onto the runtime's error machinery, which maintains a parent-linked context chain, sets a jump target per subprogram, and unwinds to the handler when an error is signalled. RESUME and RETRY resume execution, and the structured WHEN ERROR USE and HANDLER forms are supported with up to ten levels of nesting.

Programs introspect errors with ERR, ERL, ERT$, RMSSTATUS, and VMSSTATUS, exactly as on OpenVMS. RMS status values carry through as well: for example, the OpenVMS "file not found" condition (value 98962) is the same value a migrated program sees, so return-value checks on system routines keep working without modification.

System services. When a program calls OpenVMS system routines and checks their return values, VX/BASIC backs that behaviour with the VX/RT runtime libraries and the bundled system-symbol headers, so status codes and RMS behaviour match the original.

Command-line reference

The translator is driven from the command line. Each short option has a DCL-style long form for developers used to OpenVMS qualifier syntax. The highest-value flags are listed below.

ShortDCL formEffect
-a/NOPREPROCESSDo not run the preprocessor as a separate pass; the translator handles % directives directly.
-c/BOUNDSEmit runtime array-bounds checks.
-C/CDDTreat the data definition as new-CDD format.
-ds / -dd/REAL_SIZE=SINGLE|DOUBLESet the default real type.
-ib / -iw / -il/INT_SIZE=BYTE|WORD|LONGSet the default integer width.
-g / -G/GO / /EXEC_GOAfter translating, run the bundled host-compile script.
-k/NATIVE_ACCESSEmit direct C MAP-field access instead of descriptor accessors.
-L/LISTEmit a .lst listing.
-nN/SCALE=NSet the DECIMAL scale factor.
-q/SQLTreat the module as embedded SQL and emit Pro*C / ESQL-C output.
-R/ROUND_DECIMALSRound rather than truncate DECIMAL values.
-T/LARGE_KEYSAllow RMS index keys longer than 255 bytes.
-u/PREPROCESS_ONLYRun only the preprocessor and exit.
-vN/VARIANT=NSet the preprocessor %VARIANT value.
-x/EXTERNALForce an EXTERNAL module with no main() emitted.

Environment controls

Translator behaviour can also be set through environment variables, including VXB_OPT, VXB_GO, VXB_LOWER_FUNCTION_NAMES, VXB_LOWER_MAP_NAMES, VXB_USE_RECORD_COPY, and VXB_USE_DESCR64.

Exit codes

CodeMeaning
0Success.
1Completed with errors.
98962Could not open the input source (the OpenVMS RMS "file not found" condition value).

Compatibility and status

The core language, RMS I/O, descriptor strings, packed DECIMAL, and structured error handling are fully supported. A small number of features are converted with a documented trade-off, and a few OpenVMS-specific constructs are out of scope. The matrix below records exactly one status per feature.

FeatureStatusDetail
Core language: types, flow control, SUB/FUNCTION, DEF, RECORD, MAP, COMMONliveFull coverage with byte-exact layout.
RMS I/O: sequential, relative, indexed, virtualliveAll four file organizations supported.
Descriptor strings (dynamic and fixed)liveVMS string descriptors preserved.
Packed DECIMAL arithmetic (up to 31 digits)liveScale and rounding controllable with OPTION SCALE, -nN, and -R.
Structured WHEN ERROR USE / HANDLERliveUp to ten levels of nesting.
HFLOAT (128-bit H-float)partialConverted to 64-bit double with a warning; precision is lost.
GFLOAT on non-VMS hostspartialEmitted as double; there is no native G-float on the target platforms.
MAT matrix familypartialBasic forms work; mixed integer and decimal operands are rejected.
Embedded SQL (-q, Pro*C / ESQL-C)partialRequires an Oracle Pro*C toolchain on the host.
OPTION ANGLE = DEGREES / RADIANS / GRADSout of scopeTrigonometry is always in radians.
GRAPHICS family (DRAW, PLOT, ROTATE, ...)out of scopeRecognised but not translated; this is the documented "all commands except graphics" exclusion.
Maintain in place, or convert. Because the translation preserves structure, variable names, and comments, an application can continue to be developed in OpenVMS BASIC and re-translated on each release, or converted once and maintained as C. Either path keeps the same behaviour on Linux and Windows.

Quick reference

Invoke

vxbasic file.bas [-options]   ! produces file.c
vxbasic file.bas -g           ! translate then auto-compile
vxbasic file.bas -L           ! also emit a .lst listing
vxbasic file.bas -u           ! preprocess only

Type map

BYTE = int8_t
WORD = int16_t
LONG = int32_t
QUAD = int64_t
SINGLE = float
DOUBLE = double
GFLOAT = double
HFLOAT = double
DECIMAL = packed BCD
STRING = descriptor
RFA = uchar[6]
ADDRESS = void *

Translation rules

RECORD -> typedef struct
VARIANT / CASE -> union / struct
MAP overlays -> parallel structs on one store
intrinsic X -> Vxb_Xxx
helper -> Vxbf_*
ON ERROR GOTO -> Vxbf_OnError_GoTo

Error introspection

ERR
ERL
ERT$
RMSSTATUS
VMSSTATUS
STATUS

Frequently Asked Questions

Curious about how Sector7 can facilitate your application migration? Explore our FAQs for expert insights.

Our OpenVMS application makes use of multiple System Services. How do you support that?

Sector7 has an extensive library of these services running on Linux to perform the same functions as on OpenVMS.  our language conversion tools will adapt the arguments in the procedure API to work with this library.  For instance, VX/COBOL or VX/FORTRAN etc will transform the argument passed BY DESCRIPTOR to a method that will work on Linux.

When the code is compiled on Linux, the compiled objects are linked with the Sector7 library of system services and the program executes on Linux just as it does on OpenVMS, making full use of the various system services.

The critical point here is that there is no need to touch the original source code, the Sector7 tools do all the work.

What is VX/BASIC and how does it help with legacy system migration?

VX/BASIC is a full-featured OpenVMS BASIC to ANSI C transpiler that enables legacy BASIC applications to run natively on Linux. It converts VMS BASIC syntax to working C code (the graphics command family is the one documented exclusion) while maintaining the original structure, variable names, and comments for easy maintenance.

For organizations ready to modernize their legacy systems, contact us to discuss your specific migration requirements.

How many VMS system service calls does VX/BASIC support?

VX/BASIC programs that call OpenVMS system routines are backed by the VX/RT runtime libraries, which replicate over 900 OpenVMS system service and run-time calls, including RMS file handling and other system services.

What makes VX/BASIC different from rewriting applications from scratch?

VX/BASIC maintains the original BASIC source code structure while generating readable ANSI C code, allowing developers to continue working with familiar BASIC syntax. The transpiled C code retains the original program flow and variable names, making debugging and maintenance much easier than completely rewritten applications.

What are the key benefits of using VX/BASIC for migration?

VX/BASIC converts VMS BASIC to ANSI C that keeps VAX BASIC semantics, with the graphics command family the one documented exclusion. Organizations retain their valuable software investments while moving to modern, portable infrastructure.

The generated ANSI C is built with the host's own toolchain, so it can be maintained, built and debugged with standard modern tools.

Ready to explore migration options for your BASIC applications? Contact us to discuss your specific requirements.

What does VX/BASIC produce, an interpreter or C source?

It translates VMS and OpenVMS BASIC into ANSI C source and then compiles that C. C is used as an intermediate language, which is what gives the output long-term portability and lets it build, run, and be debugged directly on modern systems with standard tools.

Which platforms can the converted application run on?

VX/BASIC converts OpenVMS BASIC into C that compiles and runs on Linux and Windows, while still allowing the application to be maintained in its original OpenVMS BASIC form and re-translated on each release.

Which VMS BASIC data types are supported, and how do they map to C?

All VMS and OpenVMS BASIC data types are supported. Integer types map to fixed-width C types (BYTE to int8_t, WORD to int16_t, LONG to int32_t, QUAD to int64_t), SINGLE and DOUBLE map to float and double, DECIMAL maps to a packed decimal type, and STRING maps to a VMS string descriptor. GFLOAT and HFLOAT are converted to double.

Are strings handled the same way as under VMS BASIC?

Yes. VX/BASIC keeps both dynamic and fixed-length string handling and uses VMS string descriptors for STRING data, so migrated code stays compatible with VMS BASIC string memory management.

Will my error-handling logic still work after conversion?

VX/BASIC preserves VMS error codes and the ON ERROR handling model, so programs behave the same as they did on OpenVMS, including RMS errors such as the file-not-found condition. Return-value checks on system routines are backed by the VX/RT runtime libraries, and ERR, ERL, ERT$, RMSSTATUS, and VMSSTATUS are all available for introspection.

How are VMS BASIC records and maps converted?

VX/BASIC fully translates RECORD and MAP declarations into C. A RECORD becomes a typedef'd struct, a VARIANT becomes a union with one struct per CASE, and several MAP declarations that name the same storage become parallel structs bound to one backing block, preserving the exact VAX BASIC byte layout.

Which BASIC statements and I/O operations are covered?

All VMS BASIC statements except the graphics family are supported, including IF...THEN, FOR...NEXT, WHILE, SELECT CASE, GOTO, and ON ERROR GOTO. Terminal I/O such as PRINT, INPUT, and LINPUT is covered, and RMS file I/O supports sequential, relative, indexed, and virtual organizations.

Are there any limitations, for example graphics?

The one documented exclusion is the graphics command family, which is recognised but not translated. GFLOAT and HFLOAT are converted to double rather than preserved exactly (HFLOAT loses precision), and a few OpenVMS-specific options such as OPTION ANGLE are out of scope. Everything else in the core language is supported.

Transform Your Legacy Software Today!

Get In Touch
Unlock the potential of your legacy software with our expert migration services.