Professional Documents
Culture Documents
Programming
Language
July 2007
Mynx Programming Language
-2-
Mynx Programming Language
William F. Gilreath
http://www.williamgilreath.com/mynx
-3-
Mynx Programming Language
-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 ...................................................................................................................................................... 27
SYMBOLS ....................................................................................................................................................... 28
NUMBERS ..................................................................................................................................................... 28
META STRINGS ............................................................................................................................................ 29
OPERATORS ................................................................................................................................................. 30
ENCODING................................................................................................................................................... 31
COMMENTS .................................................................................................................................................. 31
Single Comments ................................................................................................................................... 31
Multiple Comments ............................................................................................................................... 31
ENUMERATED TYPES ................................................................................................................................. 32
STATEMENTS .............................................................................................................................................. 33
COMPUTATION ............................................................................................................................................ 36
Expression Statement............................................................................................................................ 36
Declaration ......................................................................................................................................... 36
Expression .......................................................................................................................................... 36
Postfix............................................................................................................................................. 37
Assignment..................................................................................................................................... 37
Assign ......................................................................................................................................... 37
Create ......................................................................................................................................... 37
Input-Output............................................................................................................................. 38
Access ............................................................................................................................................. 38
Attribute..................................................................................................................................... 38
-5-
Mynx Programming Language
Method....................................................................................................................................... 39
Array........................................................................................................................................... 39
Multiple ...................................................................................................................................... 39
Null Statement........................................................................................................................................ 40
ERROR .......................................................................................................................................................... 40
Assert Statement..................................................................................................................................... 40
Flag Statement ........................................................................................................................................ 41
Try Statement.......................................................................................................................................... 41
FLOW OF CONTROL .................................................................................................................................... 42
Exit Statement ........................................................................................................................................ 43
Next Statement....................................................................................................................................... 44
Prefix If Statement................................................................................................................................. 44
Return Statement.................................................................................................................................... 45
REPETITION ................................................................................................................................................. 46
For Statement ......................................................................................................................................... 46
For Statement over a Range............................................................................................................. 46
For Statement over an Array ........................................................................................................... 47
For Statement over Other Integral Type ....................................................................................... 47
Until Statement....................................................................................................................................... 49
While Statement ..................................................................................................................................... 49
Repeat Statement.................................................................................................................................... 50
Pre-conditional and Post-conditional Loops ..................................................................................... 51
Case Statement ....................................................................................................................................... 52
If Statement............................................................................................................................................. 53
MUTEX STATEMENT ................................................................................................................................... 55
Mutex Statement Syntax........................................................................................................................ 55
Mutex Expression .................................................................................................................................. 55
NAMESPACES ............................................................................................................................................... 57
Declaration.............................................................................................................................................. 57
Default Namespace................................................................................................................................ 57
Classes and Programs within a Namespace ....................................................................................... 58
Inclusion of Classes from a Namespace............................................................................................. 58
Nested Namespace Inclusion............................................................................................................... 59
Declaration Order for Namespace Inclusion..................................................................................... 60
Mynx Namespace................................................................................................................................... 60
Nonexistent Namespace Inclusion...................................................................................................... 60
Static Inclusion from Default Namespace ......................................................................................... 61
ARRAYS ......................................................................................................................................................... 62
Array Attributes...................................................................................................................................... 62
Array Declaration................................................................................................................................... 63
Array Creation ........................................................................................................................................ 64
Initialization with a List .................................................................................................................... 64
Initialization with an Implicit Indexed List............................................................................... 64
Initialization with an Explicit Indexed List ............................................................................... 65
Initialization with a Non-List........................................................................................................... 65
Initialization with Default Constructor...................................................................................... 65
Initialization with Null.................................................................................................................. 66
Using an Element of an Array ......................................................................................................... 67
-6-
Mynx Programming Language
Array as an Object............................................................................................................................. 68
Array as a Parameter ......................................................................................................................... 68
TRAPS ............................................................................................................................................................ 70
Kinds of Traps........................................................................................................................................ 70
Trap Declaration .................................................................................................................................... 70
Trap Invocation...................................................................................................................................... 70
Trap Handling......................................................................................................................................... 71
Trap Propagation ................................................................................................................................... 71
UNITS .............................................................................................................................................................. 73
PRIMARY ELEMENTS – PROGRAM AND CLASS........................................................................................ 75
Program ................................................................................................................................................... 75
Class ......................................................................................................................................................... 76
KINDS OF CLASSES...................................................................................................................................... 76
Abstract ................................................................................................................................................... 77
Constant .................................................................................................................................................. 77
Default ..................................................................................................................................................... 77
Generic .................................................................................................................................................... 77
Singular .................................................................................................................................................... 78
Static......................................................................................................................................................... 78
Virtual ...................................................................................................................................................... 78
INHERITANCE AND CLASS TYPES ............................................................................................................. 79
TYPES OF INHERITANCE ............................................................................................................................ 79
Null........................................................................................................................................................... 79
Single ........................................................................................................................................................ 80
Multiple Virtual....................................................................................................................................... 81
Multiple Disjoint .................................................................................................................................... 82
CLASSES AND INHERITANCE ..................................................................................................................... 84
INHERITANCE OF ATTRIBUTES AND METHODS ..................................................................................... 84
Attributes................................................................................................................................................. 84
Methods................................................................................................................................................... 85
INHERITANCE OF METHODS ..................................................................................................................... 85
METHOD OVERRIDING .............................................................................................................................. 85
Rules for Method Overriding............................................................................................................... 86
Covariant Method Overriding.............................................................................................................. 87
Method Overloading ............................................................................................................................. 89
OPERATOR OVERLOADING ....................................................................................................................... 90
CLASS REFERENCE PREFIXES .................................................................................................................... 90
Dottic Access Prefix .............................................................................................................................. 91
Super Class Prefix.............................................................................................................................. 91
This Class Prefix ................................................................................................................................ 92
Self Class Prefix ................................................................................................................................. 94
GENERICS .................................................................................................................................................... 95
Elements of a Generic Class................................................................................................................. 95
Generic Attributes............................................................................................................................. 95
Generic Methods ............................................................................................................................... 96
Operator Overloads in Generic Class................................................................................................. 96
Default Method in Generic Class ........................................................................................................ 97
-7-
Mynx Programming Language
-8-
Mynx Programming Language
-9-
Mynx Programming Language
- 10 -
Mynx Programming Language
- 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.
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…)
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.
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.
Int x to 7;
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#.
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
class example is
//C++
public myMethod(int x, int y=0) is ...
//Java
public myMethod(int x) {
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:
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.)
- 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.
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,
- 21 -
Mynx Programming Language
rather than either make the choice for them by design or for easier compiler construction.
Units
Units are the high-level organizing entity. In Mynx, the units are divided into two categories:
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.)
3. Portable: A programming language to target two major platforms, Java and .NET, and
be source compatible on both.
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:
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:
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.
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.
- 27 -
Mynx Programming Language
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
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
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.
- 28 -
Mynx Programming Language
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.
Meta Strings
A meta string is the Mynx partial replacement for the macro system of C/C++. It does not attempt
to replace or define macros for conditional code inclusion, or textual substitutions. Meta strings are
equivalent to the the __FILE__ and __LINE__ macros.
A meta-string is a string identifier in uppercase, beginning with the hash or pound sign #. A meta
string is substituted with the information it represents. A meta-string allows for information about
the source code, but without the manual effort to represent it, or the overhead of changing it when
the source code is revised. There are 19-standard meta strings in Mynx.
- 29 -
Mynx Programming Language
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.
end class;
The output for calling aMethod with the class metaStrExample is:
Module is default
Method name is aMethod
Class is metaStrExample
This meta string is UNDEFINED
Programmer defined meta strings are not supported, as then source code would contain undefined
meta strings which would need to be defined in the source, essentially creating a macro system
(which Mynx is trying to avoid without sacrificing some convenience) indirectly.
Operators
There are 44-operators in Mynx that represent the non-character symbols used to create expressions
and statements. The operators are classified into five categories:
1. Assignment
2. Logical and Bitwise
3. Relational
4. Stream
5. Mathematic
- 30 -
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.
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.
The Mynx compiler ignores comments, but for documentation, the comments are processed with
the specific documentation with XML markup tags.
- 31 -
Mynx Programming Language
Enumerated Types
An enumerated type is a named discrete set of named constants that are treated as a unique type.
Each constant has a non-negative integral value, and a string name. The Mynx programming
language has neither a predefined language construct for defining types (like the C programming
language typedef declaration), nor to define an enumeration or enumerated type (like the C
programming language enum declaration) either.
The reason is to avoid defining in the programming language that which can be defined using a class
and other features of the Mynx programming language, such as static inclusion of a class, and
operator overloading. Both the keywords enum and type are reserved words, to avoid creating
classes, attributes, constants, variables, or methods with those names and cause confusion.
- 32 -
Mynx Programming Language
Statements
- 33 -
Mynx Programming Language
- 34 -
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.
- 35 -
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
Declaration
A declaration statement is a declaration within a method, and has a similar syntax to a class or
program attribute. A declaration statement is preceded by the keyword var to distinguish the
declaration from an expression statement. Unlike a class or program attribute, a declaration sub-
statement does not need an initial value. A declaration without an initial value merely declares a
variable and initializes it to a value of null. A declaration with or without an initial value declares and
creates an instance of a class as an object, invoking the class constructor.
var Int x to 0;
var Char c,d; //no initial value, just a declaration to null;
var Point p to null;
var Real r to default;
var String[*] tables to { “0”,“1”,“2”,“3” };
Expression
An expression statement is a computation statement that evaluates an expression form to compute
and create an object instance for the value of the evaluated expression. The operators used in an
expression statement are overloaded to represent a method call or access to compute a value. An
expression statement has five sub-expression statement types:
1. postfix
2. assignment
3. creation
4. input-output
5. access
- 36 -
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)--;
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:
Assign
Assignment statements use a left value, right value, and are separated by an assignment operator.
The left value must be an identifier, array access, or attribute access. The right value can be an
expression, literal, method call, attribute access, or array access.
x = 3;
y += x+7 / 2;
z = this.computeValue(x,y);
data[3] = 17;
x`y := i+j*3;
total = x**y + 1;
q is y;
this`y = 0;
self`ct = super.getCount;
Create
A create or creation statement is an assignment expression that creates a new instance of a class and
assigns it to an object reference or variable. The keyword as follows the object reference variable
and the class name with any constructor parameters.
- 37 -
Mynx Programming Language
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.
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:
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.
- 38 -
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;
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.
Array
An access sub-expression for an array is accessing an array element of the method or class. An array
access can be read or written. The sub-script of index into the array can be a literal constant,
variable, or an expression.
y = data[x];
data[base+count*sizeof(data)] = 0;
x[0] = y;
Multiple
The access statement can be made up of multiple accesses, such as accessing a method, then an
attribute, an array, and so forth. Note that a super or this reference only appears as the first element
of an access statement.
this.callMethod(0,”hello”).doSomething`rawData[x];
super.doIt[x]`data;
- 39 -
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;
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.
- 40 -
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.
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;
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;
- 41 -
Mynx Programming Language
try
return 0;
do
return 1; //compiler error: invalid flow of control
end try; //from try do-clause
loop
try
next loop(0);
do
next loop(0); //compiler error: invalid flow of control
end try; //from try do-clause
end loop(0);
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.
- 42 -
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);
file.open;
while(! file.endOfFile)
this.processRecord(file,i,status);
if(!status)
exit while(0);
end if;
end for(1);
end while(0);
file.close;
- 43 -
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.
for(Int x is 0 to row)
for(Int y is 0 to col)
val = matrix.get(x,y);
if(val == 0)
next for(1);//skip to next y
end if;
end for(1);
end for(0);
end findInMatrix;
Prefix If Statement
A prefix-if statement is a specialized form of if-statement, which combines an exit or next statement
into a single statement form. A prefix-if statement is used mostly within a loop statement, to define
the exit or next condition for a loop.
exit(0) if ( i >= j );
next(2) if ( foundFlag );
where = index;
exit for(0) if(list[index] == val);
end for(0);
return where;
end findMax;
- 44 -
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.
for(Int x is 0 to list.length)
if(list[x] == value)
return value;
end if;
end for;
return null;
end find;
if(uint == 0)
return 1;
else
return (uint * factorial(uint-1));
end if;
end factorial;
this.processFile(file);
end processFile;
- 45 -
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:
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.
- 46 -
Mynx Programming Language
for(String x in dataTable)
IO <<< x <<< eoln;
end for(0);
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.
- 47 -
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.
loop
doFileOperation(statusFlag);
exit if(statusFlag); //prefix-if explicit exit
end loop;
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;
- 48 -
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;
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;
- 49 -
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:
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.
dataFile.open;
repeat
dataFile.readRecord;
while(!dataFile.endOfFile );
dataFile.open;
repeat
dataFile.readRecord;
until( File.endOfFile );
Each of the repeat loop statements is logically equivalent. Depending upon the logical expression, a
repeat-while and repeat-until can be used. A loop statement is equivalent to a repeat statement, only
with the logic to terminate of the loop part of the body of statements. A repeat statement avoids the
mixing of logic and statements in a cleaner repetition statement.
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.
- 50 -
Mynx Programming Language
repeat
rec = dataFile.readRecord;
exit if(rec == null) repeat(0);
while(!dataFile.endOfFile )(0);
dataFile.close
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.
- 51 -
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.
case(x)
as 0 is
doSomething0;
as 1 is
doSomething1;
else //negative integer, positive integer > 1
callError;
end case;
case(c)
as ‘a’,’e’,’i’,’o’,’u’ is
this.handelVowel(c);
as ‘,’,’’’,’”’,’;’,’:’ is
this.handleControlChar(c);
else
this.handleOtherChar(c);
end case;
The else statement is for the default or non-case specific option, and is required for a case statement.
- 52 -
Mynx Programming Language
loop
cmd = in.readLine;
case(cmd)
as “exit”, “quit” is exit;
as “version” is reportVersion;
else execute(cmd);
end case;
end loop;
If Statement
An if statement is a logical condition selection statement; based upon the condition in the if-clause,
either the then-block is evaluated, or the else-block. An else-block for an if-statement is an optional
part, the equivalent if-statement with an else-block has a null statement.
if(x < y)
x = y; //then-block
end if;
if(x < y)
x = y;//then-block
else
null; //else-block
end if;
- 53 -
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;
if(ival < 0)
flag IntegerValueTrap;
elif(ival == 0)
return 1;
else
return( ival * this.factorial(ival-1) );
end if;
end factorial;
- 54 -
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 ( EXPRESSION )
STATEMENTS
end mutex ;
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;
- 55 -
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.
mutex(myMutex)
null;
end mutex;
- 56 -
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;
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.
- 57 -
Mynx Programming Language
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:
An absolute inclusion of a namespace includes a specific class in a specific namespace. The with
statement for absolute inclusion of a class in a namespace is the with keyword with a namespace and
class, followed by an ending semicolon ‘;’.
Example absolute inclusion of class for a namespace:
with mynx.core.String;
with mynx.io.File;
A relative inclusion declaration is like an absolute, except that instead of a specific class name after
the namespace, a wildcard or asterisk ‘*’ is used to include all classes within the namespace.
with mynx.core.*;
with mynx.io.*;
with de.internet.util.*;
- 58 -
Mynx Programming Language
module example;
module example.first;
module example.first.second;
with example.*;
The namespace will include all classes within the example namespace; however it does not include
any sub-namespaces that are nested. To include sub-namespaces, a namespace must specify the sub-
namespace.
with example.*;
with example.first.*;
with example.first.second.*;
The namespace wildcard or asterisk ‘*’ is for all classes within a namespace, not any sub-namespaces.
Hence the following namespace inclusion is invalid:
with example.*.*.*;
The namespace for class inclusion must be explicitly and fully declared, sub-namespaces that are
nested are not included unless declared explicitly.
- 59 -
Mynx Programming Language
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.
- 60 -
Mynx Programming Language
module default;
static class S3 is
end class;
program useS3 is
end program;
- 61 -
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.
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.
A bounded array is of the form where for the array bounds uses a non-negative integer value for
each dimension.
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:
- 62 -
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:
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.
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.
- 63 -
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.
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.
- 64 -
Mynx Programming Language
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.
Array initialization in Mynx is absolute, flat-indexed, and independent of the underlying array
organization such as row-major or column-major structure.
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)
- 65 -
Mynx Programming Language
An array can be declared, but then created with the as operator and a class constructor called
explicitly.
- 66 -
Mynx Programming Language
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.
x = ints[0]; //x.set(ints[0]); x == 1
y is ints[1]; //y == ints[1]; y == 1
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
- 67 -
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.
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.
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;
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.
- 68 -
Mynx Programming Language
end main;
- 69 -
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:
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.
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.
- 70 -
Mynx Programming Language
if(divisor == 0)
flag ZeroDivideTrap;
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;
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.
- 71 -
Mynx Programming Language
- 72 -
Mynx Programming Language
Units
- 73 -
Mynx Programming Language
- 74 -
Mynx Programming Language
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.
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
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.
- 75 -
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
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:
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.
- 76 -
Mynx Programming Language
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.
- 77 -
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.
- 78 -
Mynx Programming Language
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.
end class;
end class;
The class Void explicitly inherits null or nothing, but implicitly inherits null. A virtual class can
declare but not define a class, to be used as a specification for implemented functionality in a
concrete class. A virtual class can re-use specified functionality from another virtual class. But if a
virtual class wants to specify additional functionality without inheriting more from another virtual
class, it would declare the super class as null.
- 79 -
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.*;
//...class body...
end class;
- 80 -
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.*;
- 81 -
Mynx Programming Language
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.
- 82 -
Mynx Programming Language
//...class definition...
end class;
- 83 -
Mynx Programming Language
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:
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. 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.
- 84 -
Mynx Programming Language
end class;
end class;
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.
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
- 85 -
Mynx Programming Language
method equivalence from the super class (although it is not method overriding, it is method
equivalence).
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.
end class;
end class;
- 86 -
Mynx Programming Language
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.)
- 87 -
Mynx Programming Language
end class;
end 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.
- 88 -
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.
end class;
end class;
- 89 -
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;
end class;
end class;
program addExample is
//equivalent to
i64.set(i64.add(i32));
end program;
- 90 -
Mynx Programming Language
This clearly disambiguates an attribute over a method. As a result, attributes and methods can have
similar names without any confusion or ambiguity.
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.
- 91 -
Mynx Programming Language
end class;
end class;
- 92 -
Mynx Programming Language
end class;
A class attribute or a class method that is accessed without a prefix is implicitly using the this prefix
to access the class element.
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 X get is
return this;
end get;
end class;
- 93 -
Mynx Programming Language
end class;
Similar to the concept of the read-only this class instance variable, the class reference prefix super
can refer to the static form of a class, essentially a generalized reference to the class as its name.
- 94 -
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.
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.
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.
end class;
- 95 -
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.
end class;
end class;
- 96 -
Mynx Programming Language
end class;
- 97 -
Mynx Programming Language
end class;
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.
- 98 -
Mynx Programming Language
end class;
end class;
end class;
- 99 -
Mynx Programming Language
end class;
end class;
end class;
- 100 -
Mynx Programming Language
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.
Kinds of Instantiation
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.
end class;
- 101 -
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.
end class;
- 102 -
Mynx Programming Language
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:
- 103 -
Mynx Programming Language
end class;
class useGenericClasses is
gStrVar as StringVar(“global”);
end construct;
strvar = sv;
if(sv == this`gStrVar)
this`lStrVar is sv;
end if;
end doSomething;
end class;
- 104 -
Mynx Programming Language
Elements
- 105 -
Mynx Programming Language
- 106 -
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:
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:
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.
The attribute kind does not have to be explicitly declared, but is implicitly variable.
- 107 -
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.
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.
- 108 -
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.
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.
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:
The remainder of a class attribute is the standard declaration, similar to a program attribute.
- 109 -
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:
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.
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.
- 110 -
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.
If a parameter mode is not given, it is implicitly an in parameter. Each kind of parameter differs in
terms of:
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.
- 111 -
Mynx Programming Language
temp = first;
first = last; //error immutable reference, unchangeable
last = temp; //error immutable reference, unchangeable
end swap;
var Int i to 7;
var Int j to 3;
var Int k to null;
swap(i,j);
swap(j,k); //error in parameter can not be null
swap(k,i); //error in parameter can not be null
A general-purpose method swap is not possible using an in parameter mode. The parameters are
immutable, and are not able to assign null.
temp = first;
first = last;
last = temp;
end swap;
- 112 -
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
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.
temp = first;
first = last; //error immutable reference, unchangeable
last = temp; //error immutable reference, unchangeable
end swap;
var Int i to 7;
var Int j to 3;
var Int k to null;
The parameter mode var allows for mutable parameters but that are not null. The swap method
using var parameter mode is the best implementation.
- 113 -
Mynx Programming Language
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);
- 114 -
Mynx Programming Language
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.
- 115 -
Mynx Programming Language
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.
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.
- 116 -
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:
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.
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.
- 117 -
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 Headers
A class method header is a composite of information about the class method. A class method must
specify the elements:
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.
- 118 -
Mynx Programming Language
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.
Each kind of static method is for specifics for overriding the class method.
- 119 -
Mynx Programming Language
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.
end sort;
end class;
end sort;
end class;
- 120 -
Mynx Programming Language
A refinement of the QuickSort class and the method sort by checking if it is sorted in the
QuickerSort class.
if(! isSorted(ro) )
QuickSort.sort(ro); //call super-class static method
end if;
end sort;
end class;
Using the various classes that implement the virtual class VSort in a program:
program sortdemo is
end program;
- 121 -
Mynx Programming Language
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
- 122 -
Mynx Programming Language
method helloWorld is
IO.put(self`greeting);
end helloWorld;
end main;
end program;
with mynx.core.*;
- 123 -
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;
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.
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;
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.
if(x.isReady == Bool.True)
flag NotReadyTrap;
end if;
- 124 -
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;
The implicit static class prefix reference can be used with attributes or pure methods, for example:
The Abs or absolute value method refers to the static method of the Math class. Rewritten with the
full static class name prefix reference:
x = Math.Abs(r);
If a class is not included utilizing a with statement, then it will generate a Mynx semantic error of
irresolvable reference to a static class method prefix.
Ambiguous class references occur when two or more classes have static methods defined with the
same method signature, and method name. In which case, the class name would have to be explicitly
given, it cannot be implicitly determined by Mynx.
- 125 -
Mynx Programming Language
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
end class;
The methodEquiv class has a constructor and destructor, only both are equivalent to a null, so are
do nothing methods of the class. The same constructors and destructors defined with full methods
is:
class methodEquiv is
public construct is
null;
end construct;
public destruct is
null;
end destruct;
end class;
- 126 -
Mynx Programming Language
When defined in an integer class, the arithmetic methods take an implicit this to be used in the
operation.
this.addition(this,augend);
end addition;
- 127 -
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.
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:
- 128 -
Mynx Programming Language
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:
end construct;
- 129 -
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;
A non-default constructor is any constructor that takes arguments in the parameter list.
this`int = i;
end construct;
A constructor is like a method, and like a method can be defined by using a method equivalent. A
constructor can be defined by a method equivalent as:
end class;
- 130 -
Mynx Programming Language
return this`y;
end y;
end class;
Constructor Invocation
A constructor is invoked indirectly, either through:
When invoked, a constructor is invoked on the same class type, not a sub-class or super-class of the
variable or constant type.
x as Int(0);
str as String(“hello world”);
p as Point(0,0);
- 131 -
Mynx Programming Language
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.
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.
x as null; or x is null;
str as null; or str is null;
b as null; or b is null;
In the creation expression involving null, the as creation operator is equivalent to the is assignment
operator, but only in the case of null. Using the 2DPoint class in a program:
program 2PointProgram is
end program;
- 132 -
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
end destructor;
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.
- 133 -
Mynx Programming Language
if(! this`procFile.isReady)
this`procFile is null;
this`procFile.nullify;
end if;
end construct;
end class;
Like a constructor, only an abstract, constant, or default class can define a destructor. There is no
guarantee when a destructor is called, if an instance is destroyed explicitly through a nullify method,
and then the destructor is invoked. If an instance is destroyed implicitly, then the destructor is called
upon garbage collection, or upon the end of the application, which ever occurs first, with no
assurance of when the destructor is called.
A destructor is useful as a post-check for proper termination and clean-up of an instance, rather
than as a guaranteed means for the disposal and release of resources utilized with an instance.
- 134 -
Mynx Programming Language
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.
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.
zeroInt to Int(0);
oneInt to Int(1);
sum to Int(0);
- 135 -
Mynx Programming Language
The equality operator = is overloaded with set or the assign. The simple expression statement
becomes:
sum = zeroInt;
sum.set(zeroInt);
The instance zeroInt invokes the implicit default method of get, which gets the value of zeroInt.
sum.set(zeroInt);
sum.set(zeroInt.get);
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.
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:
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.
- 136 -
Mynx Programming Language
end class;
- 137 -
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.
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.
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.
- 138 -
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
end class;
The Mynx class with the implied method execute will cause the generation of an interface and an
implementing class around the implied methods within the same namespace. The implied method
interface and class use a “mangled” name, with a trailing underscore after the Mynx class name to
avoid conflict with any Mynx class names. The interface is prefixed with _impliedI for implied
interface, and the implementing class is prefixed with _implied before the Mynx class name.
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.
package example.impliedMethod;
- 139 -
Mynx Programming Language
package example.impliedMethod;
The implementation code generated in Java for the corresponding Mynx class:
package example.impliedMethod;
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.
- 140 -
Mynx Programming Language
- 141 -
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.
- 142 -
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.
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.
end class;
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.
- 143 -
Mynx Programming Language
end class;
The original method wagtail in the super class Cat is now invalid (since a Manx cat does not have a
tail…) obsolete or, hence in the sub-class manxCat must be made obviate. Obviating a method does
not “undefined” the method, but removes it from the class interface
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.
end class;
- 144 -
Mynx Programming Language
The class hierarchy for the various classes with an obviate method is:
’ to
The Uniform Modeling Language diagram is not standard, it uses the symbol character ‘
indicate an obviate method.
- 145 -
Mynx Programming Language
end class;
end class;
The class getConsoleInput sub-classes ConsoleInput, but also obviates all methods by the name
readln. All methods by the name readln are obviated, not just a specific method by the method
signature. The methods are still visible, just can never be invoked from that class. The only method
that can be invoked in the getConsoleInput class is the method getln. The method getln is a method
equivalent for all the readln methods, and not obviated.
program useConsole is
end program;
- 146 -
Mynx Programming Language
program wagTheCat is
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.
end class;
The obviate method wagtail cannot be re-defined within the class, even as an internal private
method.
- 147 -
Mynx Programming Language
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.
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.
- 148 -
Mynx Programming Language
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 six categories for operators in Mynx:
1. Assignment
2. Logical Bitwise
3. Relational
4. Stream
5. Mathematical
6. Access
- 149 -
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.
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.
var Int x to 0;
var Int y to 1;
x++;
y is x; //y is x
y++; //y is x, so x++
- 150 -
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.
x as Int(“7”);
y as Int(0);
x = y;
y = 5; //x != 5, = overloaded
//same code:
x.set(y);
y.set(5);
It is important to note that in initialization of declared variables and constants, the to is a separator
between the class type and the initial value, it is not the regular assignment operator.
- 151 -
Mynx Programming Language
Cast Operator to
The Mynx programming language is strongly typed, and the language requires type-compatibility
among the operands used in expressions and parameters.
The cast operator to is used to cast or re-type an object. An object can only be re-cast to a super-
type, or a super-class from which the object class type is derived. A cast or re-typing of an object to
a non-existent class type (one which the object's class does not sub-class) will result in flagging a
runtime type cast trap.
The to operator has both a left and right operand. The left operand is the instance object variable,
and the right operand is the class type.
Implicit Upcast ??
- 152 -
Mynx Programming Language
var Int x to 3;
var Real y to 1.0;
y := x;
y = x to Real; //same as
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.
- 153 -
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;
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.
//similarly
r = r - 1.0;
- 154 -
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.
//similarly
m = m * 2.0
//overloaded
m = m.mul(2.0);
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);
- 155 -
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);
The bitwise-and assignment operator, because of the dual operation, cannot be overloaded directly,
but indirectly through bitwise-and and assignment overloads.
//similarly
x = x & 0XFF01;
//overloaded
x = x.bitAND(0XFF01);
- 156 -
Mynx Programming Language
//similarly
x = x | 0XFF01;
//overloaded
x = x.bitIOR(0XFF01);
//similarly
x = x ^ 0XFF01;
//overloaded
x = x.bitXOR(0XFF01);
- 157 -
Mynx Programming Language
//overloaded
x = x.shiftRight(0X001);
//similarly
x = x << 0X0001;
//overloaded
x = x.shiftLeft(0X001);
- 158 -
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
The 9-logical bitwise operators are all overloaded operators, and are overloaded in the Mynx core
classes.
//overloaded
var Bool logical to True;
var Int x to 1;
- 159 -
Mynx Programming Language
//overloaded
x = x.bitAND(y);
- 160 -
Mynx Programming Language
//overloaded
x = x.bitOR(y);
- 161 -
Mynx Programming Language
var Int j to 3;
var Int i to null;
var Int j to 8;
var Int i to null;
- 162 -
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
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.
if(x == y)
x.doSomething(y);
end if;
//overloaded
if(x.isEqual(y))
x.doSomething(y);
end if;
- 163 -
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.
if(i != j)
return i;
else
return j;
end if;
//overloaded
if(i.isUnequal(j))
return i;
else
return j;
end if;
- 164 -
Mynx Programming Language
if(s in String)
this.processString(s);
end if;
The second case the in operator tests if two instances reference the same object. The operator is
equates two object references with the same instance, the in operator performs a logical check if two
objects refer to the same instance. Both variables must be of the same (or compatible?) type, as
different type of object references cannot reference the same object.
y is x; //equate y with x
if(x in y)
doSomething;
end if;
var Int j to 7;
var Int k to 8;
if(j < k)
handleInt(k);
else
handleInt(j);
end if;
- 165 -
Mynx Programming Language
var Int j to 7;
var Int k to 8;
if(k > j)
handleInt(k);
else
handleInt(j);
end if;
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.
while(c >= d)
IO.put(“c = “);
IO.put(c);
IO.putln;
end while;
- 166 -
Mynx Programming Language
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.
- 167 -
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
Both stream operators can be overloaded, and are overloaded for the core Mynx input/output
stream classes.
with mynx.core.IOStream;
- 168 -
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
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.
y = x + y;
y = x.add(y);
x.set(x.add(y));
Subtraction Operator -
The subtraction operator - is an overloadable infix operator, overloaded for the Mynx numeric types
both variable and literal.
i = i - j;
i = i.sub(j);
i.set(i.sub(j));
- 169 -
Mynx Programming Language
Division Operator /
The division operator / is an overloadable infix operator, overloaded for the Mynx numeric types
both variable and literal.
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.
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.
IO.putln(p * q);
IO.putln(p.mul(q));
- 170 -
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.
i = j ** 2;
i = j.pow(2);
i.set(j.pow(2));
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;
Decrement Operator --
The decrement operator -- is a post-operator, there is no pre-decrement operator.
var Int i to 0;
i--;
//similarly
i.dec;
- 171 -
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
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.
- 172 -
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_
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]
- 173 -
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.
- 174 -
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.
Kinds of Overloads
There are two types of operator overloads:
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.
- 175 -
Mynx Programming Language
- 176 -
Mynx Programming Language
end class;
end class;
end class;
end class;
- 177 -
Mynx Programming Language
end class;
end class;
- 178 -
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
- 179 -
Mynx Programming Language
- 180 -
Mynx Programming Language
x = x**2 + 2*y + 1
- 181 -
Mynx Programming Language
x.set(x.pow(2).add( y.mul(2).add(1) ) )
- 182 -
Mynx Programming Language
Appendices
- 183 -
Mynx Programming Language
- 184 -
Mynx Programming Language
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] 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 ‘;’
- 185 -
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
- 186 -
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 ‘‘’
- 187 -
Mynx Programming Language
Comments
* *
COMMENT := ‘//’ (UNICODECHAR) (‘\n’ | ‘\r’ | ‘\n’ ‘\r’) | ‘!!’ (UNICODECHAR) ‘!!’
- 188 -
Mynx Programming Language
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.
- 189 -
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.
- 190 -
Mynx Programming Language
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.
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
- 191 -
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.
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.
- 192 -
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
the Modified Version to whoever possesses a copy of it. In addition, you must do these things in
the Modified Version:
- 193 -
Mynx Programming Language
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.
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.
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.
M. Delete any section Entitled "Endorsements". Such a section may not be included in the
Modified Version.
- 194 -
Mynx Programming Language
N. Do not retitle any existing section to be Entitled "Endorsements" or to conflict in title with
any Invariant Section.
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".
- 195 -
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.
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
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
received copies, or rights, from you under this License will not have their licenses terminated so long
as such parties remain in full compliance.
- 196 -
Mynx Programming Language
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.
- 197 -
Mynx Programming Language
- 198 -
Mynx Programming Language
Epilog
- 199 -
Mynx Programming Language
- 200 -
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.
- 201 -
Mynx Programming Language
- 202 -
Mynx Programming Language
Credits
Credit for contributions, ideas, and thoughts in the design and formulation of the Mynx
programming language is given to:
- 203 -
Mynx Programming Language
- 204 -
Mynx Programming Language
Indices
- 205 -
Mynx Programming Language
- 206 -
Mynx Programming Language
Index of Diagrams
DIAGRAM OF SINGLE INHERITANCE ............................................................................................................ 80
DIAGRAM OF UML CLASS DIAGRAM OF MULTIPLE VIRTUAL INHERITANCE ....................................... 82
DIAGRAM OF UML CLASS DIAGRAM OF MULTIPLE DISJOINT INHERITANCE ...................................... 83
DIAGRAM OF IMPLIED METHOD................................................................................................................. 141
DIAGRAM OF AN OBVIATE CLASS ............................................................................................................... 145
DIAGRAM OF HIERARCHY OF OPERATORS FOR EXPRESSION ................................................................ 181
DIAGRAM OF HIERARCHY OF OPERATORS WITH METHODS FOR EXPRESSION ................................... 182
- 207 -
Mynx Programming Language
- 208 -
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 ............................................................................................................. 30
EXAMPLE OF MYNX SINGLE-LINE COMMENTS .......................................................................................... 31
EXAMPLE OF VARIABLE DECLARATION EXPRESSION ............................................................................... 36
EXAMPLE OF POSTFIX EXPRESSION ............................................................................................................. 37
EXAMPLE OF ASSIGN EXPRESSION ............................................................................................................... 37
EXAMPLE OF CREATION EXPRESSION ......................................................................................................... 38
EXAMPLE OF INPUT-OUTPUT EXPRESSION................................................................................................. 38
EXAMPLE OF ATTRIBUTE ACCESS SUB-EXPRESSION ................................................................................. 38
EXAMPLE OF METHOD ACCESS SUB-EXPRESSION ..................................................................................... 39
EXAMPLE OF METHOD ACCESS BY DEFAULT SUB-EXPRESSION ............................................................. 39
EXAMPLE OF ARRAY ACCESS SUB-EXPRESSION ......................................................................................... 39
EXAMPLE OF MULTIPLE ACCESS EXPRESSION STATEMENT ..................................................................... 39
EXAMPLE OF NULL STATEMENT ................................................................................................................... 40
EXAMPLE OF ASSERT STATEMENTS .............................................................................................................. 40
EXAMPLE OF FLAG STATEMENT ................................................................................................................... 41
EXAMPLE OF TRY STATEMENT ..................................................................................................................... 41
EXAMPLE OF TRY STATEMENT WITH ELSE CLAUSE .................................................................................. 41
EXAMPLE OF INVALID TRY STATEMENT WITH FLOW OF CONTROL USING RETURN ........................... 42
EXAMPLE OF INVALID TRY STATEMENT WITH FLOW OF CONTROL USING NEXT................................ 42
EXAMPLE OF EXIT STATEMENT .................................................................................................................... 43
EXAMPLE OF EXIT STATEMENT .................................................................................................................... 43
EXAMPLE OF NEXT STATEMENT .................................................................................................................. 44
EXAMPLE OF PREFIX IF STATEMENT ........................................................................................................... 44
EXAMPLE OF RETURN STATEMENT .............................................................................................................. 45
EXAMPLE OF FOR STATEMENT OVER FIXED RANGE ................................................................................ 46
EXAMPLE OF FOR STATEMENT OVER RANGE ............................................................................................ 46
EXAMPLE OF FOR STATEMENT OVER AN ARRAY ....................................................................................... 47
EXAMPLE OF A FOR STATEMENT WITH AN EXPLICIT INTEGRAL TYPE .................................................. 47
EXAMPLE OF A FOR STATEMENT WITH AN EXPLICIT INTEGRAL TYPE .................................................. 47
EXAMPLE OF LOOP STATEMENT ................................................................................................................... 48
EXAMPLE OF LOOP STATEMENT WITH PREFIX IF STATEMENT ............................................................... 48
EXAMPLE OF LOOP STATEMENT WITH EXIT IN CASE STATEMENT......................................................... 48
EXAMPLE OF UNTIL STATEMENT ................................................................................................................. 49
EXAMPLE OF WHILE STATEMENT ................................................................................................................ 49
EXAMPLE OF REPEAT STATEMENT WITH WHILE CONDITION ................................................................ 50
EXAMPLE OF REPEAT STATEMENT WITH UNTIL CONDITION ................................................................. 50
EXAMPLE OF REPEAT STATEMENT WITH PREFIX-IF AND NESTING ....................................................... 51
EXAMPLE OF CASE STATEMENT ................................................................................................................... 52
EXAMPLE OF DELIMITED LIST OF VALUES WITH A CASE STATEMENT................................................... 52
EXAMPLE OF CASE STATEMENT WITH STRING LITERAL ........................................................................... 53
EXAMPLE OF EQUIVALENT IF STATEMENTS ............................................................................................... 53
- 209 -
Mynx Programming Language
- 210 -
Mynx Programming Language
- 211 -
Mynx Programming Language
- 212 -
Mynx Programming Language
- 213 -
Mynx Programming Language
- 214 -
Mynx Programming Language
Index of Tables
TABLE OF MYNX KEYWORDS ........................................................................................................................ 27
TABLE OF ESCAPED CHARACTERS ................................................................................................................ 28
TABLE OF STANDARD META STRINGS IN MYNX ........................................................................................ 29
TABLE OF OUTPUT WITH USING A META STRING ...................................................................................... 30
TABLE OF MYNX MULTIPLE LINE COMMENTS ........................................................................................... 31
TABLE OF PRE- AND POST- CONDITIONAL STATEMENTS AND BOUNDS ............................................... 51
TABLE OF MYNX NAMESPACES ..................................................................................................................... 60
TABLE OF MYNX CLASS KINDS, INHERITANCE, INSTANCE, CATEGORY ............................................... 77
TABLE OF CLASS ELEMENT ACCESS OPERATORS ....................................................................................... 91
TABLE OF ATTRIBUTE KINDS ...................................................................................................................... 107
TABLE OF IMPLICIT SCOPE ATTRIBUTES .................................................................................................... 109
TABLE OF METHOD PARAMETER MODES TABLE .................................................................................... 111
TABLE FOR OVERRIDING A STATIC METHOD ........................................................................................... 120
TABLE OF STATIC METHOD PREFIXES ....................................................................................................... 122
TABLE SYNOPSIS SPECIAL CLASS METHODS ............................................................................................. 129
TABLE OF ASSIGNMENT OPERATORS ......................................................................................................... 150
TABLE OF LOGICAL BITWISE OPERATORS................................................................................................. 159
TABLE OF RELATIONAL OPERATORS ......................................................................................................... 163
TABLE OF STREAM OPERATORS .................................................................................................................. 168
TABLE OF MATHEMATIC OPERATORS ........................................................................................................ 169
TABLE OF ACCESS OPERATORS ................................................................................................................... 172
TABLE OF OPERATOR PRECEDENCE .......................................................................................................... 174
TABLE OF OPERATORS, PRECEDENCE, AND OVERLOADED .................................................................. 179
TABLE OF STANDARD OPERATOR OVERLOADS BY METHOD NAME .................................................... 180
TABLE OF MYNX FILE TYPES AND TOOLS ................................................................................................ 189
- 215 -
Mynx Programming Language
- 216 -