Making a Programming Language From Scratch/Simple Data Types

Simple Data TypesEdit

What does 'Simple Data Types' mean? The term refers to data types such as float, int and char declared in single format. Thus this type of data declarations exclude arrays and structures which are covered later.

Format for Simple Data Declarations

[further definitions] type of variable variable name 1 [,(or);] [variable name 2] ...
[further definitions] can be:
type of variable can be:
variable name can be any ASCII character(in some languages Extended-ASCII or UTF-8) beginning with an alphabet(A-Z)(a-z)

Assembly equivalents for common data typesEdit

Assembly language , however does not recognize these data types. In fact, there is no distinction between an int and a char, or even between an int and a float (just that float variables are stored in a different format).

Assembly language does not recognize static, local or extern variables. All variables declared in the BSS or DATA section are static and all variables declared with Macro LOCAL are local. Local variables are declared in CODE sections

Also you cannot declare more than one variable in one logical line. Assembly language recognizes the following type of variables:

BYTE(equivalent to char)(takes 1 byte)
WORD(equivalent to short int)(takes 2 bytes)
DWORD(equivalent to int)(takes 4 bytes)
QWORD(equivalent to long int)(takes 8 bytes)
TBYTE(equivalent to long long int)(takes 10 bytes)
REAL4(IEEE format)(equivalent to single float)(takes 4 bytes)
REAL8(IEEE format)(equivalent to double float)(takes 8 bytes)
REAL10(IEEE format)(equivalent to long double float)(takes 10 bytes)

The first group is the integer group which store non-fractional data
The second group is the fractional group which stores fractional data


1.Scan for identifiers
 1.1 If "static" set static flag 1
 1.2 Else static flag 0
2.Scan for data type
 2.1 If "int" set int flag 1
 2.2 If "float" set float flag 1
 2.3 If "char" set char flag 1
3.Until ',' or '=' or ';' is encountered, get character and store in name array
  3.1.1. If Float flag set write name and "real8"
  3.1.2. If Int flag set write name and "dword"
  3.1.3 If Char flag set write name and "byte"
  3.2.1 If '=' Until ',' or ';' is encountered get character and store in value array Write value after type 
  3.2.2 If ';' terminate process
4 Repeat step 1

Sample ConversionsEdit

Original Code:

int a,b,c;

Resultant Code:

a dword ?
b dword ?
c dword ?

Original Code:

int a=1,b=2,c=3;

Resultant Code:

a dword 1
b dword 2
c dword 3

Note: All uninitialized variables are to be declared in the .BSS or .DATA? section while all initialized variables are to be stored in .DATA section. All local variables are to be declared in .CODE section in the following format

LOCAL [name of variable] [type of variable]