Compilers seemed me extremely difficult and available books not in the least did not change
this presentation. But I wanted to understand, how they work. In 1994 I tried to write a compiler.
And though I was able to get something working for a month and between the deal, this was
a long way. The first version (0.5) was written on Pascal language (Borland). It was not
too well thought-out and one year ago I completely rewrite it (on C language). In the result
I got simple and expressive (as I think) language and corresponding compiler. Later I
translate my compiler from C language to it's own input language and write a simple assembler.
After 1997 I add object-oriented extension and correct several mistakes. Here You may view and
download language description, source codes and executable files. In the description I tried to
show that decision of problem is not extremely difficult. Word-combination "formal grammatics"
is meet only once upon a time and that sense, that knowledge of these words is not require
(I at all not against the science, but suppose, that begin is necessary with simple).
Each appearance of identifier in the text assumes its value. For the address
calculation operator @ must be used.
Number of operations with pointers (references) are limited, possible only
dereference (tacit and by means of square brackets), comparison with NULL
(equal/not equal) and assignment.
Local variables are to be described in any place of functions, each valiable
can be referenced from the place of description to the end of block, in which
(before the end of cycle etc.).
There are no internal functions.
Using of delimiter "semicolon" is reduced. It use only for termination of
struct and functions descriptions and termination of assignments.
First point is most important. If reference @P defined (for example,
reference to char), P means a char, @P - means an address of char,
and @@P - means an address of reference.
void - empty type
char - symbol
byte - byte (unsigned)
word - word (unsigned integer)
int - signed integer
real - floating point number
Boolean datatype also present, but variables of this type are not
allowed. There are limited support of real datatype in version 1.2
(context.sim, FPU required - NOT TESTED!).
Only one way to define you own datatype is define the structure:
section // variant part
Operator @ show that variable is reference to data. For example:
char @PC; // reference to char (and to array of char's)
char @@PP; // reference to (reference to char)
Number of @ is reference power.
Type_name [@[@[...]]]Function_name(Type_name [@[@[...]]]Parameter_name[, ...])
Declarations of fynctions are allowed. This allows to use indirect recursion.
define @S "String" // reference to string
define C1 'C' // char
define C2 #10 // char
define M 16 // number
define N $10 // number (hex)
Global variables description
Main function (begin)
Operators (in order of priority, from lowest to highest):
| or (boolean and bitwise)
^ exclude or (boolean and bitwise)
& and (boolean and bitwise)
<= less or equal
!= not equal
>= greater or equal
% calculation of the remainder from division
! not (boolean and bitwise)
@ calculation of object reference (address)
 indexation and dereference
Assignment to variable or function parameter are possible in following cases:
If references powers of both operands equals to zero and source datatype can be
converted to dest datatype.
If one of operands has datatype void and its reference power is equal to one,
reference power of other operand equal or greater to one.
If one of operands has void datatype and reference powers of both operands are
greater then zero and equals.
If datatypes and reference powers of both operands are equal.
There are some control statements:
if Boolean_expression then
Select from many choices:
while Boolean_expression do
loop // Jump to beginning of cycle
exit // Exit from cycle
while TRUE do
Returns from function:
return Expression; // Returm value
return // Return from void function
inc Variable_name; // Increment by 1
dec Variable_name; // Decrement by 1
asm OpCode [Operands]
Are to be use in any place of functions, In given version using the variable
names not allowed. Mistakes are not reveal.
For the definition of class old keyword "struct" is used, only single
inheritance allowed (i.e. derived class can be build on the base of only
one base class), variant part (section) not allowed in classes:
struct Class_name [(Base_class_name)]
Type_name [@[...]]Method_name([parameters]) [virtual];
// Method implementation
Type_name [@[...]]Class_name.Method_name([parameters]) [virtual]
In method implementation available two predefined references:
Base_class_name @base; // Only for derived classes
Assignment of reference to derived class to the reference to base class is
possible, for example
struct CDerived (CBase)
Constructor of class instance only implicit, its single function - an
initialization a reference to the virtual methods table (VMT) and calling
the constructors for class members. Constructor is called automatically for
each declared class instance. Object-oriented extension are implemented
in version 1.2
There are no way to create class instance dynamically in this version. One
of possible ways is using of type cast:
CClass @P=@CClass(@GetMem(sizeof CClass));
First name of my compiler was mix8086. How has appear a name Context I presently can
not recall. Word Itself a context (from lat contextus - a join, relationship) means
comparatively complete fragment of written or spoken speech (text), which general sense
allows to elaborate a value separate fall into it words, expressions etc. (Soviet
encyclopedic dictionary, 1980). As I think, this name at all not bad...