Skip to content

2. Language Description

6502Nerd edited this page Oct 5, 2021 · 7 revisions

Overview

dflat has a simple BASIC-like structure which takes inspiration from BASIC dialects on machines such as BBC, Atari and Oric, with some Pascal and C parts thrown in.

A big difference from BASIC is that dflat is procedural - all executed statements have to be inside a procedure definition. In addition, dflat provides structured flow control and no support for GOTO or GOSUB like all BASICs from the early 80s.

But you will still see line numbers - why? Line numbers in dflat are used to order statements in memory, just like in regular BASIC.

Example

Best to show the dflat approach with a simple and time honoured example of Hello World..

  • 100 def_hello()
  • 110 println "Hello, world"
  • 120 enddef

So what's going on here is;

  • Line 100 defines a procedure called _hello which takes no parameters (parameters and variables we'll cover later)
  • Line 110 prints a string literal followed by a new line
  • Line 120 indicates the end of a definition

To invoke this routine, from the command line, one types _hello() (notice no line number) which will result in the message being printed. Notice the use of the underscore character; all user procedure names in dflat must start with this.

Also note that dflat is case sensitive so _hello is different to _Hello

The BASICs

Ok, let's get the core language principles explained, then the next page(s) will explain the detail and then the features.

Line numbers

As seen from the example, dflat needs line numbers to order program statements, but is their only purpose - they cannot be referred to. From the command line, typing a line number then a program line will store that line in the expected order. And like BASIC, a program line entered without a line number will be executed immediately, as per the example above.

Data types

There are three types of data in dflat; integers, characters, and strings;

Integers

dflat uses 2 byte signed integers as its core number format, which means numbers are in the range -32768 to +32767. Integer constants can be expressed in decimal, hex or binary format using C style syntax e.g. the follow all are the same number;

  • 15 (decimal)
  • 0xf (hex)
  • 0b1111 (binary)

The following expression operators are available on integers in order of precedence (where equal, always evaluated left->right);

  • () : brackets
  • * / \ : integer multiply, divide, modulus
  • << >> : bit shift left, shift right
  • + - : integer addition, subtraction
  • & | ^ : logical (bitwise) AND, OR, EOR
  • <= >= < > <> == : boolean less than or equal, greater than or equal, less than, greater than, not equal, equals

It is important to note that the boolean operators evaluate to -1 (0xffff) for true conditions and 0 (0x0000) for false.

Variables

dflat has two types of variable; integers and strings, with arrays of either type being allowed.

Variables names are case sensitive and start with a letter then any number of letters and numbers. Variables don't have to declared before first use.

The default type of a variable stores a 2 byte signed integer and simple variables can be used when needed. Arrays of integers up to two dimensions can be used, but must be declared in advance.

String variables have a special $ postfix in the name to identify them as such. Also, they must be declared in advance with a maximum size like an array. Arrays of strings are allowed by declaring two dimensions.

The following examples clarify (note this is to show syntax - you cannot access arrays in immediate mode unless all statements are on a single line; more explanation later in the arrays section):

  • a=1 creates a new variable called a (if doesn't exist already) and assigns it to the expression
  • dim b[10] declares an array called b with 10 elements. NOTE: Array indices start at 1 not 0
  • b[1]=1 stores a value in to the first element of array b
  • dim c$[10] declares a string called c with 10 characters. NOTE: this needs to include the zero terminator
  • c$="Hello" copies in to c$ the string expression (in the example, just a literal)
  • dim d[5,7] declares an integer array called d with 5 columns and 7 rows
  • dim e$[10,30] declares a string array called e$ containing 30 strings of 10 characters (* contrast with integer arrays *)