Professional Documents
Culture Documents
Programming
Language
May 2006
- 2 -
Mynx Programming Language
- 3 -
- 4 -
Table of Contents
INTRODUCTION TO MYNX AND PROXIMA...................................................... 13
A. Prolog............................................................................................................................................................14
B. Name and Project.....................................................................................................................................14
C. Manifesto.....................................................................................................................................................15
D. Target Platforms ......................................................................................................................................18
E. Principles of Design ................................................................................................................................19
F. Philosophical Statement .......................................................................................................................19
G. Goals..............................................................................................................................................................20
- 5 -
Method Parameter Modes ...................................................................................................................................38
In Parameter Mode...........................................................................................................................................38
Out Parameter Mode ........................................................................................................................................39
Var Parameter Mode ........................................................................................................................................39
Series Parameter Mode ....................................................................................................................................40
Method Traps ........................................................................................................................................................42
Method Scope ........................................................................................................................................................42
E. Class Methods............................................................................................................................................43
Method Mode ........................................................................................................................................................43
Method Synchronization......................................................................................................................................43
Method Return Type ............................................................................................................................................44
Method Headers....................................................................................................................................................44
Undefined Method Header ..................................................................................................................................44
NAMESPACES ........................................................................................................... 45
A. Declaration .................................................................................................................................................46
B. The Default Namespace.........................................................................................................................46
C. Classes and Programs within a Namespace ..................................................................................47
D. Inclusion of Classes from a Namespace..........................................................................................47
E. Multiple Sub-Namespace Inclusion..................................................................................................47
F. Declaration Order for Namespace Inclusion................................................................................48
G. The Mynx Namespace.............................................................................................................................48
H. Nonexistent Namespace Inclusion ...................................................................................................49
- 6 -
Regular Assignment Operator = .....................................................................................................................72
Cast Operator to ................................................................................................................................................73
Cast Assignment Operator := ..........................................................................................................................74
Dual Assignment Operation Operators..........................................................................................................74
Subtraction-Assignment Operator -= ............................................................................................................75
Multiplication-Assignment Operator *=........................................................................................................75
Division-Assignment Operator /= ..................................................................................................................76
Modulus-Assignment Operator %=................................................................................................................76
Bitwise-And Assignment Operator &= ..........................................................................................................77
Bitwise Inclusive-Or Assignment Operator |=..............................................................................................77
Bitwise Exclusive-Or Assignment Operator ^= ............................................................................................78
Bitwise Shift-Right Assignment Operator >>=.............................................................................................78
Bitwise-Shift-Left Assignment Operator <<=...............................................................................................79
Logical Bitwise.......................................................................................................................................................80
Logical Not Operator !......................................................................................................................................80
Logical Bitwise And Operator &......................................................................................................................81
Logical And Operator &&.................................................................................................................................81
Logical Bitwise Inclusive Or Operator | .........................................................................................................81
Logical Inclusive Or Operator || .....................................................................................................................82
Bitwise Complement Operator ~ ....................................................................................................................82
Bitwise Shift Left Operator << ........................................................................................................................82
Bitwise Shift Right Operator >> .....................................................................................................................83
Logical Exclusive Or Operator ^.....................................................................................................................83
Relational ...............................................................................................................................................................84
Equality Operator == .......................................................................................................................................84
Inequality Operator != .....................................................................................................................................84
Instance Type Of Operator in..........................................................................................................................85
Lesser Than Operator < ...................................................................................................................................85
Greater Than Operator > .................................................................................................................................86
Greater Equal Operator >=..............................................................................................................................86
Lesser Equal Operator <=................................................................................................................................87
Stream ....................................................................................................................................................................88
Insertion Operator <<< ...................................................................................................................................88
Extraction Operator >>> .................................................................................................................................88
Mathematic ............................................................................................................................................................89
Addition Operator + .........................................................................................................................................89
Subtraction Operator - .....................................................................................................................................89
Division Operator /...........................................................................................................................................90
Modulus Operator % ........................................................................................................................................90
Multiplication Operator * ................................................................................................................................90
Exponentiation Operator ** ............................................................................................................................90
Increment and Decrement Operator -- or ++ ...............................................................................................91
Return Types for Mathematical Operators....................................................................................................91
Access .....................................................................................................................................................................92
Method Invocation . .........................................................................................................................................92
Attribute Access `..............................................................................................................................................92
Array Access []...................................................................................................................................................93
Operator Precedence ............................................................................................................................................94
C. Operator Overloading ............................................................................................................................95
Operator Overload Declaration...........................................................................................................................95
Kinds of Overloads................................................................................................................................................95
Implicit Upward Cast ...........................................................................................................................................95
Rules for Operator Overloading..........................................................................................................................97
Table of Operators ................................................................................................................................................99
Standard Method Names for Overloads ..........................................................................................................100
Implicit Hierarchy of Operators........................................................................................................................101
- 7 -
SPECIAL METHODS OF THE CLASS.................................................................. 103
A. Advanced Method Definition and Use ...........................................................................................104
B. Static Methods.........................................................................................................................................104
Kinds of Static Methods .....................................................................................................................................104
Overriding a Static Method ...............................................................................................................................104
Prefix for Static Method .....................................................................................................................................107
Program Methods as Default Static..................................................................................................................108
C. Implicit Static Method .........................................................................................................................108
Inclusion...............................................................................................................................................................108
Reference .............................................................................................................................................................109
D. Method Equivalents: Low Fat Methods.........................................................................................110
Default Parameters by Method Equivalents....................................................................................................111
Export Instance Method ....................................................................................................................................112
Renaming All Class Methods of a Name..........................................................................................................112
Accessor Methods ...............................................................................................................................................113
Implicit Accessor Methods ............................................................................................................................114
Explicit Accessor Methods.............................................................................................................................114
E. Class Creation, Destruction, and Default.....................................................................................116
F. Constructor ..............................................................................................................................................116
Constructor Definition .......................................................................................................................................116
Constructor Invocation ......................................................................................................................................118
G. Destructor.................................................................................................................................................120
Destructor Definition .........................................................................................................................................120
Destructor Invocation ........................................................................................................................................121
H. Default Class Method............................................................................................................................121
Default Method Declaration ..............................................................................................................................122
Default Method Invocation................................................................................................................................122
I. Incomplete Methods .............................................................................................................................123
J. Other Special Methods.........................................................................................................................123
- 8 -
STATEMENTS.......................................................................................................... 139
A. Computation ............................................................................................................................................141
Expression Statement.........................................................................................................................................141
Declaration.......................................................................................................................................................141
Expression........................................................................................................................................................141
Postfix ...........................................................................................................................................................141
Assignment ..................................................................................................................................................142
Assign .......................................................................................................................................................142
Create........................................................................................................................................................142
Input-Output ...........................................................................................................................................143
Access ...........................................................................................................................................................143
Attribute ...................................................................................................................................................143
Method .....................................................................................................................................................144
Array .........................................................................................................................................................144
Multiple ....................................................................................................................................................144
Null Statement ....................................................................................................................................................144
B. Error ...........................................................................................................................................................145
Assert Statement .................................................................................................................................................145
Flag Statement ....................................................................................................................................................145
Try Statement ......................................................................................................................................................145
C. Flow of Control .......................................................................................................................................147
Exit Statement .....................................................................................................................................................147
Next Statement....................................................................................................................................................148
Prefix If Statement..............................................................................................................................................148
Return Statement................................................................................................................................................149
D. Repetition..................................................................................................................................................150
For Statement ......................................................................................................................................................150
For Statement over a Range: .........................................................................................................................150
For Statement over an Array .........................................................................................................................151
For Statement over Other Integral Type......................................................................................................151
Until Statement ...................................................................................................................................................152
While Statement..................................................................................................................................................152
Equivalence between While-Until ....................................................................................................................153
Repeat Statement................................................................................................................................................153
Pre-conditional and Post-conditional Loops ..................................................................................................154
E. Selection ....................................................................................................................................................155
Case Statement ....................................................................................................................................................155
If Statement .........................................................................................................................................................156
F. Mutex Statement ....................................................................................................................................158
- 9 -
ARRAYS .................................................................................................................... 173
A. Array Attributes......................................................................................................................................174
B. Declaration ...............................................................................................................................................174
C. Creation .....................................................................................................................................................174
D. Initialization ............................................................................................................................................175
Implicit Integral Indexed List ...........................................................................................................................175
Explicit Indexed List...........................................................................................................................................175
Using Default Constructor .................................................................................................................................175
Deferred Creation ...............................................................................................................................................176
Initialization with a Constructor.......................................................................................................................176
Null in Declaration..............................................................................................................................................177
E. Using an Array ........................................................................................................................................177
Using an Element................................................................................................................................................177
Using as an Object ..............................................................................................................................................178
Passing as a Parameter.......................................................................................................................................178
F. Array as a Mynx Class...........................................................................................................................178
REFERENCES.......................................................................................................... 201
- 10 -
INDEX ....................................................................................................................... 203
- 11 -
- 12 -
I
Introduction to Mynx and Proxima
- 13 -
A. Prolog
The myriad of programming languages available (and the plethora of programming languages that will be
created long in the future) underscores that for software there is no one universal programming language,
nor that “one size fits all.” Two frequent comments on anything creative, inventive, or new are: “I don’t
see the need” and “why would you want to another one, with so many out there?” Fortunately, as Finnish
composer Jean Sibelius once said, ”No statue has ever been created for a critic.” If the world followed
those views, all software would be in the native machine code for the platform, no need for a new
programming language, and there would be only one out there.
For each programming language, there is often a story, reason, an impetus for the language. Niklaus
Wirth created Pascal out of frustration to the slow standardization of Algol68. Bjarne Stroustrup created
C++ to have the C programming language but with objects. Larry Wall created Perl out of a need for a
scripting language above shell scripts that could handle text with ease. Ada was an attempt by the United
States Department of Defense to make a state of the art language for defense and military projects, and
cut software costs. The reasons and motives for a programming language can serve as a way to understand
the programming language itself within the creator’s context. The “what” of a feature in a programming
language can be less important than the “why” for a programming language.
Summary: The Mynx programming language is a general-purpose, modular, portable, high-level, strongly
typed object-oriented programming language.
Project: Proxima is the name of the overall project to implement a new programming language and the
compiler, which uses new methods for compilation into another high-level programming language.
Proxima is named after the star the spacecraft was trying to reach in the movie “Event Horizon” and is
Proxima Centauri. The Sun's nearest known stellar neighbor is a red dwarf star called Proxima Centauri,
at a distance of 4.3 light years away. Like the nearest star to our solar system, the goals are far enough
away but not so far away without some possibility of success.
Programming Language: Mynx is the name of the programming language that is implemented by the
compiler, and is specified with a grammar, design philosophy, and user manual, and programming
language report.
Mynx is an amalgamation of two cat breed names, Lynx and Manx. M+Y+NX (the NX is from both…)
The Manx cat has no tail, and the Lynx is a aggressive wildcat…Mynx is meant to reflect qualities of both
names, unusual like the Manx, but still having some of aggressive properties of the Lynx.
- 14 -
C. Manifesto
The primary design criteria and aims for the Mynx programming language that are:
1. Distinguish attributes from methods within a class. Death to the Dead Parenthesis:
myMethod() or stack.pop(). Dottic notation, dot for method invocation, a tic for
attribute access.
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;
- 15 -
7. Eliminate duplication of types, 32-bit int to 64-bit long, 32-bit float to 64-bit double.
No L suffix, or f suffix to indicate if float or long types. Only int and real types, 64-bits.
Also byte type, and enumerated Bool type of true, false.
8. All things are objects, no primitive types that are not objects as in Java, no boxing and
un-boxing of objects as in C#.
10. Controlled operator overloading with the ability to lock the overload of a method.
11. More rich control of parameter passing, no default reference pass by value of address
of reference like in Java. Explicit in, out, var, and own passing quantifiers. And
varying parameters with series.
12. Disjoint multiple inheritance to permit code re-use, without just specification of
methods to implement (Java interfaces).
13. Explicit naming of constructor, destructor in classes. Class name is not used as
constructor name in declaration and definition of a constructor.
14. The self parameter to represent class in a generalized way for types. A clone() or copy
method would return self rather than Object that is cast.
15. Create local versions of variables that are not allocated from the heap, and only have
the scope and lifetime of the method. Local or own methods similar to own
parameters.
16. Explicit scope of methods for class attributes and methods for internal visibility.
Dual forms of access control, external to a class, and scope within a class. #9.
17. Concept of levels of programming language compliance, so that the language can be
used in different programming venues, such as embedded where a GUI library is not
required, or in a distributed environment.
Level 0 is the core language, with additional modules written in the language, which
can be built for a platform. proxima.core.*;
18. Everything is a class, no alternative structures, such as interface (in Java) and struct
(C# and C++).
19. No special package or within a module access to class attributes or methods. All
access is private, protect, public.
20. Default method specification for a default behavior of a class. Do not state what is
apparent, such as no return type implies void type.
21. No half-sided statements, what is implicit can be stated explicitly. Java has synchronized,
keyword sync, but not a unsynchronized. C# has var and ref parameters, but no default in
parameter. Synch and asynch for methods, variable and constant for attributes.
- 16 -
22. Method equivalents, if method is overloaded in optional arguments, do not specify
in declaration (C++), or require wrapper methods (Java). i.e.
class example is
public myMethod(int x, int y) is
end myMethod;
//C++
public myMethod(int x, int y=0) is ...
//Java
public myMethod(int x) {
this.myMethod(x,0);
}
- 17 -
D. Target Platforms
Mynx is intended to be its own programming language, incorporating features from other programming
languages, and having newly unique features of its own. Mynx is not intended to “clone” either Java or C#,
or another successor language to C++. The major intention is to have a programming language for both
platforms, with a feature set, and conceptual model that is not specific to any platform.
The two major platforms targeted for Mynx are initially the Java platform of the Java Virtual Machine
(JVM), and the .NET Common Language Runtime (CLR). Later, taking advantage of native translations of
Java to machine code, and re-implementing the source generation, other platforms can be targeted, using
C and C++.
Mynx generates high-level source in either Java or C# for the respective platforms. Java is intended to be
as wide an audience as possible, targeting JDK 1.1.x. Another reason for the Java backward compatibility
is to avoid Mynx classes, libraries, and packages from becoming “wrappers” around either
implementation language. Over time, and hopefully with a large audience for contributions, comments,
and input Mynx will develop standard libraries for such things a graphic user interfaces (GUI’s), and other
modules.
C# is used for the .NET platform and is similar enough but not identical to Java to allow mirroring similar
code generation. (Although in theory J# could be used for both...). Depending on the compilation mode,
both Java and C# source can be generated, and then the code compiled to produce byte code or IL code
for either platform. The high-level source code uses classes in modules written in both languages to
“bootstrap” the core class library, and the high-level source implements features of the Mynx
programming language statements, expressions, classes, and programs. Another reason to use source
generation is to leverage the existing compilers for both languages, although a major design goal is to
integrate an open-source free compiler into the Mynx software development kit (MDK).
- 18 -
E. Principles of Design
There are six major design principles upon which the Mynx programming language is based. Those design
principles, not in order of importance, are:
1. Implicit-explicit principle. A programming language should have implicit features that do not
have to be stated, but can be. Too often, programming languages have a feature in the source
code that is stated by not stating it.
3. Explicitness by user, but not by design. Some programming languages will create implicit
features if not specified. If the user wants to automatically be given a feature, it should be by
the tool, not within the programming language design. (Java gives default null constructor,
C++ gives the copy constructor. Methods in both languages have an implicitly given access
associated.)
4. Consistency of syntax. A programming language should be consistent in syntax, and not have
constant exceptions to rules for different programming language entities or concepts. (C++
the for loop syntax is different from a simple while, and a do-while is very syntactically
different.)
F. Philosophical Statement
Mynx is a programming language is not meant to be an end unto itself. Mynx follows the idea to
implement software by a user that allows for software within a domain to focus on the domain, and not
the programming language or the platform. Thus, Mynx is an aggregation of concepts, not one concept
that is used by fiat to clarify programming language design issues, often times slavish following of a single
principle to surmount a recurrent problem can create yet another problem.
- 19 -
G. Goals
There are five major goals for the Mynx programming language that are:
1. Pedagogy: A programming language to teach and learn concepts but still usable (i.e., not a toy
language compared to a “real” programming language used in software development.)
3. Platform Portable: A programming language to target two major platforms, Java and .NET,
and be source compatible on both.
5. Personal: A programming language of my own for my use, and as a base to do research into
programming language and software engineering.
- 20 -
II
Basic Lexical Elements
- 21 -
The Mynx programming language Mynx has the elementary building blocks, which are the basic elements
of identifiers, keywords, literals, meta-strings, operators, and comments.
A. Identifiers
Identifiers are case sensitive names that use characters, of any length in Mynx, but with at least one
character. An identifier must begin with a letter character, followed by another letter character, digit, or
underscore.
Example Identifiers:
B. Keywords
Keywords are identifiers, but are reserved words for use by Mynx. There are a total of 66-keywords in
Mynx, all except four are used in the syntax of the programming language. The Mynx keywords are:
The keywords goto and new are not used, but are considered keywords to prevent usage. The use of the
keywords goto and new as the name of a variable, constant, class, or program can be confusing and
misleading. The keywords enum and type are reserved the same reason to avoid confusion in type or
enumeration definition. Since four keywords are not used in Mynx, there are effectively 61-keywords.
C. Literals
Literals are actual data for characters, strings, integers, and real numbers. A literal can be thought of as an
unnamed (not associated with an identifier), anonymous constant of an instance type. Literals are to the
Mynx compiler effectively an anonymous constant, a constant value with no name.
Literal characters with the at-sign ‘@’ or the question-mark ‘?’ are invalid literals, except as a character
literal ‘@’ or ‘?’ or within a string literal. The at-sign ‘@’ is reserved for possible future use in Mynx
possibly as meta-code for classes.
- 22 -
D. Symbols
A literal character is enclosed in single quotes, a string with double quotes. A literal character uses a single
symbol; a string is a sequence of multiple symbols. There are nine special “escaped” character literals that
are delimited with the ‘\’ escape character.
Character Description
\b Backspace
\f Formfeed
\n Newline
\r Carriage Return
\t Tabulation
\u Unicode Prefix
\\ Slash (Escape Character)
\” Double Quote or Parenthesis
\’ Single Quote or Apostrophe
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
E. Numbers
Numbers are represented without any quotation. A number is either decimal (base 10) or hexadecimal
(base 16); a hexadecimal number is prefixed with the two characters of ‘0X’ and the remaining hex digits
are all uppercase.
- 23 -
A numeric real literal (which is the default for non-integer number literals) is 64-bit, a float is 32-bit, and
is indicated with a trailing capital ‘F’ to indicate a float numeric literal. Both a numeric real and float must
begin with a digit.
F. Meta Strings
A meta string is the Mynx partial replacement for the macro system of C/C++. It does not attempt to
replace or define macros for conditional code inclusion, or textual substitutions. Meta strings are
equivalent to the the __FILE__ and __LINE__ macros.
A meta-string is a string identifier in uppercase, beginning with the hash or pound sign #. A meta string is
substituted with the information it represents. A meta-string allows for information about the source
code, but without the manual effort to represent it, or the overhead of changing it when the source code is
revised. There are 19-standard meta strings in Mynx.
- 24 -
Mynx does not specify the format for the substituted literal strings for the meta strings, this is
implementation specific. If a meta string is used but is inappropriate (such as #PROGRAM in a class), then
the string is the “UNDEFINED” literal string text.
end class;
The output for calling aMethod with the class metaStrExample is:
Module is default
Method name is aMethod
Class is metaStrExample
This meta string is UNDEFINED
Programmer defined meta strings are not supported, as then source code would contain undefined meta
strings which would need to be defined in the source, essentially creating a macro system (which Mynx is
trying to avoid without sacrificing some convenience) indirectly.
G. Operators
There are 44-operators in Mynx that represent the non-character symbols used to create expressions and
statements. The operators are classified into five categories:
1. Assignment
2. Logical and Bitwise
3. Relational
4. Stream
5. Mathematic
The operators can be overloaded, excluding the assign-mathematical operators, and the word operators of
as, in, is, to. Most of the operators are already overloaded in the core library of Mynx classes.
- 25 -
H. Encoding
Mynx uses Unicode 16-bit character encoding, hence literals and identifiers can use non-Roman alphabet
letters. However, for portability to other platforms, Mynx uses the Roman alphabet letters and Arabic
numbers in the syntax and grammar, and portable software written in Mynx is recommended to do the
same.
I. Comments
There are two kinds of comments in Mynx: single-line, and multiple-line. Comments can encompass any
symbols or characters, comments are ignored in Mynx, although other tools such as documentation
generators might process the comments.
Single Comments
Single-line comments are one comment for a line, beginning with the comment prefix of two slashes //,
and ending at the end of the line. The single-line comment syntax is the same as for C++ and Java, for
familiarity.
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.
Comments are normally ignored by the Mynx compiler, but for documentation, then comments are
processed with the specific documentation XML tags.
- 26 -
J. Enumerated Types
An enumerated type is a named discrete set of named constants that are treated as a unique type. Each
constant has a non-negative integral value, and a string name. The Mynx programming language has
neither a predefined language construct for defining types (like the C programming language typedef
declaration), nor to define an enumeration or enumerated type (like the C programming language enum
declaration) either.
The reason is to avoid defining in the programming language that which can be defined using a class and
other features of the Mynx programming language, such as static inclusion of a class, and operator
overloading. Both the keywords enum and type are reserved words, to avoid creating classes, attributes,
constants, variables, or methods with those names and cause confusion.
- 27 -
- 28 -
III
The Primary Elements: Program
and Class
- 29 -
There are two major top-level programming elements in Mynx, which are:
A program is distinguished from a class, as a program is not re-useable, nor can a program be used as an
object in another class or program. Conversely, a class is the element of re-use, but can not be used as an
application or program. Mynx distinguishes from C++ and Java where an application is a class, and so can
be used other than as an application.
A. Program
A program is a basic element of an application, and is block structured, with a header and footer
surrounding the program body. Enclosed within the header and footer is the body of the program.
The program header contains the name of the program, and specifies which method in the body acts as
the main method of the program. The program name will always precede the name of the main method in
the program header.
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.
B. Class
A class is a basic element of a library for code use and re-use. A class is block structured, with a header
and footer. The body of the class is enclosed within the header and footer, and the body of a class can be
empty.
The class header defines the type or kind of class, the class name, and a comma-delimited list of any
parent classes the class inherits. For some classes, there is an implicit parent class provided by default
through Mynx.
- 30 -
Example Class Header:
class doIt is
class Void as null is
class subClass as parent is
abstract class AClass is
default class example as
virtual class VMyClass as Void, VObject, VCompare is
class intStack as Void has genericStack to Int is
C. Kinds of Classes
The class, as a basic unit for a library emphasizes use and re-use. There are two ways to utilize a class in
Mynx:
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.
- 31 -
D. Abstract
An abstract class is similar to a virtual class; however an abstract class cannot be instantiated to create an
instance, or have a sub-class cast to the abstract class. An abstract class can provide partial
implementation, and have attributes within the class. Abstract classes are useful to provide easily defined
common functionality to be used by sub-classes.
E. Constant
A constant class can be used and instances created, but it cannot be inherited or sub-classed for re-use. A
constant class is useful as an invariant, so that other sub-classes with other functionality can be avoided,
only multiple instances.
F. Default
A default class is by its class modifier name, default if no class kind is specified. A default class can be sub-
classed through inheritance for re-use, and instances created for use in a class or program.
G. Generic
A generic class is an almost complete class, except for the type, so a generic class, like an abstract class,
provides an implementation. A generic class is a parameterized type class, a polymorphic type class.
A generic class can be bound to a class type, which can be used as an instance. The generic class is useful
to define type-independent classes, to avoid re-implementation of functionality, or much type conversion
and coercion.
H. Singular
A singular class is both constant and static, so can never be sub-classed through inheritance for re-use.
Nor can instance be created for use; there is only the single static class. A singular class is somewhat like a
program in that it never can be used to instance or inherit from as a parent class.
I. Static
The static class can be inherited for re-use, but can not create an instance for use. There is only one
existing instance of a class, the single static instance. A static class is useful for a class in which only one
instance is required to prevent duplicate instances from existing and being unsynchronized.
J. Virtual
The virtual class is useful to specify methods, and to tag another class for functionality. A virtual class
contains only method signatures, specifying name, return type, and any parameters to the method. A
virtual class while without an instance, it can be cast upward to an instance of a sub-class.
The super-parent root class in Mynx, the class Void, is a virtual class, which defines no methods. Because
Void is the super-class of all classes, any object reference Void can refer to any possible instance of a
class, but cannot use any methods, as Void defines no methods.
- 32 -
IV
The Minor Elements: Attributes
and Methods
- 33 -
There are two minor elements that are used in the body of a class or program. The two minor elements
that define the functionality of a class or program are:
A. Attributes
Attributes are the data of a class, or the variables of a program, and are instances of other classes being
used within the class or program.
All attributes have mode, kind, type, and a name. Attributes must have an initial value, and can be scoped
(hidden or made accessible) within a class or program.
Attribute Mode
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.
Attribute Type
Attribute type is simply the class for which the instance is created, and must be given explicitly. The kind
of class can not conflict with the attributes use as an instance, such as a singular class used as an attribute
type.
Attribute Name
The attribute name is an identifier used to bind an instance object of the type class to the attribute
through a name. Each attribute name must be unique from other attributes, and a declaration of an
attribute can have multiple names.
- 34 -
Initial Value
All attributes initialized explicitly, either by equivalence with a value, or through parameters to the
instance. Multiple attributes declared can all be initialized to the same value. The initial value can be a
literal, static attribute of a class, or a call to a static method, or a mixed expression of literals, static
attributes, and static methods. The keyword null can be used as an initial value, indicating the object
instance reference refers to nothing in the initial value. Initial values can not be initialized with non-static
attributes, as the order of attribute initialization is not specified nor guaranteed by Mynx.
Attribute Scope
Attribute scope is used to control visibility of attributes to methods within the class or program. Attributes
can optionally be scoped by hiding the attribute from methods, or exposing an attribute to methods.
Attributes are checked for visibility by a method if accessed, and a method that can not access an attribute
will generate an error. Attribute scope is internal to a class or program, so inapplicable outside a class or
program.
The scope expression of an attribute declaration begins with whether the attribute is inclusive or exclusive
to methods. Attributes that are inclusive or visible use the keyword in, and attributes that are exclusive or
hidden use the keyword out. Then it is followed by the keyword for, and the method list.
Two special methods are all and null; these special method keywords are to avoid the need to list all
class methods, and to explicitly have a means to say no method of the class.
An attribute can exclude all methods, and a method can include null or nothing, hence can not be called
from within a class or program.
Both scope expressions are the same, making an attribute implicitly accessible for all methods.
- 35 -
B. Program Attributes
Program attributes are declared with the keyword let prefixing or beginning the declaration. The rest of
the declaration is the required program attribute kind that is a variable or constant, followed by a
regular attribute declaration. Program attributes are static in nature, either variable for modification
within the program, or constant for a final program attribute. Similar to a class attribute, program
attributes must be initialized to a starting value.
C. Class Attributes
Class attributes are declared by the external access keyword. Class attributes can be accessed by other
classes using the class as an instance object. There are three kinds of access:
The remainder of a class attribute is the standard declaration, similar to a program attribute.
All class attributes must be initialized when declared; there are no default initial values for a class
attribute of a type. The initial value must be of the same type, not a super-type or sub-type, and initialized
in the attribute declaration.
D. Methods
Methods are the means to change the data of a class or program, and provide the functionality of a class. A
method has three elements:
- 36 -
Program Methods
A program method is preceded by the keyword method, with the rest of the method header declaration
following, and ends with the is keyword. A method declares a return type, which is a class to be returned
by a method, if the method is defined as a function. A program method is of the class method mode
singular, static and constant. As a program can never be inherited or overridden, it follows the methods
are immutable and program wide.
A method can declare a return type of void, which declares the method returns nothing, or is a
procedure. If a method does not explicitly state a return type, an implicit void (the method as a
procedure) is used as the return type. Note that the return type void is nothing, but the return type of
Void is the root virtual parent class Void. Both are entirely different entities.
Following the return type is the name of the method, which must be a valid identifier.
Class Methods
A class method is similar to a program method, except it must declare the class access to the method
before all other method elements. Like class attributes, there are public, protect, and private methods.
Parameter List
After the method name, the parameters to the method are specified, the name and parameter list form the
“method signature” which is used to identify a method within a class.
No two methods can have the same signature (note that two similar methods can have different return
types...). Unlike other programming languages, a method with no parameters does not use a pair of “dead
parenthesis” or dead parens “()” trailing after the method name.
A parameter list that is non-empty begins with an opening parenthesis ‘(‘ and ends with a closing
parenthesis ‘)’ with a list of parameters separated by a comma. Each parameter is specified by
parameter mode, the class or object type, and the parameter name within the method.
- 37 -
Method Parameter Modes
There are four kinds of method parameters, each with a unique keyword:
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.
temp = first;
first = last; //error immutable reference, unchangeable
last = temp; //error immutable reference, unchangeable
end swap;
- 38 -
Example of using the defined method:
var Int i to 7;
var Int j to 3;
var Int k to null;
swap(i,j);
swap(j,k); //error in parameter can not be null
swap(k,i); //error in parameter can not be null
A general-purpose method swap is not possible using an in parameter mode. The parameters are
immutable, and are not nullable.
An out parameter can be null as it is intended to return information from a method, and the object
reference is variable so can change. Hence changes to the parameter object by its methods are global and
passed back. An out parameter is used to return information from a method.
temp = first;
first = last;
last = temp;
end swap;
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.
A var parameter is like an out parameter, except that it can not be null, and is used like an in to pass
information to a method, but also to return data from a method. A var parameter changes information to
- 39 -
pass information in and out, so a var parameter is non-constant or is mutable. Like the in and out
parameter, a var parameter changes are global and propagated back from a method.
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.
A series parameter is like an in parameter, but takes multiple parameters, and within the method is a
1-dimensional array of those parameter types. A series parameter is useful for a variable or optional
varying list of parameters to a method. A series parameter can be null for 0-parameters, but no
information can be returned by a series parameter list. Hence a series parameter list even when null
is constant.
- 40 -
Example of series parameter in use:
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);
- 41 -
Method Traps
A method, following a parameter list (if any...) then lists the traps (or exceptions...) flagged by a method.
Traps are flagged within a method, and if not handled, are propagated back as an error report.
Declaring a method to flag a trap requires that any calls to the method must handle the trap with a try
statement. A method can flag a trap without declaring it, forcing the handling of a trap is independent of
flagging the trap within the method.
A method declares any traps flagged as an identifier list (the actual traps are classes which are defined...)
which begins with the has keyword. The list of flagged traps must declare at least one, without any limit
on the number of possible traps flagged.
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.
- 42 -
Example program method headers:
E. Class Methods
A class method is similar conceptually to a program method, but a class method has different features
from the fact it is a method of a class, a means for extending and re-using functionality.
There are three special kinds of class methods, relating to class creation, destruction, and implicit use.
These special methods are:
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.
- 43 -
The asynchronous mode is the default synchronization mode used, and is explicitly declared with the
async keyword. The synchronous mode is declared explicitly with the sync keyword before a class
method header.
A synchronous class method for multi-threaded, thread safe methods creates an overhead for invoking
and using a class method. A synchronous method creates a lock on a method, ensuring that a method used
has only one thread executing the method at a time.
A method can declare a return type of generic indicating the type returned is generalized or generic, but
this is only for a generic class. If no return type is specified, the type is implicitly a void type. The method
return type is not part of the method signature.
Method Headers
Need discussion
Since virtual and abstract methods are not completely defined, only the method headers, the parameter
lists that form the method signature specify only parameter mode and parameter type. The parameter is
not a variable when used in declaring an undefined method. So for an undefined method which is virtual
or abstract, the parameters are unnamed. Nor can an undefined method header specify scope, as the
method will be implemented and defined with scope in a sub-class. Undefined method headers are only
possible for classes, not programs.
- 44 -
V
Namespaces
- 45 -
The namespace concept is organizing classes and programs into a hierarchy based upon a module name to
give unique names to a class or program. A namespace helps to modularize classes and programs so that a
more descriptive full namespace name can be given, rather than a simple name to an individual class or
program. Mynx requires an explicit namespace, or else a default namespace is implicitly given (unless of
course the default namespace is explicitly used...).
A. Declaration
A namespace, if explicitly declared is the first statement in a Mynx source file. A namespace is declared
with the module keyword, followed by the name of the declared namespace, with a closing semicolon ‘;’
to terminate. The declared namespace is a series of a least one identifier, each of which is delimited or
separated by a dot ‘.’ or period. The declared name of the namespace can not contain Mynx reserved
words or keywords, except in one specific case. For a unique namespace, an internet name in the form of
“domain extension, domain name...” followed by specific namespace name to identify the classes
organized within the namespace.
module mynx.core;
module com.williamgilreath.util;
module de.daslangeheisse.package;
module info.mynx.tools;
module one_big_long_namespace0;
module default;
module default.more.added; – invalid, default only
module prefix.default; – invalid, default only
module default.module; – invalid, default only and using keyword
- 46 -
C. Classes and Programs within a Namespace
Classes and programs are organized around namespaces, following a namespace declaration, either a
program or a set of classes is declared within the same Mynx source file. As a class and program are
mutually exclusive, and non-nest able (a program and class can not contain another inner class), the
namespace provides the full class or program name.
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 ‘;’.
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.*;
The namespaces:
module example;
module example.first;
module example.first.second;
- 47 -
Using the namespace:
with example.*;
The namespace will include all classes within the example namespace; however it does not include any
sub-namespaces that are nested. To include sub-namespaces, a namespace must specify the sub-
namespace.
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.
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.
- 48 -
H. Nonexistent Namespace Inclusion
A with statement directs Mynx to use a namespace when determining which class to reference for a
declaration and use within a class or program. If a with statement directs Mynx to use an absolute
namespace that does not exist, it will create a semantic compiler error.
- 49 -
- 50 -
VI
Inheritance and Class Types
- 51 -
A. Concept of Inheritance
Inheritance is used to create a new class, and to re-use existing Mynx source code in the form of pre-
existing classes. There are four types of inheritance, each with restrictions and requirements for use. All
classes must inherit a super class when defined. A program however, is not a class nor does it use a super
class, so it never inherits a super class.
B. Types of Inheritance
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.
For a concrete class implementing multiple virtual classes which inherit null, then there is no overlap in
specified methods of class functionality. This can be important in multiple disjoint inheritance, when
multiple abstract classes that can partially implement methods are used. By and of itself with virtual
classes, multiple inheritance of virtual classes is not syntactically or semantically erroneous, as only one
declared method is implemented in the concrete class.
- 52 -
Single
Single inheritance is a standard type of inheritance; in Mynx single inheritance is inheriting one parent
class, an abstract, default, or virtual class. For a default or normal class, single inheritance is the only kind
of inheritance possible.
with mynx.core.*;
//...class body...
end class;
- 53 -
Multiple Virtual
Multiple virtual inheritance uses multiple virtual classes to inherit a set of specifications essentially. This
is akin to Java's multiple interface inheritance, although for Mynx it is a virtual class instead of an
interface. Multiple virtual class inheritance allows for multiple methods, which can overlap, but the sub-
class must implement each method once. The methods must be similar in return type, if similar in name
and parameter signature. Any overlaps in similar method signatures must be exact, or otherwise there is a
return type conflict.
The drawback of multiple virtual inheritance is that functionality can overlap, but it is only declared or
specified, not defined in the virtual classes inherited by the sub-class.
with mynx.core.*;
- 54 -
UML Class Diagram of Multiple Virtual Inheritance
Multiple Disjoint
Multiple disjoint inheritance is multiple inheritance, but is restricted to abstract classes which declare and
define functionality, and that the methods of the inherited abstract classes are disjoint, or mutually
exclusive with no overlapping method signatures. An abstract class must define functionality, but no
constructor to avoid super-class reference ambiguity. A primary reason for an abstract class not having a
static method is to avoid overlapping class methods in multiple disjoint virtual inheritance.
It is possible to mix multiple disjoint inheritance with multiple virtual inheritance, following the
constraints of both. If an inherited abstract method is abstract or undefined, then the sub-class must
implement the declared but not define the method. Multiple disjoint inheritance can be used with single
inheritance, the caveat being that the super class is likewise disjoint from the multiply inherited abstract
classes.
//...class definition...
end class;
- 55 -
UML Class Diagram of Multiple Disjoint Inheritance
The partial classes are the abstract, generic, and virtual. Partial refers to an incomplete or partial class
definition. The partial classes can only inherit other partial classes, or become sub-classed (inherited by a
default class) to a non-partial class. The kinds of classes the partial classes can inherit for each class kind
are:
1. abstracted – abstract, virtual class inheritance
2. generic – generic inheritance
3. virtual – virtual inheritance
- 56 -
The default classes consist of only a default class. The default class is a concrete, fully defined, class. It is
the conventional or normal class. The default class can only inherit other default classes.
The restricted classes are the constant, singular, and static classes. Restricted refers to that the classes are
restricted in capability to inherit other classes, or be sub-classed. Only the static class can inherit another
static class, the singular and constant classes can not inherit other classes as both are constant so non-
inheritable. A synopsis for the restricted class inheritance is:
When a class is inherited, there are three class elements that are possibly inherited:
1. attributes
2. methods
3. operator overloads
Attributes
Attributes are inherited by a class, but if attributes in the sub-class “shadow” or mask attributes in the
super class, then it is a semantic error with inheritance. Attributes should be encapsulated within a class
as private or protected, or public if a constant.
end class;
end class;
- 57 -
Methods
Methods are inherited by a class, and super class methods, if not constant, can be either overridden or
overloaded. If a super class has an abstract or virtual method, the sub class must implement the method
unless the sub class is abstract.
A common concern in object-oriented is methods being covariant, contra variant, or invariant. Mynx uses
invariant methods in inheritance, effectively do not care about variance in methods in inheritance with
classes. Overloading requires a unique set of parameters for each method definition, but excludes the
method type. Overriding requires an exact method signature including the method type to override an
existing method.
E. Inheritance of Methods
Class methods can be overridden, or overloaded in a class by inheritance. The special methods of a class,
the constructor, destructor, and default method are never inherited, nor overridden in a class that is
inherited. A class must define its own constructor, destructor, or default method; a class can reference a
parent class constructor, destructor, or default method in its definition, but it must always define its own,
none is every inherited. Overriding a method is to redefine the method in a sub-class of the parent class.
Overloading is to define more than one kind of method with the same method name.
F. Method Overriding
Method overriding re-defines a method in a sub class in terms specific for that sub class. A method
overrides a super class method if it has the same method signature. A method can override a super class
method even if the return type of the method is different from the return type of the parent method.
Methods can override a super class method, except for the super class constructor, destructor, and default
method. A constructor, destructor, or default method can be included by method equivalence from the
super class (although it is not method overriding, it is method equivalence).
2. A method override can only increase the level to public from protect access, or retain the
same access level. A private method is never visible to be inherited and overridden in a sub
class.
3. A method override can only be the same mode such as static, default, generic. A
constant or singular method can never be overridden.
4. An overridden method with a self type for the method type must use the class name as the
type when overridden.
5. An overridden method must use the same parameter signature including the return type
(except in the case of a self type), as Mynx does not support contra variant typing, but
invariant.
- 58 -
Example of Method Overriding with Inheritance:
end class;
end class;
The four rules for covariant method return type override are:
1. A covariant return type method must match the parameter list or the signature of the super-class
method exactly. More simply put, the parameter list of a method is invariant even if the return
type is covariant.
2. The return type of a method that is overridden must be a sub-class of the return type in the super-
class method.
3. The return type of a super-class method that is overridden cannot be void return type, nor can
the return type of the sub-class class method. (A method which returns void is a procedure, so is
invariant by definition.)
4. A method must be an instance method available in the super-class to be overridden, hence cannot
be constant, singular, or static.
5. Invariance of abstract self method; the return type of a super-class method that is overridden
cannot be self return type, nor can be the return type of the sub-class method. (A self return type
is used in an abstract class so is abstract and based upon the sub-class type.)
- 59 -
Example of Covariant Method Override of an Implied Method:
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.
- 60 -
I. Method Overloading
A super class method can be overloaded in a sub class with a similarly named method but with a different
method signature. Method overloading can apply to constant methods which can not be overridden, but
are overloaded in the sub class. A method can be overloaded within a class without inheritance.
end class;
end class;
- 61 -
J. Operator Overloading
Overloaded operators in a sub class do not inherit the super class overloaded operators. However,
constant operators can not be overloaded in the sub class, and so by implicit upward cast (which is
implicit) apply to the sub class. In effect, the constant operators of a super class are implicitly part of a sub
class, but not by inheritance.
class UnsignedInt64 is
public UnsignedInt64 add(in UnsignedInt64 op) is
//define addition for UnsignedInt64
end add;
end class;
program addExample is
//equivalent to
i64.set(i64.add(i32));
end program;
There are three ways to reference a class in Mynx, each reference refers to a class in the relation of
inheritance of classes. The three class inheritance reference prefixes are:
- 62 -
L. Dottic Access Prefix
Accessing an attribute is distinguished syntactically from accessing or invoking a method in Mynx. Mynx
uses a “dottic” from of syntax, a dot or period ‘.’ to invoke a method, and a tic ‘`’ to access an attribute.
Hence access of class elements is with a “dottic” operator.
This clearly disambiguates an attribute over a method. As a result, attributes and methods can have
similar names without any confusion or ambiguity.
The super reference prefix refers to the super class or parent class to access an attribute or method. The
methods and attributes of a parent are available in a derived class using the super prefix. The super
prefix can not reference undefined methods, such as a virtual or abstract method which is declared but
undefined.
For a class with multiple inheritance of disjoint classes, as the methods must be disjoint, the super class is
implicit with no ambiguity about which method is referenced through the super prefix. The super
reference prefix can be used within a method, or method equivalent.
end class;
- 63 -
class Child as Parent is
end class;
The this class reference prefix refers to the current class, and is used to disambiguate methods and
attributes within a class. The this reference by itself refers to the class instance. Similar to a super class
reference prefix, the this class reference prefix can be used within a method or method equivalent.
end class;
A class attribute or a class method that is accessed without a prefix is implicitly using the this prefix to
access the class element.
- 64 -
The this class reference prefix also can refer to the class instance within the class as an implicitly
declared as a read-only variable. An example of using the class instance variable this is:
class X is
public X get is
return this;
end get;
end class;
The self reference prefix refers to the static attributes or methods (similar to the this class reference
prefix), and when used in an abstract class refers to the class when concrete, or essentially the future
concrete sub class. This abstraction capability allows more generalized generic but abstract methods to be
defined, such as a cast method for all classes. The self class reference prefix can be used within a method
or method equivalent.
if(obj in self)
return obj to self;
else
flag InvalidCastTrap;
end if;
end cast;
end class;
- 65 -
Example increment method with self prefix:
end class;
Similar to the concept of the read-only this class instance variable, the class reference prefix super can
refer to the static form of a class, essentially a generalized reference to the class as its name. For example:
class Q is
if(vobj in Q)
result = vobj to Q;
end if;
end castTo;
end class;
- 66 -
Rewriting the same class with the self class reference prefix:
class Q is
if(vobj in self)
result = vobj to self;
end if;
end castTo;
end class;
- 67 -
- 68 -
VII
Operators and Operator
Overloading
- 69 -
The Mynx programming language allows for operator overloading, within restrictions on the methods and
the operators that can be overloaded. Operator overloading is declared within a class (never a program),
and applies to instance objects of the class exclusively.
A. Operators
There are a total of 44-operators overall in the Mynx programming language that are organized into six
major categories. There are 27-operators out of the 44-operators that can be overloaded, more than half of
the available operators. Most operators are infix, but there are 2-prefix operators, and 2-suffix operators.
B. Operator Categories:
There are six categories for operators in Mynx:
1. Assignment
2. Logical Bitwise
3. Relational
4. Stream
5. Mathematical
6. Access
- 70 -
Assignment
The assignment operators are primarily for assigning or moving data to and from instance objects. The
data can be simply the reference to the object, or the actual information within a class instance.
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.
The reference assignment operator is, assigns the reference of an object to another object, and cannot be
overloaded. Hence the is reference assignment object always assigns a reference of an object or a shallow
copy, so like (in C++) a form of address assignment. The reference assignment is a universal form of
reference to reference assignment, if the regular assignment operator = is overloaded with other non-
reference assignment functionality.
var Int x to 0;
var Int y to 1;
x++;
y is x; //y is x
y++; //y is x, so x++
- 71 -
Creation Operator as
The creation with assignment operator as, creates an object and assigns the reference for the newly
created object to another object. The as operator cannot be overloaded explicitly with a method. Hence
the creation operator as creates new instances, invoking the constructor of a class implicitly.
x as Int(“7”);
y as Int(0);
The regular assignment operator = by default is a reference to reference assignment operator, similar to
the is assignment operator. However, unlike the reference assignment operator, the regular assignment
operator can be overloaded. The numerical types Int and Real both have overloaded the assignment
operator.
var Int x to 3;
var Int y;
x = y;
y = 5; //x != 5, = overloaded
//same code:
x.set(y);
y.set(5);
It is important to note that in initialization of declared variables and constants, the to is a separator
between the class type and the initial value, it is not the regular assignment operator.
- 72 -
Cast Operator to
The Mynx programming language is strongly typed, and the language requires type-compatibility among
the operands used in expressions and parameters.
The cast operator to is used to cast or re-type an object. An object can only be re-cast to a super-type, or a
super-class from which the object class type is derived. A cast or re-typing of an object to a non-existent
class type (one which the object's class does not sub-class) will result in flagging a runtime type cast trap.
The to operator has both a left and right operand. The left operand is the instance object variable, and
the right operand is the class type.
Implicit Upcast ??
- 73 -
Cast Assignment Operator :=
The cast assignment := operator is overloaded with a cast operator to the class type of the left value (l-
value) from the right value (r-value). The cast assignment operator is a cast to the l-value class type, along
with a regular assignment operator, using the class assignment (which can be overloaded).
var Int x to 3;
var Real y to 1.0;
y := x;
y = x to Real; //same as
The dual assignment operation operators are a joining of operation with assignment. These operators are
not directly overloaded with a method. However, the dual assignment operator is translated into separate
assignment = and the operation or operator ⊕. The general assignment operation expression of:
IDENTIFIER ⊕= EXPRESSION
Essentially the identifier and the operator precede the remaining expression, which is then assigned to the
identifier. The identifier is in the expression with the operator, and is then the assignment of the result.
The equivalent expression with the assignment operator = and the operator ⊕ that are overloaded.
Addition-Assignment Operator +=
The addition-assignment operator += combines the possibly overloaded addition operator + with the
assignment operator = in a single operator. The addition-assignment operator, because of the dual
operation, cannot be overloaded directly, but indirectly through addition and assignment overloads.
var Int x to 3;
x+=7;
//similarly
x = x + 7;
- 74 -
Subtraction-Assignment Operator -=
The subtraction-assignment operator -= combines the possibly overloaded subtraction operator - with
the assignment operator = in a single operator. The subtraction-assignment operator, because of the dual
operation, cannot be overloaded directly, but indirectly through subtraction and assignment overloads.
//similarly
r = r - 1.0;
Multiplication-Assignment Operator *=
The multiplication-assignment operator *= combines the possibly overloaded multiplication operator *
with the assignment operator = in a single operator.
The multiplication-assignment operator, because of the dual operation, never can be overloaded directly,
but indirectly through multiplication and assignment overloads.
//similarly
m = m * 2.0
//overloaded
m = m.mul(2.0);
- 75 -
Division-Assignment Operator /=
The division-assignment operator /= combines the possibly overloaded division operator / with the
assignment operator = in a single operator. The division-assignment operator, because of the dual
operation, cannot be overloaded directly, but indirectly through division and assignment overloads.
var Int i to 4;
i /= 2; //i = 2
//similarly
i = i / 2;
//overloaded
i = i.div(2);
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);
- 76 -
Bitwise-And Assignment Operator &=
The bitwise and assignment operator &= combines the possibly overloaded bitwise and operator & with
the assignment operator = in a single operator.
The bitwise-and assignment operator, because of the dual operation, cannot be overloaded directly, but
indirectly through bitwise-and and assignment overloads.
//similarly
x = x & 0XFF01;
//overloaded
x = x.bitAND(0XFF01);
The bitwise inclusive or assignment operator |= combines the possibly overloaded bitwise inclusive or
operator | with the assignment operator = in a single operator. The bitwise-inclusive or assignment
operator, because of the dual operation, can not be overloaded directly, but indirectly through bitwise
inclusive or and assignment overloads.
//similarly
x = x | 0XFF01;
//overloaded
x = x.bitIOR(0XFF01);
- 77 -
Bitwise Exclusive-Or Assignment Operator ^=
The bitwise exclusive or and assignment operator ^= combines the possibly overloaded bitwise exclusive
or operator ^ with the assignment operator = in a single operator. The bitwise exclusive or assignment
operator, because of the dual operation, can not be overloaded directly, but indirectly through bitwise
exclusive-or and assignment overloads.
//similarly
x = x ^ 0XFF01;
//overloaded
x = x.bitXOR(0XFF01);
//overloaded
x = x.shiftRight(0X001);
- 78 -
Bitwise-Shift-Left Assignment Operator <<=
The bitwise shift-left and assignment operator <<= combines the possibly overloaded bitwise shift-left
operator << with the assignment operator = in a single operator. The bitwise shift-left assignment
operator, because of the dual operation, can not be overloaded directly, but indirectly through bitwise
shift-left and assignment overloads.
//similarly
x = x << 0X0001;
//overloaded
x = x.shiftLeft(0X001);
- 79 -
Logical Bitwise
Both operators process integral bits or Boolean values. The logical operators are logic operations on the
Boolean true and false. The bitwise operators do bit twiddling on integral types.
Operator Description
! logical not
& logical and (short-circuit)
&& logical and, bitwise and
| logical inclusive or (short-circuit)
|| logical or, bitwise or
~ logical complement
<< bitwise shift left
>> bitwise shift right
^ bitwise exclusive or
The 9 logical bitwise operators are all overloaded operators, and are overloaded in the Mynx core classes.
The logical not or logical complement or negation operator ! takes a Boolean value of true or false, and
returns the logical not of the Boolean value. The logical not operator ! is overloadable, and is overloaded
in the Mynx core classes.
//overloaded
var Bool logical to True;
var Int x to 1;
- 80 -
Logical Bitwise And Operator &
The logical bitwise and operator & is both a logical operator, and a bitwise operator, depending on the
class type of the operands. For the Boolean class type, the logical and is a full evaluation logical operator.
Both operands to the operator are evaluated, even if one of them is false.
//overloaded
x = x.bitAND(y);
The logical inclusive or operator && takes a Boolean value of true or false, and returns the logical and of
the Boolean value. The logical and operator is a short-circuit operator, if either operand is false, the other
operand is not evaluated. The logical and operator && is overloadable, and is overloaded in the Mynx core
classes.
The logical bitwise and operator | is both a logical operator, and a bitwise operator, depending on the
class type of the operands. For the Boolean class type, the logical or is a full evaluation logical operator.
Both operands to the operator are evaluated, even if one of them is true.
- 81 -
Example of Bitwise Operator:
//overloaded
x = x.bitOR(y);
The logical inclusive or operator || takes a Boolean value of true or false, and returns the logical inclusive
or of the Boolean value. The logical inclusive or operator is a short-circuit operator, if either operand is
true, the other operand is not evaluated. The logical inclusive or operator || is overloadable, and is
overloaded in the Mynx core classes.
The bitwise complement operator ~ is also called the bitwise negation operator, takes an integer data type
and computes the complement or negation. The bitwise complement operator can take a signed or
unsigned integral type, but it returns a signed integral type.
var Int j to 3;
var Int i to null;
- 82 -
Bitwise Shift Right Operator >>
var Int j to 8;
var Int i to null;
The logical exclusive or operator ^ takes a Boolean value of true or false, and returns the logical exclusive
or of the Boolean value. The logical exclusive or operator ^ is overloadable, and is overloaded in the Mynx
core classes.
- 83 -
Relational
The relational operators are used for comparison, to compare and relate object instances. The object
instances “base objects” all have the relation of equality and inequality, and “rank objects” have
comparison of greater and lesser than relations.
Operator Description
== relational equality
!= relational inequality
in relational instance of
< relational lesser than
> relational greater than
>= relational greater-equal
<= relational lesser-equal
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;
Inequality Operator !=
The inequality operator != is overloaded with the method isUnequal in the Mynx class VObject, and is
a constant overload. The inequality operator is defined as the logical inverse or not of the equality
operator. Hence, changing the definition of equality == will automatically change by definition the
meaning of the inequality operator. Like the equality operator the inequality operator returns a Bool
logical value of True or False, and requires both objects being compared for inequality be the same type
class.
- 84 -
var Int i,j to 3;
if(i != j)
return i;
else
return j;
end if;
//overloaded
if(i.isUnequal(j))
return i;
else
return j;
end if;
The instance type of operator in tests two cases for an instance object reference. The first case is if an
object instance is an instance of a type of class, or a sub-class type. Using the instance type of operator on
the super class Void will always return true, as all sub-classes are derived from the base virtual class
Void. Unlike the other logical operators, the in operator is not overloadable.
if(s in String)
this.processString(s);
end if;
The second case the in operator tests if two instances reference the same object. The operator is
equates two object references with the same instance, the in operator performs a logical check if two
objects refer to the same instance. Both variables must be of the same (or compatible?) type, as different
type of object references cannot reference the same object.
y is x; //equate y with x
if(x in y)
doSomething;
end if;
The relational lesser than operator < is used in comparison, and for two objects of the same type that are
unequal. The definition of lesser-than is an ordering feature of the class which defines it. The core Mynx
types such as String, Char, Int, Real, Float, UnsignedInt, Byte, UnsignedByte have the
relational lesser than operator and the ordering defined already.
- 85 -
var Int j to 7;
var Int k to 8;
if(j < k)
handleInt(k);
else
handleInt(j);
end if;
The relational greater than operator > is used in comparison, and for two objects of the same type that are
unequal. The definition of greater than is an ordering feature of the class that defines it. The core Mynx
types such as String, Char, Int, Real, Float, UnsignedInt, Byte, UnsignedByte have the
relational greater than operator and the ordering defined already.
var Int j to 7;
var Int k to 8;
if(k > j)
handleInt(k);
else
handleInt(j);
end if;
The relational greater than equal operator >= is a logical inclusive or of the equality and greater than
relation operator.
The relational greater equal operator is used in comparison, and for two objects of the same type. The
definition of greater equal is an ordering feature of the class, which defines it. The core Mynx types such
as String, Char, Int, Real, Float, UnsignedInt, Byte, UnsignedByte have the relational greater
equal operator and the ordering defined already. For some classes the greater equal operator simply uses
each of the base operators of equality and greater than to define greater equal.
while(c >= d)
IO.put(“c = “);
IO.put(c);
IO.putln;
end while;
- 86 -
Lesser Equal Operator <=
The relational lesser than equal operator <= is a logical inclusive or of the equality and lesser than
relation operator.
The relational lesser equal operator is used in comparison, and for two objects of the same type. The
definition of lesser equal is an ordering feature of the class, which defines it. The core Mynx types such as
String, Char, Int, Real, Float, UnsignedInt, Byte, UnsignedByte have the relational lesser
equal operator and the ordering defined already. For some classes the lesser equal operator simply uses
each of the base operators of equality and lesser than to define lesser equal.
- 87 -
Stream
The stream operators are used for moving data in and out to the data streams from object instances. The
operators for input and output are overloaded for the different stream classes.
Operator Description
<<< stream insertion or output
>>> stream extraction or input
Both stream operators can be overloaded, and are overloaded for the core Mynx input/output stream
classes.
The insertion operator is an infix operator that inserts data to an output stream, and is overloadable.
The insertion operator is an infix operator that extracts data to an output stream, and is overloadable.
with mynx.core.IOStream;
- 88 -
Mathematic
The mathematical operators are used with real and integral objects (number objects representing numeric
quantities) to perform mathematical operations.
Operator Description
+ Addition
- Subtraction
/ Division
% Modulo or Remainder
* Multiplication
** Exponentiation or Power of
++ Integral Increment
-- Integral Decrement
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));
- 89 -
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));
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));
- 90 -
Increment and Decrement Operator -- or ++
Both the increment ++ and decrement -- are only post-operators, there is no pre-decrement or pre-
increment, a source of confusion in C/C++/Java. Both the increment and decrement operators are
overloaded for the signed and unsigned integer class types.
var Int i to 0;
i++;
//similarly
i.inc;
- 91 -
Access
The access operators are implicit operators to get information in a class as a method invocation, attribute
access, or an index for an element of an array.
Operator Description
. method access
` attribute access
[] array access
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.
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`variable
ex`value_
getIt
x_
- 92 -
Array Access []
An attribute is one instance of data with a variable name. Multiple instances of attributes can be created
with an array. An array access uses left bracket ‘[‘ and right bracket ‘]’ to indicate an access, with a non-
negative integer index to indicate which element to access. Multiple indices use a comma to separate each
index for each dimension. The index does not have to be a literal integer value, it can be an expression,
variable, or method call. As an attribute, the array has to be accessed using explicit tic ‘`’ with an instance
reference with a name, or implicitly with only the attribute name.
this`matrix[7]
super`data[1,3]
myData[1,2]
table[x+1]
matrix`data[this.getIndex]
- 93 -
Operator Precedence
There are 13 overall precedence levels in Mynx, but the highest level cannot be overloaded or changed, so
effectively there are 12 levels. Parenthesis can override the operator precedence, except for level-0
precedence.
- 94 -
C. Operator Overloading
Operator overloading is associating an operator with a method. When an operator is used in prefix, infix,
or postfix form, the associated method is invoked instead. Operator overloading permits cleaner
expressions with shorter notation for classes. Only a certain set of operators are possible to overload, and
in some classes, some operators are restricted from further overload.
An operator overload is declared like a method or attribute, except without any scope or access. An
overload declaration begins with the keyword overload, and ends with a semicolon ; character.
Following the overload keyword, the overload type is given, or optionally is not which makes an implicit
default overload. The operator is then specified, followed by the keyword as, with the method identifier.
Kinds of Overloads
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.
Classes with overloads that are constant, and are sub-classed do not pass the overloaded operators to the
sub-class. In short, a parent class with a constant operator overloads are not inherited by sub-classes.
However, in using the operators with the sub-class, there is an implicit upward cast to the parent, if the
child class does not overload the operators itself. An overloaded method, if not defined in the parent, is
invoked in the sub-class that defines it. The same principle for method selection applies to an overridden
method in the sub-class.
An example of an implicit upward cast of an operator overload is to define a virtual base class with an
addition operator:
end class;
- 95 -
Implement the class as an integral type, as a byte:
end class;
program useByte is
let Byte b0 to 0;
let Byte b1 to 1;
let Byte bx to null;
end program;
The equivalent program uses the virtual base class VInt to define the variables, but is instantiated with
the implemented sub-class Byte.
program useByte is
b0 as Byte(0);
b1 as Byte(1);
bx is b0 + b1;
end program;
- 96 -
Rules for Operator Overloading
Operator overloading is not possible for all method kinds and operators. There are ten rules for the
overloading of operators:
end class;
end class;
- 97 -
Example of operator overloading with a default overload:
end class;
end class;
An example of operator overloading with mixed constant and default modes is:
end class;
end class;
- 98 -
Table of Operators
- 99 -
Standard Method Names for Overloads
The Mynx library of classes uses a set of standard names for overloading operators in specific classes.
When overloading an operator in a user-defined class, it is a good practice to use a standard name for the
method.
Put logical short circuit or and and as separate operators although similar to
bitwise??
- 100 -
Implicit Hierarchy of Operators
The operators in Mynx that are overloaded have an implicit hierarchy. The operator overloads can change,
but the implicit hierarchy cannot change. The implicit hierarchy of overloaded operators is translated by
Mynx into the equivalent method calls for the methods that are overloaded. In the process of translation,
the operator hierarchy is preserved.
x = x**2 + 2*y + 1
- 101 -
x.set(x.pow(2).add( y.mul(2).add(1) ) )
- 102 -
VIII
Special Methods of the Class
- 103 -
A. Advanced Method Definition and Use
Mynx provides three advanced approaches towards defining methods, and using the methods. The three
advanced approaches are:
B. Static Methods
A static method is a class method accessed through the class type or name. A static method is a single or
only one method, which does not maintain state between invocations, hence is stateless. Static methods
can provide class wide functionality independent of instances. A singular or static class is explicitly
declaring a class of nothing but static or class methods.
Each kind of static method is for specifics for overriding the class method.
The three different kinds of static methods differ in the nature of overriding a static method.
A static method can optionally be overridden, but the override is invariant. Overriding a static method is
re-defining a class function definition, so not the same as specialization of an instance. Thus, a static
method as a stateless function cannot be covariant in return type when overridden and is always
invariant.
- 104 -
Examples of Overriding Static Methods
end class;
end sort;
end class;
end class;
- 105 -
Refine the QuickSort class method sort by checking if it is sorted in the QuickerSort class. The class
QuickerSort and method sort then is:
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
- 106 -
Prefix for Static Method
In order to use a static method, the method must be invoked, and invoking a static method uses a prefix
followed by a dot or period ‘.’ with the static method name, and then the parameters. The prefix for a
static method is different for a method called within a class in which it is defined or externally from
outside the class.
A static method can explicitly be invoked as a static or class method, or implicitly. Within a class, a call to
a method can be implicitly static without using a prefix, or explicitly using the prefix self. The prefix
self is similar to the instance prefix this, only for a class static method instead of an instance method.
When a static method is referenced from outside the class, the class name is explicitly used rather than
the instance variable name. A static class method can be invoked implicitly only by static method
inclusion. Then the static class method does not have to be invoked through the class name, but implicitly
similar to a static method invoked within its defining class.
Static Method
Class Scope Reference
Visibility
Implicit Explicit
- 107 -
Program Methods as Default Static
A program that defines methods and attributes defines both as implicitly static. A program is similar to a
singular class, static and cannot be inherited. But all methods of a program are static, so referenced with
the prefix self explicitly, or implicitly by name with no prefix.
method helloWorld is
IO.put(self`greeting);
end helloWorld;
end main;
end program;
Inclusion
For example:
with mynx.core.*;
The MAXIMUM method of the Int class is static, and is called to get the maximum range attribute. Using a
with inclusion statement for an unambiguous reference, the code can be simplified to:
- 108 -
with mynx.core.Int;
The class must have an absolute namespace to explicitly include the Int class, and allow for implicit
static reference. A wildcard or relative reference is ambiguous, for there can be multiple classes which
define a static method of the same name. If there is a publicly static method in multiple classes that are
absolute in namespace, then the class name would have to be explicit in the method reference.
Attributes can never be referenced implicitly. Only a method using a dot or period to access within a class
can be implicitly referenced as static. However, the methods that access the attribute “getters” or
inspector methods can be used to provide implicit static reference.
Reference
A static method of a class can be used without prefixing the class name for static reference. This avoids the
repetition and verbosity of names of classes with names of methods. Mynx uses the classes included in a
with statement to determine the class associated with the static method.
Implicit static reference of a method can be used to refer to methods or attributes more naturally than full
prefix reference.
For example:
if(x.isReady == True)
flag NotReadyTrap;
end if;
The True is not a value or object instance, it refers to the class Bool, and the access or inspector method
True which returns the Bool instance of True defined as an enumerated type.
if(x.isReady == Bool.True)
flag NotReadyTrap;
end if;
The requirement would be that the method is in a class which includes the Bool class either explicitly or
indirectly in a with statement.
Only public static (or singular) class methods can have implicit class prefix referencing not attributes. In
the example the Bool class value of TRUE is accessed by an access or inspector method of True but not
the constant attribute. Attributes can be accessed by static methods that are then used in their place.
Using the full Bool class attribute would require the full syntax.
- 109 -
Rewritten:
if(x.isReady == Bool`True)
flag NotReadyTrap;
end if;
The implicit static class prefix reference can be used with attributes or pure methods, for example:
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.
A method is declared with the method head, and defined with a method body, which ends with the
method footer. However sometimes a method is a variation upon another and declaring and defining a
full method would be tedious and cumbersome. A method equivalent defines a method in terms of other
methods of the class. Any method, including constructor and destructor can be a method equivalent.
A method equivalent is like a fully declared and defined method, so can be public, private, or protect
access; similarly within the class a method equivalent can be scoped with other methods of the class.
- 110 -
For example:
class methodEquiv is
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;
A method equivalent is useful for default parameters, but without defining them in the method definition
(like C++), and without a complete method wrapped around the actual method (like Java).
For example:
When defined in an integer class, the arithmetic methods take an implicit this to be used in the
operation.
- 111 -
Fully declared and defined with a wrapper method would be:
this.addition(this,augend);
end addition;
A method equivalent can be used to export a static, or constant method, which is not public (or is
public…) as a default instance method. For example:
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.
Method equivalents can be used to rename a class method, either in the child class of a parent, or within
the same class. This would avoid the tedium or re-defining the same methods again, or defining methods
as wrapper methods to a renamed method. For example:
A class could rename methods put and putln as methods write and writeln methods.
- 112 -
The fully declared and defined methods by the method equivalent are:
Accessor Methods
A traditional accessor method get is of the generalized form when implemented in Mynx:
The traditional accessor method to simply inspect an attribute is somewhat semantically ambiguous. The
semantic ambiguity is by the design and implementation of operator overloading and interaction of a
return of an overloaded reference to an attribute of the class.
- 113 -
Implicit Accessor Methods
For example, consider a class Point2D in Mynx representing a point in a Cartesian coordinate system:
class Point2D is
end class;
The ambiguity using an access in the accessor methods is illustrated in the code fragment, with the
overloaded operators translated to the equivalent method calls:
p.Y = ui;
p.Y.set(ui);//getter now setter
In the Point2D class, the accessor methods X and Y are defined using method equivalents of the accessor
method get. Clearly from the code fragment, get is no longer a simple inspector accessor method. An
accessor the returns a reference or handle to an attribute that is overloaded with an operator indirectly
creates a full access accessor method.
One possible solution is a compiler semantic check for accessor methods by name of get and set.
Unfortunately this implicitly places the keywords get and set into the programming language reserved
word or vocabulary, but indirectly. It also adds a complication to the compiler of the language.
Another solution is to simply do nothing, but this leaves a subtle side effect in the programming language,
one that could create a minor wrinkle that impacts the integrity of the Mynx language.
A much more useful solution is to add three keywords to the language, and use a variant of method
equivalents to create explicit accessor methods to read, write, and access class attributes. The syntax is:
- 114 -
Essentially the access kind becomes an implicit method name with an identifier as method parameter, but
not using an explicit existing class method.
There are three modes to an accessor of a class attribute:
The three modes effectively cover the operation of accessing a variable that represents memory in a read-
only, write-only, or read-write manner.
Rewriting the Point2D class in the changed syntax using method equivalents, but have equivalent
functionality for accessor methods:
class Point2D is
end class;
An added advantage to this approach is that an attribute can be easily defined with an accessor method
without fully defining a complete “wrapper” method, and the definition is explicit in creating an accessor.
- 115 -
E. Class Creation, Destruction, and Default
There are three special methods of a class, two are to create and destroy instances or objects of a class.
The methods are a constructor, destructor, which are a special kind of method in a class. The third
method is the default implicit method of the class. All special methods are not directly accessible or
explicitly invoked, but are indirectly called through usage of a class.
F. Constructor
A constructor is used implicitly to create a new class instance, or an object. A non-partial and non-static
class must have at least one constructor defined, and there is no automatically created or a predefined,
given constructor (like in Java and C++, although a compiler could generate one but this is an
implementation feature, and not a programming language feature...).
A virtual class can never define a constructor (as it is a class specification), nor can a static or singular
class (as a static class will never create any instances.) An abstract class can optionally define a
constructor, a constant or default class must define at least one constructor. Since a program is not a
class, it never has any kind of a constructor.
Constructors are never inherited from the parent classes. A constructor can be overloaded on different
parameters, but never returns a value, hence a constructor has no method type.
Constructor Definition
A constructor is defined like a method, but rather than a return type or a method name the keyword
constructor is used instead. Similar to methods, a constructor can be public, private, or protected
access. A constructor can have parameters or arguments exactly like a method, or no parameters in the
constructor header. The constructor is defined internally like a method, using statements to initialize the
class instance. The constructor uses a footer like a method with the constructor keyword instead of the
method name. A constructor, like a method, can be overloaded with different parameter signatures for
each constructor.
end construct;
One special type of constructor is the default constructor, a public constructor that takes no arguments. A
default constructor is useful to create an instance of a class in a default state.
- 116 -
An example of a default constructor:
public construct is
null;
end construct;
A non-default constructor is any constructor that takes arguments in the parameter list.
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;
- 117 -
Example of Defining Multiple Constructors in a Class:
this`i = x;
this`j = y;
end construct;
return this`x;
end x;
return this`y;
end y;
end class;
Constructor Invocation
When invoked, a constructor is invoked on the same class type, not a sub-class or super-class of the
variable or constant type.
- 118 -
Examples of invoking a constructor by creation:
x as Int(0);
str as String(“hello world”);
p as Point(0,0);
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.
- 119 -
Using the 2DPoint class in a program:
program 2PointProgram is
end program;
G. Destructor
A destructor is used to implicitly destroy (more like clean up afterward) or destruct a class instance when
the instance is terminated. A class can optionally define a destructor, but like a constructor a destructor is
never automatically provided, and is never inherited by a sub-class. A class's destructor takes no
parameters, and therefore can only be one destructor defined, so no overloading of a destructor. Similar
to a constructor, a destructor returns no value, so has no method type. There is no guarantee of when a
destructor will be executed, so a destructor is more of a post-check method, to verify that a class is
properly terminated.
Destructor Definition
A destructor is like a constructor in declaration, but only the keyword destruct is used instead of
construct in the header and footer. Unlike a class constructor, a class can only have one destructor,
which takes no parameters. A destructor can be public, private, or protect access. A class with a private
destructor never can invoke the destructor implicitly.
public destruct is
end destructor;
A destructor can be defined using a method equivalent, similar to a method or constructor. A destructor
must be defined in terms of method equivalents, as no other destructors can be defined except the one
destructor.
- 120 -
Destructor Invocation
A class destructor is never explicitly invoked directly; it is invoked when the class is taken out of service by
the underlying runtime (at this writing July 2004, the .NET or JVM platforms) when garbage-collected.
A better class design approach is to use a method to deactivate and take an instance out of service (in this
case, the super-class VObject method nullify) and then by method equivalent to define the destructor
in terms of that method. Then the instance can be deactivated explicitly by the user, or implicitly by the
runtime platform using the same functionality.
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.
When an instance is used, either with no arguments, or with arguments, an implicit instance method
called the default method is invoked. A class with a default method never explicitly invokes the default
method, as the keyword default is a reserved word.
- 121 -
Default Method Declaration
The default method is a method equivalent with an existing class method. The method equivalent
definition uses the keyword default for the method equivalent name.
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.
A default method is never invoked explicitly on an instance. A default method is invoked implicitly when
no method is invoked explicitly.
zeroInt to Int(0);
oneInt to Int(1);
sum to Int(0);
The equality operator = is overloaded with set or the assign. The simple expression statement becomes:
sum = zeroInt;
sum.set(zeroInt);
The instance zeroInt invokes the implicit default method of get, which gets the value of zeroInt. The
expression then is:
sum.set(zeroInt);
sum.set(zeroInt.get);
- 122 -
The default method of a class depends upon the functionality and use of a class. A default method can also
be called with parameters, depending on the class. For example, a class instance out of an output stream
with a default method:
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.
I. Incomplete Methods
Two class kinds, abstract and virtual or partial classes, allow for methods to be declared by the method
signature and access, but not defined with statements. An abstract class can allow for method definition,
but a method that is abstract then becomes like a virtual method, declared by not defined.
An example of an incomplete method in a class involves an abstract data structure class, ATrove. The
class has a method for getting and setting data, but it is undefined as it is implementation specific.
end class;
- 123 -
- 124 -
IX
Traps
- 125 -
A. Concept of Trap
An exception or trap (as it is called in Mynx) is the basis for error notification and handling in Mynx. A
trap is an exception in Mynx (think of a trap snaring an error…), and a statement will flag a trap (like
flagging down a passing car…) within the statements of a method.
B. Kinds of Traps
There are two primary kinds of traps or exceptions in Mynx:
There has been considerable discussion in the two major object-oriented language camps (Java and C# at
the time of this writing…) concerning exceptions which are checked (forced to handle) and unchecked
(not forced to handle.)
Mynx uses an approached of unchecked, unless the trap or exception is declared in the method header.
There are no special exception classes which require check or unchecked (as in Java), nor is the
unchecked exception approach forced (as in C#). The Mynx approach to exceptions or traps is that the
choice is the responsibility of the software developer, and so provides ways for both options to be used in
writing source code.
C. Declaration
A trap is declared as part of a method header (there are no traps for attributes…) as a clause that begins
with the keyword has and ends with the keyword is with a following list of identifiers that are the traps
the method can flag. Any declared traps in a method must be handled, but a method can flag traps that are
not declared in the method header. Any methods invoked can likewise flag a trap that is not declared in
the method header, or can be to require handling the possible trap that is flagged.
D. Invocation
A trap is caused or raised with a flag statement. A flag statement begins with the keyword flag, followed
by the identifier name of the trap, and any information for the constructor. The flag statement creates the
trap object with any parameters such as message, or error number, and the method is exited. The point of
execution in the statements returns to the caller method, and an encompassing try statement.
The class for the trap is declared and defined separately, then included in the class or program.
if(divisor == 0)
flag ZeroDivideTrap;
- 126 -
E. Handling
A trap is handled with a try statement. A try statement consists of the try clause which begins with the
keyword try, any statements which can flag traps, and then a series of when clause to handle particular
exceptions with an ending end tries to enclose the block. Then, when-blocks begin with a when- clause,
which is the when keyword, and then a pair of parenthesis with the trap name, and variable if the trap
instance is to be used.
A trap must be declared, but a trap variable does not if the trap instance is not to be used (i.e. invoke
methods on the instance to get trap information, etc.).
try
x.doSomethingDangerous;
when(ZeroDivideTrap) //handle, but no instance
//handle it
when(InvalidInputTrap i) //handle, but with instance of trap
null;
end try;
Two other clauses for a try statement are else and do. An else clause is a set of statements that execute if
no trap is flagged in the try clause. An else clause is the next or last clause in the try statement, beginning
with the keyword else.
try
x.doSomethingDangerous;
when(ZeroDivideTrap) //handle, but no instance
//handle it
when(InvalidInputTrap i) //handle, but with instance of trap
//handle it
else
IO.put(“No traps.”);
end try;
A do-clause is the last clause of a try statement, and is always executed last, after handling an exception,
executing an else, or after executing the statements in the try clause. The do-clause begins with the
keyword do, and then statements to be executed.
The try statement does not allow any exit, next, or return statements to be executed in the clauses within
(if present...) the do clause of a try statement. This restriction on statements within the do clause is to
avoid ambiguity and confusion in flow of control with a method or iterative statements.
- 127 -
Example of a try statement with do:
try
x = file.readInt;
when(FileNotReadyTrap) //handle, but no instance
//handle it
when(InvalidInputTrap i) //handle, but with instance of trap
i.doSomething;
do
x.close; //always close the file
end try;
Like an if statement, a try statement cannot break from the flow of control prematurely, the normal flow
of execution is followed (in contrast to a loop…). Hence there is no possible flow of control exit try or
next try statement.
loop
try
inInt = in.readInt
when(NonIntegerFormat) //handle by continuing
next;
do
return; //error: return invalid in do-clause of try
end try;
end loop;
Like an if statement, a try statement cannot break from the flow of control prematurely, the normal flow
prematurely, the normal flow of control is followed. Hence there is no exit try or next try
statement.
F. Propagation
A trap can be handled with a when clause, and then flagged again to propagate the trap, possibly with
other exception or debugging information.
try
x.doSomething
when(Trap)
flag OtherTrap(“some information”);
end try;
- 128 -
G. Unhandled Traps
An unhandled trap is automatically propagated up the chain of method calls, until it reaches the top-level
calling method, and if unhandled, will cause an application to halt with a report on the trap.
- 129 -
- 130 -
X
Generic Classes
- 131 -
A. Parameterized Types
A generic or parameterized type class is a class that is fully declared and defined, except for the primary
type. Only a class can be generic, there is no concept of a generic program in Mynx. A generic class is an
abstract class in that the class type is abstract, or generic.
A generic class is an abstract class, completely concrete except for the type, which must be instantiated
with the class for an instance to be created. A Mynx generic class can only be generic on one type, multiple
generics are not supported.
A generic class allows for general-purpose classes to be defined, and used with specific types for strong
typing without having to rewrite and re-implement the same class functionality again. A generic class is
declared and written as a regular class, except that parameter arguments are generic.
A generic class has attributes and methods that can be generic or undefined type. Unlike a default class, a
generic class does not process the generic elements within a class.
Attributes
A generic attribute, like an attribute for all classes, must be initialized, but as it is a generic attribute it is
initialized to null. A generic attribute is an undefined type, so cannot be initialized to a specific class type
or value. No methods can be invoked on a generic attribute within the defining class methods of a generic
class.
Methods
The generic methods of a class can take a generic parameter or return a generic result. But, the methods
cannot invoke methods on the generic parameter, nor process the parameter passed or result returned.
C. Definition
In a generic class the keyword generic is used in place of a formal class type such as Char, Int, or
String. When a generic class is instantiated, then the type of generic is the instantiation type.
- 132 -
Example of a generic class:
public construct is
end construct;
if(this`stack.size == 0)
flag StackUnderFlowTrap;
end if;
element = stack.remove(stack.size-1);
return (element to generic); //cast and return element
end pop;
end class;
D. Inheritance
Similar to a static class, a generic class can only inherit from another single generic class. Inheriting a
generic class is for specializing and refining a generic class; while still being abstract about specific class
type. A generic class can only inherit one generic class at a time, unless it inherits multiple virtual classes
(no multiple disjoint inheritance.)
- 133 -
The syntax used to inherit a generic class is the same as for all classes. An example of inheriting a generic
stack is:
element is super.pop;
super.push(element);
return element;
end peek;
end class;
The derived class adds a new method to peek at the top most element of the stack. The added method or
attribute need not be specifically of a generic type, as the example illustrates.
E. Instantiation
In order to use a generic class, the class must be instantiated, or bound to a specific class type. The
instantiation type can not be another generic class, or to the self abstract type. Hence a generic stack class
of generic queues is not a valid class type for instantiation.
Instantiation is separate from class inheritance, instantiation creates a class, and inheritance uses a class
to add additional functionality. Instantiation binds the generic class to a class type, effectively creating a
useable class based upon that type. The instantiated class is a default class, and can be used like any other
default class in Mynx.
F. Types of Instantiation
A generic class needs to be instantiated or bound to a specific class type before it can be used.
Global Instantiation
Class level or global instantiation of a generic class creates a new class type, which is available as a default
class. Attribute level or local instantiation creates a local type within the class that the generic class is
instantiated. The class instantiation syntax is a non-template style from C++ to keep instantiation syntax
from becoming mangled.
- 134 -
The syntax for instantiating at the class level is:
end class;
Class level instantiation creates a new class, and new attributes and methods can be defined when the
class is instantiated. The has-to clause of the class header declares what generic class, and the instantiated
class type. The created default class type can inherit other classes as well as instantiate to a class type.
For example, the generic class GStack when instantiated with the class type Int would be effectively the
code of:
public construct is
this`stack = new Vector;
end construct;
if(this`stack.size == 0)
flag StackUnderFlowTrap;
end if;
element = this`stack.remove(stack.size-1);
end pop;
end class;
- 135 -
Local Instantiation
Local instantiation of a generic class to a class type creates a local copy, but does not create a class that
can be used beyond the locality of the instantiation within the class.
class Example is
end class;
Attribute level instantiation creates a class that is defined within the class where it is instantiated. In the
given example class, myStack is a class attribute which is a generic GStack bound to a class type of Int.
But, the class myStack is local to the class Example, so it cannot be used like a default class.
There are only two other classes a generic class can possible inherit:
For example, a generic class GStack with a self cast method would upon instantiation to Char type as
charStack would now cast to charStack.
- 136 -
generic class GStack as Void is
if(castFrom in self)
return castFrom to self;
else
return null;
end if;
end cast;
end class;
When instantiated either locally or globally using the type class Char, the instantiated generic class is the
same as a default class with the instantiation type:
if(castFrom in charStack)
return castFrom to charStack;
else
return null;
end if;
end cast;
end class;
Generic classes are a form of abstract class, so can be declared but not defined or abstract in nature. A
generic class can contain an abstract method in the declaration of the class. However, such an abstract
method in a generic class will make the class unable to instantiate, and must be inherited and defined in
the sub-class.
An example of a generic class with an abstract method is in defining a generic Vector class, with abstract
methods. One method isEmpty is defined in terms of an abstract or undefined method size.
- 137 -
generic class GVector as Void is
if(size == 0)
return Bool.True;
else
return Bool.False;
end if;
end isEmpty;
end class;
- 138 -
XI
Statements
- 139 -
Mynx statements are the basic means for expressing functionality of methods, and the data of attributes.
Mynx has seventeen statement types, and six categories of statements.
1. repetition or iteration
2. selection or decision
3. error
4. flow of control or jump
5. computation
6. mutual exclusion
- 140 -
A. Computation
The computation statements “do” or compute something, such as invoke a method, evaluate an
expression, assignment to a variable, declare a variable, etc. The two computation statements are
expression, which does actual computation, and the null statement that does nothing but is an explicit
statement of no operation.
Expression Statement
Declaration
A declaration statement is a declaration within a method, and has a similar syntax to a class or program
attribute. A declaration statement is preceded by the keyword var to distinguish the declaration from an
expression statement. Unlike a class or program attribute, a declaration sub-statement does not need an
initial value. A declaration without an initial value merely declares a variable and initializes it to a value of
null. A declaration with or without an initial value declares and creates an instance of a class as an
object, invoking the class constructor.
var Int x to 0;
var Char c,d; //no initial value, just a declaration to null;
var Point p to null;
var Real r to default;
var String[*] tables to { “0”,“1”,“2”,“3” };
Expression
An expression statement is a computation statement that evaluates an expression form to compute and
create an object instance for the value of the evaluated expression. The operators used in an expression
statement are overloaded to represent a method call or access to compute a value. An expression
statement has five sub-expression statement types:
1. postfix
2. assignment
3. creation
4. input-output
5. access
Postfix
A postfix expression involves a variable, method call, or an instance object, and the method which the
postfix operator (++ or --) which is overloaded. For the integral numeric types the increment operator ++
overloads the increment method, and the decrement operator –- overloads the decrement method.
- 141 -
var Int x to 0;
var Int y to null;
x++;
y = (this.getValue)--;
Assignment
Assign
Assignment statements use a left value, right value, and are separated by an assignment operator. The left
value must be an identifier, array access, or attribute access. The right value can be an expression, literal,
method call, attribute access, or array access.
x = 3;
y += x+7 / 2;
z = this.computeValue(x,y);
data[3] = 17;
x`y := i+j*3;
total = x**y + 1;
q is y;
this`y = 0;
self`ct = super.getCount;
Create
A create or creation statement is an assignment expression that creates a new instance of a class and
assigns it to an object reference or variable. The keyword as follows the object reference variable and the
class name with any constructor parameters.
- 142 -
An example of a creation expression statement:
Input-Output
Access
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.
- 143 -
Method
The access statement for a method is a method invocation is the calling of a method in the current class,
super class, or on an instance of a class.
this.callMethod(0,”hello”);
super.invokeMethod(‘a’);
x.doIt;
An object instance variable or constant by itself is potentially a method access if the default method of the
class the object is an instance of is defined and invoked.
Array
An access sub-expression for an array is accessing an array element of the method or class. An array
access can be read or written. The sub-script of index into the array can be a literal constant, variable, or
an expression.
y = data[x];
data[base+count*sizeof(data)] = 0;
x[0] = y;
Multiple
The access statement can be made up of multiple accesses, such as accessing a method, then an attribute,
an array, and so forth. Note that a super or this reference only appears as the first element of an access
statement.
this.callMethod(0,”hello”).doSomething`rawData[x];
super.doIt[x]`data;
Null Statement
The null statement is an empty statement, which does nothing. Instead of a blank or single semicolon on a
line, Mynx null statement is explicit.
public doNothing is
null;
end doNothing;
- 144 -
B. Error
The error statements include explicit error assertion checking with an assert statement, and error flagging
with a trap, and handling a flagged trap with a try statement.
Error statements are for debugging software and to manage software errors as they occur in software.
Methods can require that a trap error must be handled with a try statement. The method then must flag
the trap when it occurs, and a caller of the method must handle the error with a try statement or
propagate it by declaring it as a flagged trap of the method.
One form of error statement, the assert statement is for debugging software under development, and the
other kinds of error flagging and handling are for handling software errors.
Assert Statement
The assert statement is used to debug software. The assert statement is compiled during a debug build by
the compiler, but during a release or final build becomes a null statement and is excluded from the
compiled source.
As the assert statement is for debugging purposes, it is a very simple statement. An expression is asserted,
and if it is not true, then the assert statement causes execution of software to stop, along with reporting an
error message, and an optional literal string message. Assert statements are not intended for sophisticated
error handling or logic, only to assist in debugging source code.
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.
- 145 -
A try statement restricts placing a flow of control statement (exit, next, return) in the do-clause of a
try statement. This is to avoid flow of control ambiguity in a try statement.
A when-clause has the trap class, and an optional identifier to associate with the instance.
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;
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);
- 146 -
C. Flow of Control
Nesting and need for non-sequential exit and next stepping through the iteration statements. Not valid for
try, if, or case. Statements, in particular the repetition category of statements, are nested often. There are
times when a non-sequential skip or continuation from a nested loop block is efficient. An exit statement
exits or skips out from a nested block of repetition statements, a next statement continues to the next
cycle of a loop cycle.
The repetition statement blocks can be nested, and with each nesting have a nesting level in the form of a
parenthesized integer following the end clause before the semicolon. The nesting level starts at zero and
progressively counts upward by an increment of one, so the range is 0..n-1 for n nested repetition
statements. An exit or next can specify the level to which an exit or next is reached, the default being the
current repetition statement only.
Exit Statement
The exit statement is used within an iteration statement, such as a loop, while, or for, or statement.
The exit statement causes an immediate exiting of the iterative structure, a jump to the end clause of the
iteration block statement.
for(Int x is 0 to 100)
for(Int y is 0 to 200)
if(x == 100 && x == y)
exit for(0);
end if;
end for(1);
end for(0);
An alternative example:
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;
- 147 -
Next Statement
The next statement is like an exit statement, except that instead of exiting a repetition statement, it
continues to the next cycle of the repetition statement. A next statement can skip to continue to an outer
repetition statement in which the next statement is nested.
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 );
for(index is 0 to list.size)
where = index;
exit for(0) if(list[index] == val);
end for(0);
return where;
end findMax;
- 148 -
Return Statement
A return statement returns or exits a class or program method, and can return a value. The value returned
from a method must correspond with the method type or return nothing if the method is a void type
return or procedure. The type null is a valid return type for all return values except void, indicating a null
or non-initialized object reference return. A return statement is like a non-sequential exit that can return
a value from a method.
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;
- 149 -
D. Repetition
The repetition statements repeat or iterate over a block of statements. A for statement iterates over a fixed
range or count of elements. A loop statement is a infinite loop, no specific explicit conditions exist to
terminate the loop. The until-loop and while-loop have explicit conditions to exit a loop, which are
logically the inverse of each other.
Add restrictions and limits on for loop variables and types; implicit UnsignedInt or
Int for a for-range. ??
For Statement
A for statement is a fixed iteration statement, it repeats over a discrete range. There are two types of for
loop statements:
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.
A fixed for statement over an integral range counts up or down from an initial value up to an upper limit.
The lower bound and upper bound are an actual for loop variables; the for-loop variable will equal the
boundary values.
- 150 -
For Statement over an Array
The for-statement over an array iterates over the range of a 1-dimensional array, returning the element of
an array at an index instead of the value in the range.
for(String x in dataTable)
IO <<< x <<< eoln;
end for(0);
A for statement does not have to have an implicit range of UnsignedInt or Int integral type. Other
integral types such as Byte, Short, and UnsignedByte can be used explicitly in a for statement.
For a non-implicit integral variable in a for loop, the type must be explicitly declared and the ranges for
the variable must be valid for the integral range.
Loop Statement
A loop statement is an infinite loop, with no explicit bounds on the termination of the loop. The loop
statement is used instead of a “hardwired” while or until loop. An infinite loop must have an explicit
statement to exit or continue to the next cycle of iteration within the loop.
- 151 -
Example of loop statement with prefix-if statement:
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;
Until Statement
An until-loop repetition statement continues iteration until the loop condition is true, or continues while
the condition remains false.
var Int x to 3;
until(x == 0)
x--;
end until;
While Statement
A while-loop repetition statement continues iteration while the loop condition remains true, or stops
when the condition is false. For example:
var Int x to 3;
while(x != 0)
x--;
end while;
- 152 -
Equivalence between While-Until
A while-loop is the logical inverse of an until-loop, and vice-versa. Effectively one repetition statement is
the opposite of the other:
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.
repeat
dataFile.readRecord;
while(!dataFile.endOfFile );
repeat
dataFile.readRecord;
until( File.endOfFile );
Each of the repeat loop statements is logically equivalent. Depending upon the logical expression, a
repeat-while and repeat-until can be used. A loop statement is equivalent to a repeat statement, only with
the logic to terminate of the loop part of the body of statements. A repeat statement avoids the mixing of
logic and statements in a cleaner repetition statement.
- 153 -
A repeat statement can have a nesting level, as a repeat statement can be nested within another repeat
statement. And like the other loops, a exit, next, and prefix-if statement can alter flow of control in the
repeat statement.
repeat
rec = dataFile.readRecord;
exit if(rec == null) repeat(0);
while(!dataFile.endOfFile )(0);
dataFile.close
A repeat statement is similar to a loop statement in that both will execute the body of statements at least
once. A while and until statement can optionally never execute the body of statements, and the for
statement (again depending on the logic of the expression) can possibly never execute the body
statements.
A for statement always has some constant upper bound, which is always less than infinity—hence a for
loop statement will always terminate. Other loops are always less or equal to infinity—hence a possible
infinite loop for the upper bound.
Post-conditional loop or repetition statements are useful when the body of statements needs to be
executed at least once, and then a logical expression to continue the loop is evaluated. Conversely, a pre-
conditional loop is utilized if the body of statements need never execute; the logical condition is evaluated
and then the body of the loop is executed if the evaluation is logically true. A false logical condition and
the loop, and the body of statements is not executed similar to an if statement.
- 154 -
E. Selection
Selection statements select a block of statements to execute based upon a value or condition. A case
statement uses a discrete value to select a statement block to execute, the if statement uses a logical
Boolean condition or set of Boolean conditionals to select a block to execute.
Case Statement
A case statement is a multi-way selection statement that uses a discrete value to select the choice of
decision. A case statement can be more efficient than a ladder of nested if-elif-else statements. A case
statement uses a discrete type such as integer, Boolean, character, or strings.
The case of the variable heads a case statement, then with each valid case values as a comma-delimited list
between the keywords as and is. The last part of a case statement is the optional else-clause that begins
with the keyword else, which is the catchall if no specific case is selected. A case statement ends with the
case footer, which follows the syntactic form of an if statement with an end keyword with a case keyword
with the terminating semicolon.
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.
- 155 -
A case statement can case on a String literal, an example of which is:
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;
- 156 -
An example of an if statement with else-if elif block, equivalent to else with an if block:
if(x < y)
this.computeValue(x,y);
elif(x > y)
this.computeValue(y,x);
else //x == y
this.computeValue(x,x);
end if;
if(x < y)
x += y;
else //x >= y
if(x > y)
y -= x;
else //x == y
x is y;
end if;
end if;
if(ival < 0)
flag IntegerValueTrap;
elif(ival == 0)
return 1;
else
return( ival * this.factorial(ival-1) );
end if;
end factorial;
- 157 -
F. Mutex Statement
A mutual exclusion or the shorter, concise form of mutex is a statement relating to threading and the
mutual exclusion of threads from multiple statements. A mutex statement does not compute anything, bu
provides a means to explicitly delineate a block of multiple statements for thread-safe mutual exclusion.
The mutex statement is examined more thoroughly in a later chapter.
- 158 -
XII
Implied Methods
- 159 -
A class can have a method which is implied, a method which is declared with a method header, but is
defined in the compilation (Java or C#) language. An implied method is implied functionality,
functionality provided through the class but not defined in it. An implied method is opposite of an
abstract or virtual method, declared but defined in the implementation language, whereas a virtual or
abstract method declares a method but a sub-class must define it in Mynx.
B. Declaration
The syntax for an implied class method is similar to a normal class method header, except that after the
is keyword follows the implied keyword without the method body definition using statements. In effect
the method is implied, after the method header is declared.
C. Implementation
An implied method is like an ordinary default method in a Mynx class, except that the generated Java or
C# code is different.
The implied methods of a class will generate an implied method class stub, in Java and C#, as an
interface. The interface is then implemented as a final class with the implied methods defined in the
underlying implementation programming language (Java or C#).
module example.impliedMethod;
class X as Void is
end class;
The Mynx class with the implied method execute will cause the generation of an interface and an
implementing class around the implied methods within the same namespace. The implied method
interface and class use a “mangled” name, with a trailing underscore after the Mynx class name to avoid
conflict with any Mynx class names. The interface is prefixed with _impliedI for implied interface, and
the implementing class is prefixed with _implied before the Mynx class name.
- 160 -
The implementing class then uses the implied class implementation as a class delegate, and uses a private
constant attribute of the _implied name. The underscore creates a unique identifier which will not
conflict with a possible Mynx identifier.
An interface is generated so that an implementing class can optionally have other functionality, but the
interface ensures the implied methods are implemented, and by instantiation only those methods are
accessible in the implementing programming language. A final class provides the implementation of the
interface, separating the interface to the implied method functionality from the implementation.
package example.impliedMethod;
package example.impliedMethod;
- 161 -
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.
- 162 -
D. Implied Method UML
The UML for the implied method and the related implementing class and interface is:
- 163 -
- 164 -
XIII
Obviate Methods
- 165 -
A visible, callable method can be obviate or removedfrom a Mynx class. The obviated method is “masked”
out or “hidden” from any further derived class, and invoking an obviated method in a class will flag a trap.
Effectively, the obviated method or methods are removed from the class interface. However, an obviate
method is still useable within the parent class, and any methods inherited in a child class which use the
parent method. Obviating a method will not “break” existing code.
A method must be visible and callable, hence private methods of a class are not accessible, so can never be
obviated. Class methods that are invisible from the outside of the class are already hidden or masked out
from use. Obviating a class method from the interface that is already invisible is redundant. Any method
that is callable is explicitly callable; hence implicitly called methods such as constructor, destructor, and
default method cannot be obviated. Implicitly called methods are invoked automatically in use, so
obviating them can cause unexpected side effects within the class.
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.
- 166 -
Example obviate method declarations:
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;
The class Cat contains the public method wagtail, which as on operation on a cat object, wags the tail of
the cat, and takes no parameters, and returns nothing when called.
But, when another class manxCat subclasses or derives a new class from Cat, the method is no longer
valid in the subclass. The method is simply an obsolete method in the class interface.
end class;
The original method wagtail in the super class Cat is now invalid (since a Manx cat does not have a
tail…) obsolete or, hence in the sub-class manxCat must be made obviate. Obviating a method does not
“undefined” the method, but removes it from the class interface
- 167 -
The method myManxCatMethod invokes the method wagtail in the super-class, and is a valid method call
or invocation. The method wagtail is removed from the manxCat and all further sub-class interfaces, but
the method still exists in the super-class. Again, obviating a method does not “undefine” the method, but
removes it from the class interface.
If a derived class from manxCat, such as a curlyManxCat that has a method wiggleEars, the method
wagTail is completely absent or void from the super class.
Example class deriving from a parent class with an obviate method that is not in the class interface:
end class;
- 168 -
The class hierarchy for the various classes with an obviate method is:
end class;
- 169 -
The class ConsoleInput declares multiple methods by the name readln, which are overloaded for the
data type to be read. The methods are implied, so implemented in the underlying implementation
language.
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;
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.
- 170 -
An example of invalid re-definition of a method:
end class;
The obviate method wagtail cannot be re-defined within the class, even as an internal private method.
Once a method is obviated in a class, it cannot be invoked explicitly on an instance, or internally with a
sub-class.
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.
- 171 -
- 172 -
XIV
Arrays
- 173 -
An array is an indexed, homogeneous, aggregate collection of a class type. An array in Mynx is a first-class
object, and an array can be multi-dimensional. Mynx does not have the concept of “arrays of arrays” only
a multi-dimensional array as an object reference. Mynx has a basic array that is defined in the
programming language, and class-based arrays that are declared and defined using a Mynx class. Class-
based arrays avoid the restriction of declaring the rank of an array, and are more general, although lack
the bracket syntax of basic arrays.
A. Array Attributes
A basic array has three primary attributes:
A 1-dimensional array, the size and dim(0) length are equivalent, with a rank of 1. For an array that has
not be instantiated, the length and dimensions are undefined hence accessing undefined will flag a trap.
B. Declaration
Declaring an array uses the class, followed by the dimensions of the array in brackets. All array
dimensions begin at an index of 0, and continue to the dimension – 1. Such an array declaration is a
definite array declaration.
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.
An array is declared with the rank always explicitly given in definite or indefinite form, with an implicit
one dimensional array rank. An indefinite array can change its dimensions and have a new array created
and allocated, but the rank always is the same for an array.
C. Creation
An array declares a class type, and a fixed number of dimensions or rank. Declaring an array does not
allocate space for an array. Creating an array can be part of the declaration, following an as keyword with
an initial value list. Creating an array does allocate space for the instances of the type of that array.
- 174 -
An initial list is an explicit list of values with an implicit index starting at zero and continuing until the
length of the array offset by one.
D. Initialization
An array can be created by defining the array, and then by specifying initial values for that array. Space for
the array is allocated, and the instances are initialized with the initial value.
An array can be declared with explicit list of indices to initialize each location of the array to a specific
instance value type.
An array can be initialized with a list of initial values using an explicit integer list index with a colon ‘:’
separator. One special index uses an asterisk ‘*’ as an index for all other array indices.
- 175 -
Example of Creating an Array with Explicit Integer Index:
Deferred Creation
An array can be declared, but then created later with an as-clause and an initialization list. An as-clause
can also create a new array with the same rank, but different dimensions.
Creating a new array can use a constructor to initialize all new array instances, instead of an initial value
list of literals.
- 176 -
Null in Declaration
An array can use a null to indicate no initial value or initialization with a constructor. Then later the
reference can be initialized with a list of values.
E. Using an Array
An array is a homogeneous finite collection of instance objects as elements, all of the same type or class.
However, an array itself is an instance of an object, so using an array involves two forms of use:
Using an Element
An array can be used as the whole, or as one of its elements or parts. Using an element of an array
involves accessing the element of the array with an index into the element.
x = ints[0]; //x.set(ints[0]); x == 1
y is ints[1]; //y == ints[1]; y == 1
- 177 -
Using as an Object
An array can be used as an object, the entire collection of homogeneous element instances as a single
entity or object.
Passing as a Parameter
An array can be passed as an object to a method that only knows the type and rank of the array object.
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;
this.myMethod(array2D);
- 178 -
XV
Mynx File Types and Tools
- 179 -
There are six major Mynx file types used by different Mynx tools. Each Mynx tool uses the name of the file
extension. Instead of appending a character ‘c’ at the end of the compiler name, like mynxc, the
compiler is the same as the file extension mynx.
A. Mynx
A Mynx file type has the .mynx file extension, and mynx is the compiler tool name. A single Mynx class or
program has the same name as the file. So a program with the name helloWorld would be in a
helloWorld.mynx file. Multiple private classes can be included with a public class.
B. Myxm
A file with multiple Mynx classes all public is a .myxm file extension. MYXM is an anagram for MYnX
Multiple classes file type. The tool myxm separates and into individual Mynx class files, and compiles the
multiple Mynx classes.
C. Moxi
A Moxi or Mynx Object XML Interface file is the XML interface for a Mynx class, used by the compiler for
external semantic checks. The XML document specifies methods, attributes, overloads, and obviates of
the class. A program does not have a moxi file type. The moxi tool is an object-class browser, showing a
class in a module namespace, the methods, attributes, obviates, and overloads.
D. Myna
A myna or Mynx Archive is a ZIP-compatible archive file format. The Mynx tool allows adding, viewing,
extracting, and deleting files from the archive file. A myna file can be processed by other ZIP-compatible
programs.
E. Minx
A .minx file type is the end result of compiling Mynx into an intermediate platform-independent
representation in XML. Hence MINX is the acronym (and similar pronunciation as Mynx the
programming language) for Mynx INtermediate XML file type. The minx tool allows for translation into a
native programming language, originally Java and C#. As an XML file, a minx file is transformed into
HTML to place of Mynx code on the Internet.
- 180 -
F. Myxd
The myxd file type and tool is for the MYnx XML Documentation generator, which processes a Mynx or
Myxm source file and generates a myxd documentation file. The myxd tool allows the documentation to
be browsed and searched interactively.
- 181 -
- 182 -
XVI
Mutual Exclusion
- 183 -
A. Concept of Mutual Exclusion
Mutual exclusion (mutex) is a necessary language feature for writing platform independent multiple
threaded (multithreaded) classes in Mynx. The concept of mutual exclusion involves 2-elements:
Thread or Task
A thread or task is a “lightweight” process that is a window of execution for an object. A thread is an
object, but in multithreaded applications, more than one thread exists, but only one is actually executing.
A simple example of multithreading is when using one application, other activity can occur nearly
simultaneously. A thread allows activities to be separated and to occur concurrently, making an
application or library more useful. The term “thread” is from each “thread of execution” running on the
computer processor.
Mutex
In software that is designed for multithreading, methods and blocks of code within methods of a class can
have critical sections. A critical section is code that must be mutually exclusive to all other threads except
one. Essentially, only one thread can access and execute the block of code or method in a critical section.
Otherwise variables and values can change unpredictably.
For example, if two threads access a critical section in which a variable is changed based upon its value,
each thread might change the variable as the other is changing; essentially one thread interacts with the
other. The variable might be changed based upon the transient value of the other thread, causing it to be
updated incorrectly. Debugging synchronization bugs is difficult and frustrating.
A mutex is a mechanism to enforce that only one thread can access a critical section at a time. How the
mutex is implemented (semaphore, monitor, spin-lock, etc.) is less important than the mutual exclusion
of threads from a critical section. Referring to the update anomaly example, only one thread could execute
the critical section of code there would be no transient changes.
- 184 -
For example, the two methods are both asynchronous:
A sync or “synchronous” method has synchronization and is thread-safe or mutually exclusive. Once a
thread has acquired the mutex for a synchronized method, no other thread can execute or invoke that
method.
A method must explicitly use the sync keyword in the method declaration to specify thread-safety
through synchronization.
For example:
Only classes and methods of a class can be mutually exclusive, or have a mutex – class attributes cannot
be mutually exclusive. A class method, even when synchronized as with a mutual exclusion, has the
disadvantage that the entire method is mutually exclusive. The scope of mutual exclusion can be too
encompassing, when only a small block of statements is a critical section.
D. Mutex Statement
A mutex statement is used to create a block of mutual exclusive statements within a class method, without
making the method completely synchronized. A mutex statement does not create a separate thread, or
task. A mutex statement consists of a mutex header, the block of statements, and a mutex footer.
The mutex header begins with the keyword mutex, and the mutex variable or expression in parenthesis.
The mutex footer is simply the keyword end followed by mutex and a semicolon.
mutex ( EXPRESSION )
STATEMENTS
end mutex ;
The statements can be any possible statement, including another nested mutex statement.
- 185 -
E. Mutex Expression
The mutex expression is an expression for an object lock, or in actuality, a monitor for the object. A
monitor is a fundamental mutual exclusion concept, but for each object there is one lock. Hence a
synchronized method uses the instance object lock implicitly, but for a block of statements it requires an
explicit lock – in the form of an expression. The simplest lock is to use the keywords of this and self
class references for the object instance and class static reference locks, respectively.
mutex(this)
STATEMENTS STATEMENTS
end mutex;
mutex(self)
STATEMENTS STATEMENTS
end mutex;
Hence an asynchronous method with a mutex statement for the entire block of statements for a method is
equivalent to the synchronized method on the instance or static class reference.
For example:
- 186 -
overload constant + as concat;
end concat;
Then the use of the + operator, and invokes the method concat, which is a synchronized or mutex
method.
Indirectly an operator invokes a method that is mutually exclusive. An operator overloaded method is the
same a direct access and invocation of a method, only implicitly. Mutual exclusion and synchronization is
basically implicit to the method, overload is merely an indirect way to call the method.
- 187 -
- 188 -
Glossary of Terminology
The specific terminology or jargon used with the Mynx programming language is summarized as the term
and the relevant definition of the term. (142-words in glossary) add mutex statement terms and jargon.
Abstract: a class and method mode that is undefined for a method, or partially defined for a class.
Array Dimension: the length of a dimension, the upper bound for an array index.
Array Rank: the number of dimensions for an array. Non-array instances have a rank of zero.
Array Size: the product of all dimensions for the total space or size of the array.
Assert Statement: a statement that verifies a condition is true, or else it will flag a trap.
Assignment: an operator and statement that associates values from one reference name to another.
Asynchronous: a single-threaded method that does not require mutual exclusion or synchronization.
Case Statement: a statement that determines which statements to execute based upon the value of a
discrete variable.
Checked Exception or Trap: a trap that must be handled with a try statement by the calling method.
Class Kind: the kind of class that controls instantiation and inheritance of the class.
Comment: a remark or commentary in the source for a class or program that is ignored by the compiler.
Constructor: a special class method that constructs or creates a new instance of a class and initializes it.
- 189 -
Contra variant: an override of a class type with a super-class type. Contra variance is not used in method
overriding.
Covariant: an override of a class type with a sub-class type. Covariant overriding is only possible with
instance method return types.
Creating an array: defining an array, and giving a size or array bounds that allocates memory or space.
Creation: a kind of expression statement that creates a new instance of a class type.
Decision: a statement category that decides which statement to execute.
Declaration: a kind of expression statement for declaring a variable by name, class type, and possible
initial value.
Declared Method: a class method that is stated by method type, parameters, signature, and scope, but not
defined with statements.
Default: a namespace that is used implicitly by default when no namespace is specified for a class.
Default Class: the normal category of class that can be instantiated and sub-classed by inheritance.
Default Method: the implicit method of a class called through an instance when none is invoked.
Default Method: a special method that is implicitly invoked or called on an instance when no method is
specifically invoked.
Default namespace: the namespace 'default' that is the implicit default namespace if none is specified for a
class or program.
Defined Method: a class method or program method, which is declared, and defined with a body of
statements.
Definite Array Declaration: declaring an array that has rank and size, but not initial values.
Enumerated type: a named discrete set of named constants that are treated as a unique type. Each
constant has a non-negative integral value, and a string name.
Escaped character: a character that uses an escape prefix ‘\’ for non-literal characters such as carriage
returns and end of line characters.
- 190 -
Flow of Control: a statement category for statements which alter execution of a method in a class or
program.
For Statement: an iterative statement over an explicit integral range or over a 1-dimensional array of
elements.
Generic: a kind of class in which the type is generalized, and so can be parameterized for a specific type.
Global Instantiation: a form of binding a generic class to a type that exists outside the invocation of the
statement.
Implicit Static Method: an inclusion of class method which is static or singular mode.
Implied Method: a method that is declared but not defined; the implied method is defined in the native
implementation language.
In: a parameter passing mode that cannot be null and the reference cannot be changed.
Indefinite Array Declaration: declaring an array that has rank, but not array bounds or size, or any initial
values.
Inheritance: a method of code re-use by classes to modify and extend the functionality of a parent class in
a derived child class.
Initializing an array: defining and creating an array, then initializing the array instance elements with
initial values.
Instantiation: to create a new instance of a class, or to bind a generic class to a specific class type.
Invariant: an override of a method by exact method signature including method parameters and return
type.
Iteration: a category of statement for repeating multiple times over a block of statements with some
logical condition to continue or stop.
Keyword: an identifier that is used by the programming language, and cannot be used in names.
Literal: a basic lexical element that is a word of actual data; an anonymous constant.
Local Instantiation: a form of binding a generic class to a type that exists only for the invocation of the
statement.
Meta String: an abstract string that contains information that is translated by the compiler into a literal
string.
- 191 -
Method: the functionality of a class or program.
Method Equivalent: a declared method that is defined in terms of another defined method in a class.
Method Mode: a method qualifier indicating if it is a class or instance method, can be overridden, and is
defined in the class.
Method Type: the return type of a method, non-void is a function method, void is a procedure method.
Multiple Disjoint Inheritance: a class that inherits multiple abstract classes, but there is no method
signature overlap, hence all methods for each non-virtual abstract class inherited multiply times is
unique.
Multiple-line: a statement that can nest other statements and spans multiple lines as a "block" of
statements.
Multiple threaded: a class method that runs multiple threads of execution and requires synchronization
for mutual exclusion.
Mutual exclusion: in multiple threaded programming, excluding all other threads except one from
executing a block of code to avoid anomalous changes to variables.
Namespace: a means of organizing classes into a hierarchy of names that contain a specific class.
Obviate Method: a method that is hidden or removed from the class interface.
Opaque Class: a class which when compiled does not have the capability for runtime type information
(RTTI) introspection.
- 192 -
Operator Category: the classification of the operator.
Out: a parameter mode where the parameter can be null, and the reference can change.
Overload: to associate an operator with a method which implements the functionality of the operator.
Prefix If Statement: an if statement that has a next or exit preceding the conditional if clause.
Private: an access to a class qualifier that makes a class attribute or method inaccessible externally.
Protect: an access to a class qualifier that makes a class attribute or method inaccessible externally, but
available to a sub-class.
Public: an access to a class qualifier that makes a class attribute or method available.
Return Statement: a statement that terminates a called method, possibly returning data.
Self Class Prefix: an explicit reference to a static method of the current class.
Self Method: an abstract class method that refers to self, or the future class type when the class is a
tangible default class.
Serialization: saving a class state in the form of its attributes to external storage.
Series: a parameter mode where multiple variable number of parameters are passed as a 1-dimensional
array.
- 193 -
Single-line: a statement that cannot nest other statements.
Single-threaded: a class method that does run multiple threads of execution and does not require
synchronization for mutual exclusion.
Statement: The most basic element of software code, the organizing unit of defining software
functionality.
Super Class Prefix: an explicit reference to a method or attribute of the parent class.
Synchronous: a multiple threaded method that does require mutual exclusion and synchronization.
This Class Prefix: an explicit reference to an instance method or attribute of the current class.
Try Statement: a statement that encloses statements to handle any flagged traps.
Unchecked Exception or Trap: a trap that optionally can be handled with a try statement by the calling
method.
Undefined Method: a method that is declared but not defined, such as an abstract, implied, or virtual
method.
Until Statement an iterative loop statement that continues until a condition is true.
Var a parameter passing mode that can be null, and the object reference can change within the called
method.
Virtual: a method and class type that declares the method but does not declare it.
While Statement: an iterative loop statement that continues until a condition is false.
- 194 -
Appendix Mynx Grammar
- 195 -
A. Header Syntax
B. Class Syntax
*
CLASSES := CLASS (CLASS)
*
CLASS := [CLASS_MODE] class ID [as (IDLIST | null )][has ID to ID] is (CLASS_BODY) end class ‘;’
CLASS_MODE := abstract | constant | default | generic | singular | static | virtual
CLASS_BODY := CLASS_METHOD | CLASS_ATTRIBUTE | CLASS_OVERLOAD | CLASS_OBVIATE
| CONSTRUCT | DESTRUCT | DEFAULT
C. Class Methods
CLASS_METHOD := METHOD_HEADER [is (METHOD_EQUIV| implied | METHOD_BODY) ] ‘;’
METHOD_EQUIV := to (null | METHOD_EQUAL | METHOD_ACCESS)
METHOD_HEADER := ACCESS [SYNC][METHOD_MODE][METHOD_TYPE] ID [ARGS][TRAPS][SCOPE]
SYNC := async | sync
METHOD_MODE := abstract | constant | covariant | default | own | singular | static | virtual
METHOD_TYPE := (ID | generic) [DIMLIST] | self | void
TRAPS := has IDLIST
*
ARGS := ‘(‘[FIXED_ARGS (‘,’ FIXED_ARGS) ] [‘,’ VARY_ARGS] ‘)’
FIXED_ARGS := [in | out | var] (ID | generic | self ) [DIM_LIST] ID
VARY_ARGS := series (ID | generic | self ) DIM_LIST ID
ACCESS := public | protect | private
METHOD_EQUAL := [METHOD_PREFIX] ID [ARGLIST]
SCOPE := (in | out) for (all | null | IDLIST)
METHOD_BODY := STATEMENTS end ID
METHOD_ACCESS := (access | reader | writer) ID
METHOD_PREFIX := (super | this | self | ID ) ‘.’
CONSTRUCT := ACCESS construct [ARGS][SCOPE] is [METHOD_EQUIV | CONSTRUCT_BODY] ‘;’
CONSTRUCT_BODY := STATEMENTS end construct
DESTRUCT := ACCESS destruct is [METHOD_EQUIV | DESTRUCT_BODY] ‘;’
DESTRUCT_BODY := STATEMENTS end destruct
DEFAULT := ACCESS default is to ( ID | null) ‘;’
D. Class Attribute
E. Class Overload
- 196 -
G. Program
H. Statements
*
STATEMENTS := STATEMENT ‘;’ (STATEMENT ‘;’)
STATEMENT := ASSERT_STATEMENT | CASE_STATEMENT | EXPRESSION_STATEMENT
| EXIT_STATEMENT | FLAG_STATEMENT | FOR_STATEMENT
| IF_STATEMENT | LOOP_STATEMENT | MUTEX_STATEMENT
| NEXT_STATEMENT | NULL_STATEMENT | PREFIX_IF_STATEMENT
| REPEAT_STATEMENT | RETURN_STATEMENT | TRY_STATEMENT
| UNTIL_STATEMENT | WHILE_STATEMENT
- 197 -
I. Expression Statements
- 198 -
K. Comments
* *
COMMENT := ‘//’ (UNICODECHAR) (‘\n’ | ‘\r’ | ‘\n’ ‘\r’) | ‘!!’ (UNICODECHAR) ‘!!’
- 199 -
- 200 -
References
Hoare, C. A. R. (1973). Hints on Programming Language Design, Stanford
University, Computer Science Department, TR CS-73-403.
- 201 -
- 202 -
Index
absolute Cast Assignment Operator :=, 72
namespace, 45, 46, 47, 107, 108, 187 Checked
abstract Trap, 124, 187
method mode, 41 class
access, 13, 14, 17, 20, 33, 34, 35, 41, 56, 61, 62, 90, abstract, 20, 29, 30, 41, 42, 50, 51, 53, 54, 56, 57,
91, 93, 107, 108, 112, 113, 114, 116, 118, 121, 61, 63, 114, 119, 120, 121, 130, 131, 132, 134,
139, 140, 141, 142, 158, 164, 175, 182, 185, 191, 135, 136, 158, 164, 189, 190, 191, 192, 194
194 constant, 14, 17, 20, 25, 29, 30, 32, 33, 34, 35, 36,
Access, 61, 68, 90, 91, 92, 97, 141, 187 38, 41, 55, 56, 57, 59, 60, 63, 64, 82, 93, 95, 96,
access sub-expression, 141 102, 104, 107, 110, 114, 116, 119, 141, 142,
Accessor Methods, 111 148, 159, 164, 169, 176, 185, 187, 188, 189,
Addition Operator +, 87 192, 194, 195
Advanced Method Definition, 102 default, 29
aggregate collection, 172 generic, 13, 20, 29, 30, 42, 54, 56, 63, 130, 131,
array, 38, 39, 90, 91, 140, 141, 142, 148, 149, 164, 132, 133, 134, 135, 136, 189, 194
172, 173, 174, 175, 176, 187, 188, 189, 191 singular, 20, 23, 29, 30, 32, 35, 41, 42, 55, 56, 57,
Array Access [], 91 64, 102, 103, 104, 106, 107, 110, 114, 119, 120,
array declaration, 172 138, 164, 189, 194
assert statement, 143 static, 13, 20, 25, 29, 30, 32, 33, 34, 35, 41, 42, 53,
assignment, 69, 70, 72, 73, 74, 75, 76, 77, 117, 139, 55, 56, 57, 60, 63, 64, 95, 102, 103, 104, 105,
140, 141 106, 107, 108, 110, 114, 119, 120, 131, 184,
Assignment, 23, 68, 69, 70, 72, 73, 74, 75, 76, 77, 189, 191, 192, 194, 195
92, 97, 98, 140, 187 virtual, 20, 29, 30, 35, 41, 42, 47, 50, 51, 52, 53,
Assignment statement, 140 54, 56, 58, 59, 61, 83, 93, 94, 95, 102, 103, 104,
Async, 182 114, 120, 121, 131, 134, 158, 164, 190, 192, 194
asynchronous Class, 14, 23, 27, 28, 29, 34, 35, 41, 49, 51, 53, 54,
method synchronization, 41, 42, 182, 183, 184 55, 56, 58, 59, 60, 61, 62, 63, 89, 101, 105, 110,
asynchronous method, 184 114, 116, 119, 132, 133, 164, 167, 168, 172, 176,
Asynchronous methods, 182 183, 187, 188, 190, 191, 192, 194
asynchronous mode, 42 Class Attributes, 34
Attribute Access `, 90 Class Creation, Destruction, and Default,
Attribute Kind, 32, 187 114
Attribute Mode, 32, 187 class header, 28, 133
Attribute Scope, 33 class method, 35, 41, 42, 56, 57, 59, 62, 90, 102,
Attribute Type, 32 104, 105, 106, 108, 110, 113, 119, 120, 158, 164,
Attributes, 31, 32, 33, 34, 55, 107, 130, 172 168, 183, 184, 187, 188, 189, 190, 191, 192
generics, 130 Class Methods, 35
Bitwise, 23, 68, 75, 76, 77, 78, 79, 80, 81, 92, 97, 98 Class Reference Prefixes, 60
Bitwise Complement Operator ~, 80 Comments, 24, 197
Bitwise Exclusive-Or Assignment computation, 138, 139, 187
Operator ^=, 76 constant
Bitwise Inclusive-Or Assignment method mode, 41
Operator |=, 75 operator overload, 93
Bitwise Shift Left Operator <<, 80 Constructor, 114, 116, 173, 174, 187
Bitwise Shift Right Operator >>, 81 Constructor Definition, 114
Bitwise Shift-Right Assignment Operator Constructor Invocation, 116
>>=, 76 covariant method, 57, 58
Bitwise-And Assignment Operator &=, 75 Covariant Method, 57, 58
Bitwise-Shift-Left Assignment Operator covariant method return type, 57
<<=, 77 creation, 41, 69, 70, 117, 139, 140, 141, 188
Case Operator to, 71 creation statement, 140
case statement, 13, 150, 153, 154
- 203 -
declaration, 14, 15, 25, 32, 33, 34, 35, 41, 45, 46, generic class, 130
47, 50, 70, 93, 108, 116, 117, 118, 121, 135, 139, generic methods, 130
172, 183, 188, 189 global instantiation, 132
Declaration Goals
Trap, 44, 46, 93, 124, 139, 158, 172, 175, 188, 189 Mynx programming language, 18
declaration statement, 139 Greater Equal Operator >=, 84
default Greater Than Operator >, 84
attribute mode, 32 Handling
class category, 13, 14, 17, 20, 22, 23, 28, 29, 30, Trap, 125
32, 33, 34, 40, 41, 42, 44, 51, 52, 54, 55, 56, 58, hexadecimal number, 21
62, 64, 70, 86, 93, 95, 96, 102, 103, 104, 105, Identifiers, 20, 196
108, 109, 110, 114, 115, 116, 117, 118, 119, if statement, 126, 146, 153, 154, 155, 191
120, 121, 130, 132, 133, 134, 135, 139, 141, Implicit Accessor Methods, 112
142, 145, 153, 155, 158, 164, 168, 173, 174, implicit hierarchy
175, 176, 182, 184, 185, 188, 189, 191, 194, operators, 99
195, 196 implicit namespace, 44
method mode, 41 implied, 20, 58, 121, 158, 159, 160, 161, 164, 167,
operator overload, 93 168, 189, 192, 194
Default Method Declaration, 120 implied method, 121, 158, 159
Default Method Invocation, 120 in parameter, 36, 37, 38
Default Namespace, 44 In Parameter Mode, 36
Default Parameters by Method Incomplete Methods, 121
Equivalents, 109 Increment and Decrement Operator -- or
Definition ++, 89
generic class, 130 Inequality Operator !=, 82
Destructor, 114, 118, 119, 188 Inheritance, 29, 49, 50, 51, 53, 54, 55, 56, 57, 61,
Destructor Definition, 118 131, 165, 167, 189, 190, 191, 192
Destructor Invocation, 119 generic class, 131
dim, 40, 172, 176 Inheriting Other Classes
Division Operator /, 88 generic class, 134
Division-Assignment Operator /=, 74 Initial Value, 33, 189
Dottic Access, 61 input-output, 139, 141
Dual Assignment Operation Operators, 72 input-output sub-expression, 141
Encoding, 24 Insertion Operator <<<, 86
enumerated type, 25, 107 Instance Type Of Operator in, 83
Enumerated Types, 25 Instantiation
Equality Operator ==, 82 generic class, 132, 134, 189
error, 33, 36, 37, 38, 39, 40, 42, 47, 55, 58, 96, 104, Introduction, 11
108, 113, 117, 121, 124, 126, 138, 141, 143, 144, invalid namespace declaration, 44
148, 164, 165, 166, 168, 169, 173, 175, 188, 192 Invocation
error statement, 143 Trap, 90, 124, 168, 190
escaped character, 21 Keywords, 20
exception, 124, 125, 126, 143, 188, 192 kinds of classes, 29, 54
exit statement, 145, 146 kinds of static, 102
Explicit Accessor Methods, 112 Kinds of Traps, 124
Exponentiation Operator **, 88 Lesser Equal Operator <=, 85
Export Instance Method, 110 Lesser Than Operator <, 83
expression, 17, 33, 72, 91, 113, 116, 117, 120, 121, literal character, 21
138, 139, 140, 141, 142, 143, 175, 183, 184, 188 Literals, 20, 196
expression statement, 116, 120, 139, 141, 188 local instantiation, 132
Extraction Operator >>>, 86 Logical, 23, 68, 78, 79, 80, 81, 92, 97, 98
flag statement, 124, 143 Logical And Operator &&, 79
flow of control or jump, 138 Logical Bitwise And Operator &, 79
for statement, 148, 149 Logical Bitwise Inclusive Or Operator |, 79
generic, 130 Logical Exclusive Or Operator ^, 81
generic attribute, 130 Logical Not Operator !, 78
- 204 -
loop statement, 146, 148, 149, 150, 151, 192 myxd, 179
major design principles, 17 myxm, 178
Manifesto, 13 Name
Mathematic, 23, 87, 92 Mynx, 12, 22, 32, 61, 97, 98, 110, 164, 178
Mathematical, 68, 89, 97 namespace, 44, 45, 46, 47, 106, 107, 158, 178, 187,
meta string, 22, 23 188, 191
Meta Strings, 22 namespace declaration, 45, 46
Method definition by a method equivalent, 102 next statement, 145, 146
Method definition that is incomplete, 102 non-existent namespace, 47
Method Equivalents, 108, 109 nothing inheritance, 50
Method Headers, 42 Null
Method Invocation ., 90 inheritance, 50
Method Mode, 41, 190 null statement, 139, 142, 143, 154
Method Overloading, 59 Nullity, 36
Method Overriding, 56, 57 Numbers, 21
Method Parameter Modes, 36 numeric real literal, 22
Method Return Type, 42 obviate, 121, 164, 165, 166, 167, 168, 169
Method Scope, 40 obviate method, 121, 164
method signature, 34, 35, 42, 56, 59, 106, 108, 121, Obviate Method, 165, 168, 190
164, 165, 168, 189, 190 Operator =, 70, 82
Method Synchronization, 41, 190 operator as, 70
Method Traps, 40 operator is, 69, 72, 79, 80, 82, 83, 84, 85, 86, 93,
Method usage with a static method, 102 95, 117
Methods, 17, 31, 32, 34, 35, 41, 55, 56, 100, 101, Operator Overloading, 60, 67, 93, 95, 191
102, 103, 106, 108, 110, 111, 112, 114, 121, 130, Operators, 23, 61, 67, 68, 69, 72, 78, 79, 82, 86,
135, 143, 157, 158, 163, 164, 167, 182, 184, 194 87, 89, 90, 92, 97, 99, 100
minx, 178 Other Special Methods, 121
Modulus Operator %, 88 out parameter, 37
Modulus-Assignment Operator %=, 74 Out Parameter Mode, 37
Moxi, 178 Overriding a Static Method, 102
multi-dimensional, 172 Parameter List, 35, 191
Multiple Disjoint parameter mode, 35, 36, 37, 38, 42, 191
inheritance, 50, 53, 54, 190 Parameterized Types, 130
Multiple disjoint inheritance, 53 parameters, 14, 30, 33, 35, 36, 37, 38, 39, 42, 56,
multiple line comment, 24 61, 105, 108, 109, 114, 115, 117, 118, 121, 124,
Multiple Virtual 140, 164, 165, 188, 189, 191
inheritance, 50, 52, 53, 190 partial
Multiple virtual inheritance, 52 class category, 22, 29, 30, 54, 114, 120, 121
Multiple-line comments, 24 Philosophical Statement, 17
Multiplication Operator *, 88 Post-conditional loop, 152
Multiplication-Assignment Operator *=, postfix, 93, 139
73 postfix expression, 139
multithreaded, 182 pre-conditional loop, 152
mutex, 20, 138, 156, 182, 183, 184, 185, 187, 195 prefix-if statement, 146, 150
mutex expression, 184 primary design criteria, 13
mutex statement, 156, 183, 184 Principles of Design, 17
mutual exclusion, 138, 156, 182, 183, 184, 187, Program, 22, 27, 28, 34, 35, 106, 191, 195
190, 192 Program Attributes, 34
Mutual exclusion, 182, 185, 190 program method, 35, 40, 41, 147, 188
myna, 178 Program Methods, 35
Mynx, 11, 12, 13, 16, 17, 18, 20, 22, 23, 24, 25, 28, Program Methods as Default Static, 106
29, 30, 33, 41, 44, 45, 46, 47, 50, 51, 52, 54, 56, Project
57, 59, 60, 61, 68, 69, 78, 79, 80, 81, 82, 83, 84, Mynx, 12
85, 86, 87, 88, 90, 92, 98, 99, 102, 107, 108, 111, Prolog, 12
112, 121, 124, 130, 132, 138, 142, 158, 159, 160, Propagation
164, 169, 172, 176, 177, 178, 179, 182, 187, 193 Trap, 126
- 205 -
Proxima, 11, 12, 13, 15 Stream, 23, 46, 68, 86, 92, 97, 98
rank, 82, 172, 174, 175, 176, 187, 188, 189 Subtraction Operator -, 87
Reference Assignment Operator is, 69 Subtraction-Assignment Operator -=, 73
References, 36, 199 super, 20, 30, 34, 50, 53, 55, 56, 57, 58, 59, 60, 61,
other works, 199 62, 64, 83, 90, 91, 95, 104, 108, 115, 116, 119,
Relational, 23, 68, 82, 92, 97, 98 120, 132, 140, 141, 142, 165, 166, 168, 169, 188,
relative 191, 194, 196
namespace, 45, 46, 96, 107 Symbols, 21
Renaming All Class Methods of a Name, Sync, 182
110 synchronization, 41, 42, 182, 183, 185, 187, 190,
repeat loop, 151 192
repetition or iteration, 138 synchronous
repetition statement, 145, 146, 150, 151 method synchronization, 41, 42, 183, 184
reserved words, 20, 25, 41, 44 synchronous mode, 42
restricted Target Platforms, 16
class category, 29, 53, 54, 55, 93 task, 182, 183
return statement, 147 this, 15, 20, 23, 24, 39, 42, 55, 60, 62, 63, 64, 83, 90,
Return Types for Mathematical 91, 105, 109, 110, 111, 112, 113, 114, 115, 116,
Operators, 89 118, 119, 120, 124, 131, 133, 140, 141, 142, 145,
Rules for Method Overriding, 56 147, 153, 155, 160, 176, 184, 194, 196
Rules for Operator Overloading, 95 Thread, 182
scope of attributes, 33 Trap, 124, 126, 187, 192
scoping methods, 40 try clause, 125
selection or decision, 138 try statement, 40, 124, 125, 126, 143, 144, 187, 192
self, 13, 14, 20, 56, 57, 60, 63, 64, 65, 105, 106, 132, Types of Inheritance, 50
134, 135, 140, 184, 191, 194, 196 Types of Instantiation
series parameter, 38, 39 generic class, 132
Series Parameter Mode, 38 Unchecked
signature, 35, 52, 56, 57, 164, 165, 188 Trap, 124, 192
Single Undefined Method Header, 42
inheritance, 51 Unhandled Traps, 127
Single inheritance, 51 Unicode escape character, 21
Single-line comments, 24 until-loop repetition statement, 150
singular var parameter, 37, 38
method mode, 41 Var Parameter Mode, 37
size, 12, 34, 79, 87, 131, 132, 133, 135, 136, 146, virtual
172, 176, 187, 188, 189 method mode, 41
statements, 138 volatile
static attribute mode, 32
method mode, 41 while-loop repetition statement, 150
static method, 102 word operators, 23
static reference, 107
- 206 -