You are on page 1of 206

Mynx

Programming
Language

May 2006
- 2 -
Mynx Programming Language

 2006 William F. Gilreath


1702 Provost Circle
Picayune, MS 39466
will@williamgilreath.com

- 3 -
- 4 -
Table of Contents
INTRODUCTION TO MYNX AND PROXIMA...................................................... 13
A. Prolog............................................................................................................................................................14
B. Name and Project.....................................................................................................................................14
C. Manifesto.....................................................................................................................................................15
D. Target Platforms ......................................................................................................................................18
E. Principles of Design ................................................................................................................................19
F. Philosophical Statement .......................................................................................................................19
G. Goals..............................................................................................................................................................20

BASIC LEXICAL ELEMENTS.................................................................................. 21


A. Identifiers ...................................................................................................................................................22
B. Keywords.....................................................................................................................................................22
C. Literals .........................................................................................................................................................22
D. Symbols........................................................................................................................................................23
E. Numbers ......................................................................................................................................................23
F. Meta Strings ...............................................................................................................................................24
G. Operators ....................................................................................................................................................25
H. Encoding......................................................................................................................................................26
I. Comments ...................................................................................................................................................26
Single Comments ..................................................................................................................................................26
Multiple Comments ..............................................................................................................................................26
J. Enumerated Types...................................................................................................................................27

THE PRIMARY ELEMENTS: PROGRAM AND CLASS ...................................... 29


A. Program .......................................................................................................................................................30
B. Class ..............................................................................................................................................................30
C. Kinds of Classes ........................................................................................................................................31
D. Abstract........................................................................................................................................................32
E. Constant.......................................................................................................................................................32
F. Default ..........................................................................................................................................................32
G. Generic .........................................................................................................................................................32
H. Singular........................................................................................................................................................32
I. Static .............................................................................................................................................................32
J. Virtual...........................................................................................................................................................32

THE MINOR ELEMENTS: ATTRIBUTES AND METHODS .............................. 33


A. Attributes ....................................................................................................................................................34
Attribute Mode ......................................................................................................................................................34
Attribute Kind........................................................................................................................................................34
Attribute Type .......................................................................................................................................................34
Attribute Name......................................................................................................................................................34
Initial Value ...........................................................................................................................................................35
Attribute Scope......................................................................................................................................................35
B. Program Attributes .................................................................................................................................36
C. Class Attributes.........................................................................................................................................36
D. Methods .......................................................................................................................................................36
Program Methods .................................................................................................................................................37
Class Methods........................................................................................................................................................37
Parameter List .......................................................................................................................................................37

- 5 -
Method Parameter Modes ...................................................................................................................................38
In Parameter Mode...........................................................................................................................................38
Out Parameter Mode ........................................................................................................................................39
Var Parameter Mode ........................................................................................................................................39
Series Parameter Mode ....................................................................................................................................40
Method Traps ........................................................................................................................................................42
Method Scope ........................................................................................................................................................42
E. Class Methods............................................................................................................................................43
Method Mode ........................................................................................................................................................43
Method Synchronization......................................................................................................................................43
Method Return Type ............................................................................................................................................44
Method Headers....................................................................................................................................................44
Undefined Method Header ..................................................................................................................................44

NAMESPACES ........................................................................................................... 45
A. Declaration .................................................................................................................................................46
B. The Default Namespace.........................................................................................................................46
C. Classes and Programs within a Namespace ..................................................................................47
D. Inclusion of Classes from a Namespace..........................................................................................47
E. Multiple Sub-Namespace Inclusion..................................................................................................47
F. Declaration Order for Namespace Inclusion................................................................................48
G. The Mynx Namespace.............................................................................................................................48
H. Nonexistent Namespace Inclusion ...................................................................................................49

INHERITANCE AND CLASS TYPES...................................................................... 51


A. Concept of Inheritance ..........................................................................................................................52
B. Types of Inheritance ...............................................................................................................................52
Null .........................................................................................................................................................................52
Single ......................................................................................................................................................................53
Multiple Virtual .....................................................................................................................................................54
Multiple Disjoint ...................................................................................................................................................55
C. Classes and Inheritance ........................................................................................................................56
D. Inheritance of Attributes and Methods...........................................................................................57
Attributes ...............................................................................................................................................................57
Methods..................................................................................................................................................................58
E. Inheritance of Methods .........................................................................................................................58
F. Method Overriding ..................................................................................................................................58
G. Rules for Method Overriding ..............................................................................................................58
H. Covariant Method Overriding.............................................................................................................59
I. Method Overloading ...............................................................................................................................61
J. Operator Overloading ............................................................................................................................62
K. Class Reference Prefixes .......................................................................................................................62
L. Dottic Access Prefix.................................................................................................................................63
M. Super Class Prefix....................................................................................................................................63
N. This Class Prefix .......................................................................................................................................64
O. Self Class Prefix ........................................................................................................................................65

OPERATORS AND OPERATOR OVERLOADING ............................................... 69


A. Operators ....................................................................................................................................................70
B. Operator Categories: ..............................................................................................................................70
Assignment ............................................................................................................................................................71
Reference Assignment Operator is .................................................................................................................71
Creation Operator as ........................................................................................................................................72

- 6 -
Regular Assignment Operator = .....................................................................................................................72
Cast Operator to ................................................................................................................................................73
Cast Assignment Operator := ..........................................................................................................................74
Dual Assignment Operation Operators..........................................................................................................74
Subtraction-Assignment Operator -= ............................................................................................................75
Multiplication-Assignment Operator *=........................................................................................................75
Division-Assignment Operator /= ..................................................................................................................76
Modulus-Assignment Operator %=................................................................................................................76
Bitwise-And Assignment Operator &= ..........................................................................................................77
Bitwise Inclusive-Or Assignment Operator |=..............................................................................................77
Bitwise Exclusive-Or Assignment Operator ^= ............................................................................................78
Bitwise Shift-Right Assignment Operator >>=.............................................................................................78
Bitwise-Shift-Left Assignment Operator <<=...............................................................................................79
Logical Bitwise.......................................................................................................................................................80
Logical Not Operator !......................................................................................................................................80
Logical Bitwise And Operator &......................................................................................................................81
Logical And Operator &&.................................................................................................................................81
Logical Bitwise Inclusive Or Operator | .........................................................................................................81
Logical Inclusive Or Operator || .....................................................................................................................82
Bitwise Complement Operator ~ ....................................................................................................................82
Bitwise Shift Left Operator << ........................................................................................................................82
Bitwise Shift Right Operator >> .....................................................................................................................83
Logical Exclusive Or Operator ^.....................................................................................................................83
Relational ...............................................................................................................................................................84
Equality Operator == .......................................................................................................................................84
Inequality Operator != .....................................................................................................................................84
Instance Type Of Operator in..........................................................................................................................85
Lesser Than Operator < ...................................................................................................................................85
Greater Than Operator > .................................................................................................................................86
Greater Equal Operator >=..............................................................................................................................86
Lesser Equal Operator <=................................................................................................................................87
Stream ....................................................................................................................................................................88
Insertion Operator <<< ...................................................................................................................................88
Extraction Operator >>> .................................................................................................................................88
Mathematic ............................................................................................................................................................89
Addition Operator + .........................................................................................................................................89
Subtraction Operator - .....................................................................................................................................89
Division Operator /...........................................................................................................................................90
Modulus Operator % ........................................................................................................................................90
Multiplication Operator * ................................................................................................................................90
Exponentiation Operator ** ............................................................................................................................90
Increment and Decrement Operator -- or ++ ...............................................................................................91
Return Types for Mathematical Operators....................................................................................................91
Access .....................................................................................................................................................................92
Method Invocation . .........................................................................................................................................92
Attribute Access `..............................................................................................................................................92
Array Access []...................................................................................................................................................93
Operator Precedence ............................................................................................................................................94
C. Operator Overloading ............................................................................................................................95
Operator Overload Declaration...........................................................................................................................95
Kinds of Overloads................................................................................................................................................95
Implicit Upward Cast ...........................................................................................................................................95
Rules for Operator Overloading..........................................................................................................................97
Table of Operators ................................................................................................................................................99
Standard Method Names for Overloads ..........................................................................................................100
Implicit Hierarchy of Operators........................................................................................................................101

- 7 -
SPECIAL METHODS OF THE CLASS.................................................................. 103
A. Advanced Method Definition and Use ...........................................................................................104
B. Static Methods.........................................................................................................................................104
Kinds of Static Methods .....................................................................................................................................104
Overriding a Static Method ...............................................................................................................................104
Prefix for Static Method .....................................................................................................................................107
Program Methods as Default Static..................................................................................................................108
C. Implicit Static Method .........................................................................................................................108
Inclusion...............................................................................................................................................................108
Reference .............................................................................................................................................................109
D. Method Equivalents: Low Fat Methods.........................................................................................110
Default Parameters by Method Equivalents....................................................................................................111
Export Instance Method ....................................................................................................................................112
Renaming All Class Methods of a Name..........................................................................................................112
Accessor Methods ...............................................................................................................................................113
Implicit Accessor Methods ............................................................................................................................114
Explicit Accessor Methods.............................................................................................................................114
E. Class Creation, Destruction, and Default.....................................................................................116
F. Constructor ..............................................................................................................................................116
Constructor Definition .......................................................................................................................................116
Constructor Invocation ......................................................................................................................................118
G. Destructor.................................................................................................................................................120
Destructor Definition .........................................................................................................................................120
Destructor Invocation ........................................................................................................................................121
H. Default Class Method............................................................................................................................121
Default Method Declaration ..............................................................................................................................122
Default Method Invocation................................................................................................................................122
I. Incomplete Methods .............................................................................................................................123
J. Other Special Methods.........................................................................................................................123

TRAPS ....................................................................................................................... 125


A. Concept of Trap.......................................................................................................................................126
B. Kinds of Traps .........................................................................................................................................126
C. Declaration ...............................................................................................................................................126
D. Invocation .................................................................................................................................................126
E. Handling ....................................................................................................................................................127
F. Propagation..............................................................................................................................................128
G. Unhandled Traps....................................................................................................................................129

GENERIC CLASSES ................................................................................................ 131


A. Parameterized Types ............................................................................................................................132
B. Attributes and Methods.......................................................................................................................132
Attributes .............................................................................................................................................................132
Methods................................................................................................................................................................132
C. Definition ..................................................................................................................................................132
D. Inheritance ...............................................................................................................................................133
E. Instantiation ............................................................................................................................................134
F. Types of Instantiation ..........................................................................................................................134
Global Instantiation............................................................................................................................................134
Local Instantiation..............................................................................................................................................136
G. Inheriting Other Classes .....................................................................................................................136
H. Using an Abstract Self Method Type...............................................................................................136
I. Defining Abstract Methods ................................................................................................................137

- 8 -
STATEMENTS.......................................................................................................... 139
A. Computation ............................................................................................................................................141
Expression Statement.........................................................................................................................................141
Declaration.......................................................................................................................................................141
Expression........................................................................................................................................................141
Postfix ...........................................................................................................................................................141
Assignment ..................................................................................................................................................142
Assign .......................................................................................................................................................142
Create........................................................................................................................................................142
Input-Output ...........................................................................................................................................143
Access ...........................................................................................................................................................143
Attribute ...................................................................................................................................................143
Method .....................................................................................................................................................144
Array .........................................................................................................................................................144
Multiple ....................................................................................................................................................144
Null Statement ....................................................................................................................................................144
B. Error ...........................................................................................................................................................145
Assert Statement .................................................................................................................................................145
Flag Statement ....................................................................................................................................................145
Try Statement ......................................................................................................................................................145
C. Flow of Control .......................................................................................................................................147
Exit Statement .....................................................................................................................................................147
Next Statement....................................................................................................................................................148
Prefix If Statement..............................................................................................................................................148
Return Statement................................................................................................................................................149
D. Repetition..................................................................................................................................................150
For Statement ......................................................................................................................................................150
For Statement over a Range: .........................................................................................................................150
For Statement over an Array .........................................................................................................................151
For Statement over Other Integral Type......................................................................................................151
Until Statement ...................................................................................................................................................152
While Statement..................................................................................................................................................152
Equivalence between While-Until ....................................................................................................................153
Repeat Statement................................................................................................................................................153
Pre-conditional and Post-conditional Loops ..................................................................................................154
E. Selection ....................................................................................................................................................155
Case Statement ....................................................................................................................................................155
If Statement .........................................................................................................................................................156
F. Mutex Statement ....................................................................................................................................158

IMPLIED METHODS.............................................................................................. 159


A. Rules for Implied Methods ................................................................................................................160
B. Declaration ...............................................................................................................................................160
C. Implementation......................................................................................................................................160
D. Implied Method UML ...........................................................................................................................163

OBVIATE METHODS ............................................................................................. 165


A. Rules for Obviating a Class Method................................................................................................166
B. Single Method by Signature...............................................................................................................166
C. Multiple Methods by Method Name ...............................................................................................166
D. Inheritance with a Single Obviate Method ..................................................................................167
E. Using a Class with an Obviate Method...........................................................................................170
F. No Side Effects for Never Obviating a Method ...........................................................................171
G. Reason to Obviate a Method ..............................................................................................................171

- 9 -
ARRAYS .................................................................................................................... 173
A. Array Attributes......................................................................................................................................174
B. Declaration ...............................................................................................................................................174
C. Creation .....................................................................................................................................................174
D. Initialization ............................................................................................................................................175
Implicit Integral Indexed List ...........................................................................................................................175
Explicit Indexed List...........................................................................................................................................175
Using Default Constructor .................................................................................................................................175
Deferred Creation ...............................................................................................................................................176
Initialization with a Constructor.......................................................................................................................176
Null in Declaration..............................................................................................................................................177
E. Using an Array ........................................................................................................................................177
Using an Element................................................................................................................................................177
Using as an Object ..............................................................................................................................................178
Passing as a Parameter.......................................................................................................................................178
F. Array as a Mynx Class...........................................................................................................................178

MYNX FILE TYPES AND TOOLS ......................................................................... 179


A. Mynx............................................................................................................................................................180
B. Myxm ..........................................................................................................................................................180
C. Moxi.............................................................................................................................................................180
D. Myna............................................................................................................................................................180
E. Minx.............................................................................................................................................................180
F. Myxd............................................................................................................................................................181

MUTUAL EXCLUSION........................................................................................... 183


A. Concept of Mutual Exclusion ............................................................................................................184
Thread or Task ....................................................................................................................................................184
Mutex....................................................................................................................................................................184
B. Async and Sync Methods.....................................................................................................................184
C. Mutual Exclusion within a Class Method .....................................................................................185
D. Mutex Statement ....................................................................................................................................185
E. Mutex Expression ..................................................................................................................................186
F. Equivalence of Mutex Statement and Synchronized Method...............................................186
G. Mutex for Operator Overload Method...........................................................................................186

GLOSSARY OF TERMINOLOGY .......................................................................... 189

APPENDIX MYNX GRAMMAR ............................................................................ 195


A. Header Syntax .........................................................................................................................................196
B. Class Syntax..............................................................................................................................................196
C. Class Methods..........................................................................................................................................196
D. Class Attribute.........................................................................................................................................196
E. Class Overload.........................................................................................................................................196
F. Class Method Obviate ...........................................................................................................................196
G. Program .....................................................................................................................................................197
H. Statements ................................................................................................................................................197
I. Expression Statements ........................................................................................................................198
J. Lexical Elements (Scalars, Literals, Identifiers).......................................................................198
K. Comments .................................................................................................................................................199

REFERENCES.......................................................................................................... 201

- 10 -
INDEX ....................................................................................................................... 203

- 11 -
- 12 -
I
Introduction to Mynx and Proxima

- 13 -
A. Prolog

The myriad of programming languages available (and the plethora of programming languages that will be
created long in the future) underscores that for software there is no one universal programming language,
nor that “one size fits all.” Two frequent comments on anything creative, inventive, or new are: “I don’t
see the need” and “why would you want to another one, with so many out there?” Fortunately, as Finnish
composer Jean Sibelius once said, ”No statue has ever been created for a critic.” If the world followed
those views, all software would be in the native machine code for the platform, no need for a new
programming language, and there would be only one out there.

For each programming language, there is often a story, reason, an impetus for the language. Niklaus
Wirth created Pascal out of frustration to the slow standardization of Algol68. Bjarne Stroustrup created
C++ to have the C programming language but with objects. Larry Wall created Perl out of a need for a
scripting language above shell scripts that could handle text with ease. Ada was an attempt by the United
States Department of Defense to make a state of the art language for defense and military projects, and
cut software costs. The reasons and motives for a programming language can serve as a way to understand
the programming language itself within the creator’s context. The “what” of a feature in a programming
language can be less important than the “why” for a programming language.

B. Name and Project

Summary: The Mynx programming language is a general-purpose, modular, portable, high-level, strongly
typed object-oriented programming language.

Project: Proxima is the name of the overall project to implement a new programming language and the
compiler, which uses new methods for compilation into another high-level programming language.

Proxima is named after the star the spacecraft was trying to reach in the movie “Event Horizon” and is
Proxima Centauri. The Sun's nearest known stellar neighbor is a red dwarf star called Proxima Centauri,
at a distance of 4.3 light years away. Like the nearest star to our solar system, the goals are far enough
away but not so far away without some possibility of success.

Programming Language: Mynx is the name of the programming language that is implemented by the
compiler, and is specified with a grammar, design philosophy, and user manual, and programming
language report.

Mynx is an amalgamation of two cat breed names, Lynx and Manx. M+Y+NX (the NX is from both…)

MYNX = Manx + lYnx + NX

The Manx cat has no tail, and the Lynx is a aggressive wildcat…Mynx is meant to reflect qualities of both
names, unusual like the Manx, but still having some of aggressive properties of the Lynx.

- 14 -
C. Manifesto

The primary design criteria and aims for the Mynx programming language that are:

1. Distinguish attributes from methods within a class. Death to the Dead Parenthesis:
myMethod() or stack.pop(). Dottic notation, dot for method invocation, a tic for
attribute access.

2. Eliminate block ambiguity of C {} or bulk Pascal begin...end. Use explicit block


structuring with end structure statement.

3. Separate a class from a program; no kludge class structure with a static main method.
Classes are the building blocks for objects, code re-use, and structuring.

4. No repetition of information in programming language statements. State it once in a


clear form. No Java or C#:

Integer x = new Integer(7);

Int x to 7;

5. Overcome Object as a quasi-generic type in Java, or a void* type in C++, leading to


proliferation of casts. Proxima uses the self-keyword, or a truly generic class. #14

6. No default fall-through behavior in switch statements like C++ or Java, or forcing


code to use goto in C#. Default is exit the specific case of the case statement.

Java:

int x = 0;

switch(x)
{
case 0:
case 1: doZeroOrOne(); break;
default: ;
}//end switch

Mynx:

Int x to 0;

case(x)
as 0,1 is doZeroOne;
else
null;
end case;

- 15 -
7. Eliminate duplication of types, 32-bit int to 64-bit long, 32-bit float to 64-bit double.
No L suffix, or f suffix to indicate if float or long types. Only int and real types, 64-bits.
Also byte type, and enumerated Bool type of true, false.

8. All things are objects, no primitive types that are not objects as in Java, no boxing and
un-boxing of objects as in C#.

9. No nesting of classes or methods.

10. Controlled operator overloading with the ability to lock the overload of a method.

11. More rich control of parameter passing, no default reference pass by value of address
of reference like in Java. Explicit in, out, var, and own passing quantifiers. And
varying parameters with series.

12. Disjoint multiple inheritance to permit code re-use, without just specification of
methods to implement (Java interfaces).

13. Explicit naming of constructor, destructor in classes. Class name is not used as
constructor name in declaration and definition of a constructor.

14. The self parameter to represent class in a generalized way for types. A clone() or copy
method would return self rather than Object that is cast.

15. Create local versions of variables that are not allocated from the heap, and only have
the scope and lifetime of the method. Local or own methods similar to own
parameters.

16. Explicit scope of methods for class attributes and methods for internal visibility.
Dual forms of access control, external to a class, and scope within a class. #9.

17. Concept of levels of programming language compliance, so that the language can be
used in different programming venues, such as embedded where a GUI library is not
required, or in a distributed environment.

Level 0 is the core language, with additional modules written in the language, which
can be built for a platform. proxima.core.*;

18. Everything is a class, no alternative structures, such as interface (in Java) and struct
(C# and C++).

19. No special package or within a module access to class attributes or methods. All
access is private, protect, public.

20. Default method specification for a default behavior of a class. Do not state what is
apparent, such as no return type implies void type.

21. No half-sided statements, what is implicit can be stated explicitly. Java has synchronized,
keyword sync, but not a unsynchronized. C# has var and ref parameters, but no default in
parameter. Synch and asynch for methods, variable and constant for attributes.

- 16 -
22. Method equivalents, if method is overloaded in optional arguments, do not specify
in declaration (C++), or require wrapper methods (Java). i.e.

class example is
public myMethod(int x, int y) is
end myMethod;

//C++
public myMethod(int x, int y=0) is ...
//Java
public myMethod(int x) {
this.myMethod(x,0);
}

//Proxima method equivalent


public myMethod(int x) is to this.myMethod(x,0);
end class;

- 17 -
D. Target Platforms

Mynx is intended to be its own programming language, incorporating features from other programming
languages, and having newly unique features of its own. Mynx is not intended to “clone” either Java or C#,
or another successor language to C++. The major intention is to have a programming language for both
platforms, with a feature set, and conceptual model that is not specific to any platform.

The two major platforms targeted for Mynx are initially the Java platform of the Java Virtual Machine
(JVM), and the .NET Common Language Runtime (CLR). Later, taking advantage of native translations of
Java to machine code, and re-implementing the source generation, other platforms can be targeted, using
C and C++.

Mynx generates high-level source in either Java or C# for the respective platforms. Java is intended to be
as wide an audience as possible, targeting JDK 1.1.x. Another reason for the Java backward compatibility
is to avoid Mynx classes, libraries, and packages from becoming “wrappers” around either
implementation language. Over time, and hopefully with a large audience for contributions, comments,
and input Mynx will develop standard libraries for such things a graphic user interfaces (GUI’s), and other
modules.

C# is used for the .NET platform and is similar enough but not identical to Java to allow mirroring similar
code generation. (Although in theory J# could be used for both...). Depending on the compilation mode,
both Java and C# source can be generated, and then the code compiled to produce byte code or IL code
for either platform. The high-level source code uses classes in modules written in both languages to
“bootstrap” the core class library, and the high-level source implements features of the Mynx
programming language statements, expressions, classes, and programs. Another reason to use source
generation is to leverage the existing compilers for both languages, although a major design goal is to
integrate an open-source free compiler into the Mynx software development kit (MDK).

- 18 -
E. Principles of Design
There are six major design principles upon which the Mynx programming language is based. Those design
principles, not in order of importance, are:

1. Implicit-explicit principle. A programming language should have implicit features that do not
have to be stated, but can be. Too often, programming languages have a feature in the source
code that is stated by not stating it.

2. Implicit minimalist. A programming language should allow implicit features of expression,


without having to always express them. (In C++, a void type is required, even if the method
returns nothing.)

3. Explicitness by user, but not by design. Some programming languages will create implicit
features if not specified. If the user wants to automatically be given a feature, it should be by
the tool, not within the programming language design. (Java gives default null constructor,
C++ gives the copy constructor. Methods in both languages have an implicitly given access
associated.)

4. Consistency of syntax. A programming language should be consistent in syntax, and not have
constant exceptions to rules for different programming language entities or concepts. (C++
the for loop syntax is different from a simple while, and a do-while is very syntactically
different.)

5. Differentiation of entities. A programming language should make different things different in


syntax. (In C++ a destructor is syntactically different from other methods. But in
C++/Java/C# the dot operator ‘.’ is used for both method and attribute access, requiring
either dead parenthesis () or a leading or trailing underscore to distinguish.

6. Expressivity or expressiveness. A programming language is to express functionality in a given


domain, so the syntax should do that, without being cryptic. The syntax should allow the user
to focus on the problem, not the nuances of how to create it. Syntax should be designed for
the user not the compiler, or to create efficient object code, etc.

F. Philosophical Statement

Mynx is a programming language is not meant to be an end unto itself. Mynx follows the idea to
implement software by a user that allows for software within a domain to focus on the domain, and not
the programming language or the platform. Thus, Mynx is an aggregation of concepts, not one concept
that is used by fiat to clarify programming language design issues, often times slavish following of a single
principle to surmount a recurrent problem can create yet another problem.

- 19 -
G. Goals

There are five major goals for the Mynx programming language that are:

1. Pedagogy: A programming language to teach and learn concepts but still usable (i.e., not a toy
language compared to a “real” programming language used in software development.)

2. Pragmatic: A programming language to use current programming ideas and concepts.

3. Platform Portable: A programming language to target two major platforms, Java and .NET,
and be source compatible on both.

4. Practical: A programming language to specify user intention and purpose, to abstractly


reason in the domain of choice, and to compile into an underlying implementation language
(Java or C#) to execute.

5. Personal: A programming language of my own for my use, and as a base to do research into
programming language and software engineering.

- 20 -
II
Basic Lexical Elements

- 21 -
The Mynx programming language Mynx has the elementary building blocks, which are the basic elements
of identifiers, keywords, literals, meta-strings, operators, and comments.

A. Identifiers

Identifiers are case sensitive names that use characters, of any length in Mynx, but with at least one
character. An identifier must begin with a letter character, followed by another letter character, digit, or
underscore.

Example Identifiers:

x – legal, at least one letter character


_1x – illegal, begins with underscore
helloWorld – legal
123myVar – illegal, begins with digit
_variable – illegal, begins with underscore
myVeryLongVariableName – legal

B. Keywords

Keywords are identifiers, but are reserved words for use by Mynx. There are a total of 66-keywords in
Mynx, all except four are used in the syntax of the programming language. The Mynx keywords are:

abstract access all as assert async


case class constant construct covariant default
destruct do elif else end enum
exit flag for generic goto has
if implied in is let loop
method module mutex new next null
out overload own private program protect
public reader repeat return self series
singular static super sync this to
try type until var variable virtual
void volatile when while with writer

The keywords goto and new are not used, but are considered keywords to prevent usage. The use of the
keywords goto and new as the name of a variable, constant, class, or program can be confusing and
misleading. The keywords enum and type are reserved the same reason to avoid confusion in type or
enumeration definition. Since four keywords are not used in Mynx, there are effectively 61-keywords.

C. Literals

Literals are actual data for characters, strings, integers, and real numbers. A literal can be thought of as an
unnamed (not associated with an identifier), anonymous constant of an instance type. Literals are to the
Mynx compiler effectively an anonymous constant, a constant value with no name.

Literal characters with the at-sign ‘@’ or the question-mark ‘?’ are invalid literals, except as a character
literal ‘@’ or ‘?’ or within a string literal. The at-sign ‘@’ is reserved for possible future use in Mynx
possibly as meta-code for classes.

- 22 -
D. Symbols

A literal character is enclosed in single quotes, a string with double quotes. A literal character uses a single
symbol; a string is a sequence of multiple symbols. There are nine special “escaped” character literals that
are delimited with the ‘\’ escape character.

Character Description
\b Backspace
\f Formfeed
\n Newline
\r Carriage Return
\t Tabulation
\u Unicode Prefix
\\ Slash (Escape Character)
\” Double Quote or Parenthesis
\’ Single Quote or Apostrophe

Table of Escaped Characters

The escaped character literals are substituted with the corresponding character symbol in the given
encoding scheme (such as UTF-8, US-ASCII, or Unicode.)

The Unicode escape character indicates a following Unicode character literal, using four uppercase
hexadecimal digits.

Example Unicode escape literals:

\uFF3E – legal
\u2323 – legal
\uffff – illegal, all hexadecimal digits uppercase
\u65535 – illegal, greater than four hexadecimal digits

Example symbol literals:

‘x’ – legal character


‘ ‘ – legal space character
“” – legal empty string
“hello world!!!” – legal string
‘hello’ – illegal literal, character is only one symbol
“123” – legal string
“c” – legal 1-character string

E. Numbers

Numbers are represented without any quotation. A number is either decimal (base 10) or hexadecimal
(base 16); a hexadecimal number is prefixed with the two characters of ‘0X’ and the remaining hex digits
are all uppercase.

- 23 -
A numeric real literal (which is the default for non-integer number literals) is 64-bit, a float is 32-bit, and
is indicated with a trailing capital ‘F’ to indicate a float numeric literal. Both a numeric real and float must
begin with a digit.

123 – legal integer


-123 – legal integer
+73 – legal integer
FFE3 – illegal hexadecimal integer without hexadecimal prefix 0X
3.145 – legal real
0xFF – illegal hexadecimal prefix 0X is invalid
0XFF – legal hexadecimal integer
2.713F – legal float
.333337 – illegal float, must begin with a digit
0XCAFE – illegal hexadecimal integer needs uppercase ‘0X’ prefix

Diagram of Numeric Literals

F. Meta Strings
A meta string is the Mynx partial replacement for the macro system of C/C++. It does not attempt to
replace or define macros for conditional code inclusion, or textual substitutions. Meta strings are
equivalent to the the __FILE__ and __LINE__ macros.

A meta-string is a string identifier in uppercase, beginning with the hash or pound sign #. A meta string is
substituted with the information it represents. A meta-string allows for information about the source
code, but without the manual effort to represent it, or the overhead of changing it when the source code is
revised. There are 19-standard meta strings in Mynx.

Meta String Description Example


#AUTHOR Author of the source “Jon Q. Doe”
#BUILD Build version for file “Build 1.1”
#CLASS Name of the class “myClass”
#COMPILER Compiler information “Mynx Compiler 2.033”
#DATE Date of the Build “03/04/2004”
#DAY Day of Month as Integer 1…31 “17”
#FILE File Name “myClass.mynx”
#LINE Line Number “237”
#METHOD Name of the Method “myData”
#MODULE Name of the Module “mynx.core”
#MONTH Month of the Year as Text “August”
#ORG Organization Name (Company, University, etc.) “University Old York”
#PLATFORM Name of the Platform (Machine/Operating System) “AMD64X86:Linux”
#PROGRAM Name of the Program “myProgram”
#SYSTEM Name of the System (Internet or Network Name) “cupcake.oldyork.edu”
#TIME Time of Build “2:31 P.M”
#VENDOR Vendor of the compiler “MynxSoft LLC”
#VERSION Compiler Version “version 1.0.1”
#YEAR Year of Build as an Integer “2003”
#WEEKDAY Day of the Week of Build as Text “Friday”

Table of Standard Meta Strings in Mynx

- 24 -
Mynx does not specify the format for the substituted literal strings for the meta strings, this is
implementation specific. If a meta string is used but is inappropriate (such as #PROGRAM in a class), then
the string is the “UNDEFINED” literal string text.

Example of using meta strings:

class metaStrExample as null is

public construct is to null;

public singular void aMethod is


IO.put(“Module is “);
IO.put(#MODULE);
IO.putln;
IO.put(“Method name is “);
IO.put(#METHOD);
IO.putln;
IO.put(“Class is “);
IO.put(#CLASS);
IO.put(“This meta string is “);
IO.put(#NOTHING);
end aMethod;

public destruct is to null;

end class;

The output for calling aMethod with the class metaStrExample is:

Module is default
Method name is aMethod
Class is metaStrExample
This meta string is UNDEFINED

Programmer defined meta strings are not supported, as then source code would contain undefined meta
strings which would need to be defined in the source, essentially creating a macro system (which Mynx is
trying to avoid without sacrificing some convenience) indirectly.

G. Operators

There are 44-operators in Mynx that represent the non-character symbols used to create expressions and
statements. The operators are classified into five categories:

1. Assignment
2. Logical and Bitwise
3. Relational
4. Stream
5. Mathematic

The operators can be overloaded, excluding the assign-mathematical operators, and the word operators of
as, in, is, to. Most of the operators are already overloaded in the core library of Mynx classes.

- 25 -
H. Encoding
Mynx uses Unicode 16-bit character encoding, hence literals and identifiers can use non-Roman alphabet
letters. However, for portability to other platforms, Mynx uses the Roman alphabet letters and Arabic
numbers in the syntax and grammar, and portable software written in Mynx is recommended to do the
same.

I. Comments

There are two kinds of comments in Mynx: single-line, and multiple-line. Comments can encompass any
symbols or characters, comments are ignored in Mynx, although other tools such as documentation
generators might process the comments.

Single Comments

Single-line comments are one comment for a line, beginning with the comment prefix of two slashes //,
and ending at the end of the line. The single-line comment syntax is the same as for C++ and Java, for
familiarity.

Examples single line comments:

//this is a single line comment. – legal single line comment


///another single line comment – legal, even with triple slash
/* old C-style comment */ – illegal, no double slash
//* anotherr C-style comment */ – legal, with C-style comment
/ wrong comment – illegal, only single slash

Multiple Comments

Multiple-line comments are comments which span multiple lines, beginning with a double exclamation
mark (bang-bang) prefix !! and ending with a similar trailing suffix. The double exclamation mark is
used for opening and closing symmetry, and the comment style allows C-style and Java-style multiple
comments included /* ... */ to be used with existing documentation tools. The multiple line
comment can encompass other comments, a comment within a comment.

Example multiple line comments:

!! this is multiple-line !! – legal, even on one line


!! !! !! – illegal, last prefix unclosed
!! //a comment !! – legal, comment nested within
! this is a comment ! – illegal, not correct prefix
!! /** C-style */!! – legal, with nested C-style comment

Comments are normally ignored by the Mynx compiler, but for documentation, then comments are
processed with the specific documentation XML tags.

- 26 -
J. Enumerated Types

An enumerated type is a named discrete set of named constants that are treated as a unique type. Each
constant has a non-negative integral value, and a string name. The Mynx programming language has
neither a predefined language construct for defining types (like the C programming language typedef
declaration), nor to define an enumeration or enumerated type (like the C programming language enum
declaration) either.

The reason is to avoid defining in the programming language that which can be defined using a class and
other features of the Mynx programming language, such as static inclusion of a class, and operator
overloading. Both the keywords enum and type are reserved words, to avoid creating classes, attributes,
constants, variables, or methods with those names and cause confusion.

- 27 -
- 28 -
III
The Primary Elements: Program
and Class

- 29 -
There are two major top-level programming elements in Mynx, which are:

1. Program – a basic unit of an application, for software solution


2. Class – a basic unit of a library, for software reuse

A program is distinguished from a class, as a program is not re-useable, nor can a program be used as an
object in another class or program. Conversely, a class is the element of re-use, but can not be used as an
application or program. Mynx distinguishes from C++ and Java where an application is a class, and so can
be used other than as an application.

A. Program
A program is a basic element of an application, and is block structured, with a header and footer
surrounding the program body. Enclosed within the header and footer is the body of the program.

The program header contains the name of the program, and specifies which method in the body acts as
the main method of the program. The program name will always precede the name of the main method in
the program header.

Example program header:

program helloWorld as sayIt is


program computeFactorial as factorial is
program example as main is

A program, by its header, can specify if the program is body less or contains a body of methods and
attributes. A body less program simply does not contain a main method name, so the program is body
less, having no attributes or methods.

Example body less program header:

program hello_world is
program gcd is
program ticTacToe is

A program body cannot be empty; at least one statement in a body less program, and one method (the
main method in a non-body less program) must be defined.

B. Class
A class is a basic element of a library for code use and re-use. A class is block structured, with a header
and footer. The body of the class is enclosed within the header and footer, and the body of a class can be
empty.

The class header defines the type or kind of class, the class name, and a comma-delimited list of any
parent classes the class inherits. For some classes, there is an implicit parent class provided by default
through Mynx.

- 30 -
Example Class Header:

class doIt is
class Void as null is
class subClass as parent is
abstract class AClass is
default class example as
virtual class VMyClass as Void, VObject, VCompare is
class intStack as Void has genericStack to Int is

C. Kinds of Classes
The class, as a basic unit for a library emphasizes use and re-use. There are two ways to utilize a class in
Mynx:

1. Inherit or sub-class a class to re-use code in a class.


2. Instance a class or instantiate as an object to use code.

The kinds of classes in Mynx are oriented around the two ways to utilize a class, through inheritance or
creating an instance or instantiation.

There are seven kinds of classes in Mynx each of which affects the way the class can be used, and each of
which falls into three categories.

The seven kinds of classes are:

1. abstract – an incomplete class


2. constant – a completely finally complete class
3. default – the regular class
4. generic – an incomplete class, generalized in type
5. singular – a class which is completely final and static
6. static – a class that has no instances
7. virtual – a class that declares method signatures and overloads

The three basic categories for the kinds of classes are:

1. default – the implicit, regular default class


2. restricted – restricted or limits on class use
3. partial – a partially defined but incomplete class

Class Kind Inheritable Instance Inherit From Category


abstract Required No abstract or virtual Partial
constant Never Yes all Restricted
default Yes Yes all Default
generic Only generic No only generic Partial
singular Never No all Restricted
Static Only static No all Restricted
virtual Required No only virtual Partial

Mynx Class Kinds, Inheritance, Instance, Category

- 31 -
D. Abstract
An abstract class is similar to a virtual class; however an abstract class cannot be instantiated to create an
instance, or have a sub-class cast to the abstract class. An abstract class can provide partial
implementation, and have attributes within the class. Abstract classes are useful to provide easily defined
common functionality to be used by sub-classes.

E. Constant
A constant class can be used and instances created, but it cannot be inherited or sub-classed for re-use. A
constant class is useful as an invariant, so that other sub-classes with other functionality can be avoided,
only multiple instances.

F. Default
A default class is by its class modifier name, default if no class kind is specified. A default class can be sub-
classed through inheritance for re-use, and instances created for use in a class or program.

G. Generic
A generic class is an almost complete class, except for the type, so a generic class, like an abstract class,
provides an implementation. A generic class is a parameterized type class, a polymorphic type class.

A generic class can be bound to a class type, which can be used as an instance. The generic class is useful
to define type-independent classes, to avoid re-implementation of functionality, or much type conversion
and coercion.

H. Singular
A singular class is both constant and static, so can never be sub-classed through inheritance for re-use.
Nor can instance be created for use; there is only the single static class. A singular class is somewhat like a
program in that it never can be used to instance or inherit from as a parent class.

I. Static
The static class can be inherited for re-use, but can not create an instance for use. There is only one
existing instance of a class, the single static instance. A static class is useful for a class in which only one
instance is required to prevent duplicate instances from existing and being unsynchronized.

J. Virtual
The virtual class is useful to specify methods, and to tag another class for functionality. A virtual class
contains only method signatures, specifying name, return type, and any parameters to the method. A
virtual class while without an instance, it can be cast upward to an instance of a sub-class.

The super-parent root class in Mynx, the class Void, is a virtual class, which defines no methods. Because
Void is the super-class of all classes, any object reference Void can refer to any possible instance of a
class, but cannot use any methods, as Void defines no methods.

- 32 -
IV
The Minor Elements: Attributes
and Methods

- 33 -
There are two minor elements that are used in the body of a class or program. The two minor elements
that define the functionality of a class or program are:

1. Attributes – an element of data or information


2. Methods – a basic element of functionality

A. Attributes

Attributes are the data of a class, or the variables of a program, and are instances of other classes being
used within the class or program.

All attributes have mode, kind, type, and a name. Attributes must have an initial value, and can be scoped
(hidden or made accessible) within a class or program.

Attribute Mode

An attribute mode is one of two possible modes for attribute persistence:

1. default – attribute is persisted beyond the instance


2. volatile – attribute is not persisted beyond instance

Persistence of an instance allows the object state to be stored and loaded later, the mode of an attribute is
if the declared attribute will be persisted or not. An attribute implicitly is persistable, and explicit mode
declaration is not needed.

Attribute Kind

The attribute kind is the qualification placed upon the attribute for use in an instance in the declaration.
The kind of attribute determines if it is an instance or class attribute, and if it is a constant or not.

Attribute Kind Constant Static


constant Yes No
singular Yes Yes
static No Yes
variable No No

Table of Attribute Kinds

The attribute kind does not have to be explicitly declared, but is implicitly variable.

Attribute Type

Attribute type is simply the class for which the instance is created, and must be given explicitly. The kind
of class can not conflict with the attributes use as an instance, such as a singular class used as an attribute
type.

Attribute Name

The attribute name is an identifier used to bind an instance object of the type class to the attribute
through a name. Each attribute name must be unique from other attributes, and a declaration of an
attribute can have multiple names.

- 34 -
Initial Value

All attributes initialized explicitly, either by equivalence with a value, or through parameters to the
instance. Multiple attributes declared can all be initialized to the same value. The initial value can be a
literal, static attribute of a class, or a call to a static method, or a mixed expression of literals, static
attributes, and static methods. The keyword null can be used as an initial value, indicating the object
instance reference refers to nothing in the initial value. Initial values can not be initialized with non-static
attributes, as the order of attribute initialization is not specified nor guaranteed by Mynx.

Example initial value:

let Int x to 0; – initial value equivalent with is zero.


let Int y to (0); – initial value with parameters to instance.
let Real z to PI; – initial value equivalent to constant.
let Real i to (PI + E); – initial value equivalent expression
let Char c to default; – initial value through default constructor
let String s to null; – initial value is null reference

Attribute Scope

Attribute scope is used to control visibility of attributes to methods within the class or program. Attributes
can optionally be scoped by hiding the attribute from methods, or exposing an attribute to methods.
Attributes are checked for visibility by a method if accessed, and a method that can not access an attribute
will generate an error. Attribute scope is internal to a class or program, so inapplicable outside a class or
program.

The scope expression of an attribute declaration begins with whether the attribute is inclusive or exclusive
to methods. Attributes that are inclusive or visible use the keyword in, and attributes that are exclusive or
hidden use the keyword out. Then it is followed by the keyword for, and the method list.

Two special methods are all and null; these special method keywords are to avoid the need to list all
class methods, and to explicitly have a means to say no method of the class.

An attribute can exclude all methods, and a method can include null or nothing, hence can not be called
from within a class or program.

The implicit scope of attributes is:

in for all – inclusive for all methods


out for null – exclusive for no methods

Both scope expressions are the same, making an attribute implicitly accessible for all methods.

- 35 -
B. Program Attributes

Program attributes are declared with the keyword let prefixing or beginning the declaration. The rest of
the declaration is the required program attribute kind that is a variable or constant, followed by a
regular attribute declaration. Program attributes are static in nature, either variable for modification
within the program, or constant for a final program attribute. Similar to a class attribute, program
attributes must be initialized to a starting value.

Examples of program attributes:

let variable String x to “Hello world!!!” out for null;


let variable String greeting to (“Hi there!”) out for doGreeting;
let constant Real PI to (3.1457);
let variable Char blank to (' ') in for all;
let variable Int z to null; //program static attribute null?
let variable UnsignedInt i to (0);
let variable Int x, y, z to (3);

C. Class Attributes

Class attributes are declared by the external access keyword. Class attributes can be accessed by other
classes using the class as an instance object. There are three kinds of access:

1. public – fully accessible


2. protect – accessible only in a sub-class by inheritance, or within class
3. private – not accessible ever, except within the class

The remainder of a class attribute is the standard declaration, similar to a program attribute.

Example of class attributes:

public Int size to 0 in for all;


public Int count to -1 in for getCount;

All class attributes must be initialized when declared; there are no default initial values for a class
attribute of a type. The initial value must be of the same type, not a super-type or sub-type, and initialized
in the attribute declaration.

D. Methods

Methods are the means to change the data of a class or program, and provide the functionality of a class. A
method has three elements:

1. Method header or the method signature


2. Method body which defines functionality
3. Method footer that forms a method block

- 36 -
Program Methods

A program method is preceded by the keyword method, with the rest of the method header declaration
following, and ends with the is keyword. A method declares a return type, which is a class to be returned
by a method, if the method is defined as a function. A program method is of the class method mode
singular, static and constant. As a program can never be inherited or overridden, it follows the methods
are immutable and program wide.

A method can declare a return type of void, which declares the method returns nothing, or is a
procedure. If a method does not explicitly state a return type, an implicit void (the method as a
procedure) is used as the return type. Note that the return type void is nothing, but the return type of
Void is the root virtual parent class Void. Both are entirely different entities.

Examples of return types in program methods:

method void doItProcedure is – explicit void or procedure


method doItProcedure is – implicit void or procedure
method Int factorial is – explicit Int or a function
method Real program is – invalid name, keyword

Following the return type is the name of the method, which must be a valid identifier.

Class Methods

A class method is similar to a program method, except it must declare the class access to the method
before all other method elements. Like class attributes, there are public, protect, and private methods.

Example of return types in class methods:

public implicitVoidMethod is – implicit void return type


public void doSomething is – explicit void return type
private Void doIt is – method return of Void virtual class
protect method(VCompare comp) is – invalid method name, keyword

Parameter List

After the method name, the parameters to the method are specified, the name and parameter list form the
“method signature” which is used to identify a method within a class.

No two methods can have the same signature (note that two similar methods can have different return
types...). Unlike other programming languages, a method with no parameters does not use a pair of “dead
parenthesis” or dead parens “()” trailing after the method name.

A parameter list that is non-empty begins with an opening parenthesis ‘(‘ and ends with a closing
parenthesis ‘)’ with a list of parameters separated by a comma. Each parameter is specified by
parameter mode, the class or object type, and the parameter name within the method.

- 37 -
Method Parameter Modes

There are four kinds of method parameters, each with a unique keyword:

1. in – parameter passed into method


2. out – parameter passed out of a method
3. var – parameter passed both in and out of a method or variant
4. series – parameter passed in with variable number of parameters

If a parameter mode is not given, it is implicitly an in parameter. Each kind of parameter differs in terms
of:

1. Nullity – Object reference can be initially null.


2. Mutable – Object reference can change within a method.
3. Number – Count of references per parameter (one or many).

Parameter Initially Reference Number of


Mode Null? Immutable? References
In No Yes 1
Out Yes No 1
Var No No 1
Series No Yes N

Summary of Method Parameter Modes Table

In Parameter Mode

An in parameter can not be null, and the object reference is constant or immutable, so can not be
changed. Changes to a parameter object by its methods are propagated back, so global. Essentially, an in
parameter is information passed to a method by reference, which is a not null, and a constant to the
method. An in parameter does not pass information back from the method.

Example of defining a method using in parameter mode:

public swap(in Int first, in Int last) is

var Int temp to null;

temp = first;
first = last; //error immutable reference, unchangeable
last = temp; //error immutable reference, unchangeable

end swap;

- 38 -
Example of using the defined method:

var Int i to 7;
var Int j to 3;
var Int k to null;

swap(i,j);
swap(j,k); //error in parameter can not be null
swap(k,i); //error in parameter can not be null

A general-purpose method swap is not possible using an in parameter mode. The parameters are
immutable, and are not nullable.

Out Parameter Mode

An out parameter can be null as it is intended to return information from a method, and the object
reference is variable so can change. Hence changes to the parameter object by its methods are global and
passed back. An out parameter is used to return information from a method.

Example of defining a method using in parameter mode:

public swap(out Int first, out Int last) is

var Int temp to null;

temp = first;
first = last;
last = temp;

end swap;

Example of using the defined method:

var Int i to 7;
var Int j to null;

swap(i,j);
swap(i, null); //possible, but only parameter i changes
swap(null, j); //possible, but j is originally null so unchanged

A general-purpose swap method using an out parameter mode is possible, but has the problem of that
null can be passed but is a value.

Var Parameter Mode

A var parameter is like an out parameter, except that it can not be null, and is used like an in to pass
information to a method, but also to return data from a method. A var parameter changes information to

- 39 -
pass information in and out, so a var parameter is non-constant or is mutable. Like the in and out
parameter, a var parameter changes are global and propagated back from a method.

Example of defining a method using in parameter mode:

public swap(var Int first, var Int last) is

var Int temp to null;

temp = first;
first = last; //error immutable reference, unchangeable
last = temp; //error immutable reference, unchangeable

end swap;

Example of using the defined method:

var Int i to 7;
var Int j to 3;
var Int k to null;

swap(i,k); //error k is null


swap(i,j); //valid, non-null parameter
swap(i, null); //error parameter is null
swap(null, j); //error parameter is null

The parameter mode var allows for mutable parameters but that are not null. The swap method using
var parameter mode is the best implementation.

Series Parameter Mode

A series parameter is like an in parameter, but takes multiple parameters, and within the method is a
1-dimensional array of those parameter types. A series parameter is useful for a variable or optional
varying list of parameters to a method. A series parameter can be null for 0-parameters, but no
information can be returned by a series parameter list. Hence a series parameter list even when null
is constant.

There are three rules for using a series parameter:

1. Only one series parameter in a method header.


2. With mixed parameters, the series parameter is last.
3. A method header with a series parameter cannot be ambiguous with other overloaded
methods of the same name.

- 40 -
Example of series parameter in use:

public Int addIntegers(series Int[] ints) is


//...
end addIntegers;

this.addIntegers(0);
this.addIntegers(0,1,2,3,4);

Int[] i to {0 };
this.addIntegers(i);

Int[] i to {0,1,2,3,4};
this.addIntegers(i);

Example of series parameter used incorrectly:

!! compiler error! Bad series parameters; only one


series type parameter.
Example: this.badMethod(-1,-2,-3,4,5,6);
Which parameters are array x, y ?? No way to tell !!
public void badMethod(series Int[] x, series Int[] y) is
//...
end badMethod;

!! compiler error! Ambiguous series parameters; unable


to disambiguate methods named badMethod2
Example: this.badMethod2(0);
Which: badMethod2(Int), badMethod2(Int[]) ?? !!
public void badMethod2(in Int x) is
//...
end badMethod;

public void badMethod2(series Int[] y) is


//...
end badMethod2;

!! compiler error! Bad series parameter is must be


last in method named badMethod3 !!
public void badMethod3(series Int[] x, in Int y) is
//...
end badMethod3;

!! compiler error! Ambiguous series parameters; unable


to disambiguate methods named badMethod4
Example: this.badMethod4(3.14, 13, 7);
Which: badMethod2(Real,Int,Int),
badMethod2(Int[]) ?? !!
public void badMethod4(in Real r, in Int i, in Int j) is
//...
end badMethod4;

public void badMethod4(in Real r, series Int[] x) is


//...
end badMethod4;

- 41 -
Method Traps

A method, following a parameter list (if any...) then lists the traps (or exceptions...) flagged by a method.
Traps are flagged within a method, and if not handled, are propagated back as an error report.

Declaring a method to flag a trap requires that any calls to the method must handle the trap with a try
statement. A method can flag a trap without declaring it, forcing the handling of a trap is independent of
flagging the trap within the method.

A method declares any traps flagged as an identifier list (the actual traps are classes which are defined...)
which begins with the has keyword. The list of flagged traps must declare at least one, without any limit
on the number of possible traps flagged.

Examples declaring traps in a method:

method doIt has IOTrap is


method Int factorial has MemoryTrap, IOTrap is

public File open(in String fileName) has FileNotFoundTrap is


public Array1D make(in UnsignedInt dim) has OutOfMemoryTrap is

Method Scope

After any traps to be flagged by a method, the scope or visibility of a method is declared. Scope determines
if a method is visible or invisible to other methods, and can be called by other methods. Scope is declared
with the scoping keywords in or out to indicate inclusive scope or exclusive scope, respectively. The
scope is then an identifier list of excluded or included methods proceeded by the keyword for. The
keywords all and null can be used for all class methods, or no class methods. Like an attribute, the
default scope is visible for all, or invisible for none.

Examples of scoping methods are:

method doIt in for all is


method void doNone out for null is
method Int fact out for doIt, doNone is
method doWhy out for all, doIt is – invalid all with method names

public construct in for null is


public construct out for all is
public aRecursiveMethod in for aRecusiveMethod is
protect Int compare(in VCompare comp) out for compare is

All the elements of a program method header declare a method of a program. Following the method
header, the actual definition of a method is through a sequence of statements, and then the method footer.

- 42 -
Example program method headers:

method void main(in String[] args) out for all is


method main(String[] args) in for null is
method Int factorial(in Int x) in for factorial is

E. Class Methods

A class method is similar conceptually to a program method, but a class method has different features
from the fact it is a method of a class, a means for extending and re-using functionality.

There are three special kinds of class methods, relating to class creation, destruction, and implicit use.
These special methods are:

1. constructor – create or make a new class instance method


2. destructor – destroy or cleanup an existing class instance
3. default – default method of an instance called when none specified

The special class methods use the reserved words or keywords construct, destruct, and default
instead of a class method name.

A class method is declared first with a keyword indicating access; Mynx does not have any implicit access
(like private in C++, public in Java, or protect in Objective-C), and declaring a method without
explicit access is incorrect syntax. The access keyword is used instead of the keyword method as in a
program.

Method Mode

Following the method access in the class, the method mode is declared. For a class, the method mode
determines the kind of method, and if the method can be changed or re-defined when inherited in a sub-
class. The method mode follows class inheritance, and the class kinds.

1. abstract – undefined in abstract class, must be defined in sub-class


2. constant – method can not be overridden in inherited class
3. default – regular method for an instance object
4. singular – method is constant, and static
5. static – method is a class method, not an instance
6. virtual – undefined method in virtual class, must implement in non-virtual sub-class

After the access keyword, the remainder of a method declaration is similar, with method synchronization,
method mode, return type, method name, parameter list, trap list, and internal scoping.

Method Synchronization

A class method, unlike a program method, can be synchronous (thread-safe) or asynchronous (non-
thread) safe. A program is single-threaded and hence its methods are by default non-thread safe or
asynchronous.

A class method can have two types of synchronization:

1. asynchronous – not thread safe; single-threaded method


2. synchronous – thread safe method; multi-threaded method

- 43 -
The asynchronous mode is the default synchronization mode used, and is explicitly declared with the
async keyword. The synchronous mode is declared explicitly with the sync keyword before a class
method header.

A synchronous class method for multi-threaded, thread safe methods creates an overhead for invoking
and using a class method. A synchronous method creates a lock on a method, ensuring that a method used
has only one thread executing the method at a time.

Method Return Type

A method can declare a return type of generic indicating the type returned is generalized or generic, but
this is only for a generic class. If no return type is specified, the type is implicitly a void type. The method
return type is not part of the method signature.

Example of similar method signatures with different return types:

public abstract void doSomething(Int i);


public abstract Int doSomething(Int j);//error, same method signature
public abstract Real doSomething(Int q);//error, same method signature

Method Headers

Need discussion

Example class method header:

public static myOwnMethod(in Int i, var Bool flag) in for all is


public generic pop out for all is
public asynch singular UnsignedInt getFreeMemory out for all is
public sync default void waitForObject(in VObject vobj) out for all is
public covariant Void myCovariant(in VObject obj) is
public asynch covariant UnsignedInt computeVal(in VInteger vint) is

Undefined Method Header

Since virtual and abstract methods are not completely defined, only the method headers, the parameter
lists that form the method signature specify only parameter mode and parameter type. The parameter is
not a variable when used in declaring an undefined method. So for an undefined method which is virtual
or abstract, the parameters are unnamed. Nor can an undefined method header specify scope, as the
method will be implemented and defined with scope in a sub-class. Undefined method headers are only
possible for classes, not programs.

Example undefined class method header:

public abstract Bit compare(in VCompare);


protect virtual Bool isEqual(in VObject);
public abstract abstractMethod(in Int);

- 44 -
V
Namespaces

- 45 -
The namespace concept is organizing classes and programs into a hierarchy based upon a module name to
give unique names to a class or program. A namespace helps to modularize classes and programs so that a
more descriptive full namespace name can be given, rather than a simple name to an individual class or
program. Mynx requires an explicit namespace, or else a default namespace is implicitly given (unless of
course the default namespace is explicitly used...).

A. Declaration
A namespace, if explicitly declared is the first statement in a Mynx source file. A namespace is declared
with the module keyword, followed by the name of the declared namespace, with a closing semicolon ‘;’
to terminate. The declared namespace is a series of a least one identifier, each of which is delimited or
separated by a dot ‘.’ or period. The declared name of the namespace can not contain Mynx reserved
words or keywords, except in one specific case. For a unique namespace, an internet name in the form of
“domain extension, domain name...” followed by specific namespace name to identify the classes
organized within the namespace.

Example namespace declarations:

module mynx.core;
module com.williamgilreath.util;
module de.daslangeheisse.package;
module info.mynx.tools;
module one_big_long_namespace0;

Example invalid namespace declarations:

module module.program; – can not use keywords in name


module *; – operators are not valid in name
module 0.1.2.3; – namespace invalid using numbers
module ; – invalid, no name given for namespace

B. The Default Namespace


The implicit namespace a class or program is organized into is the default namespace. The default
namespace is implicitly used if no namespace is given, and uses the Mynx keyword default the name in
the namespace.

Example default namespace declarations:

module default;
module default.more.added; – invalid, default only
module prefix.default; – invalid, default only
module default.module; – invalid, default only and using keyword

- 46 -
C. Classes and Programs within a Namespace
Classes and programs are organized around namespaces, following a namespace declaration, either a
program or a set of classes is declared within the same Mynx source file. As a class and program are
mutually exclusive, and non-nest able (a program and class can not contain another inner class), the
namespace provides the full class or program name.

D. Inclusion of Classes from a Namespace


In order to use a class or classes within a namespace, the class must be included in the class or program.
Inclusion of a namespace allows classes to be used within the program or class. Mynx does not
automatically include any namespaces, including a namespace declared for a class or program. All
namespaces for inclusion in a class or program must be explicitly given.

Inclusion of a namespace uses a with statement that follows the namespace declaration, but precedes a
class or program declaration. Inclusion of a namespace is of two kinds:

1. absolute – a class is specifically identified by namespace and name.


2. relative – inclusion of a namespace, which includes all classed within the namespace.

An absolute inclusion of a namespace includes a specific class in a specific namespace. The with statement
for absolute inclusion of a class in a namespace is the with keyword with a namespace and class, followed
by an ending semicolon ‘;’.

Example absolute inclusion of class for a namespace:

with mynx.core.String;
with mynx.io.File;

A relative inclusion declaration is like an absolute, except that instead of a specific class name after the
namespace, a wildcard or asterisk ‘*’ is used to include all classes within the namespace.

Example relative inclusion of a class for a namespace:

with mynx.core.*;
with mynx.io.*;
with de.internet.util.*;

E. Multiple Sub-Namespace Inclusion


Not all namespaces are “flat” or use a short namespace with no nested namespaces within the overall
namespace. The namespace can be hierarchical, containing sub-namespaces.

The namespaces:

module example;
module example.first;
module example.first.second;

- 47 -
Using the namespace:

with example.*;

The namespace will include all classes within the example namespace; however it does not include any
sub-namespaces that are nested. To include sub-namespaces, a namespace must specify the sub-
namespace.

Using the nested namespace:

with example.*;
with example.first.*;
with example.first.second.*;

The namespace wildcard or asterisk ‘*’ is for all classes within a namespace, not any sub-namespaces.
Hence the following namespace inclusion is invalid:

with example.*.*.*;

The namespace for class inclusion must be explicitly and fully declared, sub-namespaces that are nested
are not included unless declared explicitly.

F. Declaration Order for Namespace Inclusion


The order of declaration for namespaces is immaterial or order independent for an absolute namespace,
but is significant or order dependent for relative namespaces. Mynx resolves a relative namespace to an
absolute with a class name, using the order of declaration to find the first match for an absolute
namespace.

If within two namespaces, there is an overlapping class name, the class that the relative namespace
inclusion resolves to is the first namespace with the class by the name. Essentially, a relative namespace is
resolved to an absolute namespace, but in the order of the relative namespace declaration.

G. The Mynx Namespace


The Mynx programming language uses five existing module namespaces to organize programming
language classes. All of the namespaces begin with the name mynx, followed by the namespace name. In
general, only language standard classes and namespaces should use the Mynx namespace, or risk
incompatibilities or inconsistencies.

Module Namespace Description of Classes Included


mynx.core Programming Language Core Classes, Types
mynx.io Input and Output Stream Classes
mynx.own Introspective Runtime Type Information Classes
mynx.trap Language Traps or Exceptions
mynx.trove Collections, Data Structures, Algorithms
mynx.gui Graphic User Interface Classes

Table of Mynx Namespaces

- 48 -
H. Nonexistent Namespace Inclusion
A with statement directs Mynx to use a namespace when determining which class to reference for a
declaration and use within a class or program. If a with statement directs Mynx to use an absolute
namespace that does not exist, it will create a semantic compiler error.

Example of non-existent namespace inclusion:

with nothing.doesnotexist.noClass; // semantic error! inclusion of a


// non-existent absolute namespace

virtual class Nothing as null is


//...
end class;

Static inclusion of class in default namespace ??

- 49 -
- 50 -
VI
Inheritance and Class Types

- 51 -
A. Concept of Inheritance

Inheritance is used to create a new class, and to re-use existing Mynx source code in the form of pre-
existing classes. There are four types of inheritance, each with restrictions and requirements for use. All
classes must inherit a super class when defined. A program however, is not a class nor does it use a super
class, so it never inherits a super class.

B. Types of Inheritance

The four types of inheritance in Mynx are:

1. Null
2. Single
3. Multiple Virtual
4. Multiple Disjoint

Null

Null or nothing inheritance seems an oxymoron, but is a special form of inheritance used only by a virtual
class. A virtual class does not have to inherit from another virtual class, if no super class is given in the
virtual class declaration the class inherits null or nothing.

Example of null inheritance:

virtual class Void as null is //explicitly inherits null or nothing

//define the class

end class;

Example of similar but implicit:

virtual class Void is //implicitly inherits null or nothing

//define the class

end class;

The class Void explicitly inherits null or nothing, but implicitly inherits null. A virtual class can declare
but not define a class, to be used as a specification for implemented functionality in a concrete class. A
virtual class can re-use specified functionality from another virtual class. But if a virtual class wants to
specify additional functionality without inheriting more from another virtual class, it would declare the
super class as null.

For a concrete class implementing multiple virtual classes which inherit null, then there is no overlap in
specified methods of class functionality. This can be important in multiple disjoint inheritance, when
multiple abstract classes that can partially implement methods are used. By and of itself with virtual
classes, multiple inheritance of virtual classes is not syntactically or semantically erroneous, as only one
declared method is implemented in the concrete class.

- 52 -
Single

Single inheritance is a standard type of inheritance; in Mynx single inheritance is inheriting one parent
class, an abstract, default, or virtual class. For a default or normal class, single inheritance is the only kind
of inheritance possible.

Example of single inheritance:

with mynx.core.*;

default class myClass as baseObject is

//...class body...

end class;

UML Class Diagram of Single Inheritance

- 53 -
Multiple Virtual

Multiple virtual inheritance uses multiple virtual classes to inherit a set of specifications essentially. This
is akin to Java's multiple interface inheritance, although for Mynx it is a virtual class instead of an
interface. Multiple virtual class inheritance allows for multiple methods, which can overlap, but the sub-
class must implement each method once. The methods must be similar in return type, if similar in name
and parameter signature. Any overlaps in similar method signatures must be exact, or otherwise there is a
return type conflict.

The drawback of multiple virtual inheritance is that functionality can overlap, but it is only declared or
specified, not defined in the virtual classes inherited by the sub-class.

Example of multiple virtual inheritance:

with mynx.core.*;

virtual class VClassA is //implicitly inherit from null


public virtual f;
public virtual g;
end class;

virtual class VClassB is


public virtual g;
public virtual h;
end class;

virtual class VClassC is


public virtual f;
public virtual h;
end class;

default class ClassABC as VClassA, VClassB, VClassC is


public construct is to null;
public void f is to null;
public void g is to null;
public void h is to null;
end class;

- 54 -
UML Class Diagram of Multiple Virtual Inheritance

Multiple Disjoint

Multiple disjoint inheritance is multiple inheritance, but is restricted to abstract classes which declare and
define functionality, and that the methods of the inherited abstract classes are disjoint, or mutually
exclusive with no overlapping method signatures. An abstract class must define functionality, but no
constructor to avoid super-class reference ambiguity. A primary reason for an abstract class not having a
static method is to avoid overlapping class methods in multiple disjoint virtual inheritance.

It is possible to mix multiple disjoint inheritance with multiple virtual inheritance, following the
constraints of both. If an inherited abstract method is abstract or undefined, then the sub-class must
implement the declared but not define the method. Multiple disjoint inheritance can be used with single
inheritance, the caveat being that the super class is likewise disjoint from the multiply inherited abstract
classes.

Example of multiple disjoint inheritance:

class SubClassXY as ABaseClassX, ABaseClassY, VirtualRootClass is

!! comparison abstract class methods are disjoint


from persistence class !!

//...class definition...

end class;

- 55 -
UML Class Diagram of Multiple Disjoint Inheritance

C. Classes and Inheritance

There are three categories of classes in Mynx:

1. Partial – a partially defined class


2. Default – a normal, default class
3. Restricted – restricted class in inheritance or instantiation

The partial classes are the abstract, generic, and virtual. Partial refers to an incomplete or partial class
definition. The partial classes can only inherit other partial classes, or become sub-classed (inherited by a
default class) to a non-partial class. The kinds of classes the partial classes can inherit for each class kind
are:
1. abstracted – abstract, virtual class inheritance
2. generic – generic inheritance
3. virtual – virtual inheritance

- 56 -
The default classes consist of only a default class. The default class is a concrete, fully defined, class. It is
the conventional or normal class. The default class can only inherit other default classes.

The restricted classes are the constant, singular, and static classes. Restricted refers to that the classes are
restricted in capability to inherit other classes, or be sub-classed. Only the static class can inherit another
static class, the singular and constant classes can not inherit other classes as both are constant so non-
inheritable. A synopsis for the restricted class inheritance is:

1. constant – no class inheritance


2. singular – no class inheritance
3. static – static class inheritance

D. Inheritance of Attributes and Methods

When a class is inherited, there are three class elements that are possibly inherited:

1. attributes
2. methods
3. operator overloads

Attributes

Attributes are inherited by a class, but if attributes in the sub-class “shadow” or mask attributes in the
super class, then it is a semantic error with inheritance. Attributes should be encapsulated within a class
as private or protected, or public if a constant.

Example of Shadowing a Class Attribute:

class parentAttribute as null is

private construct is null;

public default variable Int field to 0; //this`field;

end class;

class childAttribute as parentAttribute is

private construct is null;

!! semantic error! Attribute shadows super`field !!


public Int field to 1;

end class;

- 57 -
Methods

Methods are inherited by a class, and super class methods, if not constant, can be either overridden or
overloaded. If a super class has an abstract or virtual method, the sub class must implement the method
unless the sub class is abstract.

A common concern in object-oriented is methods being covariant, contra variant, or invariant. Mynx uses
invariant methods in inheritance, effectively do not care about variance in methods in inheritance with
classes. Overloading requires a unique set of parameters for each method definition, but excludes the
method type. Overriding requires an exact method signature including the method type to override an
existing method.

E. Inheritance of Methods

Class methods can be overridden, or overloaded in a class by inheritance. The special methods of a class,
the constructor, destructor, and default method are never inherited, nor overridden in a class that is
inherited. A class must define its own constructor, destructor, or default method; a class can reference a
parent class constructor, destructor, or default method in its definition, but it must always define its own,
none is every inherited. Overriding a method is to redefine the method in a sub-class of the parent class.
Overloading is to define more than one kind of method with the same method name.

F. Method Overriding

Method overriding re-defines a method in a sub class in terms specific for that sub class. A method
overrides a super class method if it has the same method signature. A method can override a super class
method even if the return type of the method is different from the return type of the parent method.
Methods can override a super class method, except for the super class constructor, destructor, and default
method. A constructor, destructor, or default method can be included by method equivalence from the
super class (although it is not method overriding, it is method equivalence).

G. Rules for Method Overriding


There are six rules for overriding a method:

1. A method override must be a non-virtual and a non-abstract class method.

2. A method override can only increase the level to public from protect access, or retain the
same access level. A private method is never visible to be inherited and overridden in a sub
class.

3. A method override can only be the same mode such as static, default, generic. A
constant or singular method can never be overridden.

4. An overridden method with a self type for the method type must use the class name as the
type when overridden.

5. An overridden method must use the same parameter signature including the return type
(except in the case of a self type), as Mynx does not support contra variant typing, but
invariant.

- 58 -
Example of Method Overriding with Inheritance:

class Parent as null is

private construct is null;

public doSomething(in Int i) is


if(i == 0)
i = 1;
else
i++;
end if;
end doSomething;

end class;

class Child as Parent is

private construct is null;

!! override method from parent !!


public void doSomething(in Int i) is
i++;
end doSomething;

end class;

H. Covariant Method Overriding


A method that is overridden in a sub-class is normally invariant, requiring the same method return type,
and parameter list. However, Mynx allows an overridden method to be covariant in the return type of the
method overridden, or a covariant method return type (CMRT) override.

The four rules for covariant method return type override are:

1. A covariant return type method must match the parameter list or the signature of the super-class
method exactly. More simply put, the parameter list of a method is invariant even if the return
type is covariant.

2. The return type of a method that is overridden must be a sub-class of the return type in the super-
class method.

3. The return type of a super-class method that is overridden cannot be void return type, nor can
the return type of the sub-class class method. (A method which returns void is a procedure, so is
invariant by definition.)

4. A method must be an instance method available in the super-class to be overridden, hence cannot
be constant, singular, or static.

5. Invariance of abstract self method; the return type of a super-class method that is overridden
cannot be self return type, nor can be the return type of the sub-class method. (A self return type
is used in an abstract class so is abstract and based upon the sub-class type.)

- 59 -
Example of Covariant Method Override of an Implied Method:

class Parent as Void is //define super-class as Parent

public covariant VObject doIt is implied;

public void doProcedure is


IO.putln(“Hello World!!!”);
end doProcedure;

public Object doObject is implied;

end class;

default class Child as Parent is //define and override methods


//in the sub-class of Parent
public baseObject doIt is //covariant override of doIt
//baseObject sub-class VObject
//...method body //but not covariant for sub-class
end doIt;

public Real doProcedure is //compiler error! Try to override


return null; //void in super class return type
end doProcedure; //or class procedural method

public void doObject is //compiler error! Try to override


null; //void in sub class return type or
end doObject; //class procedural method

end class;

Example Covariant Method Override with Virtual Class:

virtual class VCopy is

virtual covariant VObject copy; //covariant method definition


//for copy deep-copy method
end class;

class doCopy as VCopy, VObject is

public construct is to null;

public doCopy is //doCopy covariant override


//...method body //of virtual method; doCopy
end doCopy; //is sub-class VObject, thus
//return of doCopy override
end class; //super-class type of VObject

It is important to remember that the virtual class Void is the root super-class for all classes in Mynx, and
is a legitimate super-class. The type void is a predefined type that means nothing or empty, and a void
type method can never be covariant.

- 60 -
I. Method Overloading

A super class method can be overloaded in a sub class with a similarly named method but with a different
method signature. Method overloading can apply to constant methods which can not be overridden, but
are overloaded in the sub class. A method can be overloaded within a class without inheritance.

Example of Overloading within the Class and Sub-Class:

class Parent as null is

private construct is null;

public doSomething(in Int i) is


if(i == 0)
i = 1;
else
i++;
end if;
end doSomething;

!! overload the method within the class !!


public doSomething(in Real r) is
r = r + 1.0;
end doSomething;

end class;

class Child as Parent is

private construct is null;

!! overload method from parent !!


public void doSomething(in UnsignedInt i) is
i++;
end doSomething;

end class;

- 61 -
J. Operator Overloading

Overloaded operators in a sub class do not inherit the super class overloaded operators. However,
constant operators can not be overloaded in the sub class, and so by implicit upward cast (which is
implicit) apply to the sub class. In effect, the constant operators of a super class are implicitly part of a sub
class, but not by inheritance.

class UnsignedInt64 is
public UnsignedInt64 add(in UnsignedInt64 op) is
//define addition for UnsignedInt64
end add;

overload constant + as add;

end class;

class UnsignedInt32 as UnsignedInt64 is //sub-class of UnsignedInt64

public UnsignedInt32 add(in UnsignedInt32 op) is


//define addition for UnsignedInt32
end add;

//implicit overload + as constant overload from parent class


end class;

program addExample is

let UnsignedInt64 i64 to 0;


let UnsignedInt32 i32 to 37;

i64 = i64 + i32;

//equivalent to
i64.set(i64.add(i32));

//implicit upcast explicitly:


i64.set(i64.add(i32 to UnsignedInt64));

end program;

K. Class Reference Prefixes

There are three ways to reference a class in Mynx, each reference refers to a class in the relation of
inheritance of classes. The three class inheritance reference prefixes are:

1. super – parent or super class reference


2. this – instance or current class reference
3. self – static elements of the current class

- 62 -
L. Dottic Access Prefix

Accessing an attribute is distinguished syntactically from accessing or invoking a method in Mynx. Mynx
uses a “dottic” from of syntax, a dot or period ‘.’ to invoke a method, and a tic ‘`’ to access an attribute.
Hence access of class elements is with a “dottic” operator.

Access Class Element Operator Name Operator


Attribute Call Tic `
Method Invoke Dot .

Table of Class Element Access Operators

This clearly disambiguates an attribute over a method. As a result, attributes and methods can have
similar names without any confusion or ambiguity.

Examples of accessing attribute over method:

myClass.method(1,2,3); //method invocation


myClass`attribute_; //attribute call
aClass`CONSTANT_ATTRIBUTE;
myClass.noParameterMethod; //method no parameters

M. Super Class Prefix

The super reference prefix refers to the super class or parent class to access an attribute or method. The
methods and attributes of a parent are available in a derived class using the super prefix. The super
prefix can not reference undefined methods, such as a virtual or abstract method which is declared but
undefined.

For a class with multiple inheritance of disjoint classes, as the methods must be disjoint, the super class is
implicit with no ambiguity about which method is referenced through the super prefix. The super
reference prefix can be used within a method, or method equivalent.

Example of Super Class Reference with Inheritance

class Parent as null is

private construct is null;

public doSomething(in Int i) is


if(i == 0)
i = 1;
else
i++;
end if;
end doSomething;

end class;

- 63 -
class Child as Parent is

private construct is null;

!! override method from parent as same method !!


public void doSomething(in Int i) is
super.doSomething(i);
end doSomething;

!! overload method from parent using parent method !!


public void doSomething(in Char c) is
super.doSomething(c.valueOf);
end doSomething;

end class;

N. This Class Prefix

The this class reference prefix refers to the current class, and is used to disambiguate methods and
attributes within a class. The this reference by itself refers to the class instance. Similar to a super class
reference prefix, the this class reference prefix can be used within a method or method equivalent.

Example of Class with This Reference Prefix:

class Parent as null is

private construct is null; //no constructor

private Int zero to 0;

publid default theMethod(in Int i) is


//define the method ...
end theMethod;

!! overload the method within the class !!


public void theMethod(in Bit b) is
this.theMethod(b + this`zero);
end theMethod;

end class;

A class attribute or a class method that is accessed without a prefix is implicitly using the this prefix to
access the class element.

- 64 -
The this class reference prefix also can refer to the class instance within the class as an implicitly
declared as a read-only variable. An example of using the class instance variable this is:

class X is

public construct is to null;

public X get is
return this;
end get;

end class;

O. Self Class Prefix

The self reference prefix refers to the static attributes or methods (similar to the this class reference
prefix), and when used in an abstract class refers to the class when concrete, or essentially the future
concrete sub class. This abstraction capability allows more generalized generic but abstract methods to be
defined, such as a cast method for all classes. The self class reference prefix can be used within a method
or method equivalent.

Example cast method in abstract class with self prefix:

abstract class Cast as Void is

public constant self cast(in VObject obj) is

if(obj in self)
return obj to self;
else
flag InvalidCastTrap;
end if;

end cast;

end class;

- 65 -
Example increment method with self prefix:

default class IncrementIt as null is

private construct is null;

public singular Int INC to 1; //static constant

public static Int increment(in Int i) is


return i + self`INC;
end increment;

public default Int inc(in Int int) is


return self.increment(int);
end inc;

end class;

Similar to the concept of the read-only this class instance variable, the class reference prefix super can
refer to the static form of a class, essentially a generalized reference to the class as its name. For example:

class Q is

public construct is to null;

public Q castTo(in VObject vobj) is

var Q result to null;

if(vobj in Q)
result = vobj to Q;
end if;

end castTo;

end class;

- 66 -
Rewriting the same class with the self class reference prefix:

class Q is

public construct is to null;

public Q castTo(in VObject vobj) is

var Q result to null;

if(vobj in self)
result = vobj to self;
end if;

end castTo;

end class;

- 67 -
- 68 -
VII
Operators and Operator
Overloading

- 69 -
The Mynx programming language allows for operator overloading, within restrictions on the methods and
the operators that can be overloaded. Operator overloading is declared within a class (never a program),
and applies to instance objects of the class exclusively.

A. Operators
There are a total of 44-operators overall in the Mynx programming language that are organized into six
major categories. There are 27-operators out of the 44-operators that can be overloaded, more than half of
the available operators. Most operators are infix, but there are 2-prefix operators, and 2-suffix operators.

B. Operator Categories:
There are six categories for operators in Mynx:

1. Assignment
2. Logical Bitwise
3. Relational
4. Stream
5. Mathematical
6. Access

- 70 -
Assignment

The assignment operators are primarily for assigning or moving data to and from instance objects. The
data can be simply the reference to the object, or the actual information within a class instance.

Operator Description Overload


is reference assignment No
as creation assignment No
= overloaded assignment Yes
:= cast assignment Yes
+= addition assignment No
-= subtraction assignment No
*= Multiplication assignment No
/= division assignment No
%= modulus assignment No
&= bitwise-and assignment No
|= bitwise-inclusive-or assignment No
^= bitwise-exclusive-or assignment No
>>= bitwise shift-right assignment No
<<= bitwise shift-left assignment No

Table of Assignment Operators

The 14-assignment operators include the regular assignment =, and reference assign is, along with a cast
assignment := operator. Only two operators, the regular assignment = and cast-assign := are
overloadable, and are overloaded in the Mynx core classes.

Reference Assignment Operator is

The reference assignment operator is, assigns the reference of an object to another object, and cannot be
overloaded. Hence the is reference assignment object always assigns a reference of an object or a shallow
copy, so like (in C++) a form of address assignment. The reference assignment is a universal form of
reference to reference assignment, if the regular assignment operator = is overloaded with other non-
reference assignment functionality.

var Int x to 0;
var Int y to 1;

x++;
y is x; //y is x
y++; //y is x, so x++

- 71 -
Creation Operator as

The creation with assignment operator as, creates an object and assigns the reference for the newly
created object to another object. The as operator cannot be overloaded explicitly with a method. Hence
the creation operator as creates new instances, invoking the constructor of a class implicitly.

var Int x to null;


var Int y to null;

x as Int(“7”);
y as Int(0);

Regular Assignment Operator =

The regular assignment operator = by default is a reference to reference assignment operator, similar to
the is assignment operator. However, unlike the reference assignment operator, the regular assignment
operator can be overloaded. The numerical types Int and Real both have overloaded the assignment
operator.

var Int x to 3;
var Int y;

x = y;
y = 5; //x != 5, = overloaded

//same code:
x.set(y);
y.set(5);

It is important to note that in initialization of declared variables and constants, the to is a separator
between the class type and the initial value, it is not the regular assignment operator.

//not regular assignment in declaration with initial value


var Int x to (3); //constructor invocation
var Int y to null;

- 72 -
Cast Operator to
The Mynx programming language is strongly typed, and the language requires type-compatibility among
the operands used in expressions and parameters.

The cast operator to is used to cast or re-type an object. An object can only be re-cast to a super-type, or a
super-class from which the object class type is derived. A cast or re-typing of an object to a non-existent
class type (one which the object's class does not sub-class) will result in flagging a runtime type cast trap.

The to operator has both a left and right operand. The left operand is the instance object variable, and
the right operand is the class type.

The cast operator syntax example is:

data to Int //cast to Int class type


obj to VObject //cast to VObject class type

An example of using the cast operator:

var Int i to 123;


var VObject v to null;

v is i to VObject; //cast i to VObject -- downcast


i is v to Int; //cast i to Int -- upcast

Implicit Upcast ??

v is i; //VObject implicit upcast


v is i to VObject; //equivalent explicit upcast
v := i; => v.set(i to VObject);
utility of upcasting, using virtual classes, passing parameters to method.

- 73 -
Cast Assignment Operator :=
The cast assignment := operator is overloaded with a cast operator to the class type of the left value (l-
value) from the right value (r-value). The cast assignment operator is a cast to the l-value class type, along
with a regular assignment operator, using the class assignment (which can be overloaded).

var Int x to 3;
var Real y to 1.0;

y := x;

y = x to Real; //same as

//using the Int overload for =


y.set(x to Real);

Dual Assignment Operation Operators

The dual assignment operation operators are a joining of operation with assignment. These operators are
not directly overloaded with a method. However, the dual assignment operator is translated into separate
assignment = and the operation or operator ⊕. The general assignment operation expression of:

IDENTIFIER ⊕= EXPRESSION

This expression is translated into the more verbose equivalent of:

IDENTIFIER = IDENTIFIER ⊕ EXPRESSION

Essentially the identifier and the operator precede the remaining expression, which is then assigned to the
identifier. The identifier is in the expression with the operator, and is then the assignment of the result.
The equivalent expression with the assignment operator = and the operator ⊕ that are overloaded.

Addition-Assignment Operator +=

The addition-assignment operator += combines the possibly overloaded addition operator + with the
assignment operator = in a single operator. The addition-assignment operator, because of the dual
operation, cannot be overloaded directly, but indirectly through addition and assignment overloads.

var Int x to 3;
x+=7;

//similarly
x = x + 7;

//overloaded + for int


x = x.add(7);

//overloaded = for set


x.set( x.add(7) );

- 74 -
Subtraction-Assignment Operator -=

The subtraction-assignment operator -= combines the possibly overloaded subtraction operator - with
the assignment operator = in a single operator. The subtraction-assignment operator, because of the dual
operation, cannot be overloaded directly, but indirectly through subtraction and assignment overloads.

var Real r to 3.14;


r -= 1.0;

//similarly
r = r - 1.0;

//overloaded - for real


r = r.sub(1.0);

//overloaded = for set


x.set( x.sub(1.0) );

Multiplication-Assignment Operator *=
The multiplication-assignment operator *= combines the possibly overloaded multiplication operator *
with the assignment operator = in a single operator.

The multiplication-assignment operator, because of the dual operation, never can be overloaded directly,
but indirectly through multiplication and assignment overloads.

var Real m to 1.11;


m *= 2.0; //m = 2.22

//similarly
m = m * 2.0

//overloaded
m = m.mul(2.0);

//overloaded = for set


x.set( x.mul(2.0) );

- 75 -
Division-Assignment Operator /=
The division-assignment operator /= combines the possibly overloaded division operator / with the
assignment operator = in a single operator. The division-assignment operator, because of the dual
operation, cannot be overloaded directly, but indirectly through division and assignment overloads.

var Int i to 4;
i /= 2; //i = 2

//similarly
i = i / 2;

//overloaded
i = i.div(2);

//overloaded = for set


x.set( x.div(2) );

Modulus-Assignment Operator %=

The modulus-assignment operator %= combines the possibly overloaded modulus operator % with the
assignment operator = in a single operator. The modulus-assignment operator, because of the dual
operation, cannot be overloaded directly, but indirectly through modulus and assignment overloads.

var Int j to 3;
j %= 2; //j = 3 % 2 = 1

//similarly
j = j % 2;

//overloaded
j = j.mod(2);

//overloaded = for set


x.set( x.mod(2) );

- 76 -
Bitwise-And Assignment Operator &=
The bitwise and assignment operator &= combines the possibly overloaded bitwise and operator & with
the assignment operator = in a single operator.

The bitwise-and assignment operator, because of the dual operation, cannot be overloaded directly, but
indirectly through bitwise-and and assignment overloads.

var Int x to 0XFFFF;


x &= 0XFF01; //x = 0XFF01

//similarly
x = x & 0XFF01;

//overloaded
x = x.bitAND(0XFF01);

//overloaded = for set


x.set( x.bitAND(0XFF01) );

Bitwise Inclusive-Or Assignment Operator |=

The bitwise inclusive or assignment operator |= combines the possibly overloaded bitwise inclusive or
operator | with the assignment operator = in a single operator. The bitwise-inclusive or assignment
operator, because of the dual operation, can not be overloaded directly, but indirectly through bitwise
inclusive or and assignment overloads.

var Int x to 0XFFFF;


x |= 0XFF01; //x = 0XFFFF

//similarly
x = x | 0XFF01;

//overloaded
x = x.bitIOR(0XFF01);

//overloaded = for set


x.set( x.bitIOR(0XFF01) );

- 77 -
Bitwise Exclusive-Or Assignment Operator ^=

The bitwise exclusive or and assignment operator ^= combines the possibly overloaded bitwise exclusive
or operator ^ with the assignment operator = in a single operator. The bitwise exclusive or assignment
operator, because of the dual operation, can not be overloaded directly, but indirectly through bitwise
exclusive-or and assignment overloads.

var Int x to 0XFFFF;


x ^= 0XFF01; //x = 0X00FE

//similarly
x = x ^ 0XFF01;

//overloaded
x = x.bitXOR(0XFF01);

//overloaded = for set


x.set( x.bitXOR(0XFF01) );

Bitwise Shift-Right Assignment Operator >>=


The bitwise shift-right and assignment operator >>= combines the possibly overloaded bitwise shift-right
operator >> with the assignment operator = in a single operator. The bitwise shift-right assignment
operator, because of the dual operation, can not be overloaded directly, but indirectly through bitwise
shift-right and assignment overloads.

var Int x to 0XFFFF;


x >>= 0X0001; //x = 0X7FFF

x = x >> 0X0001; //similarly

//overloaded
x = x.shiftRight(0X001);

//overloaded = for set


x.set( x.shiftRight(0X001) );

- 78 -
Bitwise-Shift-Left Assignment Operator <<=

The bitwise shift-left and assignment operator <<= combines the possibly overloaded bitwise shift-left
operator << with the assignment operator = in a single operator. The bitwise shift-left assignment
operator, because of the dual operation, can not be overloaded directly, but indirectly through bitwise
shift-left and assignment overloads.

var Int x to 0XFFFF;


x <<= 0X0001; //x = 0X1FFFE

//similarly
x = x << 0X0001;

//overloaded
x = x.shiftLeft(0X001);

//overloaded = for set


x.set( x.shiftLeft(0X001) );

- 79 -
Logical Bitwise

Both operators process integral bits or Boolean values. The logical operators are logic operations on the
Boolean true and false. The bitwise operators do bit twiddling on integral types.

Operator Description
! logical not
& logical and (short-circuit)
&& logical and, bitwise and
| logical inclusive or (short-circuit)
|| logical or, bitwise or
~ logical complement
<< bitwise shift left
>> bitwise shift right
^ bitwise exclusive or

Table of Logical Bitwise Operators

The 9 logical bitwise operators are all overloaded operators, and are overloaded in the Mynx core classes.

Logical Not Operator !

The logical not or logical complement or negation operator ! takes a Boolean value of true or false, and
returns the logical not of the Boolean value. The logical not operator ! is overloadable, and is overloaded
in the Mynx core classes.

var Bool logical to True;


var Int x to 1;

if(! logical) //logical = ! True = False


x++;
else
x--;
end if;

//overloaded
var Bool logical to True;
var Int x to 1;

if(logical.not) //logical = ! True = False


x++;
else
x--;
end if;

- 80 -
Logical Bitwise And Operator &

The logical bitwise and operator & is both a logical operator, and a bitwise operator, depending on the
class type of the operands. For the Boolean class type, the logical and is a full evaluation logical operator.
Both operands to the operator are evaluated, even if one of them is false.

Example of Logical Operators:

if( x > 0 & y < 0)


doSomething;
end if;

Example of Bitwise Operators:

var Int y to 0XFFFF;


var Int x to 0XFFFF;

x = y & 0XFF01; //x = 0XFF01

//overloaded
x = x.bitAND(y);

Logical And Operator &&

The logical inclusive or operator && takes a Boolean value of true or false, and returns the logical and of
the Boolean value. The logical and operator is a short-circuit operator, if either operand is false, the other
operand is not evaluated. The logical and operator && is overloadable, and is overloaded in the Mynx core
classes.

if( file.exists && file.size > 0)


file.open;
end if;

Logical Bitwise Inclusive Or Operator |

The logical bitwise and operator | is both a logical operator, and a bitwise operator, depending on the
class type of the operands. For the Boolean class type, the logical or is a full evaluation logical operator.
Both operands to the operator are evaluated, even if one of them is true.

Example of Logical Operator:

if( x > 0 | y < 0)


doSomething;
end if;

- 81 -
Example of Bitwise Operator:

var Int y to 0XFFFF;


var Int x to 0XFFFF;

x = y | 0XFF01; //x = 0XFF01

//overloaded
x = x.bitOR(y);

Logical Inclusive Or Operator ||

The logical inclusive or operator || takes a Boolean value of true or false, and returns the logical inclusive
or of the Boolean value. The logical inclusive or operator is a short-circuit operator, if either operand is
true, the other operand is not evaluated. The logical inclusive or operator || is overloadable, and is
overloaded in the Mynx core classes.

if( x > 0 || y < 0)


doSomething;
end if;

Bitwise Complement Operator ~

The bitwise complement operator ~ is also called the bitwise negation operator, takes an integer data type
and computes the complement or negation. The bitwise complement operator can take a signed or
unsigned integral type, but it returns a signed integral type.

let Int b to 0X0000FFFF;


b = ~b; //b = 0XFFFF0000

let Int b to 0XFFFF0000;


b = ~b; //b = 0X0000FFFF;

Bitwise Shift Left Operator <<

var Int j to 3;
var Int i to null;

i = j << 3; //same as multiply by 2**3 or 8, i = 24

- 82 -
Bitwise Shift Right Operator >>

var Int j to 8;
var Int i to null;

i = j >> 3; //same as divide by 2**3 or 8, i = 1

Logical Exclusive Or Operator ^

The logical exclusive or operator ^ takes a Boolean value of true or false, and returns the logical exclusive
or of the Boolean value. The logical exclusive or operator ^ is overloadable, and is overloaded in the Mynx
core classes.

if( x > 0 ^ y < 0)


doSomething;
end if;

- 83 -
Relational

The relational operators are used for comparison, to compare and relate object instances. The object
instances “base objects” all have the relation of equality and inequality, and “rank objects” have
comparison of greater and lesser than relations.

Operator Description
== relational equality
!= relational inequality
in relational instance of
< relational lesser than
> relational greater than
>= relational greater-equal
<= relational lesser-equal

Table of Relational Operators

There are 7 relational operators; all but the in instance of relational operator can be overloaded. The
relational operators are overloaded in the Mynx core classes. The two parent objects in the Mynx class
hierarchy are baseObject and rankObject. A regular baseObject is only overloaded for equality and
inequality. The rankObject is a sub-class of baseObject, but overloads the relational operators and
provides a comparison method to establish the “rank” of two compared objects.

Equality Operator ==

The equality operator == is overloaded with the method isEqual in the Mynx class VObject, and is used
to determine if two objects are equal. The equality operator returns a Bool logical value of True or
False. The equality operator requires two objects be of the same type class, otherwise the equality is a
indeterminate comparison.

var Int x,y to 3;

if(x == y)
x.doSomething(y);
end if;

//overloaded
if(x.isEqual(y))
x.doSomething(y);
end if;

Inequality Operator !=

The inequality operator != is overloaded with the method isUnequal in the Mynx class VObject, and is
a constant overload. The inequality operator is defined as the logical inverse or not of the equality
operator. Hence, changing the definition of equality == will automatically change by definition the
meaning of the inequality operator. Like the equality operator the inequality operator returns a Bool
logical value of True or False, and requires both objects being compared for inequality be the same type
class.

- 84 -
var Int i,j to 3;

if(i != j)
return i;
else
return j;
end if;

//overloaded
if(i.isUnequal(j))
return i;
else
return j;
end if;

Instance Type Of Operator in

The instance type of operator in tests two cases for an instance object reference. The first case is if an
object instance is an instance of a type of class, or a sub-class type. Using the instance type of operator on
the super class Void will always return true, as all sub-classes are derived from the base virtual class
Void. Unlike the other logical operators, the in operator is not overloadable.

if(s in String)
this.processString(s);
end if;

The second case the in operator tests if two instances reference the same object. The operator is
equates two object references with the same instance, the in operator performs a logical check if two
objects refer to the same instance. Both variables must be of the same (or compatible?) type, as different
type of object references cannot reference the same object.

var String x to “hello”;


var String y to null;

y is x; //equate y with x

if(x in y)
doSomething;
end if;

Lesser Than Operator <

The relational lesser than operator < is used in comparison, and for two objects of the same type that are
unequal. The definition of lesser-than is an ordering feature of the class which defines it. The core Mynx
types such as String, Char, Int, Real, Float, UnsignedInt, Byte, UnsignedByte have the
relational lesser than operator and the ordering defined already.

- 85 -
var Int j to 7;
var Int k to 8;

if(j < k)
handleInt(k);
else
handleInt(j);
end if;

Greater Than Operator >

The relational greater than operator > is used in comparison, and for two objects of the same type that are
unequal. The definition of greater than is an ordering feature of the class that defines it. The core Mynx
types such as String, Char, Int, Real, Float, UnsignedInt, Byte, UnsignedByte have the
relational greater than operator and the ordering defined already.

var Int j to 7;
var Int k to 8;

if(k > j)
handleInt(k);
else
handleInt(j);
end if;

Greater Equal Operator >=

The relational greater than equal operator >= is a logical inclusive or of the equality and greater than
relation operator.

The relational greater equal operator is used in comparison, and for two objects of the same type. The
definition of greater equal is an ordering feature of the class, which defines it. The core Mynx types such
as String, Char, Int, Real, Float, UnsignedInt, Byte, UnsignedByte have the relational greater
equal operator and the ordering defined already. For some classes the greater equal operator simply uses
each of the base operators of equality and greater than to define greater equal.

var Char c to ‘ ’;//space character


var Char d to 32; //space character with ASCII value

while(c >= d)
IO.put(“c = “);
IO.put(c);
IO.putln;
end while;

- 86 -
Lesser Equal Operator <=
The relational lesser than equal operator <= is a logical inclusive or of the equality and lesser than
relation operator.

The relational lesser equal operator is used in comparison, and for two objects of the same type. The
definition of lesser equal is an ordering feature of the class, which defines it. The core Mynx types such as
String, Char, Int, Real, Float, UnsignedInt, Byte, UnsignedByte have the relational lesser
equal operator and the ordering defined already. For some classes the lesser equal operator simply uses
each of the base operators of equality and lesser than to define lesser equal.

- 87 -
Stream

The stream operators are used for moving data in and out to the data streams from object instances. The
operators for input and output are overloaded for the different stream classes.

Operator Description
<<< stream insertion or output
>>> stream extraction or input

Table of Stream Operators

Both stream operators can be overloaded, and are overloaded for the core Mynx input/output stream
classes.

Insertion Operator <<<

The insertion operator is an infix operator that inserts data to an output stream, and is overloadable.

var IOStream IO to default;

IO <<< “hello” <<< “ ” <<< “world!!!”;


IO.put(“hello”).put(“ ”).put(“world!!!”);

Extraction Operator >>>

The insertion operator is an infix operator that extracts data to an output stream, and is overloadable.

var IOStream IO to default;

IO >>> firstName >>> lastName;


IO.getLine(firstName).getLine(lastName);

with mynx.core.IOStream;

IO <<< x <<< eoln;


IOStream.IO <<< x <<< IOStream.eoln;
IOStream.IO.putln(x).putln(IOStream.eoln);

- 88 -
Mathematic

The mathematical operators are used with real and integral objects (number objects representing numeric
quantities) to perform mathematical operations.

Operator Description
+ Addition
- Subtraction
/ Division
% Modulo or Remainder
* Multiplication
** Exponentiation or Power of
++ Integral Increment
-- Integral Decrement

Table of Mathematic Operators

All 8 mathematical operators can be overloaded, and are overloaded for the core or foundation Mynx
classes. If an operator results in an integral or real value that exceeds the size for a numeric type, it will
flag an overflow or underflow trap.

Addition Operator +

The addition operator + is an overloadable infix operator, overloaded for the Mynx numeric types both
variable and literal.

var Int x,y to 1;

y = x + y;
y = x.add(y);
x.set(x.add(y));

Subtraction Operator -

The subtraction operator - is an overloadable infix operator, overloaded for the Mynx numeric types both
variable and literal.

var Int i,j to 1;

i = i - j;
i = i.sub(j);
i.set(i.sub(j));

- 89 -
Division Operator /

The division operator / is an overloadable infix operator, overloaded for the Mynx numeric types both
variable and literal.

var Int p,q to 1;


IO.putln(p/q);
IO.putln(p.div(q));

Division is defined on the integer and real types, and division by zero will flag a runtime division by zero
trap ZeroDivideTrap.

Modulus Operator %

The modulus operator % is an overloadable infix operator, overloaded for the Mynx numeric types both
variable and literal. The modulus operator computes the remainder or modulus for division of numbers.

var Int p,q to 1;


IO.putln(p % q);
IO.putln(p.mod(q));

Multiplication Operator *

The multiplication or multiply operator * is an overloadable infix operator, overloaded for the Mynx
numeric types both variable and literal. Multiplication is defined for integral and real types, and computes
the product of the two numeric values.

var Int p,q to 1;

IO.putln(p * q);
IO.putln(p.mul(q));

Exponentiation Operator **

The exponentiation or power of operator ** is an overloadable infix operator, overloaded for the Mynx
numeric types both variable and literal.

var Int i to 10;

i = j ** 2;
i = j.pow(2);
i.set(j.pow(2));

- 90 -
Increment and Decrement Operator -- or ++

Both the increment ++ and decrement -- are only post-operators, there is no pre-decrement or pre-
increment, a source of confusion in C/C++/Java. Both the increment and decrement operators are
overloaded for the signed and unsigned integer class types.

var Int i to 0;
i++;

//similarly
i.inc;

Return Types for Mathematical Operators

Type Integer UnsignedInt Real


Integer Integer Integer Real
UnsignedInt Integer UnsignedInt Real
Real Real Real UnsignedInt

Table of Mathematical Class Operation Return Types

- 91 -
Access

The access operators are implicit operators to get information in a class as a method invocation, attribute
access, or an index for an element of an array.

Operator Description
. method access
` attribute access
[] array access

Table of Access Operators

The access operators allow for accessing information of instances, through methods (messaging in object-
oriented parlance), attributes, and through arrays (which are multiple attributes bound to an instance).
None of the access operators can be overloaded, this is to avoid confusing the function of the operators,
and to keep the rules for operator overloading consistent and simple in Mynx.

Method Invocation .

Method invocation invokes or calls a method associated with an instance variable, with an instance, or the
super class. The dot or period separates the instance name reference from the method name. An explicit
method invocation calls the method using the dot operator ‘.’ , an implicit method invocation simply uses
the method name.

this.myMethod(3); //explicit instance method invocation


super.aMethod; //explicit super class method invocation
x.doSomething //explicit instance variable invocation
callAMethod; //implicit method invocation

Attribute Access `

Attribute access gets the attribute reference from an instance variable, or instance class, or the super class.
The tic ‘`’ separates the instance name from the attribute reference. Because of the different access
operators, attributes and methods can have the same name without ambiguity. An implicit attribute
access must be clearly disambiguated from a method, especially if a method has the same name and type
as the attribute. If not implicitly disambiguated, then an explicit tic must be used to distinguish the
attribute access.

One syntax style is for constants to be all upper case, and to use a trailing underscore for a class attribute
name.

Examples of attribute access:

this`MAXIMUM
super`variable
ex`value_
getIt
x_

- 92 -
Array Access []

An attribute is one instance of data with a variable name. Multiple instances of attributes can be created
with an array. An array access uses left bracket ‘[‘ and right bracket ‘]’ to indicate an access, with a non-
negative integer index to indicate which element to access. Multiple indices use a comma to separate each
index for each dimension. The index does not have to be a literal integer value, it can be an expression,
variable, or method call. As an attribute, the array has to be accessed using explicit tic ‘`’ with an instance
reference with a name, or implicitly with only the attribute name.

Examples of access operators:

this`matrix[7]
super`data[1,3]
myData[1,2]
table[x+1]
matrix`data[this.getIndex]

- 93 -
Operator Precedence

There are 13 overall precedence levels in Mynx, but the highest level cannot be overloaded or changed, so
effectively there are 12 levels. Parenthesis can override the operator precedence, except for level-0
precedence.

Level Operator Category Description


0 . ` [] Access Invoke and Access
1 ++ -- Mathematic Increment, Decrement
1 ~ Logical Bitwise
1 ! Logical Logical Not
1 := Assignment Cast Assignment
2 ** * / % Mathematic Multipy, Divide, Remainder
3 + - Mathematic Addition, Subtraction
4 << >> Bitwise Shift
5 < <= > >= Relational
5 in Relational Relational Instance
6 == != Relational Equality and Inequality
7 & Logical Bitwise And
8 ^ Bitwise Exclusive Or
9 | Bitwise Inclusion Or
10 && Logical And
11 || Logical Or
12 = is as Assignment or Creation
12 <<< >>> Stream
12 += -= *= /= %= Assignment Operation Dual Assignment Operators
&= |= ^= <<= >>=

Table of Operator Precedence

- 94 -
C. Operator Overloading
Operator overloading is associating an operator with a method. When an operator is used in prefix, infix,
or postfix form, the associated method is invoked instead. Operator overloading permits cleaner
expressions with shorter notation for classes. Only a certain set of operators are possible to overload, and
in some classes, some operators are restricted from further overload.

Operator Overload Declaration

An operator overload is declared like a method or attribute, except without any scope or access. An
overload declaration begins with the keyword overload, and ends with a semicolon ; character.
Following the overload keyword, the overload type is given, or optionally is not which makes an implicit
default overload. The operator is then specified, followed by the keyword as, with the method identifier.

Kinds of Overloads

There are two types of operator overloads:

1. default – operator can be overloaded in a sub-class


2. constant – operator cannot be overloaded again

A default overload is specified with the keyword default, explicitly, and is an overload, which can be re-
overloaded in a sub class. If an operator overload declaration is not explicitly given, then the overload is
implicitly default.

A constant overload is declared explicitly with the constant keyword, and for all sub-classes of the class,
the operator cannot be re-overloaded. However, the method can be overloaded, or overridden as the
overload declaration on specifies the operator and the overload properties, not the method.

Implicit Upward Cast (consistent move to cast operator??)

Classes with overloads that are constant, and are sub-classed do not pass the overloaded operators to the
sub-class. In short, a parent class with a constant operator overloads are not inherited by sub-classes.
However, in using the operators with the sub-class, there is an implicit upward cast to the parent, if the
child class does not overload the operators itself. An overloaded method, if not defined in the parent, is
invoked in the sub-class that defines it. The same principle for method selection applies to an overridden
method in the sub-class.

An example of an implicit upward cast of an operator overload is to define a virtual base class with an
addition operator:

virtual class VInt is

public Integer add(in Integer);

overload constant + as add;

end class;

- 95 -
Implement the class as an integral type, as a byte:

class Byte as VInt is

public Byte add(in Byte); //already overloaded with +

end class;

Use the implemented Byte class in a program:

program useByte is

let Byte b0 to 0;
let Byte b1 to 1;
let Byte bx to null;

bx is b0 + b1; //implicit upcast to base type of VInt

end program;

The equivalent program uses the virtual base class VInt to define the variables, but is instantiated with
the implemented sub-class Byte.

program useByte is

let VInt b0 to null;


let VInt b1 to null;
let Byte bx to null;

b0 as Byte(0);
b1 as Byte(1);

bx is b0 + b1;

//use overload of b0 as a VInt


bx is b0.add(b1);

end program;

- 96 -
Rules for Operator Overloading

Operator overloading is not possible for all method kinds and operators. There are ten rules for the
overloading of operators:

1. The method is public.


2. The method is a regular method, not a constructor, destructor, or default.
3. The class is non-static.
4. The method is an actual method in the class (by definition or equivalent).
5. The method takes one parameter (unary).
6. The return type of the method is non-void, function method.
7. The operator is valid for overloading.
8. The operator is not locked as a constant overload in a super-class.
9. The method is (non-static) constant, default, virtual.
10. The method is not obviated in the class.
11. An operator overload not declared overloaded in a sub-class is not overloaded.
12. A constant operator overload must reference the super-class overload in a sub-class.

Example of operator overloading with a constant overload:

class String as VObject, Void is

public String concat(in String str) is


//define the method
end concat;

overload constant + as concat;

end class;

class subString as String, Void is

public String concat(in String str) is


//define the method
end concat;

//reference and re-use constant overload in super-class


overload constant in String is + as concat;

end class;

- 97 -
Example of operator overloading with a default overload:

class Integer as VObject, Void, VNumber is

overload default + as add;


overload default * as mul;

end class;

class subInteger as VObject, Void, VNumber is

//re-overload operator with new method


overload default + as addition;
overload default * as multiplication;

end class;

An example of operator overloading with mixed constant and default modes is:

class Group as Void is

overload default + as associative;


overload constant * as commutative;
overload default - as relative;

end class;

class subGroup as Group is

//re-overload operator with new method


overload default + as transitive;

//reference overloaded operator in parent


overload default in Group is * as commutative;

//compiler error! operator ‘–‘ overloaded as relative


//not overloaded or referenced in parent class Group

end class;

- 98 -
Table of Operators

Op Level Type Name Overload Category


! 1 Prefix Logical Not Yes Logical Bitwise
!= 6 Infix Inequality Yes Relational
% 2 Infix Modulus Yes Mathematical
%= 12 Infix Modulus Assignment No Assignment
&& 10 Infix Logical And Yes Logical Bitwise
& 7 Infix Bitwise Logical And Yes Logical Bitwise
&= 12 Infix Bitwise And Assignment No Assignment
* 2 Infix Multiply Yes Mathematical
** 2 Infix Exponentiation Yes Mathematical
*= 12 Infix Multiply Assignment No Assignment
+ 3 Infix Addition Yes Mathematical
++ 1 Postfix Increment Yes Mathematical
+= 12 Infix Addition Assignment No Assignment
- 3 Infix Subtract Yes Mathematical
-- 1 Postfix Decrement Yes Mathematical
-= 12 Infix Subtract Assignment No Assignment
. 0 Infix Method Access No Access
/ 2 Infix Division Yes Mathematical
/= 12 Infix Division Assignment No Assignment
:= 1 Infix Cast Assignment Yes Assignment
< 5 Infix Less Than Yes Relational
<< 4 Infix Shift Left Yes Logical Bitwise
<<< 12 Infix Insertion Yes Stream
<<= 12 Infix Shift Left Assignment No Assignment
<= 5 Infix Less Than Equal Yes Relational
= 12 Infix Assignment Yes Assignment
== 6 Infix Equality Yes Relational
> 5 Infix Greater Than Yes Relational
>= 5 Infix Greater Than Equal Yes Relational
>> 4 Infix Shift Right Yes Bitwise Logical
>>= 12 Infix Shift Right Assignment No Assignment
>>> 12 Infix Extraction Yes Stream
[] 0 Infix Array Access No Access
^ 8 Infix Bitwise Inclusive Or Yes Bitwise Logical
^= 12 Infix Bitwise Exclusive Or Assign No Assignment
` 0 Infix Attribute Access No Access
in 5 Infix Instance Of No Relational
is 12 Infix Reference Assignment No Assignment
as 12 Infix Instance Creation No Assignment
| 9 Infix Bitwise Inclusive Or Yes Logical Bitwise
|= 12 Infix Bitwise Inclusive Or Assign No Assignment
|| 11 Infix Logical Or Yes Logical Bitwise
~ 1 Prefix Complement Yes Logical Bitwise

Table of Operators, Precedence, and Overloaded

- 99 -
Standard Method Names for Overloads

The Mynx library of classes uses a set of standard names for overloading operators in specific classes.
When overloading an operator in a user-defined class, it is a good practice to use a standard name for the
method.

Operator Operator Name Standard Method Overload


= Assignment set, setIs
:= Cast Assign setAs
! Logical Not not
& Bitwise And bitAnd andis
&& Logical And and
| Bitwise Inclusive Or bitOr oris
|| Logical Or or
~ Bitwise Not bitNot
<< Bitwise Shift Left bitShl
>> Bitwise Shift Right bitShr
^ Bitwise Exclusive Or bitXor
< Relational Lesser Than isLT
> Relational Greater Than isGT
== Relational Equality isEqual isEQ
!= Relational Inequality isUnequal isNE
>= Relational Greater Equal isGE
<= Relational Lesser Equal isLE
<<< Stream Insertion put
>>> Stream Extraction get
% Math Modulus mod
* Math Multiply mul
** Math Power Of pow
+ Math Addition add
++ Math Increment inc
-- Math Decrement dec
- Math Subtraction sub
/ Math Division div

Table of Standard Operator Overloads by Method Name

Put logical short circuit or and and as separate operators although similar to
bitwise??

- 100 -
Implicit Hierarchy of Operators

The operators in Mynx that are overloaded have an implicit hierarchy. The operator overloads can change,
but the implicit hierarchy cannot change. The implicit hierarchy of overloaded operators is translated by
Mynx into the equivalent method calls for the methods that are overloaded. In the process of translation,
the operator hierarchy is preserved.

x = x**2 + 2*y + 1

Chart of Hierarchy of Operators for Expression

- 101 -
x.set(x.pow(2).add( y.mul(2).add(1) ) )

Chart of Hierarchy of Operators with Methods for Expression

- 102 -
VIII
Special Methods of the Class

- 103 -
A. Advanced Method Definition and Use
Mynx provides three advanced approaches towards defining methods, and using the methods. The three
advanced approaches are:

1. Method usage with a static method.


2. Method definition by a method equivalent.
3. Method definition that is incomplete.

B. Static Methods
A static method is a class method accessed through the class type or name. A static method is a single or
only one method, which does not maintain state between invocations, hence is stateless. Static methods
can provide class wide functionality independent of instances. A singular or static class is explicitly
declaring a class of nothing but static or class methods.

Kinds of Static Methods

There are three primary kinds of static methods:

1. static – a default static method that can be overridden


2. singular – a constant static method which cannot override
3. own – a virtual static method that is class own

Each kind of static method is for specifics for overriding the class method.

Overriding a Static Method

The three different kinds of static methods differ in the nature of overriding a static method.

Kind of Method Override


Own Yes, must implement in sub-class
Static Yes, can optionally override
Singular No, can never override

Table for Overriding a Static Method

A static method can optionally be overridden, but the override is invariant. Overriding a static method is
re-defining a class function definition, so not the same as specialization of an instance. Thus, a static
method as a stateless function cannot be covariant in return type when overridden and is always
invariant.

- 104 -
Examples of Overriding Static Methods

An example of overriding a static method in multiple classes is:

virtual class VSort is //define base class with own static

//declare static method that is virtual, must be overriden


public own void sort(var rankObject[]);

end class;

default class BubbleSort as VSort is //implement VSort

public construct is to null;

public singular void sort(var rankObject[] ro) is

//...implementation of bubble sort

end sort;

end class;

default class QuickSort as VSort is //implement VSort

public construct is to null;

public static void sort(var rankObject[] ro) is

//...implementation if quick sort


end sort;

end class;

- 105 -
Refine the QuickSort class method sort by checking if it is sorted in the QuickerSort class. The class
QuickerSort and method sort then is:

constant class QuickerSort as QuickSort, VSort is

public construct is to null;

public static void sort(var rankObject[] ro) is

if(! isSorted(ro) )
QuickSort.sort(ro); //call super-class static method
end if;

end sort;

private singular Bool isSorted(in rankObject[] ro) is


//...implementation
end isSorted;

end class;

Using the various classes that implement the virtual class VSort in a program:

program sortdemo is

//invoke static method


rankObject robj as randomRankObject.get;

//for each sort must call class by name, no instances


QuickSort.sort(robj);
QuickerSort.sort(robj); //already sorted, so will return
BubbleSort.sort(robj); //bubble sort best on already sorted

VSort.sort(robj); //compiler error! Invoking own virtual


// static method which is declared but not
// defined
end program;

using default package classes with implicit static reference ??

- 106 -
Prefix for Static Method

In order to use a static method, the method must be invoked, and invoking a static method uses a prefix
followed by a dot or period ‘.’ with the static method name, and then the parameters. The prefix for a
static method is different for a method called within a class in which it is defined or externally from
outside the class.

A static method can explicitly be invoked as a static or class method, or implicitly. Within a class, a call to
a method can be implicitly static without using a prefix, or explicitly using the prefix self. The prefix
self is similar to the instance prefix this, only for a class static method instead of an instance method.

When a static method is referenced from outside the class, the class name is explicitly used rather than
the instance variable name. A static class method can be invoked implicitly only by static method
inclusion. Then the static class method does not have to be invoked through the class name, but implicitly
similar to a static method invoked within its defining class.

Static Method
Class Scope Reference
Visibility
Implicit Explicit

nothing, default keyword self


Internal call to static references
Method static method
with statement name of the
External for inclusion Class
static class

Table of Static Method Prefixes

- 107 -
Program Methods as Default Static

A program that defines methods and attributes defines both as implicitly static. A program is similar to a
singular class, static and cannot be inherited. But all methods of a program are static, so referenced with
the prefix self explicitly, or implicitly by name with no prefix.

An example of invoking static methods and attributes in a program:

program exampleStatic as main is

let String greeting as String(“Hello World!!!”);

method helloWorld is

IO.put(self`greeting);

end helloWorld;

method main(String[] args) is

helloWorld; //implicit call to static method


self.helloWorld; //explicit call to static method

//implicit get attribute


IO <<< greeting <<< IO.eoln;

//explicit get attribute


IO <<< self`greeting <<< IO.eoln;

end main;

end program;

C. Implicit Static Method


An implicit static method allows a method to be referenced without the class name to prefix it. This is
similar to using a class name instead of the namespace, but for a public class method that is static or
singular, and is unambiguously referenced. Similar to overloaded methods, the method signature is used
to determine which static method is called implicitly.

Inclusion

Discussion of implicit static method inclusion.

For example:

with mynx.core.*;

if(x < Int.MAXIMUM)


//do something
end if;

The MAXIMUM method of the Int class is static, and is called to get the maximum range attribute. Using a
with inclusion statement for an unambiguous reference, the code can be simplified to:

- 108 -
with mynx.core.Int;

if(x < MAXIMUM)


//do something
end if;

The class must have an absolute namespace to explicitly include the Int class, and allow for implicit
static reference. A wildcard or relative reference is ambiguous, for there can be multiple classes which
define a static method of the same name. If there is a publicly static method in multiple classes that are
absolute in namespace, then the class name would have to be explicit in the method reference.

Attributes can never be referenced implicitly. Only a method using a dot or period to access within a class
can be implicitly referenced as static. However, the methods that access the attribute “getters” or
inspector methods can be used to provide implicit static reference.

Reference

A static method of a class can be used without prefixing the class name for static reference. This avoids the
repetition and verbosity of names of classes with names of methods. Mynx uses the classes included in a
with statement to determine the class associated with the static method.

Implicit static reference of a method can be used to refer to methods or attributes more naturally than full
prefix reference.

For example:

if(x.isReady == True)
flag NotReadyTrap;
end if;

The True is not a value or object instance, it refers to the class Bool, and the access or inspector method
True which returns the Bool instance of True defined as an enumerated type.

Rewritten with the static class name reference prefix:

if(x.isReady == Bool.True)
flag NotReadyTrap;
end if;

The requirement would be that the method is in a class which includes the Bool class either explicitly or
indirectly in a with statement.

Only public static (or singular) class methods can have implicit class prefix referencing not attributes. In
the example the Bool class value of TRUE is accessed by an access or inspector method of True but not
the constant attribute. Attributes can be accessed by static methods that are then used in their place.
Using the full Bool class attribute would require the full syntax.

- 109 -
Rewritten:

if(x.isReady == Bool`True)
flag NotReadyTrap;
end if;

The implicit static class prefix reference can be used with attributes or pure methods, for example:

var Int x to null;


var Real r to 2.7714;
x = Abs(r);

The Abs or absolute value method refers to the static method of the Math class. Rewritten with the full
static class name prefix reference:

var Int x to null;


var Real r to 2.7714;

x = Math.Abs(r);

If a class is not included utilizing a with statement, then it will generate a Mynx semantic error of
irresolvable reference to a static class method prefix.

Ambiguous class references occur when two or more classes have static methods defined with the same
method signature, and method name. In which case, the class name would have to be explicitly given, it
cannot be implicitly determined by Mynx.

D. Method Equivalents: Low Fat Methods


A method equivalent allows for defining a method by declaration in terms of other existing class methods.
A method equivalent is a shorthand way to define a method without writing the entire method. A method
equivalent has a method header, but not method body or footer.

Method equivalents are useful for:

1. default parameters to a method (overload a method)


2. alias a method with a different name without rewriting it
3. include super class methods explicitly in a class
4. define constructor and destructor as regular class methods
5. override a super class method with a different local method

A method is declared with the method head, and defined with a method body, which ends with the
method footer. However sometimes a method is a variation upon another and declaring and defining a
full method would be tedious and cumbersome. A method equivalent defines a method in terms of other
methods of the class. Any method, including constructor and destructor can be a method equivalent.

A method equivalent is like a fully declared and defined method, so can be public, private, or protect
access; similarly within the class a method equivalent can be scoped with other methods of the class.

- 110 -
For example:

class methodEquiv is

public construct is to null;


public desturct is to null;

end class;

The methodEquiv class has a constructor and destructor, only both are equivalent to a null, so are do
nothing methods of the class. The same constructors and destructors defined with full methods is:

class methodEquiv is

public construct is
null;
end construct;

public destruct is
null;
end destruct;

end class;

Default Parameters by Method Equivalents

A method equivalent is useful for default parameters, but without defining them in the method definition
(like C++), and without a complete method wrapped around the actual method (like Java).

For example:

public Int addition(in Int addend, in Int augend) is


//method body
end addition;

When defined in an integer class, the arithmetic methods take an implicit this to be used in the
operation.

Using an equivalent method to do so:

public Int addition(in Int augend) is addition(this, augend);

- 111 -
Fully declared and defined with a wrapper method would be:

public Int addition(in Int augend) is

this.addition(this,augend);

end addition;

Export Instance Method

A method equivalent can be used to export a static, or constant method, which is not public (or is
public…) as a default instance method. For example:

protect singular void myClassMethod is


// method body
end myClassMethod;

public void myMethod is myClassMethod;

The method myMethod exposes a hidden singular method as an instance method. Since overloading is
only applicable to public instance methods, method equivalents can be used to permit overloading of
static class methods.

Renaming All Class Methods of a Name

Method equivalents can be used to rename a class method, either in the child class of a parent, or within
the same class. This would avoid the tedium or re-defining the same methods again, or defining methods
as wrapper methods to a renamed method. For example:

public writeln is to putln;

A class could rename methods put and putln as methods write and writeln methods.

- 112 -
The fully declared and defined methods by the method equivalent are:

public writeln is //no argument method


this.putln;
end writeln;

public writeln(in String str) is //String argument method


this.putln(str);
end writeln;

public writeln(in Char chr) is //Character argument method


this.putln(chr);
end writeln;

public writeln(in Bool bool) is //Bool argument method


this.putln(bool);
end writeln;

public writeln(in UnsignedInt uint) is //UnsignedInt argument method


this.putln(uint);
end writeln;

public writeln(in Int int) is //SignedInt parameter method


this.putln(int);
end writeln;

Accessor Methods

A traditional accessor method get is of the generalized form when implemented in Mynx:

public <type> get is


return this`<attribute of type>;
end get;

The traditional accessor method to simply inspect an attribute is somewhat semantically ambiguous. The
semantic ambiguity is by the design and implementation of operator overloading and interaction of a
return of an overloaded reference to an attribute of the class.

- 113 -
Implicit Accessor Methods

For example, consider a class Point2D in Mynx representing a point in a Cartesian coordinate system:

class Point2D is

private UnsignedInt x to null;


private UnsignedInt y to null;

public construct(in UnsignedInt i,j) is


this`x = i; //x.set(i);
this`y = j;
end construct;

public Unsigned get(in Unsigned ui) is


return ui;
end get;

public Unsigned X is to get(this`x);


public Unsigned Y is to get(this`y);

end class;

The ambiguity using an access in the accessor methods is illustrated in the code fragment, with the
overloaded operators translated to the equivalent method calls:

var Point2D p to (0,0);


var UnsignedInt ui to null;

ui = p.X; //getter gets attribute


ui.set(p.X);

p.Y = ui;
p.Y.set(ui);//getter now setter

In the Point2D class, the accessor methods X and Y are defined using method equivalents of the accessor
method get. Clearly from the code fragment, get is no longer a simple inspector accessor method. An
accessor the returns a reference or handle to an attribute that is overloaded with an operator indirectly
creates a full access accessor method.

One possible solution is a compiler semantic check for accessor methods by name of get and set.
Unfortunately this implicitly places the keywords get and set into the programming language reserved
word or vocabulary, but indirectly. It also adds a complication to the compiler of the language.

Another solution is to simply do nothing, but this leaves a subtle side effect in the programming language,
one that could create a minor wrinkle that impacts the integrity of the Mynx language.

Explicit Accessor Methods

A much more useful solution is to add three keywords to the language, and use a variant of method
equivalents to create explicit accessor methods to read, write, and access class attributes. The syntax is:

to ( reader | writer | access ) IDENTIFIER ;

- 114 -
Essentially the access kind becomes an implicit method name with an identifier as method parameter, but
not using an explicit existing class method.
There are three modes to an accessor of a class attribute:

1. reader – read the class attribute as an inspector or use as r-value in an expression.


2. writer – write the class attribute as a mutator or use as l-value in an expression.
3. access – read or write the class attribute, either as an r-value or l-value in an expression.

The three modes effectively cover the operation of accessing a variable that represents memory in a read-
only, write-only, or read-write manner.

Rewriting the Point2D class in the changed syntax using method equivalents, but have equivalent
functionality for accessor methods:

class Point2D is

private UnsignedInt x to null;


private UnsignedInt y to null;

public construct(in UnsignedInt i,j) is


this`x = i; //x.set(i);
this`y = j;
end construct;

public Unsigned X is to access x;


public Unsigned Y is to access y;
public Unsigned getX is to reader x;
public Unsigned setX is to writer x;

end class;

Using and expanding the original code fragment to illustrate:

var Point2D p to (0,0);


var UnsignedInt ui to null;

ui = p.X; //X is access, so read-write


ui.set(p.X);

p.Y = ui; //Y is access, so read-write


p.Y.set(ui);

p.getX = ui; //error, readable not writeable


p.setX = ui;

ui = p.setX; //error, writable not readable


p.setX = ui;

An added advantage to this approach is that an attribute can be easily defined with an accessor method
without fully defining a complete “wrapper” method, and the definition is explicit in creating an accessor.

- 115 -
E. Class Creation, Destruction, and Default

There are three special methods of a class, two are to create and destroy instances or objects of a class.
The methods are a constructor, destructor, which are a special kind of method in a class. The third
method is the default implicit method of the class. All special methods are not directly accessible or
explicitly invoked, but are indirectly called through usage of a class.

Special Method Number Restrictions


Constructor At least ≥1 Not for static, singular, or partial classes
Destructor Optionally ≤ 1 Not for singular, static, or partial classes
Default Optionally ≤ 1 Not for static or singular classes

Table Synopsis Special Class Methods

F. Constructor

A constructor is used implicitly to create a new class instance, or an object. A non-partial and non-static
class must have at least one constructor defined, and there is no automatically created or a predefined,
given constructor (like in Java and C++, although a compiler could generate one but this is an
implementation feature, and not a programming language feature...).

A virtual class can never define a constructor (as it is a class specification), nor can a static or singular
class (as a static class will never create any instances.) An abstract class can optionally define a
constructor, a constant or default class must define at least one constructor. Since a program is not a
class, it never has any kind of a constructor.

Constructors are never inherited from the parent classes. A constructor can be overloaded on different
parameters, but never returns a value, hence a constructor has no method type.

Constructor Definition

A constructor is defined like a method, but rather than a return type or a method name the keyword
constructor is used instead. Similar to methods, a constructor can be public, private, or protected
access. A constructor can have parameters or arguments exactly like a method, or no parameters in the
constructor header. The constructor is defined internally like a method, using statements to initialize the
class instance. The constructor uses a footer like a method with the constructor keyword instead of the
method name. A constructor, like a method, can be overloaded with different parameter signatures for
each constructor.

A general form of constructor definition is:

ACCESS construct PARAMETERS is

//code to initialize class

end construct;

One special type of constructor is the default constructor, a public constructor that takes no arguments. A
default constructor is useful to create an instance of a class in a default state.

- 116 -
An example of a default constructor:

public construct is

null;

end construct;

A non-default constructor is any constructor that takes arguments in the parameter list.

An example of a non-default constructor:

public construct(in Int i) is

this`int = i;

end construct;

A constructor is like a method, and like a method can be defined by using a method equivalent. A
constructor can be defined by a method equivalent as:

1. A set of default parameters to existing constructor or method


2. A reference to a super-class constructor or methods.

Example of defining a constructor by method equivalent:

class childClass as parentClass is

public construct(in String s) is to super.construct(s);

public construct is this.constructor(0,0);

public construct(Int I, Int j) is


//define constructor
end construct;

public construct(Int x) is to this.construct(x,0);

end class;

- 117 -
Example of Defining Multiple Constructors in a Class:

class 2DPoint as Void is

private default variable Int i to null;


private default variable Int j to null;

public construct is to this.construct(0,0);

public construct(in Int x, in Int y) is

this`i = x;
this`j = y;

end construct;

public constant x is //access x-coordinate as method

return this`x;

end x;

public constant y is //access y-coordinate as method

return this`y;

end y;

end class;

Constructor Invocation

A constructor is invoked indirectly, either through:

1. Create expression as part of an expression statement.


2. As part of the declaration of a variable or constant.

When invoked, a constructor is invoked on the same class type, not a sub-class or super-class of the
variable or constant type.

Examples of invoking a constructor by declaration:

public Int x to 0; //invoke constructor(Int)


public String str x to “hello world!!!”; //invoke constructor(String)
private Point p to (0,0); //invoke constructor(Int)

- 118 -
Examples of invoking a constructor by creation:

x as Int(0);
str as String(“hello world”);
p as Point(0,0);

There are two special cases of invoking a constructor:

1. Invoking a default constructor.


2. Not invoking a constructor.

Invoking the default constructor is difficult as it is a call to a constructor without any parameters. In order
to invoke a default constructor in a declaration, the keyword default is used instead of any parameters.
In a creation expression the class name is used without any parameters. If a default constructor is invoked
without the class having one, then it will generate a compiler error.

Examples of invoking a default constructor:

var Int x to default; //invoke default Int constructor


var String str to default; //invoke default String constructor
var Point p to default; //invoke default constructor

x as Int; //invoke default Int constructor


str as String; //invoke default String constructor
b as Point; //invoke default Point constructor

Non-invocation of the constructor is to declare or create an instance that is null. The syntax for not
invoking a constructor is similar to invoking the default constructor, except that instead of the keyword
default the keyword null is used.

Examples of not invoking a constructor:

var Int x to null;


var String str to null;
var Point p to null;

x as null; or x is null;
str as null; or str is null;
b as null; or b is null;

In the creation expression involving null, the as creation operator is equivalent to the is assignment
operator, but only in the case of null.

- 119 -
Using the 2DPoint class in a program:

program 2PointProgram is

var 2DPoint defaultPoint to null;


var 2DPoint aPoint to (100,100);
var 2DPoint thePoint to default;

defaultPoint as default; //use default constructor

end program;

G. Destructor

A destructor is used to implicitly destroy (more like clean up afterward) or destruct a class instance when
the instance is terminated. A class can optionally define a destructor, but like a constructor a destructor is
never automatically provided, and is never inherited by a sub-class. A class's destructor takes no
parameters, and therefore can only be one destructor defined, so no overloading of a destructor. Similar
to a constructor, a destructor returns no value, so has no method type. There is no guarantee of when a
destructor will be executed, so a destructor is more of a post-check method, to verify that a class is
properly terminated.

Destructor Definition

A destructor is like a constructor in declaration, but only the keyword destruct is used instead of
construct in the header and footer. Unlike a class constructor, a class can only have one destructor,
which takes no parameters. A destructor can be public, private, or protect access. A class with a private
destructor never can invoke the destructor implicitly.

The general form of a destructor is:

public destruct is

//cleanup class before terminating

end destructor;

A destructor can be defined using a method equivalent, similar to a method or constructor. A destructor
must be defined in terms of method equivalents, as no other destructors can be defined except the one
destructor.

Example of a Destructor with Method Equivalent:

public destructor is to this.cleanup;


public destructor is to this.exitClass;

- 120 -
Destructor Invocation

A class destructor is never explicitly invoked directly; it is invoked when the class is taken out of service by
the underlying runtime (at this writing July 2004, the .NET or JVM platforms) when garbage-collected.
A better class design approach is to use a method to deactivate and take an instance out of service (in this
case, the super-class VObject method nullify) and then by method equivalent to define the destructor
in terms of that method. Then the instance can be deactivated explicitly by the user, or implicitly by the
runtime platform using the same functionality.

An example of defining a destructor by method equivalent with nullify is:

default class fileProcessor as Void, VObject is

private File procFile to null;

public construct(in String filename) is

this`procFile as` File(filename);

if(! this`procFile.isReady)
this`procFile is null;
this`procFile.nullify;
end if;

end construct;

public void nullify is


this`procFile.close; //always close file
this`procFile.nullify; //nullify file instance
end nullify;

public destruct is to nullify;

end class;

Like a constructor, only an abstract, constant, or default class can define a destructor. There is no
guarantee when a destructor is called, if an instance is destroyed explicitly through a nullify method, and
then the destructor is invoked. If an instance is destroyed implicitly, then the destructor is called upon
garbage collection, or upon the end of the application, which ever occurs first, with no assurance of when
the destructor is called.

A destructor is useful as a post-check for proper termination and clean-up of an instance, rather than as a
guaranteed means for the disposal and release of resources utilized with an instance.

H. Default Class Method


A special class method is defined as a method equivalent, and is the implicit or default method of the
class. An implicit default method is invoked when an instance is referenced without invoking a method, or
accessing an attribute. Static classes, those classes that are static or singular, do not have a default
method as there is never an instance of a static class.

When an instance is used, either with no arguments, or with arguments, an implicit instance method
called the default method is invoked. A class with a default method never explicitly invokes the default
method, as the keyword default is a reserved word.

- 121 -
Default Method Declaration

The default method is a method equivalent with an existing class method. The method equivalent
definition uses the keyword default for the method equivalent name.

Declaring the default implicit method is:

public default is to myMethod;


public default is to super.default;
public default is to this.doSomething(0);

A class can only define one default method, and a default method is not inherited from a parent class
(although as illustrated, a default method can be equivalent to the parent class default method). A class
cannot overload an operator with the default method. A partial class (virtual, abstract) and static class
(static, singular) classes never define a default method (as instances can not be created...), so hence only a
class with constructors (a class that can create an instance) can have a default method.

Default Method Invocation

A default method is never invoked explicitly on an instance. A default method is invoked implicitly when
no method is invoked explicitly.

For example of using implicit default method:

zeroInt to Int(0);
oneInt to Int(1);
sum to Int(0);

sum = zeroInt; //implicitly call get method

The equality operator = is overloaded with set or the assign. The simple expression statement becomes:

sum = zeroInt;
sum.set(zeroInt);

The instance zeroInt invokes the implicit default method of get, which gets the value of zeroInt. The
expression then is:

sum.set(zeroInt);
sum.set(zeroInt.get);

- 122 -
The default method of a class depends upon the functionality and use of a class. A default method can also
be called with parameters, depending on the class. For example, a class instance out of an output stream
with a default method:

out(“hello world!!! \n”);

This method call will implicitly invokes the default method of the IO class, which is put to output text to
the default output. The expression is then:

out.put(“hello world!!! \n”);

The default method is used when no other method is specified, in essence; Mynx requires all instances to
explicitly invoke a method. If an instance does not invoke a method, and does not have a default method,
then there is a semantic error.

I. Incomplete Methods

Two class kinds, abstract and virtual or partial classes, allow for methods to be declared by the method
signature and access, but not defined with statements. An abstract class can allow for method definition,
but a method that is abstract then becomes like a virtual method, declared by not defined.

An example of an incomplete method in a class involves an abstract data structure class, ATrove. The
class has a method for getting and setting data, but it is undefined as it is implementation specific.

abstract class ATrove as Void is

public abstract VObject get;


public abstract void set(in VObject);

end class;

J. Other Special Methods


There are two other kinds of special methods: implied and obviate. An implied method is a concrete,
default method, but is defined in the implementing target language not in Mynx. An obviate method is a
method declaration which removes a method from a class interface, a means to redefine a method by
declaration to undefined it.

- 123 -
- 124 -
IX
Traps

- 125 -
A. Concept of Trap
An exception or trap (as it is called in Mynx) is the basis for error notification and handling in Mynx. A
trap is an exception in Mynx (think of a trap snaring an error…), and a statement will flag a trap (like
flagging down a passing car…) within the statements of a method.

B. Kinds of Traps
There are two primary kinds of traps or exceptions in Mynx:

1. Checked – force the calling method to handle any traps.


2. Unchecked – do not require calling method to handle traps.

There has been considerable discussion in the two major object-oriented language camps (Java and C# at
the time of this writing…) concerning exceptions which are checked (forced to handle) and unchecked
(not forced to handle.)

Mynx uses an approached of unchecked, unless the trap or exception is declared in the method header.
There are no special exception classes which require check or unchecked (as in Java), nor is the
unchecked exception approach forced (as in C#). The Mynx approach to exceptions or traps is that the
choice is the responsibility of the software developer, and so provides ways for both options to be used in
writing source code.

C. Declaration

A trap is declared as part of a method header (there are no traps for attributes…) as a clause that begins
with the keyword has and ends with the keyword is with a following list of identifiers that are the traps
the method can flag. Any declared traps in a method must be handled, but a method can flag traps that are
not declared in the method header. Any methods invoked can likewise flag a trap that is not declared in
the method header, or can be to require handling the possible trap that is flagged.

Example exception or trap declarations:

public openFile(in String name) has FileNotFoundTrap,ReadOnlyTrap is


public Int divide(in Int divisor) has ZeroDivideTrap is

D. Invocation
A trap is caused or raised with a flag statement. A flag statement begins with the keyword flag, followed
by the identifier name of the trap, and any information for the constructor. The flag statement creates the
trap object with any parameters such as message, or error number, and the method is exited. The point of
execution in the statements returns to the caller method, and an encompassing try statement.

The class for the trap is declared and defined separately, then included in the class or program.

Example flag statements:

if(divisor == 0)
flag ZeroDivideTrap;

flag InvalidInput(“Enter a character”);

- 126 -
E. Handling

A trap is handled with a try statement. A try statement consists of the try clause which begins with the
keyword try, any statements which can flag traps, and then a series of when clause to handle particular
exceptions with an ending end tries to enclose the block. Then, when-blocks begin with a when- clause,
which is the when keyword, and then a pair of parenthesis with the trap name, and variable if the trap
instance is to be used.

A trap must be declared, but a trap variable does not if the trap instance is not to be used (i.e. invoke
methods on the instance to get trap information, etc.).

Example of a try statement:

try
x.doSomethingDangerous;
when(ZeroDivideTrap) //handle, but no instance
//handle it
when(InvalidInputTrap i) //handle, but with instance of trap
null;
end try;

Two other clauses for a try statement are else and do. An else clause is a set of statements that execute if
no trap is flagged in the try clause. An else clause is the next or last clause in the try statement, beginning
with the keyword else.

Example try statement with else:

try
x.doSomethingDangerous;
when(ZeroDivideTrap) //handle, but no instance
//handle it
when(InvalidInputTrap i) //handle, but with instance of trap
//handle it
else
IO.put(“No traps.”);
end try;

A do-clause is the last clause of a try statement, and is always executed last, after handling an exception,
executing an else, or after executing the statements in the try clause. The do-clause begins with the
keyword do, and then statements to be executed.

The try statement does not allow any exit, next, or return statements to be executed in the clauses within
(if present...) the do clause of a try statement. This restriction on statements within the do clause is to
avoid ambiguity and confusion in flow of control with a method or iterative statements.

- 127 -
Example of a try statement with do:

try
x = file.readInt;
when(FileNotReadyTrap) //handle, but no instance
//handle it
when(InvalidInputTrap i) //handle, but with instance of trap
i.doSomething;
do
x.close; //always close the file
end try;

Like an if statement, a try statement cannot break from the flow of control prematurely, the normal flow
of execution is followed (in contrast to a loop…). Hence there is no possible flow of control exit try or
next try statement.

Example of invalid try statement:

loop

try
inInt = in.readInt
when(NonIntegerFormat) //handle by continuing
next;
do
return; //error: return invalid in do-clause of try
end try;

end loop;

Like an if statement, a try statement cannot break from the flow of control prematurely, the normal flow
prematurely, the normal flow of control is followed. Hence there is no exit try or next try
statement.

F. Propagation
A trap can be handled with a when clause, and then flagged again to propagate the trap, possibly with
other exception or debugging information.

Example of propagating a trap:

try
x.doSomething
when(Trap)
flag OtherTrap(“some information”);
end try;

- 128 -
G. Unhandled Traps
An unhandled trap is automatically propagated up the chain of method calls, until it reaches the top-level
calling method, and if unhandled, will cause an application to halt with a report on the trap.

- 129 -
- 130 -
X
Generic Classes

- 131 -
A. Parameterized Types
A generic or parameterized type class is a class that is fully declared and defined, except for the primary
type. Only a class can be generic, there is no concept of a generic program in Mynx. A generic class is an
abstract class in that the class type is abstract, or generic.

A generic class is an abstract class, completely concrete except for the type, which must be instantiated
with the class for an instance to be created. A Mynx generic class can only be generic on one type, multiple
generics are not supported.

A generic class allows for general-purpose classes to be defined, and used with specific types for strong
typing without having to rewrite and re-implement the same class functionality again. A generic class is
declared and written as a regular class, except that parameter arguments are generic.

B. Attributes and Methods

A generic class has attributes and methods that can be generic or undefined type. Unlike a default class, a
generic class does not process the generic elements within a class.

Attributes

A generic attribute, like an attribute for all classes, must be initialized, but as it is a generic attribute it is
initialized to null. A generic attribute is an undefined type, so cannot be initialized to a specific class type
or value. No methods can be invoked on a generic attribute within the defining class methods of a generic
class.

Methods

The generic methods of a class can take a generic parameter or return a generic result. But, the methods
cannot invoke methods on the generic parameter, nor process the parameter passed or result returned.

Generic parameter modes – in, out, var, series ??

C. Definition

In a generic class the keyword generic is used in place of a formal class type such as Char, Int, or
String. When a generic class is instantiated, then the type of generic is the instantiation type.

- 132 -
Example of a generic class:

generic class GStack as Void is

private Vector stack to null in for pop, push;

public construct is

this`stack = new Vector;

end construct;

public generic pop is

var Void element to null; //element is Void, root class

if(this`stack.size == 0)
flag StackUnderFlowTrap;
end if;

element = stack.remove(stack.size-1);
return (element to generic); //cast and return element

end pop;

public void push(in generic element) is


this`stack.add(element);
end push;

public UnsignedInt size is


return this`stack.size;
end size;

end class;

D. Inheritance

Similar to a static class, a generic class can only inherit from another single generic class. Inheriting a
generic class is for specializing and refining a generic class; while still being abstract about specific class
type. A generic class can only inherit one generic class at a time, unless it inherits multiple virtual classes
(no multiple disjoint inheritance.)

- 133 -
The syntax used to inherit a generic class is the same as for all classes. An example of inheriting a generic
stack is:

generic class betterStack as GStack is

public generic peek is //add peek at top-level element

var generic element as null; //generic attributes init to null

element is super.pop;
super.push(element);
return element;

end peek;

public Bool isEmpty is


return 0 == super`size;
end isReady;

end class;

The derived class adds a new method to peek at the top most element of the stack. The added method or
attribute need not be specifically of a generic type, as the example illustrates.

E. Instantiation

In order to use a generic class, the class must be instantiated, or bound to a specific class type. The
instantiation type can not be another generic class, or to the self abstract type. Hence a generic stack class
of generic queues is not a valid class type for instantiation.

Instantiation is separate from class inheritance, instantiation creates a class, and inheritance uses a class
to add additional functionality. Instantiation binds the generic class to a class type, effectively creating a
useable class based upon that type. The instantiated class is a default class, and can be used like any other
default class in Mynx.

F. Types of Instantiation
A generic class needs to be instantiated or bound to a specific class type before it can be used.

Instantiation of a generic class is in one of two possible ways:

1. class – global instantiation


2. attribute – local instantiation

Global Instantiation

Class level or global instantiation of a generic class creates a new class type, which is available as a default
class. Attribute level or local instantiation creates a local type within the class that the generic class is
instantiated. The class instantiation syntax is a non-template style from C++ to keep instantiation syntax
from becoming mangled.

- 134 -
The syntax for instantiating at the class level is:

class IntStack as Void has GStack to Int is

//create new method in created class


public void myMethod is
null;
end myMethod;

end class;

Class level instantiation creates a new class, and new attributes and methods can be defined when the
class is instantiated. The has-to clause of the class header declares what generic class, and the instantiated
class type. The created default class type can inherit other classes as well as instantiate to a class type.

For example, the generic class GStack when instantiated with the class type Int would be effectively the
code of:

default class IntStack as Void is

private Vector stack to null in for pop,push;

public construct is
this`stack = new Vector;
end construct;

public Int pop is

var Void element to null; //element is Void, root class

if(this`stack.size == 0)
flag StackUnderFlowTrap;
end if;

element = this`stack.remove(stack.size-1);

return (element to Int); //cast and return element

end pop;

public void push(in Int element) is


this`stack.add(element);
end push;

public UnsignedInt size is


return this`stack.size;
end size;

end class;

- 135 -
Local Instantiation

Local instantiation of a generic class to a class type creates a local copy, but does not create a class that
can be used beyond the locality of the instantiation within the class.

The syntax for instantiating at the attribute level is:

class Example is

public GStack has Int myStack to 0;

end class;

Attribute level instantiation creates a class that is defined within the class where it is instantiated. In the
given example class, myStack is a class attribute which is a generic GStack bound to a class type of Int.
But, the class myStack is local to the class Example, so it cannot be used like a default class.

G. Inheriting Other Classes

There are only two other classes a generic class can possible inherit:

1. abstract – using disjoint multiple inheritance


2. virtual – using multiple inheritance
Both abstract and virtual classes can be intermixed with inheritance in a generic class. A generic class, like
a default class, can inherit one or many abstract classes. However, with inherited multiple abstract classes
must be of disjoint multiple inheritance. A generic class, like with an abstract class, can inherit multiple
virtual classes. However, a generic class must implement all methods of the virtual class, which are non-
generic.

H. Using an Abstract Self Method Type


A class with a method type of self is useable within a generic, when the generic class is bound to type by
instantiation the method type using self, like the generic type takes the new class type.

For example, a generic class GStack with a self cast method would upon instantiation to Char type as
charStack would now cast to charStack.

- 136 -
generic class GStack as Void is

//define GStack push, pop, size

public self cast (in self castFrom) is

if(castFrom in self)
return castFrom to self;
else
return null;
end if;

end cast;

end class;

When instantiated either locally or globally using the type class Char, the instantiated generic class is the
same as a default class with the instantiation type:

default class charStack as Void is

//body of instantiated type class

public charStack cast (in charStack castFrom) is

if(castFrom in charStack)
return castFrom to charStack;
else
return null;
end if;

end cast;

end class;

I. Defining Abstract Methods

Generic classes are a form of abstract class, so can be declared but not defined or abstract in nature. A
generic class can contain an abstract method in the declaration of the class. However, such an abstract
method in a generic class will make the class unable to instantiate, and must be inherited and defined in
the sub-class.

An example of a generic class with an abstract method is in defining a generic Vector class, with abstract
methods. One method isEmpty is defined in terms of an abstract or undefined method size.

- 137 -
generic class GVector as Void is

public abstract UnsignedInt size in for isEmpty;

public Bool isEmpty is

if(size == 0)
return Bool.True;
else
return Bool.False;
end if;

end isEmpty;

public abstract generic[] toArray; //?

public abstract void add(in generic element);

end class;

- 138 -
XI
Statements

- 139 -
Mynx statements are the basic means for expressing functionality of methods, and the data of attributes.
Mynx has seventeen statement types, and six categories of statements.

Each statement is either a single-line or multiple-line statement. A single-line or singular statement


begins with the statement keyword, and ends with a semicolon. A multiple-line or multiple statement
begins with the statement keyword, and then follows with statements, and ends with the suffix of end
along with the keyword, and a last semicolon. There are eight single-line and nine multiple-line
statements.

The 17-statements are organized into 5-categories of statement:

1. repetition or iteration
2. selection or decision
3. error
4. flow of control or jump
5. computation
6. mutual exclusion

Statement Category Type


Assert Error Singular
Case Selection Multiple
Exit Flow of Control Singular
expression Computation Singular
Flag Error Singular
For Repetition Multiple
If Selection Multiple
Loop Repetition Multiple
Mutex Mutual Exclusion Multiple
Next Flow of Control Singular
Null Computation Singular
prefix if Flow of Control Singular
Repeat Flow of Control Multiple
Return Flow of Control Singular
Try Error Multiple
Until Repetition Multiple
While Repetition Multiple

Table of Statement Category and Types

- 140 -
A. Computation

The computation statements “do” or compute something, such as invoke a method, evaluate an
expression, assignment to a variable, declare a variable, etc. The two computation statements are
expression, which does actual computation, and the null statement that does nothing but is an explicit
statement of no operation.

Expression Statement

An expression statement is a computation statement that computes a value or an object representing a


value. There are two primary kinds of expression statements:

1. declaration – declare and create an instance of an class as an object


2. expression - computation statement to compute a value or change state

Declaration

A declaration statement is a declaration within a method, and has a similar syntax to a class or program
attribute. A declaration statement is preceded by the keyword var to distinguish the declaration from an
expression statement. Unlike a class or program attribute, a declaration sub-statement does not need an
initial value. A declaration without an initial value merely declares a variable and initializes it to a value of
null. A declaration with or without an initial value declares and creates an instance of a class as an
object, invoking the class constructor.

var Int x to 0;
var Char c,d; //no initial value, just a declaration to null;
var Point p to null;
var Real r to default;
var String[*] tables to { “0”,“1”,“2”,“3” };

Expression

An expression statement is a computation statement that evaluates an expression form to compute and
create an object instance for the value of the evaluated expression. The operators used in an expression
statement are overloaded to represent a method call or access to compute a value. An expression
statement has five sub-expression statement types:

1. postfix
2. assignment
3. creation
4. input-output
5. access

Postfix

A postfix expression involves a variable, method call, or an instance object, and the method which the
postfix operator (++ or --) which is overloaded. For the integral numeric types the increment operator ++
overloads the increment method, and the decrement operator –- overloads the decrement method.

- 141 -
var Int x to 0;
var Int y to null;
x++;
y = (this.getValue)--;

Assignment

The assignment sub-expression statements assign or associate a value of an expression to a instance


object by the identifier. An assignment statement can be of one of three forms:

1. Assign – associate an object value to an object instance by the identifier


2. Create – create a new class instance as an object, and assign it to an identifier
3. Input-output – assign but to an input or output stream variable

Assign

Assignment statements use a left value, right value, and are separated by an assignment operator. The left
value must be an identifier, array access, or attribute access. The right value can be an expression, literal,
method call, attribute access, or array access.

x = 3;
y += x+7 / 2;
z = this.computeValue(x,y);
data[3] = 17;
x`y := i+j*3;
total = x**y + 1;
q is y;
this`y = 0;
self`ct = super.getCount;

Create

A create or creation statement is an assignment expression that creates a new instance of a class and
assigns it to an object reference or variable. The keyword as follows the object reference variable and the
class name with any constructor parameters.

- 142 -
An example of a creation expression statement:

var Int x to null; //declare an initial values to null


var Int y to null;
var String z to null;

x as Int; //default construct


y as Int(-1234); //create -1234 Int
z as String(“hello world!!!”);//create String
x as Byte; //create sub-type of parent type instance

x as null; //compiler error! Null is not valid class to create


y as default;//compiler error! Default constructor by class name
z as Int; //compiler error! Incompatible class type Int to String

Input-Output

An input-output sub-expression is exactly similar to an assignment statement, however, instead of


assigning an object value to an object instance by identifier, the assignment is an object instance to input
or output stream. The operators for an input-output are the stream operators.

IO <<< x <<< eoln;


IO >>> inputLine >>> eoln;

Access

An access sub-expression statement will access a value as if it were computed in an evaluation of an


expression. There are three kinds of access sub-expressions:

1. attribute – access the attribute of a class


2. method – access the method of a class
3. array – access the element of an array
4. multiple – access multiple times nested

Attribute

An access sub-expression for an attribute is accessing an attribute of the class instance or super-class. An
attribute accessed, can be read or written, depending on if the attribute is a constant or variable.

this`total = 0; //write access of class attribute


y = super`rawData; //read access of class attribute

- 143 -
Method

The access statement for a method is a method invocation is the calling of a method in the current class,
super class, or on an instance of a class.

this.callMethod(0,”hello”);
super.invokeMethod(‘a’);
x.doIt;

An object instance variable or constant by itself is potentially a method access if the default method of the
class the object is an instance of is defined and invoked.

this.x; //default invocation


super.y; //default invocation
data; //default invocation

Array

An access sub-expression for an array is accessing an array element of the method or class. An array
access can be read or written. The sub-script of index into the array can be a literal constant, variable, or
an expression.

y = data[x];
data[base+count*sizeof(data)] = 0;
x[0] = y;

Multiple

The access statement can be made up of multiple accesses, such as accessing a method, then an attribute,
an array, and so forth. Note that a super or this reference only appears as the first element of an access
statement.

this.callMethod(0,”hello”).doSomething`rawData[x];
super.doIt[x]`data;

Null Statement

The null statement is an empty statement, which does nothing. Instead of a blank or single semicolon on a
line, Mynx null statement is explicit.

public doNothing is
null;
end doNothing;

A null statement can be useful as a “placeholder” for possible future statements.

- 144 -
B. Error
The error statements include explicit error assertion checking with an assert statement, and error flagging
with a trap, and handling a flagged trap with a try statement.

Error statements are for debugging software and to manage software errors as they occur in software.
Methods can require that a trap error must be handled with a try statement. The method then must flag
the trap when it occurs, and a caller of the method must handle the error with a try statement or
propagate it by declaring it as a flagged trap of the method.

One form of error statement, the assert statement is for debugging software under development, and the
other kinds of error flagging and handling are for handling software errors.

Assert Statement

The assert statement is used to debug software. The assert statement is compiled during a debug build by
the compiler, but during a release or final build becomes a null statement and is excluded from the
compiled source.

As the assert statement is for debugging purposes, it is a very simple statement. An expression is asserted,
and if it is not true, then the assert statement causes execution of software to stop, along with reporting an
error message, and an optional literal string message. Assert statements are not intended for sophisticated
error handling or logic, only to assist in debugging source code.

Example assert statements:

assert x > 0 as “variable x is not positive” ;


assert x != null ;
assert x != y && y > 0 as “x and y assertion failure” ;

Flag Statement

The flag statement is used to raise, or flag an exception or trap. The flag statement takes a class that is the
trap to be flagged. Essentially the flag statement creates a new instance of the trap class, and then returns
from the method to the caller.

Example flag statements:

flag IOTrap(“Device not ready.”);


flag FileNotFoundTrap(“File does not exist.”);
flag IntegerOverFlow;

Try Statement

A try statement is the counter part to a flag statement, a flag statement creates and propagates a trap, the
try statement tries to handle the trap.

A try statement encloses statements within a try-clause, and then has a series of when-clauses for the
traps it handles, and then has an else-clause optionally, and an optional do-clause.

- 145 -
A try statement restricts placing a flow of control statement (exit, next, return) in the do-clause of a
try statement. This is to avoid flow of control ambiguity in a try statement.

A when-clause has the trap class, and an optional identifier to associate with the instance.

Example try statement:

try
file = File(“test.data”);
when(FileNotFoundTrap)
IO.putln(“File was not found.”);
do
file.close;
end try;

Example try statement:

try
file = File(“test.data”);
when(FileNotFoundTrap fnf)
IO.putln(“File was not found. Error: ”+fnf.getMessage);
else
IO.putln(“File was opened successfully.”);
do
file.close;
end try;

An example of an invalid flow of control statement return:

try
return 0;
do
return 1; //compiler error: invalid flow of control
end try; //from try do-clause

Another example of an invalid flow of control statement next:

loop

try
next loop(0);
do
next loop(0); //compiler error: invalid flow of control
end try; //from try do-clause

end loop(0);

- 146 -
C. Flow of Control

Nesting and need for non-sequential exit and next stepping through the iteration statements. Not valid for
try, if, or case. Statements, in particular the repetition category of statements, are nested often. There are
times when a non-sequential skip or continuation from a nested loop block is efficient. An exit statement
exits or skips out from a nested block of repetition statements, a next statement continues to the next
cycle of a loop cycle.

The repetition statement blocks can be nested, and with each nesting have a nesting level in the form of a
parenthesized integer following the end clause before the semicolon. The nesting level starts at zero and
progressively counts upward by an increment of one, so the range is 0..n-1 for n nested repetition
statements. An exit or next can specify the level to which an exit or next is reached, the default being the
current repetition statement only.

Exit Statement

The exit statement is used within an iteration statement, such as a loop, while, or for, or statement.
The exit statement causes an immediate exiting of the iterative structure, a jump to the end clause of the
iteration block statement.

for(Int x is 0 to 100)
for(Int y is 0 to 200)
if(x == 100 && x == y)
exit for(0);
end if;
end for(1);
end for(0);

An alternative example:

var InputFile file to (“input.data”);


var Bool status to (Bool.False);

file.open;

while(! file.endOfFile)

//read 100 records


for(Int i is 0 to 100)

this.processRecord(file,i,status);
if(!status)
exit while(0);
end if;

end for(1);

end while(0);

file.close;

- 147 -
Next Statement

The next statement is like an exit statement, except that instead of exiting a repetition statement, it
continues to the next cycle of the repetition statement. A next statement can skip to continue to an outer
repetition statement in which the next statement is nested.

public void findInMatrix(in Matrix matrix) is

var Int col to matrix.getCol;


var Int row to matrix.getRow;
var Int val to –1;

for(Int x is 0 to row)

for(Int y is 0 to col)

val = matrix.get(x,y);
if(val == 0)
next for(1);//skip to next y
end if;

end for(1);

end for(0);

end findInMatrix;

Prefix If Statement

A prefix-if statement is a specialized form of if-statement, which combines an exit or next statement into a
single statement form. A prefix-if statement is used mostly within a loop statement, to define the exit or
next condition for a loop.

exit(0) if ( i >= j );
next(2) if ( foundFlag );

public UnsignedInt findFirst(in Int[*] list, in Int val) is

var UnsignedInt where to 0;

for(index is 0 to list.size)

where = index;
exit for(0) if(list[index] == val);

end for(0);

return where;

end findMax;

- 148 -
Return Statement

A return statement returns or exits a class or program method, and can return a value. The value returned
from a method must correspond with the method type or return nothing if the method is a void type
return or procedure. The type null is a valid return type for all return values except void, indicating a null
or non-initialized object reference return. A return statement is like a non-sequential exit that can return
a value from a method.

public Int findFirst(in Int[*] list, in Int value) is

for(Int x is 0 to list.length)
if(list[x] == value)
return value;
end if;
end for;

return null;

end find;

public UnsignedInt factorial(in Unsigned uint) is

if(uint == 0)
return 1;
else
return (uint * factorial(uint-1));
end if;

end factorial;

public void processFileByName(in String filename) is

var File file to (filename);


if(! file.exists)
return;
end if;

this.processFile(file);

end processFile;

- 149 -
D. Repetition

The repetition statements repeat or iterate over a block of statements. A for statement iterates over a fixed
range or count of elements. A loop statement is a infinite loop, no specific explicit conditions exist to
terminate the loop. The until-loop and while-loop have explicit conditions to exit a loop, which are
logically the inverse of each other.

Add restrictions and limits on for loop variables and types; implicit UnsignedInt or
Int for a for-range. ??

For Statement

A for statement is a fixed iteration statement, it repeats over a discrete range. There are two types of for
loop statements:

1. Iterate over a fixed integer range from lower to upper bound.


2. Iterate over an array of fixed dimensions and length.

A for statement declares a for-loop variable, which is unique to a for-loop, and conflict with any other
variable declarations within a method. A local for loop variable is declared in the for-loop clause, and is
valid within the scope of the for loop block. Outside of the for-loop block, the for-loop variable is non-
existent and non-existent. Within the scope of the for-loop block, the for-loop variable is a read-only
constant with a value for that cycle of the for-loop.

For Statement over a Range:

A fixed for statement over an integral range counts up or down from an initial value up to an upper limit.
The lower bound and upper bound are an actual for loop variables; the for-loop variable will equal the
boundary values.

Example for statement over fixed range, for-loop variable: 0 ≤ x ≤ 20:

//x implicitly UnsignedInt, count from 0 to 20


for(x is 0 to 20)
IO.putln(x);
end for;

Example for-loop variable: 100 ≥ y ≥ 0:

//x implicitly UnsignedInt, count from 100 to 0


for(y is 100 to 0)
IO <<< y <<< eoln;
y++; //error! y is constant value
end for;

- 150 -
For Statement over an Array

The for-statement over an array iterates over the range of a 1-dimensional array, returning the element of
an array at an index instead of the value in the range.

Example for statement over an array:

var String[*] dataTable to {“hello”,“world”,“hi”,“greetings”};

for(String x in dataTable)
IO <<< x <<< eoln;
end for(0);

For Statement over Other Integral Type

A for statement does not have to have an implicit range of UnsignedInt or Int integral type. Other
integral types such as Byte, Short, and UnsignedByte can be used explicitly in a for statement.

An example of implementing a for statement with a non-implicit integral type is:

//Byte is signed from -128 to +127


for(Byte b is -128 to +127)
IO <<< b << eoln;
end for;

Another example of a non-implicit integral type is:

//2^16-1 is upper limit


for(UnsignedShort ush is 0 to 65535)
sum += sum + ush; //compute sum from 0 to 65536
end for;

For a non-implicit integral variable in a for loop, the type must be explicitly declared and the ranges for
the variable must be valid for the integral range.

Loop Statement

A loop statement is an infinite loop, with no explicit bounds on the termination of the loop. The loop
statement is used instead of a “hardwired” while or until loop. An infinite loop must have an explicit
statement to exit or continue to the next cycle of iteration within the loop.

Example of loop statement:

//infinite loop without explicit end


loop
null;
end loop;

- 151 -
Example of loop statement with prefix-if statement:

var Bool statusFlag to False;

loop
doFileOperation(statusFlag);
exit if(statusFlag); //prefix-if explicit exit
end loop;

Example of loop statement with exit in case statement:

var Char c to null;

loop

IO.read(c);
case(c)
as ‘x’,’X’,’e’,’E’ is exit loop; //exit on character x or e
as ‘n’,’N’ is next loop; //exit on character n
else
next; //implicitly next loop
end case;

end loop;

Until Statement

An until-loop repetition statement continues iteration until the loop condition is true, or continues while
the condition remains false.

var Int x to 3;
until(x == 0)
x--;
end until;

While Statement

A while-loop repetition statement continues iteration while the loop condition remains true, or stops
when the condition is false. For example:

var Int x to 3;
while(x != 0)
x--;
end while;

- 152 -
Equivalence between While-Until

A while-loop is the logical inverse of an until-loop, and vice-versa. Effectively one repetition statement is
the opposite of the other:

while(! (BOOL_CONDITION) ) until(BOOL_CONDITION)


STATEMENTS; STATEMENTS;
end while; end until;

while(BOOL_CONDITION) until( !(BOOL_CONDITION) )


STATEMENTS; STATEMENTS;
end while; end until;

Repeat Statement

A repeat statement is a loop that executes the body of statements at least once, and then continues until
the terminating condition is true. There are two types of repeat loops:

1. repeat-while: repeat loop with a while logical condition for continuation.


2. repeat-until: repeat loop with an until logical condition for continuation.

The while and until conditions are logical inverses – a while continues while the expression is true, but
terminates on false, and an until continues until the expression is true or while it is false.

Example of repeat statement with while condition:

var File dataFile to “myfile.dat”;


dataFile.open;

repeat
dataFile.readRecord;
while(!dataFile.endOfFile );

Example of repeat statement with until condition:

var File dataFile to “myfile.dat”;


dataFile.open;

repeat
dataFile.readRecord;
until( File.endOfFile );

Each of the repeat loop statements is logically equivalent. Depending upon the logical expression, a
repeat-while and repeat-until can be used. A loop statement is equivalent to a repeat statement, only with
the logic to terminate of the loop part of the body of statements. A repeat statement avoids the mixing of
logic and statements in a cleaner repetition statement.

- 153 -
A repeat statement can have a nesting level, as a repeat statement can be nested within another repeat
statement. And like the other loops, a exit, next, and prefix-if statement can alter flow of control in the
repeat statement.

Example of repeat statement with prefix-if and nesting:

var Record rec to null;


var File dataFile to “myfile.dat”;
dataFile.open;

repeat
rec = dataFile.readRecord;
exit if(rec == null) repeat(0);
while(!dataFile.endOfFile )(0);

dataFile.close

Pre-conditional and Post-conditional Loops

A repeat statement is similar to a loop statement in that both will execute the body of statements at least
once. A while and until statement can optionally never execute the body of statements, and the for
statement (again depending on the logic of the expression) can possibly never execute the body
statements.

Repetition Statement Kind of Loop Lower Bound Upper Bound


For Pre-conditional 0 c < ∞
Loop Post-conditional 1 n ≤ ∞
Repeat Post-conditional 1 n ≤ ∞
Until Pre-conditional 0 n ≤ ∞
While Pre-conditional 0 n ≤ ∞

Table of Pre- and Post- Conditional Statements and Bounds

A for statement always has some constant upper bound, which is always less than infinity—hence a for
loop statement will always terminate. Other loops are always less or equal to infinity—hence a possible
infinite loop for the upper bound.

Post-conditional loop or repetition statements are useful when the body of statements needs to be
executed at least once, and then a logical expression to continue the loop is evaluated. Conversely, a pre-
conditional loop is utilized if the body of statements need never execute; the logical condition is evaluated
and then the body of the loop is executed if the evaluation is logically true. A false logical condition and
the loop, and the body of statements is not executed similar to an if statement.

- 154 -
E. Selection

Selection statements select a block of statements to execute based upon a value or condition. A case
statement uses a discrete value to select a statement block to execute, the if statement uses a logical
Boolean condition or set of Boolean conditionals to select a block to execute.

Case Statement

A case statement is a multi-way selection statement that uses a discrete value to select the choice of
decision. A case statement can be more efficient than a ladder of nested if-elif-else statements. A case
statement uses a discrete type such as integer, Boolean, character, or strings.

The case of the variable heads a case statement, then with each valid case values as a comma-delimited list
between the keywords as and is. The last part of a case statement is the optional else-clause that begins
with the keyword else, which is the catchall if no specific case is selected. A case statement ends with the
case footer, which follows the syntactic form of an if statement with an end keyword with a case keyword
with the terminating semicolon.

var Int x to 0; //integer is discrete type

case(x)
as 0 is
doSomething0;
as 1 is
doSomething1;
else //negative integer, positive integer > 1
callError;
end case;

Delimit a list of discrete values with a comma in each case.

var Char c to ‘x’;

case(c)
as ‘a’,’e’,’i’,’o’,’u’ is
this.handelVowel(c);
as ‘,’,’’’,’”’,’;’,’:’ is
this.handleControlChar(c);
else
this.handleOtherChar(c);
end case;

The else statement is for the default or non-case specific option, and is required for a case statement.

- 155 -
A case statement can case on a String literal, an example of which is:

var String cmd to null;

loop
cmd = in.readLine;
case(cmd)
as “exit”, “quit” is exit;
as “version” is reportVersion;
else execute(cmd);
end case;

end loop;

If Statement

An if statement is a logical condition selection statement; based upon the condition in the if-clause, either
the then-block is evaluated, or the else-block. An else-block for an if-statement is an optional part, the
equivalent if-statement with an else-block has a null statement.

Example if-statements that are equivalent:

if(x < y)
x = y; //then-block
end if;

if(x < y)
x = y;//then-block
else
null; //else-block
end if;

- 156 -
An example of an if statement with else-if elif block, equivalent to else with an if block:

if(x < y)
this.computeValue(x,y);
elif(x > y)
this.computeValue(y,x);
else //x == y
this.computeValue(x,x);
end if;

if(x < y)
x += y;
else //x >= y

if(x > y)
y -= x;
else //x == y
x is y;
end if;

end if;

An if statement does not require an else if an else if or elif-clause is used.

An example of an if-statement without an else:

if(x > y) //no else required


x.computeWith(y);
elif(x < y)
y.computeWith(x);
end if;

Example if statement in a recursive function, with all branches of the if-statement:

public default Int factorial(in Int ival) in for factorial is

if(ival < 0)
flag IntegerValueTrap;
elif(ival == 0)
return 1;
else
return( ival * this.factorial(ival-1) );
end if;

end factorial;

- 157 -
F. Mutex Statement
A mutual exclusion or the shorter, concise form of mutex is a statement relating to threading and the
mutual exclusion of threads from multiple statements. A mutex statement does not compute anything, bu
provides a means to explicitly delineate a block of multiple statements for thread-safe mutual exclusion.
The mutex statement is examined more thoroughly in a later chapter.

- 158 -
XII
Implied Methods

- 159 -
A class can have a method which is implied, a method which is declared with a method header, but is
defined in the compilation (Java or C#) language. An implied method is implied functionality,
functionality provided through the class but not defined in it. An implied method is opposite of an
abstract or virtual method, declared but defined in the implementation language, whereas a virtual or
abstract method declares a method but a sub-class must define it in Mynx.

A. Rules for Implied Methods


An implied method is a method that is declared but not defined in the Mynx programming language.
There are three rules for using implied methods in a class:

1. Only default methods of an instance can be implied, non-attributes or overloads.


2. An implied method cannot flag any traps.
3. An implied method can have any class access.

Synch of implied method? i.e. thread-safe implied method?

B. Declaration
The syntax for an implied class method is similar to a normal class method header, except that after the
is keyword follows the implied keyword without the method body definition using statements. In effect
the method is implied, after the method header is declared.

Examples of Implied Method Declarations:

public void myImpliedMethod(in Real r) is implied;


public Bool executeCommand(in String s) is implied;
public String getSystemAttribute(in String attr) is implied;
public UnsignedInt getSystemTime is implied;

C. Implementation
An implied method is like an ordinary default method in a Mynx class, except that the generated Java or
C# code is different.

The implied methods of a class will generate an implied method class stub, in Java and C#, as an
interface. The interface is then implemented as a final class with the implied methods defined in the
underlying implementation programming language (Java or C#).

module example.impliedMethod;

class X as Void is

public void execute(in String s) is implied;


public Int doSomething(in Real r) is implied;

end class;

The Mynx class with the implied method execute will cause the generation of an interface and an
implementing class around the implied methods within the same namespace. The implied method
interface and class use a “mangled” name, with a trailing underscore after the Mynx class name to avoid
conflict with any Mynx class names. The interface is prefixed with _impliedI for implied interface, and
the implementing class is prefixed with _implied before the Mynx class name.

- 160 -
The implementing class then uses the implied class implementation as a class delegate, and uses a private
constant attribute of the _implied name. The underscore creates a unique identifier which will not
conflict with a possible Mynx identifier.

An interface is generated so that an implementing class can optionally have other functionality, but the
interface ensures the implied methods are implemented, and by instantiation only those methods are
accessible in the implementing programming language. A final class provides the implementation of the
interface, separating the interface to the implied method functionality from the implementation.

The generated Java interface for the implied method:

package example.impliedMethod;

interface _impliedIX //implied interface


{
public void execute(final mynx.core.String s);
public mynx.core.Int doSomething(final mynx.core.Real r);
}

The generated Java class for the implied method:

package example.impliedMethod;

final class _impliedX implements _impliedIX //implied implementation


{
public _impliedX(){} //null constructor

public final void execute(final mynx.core.String s)


{
//implement implied method
}

public final mynx.core.Int doSomething(final mynx.core.Real r)


{
return null; //implement implied method
}
}

- 161 -
The implementation code generated in Java for the corresponding Mynx class:

package example.impliedMethod;

class X implements Void


{
//implied methods delegate
private final _impliedIX _implied = new _impliedX();

public void execute(final mynx.core.String s)


{
this._implied.execute(s); //invoke implemented code
}
public mynx.core.Int doSomething(final mynx.core.Real r)
{
return this._implied.doSomething(r);
}
}

The interface and class are both compiled with minimum functionality implemented. Both are compiled
into Java byte code or .NET intermediate language, and all are bundled in a Java JAR archive or .NET
assembly.

- 162 -
D. Implied Method UML
The UML for the implied method and the related implementing class and interface is:

Implied Method UML Diagram

- 163 -
- 164 -
XIII
Obviate Methods

- 165 -
A visible, callable method can be obviate or removedfrom a Mynx class. The obviated method is “masked”
out or “hidden” from any further derived class, and invoking an obviated method in a class will flag a trap.
Effectively, the obviated method or methods are removed from the class interface. However, an obviate
method is still useable within the parent class, and any methods inherited in a child class which use the
parent method. Obviating a method will not “break” existing code.

A method must be visible and callable, hence private methods of a class are not accessible, so can never be
obviated. Class methods that are invisible from the outside of the class are already hidden or masked out
from use. Obviating a class method from the interface that is already invisible is redundant. Any method
that is callable is explicitly callable; hence implicitly called methods such as constructor, destructor, and
default method cannot be obviated. Implicitly called methods are invoked automatically in use, so
obviating them can cause unexpected side effects within the class.

A. Rules for Obviating a Class Method


How the method is defined, an implied method, declared, or method equivalent does not matter to
obviate it. The method mode is superfluous; a constant or singular method is hidden from use, not
overridden or overloaded when obviated. A single method or multiple methods of the same name can be
obviated from a class.

The rules for obviating a class method are:

1. A class method must be visible, protected or public access.


2. An obviate method cannot be re-declared or defined in the class.
3. A class cannot be abstract or virtual; the methods of the class must be defined.
4. A class method must be explicitly called, hence cannot be a constructor, destructor, or default
method.
5. A class method cannot be overloaded with an operator.

B. Single Method by Signature


A single method can be specified as the method to obviate from a class. The syntax to obviate a specific
single method is by the method name and its signature.

Example obviate method declarations:

method openFile(String) as void;


method reset(String filename) as void; //error! Only parameter type
method getSystemTime as void; //valid, no parameter method
method convertToBase(UnsignedInt, UnsignedInt) as void;
method getArgs(String[]) as void; //valid, array for method signature

The method signature is used to identify which method is obviated from the class. The method signature
is the same unique information used to identify overloaded methods by the same name. A method
signature consists of the method name, and the parameters to that specific method. The method access
level, mode, return type, scope, or flagged traps are not part of the method signature.

C. Multiple Methods by Method Name


Obviating a single method can be tedious for a class with many overloaded methods by a common method
name, and not the method signature.

- 166 -
Example obviate method declarations:

method getln as all void;


method write as all void;
method putln(Int) as all void; //error! No method signature allowed
method substr as all void;
method callTo(Char c) as all void; //error! Parameter type, variable

The method name is used, similar to method equivalents to obviate all methods in the class by that name.
Because all the methods are obviated, a specific method signature is superfluous and unnecessary. The
important difference from obviating a single method is using a keyword all with a method signature to
indicate all methods for that name are obviated.

D. Inheritance with a Single Obviate Method


For example obviating a single method in a class:

class Cat as null is

//...remaining class methods, constructor


public void wagtail is
//…wagtail method body
end wagtail;

end class;

The class Cat contains the public method wagtail, which as on operation on a cat object, wags the tail of
the cat, and takes no parameters, and returns nothing when called.

But, when another class manxCat subclasses or derives a new class from Cat, the method is no longer
valid in the subclass. The method is simply an obsolete method in the class interface.

Example class deriving from parent with obsolete method:

class manxCat as Cat is

//...remaining class methods, constructor


method wagtail as void; //manx cat does not have a tail!

public void myManxCatMethod is

super.wagTail; //method obviated, but available within the


//super-class to be invoked from the sub-class
end myManxCatMethod;

end class;

The original method wagtail in the super class Cat is now invalid (since a Manx cat does not have a
tail…) obsolete or, hence in the sub-class manxCat must be made obviate. Obviating a method does not
“undefined” the method, but removes it from the class interface

- 167 -
The method myManxCatMethod invokes the method wagtail in the super-class, and is a valid method call
or invocation. The method wagtail is removed from the manxCat and all further sub-class interfaces, but
the method still exists in the super-class. Again, obviating a method does not “undefine” the method, but
removes it from the class interface.

If a derived class from manxCat, such as a curlyManxCat that has a method wiggleEars, the method
wagTail is completely absent or void from the super class.

Example class deriving from a parent class with an obviate method that is not in the class interface:

class curlyManxCat as manxCat is

//...remaining class methods, constructor


public void wiggleEars is
super.wagTail; //compiler error! Method does not exist!
end wiggleEars;

end class;

- 168 -
The class hierarchy for the various classes with an obviate method is:

Obviate Class UML Diagram

×’ to indicate an obviate method.


The UML diagram is not standard UML, it uses the symbol character ‘×

Inheritance with Multiple Obviate Methods


For example, obviating multiple methods in a class:

class ConsoleInput as Void is


public void readln(Int) is implied;
public void readln(Char) is implied;
public void readln(String) is implied;
public void readln(UnsignedInt) is implied;

public void getln is to readln; //getln(Int) is also readln(Int)

end class;

- 169 -
The class ConsoleInput declares multiple methods by the name readln, which are overloaded for the
data type to be read. The methods are implied, so implemented in the underlying implementation
language.

class getConsoleInput as ConsoleInput is

method readln as all void;

end class;

The class getConsoleInput sub-classes ConsoleInput, but also obviates all methods by the name
readln. All methods by the name readln are obviated, not just a specific method by the method
signature. The methods are still visible, just can never be invoked from that class. The only method that
can be invoked in the getConsoleInput class is the method getln. The method getln is a method
equivalent for all the readln methods, and not obviated.

program useConsole is

var String input to default;

var consoleInput ci to default;


var getConsoleInput gi to default;

ci.readln(input); //read a string


ci.getln(input); //read a string getln == readln

gi.readln(input); //error! Invocation of obviate method in class


gi.getln(input); //ok, invokes non-obviate method of the class

end program;

E. Using a Class with an Obviate Method


Using the classes in a program illustrates the un-definition of an obviate method. The example program:

program wagTheCat is

var Cat theCat to default;


var manxCat myManx to default;

theCat.wagTail; //valid method to invoke


myManx.myManxMethod; //call method which calls wagTail

myManx.wagTail; //compiler error! method wagTail


//not a member of the class interface
end program;

The method myManxMethod internally invokes the super-class method wagtail, but explicitly calling the
method that is obviated will generate a compile-time error.

When a method is obviated, it cannot be re-defined in the class that it is obviate. Removing a class from
the interface removes it from the complete or total class interface, not just the public or protect
externally accessible methods.

- 170 -
An example of invalid re-definition of a method:

class manxCat as Cat is

//...remaining class methods, constructor


method wagtail as void; //manx cat does not have a tail!

private wagtail is //compile error:


null; //can not re-define obviated method
end wagtail;

end class;

The obviate method wagtail cannot be re-defined within the class, even as an internal private method.

Once a method is obviated in a class, it cannot be invoked explicitly on an instance, or internally with a
sub-class.

An example of calling an obviate method implicitly within a class:

constant class myManxCat as manxCat is

//...remaining class methods, constructor


public void wagtail is to super.wagtail; //compile error:
//method not found!
end class;

The method wagtail is not in the interface of the class manxCat, so cannot be defined by calling the
method implicitly as a method equivalent. The manxCat class could call the method obviated within it
implicitly because the method wagtail is in the super-class Cat method interface of the class.

F. No Side Effects for Never Obviating a Method


Often in programming languages, there is a strong interdependence among the features of the
programming language. However in Mynx, with method obviation, non-use does not have any side effects
with other features in the language.

G. Reason to Obviate a Method


Obviating a method is necessary when in sub-classing from a parent class; a method or methods from the
parent class no longer are relevant in the sub-class. Specialization of a class through inheritance can lead
to classes that the functionality interface of the parent classes is no longer relevant to the class.

Another reason to obviate a method from a class is when the method is deprecated, or disused from the
class. Instead of a compiler warning about using a deprecated method, the method can be removed by
obviating it from the methods available through a class.

- 171 -
- 172 -
XIV
Arrays

- 173 -
An array is an indexed, homogeneous, aggregate collection of a class type. An array in Mynx is a first-class
object, and an array can be multi-dimensional. Mynx does not have the concept of “arrays of arrays” only
a multi-dimensional array as an object reference. Mynx has a basic array that is defined in the
programming language, and class-based arrays that are declared and defined using a Mynx class. Class-
based arrays avoid the restriction of declaring the rank of an array, and are more general, although lack
the bracket syntax of basic arrays.

A. Array Attributes
A basic array has three primary attributes:

1. rank – the number of dimensions


2. size – the product of all dimension length
3. dim (n) – the nth dimension length or dim(n)

A 1-dimensional array, the size and dim(0) length are equivalent, with a rank of 1. For an array that has
not be instantiated, the length and dimensions are undefined hence accessing undefined will flag a trap.

B. Declaration
Declaring an array uses the class, followed by the dimensions of the array in brackets. All array
dimensions begin at an index of 0, and continue to the dimension – 1. Such an array declaration is a
definite array declaration.

Examples definite array declaration:

String[2] names; //dimension 0..1


Point[4] coordinates; //dimensions 0..3
Integer[4,4] matrix; //dimensions 0..3, 0..3

An array declaration can declare the number of dimensions (the rank), without giving any array
dimensions using an asterisk instead of the array dimension. An array declaration without specific
dimensions is an indefinite array declaration. An array without specific dimensions and just brackets is
implicitly a one-dimensional array.

Examples of an indefinite array declaration:

String[*] name; //1-dimension array


Integer[*,*] matrix2D; //2-dimension array
File[*] fileList; //1-dimension array
Char[] chars; //1-dimension array implicitly

An array is declared with the rank always explicitly given in definite or indefinite form, with an implicit
one dimensional array rank. An indefinite array can change its dimensions and have a new array created
and allocated, but the rank always is the same for an array.

C. Creation
An array declares a class type, and a fixed number of dimensions or rank. Declaring an array does not
allocate space for an array. Creating an array can be part of the declaration, following an as keyword with
an initial value list. Creating an array does allocate space for the instances of the type of that array.

- 174 -
An initial list is an explicit list of values with an implicit index starting at zero and continuing until the
length of the array offset by one.

D. Initialization
An array can be created by defining the array, and then by specifying initial values for that array. Space for
the array is allocated, and the instances are initialized with the initial value.

Implicit Integral Indexed List

Example of Creating an Array with Implicit Integer Index:

var Char[5] vowels to {‘a’,’e’,’i’,’o’,’u’};


var Real[2] consts to { 3.14579, 2.7152 };
var Int[3] ints to { 0, 1, 0 };

Explicit Indexed List

An array can be declared with explicit list of indices to initialize each location of the array to a specific
instance value type.

Example of Creating an Array with Explicit Position Index:

var Char[*] chr to { *:’ ‘ , 10:’ ‘ }; //upper bounds 10 specified


var String[*,*] str to { *,*:” “, 10,8:” “ }; //upper bounds 10,8 specified
var Int[*,*,*] int to { *,*,*:0 , 3,3,3:0 }; //upper bound 3,3,3 specified
var Real[*,*] rl to { *,*:0.0 } //compiler error!
//no upper bounds specified

var Bool[3] bl to { 0:True, 1:False, 2:True}; //explicit index

Using Default Constructor

Example of Creating an Array with Default Constructor:

var String[10] strings to default; //10 strings to default


var String[*,*] stringy to default; //compiler error!
//no array bounds specified
var Int[3,3,3] ints to default; //3x3x3 array of Int to default

An array can be initialized with a list of initial values using an explicit integer list index with a colon ‘:’
separator. One special index uses an asterisk ‘*’ as an index for all other array indices.

- 175 -
Example of Creating an Array with Explicit Integer Index:

var Char[5] vowels to { 4:’u’, 0:’a’, 3:’o’, 2:’i’, 1:’e’ };


var Real[2] consts to { 0:3.14579, 1:2.7152 };
var Integer[3] ints to { *:0, 1:1 };

Deferred Creation

An array can be declared, but then created later with an as-clause and an initialization list. An as-clause
can also create a new array with the same rank, but different dimensions.

Example of Declaring an Array but Creating Later:

var String[*] name to null;


name as String[2]{“hello”,”world”};

var Char[*] vowels to null;


vowels as {4:’u’, 0:’a’, 3:’o’, 2:’i’, 1:’e’ };

var Real[*] consts to null;


consts as {3.14579, 2.7152 };

var Int[*] ints to null;


ints as { -1, 0, 1 };

Example of Declaring an Array and Creating New Array:

var Int[2] ints to { 0, 1 }; //create new array of 2 ints, implicit index


var Int[10] ints to { *:0 }; //create new array of 10 ints, initial 0
var Char[5] ch to default; //create new array of 5 char with default

Initialization with a Constructor

Creating a new array can use a constructor to initialize all new array instances, instead of an initial value
list of literals.

Example of Creating an Array Initializing with Constructor

var String[*] strings;


Strings as String[10](“”); //create 10 empty strings

var Int[2] binary;


binary as Int[2](0); //create 2 integers initial value 0

- 176 -
Null in Declaration

An array can use a null to indicate no initial value or initialization with a constructor. Then later the
reference can be initialized with a list of values.

var String[*] name to null; //initialization null reference


name as String[2](“”); //create 2 empty strings
Point[*] points; //1-dimensional, uncreated, uninitialized
points as Point[2](0,0); //constructor, all objects
var points to Point{2]; //compiler error! cast expression
points as Point[2]{(0,0),(0,0) }; //initial list of constructors
points as Point[2]{ *:(0,0) }; //initial list with index
points as Point[2]; //create array default constructor

E. Using an Array
An array is a homogeneous finite collection of instance objects as elements, all of the same type or class.
However, an array itself is an instance of an object, so using an array involves two forms of use:

1. Using an Array Element – access a specific instance element of the array.


2. Using an Array – access and use the entire array itself.

Using an Element

An array can be used as the whole, or as one of its elements or parts. Using an element of an array
involves accessing the element of the array with an index into the element.

An example of using an element of an array:

var Int[4] ints to { *:1 }; //new 1-dimensional array of Int 1


var Int[0] intx to (0);
var Int x, y to (0); //new int variables initially 0

x = ints[0]; //x.set(ints[0]); x == 1
y is ints[1]; //y == ints[1]; y == 1

y++; //both y, Int[1] incremented y==2, ints[1] == 2


x--; //x decremented x == 0
int[3] = x + y; //Int[3] = 0 + 2 == 2
y = ints[0]++; //y = 1++ == 2
x = ints[1] * ints[2]; //1 * 1 == 1
int[3]++; //2++ == 3

ints = intx; //assign array to array, valid for same rank=1

- 177 -
Using as an Object

An array can be used as an object, the entire collection of homogeneous element instances as a single
entity or object.

var Int[4] ints to { *:1 }; //new 1-dimensional array of Int 1


Int x,y to null;

x = ints.rank; //get array rank == 1


y = ints.size; //get array size == 1 * 10;
ints as Int[2]; //create new array using default

ints.nullify; //destroy the array instance


if(ints == null) //check for nullity
ints as Int[3];
else
ints.nullify;
ints as Int[3];
end if;

Passing as a Parameter

An array can be passed as an object to a method that only knows the type and rank of the array object.

public constant transpose(var Int[*,*] int) is

for(x is 0 to int.dim(0) )
for(y is 0 to int.dim(1) )
int[x,y] = int[y,x];
end for(1);
end for(0);

end transpose;

Using the array in the defined method transpose:

var Int[10,10] array2D to (0);

this.myMethod(array2D);

F. Array as a Mynx Class


The Mynx class Array defines a class as an array, as a single entity object, in contrast to the basic Mynx
programming language primitive array.

- 178 -
XV
Mynx File Types and Tools

- 179 -
There are six major Mynx file types used by different Mynx tools. Each Mynx tool uses the name of the file
extension. Instead of appending a character ‘c’ at the end of the compiler name, like mynxc, the
compiler is the same as the file extension mynx.

Tool Name/File Extension File Type


Mynx source code file, one public class, with
one or more private classes,
or one program
Myxm MYnX Multiple source code file,
multiple public classes
Moxi Mynx Object Xml Interface class file
Myna MYNx Archive file in ZIP format
Minx Mynx Intermediate XML code file
Myxd MYnx Xml Documentation generator

Table of Mynx File Types and Tools

A. Mynx
A Mynx file type has the .mynx file extension, and mynx is the compiler tool name. A single Mynx class or
program has the same name as the file. So a program with the name helloWorld would be in a
helloWorld.mynx file. Multiple private classes can be included with a public class.

B. Myxm
A file with multiple Mynx classes all public is a .myxm file extension. MYXM is an anagram for MYnX
Multiple classes file type. The tool myxm separates and into individual Mynx class files, and compiles the
multiple Mynx classes.

C. Moxi
A Moxi or Mynx Object XML Interface file is the XML interface for a Mynx class, used by the compiler for
external semantic checks. The XML document specifies methods, attributes, overloads, and obviates of
the class. A program does not have a moxi file type. The moxi tool is an object-class browser, showing a
class in a module namespace, the methods, attributes, obviates, and overloads.

D. Myna
A myna or Mynx Archive is a ZIP-compatible archive file format. The Mynx tool allows adding, viewing,
extracting, and deleting files from the archive file. A myna file can be processed by other ZIP-compatible
programs.

E. Minx
A .minx file type is the end result of compiling Mynx into an intermediate platform-independent
representation in XML. Hence MINX is the acronym (and similar pronunciation as Mynx the
programming language) for Mynx INtermediate XML file type. The minx tool allows for translation into a
native programming language, originally Java and C#. As an XML file, a minx file is transformed into
HTML to place of Mynx code on the Internet.

- 180 -
F. Myxd
The myxd file type and tool is for the MYnx XML Documentation generator, which processes a Mynx or
Myxm source file and generates a myxd documentation file. The myxd tool allows the documentation to
be browsed and searched interactively.

- 181 -
- 182 -
XVI
Mutual Exclusion

- 183 -
A. Concept of Mutual Exclusion

Mutual exclusion (mutex) is a necessary language feature for writing platform independent multiple
threaded (multithreaded) classes in Mynx. The concept of mutual exclusion involves 2-elements:

1. Thread – thread of execution; a light-weight process; a task in Mynx


2. Mutex – exclusion of thread from a critical section block of source code

Thread or Task

A thread or task is a “lightweight” process that is a window of execution for an object. A thread is an
object, but in multithreaded applications, more than one thread exists, but only one is actually executing.
A simple example of multithreading is when using one application, other activity can occur nearly
simultaneously. A thread allows activities to be separated and to occur concurrently, making an
application or library more useful. The term “thread” is from each “thread of execution” running on the
computer processor.

Mutex

In software that is designed for multithreading, methods and blocks of code within methods of a class can
have critical sections. A critical section is code that must be mutually exclusive to all other threads except
one. Essentially, only one thread can access and execute the block of code or method in a critical section.
Otherwise variables and values can change unpredictably.

For example, if two threads access a critical section in which a variable is changed based upon its value,
each thread might change the variable as the other is changing; essentially one thread interacts with the
other. The variable might be changed based upon the transient value of the other thread, causing it to be
updated incorrectly. Debugging synchronization bugs is difficult and frustrating.

A mutex is a mechanism to enforce that only one thread can access a critical section at a time. How the
mutex is implemented (semaphore, monitor, spin-lock, etc.) is less important than the mutual exclusion
of threads from a critical section. Referring to the update anomaly example, only one thread could execute
the critical section of code there would be no transient changes.

B. Async and Sync Methods


There are two kinds of methods or more specifically, method modes of a class in Mynx:

1. Async – single threaded code, no mutual exclusion for threads


2. Sync – multithreaded code, mutual exclusion of threads

Async is short for “asynchronous” or without synchronization or mutual exclusion. Asynchronous


methods are the default kind of method for a class, and a program can never have synchronized methods.
An asynchronous method will have the async keyword or no mutex keyword meaning it is by default
asynchronous.

- 184 -
For example, the two methods are both asynchronous:

public async void doNothing is


null;
end doNothing;

public void doNothing is //implicit asynchronous


null;
end doNothing;

A sync or “synchronous” method has synchronization and is thread-safe or mutually exclusive. Once a
thread has acquired the mutex for a synchronized method, no other thread can execute or invoke that
method.

A method must explicitly use the sync keyword in the method declaration to specify thread-safety
through synchronization.

For example:

public sync void threadSafeIncrement is


counter++;
end threadSafeIncrement;

C. Mutual Exclusion within a Class Method

Only classes and methods of a class can be mutually exclusive, or have a mutex – class attributes cannot
be mutually exclusive. A class method, even when synchronized as with a mutual exclusion, has the
disadvantage that the entire method is mutually exclusive. The scope of mutual exclusion can be too
encompassing, when only a small block of statements is a critical section.

D. Mutex Statement
A mutex statement is used to create a block of mutual exclusive statements within a class method, without
making the method completely synchronized. A mutex statement does not create a separate thread, or
task. A mutex statement consists of a mutex header, the block of statements, and a mutex footer.

The mutex header begins with the keyword mutex, and the mutex variable or expression in parenthesis.
The mutex footer is simply the keyword end followed by mutex and a semicolon.

The general syntax for a mutex statement is:

mutex ( EXPRESSION )

STATEMENTS

end mutex ;

The statements can be any possible statement, including another nested mutex statement.

- 185 -
E. Mutex Expression
The mutex expression is an expression for an object lock, or in actuality, a monitor for the object. A
monitor is a fundamental mutual exclusion concept, but for each object there is one lock. Hence a
synchronized method uses the instance object lock implicitly, but for a block of statements it requires an
explicit lock – in the form of an expression. The simplest lock is to use the keywords of this and self
class references for the object instance and class static reference locks, respectively.

F. Equivalence of Mutex Statement and Synchronized Method


The two forms of mutex statement, implicit in the class method as synchronized method, and explicit
within a method are equivalent in terms of a mutex statement.

The two instance methods are equivalent:

public sync default void aMethod is public async aMethod is

mutex(this)

STATEMENTS STATEMENTS
end mutex;

end syncMethod; end asyncMethod;

The two static methods are equivalent:

public sync static void aMethod is public async static aMethod is

mutex(self)

STATEMENTS STATEMENTS
end mutex;

end syncMethod; end asyncMethod;

Hence an asynchronous method with a mutex statement for the entire block of statements for a method is
equivalent to the synchronized method on the instance or static class reference.

G. Mutex for Operator Overload Method


Methods that are overloaded with an operator can be asynchronous or synchronous. A call to a method is
implicit when using an overloaded operator, and hence mutual exclusion is implicit as well.

For example:

var String str to “”;

str is str + “hello world”;

and if the + is overloaded as:

- 186 -
overload constant + as concat;

and the method is defined as:

public sync default String concat(in String str) is

end concat;

Then the use of the + operator, and invokes the method concat, which is a synchronized or mutex
method.

Indirectly an operator invokes a method that is mutually exclusive. An operator overloaded method is the
same a direct access and invocation of a method, only implicitly. Mutual exclusion and synchronization is
basically implicit to the method, overload is merely an indirect way to call the method.

- 187 -
- 188 -
Glossary of Terminology
The specific terminology or jargon used with the Mynx programming language is summarized as the term
and the relevant definition of the term. (142-words in glossary) add mutex statement terms and jargon.

Absolute Namespace: inclusion of a class by its exact, absolute namespace

Abstract: a class and method mode that is undefined for a method, or partially defined for a class.

Access: to get an attribute or method of a class.

Array: a n-dimensional matrix of a class type element.

Array Dimension: the length of a dimension, the upper bound for an array index.

Array Rank: the number of dimensions for an array. Non-array instances have a rank of zero.

Array Size: the product of all dimensions for the total space or size of the array.

Assert Statement: a statement that verifies a condition is true, or else it will flag a trap.

Assignment: an operator and statement that associates values from one reference name to another.

Asynchronous: a single-threaded method that does not require mutual exclusion or synchronization.

Attribute: the data elements of a class or program.

Attribute Kind: a qualification of an attribute indicating if it is a class or instance attribute, and if it is


constant or variable.

Attribute Mode: a qualification of an attribute to indicate if it can persist in serialization.

Case Statement: a statement that determines which statements to execute based upon the value of a
discrete variable.

Checked Exception or Trap: a trap that must be handled with a try statement by the calling method.

Class Kind: the kind of class that controls instantiation and inheritance of the class.

Class: a basic organizing unit of software re-usability.

Comment: a remark or commentary in the source for a class or program that is ignored by the compiler.

Computation: a statement type that performs some computation.

Constant: a kind of class that cannot be sub-classed.

Constant Overload: an overload of an operator by a method in a class that cannot be re-overloaded in a


sub-class.

Constructor: a special class method that constructs or creates a new instance of a class and initializes it.

- 189 -
Contra variant: an override of a class type with a super-class type. Contra variance is not used in method
overriding.

Covariant: an override of a class type with a sub-class type. Covariant overriding is only possible with
instance method return types.

Creating an array: defining an array, and giving a size or array bounds that allocates memory or space.

Creation: a kind of expression statement that creates a new instance of a class type.
Decision: a statement category that decides which statement to execute.

Declaration: a kind of expression statement for declaring a variable by name, class type, and possible
initial value.

Declared Method: a class method that is stated by method type, parameters, signature, and scope, but not
defined with statements.

Default: a namespace that is used implicitly by default when no namespace is specified for a class.

Default Class: the normal category of class that can be instantiated and sub-classed by inheritance.

Default Method: the implicit method of a class called through an instance when none is invoked.

Default Method: a special method that is implicitly invoked or called on an instance when no method is
specifically invoked.

Default namespace: the namespace 'default' that is the implicit default namespace if none is specified for a
class or program.

Default Overload: the default overload is to allow an operator to be re-overloaded in a sub-class.

Defined Method: a class method or program method, which is declared, and defined with a body of
statements.

Defining an array: similar to a definite array declaration.

Definite Array Declaration: declaring an array that has rank and size, but not initial values.

Destructor: a special method that destructs or cleans up after a class is destroyed.

Enumerated type: a named discrete set of named constants that are treated as a unique type. Each
constant has a non-negative integral value, and a string name.

Error: a category of statements that is for error creation and handling.

Escaped character: a character that uses an escape prefix ‘\’ for non-literal characters such as carriage
returns and end of line characters.

Exit Statement: a statement that exits the body a loop.

Explicit Method Invoke: explicitly invoking a method on an instance or class by name.

Expression Statement: a statement that involves an expression.

Flag Statement: a statement that causes a trap or exception to be generated.

- 190 -
Flow of Control: a statement category for statements which alter execution of a method in a class or
program.

For Statement: an iterative statement over an explicit integral range or over a 1-dimensional array of
elements.

Generic: a kind of class in which the type is generalized, and so can be parameterized for a specific type.

Global Instantiation: a form of binding a generic class to a type that exists outside the invocation of the
statement.

Identifier: a basic lexical element that is a word of characters.

If Statement: a statement that executes dependent upon a conditional clause.

Implicit Method Invoke: implicitly invoking a method by default for an instance.

Implicit Static Method: an inclusion of class method which is static or singular mode.

Implied Method: a method that is declared but not defined; the implied method is defined in the native
implementation language.

In: a parameter passing mode that cannot be null and the reference cannot be changed.

Indefinite Array Declaration: declaring an array that has rank, but not array bounds or size, or any initial
values.

Inheritance: a method of code re-use by classes to modify and extend the functionality of a parent class in
a derived child class.

Initial Value: a value in a declaration implicitly assigned to a reference once it is created.

Initializing an array: defining and creating an array, then initializing the array instance elements with
initial values.

Instantiation: to create a new instance of a class, or to bind a generic class to a specific class type.

Invariant: an override of a method by exact method signature including method parameters and return
type.

Iteration: a category of statement for repeating multiple times over a block of statements with some
logical condition to continue or stop.

Jump: see flow of control.

Keyword: an identifier that is used by the programming language, and cannot be used in names.

Literal: a basic lexical element that is a word of actual data; an anonymous constant.

Local Instantiation: a form of binding a generic class to a type that exists only for the invocation of the
statement.

Loop Statement: an iterative statement that is infinite with no logical condition.

Meta String: an abstract string that contains information that is translated by the compiler into a literal
string.

- 191 -
Method: the functionality of a class or program.

Method Equivalent: a declared method that is defined in terms of another defined method in a class.

Method Invocation: to call or invoke a method.

Method Mode: a method qualifier indicating if it is a class or instance method, can be overridden, and is
defined in the class.

Method Overload: see overload.

Method Override: see override.

Method Synchronization: whether a method is thread-safe and mutually exclusive.

Method Type: the return type of a method, non-void is a function method, void is a procedure method.

Multiple Disjoint Inheritance: a class that inherits multiple abstract classes, but there is no method
signature overlap, hence all methods for each non-virtual abstract class inherited multiply times is
unique.

Multiple Virtual Inheritance: a class that inherits multiple virtual classes.

Multiple-line: a statement that can nest other statements and spans multiple lines as a "block" of
statements.

Multi-threaded: a shortened version of multiple-threaded.

Multiple threaded: a class method that runs multiple threads of execution and requires synchronization
for mutual exclusion.

Mutual exclusion: in multiple threaded programming, excluding all other threads except one from
executing a block of code to avoid anomalous changes to variables.

Mutex: an acronym for mutual exclusion.

Namespace: a means of organizing classes into a hierarchy of names that contain a specific class.

Next Statement: a statement that continues to the next pass of a loop.

Nothing or Null Inheritance: inheritance of no classes or nothing.

Null: a reference to “nothing” a non-existent or nothing.

Null Inheritance: a class which inherits no class, or nothing.

Null Statement: a statement placeholder, a do nothing statement.

Nullable: able to assign or set null reference to an object reference.

Obviate Method: a method that is hidden or removed from the class interface.

Opaque Class: a class which when compiled does not have the capability for runtime type information
(RTTI) introspection.

Operator: a basic lexical word or element that signifies an operation.

- 192 -
Operator Category: the classification of the operator.

Operator Overloading: associating a method name with an operator in a class.

Out: a parameter mode where the parameter can be null, and the reference can change.

Overload: to associate an operator with a method which implements the functionality of the operator.

Override: to re-define a method in a sub-class from the original super-class definition.

Parameter List: the list of parameters that is passed to a method.

Parameter Mode: the restrictions on a parameter when passed in a call to a method.

Parameterized Type: the class type of a parameter.

Partial Class: a class that is not completely defined.

Postfix: an operator kind that precedes the operand.

Prefix If Statement: an if statement that has a next or exit preceding the conditional if clause.

Private: an access to a class qualifier that makes a class attribute or method inaccessible externally.

Program: an organizing unit of software application.

Protect: an access to a class qualifier that makes a class attribute or method inaccessible externally, but
available to a sub-class.

Public: an access to a class qualifier that makes a class attribute or method available.

Relative Namespace: inclusion of a class by a namespace prefix

Repetition or iteration: a statement type that involves repeated statements, conditionally, or


unconditionally.

Restricted Class: a class that is not sub-classed or inherited.

Reserved Word: see Keyword.

Return Statement: a statement that terminates a called method, possibly returning data.

Scope: the visibility of a method within a class or program.

Selection: see Decision.

Self Class Prefix: an explicit reference to a static method of the current class.

Self Method: an abstract class method that refers to self, or the future class type when the class is a
tangible default class.

Serialization: saving a class state in the form of its attributes to external storage.

Series: a parameter mode where multiple variable number of parameters are passed as a 1-dimensional
array.

Single Inheritance: a class that inherits from one class only.

- 193 -
Single-line: a statement that cannot nest other statements.

Single-threaded: a class method that does run multiple threads of execution and does not require
synchronization for mutual exclusion.

Singular: a class and method mode that is static and constant.

Statement: The most basic element of software code, the organizing unit of defining software
functionality.

Static: a method of the class that is the only one.

Super Class Prefix: an explicit reference to a method or attribute of the parent class.

Synchronous: a multiple threaded method that does require mutual exclusion and synchronization.

Synchronization: providing mutual exclusion for a critical section of source code.

Task: a Mynx thread of execution.

This Class Prefix: an explicit reference to an instance method or attribute of the current class.

Trap: an error or exception generated by a class or program.

Try Statement: a statement that encloses statements to handle any flagged traps.

Type Enumeration: see Enumerated type

Unchecked Exception or Trap: a trap that optionally can be handled with a try statement by the calling
method.

Undefined Method: a method that is declared but not defined, such as an abstract, implied, or virtual
method.

Until Statement an iterative loop statement that continues until a condition is true.

Var a parameter passing mode that can be null, and the object reference can change within the called
method.

Virtual: a method and class type that declares the method but does not declare it.

Virtual Inheritance: inheritance of multiple virtual classes.

While Statement: an iterative loop statement that continues until a condition is false.

- 194 -
Appendix Mynx Grammar

- 195 -
A. Header Syntax

START := HEADER (CLASSES | PROGRAM)


*
HEADER := [MODULE](WITH)
MODULE := module ( default | NAME ) ‘;’
WITH := with NAME [‘.’ ‘*’] ‘;’

B. Class Syntax
*
CLASSES := CLASS (CLASS)
*
CLASS := [CLASS_MODE] class ID [as (IDLIST | null )][has ID to ID] is (CLASS_BODY) end class ‘;’
CLASS_MODE := abstract | constant | default | generic | singular | static | virtual
CLASS_BODY := CLASS_METHOD | CLASS_ATTRIBUTE | CLASS_OVERLOAD | CLASS_OBVIATE
| CONSTRUCT | DESTRUCT | DEFAULT

C. Class Methods
CLASS_METHOD := METHOD_HEADER [is (METHOD_EQUIV| implied | METHOD_BODY) ] ‘;’
METHOD_EQUIV := to (null | METHOD_EQUAL | METHOD_ACCESS)
METHOD_HEADER := ACCESS [SYNC][METHOD_MODE][METHOD_TYPE] ID [ARGS][TRAPS][SCOPE]
SYNC := async | sync
METHOD_MODE := abstract | constant | covariant | default | own | singular | static | virtual
METHOD_TYPE := (ID | generic) [DIMLIST] | self | void
TRAPS := has IDLIST
*
ARGS := ‘(‘[FIXED_ARGS (‘,’ FIXED_ARGS) ] [‘,’ VARY_ARGS] ‘)’
FIXED_ARGS := [in | out | var] (ID | generic | self ) [DIM_LIST] ID
VARY_ARGS := series (ID | generic | self ) DIM_LIST ID
ACCESS := public | protect | private
METHOD_EQUAL := [METHOD_PREFIX] ID [ARGLIST]
SCOPE := (in | out) for (all | null | IDLIST)
METHOD_BODY := STATEMENTS end ID
METHOD_ACCESS := (access | reader | writer) ID
METHOD_PREFIX := (super | this | self | ID ) ‘.’
CONSTRUCT := ACCESS construct [ARGS][SCOPE] is [METHOD_EQUIV | CONSTRUCT_BODY] ‘;’
CONSTRUCT_BODY := STATEMENTS end construct
DESTRUCT := ACCESS destruct is [METHOD_EQUIV | DESTRUCT_BODY] ‘;’
DESTRUCT_BODY := STATEMENTS end destruct
DEFAULT := ACCESS default is to ( ID | null) ‘;’

D. Class Attribute

CLASS_ATTRIBUTE := ACCESS [ATTRIBUTE_MODE][ATTRIBUTE_KIND] ATTRIBUTE to INIT [SCOPE] ‘;’


ATTRIBUTE_MODE := default | volatile
ATTRIBUTE_KIND := constant | singular | static | variable
ATTRIBUTE := (generic | ID) [to ID] [DIMLIST] IDLIST

E. Class Overload

CLASS_OVERLOAD := overload [constant | default] [in ID is] OPERATOR as ID ‘;’

F. Class Method Obviate

CLASS_OBVIATE := method ID [PARAMLIST] as [all] void ‘;’


*
PARAMLIST := PARAM (‘,’ PARAM)
PARAM := ID [PARAMDIM]
PARAMDIM := ‘[‘ [STARLIST] ‘]’

- 196 -
G. Program

PROGRAM := program ID [as ID] is (STATEMENTS|PROGRAM_BODY) end program ‘;’


+
PROGRAM_BODY := (PROGRAM_ATTRIBUTE | PROGRAM_METHOD)
PROGRAM_KIND := constant | variable
PROGRAM_ATTRIBUTE := let [PROGRAM_KIND] DECLARE [SCOPE] ‘;’
PROGRAM_METHOD := method [LIMITED_MODE][LIMITED_TYPE] ID [ARGS][TRAPS][SCOPE] is
STATEMENTS end ID ‘;’
LIMITED_MODE := default | static
LIMITED_TYPE := ID [DIMLIST] | void

H. Statements
*
STATEMENTS := STATEMENT ‘;’ (STATEMENT ‘;’)
STATEMENT := ASSERT_STATEMENT | CASE_STATEMENT | EXPRESSION_STATEMENT
| EXIT_STATEMENT | FLAG_STATEMENT | FOR_STATEMENT
| IF_STATEMENT | LOOP_STATEMENT | MUTEX_STATEMENT
| NEXT_STATEMENT | NULL_STATEMENT | PREFIX_IF_STATEMENT
| REPEAT_STATEMENT | RETURN_STATEMENT | TRY_STATEMENT
| UNTIL_STATEMENT | WHILE_STATEMENT

ASSERT_STATEMENT := assert ‘(‘ EXPR ‘)’ [as STRINGLIT]


CASE_STATEMENT := case ‘(‘ EXPR ‘)’ CASE_BODY {CASE_BODY} [ else STATEMENTS] end case
CASE_BODY := as EXPRLIST is STATEMENTS
EXIT_STATEMENT := exit [ (for | loop | repeat |until | while) [NESTING] ] [ if ‘(‘ EXPR ‘)’ ]
FLAG_STATEMENT := flag NAME [ARGLIST]
FOR_STATEMENT := for ‘(‘ (FOR_INT | FOR_EACH) ‘)’ STATEMENTS end for [NESTING]
FORINT := [ID] ID is EXPR to EXPR
FOREACH := ID ID in EXPR
*
IF_STATEMENT := if ‘(‘ EXPR ‘)’ STATEMENTS {IF_BODY} [else STATEMENTS] end if
IF_BODY := elif ‘(‘ EXPR ‘)’ STATEMENTS
LOOP_STATEMENT := loop STATEMENTS end loop [NESTING]
MUTEX_STATEMENT := mutex ‘(‘ EXPR ‘)’ STATEMENTS end mutex
NEXT_STATEMENT := next [ (for | loop | repeat |until | while) [NESTING] ] [if ‘(‘ EXPR ‘)’ ]
NULL_STATEMENT := null
REPEAT_STATEMENT := repeat STATEMENTS ( until | while ) [NESTING] ‘(‘ EXPR ’)’
RETURN_STATEMENT := return [‘(‘ EXPR ‘)’]
*
TRY_STATEMENT := try STATEMENTS (TRY_WHEN) (TRY_WHEN) TRY_LAST end try
TRY_WHEN := when ‘(‘ ID [ID] ‘)’ STATEMENTS
TRY_LAST := [else STATEMENTS][do STATEMENTS]
UNTIL_STATEMENT := until ‘(‘ EXPR ’)’ STATEMENTS end until [NESTING]
WHILE_STATEMENT := while ‘(‘ EXPR ’)’ STATEMENTS end while [NESTING]
NESTING := ‘(‘ DECIMALINT ‘)’

- 197 -
I. Expression Statements

EXPRESSIONSTATEMENT := ASSIGN | var DECLARE


DECLARE := ID [DIMLIST] IDLIST [to INIT]
*
IDLIST := ID ( ‘,’ ID )
INIT := default | null | INITLIST | [‘(‘] EXPRLIST [‘)’]
INITLIST := ‘{‘ EXPRLIST | INDEXLIST ‘}’
*
INDEXITEM := (INT_LITERAL | ’*’) (‘,’ (INT_LITERAL |’*’) )
*
INDEXLIST := INDEXITEM ‘:’ EXPR (‘,’ INDEXITEM ‘:’ EXPR)
*
ASSIGN := POSTFIX [ ASSIGNOP EXPR | STREAMOP EXPR (STREAMOP EXPR) ]
*
EXPR := LOGEXPR ( ‘||’ LOGEXPR )
*
LOGEXPR := INCEXPR ( ‘&&’ INCEXPR )
*
INCEXPR := XOREXPR ( ‘|’ XOREXPR )
*
XOREXPR := ANDEXPR ( ‘^’ ANDEXPR )
*
ANDEXPR := EQUEXPR ( ‘&’ EQUEXPR )
*
EQUEXPR := RELEXPR ( (‘==’|’!=’|in) RELEXPR )
*
RELEXPR := SHIFTEXPR ( (‘<’|’>’|’<=’|’>=’) SHIFTEXPR )
*
SHIFTEXPR := ADDEXPR ( (‘<<’|’>>’) ADDEXPR )
*
ADDEXPR := MULEXPR ( (‘+’|’-‘) MULEXPR )
*
MULEXPR := CASTEXPR ( (‘*’|’%’|’/’|’**’) CASTEXPR )
CASTEXPR := [‘!’|‘~’ |’+’|’-‘] POSTFIX [to NAME]
POSTFIX := PRIMARY [ARGLIST | ARRAYCALL]
*
(ATTRIBUTECALL [ARRAYCALL] | METHODCALL) [‘++’|’—-‘]
ARRAYCALL := ‘[‘ EXPRLIST ‘]’
ATTRIBUTECALL := ‘`’ ID
METHODCALL := ‘.’ ID [ARGLIST]
ARGLIST := ‘(‘ EXPRLIST ‘)’
DIMLIST := ‘[‘ [STARLIST|EXPRLIST] ‘]’
*
STARLIST := ‘*’ (‘,’ ‘*’)
*
EXPRLIST := EXPR (‘,’ EXPR)
*
NAME := ID (‘.’ ID)
PRIMARY := ID | this | self | super | null | LITERAL | ‘(‘ EXPR ‘)’

J. Lexical Elements (Scalars, Literals, Identifiers)

LITERAL := DECIMALINT | HEXINT | REALLIT | CHARLIT | STRINGLIT | INT


*
LITERAL_LiST := LITERAL (‘,’ LITERAL)
*
DECIMALINT := DIGIT (DIGIT)
INT := DECIMALINT
*
HEXINT := ‘0X’ HEXDIGIT (HEXDIGIT)
DIGIT := ‘0’ | ‘1’ | ‘2’ | ‘3’ | ‘4’ | ‘5’ | ‘6’ | ‘7’ | ‘8’ | ‘9’
LETTERCHAR := ‘a’ | ‘b’ | ‘c’ | ‘d’ | ‘e’ | ‘f’| ‘g’| ‘h’ | ‘i’ | ‘j’ | ‘k’| ‘l’ | ‘m’| ‘n’ | ‘o’ | ‘p’ | ‘q’ | ‘r’| ‘s’| ‘t’ | ‘u’ | ‘v’ | ‘w’| ‘x’ |‘y’|‘z’
| ‘A’ | ‘B’| ‘C’| ‘D’| ‘E’| ‘F’ | ‘G’ | ‘H’ | ‘I’| ‘J’| ‘K’| ‘L’ | ‘M’ | ‘N’ | ‘O’ | ‘P’| ‘Q’| ‘R’ | ‘S’ | ‘T’ | ‘U’| ‘V’| ‘W’|‘X’
| ‘Y’ | ‘Z’
HEXDIGIT := DIGIT | ‘A’ | ‘B’ | ‘C’ | ‘D’ | ‘E’ | ‘F’
*
CHARLIT := ‘‘’ UNICODECHAR ( UNICODECHAR ) ‘‘’| ESCAPECHAR
| ‘‘’ ‘\u’ HEXDIGIT HEXDIGIT HEXDIGIT HEXDIGIT ‘‘’

ESCAPECHAR := ‘\n’ | ‘\r’ | ‘\t’ | ‘\b’ | ‘\f’ | ‘\\’ | ‘\”’ | ‘\’’


*
STRINGLIT := ‘“’ UNICODECHAR (UNICODECHAR) ‘“’
METASTRING := ‘#’ ID
UNICODECHAR := 000016 … FFFF16
* * *
REALLIT := [(‘+’|’-‘)]( DIGIT (DIGIT) ‘.’ (DIGIT) | ‘.’ DIGIT (DIGIT) [‘E’(‘+’|’-‘) DECIMALINT ][‘F’]
*
ID := LETTERCHAR (UNICODECHAR | DIGIT | ‘_’ | LETTERCHAR)
ASSIGNOP := ‘=’| as | is | ‘:=’|‘+=’|‘-=’|‘*=’|‘/=’|‘%=’|‘&=’|‘|=’|‘^=’|‘>>=’|‘<<=’
LOGICALBITOP := ‘!’ | ‘&’ | ‘&&’ | ‘|’ | ‘||’ | ‘~’ | ‘<<’ | ‘>>’ | ‘^’
RELATIONALOP := ‘<’ | ‘>’ | ‘==’ | ‘!=’ | ‘>=’ | ‘<=’ | in
STREAMOP := ‘<<<’ | ‘>>>’
MATHOP := ‘%’ | ‘*’ | ‘**’ | ‘+’ | ‘++’ | ‘-‘ | ‘—‘ | ‘/’
OP := ASSIGNOP | LOGICALBITOP | RELATIONALOP | STREAMOP | MATHOP

- 198 -
K. Comments
* *
COMMENT := ‘//’ (UNICODECHAR) (‘\n’ | ‘\r’ | ‘\n’ ‘\r’) | ‘!!’ (UNICODECHAR) ‘!!’

- 199 -
- 200 -
References
Hoare, C. A. R. (1973). Hints on Programming Language Design, Stanford
University, Computer Science Department, TR CS-73-403.

Hoare, C. A. R. (1981). The Emperor's Old Clothes. Communications of


ACM, 24(2), pp. 75-83.

Hoare, C. A. R. (1974). Monitors: An Operating System Structuring


Concept. Communications of ACM, 17(10), pp. 549-557.

Wirth, Niklaus (1977). What Can We Do about the Unnecessary Diversity


of Notation for Syntactic Definitions? Communications of ACM, 20(11),
pp. 822-823.

Wirth, Niklaus. (1974). On the Design of Programming Languages. IFIP


Congress, pp. 386-393.

- 201 -
- 202 -
Index
absolute Cast Assignment Operator :=, 72
namespace, 45, 46, 47, 107, 108, 187 Checked
abstract Trap, 124, 187
method mode, 41 class
access, 13, 14, 17, 20, 33, 34, 35, 41, 56, 61, 62, 90, abstract, 20, 29, 30, 41, 42, 50, 51, 53, 54, 56, 57,
91, 93, 107, 108, 112, 113, 114, 116, 118, 121, 61, 63, 114, 119, 120, 121, 130, 131, 132, 134,
139, 140, 141, 142, 158, 164, 175, 182, 185, 191, 135, 136, 158, 164, 189, 190, 191, 192, 194
194 constant, 14, 17, 20, 25, 29, 30, 32, 33, 34, 35, 36,
Access, 61, 68, 90, 91, 92, 97, 141, 187 38, 41, 55, 56, 57, 59, 60, 63, 64, 82, 93, 95, 96,
access sub-expression, 141 102, 104, 107, 110, 114, 116, 119, 141, 142,
Accessor Methods, 111 148, 159, 164, 169, 176, 185, 187, 188, 189,
Addition Operator +, 87 192, 194, 195
Advanced Method Definition, 102 default, 29
aggregate collection, 172 generic, 13, 20, 29, 30, 42, 54, 56, 63, 130, 131,
array, 38, 39, 90, 91, 140, 141, 142, 148, 149, 164, 132, 133, 134, 135, 136, 189, 194
172, 173, 174, 175, 176, 187, 188, 189, 191 singular, 20, 23, 29, 30, 32, 35, 41, 42, 55, 56, 57,
Array Access [], 91 64, 102, 103, 104, 106, 107, 110, 114, 119, 120,
array declaration, 172 138, 164, 189, 194
assert statement, 143 static, 13, 20, 25, 29, 30, 32, 33, 34, 35, 41, 42, 53,
assignment, 69, 70, 72, 73, 74, 75, 76, 77, 117, 139, 55, 56, 57, 60, 63, 64, 95, 102, 103, 104, 105,
140, 141 106, 107, 108, 110, 114, 119, 120, 131, 184,
Assignment, 23, 68, 69, 70, 72, 73, 74, 75, 76, 77, 189, 191, 192, 194, 195
92, 97, 98, 140, 187 virtual, 20, 29, 30, 35, 41, 42, 47, 50, 51, 52, 53,
Assignment statement, 140 54, 56, 58, 59, 61, 83, 93, 94, 95, 102, 103, 104,
Async, 182 114, 120, 121, 131, 134, 158, 164, 190, 192, 194
asynchronous Class, 14, 23, 27, 28, 29, 34, 35, 41, 49, 51, 53, 54,
method synchronization, 41, 42, 182, 183, 184 55, 56, 58, 59, 60, 61, 62, 63, 89, 101, 105, 110,
asynchronous method, 184 114, 116, 119, 132, 133, 164, 167, 168, 172, 176,
Asynchronous methods, 182 183, 187, 188, 190, 191, 192, 194
asynchronous mode, 42 Class Attributes, 34
Attribute Access `, 90 Class Creation, Destruction, and Default,
Attribute Kind, 32, 187 114
Attribute Mode, 32, 187 class header, 28, 133
Attribute Scope, 33 class method, 35, 41, 42, 56, 57, 59, 62, 90, 102,
Attribute Type, 32 104, 105, 106, 108, 110, 113, 119, 120, 158, 164,
Attributes, 31, 32, 33, 34, 55, 107, 130, 172 168, 183, 184, 187, 188, 189, 190, 191, 192
generics, 130 Class Methods, 35
Bitwise, 23, 68, 75, 76, 77, 78, 79, 80, 81, 92, 97, 98 Class Reference Prefixes, 60
Bitwise Complement Operator ~, 80 Comments, 24, 197
Bitwise Exclusive-Or Assignment computation, 138, 139, 187
Operator ^=, 76 constant
Bitwise Inclusive-Or Assignment method mode, 41
Operator |=, 75 operator overload, 93
Bitwise Shift Left Operator <<, 80 Constructor, 114, 116, 173, 174, 187
Bitwise Shift Right Operator >>, 81 Constructor Definition, 114
Bitwise Shift-Right Assignment Operator Constructor Invocation, 116
>>=, 76 covariant method, 57, 58
Bitwise-And Assignment Operator &=, 75 Covariant Method, 57, 58
Bitwise-Shift-Left Assignment Operator covariant method return type, 57
<<=, 77 creation, 41, 69, 70, 117, 139, 140, 141, 188
Case Operator to, 71 creation statement, 140
case statement, 13, 150, 153, 154

- 203 -
declaration, 14, 15, 25, 32, 33, 34, 35, 41, 45, 46, generic class, 130
47, 50, 70, 93, 108, 116, 117, 118, 121, 135, 139, generic methods, 130
172, 183, 188, 189 global instantiation, 132
Declaration Goals
Trap, 44, 46, 93, 124, 139, 158, 172, 175, 188, 189 Mynx programming language, 18
declaration statement, 139 Greater Equal Operator >=, 84
default Greater Than Operator >, 84
attribute mode, 32 Handling
class category, 13, 14, 17, 20, 22, 23, 28, 29, 30, Trap, 125
32, 33, 34, 40, 41, 42, 44, 51, 52, 54, 55, 56, 58, hexadecimal number, 21
62, 64, 70, 86, 93, 95, 96, 102, 103, 104, 105, Identifiers, 20, 196
108, 109, 110, 114, 115, 116, 117, 118, 119, if statement, 126, 146, 153, 154, 155, 191
120, 121, 130, 132, 133, 134, 135, 139, 141, Implicit Accessor Methods, 112
142, 145, 153, 155, 158, 164, 168, 173, 174, implicit hierarchy
175, 176, 182, 184, 185, 188, 189, 191, 194, operators, 99
195, 196 implicit namespace, 44
method mode, 41 implied, 20, 58, 121, 158, 159, 160, 161, 164, 167,
operator overload, 93 168, 189, 192, 194
Default Method Declaration, 120 implied method, 121, 158, 159
Default Method Invocation, 120 in parameter, 36, 37, 38
Default Namespace, 44 In Parameter Mode, 36
Default Parameters by Method Incomplete Methods, 121
Equivalents, 109 Increment and Decrement Operator -- or
Definition ++, 89
generic class, 130 Inequality Operator !=, 82
Destructor, 114, 118, 119, 188 Inheritance, 29, 49, 50, 51, 53, 54, 55, 56, 57, 61,
Destructor Definition, 118 131, 165, 167, 189, 190, 191, 192
Destructor Invocation, 119 generic class, 131
dim, 40, 172, 176 Inheriting Other Classes
Division Operator /, 88 generic class, 134
Division-Assignment Operator /=, 74 Initial Value, 33, 189
Dottic Access, 61 input-output, 139, 141
Dual Assignment Operation Operators, 72 input-output sub-expression, 141
Encoding, 24 Insertion Operator <<<, 86
enumerated type, 25, 107 Instance Type Of Operator in, 83
Enumerated Types, 25 Instantiation
Equality Operator ==, 82 generic class, 132, 134, 189
error, 33, 36, 37, 38, 39, 40, 42, 47, 55, 58, 96, 104, Introduction, 11
108, 113, 117, 121, 124, 126, 138, 141, 143, 144, invalid namespace declaration, 44
148, 164, 165, 166, 168, 169, 173, 175, 188, 192 Invocation
error statement, 143 Trap, 90, 124, 168, 190
escaped character, 21 Keywords, 20
exception, 124, 125, 126, 143, 188, 192 kinds of classes, 29, 54
exit statement, 145, 146 kinds of static, 102
Explicit Accessor Methods, 112 Kinds of Traps, 124
Exponentiation Operator **, 88 Lesser Equal Operator <=, 85
Export Instance Method, 110 Lesser Than Operator <, 83
expression, 17, 33, 72, 91, 113, 116, 117, 120, 121, literal character, 21
138, 139, 140, 141, 142, 143, 175, 183, 184, 188 Literals, 20, 196
expression statement, 116, 120, 139, 141, 188 local instantiation, 132
Extraction Operator >>>, 86 Logical, 23, 68, 78, 79, 80, 81, 92, 97, 98
flag statement, 124, 143 Logical And Operator &&, 79
flow of control or jump, 138 Logical Bitwise And Operator &, 79
for statement, 148, 149 Logical Bitwise Inclusive Or Operator |, 79
generic, 130 Logical Exclusive Or Operator ^, 81
generic attribute, 130 Logical Not Operator !, 78

- 204 -
loop statement, 146, 148, 149, 150, 151, 192 myxd, 179
major design principles, 17 myxm, 178
Manifesto, 13 Name
Mathematic, 23, 87, 92 Mynx, 12, 22, 32, 61, 97, 98, 110, 164, 178
Mathematical, 68, 89, 97 namespace, 44, 45, 46, 47, 106, 107, 158, 178, 187,
meta string, 22, 23 188, 191
Meta Strings, 22 namespace declaration, 45, 46
Method definition by a method equivalent, 102 next statement, 145, 146
Method definition that is incomplete, 102 non-existent namespace, 47
Method Equivalents, 108, 109 nothing inheritance, 50
Method Headers, 42 Null
Method Invocation ., 90 inheritance, 50
Method Mode, 41, 190 null statement, 139, 142, 143, 154
Method Overloading, 59 Nullity, 36
Method Overriding, 56, 57 Numbers, 21
Method Parameter Modes, 36 numeric real literal, 22
Method Return Type, 42 obviate, 121, 164, 165, 166, 167, 168, 169
Method Scope, 40 obviate method, 121, 164
method signature, 34, 35, 42, 56, 59, 106, 108, 121, Obviate Method, 165, 168, 190
164, 165, 168, 189, 190 Operator =, 70, 82
Method Synchronization, 41, 190 operator as, 70
Method Traps, 40 operator is, 69, 72, 79, 80, 82, 83, 84, 85, 86, 93,
Method usage with a static method, 102 95, 117
Methods, 17, 31, 32, 34, 35, 41, 55, 56, 100, 101, Operator Overloading, 60, 67, 93, 95, 191
102, 103, 106, 108, 110, 111, 112, 114, 121, 130, Operators, 23, 61, 67, 68, 69, 72, 78, 79, 82, 86,
135, 143, 157, 158, 163, 164, 167, 182, 184, 194 87, 89, 90, 92, 97, 99, 100
minx, 178 Other Special Methods, 121
Modulus Operator %, 88 out parameter, 37
Modulus-Assignment Operator %=, 74 Out Parameter Mode, 37
Moxi, 178 Overriding a Static Method, 102
multi-dimensional, 172 Parameter List, 35, 191
Multiple Disjoint parameter mode, 35, 36, 37, 38, 42, 191
inheritance, 50, 53, 54, 190 Parameterized Types, 130
Multiple disjoint inheritance, 53 parameters, 14, 30, 33, 35, 36, 37, 38, 39, 42, 56,
multiple line comment, 24 61, 105, 108, 109, 114, 115, 117, 118, 121, 124,
Multiple Virtual 140, 164, 165, 188, 189, 191
inheritance, 50, 52, 53, 190 partial
Multiple virtual inheritance, 52 class category, 22, 29, 30, 54, 114, 120, 121
Multiple-line comments, 24 Philosophical Statement, 17
Multiplication Operator *, 88 Post-conditional loop, 152
Multiplication-Assignment Operator *=, postfix, 93, 139
73 postfix expression, 139
multithreaded, 182 pre-conditional loop, 152
mutex, 20, 138, 156, 182, 183, 184, 185, 187, 195 prefix-if statement, 146, 150
mutex expression, 184 primary design criteria, 13
mutex statement, 156, 183, 184 Principles of Design, 17
mutual exclusion, 138, 156, 182, 183, 184, 187, Program, 22, 27, 28, 34, 35, 106, 191, 195
190, 192 Program Attributes, 34
Mutual exclusion, 182, 185, 190 program method, 35, 40, 41, 147, 188
myna, 178 Program Methods, 35
Mynx, 11, 12, 13, 16, 17, 18, 20, 22, 23, 24, 25, 28, Program Methods as Default Static, 106
29, 30, 33, 41, 44, 45, 46, 47, 50, 51, 52, 54, 56, Project
57, 59, 60, 61, 68, 69, 78, 79, 80, 81, 82, 83, 84, Mynx, 12
85, 86, 87, 88, 90, 92, 98, 99, 102, 107, 108, 111, Prolog, 12
112, 121, 124, 130, 132, 138, 142, 158, 159, 160, Propagation
164, 169, 172, 176, 177, 178, 179, 182, 187, 193 Trap, 126

- 205 -
Proxima, 11, 12, 13, 15 Stream, 23, 46, 68, 86, 92, 97, 98
rank, 82, 172, 174, 175, 176, 187, 188, 189 Subtraction Operator -, 87
Reference Assignment Operator is, 69 Subtraction-Assignment Operator -=, 73
References, 36, 199 super, 20, 30, 34, 50, 53, 55, 56, 57, 58, 59, 60, 61,
other works, 199 62, 64, 83, 90, 91, 95, 104, 108, 115, 116, 119,
Relational, 23, 68, 82, 92, 97, 98 120, 132, 140, 141, 142, 165, 166, 168, 169, 188,
relative 191, 194, 196
namespace, 45, 46, 96, 107 Symbols, 21
Renaming All Class Methods of a Name, Sync, 182
110 synchronization, 41, 42, 182, 183, 185, 187, 190,
repeat loop, 151 192
repetition or iteration, 138 synchronous
repetition statement, 145, 146, 150, 151 method synchronization, 41, 42, 183, 184
reserved words, 20, 25, 41, 44 synchronous mode, 42
restricted Target Platforms, 16
class category, 29, 53, 54, 55, 93 task, 182, 183
return statement, 147 this, 15, 20, 23, 24, 39, 42, 55, 60, 62, 63, 64, 83, 90,
Return Types for Mathematical 91, 105, 109, 110, 111, 112, 113, 114, 115, 116,
Operators, 89 118, 119, 120, 124, 131, 133, 140, 141, 142, 145,
Rules for Method Overriding, 56 147, 153, 155, 160, 176, 184, 194, 196
Rules for Operator Overloading, 95 Thread, 182
scope of attributes, 33 Trap, 124, 126, 187, 192
scoping methods, 40 try clause, 125
selection or decision, 138 try statement, 40, 124, 125, 126, 143, 144, 187, 192
self, 13, 14, 20, 56, 57, 60, 63, 64, 65, 105, 106, 132, Types of Inheritance, 50
134, 135, 140, 184, 191, 194, 196 Types of Instantiation
series parameter, 38, 39 generic class, 132
Series Parameter Mode, 38 Unchecked
signature, 35, 52, 56, 57, 164, 165, 188 Trap, 124, 192
Single Undefined Method Header, 42
inheritance, 51 Unhandled Traps, 127
Single inheritance, 51 Unicode escape character, 21
Single-line comments, 24 until-loop repetition statement, 150
singular var parameter, 37, 38
method mode, 41 Var Parameter Mode, 37
size, 12, 34, 79, 87, 131, 132, 133, 135, 136, 146, virtual
172, 176, 187, 188, 189 method mode, 41
statements, 138 volatile
static attribute mode, 32
method mode, 41 while-loop repetition statement, 150
static method, 102 word operators, 23
static reference, 107

- 206 -

You might also like