You are on page 1of 222

Mynx

Programming Language
Manual

October 2007
Mynx Programming Language

-2-
Mynx Programming Language

The Mynx Programming


Language Manual

! Copyright October 2007

William F. Gilreath

http://www.williamgilreath.com/mynx

-3-
Mynx Programming Language

This book is licensed under the terms of the GNU Free


Documentation License.

Permission is granted to copy, distribute and/or modify this


document under the terms of the GNU Free Documentation License,
Version 1.2 or any later version published by the Free Software
Foundation; with the Invariant Sections being "Prolog" and
“Epilog”, no Front-Cover Texts, and no Back-Cover Texts. A copy
of the license is included in the section entitled "GNU Free
Documentation License".

-4-
Mynx Programming Language

Table of Contents
PROLOG .........................................................................................................................................................13
PRELUDE .......................................................................................................................................................15
NAME AND PROJECT ...................................................................................................................................15
PHILOSOPHICAL STATEMENT ....................................................................................................................16
TARGET PLATFORMS ...................................................................................................................................16
MANIFESTO ..................................................................................................................................................17
LANGUAGE PRINCIPLES .............................................................................................................................20
DESIGN RATIONALE ...................................................................................................................................21
Syntax .......................................................................................................................................................21
Statements................................................................................................................................................21
Units .........................................................................................................................................................22
GOALS ...........................................................................................................................................................23
LICENSE ........................................................................................................................................................24
License Objectives..................................................................................................................................24
Documentation .......................................................................................................................................24
Software ...................................................................................................................................................24
LEXICON........................................................................................................................................................25
IDENTIFIERS .................................................................................................................................................27
KEYWORDS ...................................................................................................................................................27
LITERALS .......................................................................................................................................................28
SYMBOLS .......................................................................................................................................................28
NUMBERS ......................................................................................................................................................29
META STRINGS .............................................................................................................................................30
OPERATORS ..................................................................................................................................................31
ENCODING ...................................................................................................................................................32
COMMENTS ...................................................................................................................................................32
Single Comments....................................................................................................................................32
Multiple Comments................................................................................................................................32
ENUMERATED TYPES ..................................................................................................................................33
STATEMENTS...............................................................................................................................................35
COMPUTATION.............................................................................................................................................38
Expression Statement ............................................................................................................................38
Declaration..........................................................................................................................................38
Expression...........................................................................................................................................38
Postfix .............................................................................................................................................39
Assignment .....................................................................................................................................39
Assign..........................................................................................................................................39
Create..........................................................................................................................................39
Input-Output .............................................................................................................................40
Access..............................................................................................................................................40
Attribute .....................................................................................................................................40

-5-
Mynx Programming Language

Method .......................................................................................................................................41
Array............................................................................................................................................41
Multiple.......................................................................................................................................41
Null Statement ........................................................................................................................................42
ERROR ...........................................................................................................................................................42
Assert Statement .....................................................................................................................................42
Flag Statement.........................................................................................................................................43
Try Statement ..........................................................................................................................................43
FLOW OF CONTROL ....................................................................................................................................44
Exit Statement.........................................................................................................................................45
Next Statement .......................................................................................................................................46
Prefix If Statement .................................................................................................................................46
Return Statement ....................................................................................................................................47
REPETITION .................................................................................................................................................48
For Statement..........................................................................................................................................48
For Statement over a Range .............................................................................................................48
For Statement over an Array ............................................................................................................49
For Statement over Other Integral Type........................................................................................49
Until Statement .......................................................................................................................................51
While Statement......................................................................................................................................51
Repeat Statement ....................................................................................................................................52
Pre-conditional and Post-conditional Loops......................................................................................53
Case Statement........................................................................................................................................54
If Statement .............................................................................................................................................55
MUTEX STATEMENT ...................................................................................................................................57
Mutex Statement Syntax ........................................................................................................................57
Mutex Expression...................................................................................................................................57
NAMESPACES ................................................................................................................................................59
Declaration ..............................................................................................................................................59
Default Namespace ................................................................................................................................59
Classes and Programs within a Namespace........................................................................................60
Inclusion of Classes from a Namespace .............................................................................................60
Nested Namespace Inclusion ...............................................................................................................61
Declaration Order for Namespace Inclusion .....................................................................................62
Mynx Namespace ...................................................................................................................................62
Nonexistent Namespace Inclusion ......................................................................................................62
Static Inclusion from Default Namespace..........................................................................................63
ARRAYS .........................................................................................................................................................64
Array Attributes ......................................................................................................................................64
Array Declaration ...................................................................................................................................65
Array Creation.........................................................................................................................................66
Initialization with a List.....................................................................................................................66
Initialization with an Implicit Indexed List................................................................................66
Initialization with an Explicit Indexed List................................................................................67
Initialization with a Non-List ...........................................................................................................67
Initialization with Default Constructor ......................................................................................67
Initialization with Null ..................................................................................................................68
Using an Element of an Array..........................................................................................................69

-6-
Mynx Programming Language

Array as an Object..............................................................................................................................70
Array as a Parameter..........................................................................................................................70
TRAPS ............................................................................................................................................................72
Kinds of Traps ........................................................................................................................................72
Trap Declaration.....................................................................................................................................72
Trap Invocation ......................................................................................................................................72
Trap Handling.........................................................................................................................................73
Trap Propagation....................................................................................................................................73
UNITS...............................................................................................................................................................75
PRIMARY ELEMENTS – PROGRAM AND CLASS ........................................................................................77
Program....................................................................................................................................................77
Class..........................................................................................................................................................78
KINDS OF CLASSES ......................................................................................................................................78
Abstract....................................................................................................................................................79
Constant...................................................................................................................................................79
Default......................................................................................................................................................79
Generic.....................................................................................................................................................79
Singular.....................................................................................................................................................80
Static .........................................................................................................................................................80
Virtual.......................................................................................................................................................80
CLASS DESIGN RATIONALE .......................................................................................................................81
INHERITANCE AND CLASS TYPES ..............................................................................................................82
TYPES OF INHERITANCE.............................................................................................................................82
Null ...........................................................................................................................................................82
Single ........................................................................................................................................................83
Multiple Virtual .......................................................................................................................................84
Multiple Disjoint.....................................................................................................................................85
CLASSES AND INHERITANCE ......................................................................................................................87
INHERITANCE OF ATTRIBUTES AND METHODS......................................................................................87
Attributes .................................................................................................................................................87
Methods ...................................................................................................................................................88
INHERITANCE OF METHODS .....................................................................................................................88
METHOD OVERRIDING ..............................................................................................................................88
Rules for Method Overriding ...............................................................................................................89
Covariant Method Overriding ..............................................................................................................90
Method Overloading..............................................................................................................................92
OPERATOR OVERLOADING .......................................................................................................................93
CLASS REFERENCE PREFIXES ....................................................................................................................93
Dottic Access Prefix...............................................................................................................................94
Super Class Prefix ..............................................................................................................................94
This Class Prefix.................................................................................................................................95
Self Class Prefix ..................................................................................................................................97
GENERICS .....................................................................................................................................................98
Elements of a Generic Class .................................................................................................................98
Generic Attributes..............................................................................................................................98
Generic Methods................................................................................................................................99
Operator Overloads in Generic Class .................................................................................................99

-7-
Mynx Programming Language

Default Method in Generic Class.......................................................................................................100


Inheritance with Generic Classes .......................................................................................................100
Inheriting a Generic Class...............................................................................................................101
Inheriting Non-Generic Classes.....................................................................................................101
Inheriting an Abstract Class.......................................................................................................102
Inheriting a Virtual Class ............................................................................................................103
Instantiation of a Generic Class .........................................................................................................104
Local Instantiation.......................................................................................................................104
Global Instantiation ....................................................................................................................105
Instance of a Generic Class.................................................................................................................106
ELEMENTS ..................................................................................................................................................109
MINOR ELEMENTS ....................................................................................................................................111
ATTRIBUTES ...............................................................................................................................................111
Attribute Mode......................................................................................................................................111
Attribute Kind.......................................................................................................................................111
Attribute Type.......................................................................................................................................112
Attribute Name .....................................................................................................................................112
Initial Value............................................................................................................................................112
Attribute Scope .....................................................................................................................................112
PROGRAM ATTRIBUTES ............................................................................................................................113
CLASS ATTRIBUTES ....................................................................................................................................113
METHODS ...................................................................................................................................................114
Program Methods.................................................................................................................................114
Class Methods .......................................................................................................................................114
Parameter List .......................................................................................................................................115
Method Parameter Modes...................................................................................................................115
In Parameter Mode ..........................................................................................................................115
Out Parameter Mode.......................................................................................................................116
Var Parameter Mode........................................................................................................................117
Series Parameter Mode....................................................................................................................118
Method Traps........................................................................................................................................119
Method Scope .......................................................................................................................................120
CLASS METHODS .......................................................................................................................................121
Method Mode........................................................................................................................................121
Method Synchronization .....................................................................................................................121
Method Return Type............................................................................................................................122
Method Headers ...................................................................................................................................122
Undefined Method Header .................................................................................................................123
ADVANCED METHOD DEFINITION AND USE .......................................................................................123
STATIC METHODS ......................................................................................................................................123
Kinds of Static Methods......................................................................................................................123
Overriding a Static Method.................................................................................................................124
Prefix for Static Method ......................................................................................................................126
Program Methods as Default Static ...................................................................................................127
Implicit Static Method Inclusion........................................................................................................127
Reference to External Static Method.................................................................................................128
METHOD EQUIVALENTS: LOW FAT METHODS ....................................................................................130

-8-
Mynx Programming Language

Default Parameters by Method Equivalents.....................................................................................131


Export Instance Method .....................................................................................................................131
Renaming All Class Methods of a Name ..........................................................................................132
CONSTRUCTION, DESTRUCTION, AND DEFAULT METHOD OF A CLASS ..........................................133
CONSTRUCTOR ...........................................................................................................................................133
Constructor Definition ........................................................................................................................133
Constructor Invocation .......................................................................................................................135
DESTRUCTOR .............................................................................................................................................137
Destructor Definition ..........................................................................................................................137
Destructor Invocation..........................................................................................................................137
DEFAULT CLASS METHOD .......................................................................................................................139
Default Method Declaration...............................................................................................................139
Default Method Invocation ................................................................................................................139
INCOMPLETE METHODS ...........................................................................................................................140
IMPLIED METHODS ...................................................................................................................................142
Rules for Implied Methods .................................................................................................................142
Declaration ............................................................................................................................................142
Implementation.....................................................................................................................................143
Implied Method Diagram....................................................................................................................145
OBVIATE METHODS ..................................................................................................................................146
Rules for Obviating a Class Method..................................................................................................146
Single Method by Signature.................................................................................................................146
Multiple Methods by Method Name .................................................................................................147
Inheritance with a Single Obviate Method .......................................................................................147
Using a Class with an Obviate Method.............................................................................................151
No Side Effects for Never Obviating a Method..............................................................................152
Reason to Obviate a Method ..............................................................................................................152
OPERATORS AND OPERATOR OVERLOADING ......................................................................................153
Operators...............................................................................................................................................153
Assignment ............................................................................................................................................154
Reference Assignment Operator is................................................................................................154
Creation Operator as .......................................................................................................................155
Regular Assignment Operator =....................................................................................................155
Cast Assignment Operator := ........................................................................................................156
Dual Assignment Operation Operators........................................................................................156
Subtraction-Assignment Operator -=...........................................................................................157
Multiplication-Assignment Operator *= ......................................................................................158
Division-Assignment Operator /= ...............................................................................................158
Modulus-Assignment Operator %= .............................................................................................159
Bitwise-And Assignment Operator &=........................................................................................159
Bitwise Inclusive-Or Assignment Operator |= ..........................................................................160
Bitwise Exclusive-Or Assignment Operator ^= .........................................................................160
Bitwise Shift-Right Assignment Operator >>=..........................................................................161
Bitwise-Shift-Left Assignment Operator <<=............................................................................161
Cast Conversion....................................................................................................................................162
Cast Operator to...............................................................................................................................162
Casting Class and Type....................................................................................................................163
Casting Type Rules...........................................................................................................................163

-9-
Mynx Programming Language

Cast Type Span ............................................................................................................................163


Cast Type Intent ..........................................................................................................................163
Cast Type Limit............................................................................................................................163
Casting Conversion Examples .......................................................................................................164
Logical Bitwise ......................................................................................................................................165
Logical Not Operator !....................................................................................................................165
Logical Bitwise And Operator &...................................................................................................166
Logical And Operator &&..............................................................................................................166
Logical Bitwise Inclusive Or Operator |......................................................................................167
Logical Inclusive Or Operator || .................................................................................................167
Bitwise Complement Operator ~..................................................................................................168
Bitwise Shift Left Operator << .....................................................................................................168
Bitwise Shift Right Operator >>...................................................................................................168
Logical Exclusive Or Operator ^...................................................................................................168
Relational ...............................................................................................................................................169
Equality Operator == .....................................................................................................................169
Inequality Operator != ....................................................................................................................170
Instance Type Of Operator in .......................................................................................................171
Lesser Than Operator < .................................................................................................................171
Greater Than Operator >...............................................................................................................172
Greater Equal Operator >=...........................................................................................................172
Lesser Equal Operator <= .............................................................................................................173
Stream.....................................................................................................................................................174
Insertion Operator <<<.................................................................................................................174
Extraction Operator >>> ..............................................................................................................174
Mathematic ............................................................................................................................................175
Addition Operator + .......................................................................................................................175
Subtraction Operator - ....................................................................................................................175
Division Operator /.........................................................................................................................176
Modulus Operator %.......................................................................................................................176
Multiplication Operator * ...............................................................................................................176
Exponentiation Operator **...........................................................................................................177
Increment Operator ++..................................................................................................................177
Decrement Operator -- ...................................................................................................................177
Access.....................................................................................................................................................178
Method Invocation . ........................................................................................................................178
Attribute Access `.............................................................................................................................179
Array Access [ ].................................................................................................................................179
Operator Precedence............................................................................................................................180
OPERATOR OVERLOADING .....................................................................................................................181
Operator Overload Declaration .........................................................................................................181
Kinds of Overloads..............................................................................................................................181
Rules for Operator Overloading ........................................................................................................182
Table of Operators...............................................................................................................................185
Standard Method Names for Overloads...........................................................................................186
Implicit Hierarchy of Operators.........................................................................................................187
APPENDICES ..............................................................................................................................................189

- 10 -
Mynx Programming Language

APPENDIX - MYNX GRAMMAR ................................................................................................................191


Header Syntax .......................................................................................................................................191
Class Syntax ...........................................................................................................................................191
Class Methods .......................................................................................................................................191
Class Attribute.......................................................................................................................................191
Class Overload ......................................................................................................................................191
Class Method Obviate..........................................................................................................................191
Program..................................................................................................................................................192
Statements..............................................................................................................................................192
Expression Statements.........................................................................................................................193
Lexical Elements...................................................................................................................................193
Comments..............................................................................................................................................194
APPENDIX - MYNX FILE TYPES AND TOOLS.........................................................................................195
Mynx.......................................................................................................................................................195
Myxm......................................................................................................................................................195
Moxi........................................................................................................................................................195
Myna .......................................................................................................................................................195
Minx........................................................................................................................................................196
Myxd.......................................................................................................................................................196
APPENDIX – GNU FREE DOCUMENTATION LICENSE .......................................................................197
EPILOG .........................................................................................................................................................205
REFERENCES ..............................................................................................................................................207
CREDITS ......................................................................................................................................................209
INDICES........................................................................................................................................................211
INDEX OF DIAGRAMS ...............................................................................................................................213
INDEX OF EXAMPLES ................................................................................................................................215
INDEX OF TABLES .....................................................................................................................................221

- 11 -
Mynx Programming Language

- 12 -
Mynx Programming Language

Prolog

- 13 -
Mynx Programming Language

- 14 -
Mynx Programming Language

Prelude
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, and 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. Ada95
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.

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.

- 15 -
Mynx Programming Language

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.

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).

- 16 -
Mynx Programming Language

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 Parentheses:
myMethod() or stack.pop(). Dottic notation is used, a 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. 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;

- 17 -
Mynx Programming Language

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

8. No nesting of classes or methods.

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

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

11. Disjoint multiple inheritance to permit code re-use, without just specification of
methods to implement.

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

13. 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.

14. 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.

15. 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, in a distributed environment, or an embedded environment.

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

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

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

19. 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 keywords for methods,
and variable and constant keywords for attributes.

- 18 -
Mynx Programming Language

20. 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;

- 19 -
Mynx Programming Language

Language Principles
There are six major language principles upon which the Mynx programming language design is
based. The language design principles, not in order of importance or priority 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.

- 20 -
Mynx Programming Language

Design Rationale
Mynx is designed in specific areas with a specific intention or rationale. The design rationale is for
three specific elements of the Mynx programming language:

1. Syntax
2. Statement
3. Units

Syntax
The first, and most difficult choice in programming language design is that of syntax style and form
of the language. The syntax of Mynx is that of the Algol style of programming languages similar but
not exact syntax of both Ada95 and Pascal.

Other syntax forms of object-oriented programming languages include:

1. Smalltalk - convoluted syntax style, lacks expressivity.

2. C/C++ - cryptic syntax with ambiguity, and another C syntax style language would appear
to be a Java or C++ clone.

3. Python - interesting syntax, but Python style syntax is a distinguishing Python feature, so
another language would be a Python imitator or derivative, only compiled, not a scripting
language.

Some syntactic styles such as COBOL and FORTRAN are too archaic to consider. Other syntax
from a programming language outside the object-oriented paradigm is a counter-productive choice
for an imperative object-oriented language. Inventing a new syntax might be more expressive and
efficient, but too far different. A level of familiarity in syntax is needed to explore and use a new
programming language.

Statements
Statements are the most fundamental element in a programming language, the entity from which
code is written. Using a simile, the statements of a programming language are like the palette of
colors used to paint a canvas.

Different programming languages have different degrees of statements. Mynx provides seventeen
statements, which seems a baroque approach to language design. However, Mynx is intended to
provide a solution of choices and selections, allowing the user to focus on the problem, not on the
idiosyncrasies of the language.

A minimalist approach of “one size fits all” would be simpler, easier to write a compiler for, but for
a user would have to invent many a kludge or workaround to create a feature. The effort is to twist
and contort the minimalist language to have a feature. The best criterion is to allow the user choice,
rather than either make the choice for them by design or for easier compiler construction.

- 21 -
Mynx Programming Language

Units
Units are the high-level organizing entity. In Mynx, the units are divided into two categories:

1. program - unit of application


2. class - unit of library or reuse

A unit in which everything is a class is simpler, but not expressive. Mynx further refines a class into
seven kinds, providing a rich framework for designing a class for reuse.

- 22 -
Mynx Programming Language

Goals
There are six 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. 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.

6. Proliferation: The dissemination and widespread use of Mynx by users both in academia
and industry.

- 23 -
Mynx Programming Language

License
Both the documentation (including this text) and the software — the examples, and the Mynx
software are released and distributed but under specific legally binding conditions — the ubiquitous
license.

License Objectives
The choice of license for the Mynx project is based on two criteria:

1. Mynx is a tool of thought, so should be non-proprietary, open for all to use (both
commercial and non-commercial) for whatever purpose; in essence, open-source.

2. Give credit where credit is due and retain the copyright, and avoid plagiarism, and allow
others to contribute, and also receive credit for their efforts.

A license needs to be selected for both the elements of documentation and the software, but under
the constraint of meeting both criteria for both elements.

Documentation
The documentation for Mynx in this book is released under the terms of the GNU Free
Documentation License (FDL). The objective is for the dissemination of information about and for
the use of Mynx. However preserving information about the overall project and rationale, and
references and credits with invariant sections.

Software
The software for Mynx is released under the terms of the GNU General Public License (GPL) so
that Mynx is open-source. There are three software elements covered by the GNU General Public
license:

1. example software and code in the book


2. implemented compiler and language tools
3. libraries that are part of the core package

The core Mynx libraries, as they are compiled into binaries for both the Java and .NET platform, so
can link to proprietary packages. The Mynx libraries are licensed under the GNU General Public
license, but have the Classpath exception to link to proprietary libraries.

- 24 -
Mynx Programming Language

Lexicon

- 25 -
Mynx Programming Language

- 26 -
Mynx Programming Language

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

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.

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

Example of Identifiers

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

Table of Mynx Keywords

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.

- 27 -
Mynx Programming Language

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.

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 Form Feed
\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.

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

Example of Unicode 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

Example of Symbol Literals

- 28 -
Mynx Programming Language

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.

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 prefix 0X
3.145 – legal real
0xFF – illegal hexadecimal prefix 0X is invalid
0XFF – legal hexadecimal integer
2.713F – legal float
.333337 – illegal real, must begin with a digit
OxCAFE – illegal hexadecimal integer needs ‘0X’ prefix
0.5 - legal real

Example of Numeric Literals

- 29 -
Mynx Programming Language

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 # character.
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 twenty 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 “2004-04-03”
#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 Compilation “14:31:00”
#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

The meta string format for the date #DATE and time #TIME are ISO-8601 standard compliant.

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.

- 30 -
Mynx Programming Language

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;

Example of using Meta Strings

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

Table of Output with using a Meta String

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.

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

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

- 31 -
Mynx Programming Language

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.

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.

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.

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


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

Example of Mynx Single-Line Comments

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.

!! 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

Table of Mynx Multiple Line Comments

- 32 -
Mynx Programming Language

The Mynx compiler ignores comments, but for documentation, the comments are processed with
the specific documentation with XML markup tags.

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-style 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.

- 33 -
Mynx Programming Language

- 34 -
Mynx Programming Language

Statements

- 35 -
Mynx Programming Language

- 36 -
Mynx Programming Language

Concept of Statements
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 seventeen statements are organized into five categories of statement:

1. flow of control or jump


2. repetition or iteration
3. selection or decision
4. error computation
5. 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

- 37 -
Mynx Programming Language

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” };

Example of Variable Declaration Expression

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

- 38 -
Mynx Programming Language

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.

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

Example of Postfix Expression

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;

Example of Assign Expression

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.

- 39 -
Mynx Programming Language

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

Example of Creation Expression

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;

Example of Input-Output Expression

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

Example of Attribute Access Sub-Expression

- 40 -
Mynx Programming Language

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;

Example of Method Access Sub-Expression

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

Example of Method Access by Default Sub-Expression

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;

Example of Array Access Sub-Expression

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;

Example of Multiple Access Expression Statement

- 41 -
Mynx Programming Language

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;

Example of Null Statement

A null statement can be useful as a placeholder for possible future statements.

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.

assert x > 0 as “variable x is not positive” ;


assert x != null ;
assert x != y && y > 0 as “x and y assertion failure” ;

Example of Assert Statements

- 42 -
Mynx Programming Language

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.

flag IOTrap(“Device not ready.”);


flag FileNotFoundTrap(“File does not exist.”);
flag IntegerOverFlow;

Example of Flag Statement

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.
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.

try
file = File(“test.data”);
when(FileNotFoundTrap)
IO.putln(“File was not found.”);
do
file.close;
end try;

Example of 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;

Example of Try Statement with Else Clause

- 43 -
Mynx Programming Language

An invalid flow of control statement with a return statement is:

try
return 0;
do
return 1; //compiler error: invalid flow of control
end try; //from try do-clause

Example of Invalid Try Statement with Flow of Control using Return

An invalid flow of control statement using a next statement is:

loop

try
next loop(0);
do
next loop(0); //compiler error: invalid flow of control
end try; //from try do-clause

end loop(0);

Example of Invalid Try Statement with Flow of Control using Next

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.

- 44 -
Mynx Programming Language

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);

Example of Exit Statement

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;

Example of Exit Statement

- 45 -
Mynx Programming Language

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;

Example of Next Statement

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 Ordinal findFirst(in Int[*] list, in Int val) is

var Ordinal 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;

Example of Prefix If Statement

- 46 -
Mynx Programming Language

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 Ordinal 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;

Example of Return Statement

- 47 -
Mynx Programming Language

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.

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.

//x implicitly Ordinal, count from 0 to 20


for(x is 0 to 20)
IO.putln(x);
end for;

Example of For Statement over Fixed Range

//x implicitly Ordinal, count from 100 to 0


for(y is 100 to 0)
IO <<< y <<< eoln;
y++; //error! y is constant value
end for;

Example of For Statement over Range

- 48 -
Mynx Programming Language

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.

var String[*] dataTable to {“hello”,“world”,“hi”,“greetings”};

for(String x in dataTable)
IO <<< x <<< eoln;
end for(0);

Example of For Statement over an Array

For Statement over Other Integral Type


A for statement does not have to have an implicit range of Ordinal or Int integral type. Other
integral types such as Byte, Short, and UnsignedByte can be used explicitly in a for statement.

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;

Example of a For Statement with an Explicit Integral Type

//2^16-1 is upper limit


for(UnsignedShort ush is 0 to 65535)
sum += sum + ush; //compute sum from 0 to 65536
end for;

Example of a For Statement with an Explicit Integral Type

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.

- 49 -
Mynx Programming Language

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.

//infinite loop without explicit end


loop
null;
end loop;

Example of Loop Statement

var Bool statusFlag to False;

loop
doFileOperation(statusFlag);
exit if(statusFlag); //prefix-if explicit exit
end loop;

Example of Loop Statement with Prefix If 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;

Example of Loop Statement with Exit in Case Statement

- 50 -
Mynx Programming Language

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;

Example of Until Statement

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;

Example of While Statement

- 51 -
Mynx Programming Language

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.

var File dataFile to “myfile.dat”;

dataFile.open;

repeat
dataFile.readRecord;
while(!dataFile.endOfFile );

Example of Repeat Statement with While Condition

var File dataFile to “myfile.dat”;

dataFile.open;

repeat
dataFile.readRecord;
until( File.endOfFile );

Example of Repeat Statement with Until Condition

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.

A repeat statement can have a nesting level, as a repeat statement can be nested within another
repeat statement. And like the other loops, an exit, next, and prefix-if statement can alter flow of
control in the repeat statement.

- 52 -
Mynx Programming Language

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

Example of Repeat Statement with Prefix-If and Nesting

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.

- 53 -
Mynx Programming Language

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;

Example of Case Statement

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;

Example of Delimited List of Values with a Case Statement

The else statement is for the default or non-case specific option, and is required for a case statement.

- 54 -
Mynx Programming Language

A case statement can case on a String literal:

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;

Example of Case Statement with String Literal

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.

if(x < y)
x = y; //then-block
end if;

if(x < y)
x = y;//then-block
else
null; //else-block
end if;

Example of Equivalent If Statements

- 55 -
Mynx Programming Language

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;

Example of Equivalent If Statement with Else-If Elif Block

An if statement does not require an else if an else if or elif-clause is used.

if(x > y) //no else required


x.computeWith(y);
elif(x < y)
y.computeWith(x);
end if;

Example of If Statement without Else Block

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;

Example of an If Statement with All Branches of the If Statement

- 56 -
Mynx Programming Language

Mutex Statement
A mutex (mutual exclusion) statement is used to create a block of mutual exclusive statements (a
critical section of statements) within a class method. Every object has a lock for mutual exclusion
used by a thread or task; to use an object lock, a mutex statement for mutual exclusion is required.

A mutex statement consists of a mutex header, the block of statements forming a critical section,
and the 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.

Mutex Statement Syntax


The general syntax for a mutex statement is as a block statement, with a header and footer enclosing
the block of statements that are mutually exclusive, or thread-safe.

mutex ( EXPRESSION )
STATEMENTS
end mutex ;

Example of Mutex Statement Syntax

The statements can be any possible statement, including another nested mutex statement.

Mutex Expression
The mutex expression is an expression for an object lock, or 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 in a mutex statement
requires an explicit lock – in the form of a mutex expression.

The simplest mutex expression for a lock is to use the keywords of this class reference for the
object instance of a class.

mutex(this)
null;
end mutex;

Example Mutex Expression with This Class Reference

- 57 -
Mynx Programming Language

An alternative is to use a variable for the mutex expression, such as a class attribute or local variable
declared within a method.

Object myMutex to default;

mutex(myMutex)
null;
end mutex;

Example of Mutex Expression using Local Variable

- 58 -
Mynx Programming Language

Namespaces
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...).

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.

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

Example of Namespace Declaration

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

Example of Invalid Namespace Declaration

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.

module default; – invalid, ‘default’ is keyword


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

Example of Default Namespace Declarations

- 59 -
Mynx Programming Language

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.

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;

Example of Absolute Namespace Inclusion

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.

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

Example of Relative Namespace Inclusion

- 60 -
Mynx Programming Language

Nested 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 are declared:

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

Example of Hierarchical Sub-Namespaces

Using the declared namespaces:

with example.*;

Example of Namespace Inclusion from Hierarchical Namespace

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.*;

Example of Sub-Namespace Inclusion from Hierarchical Namespace

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.*.*.*;

Example of Invalid Namespace Inclusion

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

- 61 -
Mynx Programming Language

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.

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.introspect Introspective Runtime Type Information Classes
mynx.trove Collections, Data Structures, Algorithms
mynx.gui Graphic User Interface Classes

Table of Mynx Namespaces

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.

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


// non-existent absolute namespace

virtual class Nothing as null is


//...
end class;

Example of Non-Existent Namespace Inclusion

- 62 -
Mynx Programming Language

Static Inclusion from Default Namespace


Declaring a class within default namespace.

module default;

static class S3 is

public singular nop is to null;

end class;

Example of Declaring a Class with Default Namespace

Using static include class in default namespace.

with S3; //static inclusion of class in default namespace

program useS3 is

nop; //implicitly invoke static method on S3

end program;

Example of Using Static Include Class in Default Namespace

- 63 -
Mynx Programming Language

Arrays
An array is an indexed, homogeneous, aggregate collection of a class type. An array in Mynx is a
first-class object (the array itself can be used as an 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
that can be indexed to access an element.

Kinds of Arrays
An array is a composite, homogenous aggregate of elements, or more specifically objects. An array is
itself an object, containing other objects, or reference handles to objects in memory.

In Mynx, there are two kinds of arrays in the language:

1. Infinite - the array dimension boundaries are unknown.


2. Bounded - the array dimension boundaries are specified.

An infinite array is of the form where the array bounds in the brackets use a wildcard or asterisk ‘*’
instead of a non-negative integer value for each dimension.

Ordinal[*] ord to null; //infinite 1-dimensional array


Bit[*,*] bits to null; //infinite 2-dimensional array

Example of Infinite Array Declaration

A bounded array is of the form where for the array bounds uses a non-negative integer value for
each dimension.

Ordinal[20] ord to null; //bounded 1-dimensional array


Bit[4,4] bits to null; //bounded 2-dimensional array

Example of Bounded Array Declaration

For both bounded and infinite arrays, the rank is known, only for infinite arrays the specific
dimension lengths and overall size is unknown.

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) or length(n)

- 64 -
Mynx Programming Language

A 1-dimensional array, the size and dim(0) or length(0) are equivalent, with a rank of one. For an
array that has not be instantiated, the length and dimensions are undefined hence accessing
undefined will flag a trap. For completeness and consistency, a non-array variable or constant has a
rank of zero.

For an array, it is declared, and then initialized – the array is created fully. After creation, an array is
utilized by either accessing an element or information about the array, or the array as a complete,
individual object.

Array Declaration
An array declaration is of two types:

1. definite – array bounds are specified in declaration


2. indefinite – array bounds are not specified in declaration

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.

Declaring an array uses the class type, 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.

String[2] names; //dimensions 0..1


Point[4] coordinates; //dimensions 0..3
Integer[4,4] matrix; //dimensions 0..3, 0..3

Example of Definite Array Declaration

String[*] name; //1-dimension array


Integer[*,*] matrix2D; //2-dimension array
File[*] fileList; //1-dimension array
Char[] chars; //1-dimension array implicitly

Example of Indefinite Array Declaration

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.

- 65 -
Mynx Programming Language

Array 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.

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.

Array Initialization
An array is created, and space allocated for it from the heap memory. However, creating an array
does not initialize it an array object reference is created, but it does not contain any data. Array
initialization is when the array is filled with data elements.

There are two primary forms of initialization of an array:

1. List - a list of data element values is used to initialize the array.


2. Non-list - initialization is by a means other than a list of values.

Initialization with a List


Initialization of an array with a list uses data elements within a list to initialize each array index with
each element present in the list. There are two kinds of lists of initial values for initialization of an
array:

1. implicit indexed - no index for each element in the list


2. explicit indexed - an index for each element in the list

Initialization with a list is only possible within an array declaration.

Initialization with an Implicit Indexed List


An implicit indexed array is a list without any index for specific array element position to an array.
This is only possible for a 1-dimensional array, and is convenient to avoid the tedium of specifying
each index, when each position in the initialization list is the implicit index.

Int[*] ix to { 0, 1, 2, 3, 4 }; //implicit index


Int[*] iy to { 0:0, 1:1, 2:2, 3:3, 4:4 }; //explicit index

Example of Creating an Array with Implicit and Explicit Position Index

It is still possible to use an explicit index for a 1-dimension array—it is not semantically incorrect.
However, an implicit indexed list for initialization is only possible for a 1-dimensional array.

- 66 -
Mynx Programming Language

Initialization with an 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. An explicit indexed array is a list with an index associated with each
element in the list to indicate the array element.

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
var Bool[3] bl to { 0:True, 1:False, 2:True}; //explicit index

Example of Creating an Array with Explicit Position Index

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 – the default
for an array 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 };

Example of Creating an Array with Explicit Integer Index

Array initialization in Mynx is absolute, flat-indexed, and independent of the underlying array
organization such as row-major or column-major structure.

Initialization with a Non-List


An array can be initialized by a non-list in two possible ways:

1. constructor– use the default constructor (if the class has one, else it is a semantic error)
2. null – use a value of null to indicate no initialization (must initialize later)

Initialization with Default Constructor


Creating a new array can use a constructor to initialize all new array instances, instead of an initial
value list of literals.

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

Example of Creating an Array Initialization by Constructor

- 67 -
Mynx Programming Language

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

Example of Creating an Array using a Default Constructor

Initialization with Null


An array can use a null to indicate no initial value or initialization with a constructor. Later the
reference is initialized with a list of values. This kind of initialization is deferred creation, the array is
declared, but not created or initialized. In effect, the array initialization is explicitly deferred, and the
array must be initialized later in the code.

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); //initial list of constructors
points as Point[2]; //create array default constructor

Example of Null in the Declaration of an Array

An array can be declared, but then created with the as operator and a class constructor called
explicitly.

var String[*] name to null;


name as String[2];
name[0] is “hello”;
name[1] is “world”;

var Char[*] vowels to null;


vowels as Char[5];
vowels[0] is ‘a’;
vowels[1] is ‘e’;
vowels[2] is ‘i’;
vowels[3] is ‘o’;
vowels[4] is ‘u’;

var Real[*] consts to null;


consts[0] is 3.14579;
consts[1] is 2.7152;

Example of Declaring an Array but Creation and Initialization Later

- 68 -
Mynx Programming Language

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

Example of Declaring an Array and then Creating a New Array

Creating an array using the as operator only uses a constructor, a list can only be used in a list
initialization of an array declaration.

Utilizing 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 Object - access and use the entire array as an object.

Using an Element of an Array


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.

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

Example of Using an Element of an Array

- 69 -
Mynx Programming Language

Array as an Object
An array can be used as an object, the entire collection of homogeneous element instances as a
single entity or object. Using an array as an object involves using the array identifier as a variable.

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.destruct; //destroy the array instance

if(ints == null) //check for nullity


ints as Int[3];
else
ints.destruct;
ints as Int[3];
end if;

Example of Using an Array as an Object

Array as a Parameter
An array can be passed as an object to a method that only needs to know 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;

Example of Passing an Array as a Parameter

var Int[10,10] array2D to { *:0 };


this.myMethod(array2D);

Example of Using the Array an the Existing Method

An infinite array is useful to pass a generalized array to a method of a program or class, where such
an array size is known at runtime. The rank of an array is known at compile time, but not the
specific dimension lengths.

- 70 -
Mynx Programming Language

//main method is passed 1-dimension array length unknown


method main(String[*] args) is

//put each array element to console or IO


for(Ord index is 0 to args.size)
IO.putln(args[index]);
end for;

end main;

Example of an Infinite Array of Rank One as Parameter to Method

- 71 -
Mynx Programming Language

Traps
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.

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.

Trap 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.

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


public Int divide(in Int divisor) has ZeroDivideTrap is

Example of Declaration of Traps in a Method

Trap 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.

- 72 -
Mynx Programming Language

if(divisor == 0)
flag ZeroDivideTrap;

flag InvalidInput(“Enter a character”);

Example of Flag Statements

Trap 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.).

Trap 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.

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

Example of Propagating a Trap

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.

- 73 -
Mynx Programming Language

- 74 -
Mynx Programming Language

Units

- 75 -
Mynx Programming Language

- 76 -
Mynx Programming Language

Primary Elements – Program and Class


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.

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.

program helloWorld as sayIt is


program computeFactorial as factorial is
program example as main is

Example of Program Header

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.

program hello_world is
program gcd is
program ticTacToe is

Example of Bodyless Program Header

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.

- 77 -
Mynx Programming Language

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.

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

Example of Class Header

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; declare and/or define methods.


2. constant - a completely finally complete class
3. default - the regular instance 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 and overloads but not define methods.

- 78 -
Mynx Programming Language

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

Table of Mynx Class Kinds, Inheritance, Instance, Category

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.

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.

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.

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.

- 79 -
Mynx Programming Language

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.

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.

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.

- 80 -
Mynx Programming Language

Class Design Rationale


Mynx has seven different class kinds, which seems to complicate and convolute the language. The
seven kinds of classes however, can be organized and classified under a few simple criteria.

Class Kind Derivation Existence Method Specified Bound Type


Abstract Yes – must None Incomplete Yes
Constant No Instance Complete Yes
Default Yes – can Instance Complete Yes
Generic Yes – can None Complete No
Singular No Static Complete Yes
Static Yes Static Complete Yes
Virtual Yes – must None Incomplete Yes

Table Summary of Criterion for Mynx Classes

Both abstract and virtual classes are incomplete in having undefined methods a method is declared
but not defined. Both classes require the derivation of a sub-class to create a complete class. A
generic class is a special kind of incomplete class; it is fully declared and defined except in terms of
the class type--hence the a generic class is a parameterized type. A generic class needs instantiation
or binding to a type.

Both a constant and default classes are complete classes in both declaring and defining methods, and
bound to a type. Both classes are instances, created and initialized at runtime using a constructor,
and destroyed using a destructor. The only distinction is that a constant class cannot derive a sub-
class via inheritance, whereas a default class can derive a sub-class.

A static and singular class is a complete class in both declaring and defining methods, and bound to
a type. Both classes are not instances and exist without a constructor or destructor. The distinction is
that a singular class cannot derive a sub-class via inheritance, but a static class can derive a static sub-
class. For the seven kinds of classes, there are essentially four distinct criterion used to uniquely
classify each class. The four criteria for class classification are:

1. Derivation of a sub-class from the class.


2. Instance or non-instance for class existence.
3. Methods specified in the class.
4. Instantiated or bound to a type.

- 81 -
Mynx Programming Language

Inheritance and Class Types


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.

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.

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

//define the class

end class;

Example of Null Inheritance

virtual class Void is //implicitly inherits null or nothing

//define the class

end class;

Example of Implicit Null Inheritance

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.

- 82 -
Mynx Programming Language

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.

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.

with mynx.core.*;

default class myClass as baseObject is

//...class body...

end class;

Example of Single Inheritance

Diagram of Single Inheritance

- 83 -
Mynx Programming Language

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.

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;

Example of Multiple Virtual Inheritance

- 84 -
Mynx Programming Language

Diagram of 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.

- 85 -
Mynx Programming Language

class SubClassXY as ABaseClassX, ABaseClassY, VirtualRootClass is

!! comparison abstract class methods are disjoint


from persistence class !!

//...class definition...

end class;

Example of Multiple Disjoint Inheritance

Diagram of UML Class Diagram of Multiple Disjoint Inheritance

- 86 -
Mynx Programming Language

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

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

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.

- 87 -
Mynx Programming Language

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;

Example of Shadowing a Class Attribute in Inheritance

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.

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.

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

- 88 -
Mynx Programming Language

method equivalence from the super class (although it is not method overriding, it is method
equivalence).

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.

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;

Example of Method Overriding with Inheritance

- 89 -
Mynx Programming Language

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.

- 90 -
Mynx Programming Language

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 of Covariant Method Override with Implied Method

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

Example of Covariant Method Override with Virtual Class

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.

- 91 -
Mynx Programming Language

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.

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 Ordinal i) is
i++;
end doSomething;

end class;

Example of Overloading within the Class and Sub-Class

- 92 -
Mynx Programming Language

Operator Overloading
Overloaded operators in a sub class do not inherit the super class overloaded operators. In effect,
the constant operators of a super class are implicitly part of a sub class, but not by inheritance.

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

overload constant + as add;

end class;

class Ord32 as Ord64 is //sub-class of Ord64

public Ord32 add(in Ord32 op) is


//define addition for Ord32
end add;
//re-declare overload from super-class
overload constant in Ord64 is + as add;

end class;

program addExample is

let Ord64 i64 to 0;


let Ord32 i32 to 37;

i64 = i64 + i32;

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

//implicit upcast explicitly:


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

end program;

Example of Operator Overloading within the Class and Sub-Class

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

- 93 -
Mynx Programming Language

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.

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


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

Example of Accessing Attribute over Method

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.

- 94 -
Mynx Programming Language

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;

Example of Super Class Parent Definition

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;

Example of Super Class Reference with Inheritance

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.

- 95 -
Mynx Programming Language

class Parent as null is

private construct is null; //no constructor

private Int zero to 0;

public 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;

Example of Class with This Reference Prefix

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

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;

Example of Class with This Reference as Variable

- 96 -
Mynx Programming Language

Self Class Prefix


The self reference prefix refers to the static attributes or methods (similar to the this class reference
prefix). The self class reference prefix can be used within a method or method equivalent.

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;

Example of Class with Increment Method using Self Prefix

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.

- 97 -
Mynx Programming Language

Generics
A generic class is type parameterized, or in more simply, the specific type of the generic class is
abstract. A generic class is a complete class like a default class, except that the specific type is
declared but not defined -- it is generic. In order to use a generic class, the class must be bound to a
type or instantiated. A typeful class is a non-generic class that has a specific type, which would be a
generic class that is bound to a type.

The two primary reasons for a generic class are:

1. Reuse by instantiation to different class types.


2. Avoid repeated type casts by using a concrete type.

A generic class allows for a specific class to be defined, and then instantiated or bound to a specific
type for use. Without a generic class, the same functionality would have to be redefined, which is
error prone and wasteful.

A generic class uses a specific type, avoiding the tedious process of casting to a type, even when a
class is defined around a common super-class.

A generic class is an order one generic class -- there is only one type that is abstract. Other
programming languages with generics allow for order two or more generic types, but Mynx is
designed for order one generics.

Elements of a Generic Class


A generic class is a complete class, and so supports the four major elements of a class-- attributes,
methods, operator overloads, and a default method. A generic class method includes constructors
and a destructor. The type of methods and attributes can be both generic and typeful or non-
generic.

Generic Attributes
A generic class can have both generic and typeful attributes, depending upon how the generic class
is designed and written. A generic attribute, as the type is essentially abstract, must be initialized to
null, and not a default or specific constructor.

class GStack as null is

private Ordinal count to 0; //typeful attribute


private generic[*] data to null;//generic attribute

end class;

Example of Generic Class Attributes

- 98 -
Mynx Programming Language

Generic Methods
A generic class can have methods in the form of constructor, destructor, and regular methods.
Regular methods can be generic, typeful, or void in return type.

generic class GVar as null is

private generic value to null;

public construct(in generic val) is


this`value is val;
end construct;

public constant generic get is


return this`value;
end get;

public constant void set(in generic val) is


this`value is val;
end set;

end class;

Example of Generic Class Methods

Operator Overloads in Generic Class


A generic class can overload operators for a method in the class. The overloaded operator can only
be used once the generic class is instantiated, and an instance created for a specific type.

generic class GVar as null is

private generic value to null;

public construct(in generic val) is


this`value is val;
end construct;

public constant generic get is


return this`value;
end get;

public constant void set(in generic val) is


this`value is val;
end set;

overload constant = as set;

end class;

Example Operator Overload in a Generic Class

- 99 -
Mynx Programming Language

Default Method in Generic Class


A generic class can specify a default method for the class on a typeful instance. The default method
can only be used on a generic class that is instantiated or bound to a specific type.

generic class GVar as null is

private generic value to null;

public construct(in generic val) is


this`value is val;
end construct;

public constant generic get is


return this`value;
end get;

public constant void set(in generic val) is


this`value is val;
end set;

overload constant = as set;


public default is to get;

end class;

Example of a Default Method in a Generic Class

Inheritance with Generic Classes


A generic class as a class can inherit, but only three specific kinds of classes. A generic class can
inherit from:

1. generic - inherit another generic class.


2. abstract - inherit an abstract, incomplete class.
3. virtual - inherit a virtual class.

- 100 -
Mynx Programming Language

Inheriting a Generic Class


A generic class can singly inherit from another generic class. Inheriting a generic class is for
specializing and refining a generic class; while still being abstract about specific class type.

generic class GVarPut as GVar is

public constant generic put(in generic data) is


super.set(data);
return super.get;
end get;

end class;

Example of a Generic Class Inheritance of a Generic Class

Inheriting Non-Generic 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 inter-mixed 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.

- 101 -
Mynx Programming Language

Inheriting an Abstract Class


A generic class can multiply disjoint inherit one or many abstract classes. Inheriting an abstract class
adds specific but typed functionality to a generic class.

abstract class AEmpty is

public abstract Ordinal size;

public Bool isEmpty is


return this.size == 0;
end isEmpty;

end class;

abstract class AFull is

public abstract Ordinal count;

public Bool isFull is


return this.count != 0;
end isEmpty;

end class;

generic class GVarSize as AEmpty, AFull is

private Ordinal size to 0;

public Ordinal size is


return this`size;
end size;

public Ordinal count is to size;

end class;

Example of Generic Class Inheriting Multiple Disjoint Abstract Classes

- 102 -
Mynx Programming Language

Inheriting a Virtual Class


A generic class can multiply inherit many virtual classes. Inheriting a virtual class declares but also
requires a definition of functionality of concrete typed methods in the generic class.

virtual class VEmpty is

public Bool isEmpty;


public Ordinal size;

end class;

virtual class VFull is

public Bool isFull;


public Ordinal size;

end class;

generic class GVarSize as AEmpty, AFull, VEmpty, VFull is

private Ordinal size to 0;

public Ordinal size is


return this`size;
end size;

public Ordinal count is to size;

end class;

Example of a Generic Class Inheriting Multiple Virtual Classes

- 103 -
Mynx Programming Language

Instantiation of a Generic Class


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.

Instantiation of a generic class is to bind a generic class to a type, creating a concrete typed class. In
Mynx, there are two types of binding:

1. Local - bind a generic class within a class; class does not exist beyond class bound to type.
2. Global - bind a generic class as a class; class exists and is extendable.

Local Instantiation
Local instantiation of a generic class to a class type creates a local instance within the class, but does
not create an external class that can be used beyond the locality of the instantiation within the class.
Local instantiation is only possible at the class-level, as an attribute, and not within a class method.
Attribute level instantiation creates a class that is defined within the class where it is instantiated.

default class myLocalVariable is

private GVar to String strVar to “hello world!!!”;

public construct is to null;

end class;

Example of Local Instantiation of a Generic Class to Type String

- 104 -
Mynx Programming Language

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.

Class level instantiation creates a new class, and new attributes and methods can be defined when
the class is instantiated. The has 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.

class StringVar has GVar to String is

public void setEmptyString is


this.set(“ “);
end setEmptyString;

end class;

Example of Global Instantiation of a Generic Class to Type String

- 105 -
Mynx Programming Language

Instance of a Generic Class


Before an instance of a generic class can be created, the generic class must be instantiated to a type.
Instantiation binds a generic class to a specific class type, but it does not create an instance or object
of that class. Once instantiated, only then can an instance of a generic class be created.

Local and global instantiation instantiate a generic class, bind the generic class to a type. However,
local instantiation creates an anonymous type, a type without a specific type name. Global
instantiation creates a class as a type, so an actual type with a name. The difference in local and
global is that local instantiation can only create an instance in the same declaration of instantiation.
In contrast, an instance of a globally instantiated generic class can be created anywhere.

Anywhere an instance requires a type name; it requires a global instantiation of a generic class. The
only element for local or anonymous instantiation of a generic class is as a class attribute, but then
the name of the attribute is used throughout the class, not the type.

The three elements of a class that can use a generic class instantiation as a class type are:

1. attribute of the class


2. parameter of a class method
3. variable of a class method

- 106 -
Mynx Programming Language

class StringVar has GVar to String is

public void setEmptyString is


this.set(“ “);
end setEmptyString;

end class;

class useGenericClasses is

//create local, use constructor in declaration


public GVar to String lstrVar to “local”;

//create global, use constructor elsewhere


public StringVar gStrVar to null;

public construct is to null;

gStrVar as StringVar(“global”);

end construct;

public void doSomething(in StringVar sv) is


var StringVar strvar to null;

strvar = sv;
if(sv == this`gStrVar)
this`lStrVar is sv;
end if;

end doSomething;

end class;

Example of Local and Global Instantiation Instances within a Class

- 107 -
Mynx Programming Language

- 108 -
Mynx Programming Language

Elements

- 109 -
Mynx Programming Language

- 110 -
Mynx Programming Language

Minor Elements
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

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.

- 111 -
Mynx Programming Language

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.

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.

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

Example of Initial Values in Attributes

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.

- 112 -
Mynx Programming Language

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.

in for all – inclusive for all methods


out for null – exclusive for no methods

Table of Implicit Scope Attributes

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

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.

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 Ordinal i to (0);
let variable Int x, y, z to (3);

Example of Program Attributes

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.

public Int size to 0 in for all;


public Int count to -1 in for getCount;

Example of Class Attributes

- 113 -
Mynx Programming Language

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.

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

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.

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

Example of Program Method Return Types

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.

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

Example of Class Method Return Types

- 114 -
Mynx Programming Language

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.

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

Table 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.

- 115 -
Mynx Programming Language

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;

Example of Class Method using In Parameter Mode

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

Example of Using the Defined Method with In Parameter

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

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.

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

var Int temp to null;

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

end swap;

Example of Defining a Method with Out Parameter

- 116 -
Mynx Programming Language

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

Example of Using the Defined Method with Out Parameter

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 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.

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 Defining a Method with Var Parameter

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

Example of Using the Defined Method with Var Parameter

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

- 117 -
Mynx Programming Language

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.

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 Defining a Method and Using with Series Parameter

- 118 -
Mynx Programming Language

!! 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;

Example of Using a Method with Series Parameter Incorrectly

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.

- 119 -
Mynx Programming Language

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 Ordinal dim) has OutOfMemoryTrap is

Example of Declaring Traps in a Method

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.

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

Example of Declaring Method Scope

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.

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

Example of Declaring Program Method Headers

- 120 -
Mynx Programming Language

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

- 121 -
Mynx Programming Language

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.

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

Example of Declaring a Method Return Type

Method Headers
A class method header is a composite of information about the class method. A class method must
specify the elements:

1. visibility - the external access level of the class method


2. mode - the kind of a class method
3. type - the return type of a class method (implicit void)
4. synchronized - the class method is thread safe (implicit non-thread safe)
5. name - the name of the class method
6. parameters - any parameters in and out of the class method
7. traps - any possible traps the class method flags
8. scope - the internal access of a class method (implicit scope is visible for all)

A class method is uniquely identified by the name and parameters. The type and other class method
header information is not used. The only exception is a class method that is covariant (return type of
the method can be overridden with a sub-class of the return type) in which case the type along with
the name and parameters uniquely identify the class method.

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


public generic pop out for all is
public asynch singular Ordinal 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 Ordinal computeVal(in VInteger vint) is

Example of Declaring a Class Method Header

- 122 -
Mynx Programming Language

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.

public abstract Bit compare(in VCompare);


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

Example of an Undefined Class Method Header

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.

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

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

- 123 -
Mynx Programming Language

Overriding a Static Method


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

Kind of Method Override


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.

default class BubbleSort as null 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 null is //implement VSort

public construct is to null;

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

//...implementation if quick sort

end sort;

end class;

Example of Overriding a Static Method in Multiple Classes

- 124 -
Mynx Programming Language

A refinement of the QuickSort class and the 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 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;

Example of QuickerSort Method

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

end program;

Example of Using the Sort Methods

- 125 -
Mynx Programming Language

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

- 126 -
Mynx Programming Language

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.

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;

Example of Accessing Static Methods and Attributes in a Program

Implicit Static Method Inclusion


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.

with mynx.core.*;

if(x < Int.MAXIMUM)


//do something
end if;

Example Explicit Static Method Inclusion

- 127 -
Mynx Programming Language

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:

with mynx.core.Int;

if(x < MAXIMUM)


//do something
end if;

Example of Implicit Static Method Inclusion

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 to External Static Method


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.

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

Example of Static Method Inclusion for Reference

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;

Example of Explicit Static Inclusion

- 128 -
Mynx Programming Language

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.

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

Example of Explicit Static Inclusion by Class Attribute

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);

Example of Static Method Inclusion

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);

Example of Explicit Static Method Inclusion

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.

- 129 -
Mynx Programming Language

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.

class methodEquiv is

public construct is to null;


public desturct is to null;

end class;

Example of Defining Method Equivalents

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;

Example of Full Method Definition

- 130 -
Mynx Programming Language

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).

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


//method body
end addition;

Example of Method Definition

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 to addition(this, augend);

Example of Method Equivalents for Default Parameters

Fully declared and defined with a wrapper method would be:

public Int addition(in Int augend) is

this.addition(this,augend);

end addition;

Example of Full Method Definition

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 to myClassMethod;

Example of Method Equivalent Definition with Static Method

- 131 -
Mynx Programming Language

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;

Example of Method Equivalent to Rename All Class Methods

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

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 Ordinal uint) is //Ordinal argument method


this.putln(uint);
end writeln;

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


this.putln(int);
end writeln;

Example of Equivalent Method Redefinition

- 132 -
Mynx Programming Language

Construction, Destruction, and Default Method of a Class


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

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. The general form of constructor definition is:

ACCESS construct PARAMETERS is

//code to initialize class

end construct;

Example of Constructor Syntax

- 133 -
Mynx Programming Language

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.

public construct is

null;

end construct;

Example of Default Constructor

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

public construct(in Int i) is

this`int = i;

end construct;

Example of Non-Default Constructor

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.

class childClass as parentClass is

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

public construct is to 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;

Example of Constructor Definition with Method Equivalent

- 134 -
Mynx Programming Language

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;

Example of Defining Multiple Constructors in a 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.

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)

Example of Constructor Declaration

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

Example of Invoking a Constructor

- 135 -
Mynx Programming Language

There are two special cases of invoking a constructor:

1. Invoking a default constructor.


2. Invoking a non-default 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.

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

Example of Invoking Default 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.

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;

Example of Not Invoking Default Constructor

In the creation expression involving null, the as creation operator is equivalent to the is assignment
operator, but only in the case of null. 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;

Example of Using Constructors of a Class

- 136 -
Mynx Programming Language

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;

Example of Syntax for a 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.

public destructor is to this.cleanup;


public destructor is to this.exitClass;

Example of Destructor Definition with Method Equivalent

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.

- 137 -
Mynx Programming Language

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;

Example of Destructor Invocation

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.

- 138 -
Mynx Programming Language

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.

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.

public default is to myMethod;


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

Example of Declaring a Default Method

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.

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

sum = zeroInt; //implicitly call get method

Example of Using an Default Method

- 139 -
Mynx Programming Language

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

sum = zeroInt;
sum.set(zeroInt);

Example of Operator Overload to Method Invocation

The instance zeroInt invokes the implicit default method of get, which gets the value of zeroInt.

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

Example of Default Method

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.

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

Example of Default Method for Output Stream

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”);

Example of Explicit Method for Output Stream

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.

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.

- 140 -
Mynx Programming Language

abstract class ATrove as Void is

public abstract VObject get;


public abstract void set(in VObject);

end class;

Example of Declaring an Incomplete Method

- 141 -
Mynx Programming Language

Implied Methods
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.

Rules for Implied Methods


An implied method is a method that is declared but not defined in the Mynx programming language.
There are four 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.
4. An implied method can be synchronized or asynchronous.

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.

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 Ordinal getSystemTime is implied;
public sync void myImplied is implied;
public async Int computeDelay is implied;

Examples of Implied Method Declaration

An implied method is similar to a regular class method, including that it can be thread-safe as a
synchronized method, or non thread-safe as a asynchronous method.

- 142 -
Mynx Programming Language

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;

Example of an Implied Method Implementation

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.

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);
}

Example of Java Interface for Implied Method

- 143 -
Mynx Programming Language

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
}
}

Example of Java Class for Implied Method

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);
}
}

Example of Java code for Mynx Class

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.

- 144 -
Mynx Programming Language

Implied Method Diagram


The diagram in the Uniform Modeling Language for the implied method and the related
implementing class and interface is:

Diagram of Implied Method

- 145 -
Mynx Programming Language

Obviate Methods
A visible, callable method can be obviate or removed from 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.

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.

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.

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(Ordinal, Ordinal) as void;
method getArgs(String[]) as void; //valid, array for method signature

Example of Method Obviation Declaration

- 146 -
Mynx Programming Language

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.

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.

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

Example of Obviate Method Declaration for Multiple Methods

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.

Inheritance with a Single Obviate Method


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.

class Cat as null is

//...remaining class methods, constructor

public void wagtail is


//…wagtail method body
end wagtail;

end class;

Example of Class Declaring a Method

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.

- 147 -
Mynx Programming Language

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;

Example of Declaring an Obviate Method for Single Method

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

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.

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;

Example Declaring an Obviate Method for Non-Existent Method

- 148 -
Mynx Programming Language

The class hierarchy for the various classes with an obviate method is:

Diagram of an Obviate Class

The Uniform Modeling Language diagram is not standard, it uses the symbol character ‘$’ to
indicate an obviate method.

- 149 -
Mynx Programming Language

Inheritance with Multiple Obviate Methods


The class ConsoleInput declares multiple methods by the name readln, which are overloaded for the
data type to be read.

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(Ordinal) is implied;

public void getln is to readln; //getln(Int) is readln(Int)

end class;

Example of Multiple Methods in a Class

The methods are implied, so implemented in the underlying implementation language.

class getConsoleInput as ConsoleInput is

method readln as all void;

end class;

Example of Declaring Multiple Method Obviation

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 is readln

gi.readln(input); //error! Invocation of obviate method in class


gi.getln(input); //ok, invokes non-obviate method of the class

end program;

Example of Method Obviation

- 150 -
Mynx Programming Language

Using a Class with an Obviate Method


Using the classes in a program illustrates the un-definition of an obviate method.

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;

Example Invoking a Class Method with Obviate Method

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.

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;

Example of Invalid Redefinition of an Obviate Method

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.

- 151 -
Mynx Programming Language

constant class myManxCat as manxCat is

//...remaining class methods, constructor


public void wagtail is to super.wagtail; //compile error:
//method not found!
end class;

Example of Invoking an Obviate Method Implicitly

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.

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.

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.

- 152 -
Mynx Programming Language

Operators and Operator Overloading


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.

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.

Operator Categories
There are seven categories for operators in Mynx:

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

- 153 -
Mynx Programming Language

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++

Example of Reference Assignment Operator

- 154 -
Mynx Programming Language

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);

Example of Creation Operator

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);

Example of Regular Assignment Operator

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;

Example of Declaration with Initial Value

- 155 -
Mynx Programming Language

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);

Example of Cast Assignment Operator

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.

- 156 -
Mynx Programming Language

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) );

Example of Addition Assignment Operator

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) );

Example of Subtraction Assignment Operator

- 157 -
Mynx Programming Language

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) );

Example of Multiplication Assignment Operator

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) );

Example of Division Assignment Operator

- 158 -
Mynx Programming Language

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) );

Example of Modulus Assignment Operator

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) );

Example of Bitwise And Assignment Operator

- 159 -
Mynx Programming Language

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) );

Example of Bitwise Inclusive Or Assignment Operator

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) );

Example of Bitwise Exclusive Or Assignment Operator

- 160 -
Mynx Programming Language

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) );

Example of Bitwise Shift Right Assignment Operator

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) );

Example of Bitwise Shift Left Assignment Operator

- 161 -
Mynx Programming Language

Cast Conversion

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

Cast Operator to
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.

data to Int //cast to Int class type


obj to VObject //cast to VObject class type

Example of 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

Example of Using a Cast Operator

- 162 -
Mynx Programming Language

Casting Class and Type


In the Mynx programming language, type and class are synonymous. A class is cast or converted to
another class or type using a type cast—the to operator. Mynx uses references for all object
instances, and a reference is an identifier or literal—but it has type or the class. Mynx is a strongly
typed programming language, so the universal rule is that for each reference the type must be the
same or type compatible with another reference. A type cast is valid for a reference of rank zero, a
scalar or the element of an array.

There are two kinds of type casts:

1. Upward – A cast to the super-class of a class.


2. Downward – A cast to the base or sub-class for a class.

Casting Type Rules


The three rules for Mynx type casting that are:

1. Cast to immediate (directly derived) super-class type (not further up the hierarchy) and not
to null.
2. Cast type to convert to other class type is explicit, not implicit or automatic.
3. Cast to own type or super-type, but not to sub-class class types.

Cast Type Span


A type cast span is the name of the rule that a type cast to a super-class is to an immediate super-
class, but not further up the hierarchy.

Cast Type Intent


The intention of a type cast is always explicit--there is no implicit conversion to another type. A class
must be designed with the type intention of the class.

Cast Type Limit


A type cast cannot cast a class to a sub-class, a class that is derived from the base class. It is possible
to cast a class that was upward cast to a super-class type to the original base type.

- 163 -
Mynx Programming Language

Casting Conversion Examples


An illustrative example of cast conversion involves defining three classes with specific super, base,
and sub class relationship. The operation demonstrates the valid and invalid cast conversion
operations.

class superClass as null is


public construct is null;
end class;

class baseClass as superClass is


public construct is
super.superClass;
end construct;
end class;

class subClass as baseClass is


public construct is
super.baseClass;
end construct;
end class;

Example Definition of Cast Class Types

The definition of three classes for a super, base, and sub-class that are also class types, using those
defined types must follow the rules of class type casts.

var superClass sup to default;


var baseClass bas to default;
var subClass sub to default;

var baseClass cls to default;

//error-type intent incompatible - need explicit type cast


sup is cls;

//valid type-compatible to super (super-class)


sup is cls to superClass;

//valid type-compatible to base (sub-class)


cls is sup to baseClass;

//valid type-compatible
cls is bas;

//error-type span superClass not immediate super-class


sup is sub to superClass;

//error-type limit, superClass not originally subClass


sub is sup to subClass;

Example Using Type Cast of Class Types

- 164 -
Mynx Programming Language

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;

Example of Logical Not Operator

- 165 -
Mynx Programming Language

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.

if( x > 0 & y < 0)


doSomething;
end if;

Example of Logical And Operator

var Int y to 0XFFFF;


var Int x to 0XFFFF;

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

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

Example of Logical Bitwise And Operator

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;

Example of Logical And Operator

- 166 -
Mynx Programming Language

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.

if( x > 0 | y < 0)


doSomething;
end if;

Example of Logical Or Operator

var Int y to 0XFFFF;


var Int x to 0XFFFF;

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

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

Example of Logical Bitwise Or Operator

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;

Example of Logical Inclusive Or Operator

- 167 -
Mynx Programming Language

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;

Example of Bitwise Complement Operator

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

Example of Bitwise Shift Left Operator

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

Example of Bitwise Shift Right Operator

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;

Example of Logical Exclusive Or Operator

- 168 -
Mynx Programming Language

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;

Example of Equality Operator

- 169 -
Mynx Programming Language

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.

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;

Example of Inequality Operator

- 170 -
Mynx Programming Language

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;

Example of In instance-of Class Operator

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;

Example of in Instance Operator

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 a lesser-than ordering is an ordering feature of the class which
defines it. The core Mynx types such as String, Char, Int, Real, Float, Ordinal, Byte, UnsignedByte
have the relational lesser than operator and the ordering defined already.

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

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

Example of Less Than Operator

- 171 -
Mynx Programming Language

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 ordering is an ordering feature of the class that
defines it. The core Mynx types such as String, Char, Int, Real, Float, Ordinal, 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;

Example of Greater Than Operator

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, Ordinal, 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;

Example of Greater Than Equal Operator

- 172 -
Mynx Programming Language

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, Ordinal, 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.

- 173 -
Mynx Programming Language

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!!!”);

Example of Insertion Stream Operator

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);

Example of Extraction Stream Operator

with mynx.core.IOStream;

var IOStream IO to default;

IO <<< x <<< eoln;


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

Example of Overloaded Stream Operators

- 174 -
Mynx Programming Language

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));

Example of Addition Operator

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));

Example of Subtraction Operator

- 175 -
Mynx Programming Language

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));

Example of Division Operator

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));

Example of Modulus Operator

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));

Example of Multiplication Operator

- 176 -
Mynx Programming Language

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));

Example of Exponentiation Operator

Increment Operator ++
The increment operator ++ is only a post-operator, there is no pre-increment operator.

var Int i to 0;
i++;

//similarly
i.inc;

Example of Post-Increment Operator

Decrement Operator --
The decrement operator -- is a post-operator, there is no pre-decrement operator.

var Int i to 0;
i--;

//similarly
i.dec;

Example of Post-Decrement Operator

- 177 -
Mynx Programming Language

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

Example of Method Access or Invocation

- 178 -
Mynx Programming Language

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.

this`MAXIMUM
super`var
ex`value_
getIt
x_

Example of Attribute Access

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.

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

Example of Array Access

- 179 -
Mynx Programming Language

Operator Precedence
There are 13-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

- 180 -
Mynx Programming Language

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.

- 181 -
Mynx Programming Language

Rules for Operator Overloading


Operator overloading is not possible for all methods and operators. There are ten rules for the
overloading of operators in Mynx:

1. The method is public in a class.


2. The method is a class method, not a constructor, destructor, or default method.
3. The class is non-generic.
4. The method is an actual method in the class.
5. The method takes zero or one parameter.
6. The method is a function.
7. The operator is valid to overload.
8. The operator is not a constant overload in a super-class.
9. A constant operator overload in a super-class is referenced in a sub-class.
10. The method is not obviated in the class.

- 182 -
Mynx Programming Language

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;

Example of Operator Overloading with Constant 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;

Example of Operator Overload with Default

- 183 -
Mynx Programming Language

class Group as Void is

overload default + as associative;


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

end class;

class subGroup2 as Group is

//re-overload operator with new method as constant


overload constant + as transitive;

//reference overloaded operator in parent


overload constant in Group is * as commutative;

overload default - as relative;

end class;

Example of Operator Overload from Default to Constant

- 184 -
Mynx Programming Language

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

- 185 -
Mynx Programming Language

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

- 186 -
Mynx Programming Language

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

Diagram of Hierarchy of Operators for Expression

- 187 -
Mynx Programming Language

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

Diagram of Hierarchy of Operators with Methods for Expression

- 188 -
Mynx Programming Language

Appendices

- 189 -
Mynx Programming Language

- 190 -
Mynx Programming Language

Appendix - Mynx Grammar

Header Syntax
START := HEADER (CLASSES | PROGRAM)
*
HEADER := [MODULE](WITH)
MODULE := module ( default | NAME ) ‘;’
WITH := with NAME [‘.’ ‘*’] ‘;’

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

Class Methods
CLASS_METHOD := METHOD_HEADER [is (METHOD_EQUIV| implied | METHOD_BODY) ] ‘;’
METHOD_EQUIV := to (null | METHOD_EQUAL)
METHOD_HEADER := ACCESS [SYNC][METHOD_MODE][METHOD_TYPE] ID [ARGS][TRAPS][SCOPE]
SYNC := async | sync
METHOD_MODE := abstract | constant | covariant | default | singular | static | virtual
METHOD_TYPE := (ID | generic) [DIMLIST] | 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] | this ) ID [ARGLIST]
SCOPE := (in | out) for (all | null | IDLIST)
METHOD_BODY := STATEMENTS end 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) ‘;’

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

Class Overload
CLASS_OVERLOAD := overload [constant | default] [in ID is] OPERATOR as ID ‘;’

Class Method Obviate


CLASS_OBVIATE := method ID [PARAMLIST] as [all] void ‘;’
*
PARAMLIST := PARAM (‘,’ PARAM)
PARAM := ID [PARAMDIM]
PARAMDIM := ‘[‘ [STARLIST] ‘]’

- 191 -
Mynx Programming Language

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

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 | 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 ID [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 ‘)’

- 192 -
Mynx Programming Language

Expression Statements
EXPRESSIONSTATEMENT := ASSIGN | var DECLARE
DECLARE := ID [DIMLIST] IDLIST [to INIT]
*
IDLIST := ID ( ‘,’ ID )
INIT := default | null | INITLIST | [‘(‘] EXPRLIST [‘)’]
INITLIST := ‘{‘ EXPRLIST | INDEXLIST ‘}’
*
INDEXITEM := STARLIST | (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 ‘)’

Lexical Elements
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

- 193 -
Mynx Programming Language

Comments
* *
COMMENT := ‘//’ (UNICODECHAR) (‘\n’ | ‘\r’ | ‘\n’ ‘\r’) | ‘!!’ (UNICODECHAR) ‘!!’

- 194 -
Mynx Programming Language

Appendix - Mynx File Types and Tools


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

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.

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.

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.

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.

- 195 -
Mynx Programming Language

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.

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.

- 196 -
Mynx Programming Language

Appendix – GNU Free Documentation License


GNU Free Documentation License
Version 1.2, November 2002

Copyright (C) 2000, 2001, 2002 Free Software Foundation, Inc.


51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA

Everyone is permitted to copy and distribute verbatim copies


of this license document, but changing it is not allowed.

0. PREAMBLE

The purpose of this License is to make a manual, textbook, or other functional and useful document
"free" in the sense of freedom: to assure everyone the effective freedom to copy and redistribute it,
with or without modifying it, either commercially or noncommercially. Secondarily, this License
preserves for the author and publisher a way to get credit for their work, while not being considered
responsible for modifications made by others.

This License is a kind of "copyleft", which means that derivative works of the document must
themselves be free in the same sense. It complements the GNU General Public License, which is a
copyleft license designed for free software.

We have designed this License in order to use it for manuals for free software, because free software
needs free documentation: a free program should come with manuals providing the same freedoms
that the software does. But this License is not limited to software manuals; it can be used for any
textual work, regardless of subject matter or whether it is published as a printed book. We
recommend this License principally for works whose purpose is instruction or reference.

1. APPLICABILITY AND DEFINITIONS

This License applies to any manual or other work, in any medium, that contains a notice placed by
the copyright holder saying it can be distributed under the terms of this License. Such a notice
grants a world-wide, royalty-free license, unlimited in duration, to use that work under the
conditions stated herein. The "Document", below, refers to any such manual or work. Any
member of the public is a licensee, and is addressed as "you". You accept the license if you copy,
modify or distribute the work in a way requiring permission under copyright law.

A "Modified Version" of the Document means any work containing the Document or a portion of
it, either copied verbatim, or with modifications and/or translated into another language.

A "Secondary Section" is a named appendix or a front-matter section of the Document that deals
exclusively with the relationship of the publishers or authors of the Document to the Document's
overall subject (or to related matters) and contains nothing that could fall directly within that overall
subject. (Thus, if the Document is in part a textbook of mathematics, a Secondary Section may not
explain any mathematics.) The relationship could be a matter of historical connection with the

- 197 -
Mynx Programming Language

subject or with related matters, or of legal, commercial, philosophical, ethical or political position
regarding them.

The "Invariant Sections" are certain Secondary Sections whose titles are designated, as being those
of Invariant Sections, in the notice that says that the Document is released under this License. If a
section does not fit the above definition of Secondary then it is not allowed to be designated as
Invariant. The Document may contain zero Invariant Sections. If the Document does not identify
any Invariant Sections then there are none.

The "Cover Texts" are certain short passages of text that are listed, as Front-Cover Texts or Back-
Cover Texts, in the notice that says that the Document is released under this License. A Front-
Cover Text may be at most 5 words, and a Back-Cover Text may be at most 25 words.

A "Transparent" copy of the Document means a machine-readable copy, represented in a format


whose specification is available to the general public, that is suitable for revising the document
straightforwardly with generic text editors or (for images composed of pixels) generic paint
programs or (for drawings) some widely available drawing editor, and that is suitable for input to
text formatters or for automatic translation to a variety of formats suitable for input to text
formatters. A copy made in an otherwise Transparent file format whose markup, or absence of
markup, has been arranged to thwart or discourage subsequent modification by readers is not
Transparent. An image format is not Transparent if used for any substantial amount of text. A copy
that is not "Transparent" is called "Opaque".

Examples of suitable formats for Transparent copies include plain ASCII without markup, Texinfo
input format, LaTeX input format, SGML or XML using a publicly available DTD, and standard-
conforming simple HTML, PostScript or PDF designed for human modification. Examples of
transparent image formats include PNG, XCF and JPG. Opaque formats include proprietary
formats that can be read and edited only by proprietary word processors, SGML or XML for which
the DTD and/or processing tools are not generally available, and the machine-generated HTML,
PostScript or PDF produced by some word processors for output purposes only.

The "Title Page" means, for a printed book, the title page itself, plus such following pages as are
needed to hold, legibly, the material this License requires to appear in the title page. For works in
formats which do not have any title page as such, "Title Page" means the text near the most
prominent appearance of the work's title, preceding the beginning of the body of the text.

A section "Entitled XYZ" means a named subunit of the Document whose title either is precisely
XYZ or contains XYZ in parentheses following text that translates XYZ in another language. (Here
XYZ stands for a specific section name mentioned below, such as "Acknowledgements",
"Dedications", "Endorsements", or "History".) To "Preserve the Title" of such a section when you
modify the Document means that it remains a section "Entitled XYZ" according to this definition.

The Document may include Warranty Disclaimers next to the notice which states that this License
applies to the Document. These Warranty Disclaimers are considered to be included by reference in
this License, but only as regards disclaiming warranties: any other implication that these Warranty
Disclaimers may have is void and has no effect on the meaning of this License.

- 198 -
Mynx Programming Language

2. VERBATIM COPYING

You may copy and distribute the Document in any medium, either commercially or
noncommercially, provided that this License, the copyright notices, and the license notice saying this
License applies to the Document are reproduced in all copies, and that you add no other conditions
whatsoever to those of this License. You may not use technical measures to obstruct or control the
reading or further copying of the copies you make or distribute. However, you may accept
compensation in exchange for copies. If you distribute a large enough number of copies you must
also follow the conditions in section 3.

You may also lend copies, under the same conditions stated above, and you may publicly display
copies.

3. COPYING IN QUANTITY

If you publish printed copies (or copies in media that commonly have printed covers) of the
Document, numbering more than 100, and the Document's license notice requires Cover Texts, you
must enclose the copies in covers that carry, clearly and legibly, all these Cover Texts: Front-Cover
Texts on the front cover, and Back-Cover Texts on the back cover. Both covers must also clearly
and legibly identify you as the publisher of these copies. The front cover must present the full title
with all words of the title equally prominent and visible. You may add other material on the covers
in addition.

Copying with changes limited to the covers, as long as they preserve the title of the Document and
satisfy these conditions, can be treated as verbatim copying in other respects.

If the required texts for either cover are too voluminous to fit legibly, you should put the first ones
listed (as many as fit reasonably) on the actual cover, and continue the rest onto adjacent pages.

If you publish or distribute Opaque copies of the Document numbering more than 100, you must
either include a machine-readable Transparent copy along with each Opaque copy, or state in or
with each Opaque copy a computer-network location from which the general network-using public
has access to download using public-standard network protocols a complete Transparent copy of
the Document, free of added material. If you use the latter option, you must take reasonably prudent
steps, when you begin distribution of Opaque copies in quantity, to ensure that this Transparent
copy will remain thus accessible at the stated location until at least one year after the last time you
distribute an Opaque copy (directly or through your agents or retailers) of that edition to the public.

It is requested, but not required, that you contact the authors of the Document well before
redistributing any large number of copies, to give them a chance to provide you with an updated
version of the Document.

4. MODIFICATIONS

You may copy and distribute a Modified Version of the Document under the conditions of sections
2 and 3 above, provided that you release the Modified Version under precisely this License, with the
Modified Version filling the role of the Document, thus licensing distribution and modification of

- 199 -
Mynx Programming Language

the Modified Version to whoever possesses a copy of it. In addition, you must do these things in
the Modified Version:
A. Use in the Title Page (and on the covers, if any) a title distinct from that of the Document,
and from those of previous versions (which should, if there were any, be listed in the History
section of the Document). You may use the same title as a previous version if the original
publisher of that version gives permission.

B. List on the Title Page, as authors, one or more persons or entities responsible for
authorship of the modifications in the Modified Version, together with at least five of the
principal authors of the Document (all of its principal authors, if it has fewer than five),
unless they release you from this requirement.

C. State on the Title page the name of the publisher of the Modified Version, as the publisher.

D. Preserve all the copyright notices of the Document.

E. Add an appropriate copyright notice for your modifications adjacent to the other copyright
notices.

F. Include, immediately after the copyright notices, a license notice giving the public permission
to use the Modified Version under the terms of this License, in the form shown in the
Addendum below.

G. Preserve in that license notice the full lists of Invariant Sections and required Cover Texts
given in the Document's license notice.

H. Include an unaltered copy of this License.

I. Preserve the section Entitled "History", Preserve its Title, and add to it an item stating at
least the title, year, new authors, and publisher of the Modified Version as given on the Title
Page. If there is no section Entitled "History" in the Document, create one stating the title,
year, authors, and publisher of the Document as given on its Title Page, then add an item
describing the Modified Version as stated in the previous sentence.

J. Preserve the network location, if any, given in the Document for public access to a
Transparent copy of the Document, and likewise the network locations given in the
Document for previous versions it was based on. These may be placed in the "History"
section. You may omit a network location for a work that was published at least four years
before the Document itself, or if the original publisher of the version it refers to gives
permission.

K. For any section Entitled "Acknowledgements" or "Dedications", Preserve the Title of the
section, and preserve in the section all the substance and tone of each of the contributor
acknowledgements and/or dedications given therein.

L. Preserve all the Invariant Sections of the Document, unaltered in their text and in their titles.
Section numbers or the equivalent are not considered part of the section titles.

- 200 -
Mynx Programming Language

M. Delete any section Entitled "Endorsements". Such a section may not be included in the
Modified Version.
N. Do not retitle any existing section to be Entitled "Endorsements" or to conflict in title with
any Invariant Section.

O. Preserve any Warranty Disclaimers.

If the Modified Version includes new front-matter sections or appendices that qualify as Secondary
Sections and contain no material copied from the Document, you may at your option designate
some or all of these sections as invariant. To do this, add their titles to the list of Invariant Sections
in the Modified Version's license notice. These titles must be distinct from any other section titles.

You may add a section Entitled "Endorsements", provided it contains nothing but endorsements of
your Modified Version by various parties--for example, statements of peer review or that the text
has been approved by an organization as the authoritative definition of a standard.

You may add a passage of up to five words as a Front-Cover Text, and a passage of up to 25 words
as a Back-Cover Text, to the end of the list of Cover Texts in the Modified Version. Only one
passage of Front-Cover Text and one of Back-Cover Text may be added by (or through
arrangements made by) any one entity. If the Document already includes a cover text for the same
cover, previously added by you or by arrangement made by the same entity you are acting on behalf
of, you may not add another; but you may replace the old one, on explicit permission from the
previous publisher that added the old one.

The author(s) and publisher(s) of the Document do not by this License give permission to use their
names for publicity for or to assert or imply endorsement of any Modified Version.

5. COMBINING DOCUMENTS

You may combine the Document with other documents released under this License, under the
terms defined in section 4 above for modified versions, provided that you include in the
combination all of the Invariant Sections of all of the original documents, unmodified, and list them
all as Invariant Sections of your combined work in its license notice, and that you preserve all their
Warranty Disclaimers.

The combined work need only contain one copy of this License, and multiple identical Invariant
Sections may be replaced with a single copy. If there are multiple Invariant Sections with the same
name but different contents, make the title of each such section unique by adding at the end of it, in
parentheses, the name of the original author or publisher of that section if known, or else a unique
number. Make the same adjustment to the section titles in the list of Invariant Sections in the license
notice of the combined work.

In the combination, you must combine any sections Entitled "History" in the various original
documents, forming one section Entitled "History"; likewise combine any sections Entitled
"Acknowledgements", and any sections Entitled "Dedications". You must delete all sections
Entitled "Endorsements".

- 201 -
Mynx Programming Language

6. COLLECTIONS OF DOCUMENTS

You may make a collection consisting of the Document and other documents released under this
License, and replace the individual copies of this License in the various documents with a single
copy that is included in the collection, provided that you follow the rules of this License for
verbatim copying of each of the documents in all other respects.

You may extract a single document from such a collection, and distribute it individually under this
License, provided you insert a copy of this License into the extracted document, and follow this
License in all other respects regarding verbatim copying of that document.

7. AGGREGATION WITH INDEPENDENT WORKS

A compilation of the Document or its derivatives with other separate and independent documents
or works, in or on a volume of a storage or distribution medium, is called an "aggregate" if the
copyright resulting from the compilation is not used to limit the legal rights of the compilation's
users beyond what the individual works permit. When the Document is included in an aggregate,
this License does not apply to the other works in the aggregate which are not themselves derivative
works of the Document.

If the Cover Text requirement of section 3 is applicable to these copies of the Document, then if the
Document is less than one half of the entire aggregate, the Document's Cover Texts may be placed
on covers that bracket the Document within the aggregate, or the electronic equivalent of covers if
the Document is in electronic form. Otherwise they must appear on printed covers that bracket the
whole aggregate.

8. TRANSLATION

Translation is considered a kind of modification, so you may distribute translations of the


Document under the terms of section 4. Replacing Invariant Sections with translations requires
special permission from their copyright holders, but you may include translations of some or all
Invariant Sections in addition to the original versions of these Invariant Sections. You may include a
translation of this License, and all the license notices in the Document, and any Warranty
Disclaimers, provided that you also include the original English version of this License and the
original versions of those notices and disclaimers. In case of a disagreement between the translation
and the original version of this License or a notice or disclaimer, the original version will prevail.

If a section in the Document is Entitled "Acknowledgements", "Dedications", or "History", the


requirement (section 4) to Preserve its Title (section 1) will typically require changing the actual title.

9. TERMINATION

You may not copy, modify, sublicense, or distribute the Document except as expressly provided for
under this License. Any other attempt to copy, modify, sublicense or distribute the Document is
void, and will automatically terminate your rights under this License. However, parties who have

- 202 -
Mynx Programming Language

received copies, or rights, from you under this License will not have their licenses terminated so long
as such parties remain in full compliance.
10. FUTURE REVISIONS OF THIS LICENSE

The Free Software Foundation may publish new, revised versions of the GNU Free Documentation
License from time to time. Such new versions will be similar in spirit to the present version, but
may differ in detail to address new problems or concerns. See http://www.gnu.org/copyleft/.

Each version of the License is given a distinguishing version number. If the Document specifies that
a particular numbered version of this License "or any later version" applies to it, you have the option
of following the terms and conditions either of that specified version or of any later version that has
been published (not as a draft) by the Free Software Foundation. If the Document does not specify
a version number of this License, you may choose any version ever published (not as a draft) by the
Free Software Foundation.

- 203 -
Mynx Programming Language

- 204 -
Mynx Programming Language

Epilog

- 205 -
Mynx Programming Language

- 206 -
Mynx Programming Language

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. (1974). On the Design of Programming Languages. IFIP Congress,


pp. 386-393.

Wirth, Niklaus (1977). What Can We Do about the Unnecessary Diversity of


Notation for Syntactic Definitions? Communications of ACM, 20(11), pp. 822-823.

- 207 -
Mynx Programming Language

- 208 -
Mynx Programming Language

Credits
Credit for contributions, ideas, and thoughts in the design and formulation of the Mynx
programming language is given to:

1. William F. Gilreath – Programming language creator and designer.

2. Philip A. Laplante – Contributor to programming language.

- 209 -
Mynx Programming Language

- 210 -
Mynx Programming Language

Indices

- 211 -
Mynx Programming Language

- 212 -
Mynx Programming Language

Index of Diagrams
DIAGRAM OF SINGLE INHERITANCE ............................................................................................................83
DIAGRAM OF UML CLASS DIAGRAM OF MULTIPLE VIRTUAL INHERITANCE ........................................85
DIAGRAM OF UML CLASS DIAGRAM OF MULTIPLE DISJOINT INHERITANCE .......................................86
DIAGRAM OF IMPLIED METHOD .................................................................................................................145
DIAGRAM OF AN OBVIATE CLASS ...............................................................................................................149
DIAGRAM OF HIERARCHY OF OPERATORS FOR EXPRESSION .................................................................187
DIAGRAM OF HIERARCHY OF OPERATORS WITH METHODS FOR EXPRESSION ...................................188

- 213 -
Mynx Programming Language

- 214 -
Mynx Programming Language

Index of Examples
EXAMPLE OF IDENTIFIERS .............................................................................................................................27
EXAMPLE OF UNICODE LITERALS .................................................................................................................28
EXAMPLE OF SYMBOL LITERALS ....................................................................................................................28
EXAMPLE OF NUMERIC LITERALS .................................................................................................................29
EXAMPLE OF USING META STRINGS .............................................................................................................31
EXAMPLE OF MYNX SINGLE-LINE COMMENTS ..........................................................................................32
EXAMPLE OF VARIABLE DECLARATION EXPRESSION ...............................................................................38
EXAMPLE OF POSTFIX EXPRESSION ..............................................................................................................39
EXAMPLE OF ASSIGN EXPRESSION ...............................................................................................................39
EXAMPLE OF CREATION EXPRESSION ..........................................................................................................40
EXAMPLE OF INPUT-OUTPUT EXPRESSION .................................................................................................40
EXAMPLE OF ATTRIBUTE ACCESS SUB-EXPRESSION ..................................................................................40
EXAMPLE OF METHOD ACCESS SUB-EXPRESSION .....................................................................................41
EXAMPLE OF METHOD ACCESS BY DEFAULT SUB-EXPRESSION ..............................................................41
EXAMPLE OF ARRAY ACCESS SUB-EXPRESSION ..........................................................................................41
EXAMPLE OF MULTIPLE ACCESS EXPRESSION STATEMENT .....................................................................41
EXAMPLE OF NULL STATEMENT ...................................................................................................................42
EXAMPLE OF ASSERT STATEMENTS ..............................................................................................................42
EXAMPLE OF FLAG STATEMENT ....................................................................................................................43
EXAMPLE OF TRY STATEMENT ......................................................................................................................43
EXAMPLE OF TRY STATEMENT WITH ELSE CLAUSE ...................................................................................43
EXAMPLE OF INVALID TRY STATEMENT WITH FLOW OF CONTROL USING RETURN ............................44
EXAMPLE OF INVALID TRY STATEMENT WITH FLOW OF CONTROL USING NEXT ................................44
EXAMPLE OF EXIT STATEMENT ....................................................................................................................45
EXAMPLE OF EXIT STATEMENT ....................................................................................................................45
EXAMPLE OF NEXT STATEMENT ...................................................................................................................46
EXAMPLE OF PREFIX IF STATEMENT ............................................................................................................46
EXAMPLE OF RETURN STATEMENT ..............................................................................................................47
EXAMPLE OF FOR STATEMENT OVER FIXED RANGE .................................................................................48
EXAMPLE OF FOR STATEMENT OVER RANGE .............................................................................................48
EXAMPLE OF FOR STATEMENT OVER AN ARRAY ........................................................................................49
EXAMPLE OF A FOR STATEMENT WITH AN EXPLICIT INTEGRAL TYPE ...................................................49
EXAMPLE OF A FOR STATEMENT WITH AN EXPLICIT INTEGRAL TYPE ...................................................49
EXAMPLE OF LOOP STATEMENT ...................................................................................................................50
EXAMPLE OF LOOP STATEMENT WITH PREFIX IF STATEMENT ................................................................50
EXAMPLE OF LOOP STATEMENT WITH EXIT IN CASE STATEMENT .........................................................50
EXAMPLE OF UNTIL STATEMENT ..................................................................................................................51
EXAMPLE OF WHILE STATEMENT .................................................................................................................51
EXAMPLE OF REPEAT STATEMENT WITH WHILE CONDITION .................................................................52
EXAMPLE OF REPEAT STATEMENT WITH UNTIL CONDITION ..................................................................52
EXAMPLE OF REPEAT STATEMENT WITH PREFIX-IF AND NESTING........................................................53
EXAMPLE OF CASE STATEMENT ....................................................................................................................54
EXAMPLE OF DELIMITED LIST OF VALUES WITH A CASE STATEMENT ...................................................54
EXAMPLE OF CASE STATEMENT WITH STRING LITERAL ...........................................................................55
EXAMPLE OF EQUIVALENT IF STATEMENTS ...............................................................................................55

- 215 -
Mynx Programming Language

EXAMPLE OF EQUIVALENT IF STATEMENT WITH ELSE-IF ELIF BLOCK .................................................56


EXAMPLE OF IF STATEMENT WITHOUT ELSE BLOCK ................................................................................56
EXAMPLE OF AN IF STATEMENT WITH ALL BRANCHES OF THE IF STATEMENT ....................................56
EXAMPLE OF MUTEX STATEMENT SYNTAX .................................................................................................57
EXAMPLE MUTEX EXPRESSION WITH THIS CLASS REFERENCE ...............................................................57
EXAMPLE OF MUTEX EXPRESSION USING LOCAL VARIABLE ...................................................................58
EXAMPLE OF NAMESPACE DECLARATION ...................................................................................................59
EXAMPLE OF INVALID NAMESPACE DECLARATION ..................................................................................59
EXAMPLE OF DEFAULT NAMESPACE DECLARATIONS ...............................................................................59
EXAMPLE OF ABSOLUTE NAMESPACE INCLUSION .....................................................................................60
EXAMPLE OF RELATIVE NAMESPACE INCLUSION ......................................................................................60
EXAMPLE OF HIERARCHICAL SUB-NAMESPACES ........................................................................................61
EXAMPLE OF NAMESPACE INCLUSION FROM HIERARCHICAL NAMESPACE ...........................................61
EXAMPLE OF SUB-NAMESPACE INCLUSION FROM HIERARCHICAL NAMESPACE ...................................61
EXAMPLE OF INVALID NAMESPACE INCLUSION .........................................................................................61
EXAMPLE OF NON-EXISTENT NAMESPACE INCLUSION ............................................................................62
EXAMPLE OF DECLARING A CLASS WITH DEFAULT NAMESPACE ............................................................63
EXAMPLE OF USING STATIC INCLUDE CLASS IN DEFAULT NAMESPACE ................................................63
EXAMPLE OF INFINITE ARRAY DECLARATION ...........................................................................................64
EXAMPLE OF BOUNDED ARRAY DECLARATION .........................................................................................64
EXAMPLE OF DEFINITE ARRAY DECLARATION ..........................................................................................65
EXAMPLE OF INDEFINITE ARRAY DECLARATION ......................................................................................65
EXAMPLE OF CREATING AN ARRAY WITH IMPLICIT AND EXPLICIT POSITION INDEX .........................66
EXAMPLE OF CREATING AN ARRAY WITH EXPLICIT POSITION INDEX ...................................................67
EXAMPLE OF CREATING AN ARRAY WITH EXPLICIT INTEGER INDEX ....................................................67
EXAMPLE OF CREATING AN ARRAY INITIALIZATION BY CONSTRUCTOR ...............................................67
EXAMPLE OF CREATING AN ARRAY USING A DEFAULT CONSTRUCTOR .................................................68
EXAMPLE OF NULL IN THE DECLARATION OF AN ARRAY ........................................................................68
EXAMPLE OF DECLARING AN ARRAY BUT CREATION AND INITIALIZATION LATER ............................68
EXAMPLE OF DECLARING AN ARRAY AND THEN CREATING A NEW ARRAY .........................................69
EXAMPLE OF USING AN ELEMENT OF AN ARRAY ......................................................................................69
EXAMPLE OF USING AN ARRAY AS AN OBJECT ...........................................................................................70
EXAMPLE OF PASSING AN ARRAY AS A PARAMETER ..................................................................................70
EXAMPLE OF USING THE ARRAY AN THE EXISTING METHOD.................................................................70
EXAMPLE OF AN INFINITE ARRAY OF RANK ONE AS PARAMETER TO METHOD ..................................71
EXAMPLE OF DECLARATION OF TRAPS IN A METHOD ..............................................................................72
EXAMPLE OF FLAG STATEMENTS ..................................................................................................................73
EXAMPLE OF PROPAGATING A TRAP ............................................................................................................73
EXAMPLE OF PROGRAM HEADER .................................................................................................................77
EXAMPLE OF BODYLESS PROGRAM HEADER ..............................................................................................77
EXAMPLE OF CLASS HEADER .........................................................................................................................78
EXAMPLE OF NULL INHERITANCE ................................................................................................................82
EXAMPLE OF IMPLICIT NULL INHERITANCE ...............................................................................................82
EXAMPLE OF SINGLE INHERITANCE .............................................................................................................83
EXAMPLE OF MULTIPLE VIRTUAL INHERITANCE .......................................................................................84
EXAMPLE OF MULTIPLE DISJOINT INHERITANCE ......................................................................................86
EXAMPLE OF SHADOWING A CLASS ATTRIBUTE IN INHERITANCE ..........................................................88
EXAMPLE OF METHOD OVERRIDING WITH INHERITANCE.......................................................................89

- 216 -
Mynx Programming Language

EXAMPLE OF COVARIANT METHOD OVERRIDE WITH IMPLIED METHOD .............................................91


EXAMPLE OF COVARIANT METHOD OVERRIDE WITH VIRTUAL CLASS ..................................................91
EXAMPLE OF OVERLOADING WITHIN THE CLASS AND SUB-CLASS .........................................................92
EXAMPLE OF OPERATOR OVERLOADING WITHIN THE CLASS AND SUB-CLASS ....................................93
EXAMPLE OF ACCESSING ATTRIBUTE OVER METHOD ..............................................................................94
EXAMPLE OF SUPER CLASS PARENT DEFINITION ......................................................................................95
EXAMPLE OF SUPER CLASS REFERENCE WITH INHERITANCE ..................................................................95
EXAMPLE OF CLASS WITH THIS REFERENCE PREFIX .................................................................................96
EXAMPLE OF CLASS WITH THIS REFERENCE AS VARIABLE .......................................................................96
EXAMPLE OF CLASS WITH INCREMENT METHOD USING SELF PREFIX ...................................................97
EXAMPLE OF GENERIC CLASS ATTRIBUTES.................................................................................................98
EXAMPLE OF GENERIC CLASS METHODS ....................................................................................................99
EXAMPLE OPERATOR OVERLOAD IN A GENERIC CLASS ...........................................................................99
EXAMPLE OF A DEFAULT METHOD IN A GENERIC CLASS ......................................................................100
EXAMPLE OF A GENERIC CLASS INHERITANCE OF A GENERIC CLASS ..................................................101
EXAMPLE OF GENERIC CLASS INHERITING MULTIPLE DISJOINT ABSTRACT CLASSES.......................102
EXAMPLE OF A GENERIC CLASS INHERITING MULTIPLE VIRTUAL CLASSES .......................................103
EXAMPLE OF LOCAL INSTANTIATION OF A GENERIC CLASS TO TYPE STRING ...................................104
EXAMPLE OF GLOBAL INSTANTIATION OF A GENERIC CLASS TO TYPE STRING ................................105
EXAMPLE OF LOCAL AND GLOBAL INSTANTIATION INSTANCES WITHIN A CLASS .............................107
EXAMPLE OF INITIAL VALUES IN ATTRIBUTES .........................................................................................112
EXAMPLE OF PROGRAM ATTRIBUTES .........................................................................................................113
EXAMPLE OF CLASS ATTRIBUTES ................................................................................................................113
EXAMPLE OF PROGRAM METHOD RETURN TYPES ..................................................................................114
EXAMPLE OF CLASS METHOD RETURN TYPES ..........................................................................................114
EXAMPLE OF CLASS METHOD USING IN PARAMETER MODE .................................................................116
EXAMPLE OF USING THE DEFINED METHOD WITH IN PARAMETER ....................................................116
EXAMPLE OF DEFINING A METHOD WITH OUT PARAMETER ................................................................116
EXAMPLE OF USING THE DEFINED METHOD WITH OUT PARAMETER ................................................117
EXAMPLE OF DEFINING A METHOD WITH VAR PARAMETER .................................................................117
EXAMPLE OF USING THE DEFINED METHOD WITH VAR PARAMETER .................................................117
EXAMPLE OF DEFINING A METHOD AND USING WITH SERIES PARAMETER .......................................118
EXAMPLE OF USING A METHOD WITH SERIES PARAMETER INCORRECTLY .........................................119
EXAMPLE OF DECLARING TRAPS IN A METHOD ......................................................................................120
EXAMPLE OF DECLARING METHOD SCOPE ..............................................................................................120
EXAMPLE OF DECLARING PROGRAM METHOD HEADERS......................................................................120
EXAMPLE OF DECLARING A METHOD RETURN TYPE .............................................................................122
EXAMPLE OF DECLARING A CLASS METHOD HEADER ...........................................................................122
EXAMPLE OF AN UNDEFINED CLASS METHOD HEADER ........................................................................123
EXAMPLE OF OVERRIDING A STATIC METHOD IN MULTIPLE CLASSES ................................................124
EXAMPLE OF QUICKERSORT METHOD ......................................................................................................125
EXAMPLE OF USING THE SORT METHODS ................................................................................................125
EXAMPLE OF ACCESSING STATIC METHODS AND ATTRIBUTES IN A PROGRAM ..................................127
EXAMPLE EXPLICIT STATIC METHOD INCLUSION ...................................................................................127
EXAMPLE OF IMPLICIT STATIC METHOD INCLUSION...............................................................................128
EXAMPLE OF STATIC METHOD INCLUSION FOR REFERENCE .................................................................128
EXAMPLE OF EXPLICIT STATIC INCLUSION ...............................................................................................128
EXAMPLE OF EXPLICIT STATIC INCLUSION BY CLASS ATTRIBUTE .........................................................129

- 217 -
Mynx Programming Language

EXAMPLE OF STATIC METHOD INCLUSION ...............................................................................................129


EXAMPLE OF EXPLICIT STATIC METHOD INCLUSION ..............................................................................129
EXAMPLE OF DEFINING METHOD EQUIVALENTS ...................................................................................130
EXAMPLE OF FULL METHOD DEFINITION ................................................................................................130
EXAMPLE OF METHOD DEFINITION ..........................................................................................................131
EXAMPLE OF METHOD EQUIVALENTS FOR DEFAULT PARAMETERS ....................................................131
EXAMPLE OF FULL METHOD DEFINITION ................................................................................................131
EXAMPLE OF METHOD EQUIVALENT DEFINITION WITH STATIC METHOD ........................................131
EXAMPLE OF METHOD EQUIVALENT TO RENAME ALL CLASS METHODS ...........................................132
EXAMPLE OF EQUIVALENT METHOD REDEFINITION .............................................................................132
EXAMPLE OF CONSTRUCTOR SYNTAX ........................................................................................................133
EXAMPLE OF DEFAULT CONSTRUCTOR .....................................................................................................134
EXAMPLE OF NON-DEFAULT CONSTRUCTOR ...........................................................................................134
EXAMPLE OF CONSTRUCTOR DEFINITION WITH METHOD EQUIVALENT............................................134
EXAMPLE OF DEFINING MULTIPLE CONSTRUCTORS IN A CLASS ...........................................................135
EXAMPLE OF CONSTRUCTOR DECLARATION ............................................................................................135
EXAMPLE OF INVOKING A CONSTRUCTOR ................................................................................................135
EXAMPLE OF INVOKING DEFAULT CONSTRUCTOR .................................................................................136
EXAMPLE OF NOT INVOKING DEFAULT CONSTRUCTOR ........................................................................136
EXAMPLE OF USING CONSTRUCTORS OF A CLASS ....................................................................................136
EXAMPLE OF SYNTAX FOR A DESTRUCTOR ...............................................................................................137
EXAMPLE OF DESTRUCTOR DEFINITION WITH METHOD EQUIVALENT ..............................................137
EXAMPLE OF DESTRUCTOR INVOCATION ..................................................................................................138
EXAMPLE OF DECLARING A DEFAULT METHOD .....................................................................................139
EXAMPLE OF USING AN DEFAULT METHOD.............................................................................................139
EXAMPLE OF OPERATOR OVERLOAD TO METHOD INVOCATION .........................................................140
EXAMPLE OF DEFAULT METHOD ...............................................................................................................140
EXAMPLE OF DEFAULT METHOD FOR OUTPUT STREAM ........................................................................140
EXAMPLE OF EXPLICIT METHOD FOR OUTPUT STREAM .........................................................................140
EXAMPLE OF DECLARING AN INCOMPLETE METHOD ............................................................................141
EXAMPLES OF IMPLIED METHOD DECLARATION ....................................................................................142
EXAMPLE OF AN IMPLIED METHOD IMPLEMENTATION..........................................................................143
EXAMPLE OF JAVA INTERFACE FOR IMPLIED METHOD ..........................................................................143
EXAMPLE OF JAVA CLASS FOR IMPLIED METHOD ....................................................................................144
EXAMPLE OF JAVA CODE FOR MYNX CLASS ..............................................................................................144
EXAMPLE OF METHOD OBVIATION DECLARATION ................................................................................146
EXAMPLE OF OBVIATE METHOD DECLARATION FOR MULTIPLE METHODS ......................................147
EXAMPLE OF CLASS DECLARING A METHOD ............................................................................................147
EXAMPLE OF DECLARING AN OBVIATE METHOD FOR SINGLE METHOD ...........................................148
EXAMPLE DECLARING AN OBVIATE METHOD FOR NON-EXISTENT METHOD ..................................148
EXAMPLE OF MULTIPLE METHODS IN A CLASS ........................................................................................150
EXAMPLE OF DECLARING MULTIPLE METHOD OBVIATION ..................................................................150
EXAMPLE OF METHOD OBVIATION............................................................................................................150
EXAMPLE INVOKING A CLASS METHOD WITH OBVIATE METHOD .......................................................151
EXAMPLE OF INVALID REDEFINITION OF AN OBVIATE METHOD ........................................................151
EXAMPLE OF INVOKING AN OBVIATE METHOD IMPLICITLY .................................................................152
EXAMPLE OF REFERENCE ASSIGNMENT OPERATOR ...............................................................................154
EXAMPLE OF CREATION OPERATOR ..........................................................................................................155

- 218 -
Mynx Programming Language

EXAMPLE OF REGULAR ASSIGNMENT OPERATOR ...................................................................................155


EXAMPLE OF DECLARATION WITH INITIAL VALUE .................................................................................155
EXAMPLE OF CAST ASSIGNMENT OPERATOR ...........................................................................................156
EXAMPLE OF ADDITION ASSIGNMENT OPERATOR ..................................................................................157
EXAMPLE OF SUBTRACTION ASSIGNMENT OPERATOR ...........................................................................157
EXAMPLE OF MULTIPLICATION ASSIGNMENT OPERATOR ......................................................................158
EXAMPLE OF DIVISION ASSIGNMENT OPERATOR ....................................................................................158
EXAMPLE OF MODULUS ASSIGNMENT OPERATOR ..................................................................................159
EXAMPLE OF BITWISE AND ASSIGNMENT OPERATOR ............................................................................159
EXAMPLE OF BITWISE INCLUSIVE OR ASSIGNMENT OPERATOR ...........................................................160
EXAMPLE OF BITWISE EXCLUSIVE OR ASSIGNMENT OPERATOR ..........................................................160
EXAMPLE OF BITWISE SHIFT RIGHT ASSIGNMENT OPERATOR ..............................................................161
EXAMPLE OF BITWISE SHIFT LEFT ASSIGNMENT OPERATOR.................................................................161
EXAMPLE OF CAST OPERATOR ....................................................................................................................162
EXAMPLE OF USING A CAST OPERATOR ....................................................................................................162
EXAMPLE DEFINITION OF CAST CLASS TYPES ..........................................................................................164
EXAMPLE USING TYPE CAST OF CLASS TYPES ..........................................................................................164
EXAMPLE OF LOGICAL NOT OPERATOR ....................................................................................................165
EXAMPLE OF LOGICAL AND OPERATOR....................................................................................................166
EXAMPLE OF LOGICAL BITWISE AND OPERATOR ....................................................................................166
EXAMPLE OF LOGICAL AND OPERATOR....................................................................................................166
EXAMPLE OF LOGICAL OR OPERATOR ......................................................................................................167
EXAMPLE OF LOGICAL BITWISE OR OPERATOR .......................................................................................167
EXAMPLE OF LOGICAL INCLUSIVE OR OPERATOR ..................................................................................167
EXAMPLE OF BITWISE COMPLEMENT OPERATOR ....................................................................................168
EXAMPLE OF BITWISE SHIFT LEFT OPERATOR .........................................................................................168
EXAMPLE OF BITWISE SHIFT RIGHT OPERATOR ......................................................................................168
EXAMPLE OF LOGICAL EXCLUSIVE OR OPERATOR .................................................................................168
EXAMPLE OF EQUALITY OPERATOR ...........................................................................................................169
EXAMPLE OF INEQUALITY OPERATOR .......................................................................................................170
EXAMPLE OF IN INSTANCE-OF CLASS OPERATOR ....................................................................................171
EXAMPLE OF IN INSTANCE OPERATOR ......................................................................................................171
EXAMPLE OF LESS THAN OPERATOR .........................................................................................................171
EXAMPLE OF GREATER THAN OPERATOR ................................................................................................172
EXAMPLE OF GREATER THAN EQUAL OPERATOR...................................................................................172
EXAMPLE OF INSERTION STREAM OPERATOR ..........................................................................................174
EXAMPLE OF EXTRACTION STREAM OPERATOR ......................................................................................174
EXAMPLE OF OVERLOADED STREAM OPERATORS ..................................................................................174
EXAMPLE OF ADDITION OPERATOR ..........................................................................................................175
EXAMPLE OF SUBTRACTION OPERATOR ....................................................................................................175
EXAMPLE OF DIVISION OPERATOR ............................................................................................................176
EXAMPLE OF MODULUS OPERATOR ...........................................................................................................176
EXAMPLE OF MULTIPLICATION OPERATOR ..............................................................................................176
EXAMPLE OF EXPONENTIATION OPERATOR ............................................................................................177
EXAMPLE OF POST-INCREMENT OPERATOR .............................................................................................177
EXAMPLE OF POST-DECREMENT OPERATOR ...........................................................................................177
EXAMPLE OF METHOD ACCESS OR INVOCATION .....................................................................................178
EXAMPLE OF ATTRIBUTE ACCESS ...............................................................................................................179

- 219 -
Mynx Programming Language

EXAMPLE OF ARRAY ACCESS .......................................................................................................................179


EXAMPLE OF OPERATOR OVERLOADING WITH CONSTANT OVERLOAD .............................................183
EXAMPLE OF OPERATOR OVERLOAD WITH DEFAULT ............................................................................183
EXAMPLE OF OPERATOR OVERLOAD FROM DEFAULT TO CONSTANT .................................................184

- 220 -
Mynx Programming Language

Index of Tables
TABLE OF MYNX KEYWORDS ........................................................................................................................27
TABLE OF ESCAPED CHARACTERS.................................................................................................................28
TABLE OF STANDARD META STRINGS IN MYNX .........................................................................................30
TABLE OF OUTPUT WITH USING A META STRING .......................................................................................31
TABLE OF MYNX MULTIPLE LINE COMMENTS ...........................................................................................32
TABLE OF PRE- AND POST- CONDITIONAL STATEMENTS AND BOUNDS ...............................................53
TABLE OF MYNX NAMESPACES .....................................................................................................................62
TABLE OF MYNX CLASS KINDS, INHERITANCE, INSTANCE, CATEGORY ................................................79
TABLE SUMMARY OF CRITERION FOR MYNX CLASSES ...............................................................................81
TABLE OF CLASS ELEMENT ACCESS OPERATORS .......................................................................................94
TABLE OF ATTRIBUTE KINDS ......................................................................................................................111
TABLE OF IMPLICIT SCOPE ATTRIBUTES ....................................................................................................113
TABLE OF METHOD PARAMETER MODES TABLE .....................................................................................115
TABLE FOR OVERRIDING A STATIC METHOD ...........................................................................................124
TABLE OF STATIC METHOD PREFIXES .......................................................................................................126
TABLE SYNOPSIS SPECIAL CLASS METHODS ..............................................................................................133
TABLE OF ASSIGNMENT OPERATORS .........................................................................................................154
TABLE OF LOGICAL BITWISE OPERATORS .................................................................................................165
TABLE OF RELATIONAL OPERATORS ..........................................................................................................169
TABLE OF STREAM OPERATORS ...................................................................................................................174
TABLE OF MATHEMATIC OPERATORS ........................................................................................................175
TABLE OF ACCESS OPERATORS ....................................................................................................................178
TABLE OF OPERATOR PRECEDENCE ..........................................................................................................180
TABLE OF OPERATORS, PRECEDENCE, AND OVERLOADED ...................................................................185
TABLE OF STANDARD OPERATOR OVERLOADS BY METHOD NAME ....................................................186
TABLE OF MYNX FILE TYPES AND TOOLS .................................................................................................195

- 221 -
Mynx Programming Language

- 222 -

You might also like