If You come here not accidentally, please answer to my
questions about programming languages.
If You come here not accidentally, please answer to my
One more sample - a compiler context.bin. This is base version of compiler for DOS creates COM-file without assembler and support two sets of keywords. Near a year back I thought on changing part of the words (if/then/elseif/else instead of select/case, do ... end
instead of while TRUE do ... end, const instead of define, := instead of = for the assignment, empty operator null) and reject nearly all of them - in future Windows version will only do ... end, null and, can be, second assignment operator.
Built-in assembler will recognize only db command. Structure
context.bin is similar to structure of base version, but it several more complex - there are no sense to made large changes in the old text, future version for Windows will be more simple...
Compiler, assembler and samples update. Initial version of compiler are replaced
to small version. To compile all samples OO-version of compiler (context.sim)
must be used. Multi-pass assembler now unavailable - use one-pass assembler.
Some minor changes in compiler structure are made. Some bugs fixed:
code for 8bit register inc/dec (asm8086)
code for real numbers comparison
unbalanced comments handling
OOP sample (objects.ctx) now works correctly
some other minor bugs
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.
Object-oriented extension (context 1.2):
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
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.
Assignment of reference to derived class to the reference to base class is
possible, for example
struct CDerived (CBase)
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...