the mynx book october 2007

222
Mynx Programming Language Manual October 2007

Upload: william-gilreath

Post on 31-May-2018

224 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: The Mynx Book October 2007

8/14/2019 The Mynx Book October 2007

http://slidepdf.com/reader/full/the-mynx-book-october-2007 1/222

MynxProgramming Language

Manual

October 2007

Page 2: The Mynx Book October 2007

8/14/2019 The Mynx Book October 2007

http://slidepdf.com/reader/full/the-mynx-book-october-2007 2/222

 Mynx Programming Language

- 2 -

Page 3: The Mynx Book October 2007

8/14/2019 The Mynx Book October 2007

http://slidepdf.com/reader/full/the-mynx-book-october-2007 3/222

 Mynx Programming Language

- 3 -

The Mynx ProgrammingLanguage Manual

Copyright October 2007

William F. Gilreath

http://www.williamgilreath.com/mynx

Page 4: The Mynx Book October 2007

8/14/2019 The Mynx Book October 2007

http://slidepdf.com/reader/full/the-mynx-book-october-2007 4/222

 Mynx Programming Language

- 4 -

This book is licensed under the terms of the GNU FreeDocumentation License.

Permission is granted to copy, distribute and/or modify thisdocument under the terms of the GNU Free Documentation License,Version 1.2 or any later version published by the Free SoftwareFoundation; with the Invariant Sections being "Prolog" and“Epilog”, no Front-Cover Texts, and no Back-Cover Texts. A copyof the license is included in the section entitled "GNU Free

Documentation License".

Page 5: The Mynx Book October 2007

8/14/2019 The Mynx Book October 2007

http://slidepdf.com/reader/full/the-mynx-book-october-2007 5/222

 Mynx Programming Language

- 5 -

 Table of ContentsPROLOG .........................................................................................................................................................13

PRELUDE.......................................................................................................................................................15N AME AND PROJECT...................................................................................................................................15PHILOSOPHICAL S TATEMENT ....................................................................................................................16

 T ARGET PLATFORMS...................................................................................................................................16M ANIFESTO ..................................................................................................................................................17L ANGUAGE PRINCIPLES .............................................................................................................................20DESIGN R  ATIONALE ...................................................................................................................................21

Syntax .......................................................................................................................................................21Statements................................................................................................................................................21Units .........................................................................................................................................................22

GOALS ...........................................................................................................................................................23

LICENSE ........................................................................................................................................................24License Objectives..................................................................................................................................24Documentation.......................................................................................................................................24Software ...................................................................................................................................................24

LEXICON........................................................................................................................................................25

IDENTIFIERS .................................................................................................................................................27K EYWORDS...................................................................................................................................................27LITERALS.......................................................................................................................................................28S YMBOLS .......................................................................................................................................................28NUMBERS ......................................................................................................................................................29

META S TRINGS.............................................................................................................................................30OPERATORS ..................................................................................................................................................31ENCODING ...................................................................................................................................................32COMMENTS...................................................................................................................................................32

Single Comments....................................................................................................................................32Multiple Comments................................................................................................................................32

ENUMERATED T YPES..................................................................................................................................33

STATEMENTS...............................................................................................................................................35

COMPUTATION.............................................................................................................................................38Expression Statement ............................................................................................................................38

Declaration..........................................................................................................................................38

Expression...........................................................................................................................................38Postfix .............................................................................................................................................39

 Assignment.....................................................................................................................................39 Assign..........................................................................................................................................39Create..........................................................................................................................................39Input-Output .............................................................................................................................40

 Access..............................................................................................................................................40 Attribute .....................................................................................................................................40

Page 6: The Mynx Book October 2007

8/14/2019 The Mynx Book October 2007

http://slidepdf.com/reader/full/the-mynx-book-october-2007 6/222

 Mynx Programming Language

- 6 -

Method .......................................................................................................................................41 Array............................................................................................................................................41Multiple.......................................................................................................................................41

Null Statement ........................................................................................................................................42ERROR ...........................................................................................................................................................42

 Assert Statement .....................................................................................................................................42Flag Statement.........................................................................................................................................43

 Try Statement..........................................................................................................................................43FLOW OF CONTROL ....................................................................................................................................44

Exit Statement.........................................................................................................................................45Next Statement .......................................................................................................................................46Prefix If Statement .................................................................................................................................46Return Statement....................................................................................................................................47

R EPETITION .................................................................................................................................................48For Statement..........................................................................................................................................48

For Statement over a Range.............................................................................................................48For Statement over an Array............................................................................................................49

For Statement over Other Integral Type........................................................................................49Until Statement .......................................................................................................................................51

 While Statement......................................................................................................................................51Repeat Statement....................................................................................................................................52Pre-conditional and Post-conditional Loops......................................................................................53Case Statement........................................................................................................................................54If Statement .............................................................................................................................................55

MUTEX S TATEMENT ...................................................................................................................................57Mutex Statement Syntax........................................................................................................................57Mutex Expression...................................................................................................................................57

N AMESPACES................................................................................................................................................59

Declaration ..............................................................................................................................................59Default Namespace ................................................................................................................................59Classes and Programs within a Namespace........................................................................................60Inclusion of Classes from a Namespace .............................................................................................60Nested Namespace Inclusion ...............................................................................................................61Declaration Order for Namespace Inclusion .....................................................................................62Mynx Namespace ...................................................................................................................................62Nonexistent Namespace Inclusion ......................................................................................................62Static Inclusion from Default Namespace..........................................................................................63

 ARRAYS .........................................................................................................................................................64 Array Attributes ......................................................................................................................................64

 Array Declaration ...................................................................................................................................65 Array Creation.........................................................................................................................................66Initialization with a List.....................................................................................................................66

Initialization with an Implicit Indexed List................................................................................66Initialization with an Explicit Indexed List................................................................................67

Initialization with a Non-List ...........................................................................................................67Initialization with Default Constructor ......................................................................................67Initialization with Null..................................................................................................................68

Using an Element of an Array..........................................................................................................69

Page 7: The Mynx Book October 2007

8/14/2019 The Mynx Book October 2007

http://slidepdf.com/reader/full/the-mynx-book-october-2007 7/222

 Mynx Programming Language

- 7 -

 Array as an Object..............................................................................................................................70 Array as a Parameter..........................................................................................................................70

 TRAPS ............................................................................................................................................................72Kinds of Traps........................................................................................................................................72

 Trap Declaration.....................................................................................................................................72 Trap Invocation ......................................................................................................................................72 Trap Handling.........................................................................................................................................73 Trap Propagation....................................................................................................................................73

UNITS...............................................................................................................................................................75

PRIMARY ELEMENTS – PROGRAM AND CLASS ........................................................................................77Program....................................................................................................................................................77Class..........................................................................................................................................................78

K INDS OF CLASSES ......................................................................................................................................78 Abstract ....................................................................................................................................................79Constant ...................................................................................................................................................79Default......................................................................................................................................................79

Generic.....................................................................................................................................................79Singular.....................................................................................................................................................80Static .........................................................................................................................................................80

 Virtual .......................................................................................................................................................80CLASS DESIGN R  ATIONALE .......................................................................................................................81INHERITANCE AND CLASS T YPES..............................................................................................................82

 T YPES OF INHERITANCE.............................................................................................................................82Null ...........................................................................................................................................................82Single ........................................................................................................................................................83Multiple Virtual .......................................................................................................................................84Multiple Disjoint.....................................................................................................................................85

CLASSES AND INHERITANCE......................................................................................................................87INHERITANCE OF A TTRIBUTES AND METHODS......................................................................................87 Attributes .................................................................................................................................................87Methods ...................................................................................................................................................88

INHERITANCE OF METHODS .....................................................................................................................88METHOD O VERRIDING ..............................................................................................................................88

Rules for Method Overriding ...............................................................................................................89Covariant Method Overriding ..............................................................................................................90Method Overloading..............................................................................................................................92

OPERATOR O VERLOADING .......................................................................................................................93CLASS R EFERENCE PREFIXES ....................................................................................................................93

Dottic Access Prefix...............................................................................................................................94Super Class Prefix ..............................................................................................................................94

 This Class Prefix.................................................................................................................................95Self Class Prefix ..................................................................................................................................97

GENERICS .....................................................................................................................................................98Elements of a Generic Class.................................................................................................................98

Generic Attributes..............................................................................................................................98Generic Methods................................................................................................................................99

Operator Overloads in Generic Class .................................................................................................99

Page 8: The Mynx Book October 2007

8/14/2019 The Mynx Book October 2007

http://slidepdf.com/reader/full/the-mynx-book-october-2007 8/222

 Mynx Programming Language

- 8 -

Default Method in Generic Class.......................................................................................................100Inheritance with Generic Classes .......................................................................................................100

Inheriting a Generic Class...............................................................................................................101Inheriting Non-Generic Classes.....................................................................................................101

Inheriting an Abstract Class.......................................................................................................102Inheriting a Virtual Class............................................................................................................103

Instantiation of a Generic Class .........................................................................................................104Local Instantiation.......................................................................................................................104Global Instantiation ....................................................................................................................105

Instance of a Generic Class.................................................................................................................106

ELEMENTS..................................................................................................................................................109

MINOR ELEMENTS ....................................................................................................................................111 A TTRIBUTES ...............................................................................................................................................111

  Attribute Mode......................................................................................................................................111 Attribute Kind.......................................................................................................................................111 Attribute Type.......................................................................................................................................112

 Attribute Name.....................................................................................................................................112Initial Value............................................................................................................................................112

 Attribute Scope.....................................................................................................................................112PROGRAM A TTRIBUTES ............................................................................................................................113CLASS A TTRIBUTES....................................................................................................................................113METHODS ...................................................................................................................................................114

Program Methods.................................................................................................................................114Class Methods.......................................................................................................................................114Parameter List .......................................................................................................................................115Method Parameter Modes...................................................................................................................115

In Parameter Mode..........................................................................................................................115

Out Parameter Mode.......................................................................................................................116  Var Parameter Mode........................................................................................................................117Series Parameter Mode....................................................................................................................118

Method Traps........................................................................................................................................119Method Scope .......................................................................................................................................120

CLASS METHODS .......................................................................................................................................121Method Mode........................................................................................................................................121Method Synchronization .....................................................................................................................121Method Return Type............................................................................................................................122Method Headers ...................................................................................................................................122Undefined Method Header .................................................................................................................123

 ADVANCED METHOD DEFINITION AND USE.......................................................................................123S TATIC METHODS......................................................................................................................................123

Kinds of Static Methods......................................................................................................................123Overriding a Static Method.................................................................................................................124Prefix for Static Method......................................................................................................................126Program Methods as Default Static...................................................................................................127Implicit Static Method Inclusion........................................................................................................127Reference to External Static Method.................................................................................................128

METHOD EQUIVALENTS: LOW F AT METHODS ....................................................................................130

Page 9: The Mynx Book October 2007

8/14/2019 The Mynx Book October 2007

http://slidepdf.com/reader/full/the-mynx-book-october-2007 9/222

 Mynx Programming Language

- 9 -

Default Parameters by Method Equivalents.....................................................................................131Export Instance Method .....................................................................................................................131Renaming All Class Methods of a Name ..........................................................................................132

CONSTRUCTION, DESTRUCTION, AND DEFAULT METHOD OF A CLASS ..........................................133CONSTRUCTOR ...........................................................................................................................................133

Constructor Definition ........................................................................................................................133Constructor Invocation .......................................................................................................................135

DESTRUCTOR .............................................................................................................................................137Destructor Definition ..........................................................................................................................137Destructor Invocation..........................................................................................................................137

DEFAULT CLASS METHOD .......................................................................................................................139Default Method Declaration...............................................................................................................139Default Method Invocation ................................................................................................................139

INCOMPLETE METHODS...........................................................................................................................140IMPLIED METHODS ...................................................................................................................................142

Rules for Implied Methods .................................................................................................................142Declaration ............................................................................................................................................142

Implementation.....................................................................................................................................143Implied Method Diagram....................................................................................................................145

OBVIATE METHODS..................................................................................................................................146Rules for Obviating a Class Method..................................................................................................146Single Method by Signature.................................................................................................................146Multiple Methods by Method Name .................................................................................................147Inheritance with a Single Obviate Method.......................................................................................147Using a Class with an Obviate Method.............................................................................................151No Side Effects for Never Obviating a Method..............................................................................152Reason to Obviate a Method ..............................................................................................................152

OPERATORS AND OPERATOR O VERLOADING ......................................................................................153

Operators ...............................................................................................................................................153 Assignment............................................................................................................................................154

Reference Assignment Operator is................................................................................................154Creation Operator as .......................................................................................................................155Regular Assignment Operator =....................................................................................................155Cast Assignment Operator := ........................................................................................................156Dual Assignment Operation Operators........................................................................................156Subtraction-Assignment Operator -=...........................................................................................157Multiplication-Assignment Operator *=......................................................................................158Division-Assignment Operator /= ...............................................................................................158Modulus-Assignment Operator %= .............................................................................................159

Bitwise-And Assignment Operator &=........................................................................................159Bitwise Inclusive-Or Assignment Operator |= ..........................................................................160Bitwise Exclusive-Or Assignment Operator ^= .........................................................................160Bitwise Shift-Right Assignment Operator >>=..........................................................................161Bitwise-Shift-Left Assignment Operator <<=............................................................................161

Cast Conversion....................................................................................................................................162Cast Operator to...............................................................................................................................162Casting Class and Type....................................................................................................................163Casting Type Rules...........................................................................................................................163

Page 10: The Mynx Book October 2007

8/14/2019 The Mynx Book October 2007

http://slidepdf.com/reader/full/the-mynx-book-october-2007 10/222

 Mynx Programming Language

- 10 -

Cast Type Span ............................................................................................................................163Cast Type Intent ..........................................................................................................................163Cast Type Limit............................................................................................................................163

Casting Conversion Examples .......................................................................................................164Logical Bitwise ......................................................................................................................................165

Logical Not Operator !....................................................................................................................165Logical Bitwise And Operator &...................................................................................................166Logical And Operator &&..............................................................................................................166Logical Bitwise Inclusive Or Operator |......................................................................................167Logical Inclusive Or Operator || .................................................................................................167Bitwise Complement Operator ~..................................................................................................168Bitwise Shift Left Operator << .....................................................................................................168Bitwise Shift Right Operator >>...................................................................................................168Logical Exclusive Or Operator ^...................................................................................................168

Relational ...............................................................................................................................................169Equality Operator == .....................................................................................................................169Inequality Operator != ....................................................................................................................170

Instance Type Of Operator in .......................................................................................................171Lesser Than Operator < .................................................................................................................171Greater Than Operator >...............................................................................................................172Greater Equal Operator >=...........................................................................................................172Lesser Equal Operator <=.............................................................................................................173

Stream.....................................................................................................................................................174Insertion Operator <<<.................................................................................................................174Extraction Operator >>>..............................................................................................................174

Mathematic ............................................................................................................................................175 Addition Operator + .......................................................................................................................175Subtraction Operator - ....................................................................................................................175

Division Operator /.........................................................................................................................176Modulus Operator %.......................................................................................................................176Multiplication Operator * ...............................................................................................................176Exponentiation Operator **...........................................................................................................177Increment Operator ++..................................................................................................................177Decrement Operator -- ...................................................................................................................177

 Access.....................................................................................................................................................178Method Invocation . ........................................................................................................................178

  Attribute Access `.............................................................................................................................179 Array Access [ ].................................................................................................................................179

Operator Precedence............................................................................................................................180

OPERATOR O VERLOADING .....................................................................................................................181Operator Overload Declaration .........................................................................................................181Kinds of Overloads..............................................................................................................................181Rules for Operator Overloading ........................................................................................................182

 Table of Operators...............................................................................................................................185Standard Method Names for Overloads...........................................................................................186Implicit Hierarchy of Operators.........................................................................................................187

 APPENDICES ..............................................................................................................................................189

Page 11: The Mynx Book October 2007

8/14/2019 The Mynx Book October 2007

http://slidepdf.com/reader/full/the-mynx-book-october-2007 11/222

 Mynx Programming Language

- 11 -

 APPENDIX - M YNX GRAMMAR ................................................................................................................191Header Syntax .......................................................................................................................................191Class Syntax...........................................................................................................................................191Class Methods.......................................................................................................................................191Class Attribute.......................................................................................................................................191Class Overload ......................................................................................................................................191Class Method Obviate..........................................................................................................................191Program..................................................................................................................................................192Statements..............................................................................................................................................192Expression Statements.........................................................................................................................193Lexical Elements...................................................................................................................................193Comments..............................................................................................................................................194

 APPENDIX - M YNX FILE T YPES AND TOOLS.........................................................................................195Mynx.......................................................................................................................................................195Myxm......................................................................................................................................................195Moxi........................................................................................................................................................195Myna.......................................................................................................................................................195

Minx........................................................................................................................................................196Myxd.......................................................................................................................................................196

 APPENDIX – GNU FREE DOCUMENTATION LICENSE .......................................................................197

EPILOG .........................................................................................................................................................205

R EFERENCES ..............................................................................................................................................207CREDITS ......................................................................................................................................................209

INDICES........................................................................................................................................................211

INDEX OF DIAGRAMS ...............................................................................................................................213INDEX OF EXAMPLES ................................................................................................................................215

INDEX OF T ABLES .....................................................................................................................................221

Page 12: The Mynx Book October 2007

8/14/2019 The Mynx Book October 2007

http://slidepdf.com/reader/full/the-mynx-book-october-2007 12/222

 Mynx Programming Language

- 12 -

Page 13: The Mynx Book October 2007

8/14/2019 The Mynx Book October 2007

http://slidepdf.com/reader/full/the-mynx-book-october-2007 13/222

 Mynx Programming Language

- 13 -

Prolog 

Page 14: The Mynx Book October 2007

8/14/2019 The Mynx Book October 2007

http://slidepdf.com/reader/full/the-mynx-book-october-2007 14/222

 Mynx Programming Language

- 14 -

Page 15: The Mynx Book October 2007

8/14/2019 The Mynx Book October 2007

http://slidepdf.com/reader/full/the-mynx-book-october-2007 15/222

 Mynx Programming Language

- 15 -

Prelude

 The myriad of programming languages available (and the plethora of programming languages that  will be created long in the future) underscores that for software there is no one universalprogramming 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 somany out there?” Fortunately, as Finnish composer Jean Sibelius once said, ”No statue has everbeen created for a critic.” If the world followed those views, all software would be in the nativemachine code for the platform, no need for a new programming language, and there would be only one out there.

For each programming language, there is often a story, reason, and an impetus for the language.Niklaus Wirth created Pascal out of frustration to the slow standardization of Algol68. BjarneStroustrup created C++ to have the C programming language but with objects. Larry Wall createdPerl out of a need for a scripting language above shell scripts that could handle text with ease. Ada95

 was an attempt by the United States Department of Defense to make a state of the art language fordefense 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’scontext. The “what” of a feature in a programming language can be less important than the “why”for a programming language.

Name and Project

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

Project: Proxima is the name of the overall project to implement a new programming language andthe 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 ProximaCentauri, at a distance of 4.3 light years away. Like the nearest star to our solar system, the goals arefar 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 thecompiler, 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 fromboth…)

MYNX = Manx + lYnx + NX 

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

Page 16: The Mynx Book October 2007

8/14/2019 The Mynx Book October 2007

http://slidepdf.com/reader/full/the-mynx-book-october-2007 16/222

 Mynx Programming Language

- 16 -

Philosophical Statement

Mynx is a programming language is not meant to be an end unto itself. Mynx follows the idea toimplement software by a user that allows for software within a domain to focus on the domain, andnot 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 slavishfollowing of a single principle to surmount a recurrent problem can create yet another problem.

 Target Platforms

Mynx is intended to be its own programming language, incorporating features from otherprogramming 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 aprogramming language for both platforms, with a feature set, and conceptual model that is notspecific to any platform.

  The two major platforms targeted for Mynx are initially the Java platform of the Java VirtualMachine (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, otherplatforms can be targeted, using C and C++.

Mynx generates high-level source in either Java or C# for the respective platforms. Java is intendedto be as wide an audience as possible, targeting JDK 1.1.x. Another reason for the Java backwardcompatibility is to avoid Mynx classes, libraries, and packages from becoming “wrappers” aroundeither 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 thecompilation mode, both Java and C# source can be generated, and then the code compiled toproduce byte code or IL code for either platform. The high-level source code uses classes inmodules written in both languages to “bootstrap” the core class library, and the high-level sourceimplements features of the Mynx programming language statements, expressions, classes, andprograms. Another reason to use source generation is to leverage the existing compilers for bothlanguages, although a major design goal is to integrate an open-source free compiler into the Mynxsoftware development kit (MDK).

Page 17: The Mynx Book October 2007

8/14/2019 The Mynx Book October 2007

http://slidepdf.com/reader/full/the-mynx-book-october-2007 17/222

 Mynx Programming Language

- 17 -

Manifesto

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

1. Distinguish attributes from methods within a class. Death to the Dead Parentheses:

myMethod() or stack.pop(). Dottic notation is used, a dot for method invocation, atic for attribute access.

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

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

4. No repetition of information in programming language statements. State it once in aclear form. Java or C#:

Integer x = new Integer(7);

Int x to 7;

5. Overcome Object as a quasi-generic type in Java, or a void* type in C++, leading toproliferation of casts. Proxima uses the self keyword, or a truly generic class. #14

6. No default fall-through behavior in switch statements like C++ or Java, or forcing code to use goto in C#. Default is exit the specific case of the case statement.

 Java:

int x = 0;

switch(x){

case 0:case 1: doZeroOrOne(); break;default: ;

}//end switch

Mynx:

Int x to 0;

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

null;end case;

Page 18: The Mynx Book October 2007

8/14/2019 The Mynx Book October 2007

http://slidepdf.com/reader/full/the-mynx-book-october-2007 18/222

 Mynx Programming Language

- 18 -

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

8. No nesting of classes or methods.

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

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

 And varying parameters with series.

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

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

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

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

15. Concept of levels of programming language compliance, so that the language can beused in different programming venues, such as embedded where a GUI library is notrequired, in a distributed environment, or an embedded environment.

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

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

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

19. No half-sided statements, what is implicit can be stated explicitly. Java hassynchronized, keyword sync, but not a unsynchronized. C# has var and ref 

parameters, but no default in parameter. Synch and asynch keywords for methods,and variable and constant keywords for attributes.

Page 19: The Mynx Book October 2007

8/14/2019 The Mynx Book October 2007

http://slidepdf.com/reader/full/the-mynx-book-october-2007 19/222

Page 20: The Mynx Book October 2007

8/14/2019 The Mynx Book October 2007

http://slidepdf.com/reader/full/the-mynx-book-october-2007 20/222

 Mynx Programming Language

- 20 -

Language Principles

 There are six major language principles upon which the Mynx programming language design isbased. The language design principles, not in order of importance or priority are:

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

2. Implicit minimalist. A programming language should allow implicit features of expression, without having to always express them. (In C++, a void type is required,even if the method returns nothing.)

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

4. Consistency of syntax. A programming language should be consistent in syntax, and nothave constant exceptions to rules for different programming language entities orconcepts. (C++ the for loop syntax is different from a simple while, and a do-while is

 very syntactically different.)

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

6. Expressivity or expressiveness. A programming language is to express functionality in agiven domain, so the syntax should do that, without being cryptic. The syntax shouldallow the user to focus on the problem, not the nuances of how to create it. Syntaxshould be designed for the user not the compiler, or to create efficient object code, etc.

Page 21: The Mynx Book October 2007

8/14/2019 The Mynx Book October 2007

http://slidepdf.com/reader/full/the-mynx-book-october-2007 21/222

 Mynx Programming Language

- 21 -

Design Rationale

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

1. Syntax2. Statement3. Units

Syntax

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

Other syntax forms of object-oriented programming languages include:

1. Smalltalk - convoluted syntax style, lacks expressivity.

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

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

Some syntactic styles such as COBOL and FORTRAN are too archaic to consider. Other syntaxfrom a programming language outside the object-oriented paradigm is a counter-productive choice

for an imperative object-oriented language. Inventing a new syntax might be more expressive andefficient, but too far different. A level of familiarity in syntax is needed to explore and use a new programming language.

Statements

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

Different programming languages have different degrees of statements. Mynx provides seventeen

statements, which seems a baroque approach to language design. However, Mynx is intended toprovide a solution of choices and selections, allowing the user to focus on the problem, not on theidiosyncrasies of the language.

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

Page 22: The Mynx Book October 2007

8/14/2019 The Mynx Book October 2007

http://slidepdf.com/reader/full/the-mynx-book-october-2007 22/222

 Mynx Programming Language

- 22 -

Units

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

1. program - unit of application

2. class - unit of library or reuse

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

Page 23: The Mynx Book October 2007

8/14/2019 The Mynx Book October 2007

http://slidepdf.com/reader/full/the-mynx-book-october-2007 23/222

 Mynx Programming Language

- 23 -

Goals

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

1. Pedagogy: A programming language to teach and learn concepts but still usable (i.e., not

a toy language compared to a “real” programming language used in softwaredevelopment.)

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

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

4. Practical: A programming language to specify user intention and purpose, to abstractly reason in the domain of choice, and to compile into an underlying implementationlanguage (Java or C#) to execute.

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

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

Page 24: The Mynx Book October 2007

8/14/2019 The Mynx Book October 2007

http://slidepdf.com/reader/full/the-mynx-book-october-2007 24/222

 Mynx Programming Language

- 24 -

License

Both the documentation (including this text) and the software — the examples, and the Mynxsoftware are released and distributed but under specific legally binding conditions — the ubiquitouslicense.

License Objectives

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

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

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

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

Documentation

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

Software

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

1. example software and code in the book 2. implemented compiler and language tools3. libraries that are part of the core package

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

Page 25: The Mynx Book October 2007

8/14/2019 The Mynx Book October 2007

http://slidepdf.com/reader/full/the-mynx-book-october-2007 25/222

Page 26: The Mynx Book October 2007

8/14/2019 The Mynx Book October 2007

http://slidepdf.com/reader/full/the-mynx-book-october-2007 26/222

 Mynx Programming Language

- 26 -

Page 27: The Mynx Book October 2007

8/14/2019 The Mynx Book October 2007

http://slidepdf.com/reader/full/the-mynx-book-october-2007 27/222

 Mynx Programming Language

- 27 -

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

Identifiers

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

X – legal, at least one letter character  _1x – illegal, begins with underscorehelloWorld – legal123myVar – illegal, begins with digit  _variable – illegal, begins with underscore  myVeryLongVariableName – legal

Example of Identifiers

Keywords

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

abstract access all as assert asynccase class constant construct covariant defaultdestruct do elif else end enum  exit flag for generic goto hasif implied in is let loop  method module mutex new next nullout overload own private program protectpublic reader repeat return self seriessingular static super sync this totry type until var variable virtualvoid volatile when while with writer

Table of Mynx Keywords

 The keywords goto and new are not used, but are considered keywords to prevent usage. The use of the keywords goto and new as the name of a variable, constant, class, or program can be confusing 

and misleading. The keywords enum and type are reserved the same reason to avoid confusion intype or enumeration definition. Since four keywords are not used in Mynx, there are effectively 61-keywords.

Page 28: The Mynx Book October 2007

8/14/2019 The Mynx Book October 2007

http://slidepdf.com/reader/full/the-mynx-book-october-2007 28/222

 Mynx Programming Language

- 28 -

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. Literalsare 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 acharacter literal ‘@’ or ‘?’ or within a string literal. The at-sign ‘@’ is reserved for possible future usein Mynx possibly as meta-code for classes.

Symbols

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

Character Description

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

Table of Escaped Characters

 The escaped character literals are substituted with the corresponding character symbol in the given

encoding scheme (such as UTF-8, US-ASCII, or Unicode.) The Unicode escape character indicates afollowing Unicode character literal, using four uppercase hexadecimal digits.

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

Example of Unicode Literals

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

Example of Symbol Literals

Page 29: The Mynx Book October 2007

8/14/2019 The Mynx Book October 2007

http://slidepdf.com/reader/full/the-mynx-book-october-2007 29/222

 Mynx Programming Language

- 29 -

Numbers

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

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

123 – legal integer-123 – legal integer+73 – legal integerFFE3 – illegal hexadecimal integer without prefix 0X3.145 – legal real0xFF – illegal hexadecimal prefix 0X is invalid0XFF – legal hexadecimal integer2.713F – legal float

.333337 – illegal real, must begin with a digitOxCAFE – illegal hexadecimal integer needs ‘0X’ prefix0.5 - legal real

Example of Numeric Literals

Page 30: The Mynx Book October 2007

8/14/2019 The Mynx Book October 2007

http://slidepdf.com/reader/full/the-mynx-book-october-2007 30/222

 Mynx Programming Language

- 30 -

Meta Strings

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

 A meta string is a string identifier in uppercase, beginning with the hash or pound sign # character. A meta string is substituted with the information it represents. A meta-string allows for informationabout the source code, but without the manual effort to represent it, or the overhead of changing it

 when the source code is revised. There are twenty standard meta strings in Mynx.

Meta String Description Example#AUTHOR Author of the source “Jon Q. Doe”#BUILD Build version for file “Build 1.1”#CLASS Name of the class “myClass”#COMPILER Compiler information “Mynx Compiler 2.033”#DATE Date of the Build “2004-04-03”#DAY Day of Month as Integer 1...31 “17”

#FILE File Name “myClass.mynx”#LINE Line Number “237”#METHOD Name of the Method “myData”#MODULE Name of the Module “mynx.core”#MONTH Month of the Year as Text “August”#ORG Organization Name (Company, University, etc.) “University Old York”#PLATFORM Name of the Platform (Machine/Operating System) “AMD64X86:Linux”#PROGRAM Name of the Program “myProgram”#SYSTEM Name of the System (Internet or Network Name) “cupcake.oldyork.edu”#TIME Time of Compilation “14:31:00”#VENDOR Vendor of the Compiler “MynxSoft LLC”#VERSION Compiler Version “Version 1.0.1”#YEAR Year of Build as an Integer “2003”#WEEKDAY Day of the Week of Build as Text “Friday”

Table of Standard Meta Strings in Mynx

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

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

Page 31: The Mynx Book October 2007

8/14/2019 The Mynx Book October 2007

http://slidepdf.com/reader/full/the-mynx-book-october-2007 31/222

 Mynx Programming Language

- 31 -

class metaStrExample as null is

public construct is to null;

public singular void aMethod is

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

end aMethod;

public destruct is to null;

end class;

Example of using Meta Strings

 The output for calling aMethod with the class metaStrExample is:

Module is defaultMethod name is aMethod

Class is metaStrExampleThis meta string is UNDEFINED

Table of Output with using a Meta String

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

Operators

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

1. Assignment

2. Cast Conversion3. Logical and Bitwise4. Relational5. Stream6. Mathematic

Page 32: The Mynx Book October 2007

8/14/2019 The Mynx Book October 2007

http://slidepdf.com/reader/full/the-mynx-book-october-2007 32/222

 Mynx Programming Language

- 32 -

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

Encoding 

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

Comments

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

Single Comments

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

 Java, for familiarity.

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

Example of Mynx Single-Line Comments

Multiple Comments

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

 The multiple line comment can encompass other comments, a comment within a comment.

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

Table of Mynx Multiple Line Comments

Page 33: The Mynx Book October 2007

8/14/2019 The Mynx Book October 2007

http://slidepdf.com/reader/full/the-mynx-book-october-2007 33/222

 Mynx Programming Language

- 33 -

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

Enumerated Types

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

 The reason is to avoid defining in the programming language that which can be defined using a classand other features of the Mynx programming language, such as static inclusion of a class, andoperator 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.

Page 34: The Mynx Book October 2007

8/14/2019 The Mynx Book October 2007

http://slidepdf.com/reader/full/the-mynx-book-october-2007 34/222

 Mynx Programming Language

- 34 -

Page 35: The Mynx Book October 2007

8/14/2019 The Mynx Book October 2007

http://slidepdf.com/reader/full/the-mynx-book-october-2007 35/222

 Mynx Programming Language

- 35 -

Statements

Page 36: The Mynx Book October 2007

8/14/2019 The Mynx Book October 2007

http://slidepdf.com/reader/full/the-mynx-book-october-2007 36/222

 Mynx Programming Language

- 36 -

Page 37: The Mynx Book October 2007

8/14/2019 The Mynx Book October 2007

http://slidepdf.com/reader/full/the-mynx-book-october-2007 37/222

 Mynx Programming Language

- 37 -

Concept of Statements

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

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

 The seventeen statements are organized into five categories of statement:

1. flow of control or jump2. repetition or iteration3. selection or decision4. error computation5. mutual exclusion

Statement Category Type

  Assert Error SingularCase Selection MultipleExit Flow of Control Singular

Expression Computation SingularFlag Error SingularFor Repetition MultipleIf Selection Multiple

Loop Repetition MultipleMutex Mutual Exclusion MultipleNext Flow of Control SingularNull Computation Singular

Prefix if Flow of Control SingularRepeat Flow of Control MultipleReturn Flow of Control Singular

Try Error MultipleUntil Repetition MultipleWhile Repetition Multiple

Table of Statement Category and Types

Page 38: The Mynx Book October 2007

8/14/2019 The Mynx Book October 2007

http://slidepdf.com/reader/full/the-mynx-book-october-2007 38/222

 Mynx Programming Language

- 38 -

Computation

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

explicit statement of no operation.Expression Statement

 An expression statement is a computation statement that computes a value or an object representing a value. There are two primary kinds of expression statements:

1. declaration – declare and create an instance of an class as an object2. expression – computation statement to compute a value or change state

Declaration

  A declaration statement is a declaration within a method, and has a similar syntax to a class orprogram attribute. A declaration statement is preceded by the keyword var to distinguish thedeclaration 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 andcreates an instance of a class as an object, invoking the class constructor.

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

Example of Variable Declaration Expression

Expression

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

1. postfix

2. assignment3. creation4. input-output5. access

Page 39: The Mynx Book October 2007

8/14/2019 The Mynx Book October 2007

http://slidepdf.com/reader/full/the-mynx-book-october-2007 39/222

 Mynx Programming Language

- 39 -

Postfix

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

decrement method.

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

Example of Postfix Expression

 Assignment

 The assignment sub-expression statements assign or associate a value of an expression to a instanceobject by the identifier. An assignment statement can be of one of three forms:

1. Assign – associate an object value to an object instance by the identifier2. Create – create a new class instance as an object, and assign it to an identifier3. Input-output – assign but to an input or output stream variable

 Assign

  Assignment statements use a left value, right value, and are separated by an assignment operator.  The left value must be an identifier, array access, or attribute access. The right value can be an

expression, literal, method call, attribute access, or array access.

x = 3;y += x+7 / 2;z = this.computeValue(x,y);data[3] = 17;x`y := i+j*3;total = x**y + 1;q is y;this`y = 0;self`ct = super.getCount;

Example of Assign Expression

Create

 A create or creation statement is an assignment expression that creates a new instance of a class andassigns it to an object reference or variable. The keyword as follows the object reference variableand the class name with any constructor parameters.

Page 40: The Mynx Book October 2007

8/14/2019 The Mynx Book October 2007

http://slidepdf.com/reader/full/the-mynx-book-october-2007 40/222

 Mynx Programming Language

- 40 -

var Int x to null; //declare an initial values to nullvar Int y to null;var String z to null;

x as Int; //default construct

y as Int(-1234); //create -1234 Intz as String(“hello world!!!”);//create Stringx as Byte; //create sub-type of parent type instance

x as null; //compiler error! Null is not valid class to createy as default;//compiler error! Default constructor by class namez as Int; //compiler error! Incompatible class type Int to String

Example of Creation Expression

Input-Output

 An input-output sub-expression is exactly similar to an assignment statement, however, instead of assigning an object value to an object instance by identifier, the assignment is an object instance toinput or output stream. The operators for an input-output are the stream operators.

IO <<< x <<< eoln;IO >>> inputLine >>> eoln;

Example of Input-Output Expression

 Access

 An access sub-expression statement will access a value as if it were computed in an evaluation of anexpression. There are three kinds of access sub-expressions:

1. attribute – access the attribute of a class2. method – access the method of a class3. array – access the element of an array 4. multiple – access multiple times nested

 Attribute

 An access sub-expression for an attribute is accessing an attribute of the class instance or super-

class. An attribute accessed, can be read or written, depending on if the attribute is a constant or variable.

this`total = 0; //write access of class attributey = super`rawData; //read access of class attribute

Example of Attribute Access Sub-Expression

Page 41: The Mynx Book October 2007

8/14/2019 The Mynx Book October 2007

http://slidepdf.com/reader/full/the-mynx-book-october-2007 41/222

 Mynx Programming Language

- 41 -

Method

 The access statement for a method is a method invocation is the calling of a method in the currentclass, super class, or on an instance of a class.

this.callMethod(0,”hello”);super.invokeMethod(‘a’);x.doIt;

Example of Method Access Sub-Expression

 An object instance variable or constant by itself is potentially a method access if the default methodof the class the object is an instance of is defined and invoked.

this.x; //default invocationsuper.y; //default invocation

data; //default invocation

Example of Method Access by Default Sub-Expression

 Array 

 An access sub-expression for an array is accessing an array element of the method or class. An array access can be read or written. The sub-script of index into the array can be a literal constant,

 variable, or an expression.

y = data[x];data[base+count*sizeof(data)] = 0;x[0] = y;

Example of Array Access Sub-Expression

Multiple

 The access statement can be made up of multiple accesses, such as accessing a method, then anattribute, an array, and so forth. Note that a super or this reference only appears as the first elementof an access statement.

this.callMethod(0,”hello”).doSomething`rawData[x];super.doIt[x]`data;

Example of Multiple Access Expression Statement

Page 42: The Mynx Book October 2007

8/14/2019 The Mynx Book October 2007

http://slidepdf.com/reader/full/the-mynx-book-october-2007 42/222

 Mynx Programming Language

- 42 -

Null Statement

  The null statement is an empty statement, which does nothing. Instead of a blank or singlesemicolon on a line, Mynx null statement is explicit.

public doNothing isnull;

end doNothing;

Example of Null Statement

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

Error

  The error statements include explicit error assertion checking with an assert statement, and error

flagging with a trap, and handling a flagged trap with a try statement.

Error statements are for debugging software and to manage software errors as they occur insoftware. Methods can require that a trap error must be handled with a try statement. The methodthen 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 excludedfrom the compiled source.

 As the assert statement is for debugging purposes, it is a very simple statement. An expression isasserted, 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 notintended for sophisticated error handling or logic, only to assist in debugging source code.

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

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

Example of Assert Statements

Page 43: The Mynx Book October 2007

8/14/2019 The Mynx Book October 2007

http://slidepdf.com/reader/full/the-mynx-book-october-2007 43/222

 Mynx Programming Language

- 43 -

Flag Statement

 The flag statement is used to raise, or flag an exception or trap. The flag statement takes a class thatis the trap to be flagged. Essentially the flag statement creates a new instance of the trap class, andthen returns from the method to the caller.

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

Example of Flag Statement

 Try Statement

 A try statement is the counter part to a flag statement, a flag statement creates and propagates a trap,the try statement tries to handle the trap.

 A try statement encloses statements within a try-clause, and then has a series of when-clauses for thetraps it handles, and then has an else-clause optionally, and an optional do-clause.

 A try statement restricts placing a flow of control statement (exit, next, return) in the do-clause of atry 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.

tryfile = File(“test.data”);

 when(FileNotFoundTrap)

IO.putln(“File was not found.”);dofile.close;

end try;

Example of Try Statement

tryfile = File(“test.data”);

 when(FileNotFoundTrap fnf)IO.putln(“File was not found. Error: ”+fnf.getMessage);

elseIO.putln(“File was opened successfully.”);

dofile.close;

end try;

Example of Try Statement with Else Clause

Page 44: The Mynx Book October 2007

8/14/2019 The Mynx Book October 2007

http://slidepdf.com/reader/full/the-mynx-book-october-2007 44/222

 Mynx Programming Language

- 44 -

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

tryreturn 0;

doreturn 1; //compiler error: invalid flow of control

end try; //from try do-clause

Example of Invalid Try Statement with Flow of Control using Return

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

loop

trynext loop(0);

donext loop(0); //compiler error: invalid flow of control

end try; //from try do-clause

end loop(0);

Example of Invalid Try Statement with Flow of Control using Next

Flow of Control

Nesting and need for non-sequential exit and next stepping through the iteration statements. Not  valid for try, if, or case. Statements, in particular the repetition category of statements, are nestedoften. 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 nextstatement 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 theform of a parenthesized integer following the end clause before the semicolon. The nesting levelstarts at zero and progressively counts upward by an increment of one, so the range is 0..n-1 for nnested 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.

Page 45: The Mynx Book October 2007

8/14/2019 The Mynx Book October 2007

http://slidepdf.com/reader/full/the-mynx-book-october-2007 45/222

 Mynx Programming Language

- 45 -

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

e nd i f;

end for(1);

end for(0);

Example of Exit Statement

var InputFile file to (“input.data”);var Bool status to (Bool.False);

file.open;

 while(! file.endOfFile)

//read 100 recordsfor(Int i is 0 to 100)

this.processRecord(file,i,status);if(!status)

exit while(0);end if;

end for(1);

end while(0);

file.close;

Example of Exit Statement

Page 46: The Mynx Book October 2007

8/14/2019 The Mynx Book October 2007

http://slidepdf.com/reader/full/the-mynx-book-october-2007 46/222

 Mynx Programming Language

- 46 -

Next Statement

 The next statement is like an exit statement, except that instead of exiting a repetition statement, itcontinues to the next cycle of the repetition statement. A next statement can skip to continue to anouter repetition statement in which the next statement is nested.

public void findInMatrix(in Matrix matrix) is

var Int col to matrix.getCol;var Int row to matrix.getRow;var Int val to –1;

for(Int x is 0 to row)

for(Int y is 0 to col)

val = matrix.get(x,y);if(val == 0)

next for(1);//skip to next yend if;

end for(1);

end for(0);

end findInMatrix;

Example of Next Statement

Prefix If Statement

 A prefix-if statement is a specialized form of if-statement, which combines an exit or next statementinto a single statement form. A prefix-if statement is used mostly within a loop statement, to definethe exit or next condition for a loop.

exit(0) if ( i > = j ) ;next(2) if ( foundFlag );

public Ordinal findFirst(in Int[*] list, in Int val) is

var Ordinal where to 0;for(index is 0 to list.size)

  where = index;exit for(0) if(list[index] == val);

end for(0);

return where;

end findMax;

Example of Prefix If Statement

Page 47: The Mynx Book October 2007

8/14/2019 The Mynx Book October 2007

http://slidepdf.com/reader/full/the-mynx-book-october-2007 47/222

 Mynx Programming Language

- 47 -

Return Statement

 A return statement returns or exits a class or program method, and can return a value. The valuereturned 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-sequentialexit that can return a value from a method.

public Int findFirst(in Int[*] list, in Int value) is

for(Int x is 0 to list.length)if(list[x] == value)

return value;end if;

end for;

return null;

end find;

public Ordinal factorial(in Unsigned uint) is

if(uint == 0)return 1;

elsereturn (uint * factorial(uint-1));

end if;

end factorial;

public void processFileByName(in String filename) is

var File file to (filename);if(! file.exists)

return;end if;

this.processFile(file);

end processFile;

Example of Return Statement

Page 48: The Mynx Book October 2007

8/14/2019 The Mynx Book October 2007

http://slidepdf.com/reader/full/the-mynx-book-october-2007 48/222

 Mynx Programming Language

- 48 -

Repetition

 The repetition statements repeat or iterate over a block of statements. A for statement iterates over afixed range or count of elements. A loop statement is a infinite loop, no specific explicit conditionsexist to terminate the loop. The until-loop and while-loop have explicit conditions to exit a loop,

 which are logically the inverse of each other.

For Statement

 A for statement is a fixed iteration statement, it repeats over a discrete range. There are two types of for loop statements:

1. Iterate over a fixed integer range from lower to upper bound.2. Iterate over an array of fixed dimensions and length.

 A for statement declares a for-loop variable, which is unique to a for-loop, and conflict with any 

other variable declarations within a method. A local for loop variable is declared in the for-loopclause, and is valid within the scope of the for loop block. Outside of the for-loop block, the for-loop variable is non-existent and non-existent. Within the scope of the for-loop block, the for-loop

 variable is a read-only constant with a value for that cycle of the for-loop.

For Statement over a Range

 A fixed for statement over an integral range counts up or down from an initial value up to an upperlimit. The lower bound and upper bound are an actual for loop variables; the for-loop variable willequal the boundary values.

//x implicitly Ordinal, count from 0 to 20for(x is 0 to 20)

IO.putln(x);end for;

Example of For Statement over Fixed Range

//x implicitly Ordinal, count from 100 to 0for(y is 100 to 0)

IO <<< y <<< eoln;y++; //error! y is constant value

end for;

Example of For Statement over Range

Page 49: The Mynx Book October 2007

8/14/2019 The Mynx Book October 2007

http://slidepdf.com/reader/full/the-mynx-book-october-2007 49/222

Page 50: The Mynx Book October 2007

8/14/2019 The Mynx Book October 2007

http://slidepdf.com/reader/full/the-mynx-book-october-2007 50/222

 Mynx Programming Language

- 50 -

Loop Statement

 A loop statement is an infinite loop, with no explicit bounds on the termination of the loop. Theloop statement is used instead of a “hardwired” while or until loop. An infinite loop must have anexplicit statement to exit or continue to the next cycle of iteration within the loop.

//infinite loop without explicit endloop

null;end loop;

Example of Loop Statement

var Bool statusFlag to False;

loopdoFileOperation(statusFlag);exit if(statusFlag); //prefix-if explicit exit

end loop;

Example of Loop Statement with Prefix If Statement

var Char c to null;

loop

IO.read(c);case(c)

as ‘x’,’X’,’e’,’E’ is exit loop; //exit on character x or e

as ‘n’,’N’ is next loop; //exit on character nelse

next; //implicitly next loopend case;

end loop;

Example of Loop Statement with Exit in Case Statement

Page 51: The Mynx Book October 2007

8/14/2019 The Mynx Book October 2007

http://slidepdf.com/reader/full/the-mynx-book-october-2007 51/222

 Mynx Programming Language

- 51 -

Until Statement

 An until-loop repetition statement continues iteration until the loop condition is true, or continues while the condition remains false.

var Int x to 3;

until(x == 0)x--;

end until;

Example of Until Statement

 While Statement

 A while-loop repetition statement continues iteration while the loop condition remains true, or stops

 when the condition is false. For example:

var Int x to 3;

 while(x != 0)x--;

end while;

Example of While Statement

Page 52: The Mynx Book October 2007

8/14/2019 The Mynx Book October 2007

http://slidepdf.com/reader/full/the-mynx-book-october-2007 52/222

 Mynx Programming Language

- 52 -

Repeat Statement

 A repeat statement is a loop that executes the body of statements at least once, and then continuesuntil the terminating condition is true. There are two types of repeat loops:

1. repeat-while - repeat loop with a while logical condition for continuation.2. repeat-until - repeat loop with an until logical condition for continuation.

 The while and until conditions are logical inverses – a while continues while the expression is true,but terminates on false, and an until continues until the expression is true or while it is false.

var File dataFile to “myfile.dat”;

dataFile.open;

repeatdataFile.readRecord;

 while(!dataFile.endOfFile );

Example of Repeat Statement with While Condition

var File dataFile to “myfile.dat”;

dataFile.open;

repeatdataFile.readRecord;

until( File.endOfFile );

Example of Repeat Statement with Until Condition

Each of the repeat loop statements is logically equivalent. Depending upon the logical expression, arepeat-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 themixing of logic and statements in a cleaner repetition statement.

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

Page 53: The Mynx Book October 2007

8/14/2019 The Mynx Book October 2007

http://slidepdf.com/reader/full/the-mynx-book-october-2007 53/222

 Mynx Programming Language

- 53 -

var Record rec to null;var File dataFile to “myfile.dat”;dataFile.open;

repeat

rec = dataFile.readRecord;exit if(rec == null) repeat(0); while(!dataFile.endOfFile )(0);

dataFile.close

Example of Repeat Statement with Prefix-If and Nesting

Pre-conditional and Post-conditional Loops

 A repeat statement is similar to a loop statement in that both will execute the body of statements atleast once. A while and until statement can optionally never execute the body of statements, and the

for statement (again depending on the logic of the expression) can possibly never execute the body statements.

Repetition Statement Kind of Loop Lower Bound Upper BoundFor Pre-conditional 0 c <

Loop Post-conditional 1 n

Repeat Post-conditional 1 n

Until Pre-conditional 0 n

While Pre-conditional 0 n

Table of Pre- and Post- Conditional Statements and Bounds

 A for statement always has some constant upper bound, which is always less than infinity—hence afor loop statement will always terminate. Other loops are always less or equal to infinity—hence apossible infinite loop for the upper bound.

Post-conditional loop or repetition statements are useful when the body of statements needs to beexecuted at least once, and then a logical expression to continue the loop is evaluated. Conversely, apre-conditional loop is utilized if the body of statements need never execute; the logical condition isevaluated and then the body of the loop is executed if the evaluation is logically true. A false logicalcondition and the loop, and the body of statements is not executed similar to an if statement.

Page 54: The Mynx Book October 2007

8/14/2019 The Mynx Book October 2007

http://slidepdf.com/reader/full/the-mynx-book-october-2007 54/222

 Mynx Programming Language

- 54 -

Selection

Selection statements select a block of statements to execute based upon a value or condition. A casestatement uses a discrete value to select a statement block to execute, the if statement uses a logicalBoolean 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. Acase 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 casestatement ends with the case footer, which follows the syntactic form of an if statement with an end

keyword with a case keyword with the terminating semicolon.

var Int x to 0; //integer is discrete type

case(x)as 0 is

doSomething0;as 1 is

doSomething1;else //negative integer, positive integer > 1

callError;end case;

Example of Case Statement

var Char c to ‘x’;

case(c)as ‘a’,’e’,’i’,’o’,’u’ is

this.handelVowel(c);as ‘,’,’’’,’”’,’;’,’:’ is

this.handleControlChar(c);else

this.handleOtherChar(c);end case;

Example of Delimited List of Values with a Case Statement

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

Page 55: The Mynx Book October 2007

8/14/2019 The Mynx Book October 2007

http://slidepdf.com/reader/full/the-mynx-book-october-2007 55/222

 Mynx Programming Language

- 55 -

 A case statement can case on a String literal:

var String cmd to null;

loopcmd = in.readLine;

case(cmd)as “exit”, “quit” is exit;as “version” is reportVersion;else execute(cmd);

end case;

end loop;

Example of Case Statement with String Literal

If Statement

 An if statement is a logical condition selection statement; based upon the condition in the if-clause,either the then-block is evaluated, or the else-block. An else-block for an if-statement is an optionalpart, 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

elsenull; //else-block

end if;

Example of Equivalent If Statements

Page 56: The Mynx Book October 2007

8/14/2019 The Mynx Book October 2007

http://slidepdf.com/reader/full/the-mynx-book-october-2007 56/222

 Mynx Programming Language

- 56 -

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 == yx is y;

end if;

end if;

Example of Equivalent If Statement with Else-If Elif Block

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

if(x > y) //no else requiredx.computeWith(y);

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

end if;

Example of If Statement without Else Block

public default Int factorial(in Int ival) in for factorial is

if(ival < 0)flag IntegerValueTrap;

elif(ival == 0)return 1;

elsereturn( ival * this.factorial(ival-1) );

end if;

end factorial;

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

Page 57: The Mynx Book October 2007

8/14/2019 The Mynx Book October 2007

http://slidepdf.com/reader/full/the-mynx-book-october-2007 57/222

 Mynx Programming Language

- 57 -

Mutex Statement

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

 A mutex statement consists of a mutex header, the block of statements forming a critical section,and the mutex footer. The mutex header begins with the keyword mutex, and the mutex variable orexpression in parenthesis. The mutex footer is simply the keyword end followed by mutex and asemicolon.

Mutex Statement Syntax

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

  mutex ( EXPRESSION  )STATEMENTS

end mutex ;

Example of Mutex Statement Syntax

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

Mutex Expression

 The mutex expression is an expression for an object lock, or a monitor for the object. A monitor is a

fundamental mutual exclusion concept, but for each object there is one lock. Hence a synchronizedmethod uses the instance object lock implicitly; but for a block of statements in a mutex statementrequires an explicit lock – in the form of a mutex expression.

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

 mutex(this)null;

end mutex;

Example Mutex Expression with This Class Reference

Page 58: The Mynx Book October 2007

8/14/2019 The Mynx Book October 2007

http://slidepdf.com/reader/full/the-mynx-book-october-2007 58/222

 Mynx Programming Language

- 58 -

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

Object myMutex to default;

 mutex(myMutex)null;

end mutex;

Example of Mutex Expression using Local Variable

Page 59: The Mynx Book October 2007

8/14/2019 The Mynx Book October 2007

http://slidepdf.com/reader/full/the-mynx-book-october-2007 59/222

 Mynx Programming Language

- 59 -

Namespaces

 The namespace concept is organizing classes and programs into a hierarchy based upon a modulename to give unique names to a class or program. A namespace helps to modularize classes andprograms 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 isimplicitly given (unless of course the default namespace is explicitly used...).

Declaration

  A namespace, if explicitly declared is the first statement in a Mynx source file. A namespace isdeclared 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 whichis delimited or separated by a dot ‘.’ or period. The declared name of the namespace can not containMynx reserved words or keywords, except in one specific case. For a unique namespace, an internetname in the form of “domain extension, domain name...” followed by specific namespace name to

identify the classes organized within the namespace.

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

Example of Namespace Declaration

  module module.program; – can not use keywords in name module *; – operators are not valid in name

 module 0.1.2.3; – namespace invalid using numbers module ; – invalid, no name given for namespace

Example of Invalid Namespace Declaration

Default Namespace

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

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

Example of Default Namespace Declarations

Page 60: The Mynx Book October 2007

8/14/2019 The Mynx Book October 2007

http://slidepdf.com/reader/full/the-mynx-book-october-2007 60/222

 Mynx Programming Language

- 60 -

Classes and Programs within a Namespace

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

namespace provides the full class or program name.

Inclusion of Classes from a Namespace

In order to use a class or classes within a namespace, the class must be included in the class orprogram. Inclusion of a namespace allows classes to be used within the program or class. Mynx doesnot automatically include any namespaces, including a namespace declared for a class or program.

 All namespaces for inclusion in a class or program must be explicitly given.

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

1. absolute – a class is specifically identified by namespace and name.2. relative – inclusion of a namespace, which includes all classed within the namespace.

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

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

Example of Absolute Namespace Inclusion

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

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

Example of Relative Namespace Inclusion

Page 61: The Mynx Book October 2007

8/14/2019 The Mynx Book October 2007

http://slidepdf.com/reader/full/the-mynx-book-october-2007 61/222

 Mynx Programming Language

- 61 -

Nested Namespace Inclusion

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

 The namespaces are declared:

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

Example of Hierarchical Sub-Namespaces

Using the declared namespaces:

 with example.*;

Example of Namespace Inclusion from Hierarchical Namespace

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

Using the nested namespace:

 with example.*;

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

Example of Sub-Namespace Inclusion from Hierarchical Namespace

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

 with example.*.*.*;

Example of Invalid Namespace Inclusion

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

Page 62: The Mynx Book October 2007

8/14/2019 The Mynx Book October 2007

http://slidepdf.com/reader/full/the-mynx-book-october-2007 62/222

 Mynx Programming Language

- 62 -

Declaration Order for Namespace Inclusion

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

an absolute namespace.

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

Mynx Namespace

 The Mynx programming language uses five existing module namespaces to organize programming language classes. All of the namespaces begin with the name mynx, followed by the namespace

name. In general, only language standard classes and namespaces should use the Mynx namespace,or risk incompatibilities or inconsistencies.

Module Namespace Description of Classes Included  mynx.core Programming Language Core Classes, Types

  mynx.io Input and Output Stream Classes  mynx.introspect Introspective Runtime Type Information Classes

  mynx.trove Collections, Data Structures, Algorithms  mynx.gui Graphic User Interface Classes

Table of Mynx Namespaces

Nonexistent Namespace Inclusion

 A with statement directs Mynx to use a namespace when determining which class to reference for adeclaration and use within a class or program. If a with statement directs Mynx to use an absolutenamespace that does not exist, it will create a semantic compiler error.

 with nothing.doesnotexist.noClass; // semantic error! inclusion of a// non-existent absolute namespace

virtual class Nothing as null is//...

end class;

Example of Non-Existent Namespace Inclusion

Page 63: The Mynx Book October 2007

8/14/2019 The Mynx Book October 2007

http://slidepdf.com/reader/full/the-mynx-book-october-2007 63/222

 Mynx Programming Language

- 63 -

Static Inclusion from Default Namespace

Declaring a class within default namespace.

  module default;

static class S3 is

public singular nop is to null;

end class;

Example of Declaring a Class with Default Namespace

Using static include class in default namespace.

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

program  useS3 is

nop; //implicitly invoke static method on S3

end program ;

Example of Using Static Include Class in Default Namespace

Page 64: The Mynx Book October 2007

8/14/2019 The Mynx Book October 2007

http://slidepdf.com/reader/full/the-mynx-book-october-2007 64/222

 Mynx Programming Language

- 64 -

 Arrays

 An array is an indexed, homogeneous, aggregate collection of a class type. An array in Mynx is afirst-class object (the array itself can be used as an object), and an array can be multi-dimensional.Mynx does not have the concept of “arrays of arrays” only a multi-dimensional array as an object

that can be indexed to access an element.

Kinds of Arrays

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

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

1. Infinite - the array dimension boundaries are unknown.2. Bounded - the array dimension boundaries are specified.

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

Ordinal[*] ord to null; //infinite 1-dimensional arrayBit[*,*] bits to null; //infinite 2-dimensional array

Example of Infinite Array Declaration

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

Ordinal[20] ord to null; //bounded 1-dimensional arrayBit[4,4] bits to null; //bounded 2-dimensional array

Example of Bounded Array Declaration

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

 Array Attributes

 A basic array has three primary attributes:

1. rank – the number of dimensions2. size – the product of all dimension length3. dim(n) – the nth dimension length or dim(n) or length(n)

Page 65: The Mynx Book October 2007

8/14/2019 The Mynx Book October 2007

http://slidepdf.com/reader/full/the-mynx-book-october-2007 65/222

 Mynx Programming Language

- 65 -

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

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

 Array Declaration

 An array declaration is of two types:

1. definite – array bounds are specified in declaration2. indefinite – array bounds are not specified in declaration

 An array declaration can declare the number of dimensions (the rank), without giving any array dimensions using an asterisk instead of the array dimension. An array declaration without specificdimensions is an indefinite array declaration. An array without specific dimensions and just bracketsis implicitly a one-dimensional array.

Declaring an array uses the class type, followed by the dimensions of the array in brackets. All array dimensions begin at an index of 0, and continue to the dimension – 1. Such an array declaration is adefinite array declaration.

String[2] names; //dimensions 0..1Point[4] coordinates; //dimensions 0..3Integer[4,4] matrix; //dimensions 0..3, 0..3

Example of Definite Array Declaration

String[*] name; //1-dimension arrayInteger[*,*] matrix2D; //2-dimension arrayFile[*] fileList; //1-dimension arrayChar[] chars; //1-dimension array implicitly

Example of Indefinite Array Declaration

  An array is declared with the rank always explicitly given in definite or indefinite form, with animplicit 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.

Page 66: The Mynx Book October 2007

8/14/2019 The Mynx Book October 2007

http://slidepdf.com/reader/full/the-mynx-book-october-2007 66/222

 Mynx Programming Language

- 66 -

 Array Creation

 An array declares a class type, and a fixed number of dimensions or rank. Declaring an array doesnot allocate space for an array. Creating an array can be part of the declaration, following an askeyword with an initial value list. Creating an array does allocate space for the instances of the type

of that array.

 An initial list is an explicit list of values with an implicit index starting at zero and continuing untilthe length of the array offset by one.

 Array Initialization

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

 There are two primary forms of initialization of an array:

1. List - a list of data element values is used to initialize the array.2. Non-list - initialization is by a means other than a list of values.

Initialization with a List

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

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

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

Initialization with an Implicit Indexed List

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

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

Example of Creating an Array with Implicit and Explicit Position Index

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

Page 67: The Mynx Book October 2007

8/14/2019 The Mynx Book October 2007

http://slidepdf.com/reader/full/the-mynx-book-october-2007 67/222

 Mynx Programming Language

- 67 -

Initialization with an Explicit Indexed List

  An array can be declared with explicit list of indices to initialize each location of the array to aspecific instance value type. An explicit indexed array is a list with an index associated with eachelement in the list to indicate the array element.

var Char[*] chr to { *:’ ‘ , 10:’ ‘ }; //upper bounds 10 specifiedvar String[*,*] str to { *,*:” “, 10,8:” “ }; //upper bounds 10,8 specifiedvar Int[*,*,*] int to { *,*,*:0 , 3,3,3:0 }; //upper bound 3,3,3 specifiedvar Real[*,*] rl to { *,*:0.0 } //compiler error no upper boundsvar Bool[3] bl to { 0:True, 1:False, 2:True}; //explicit index

Example of Creating an Array with Explicit Position Index

 An array can be initialized with a list of initial values using an explicit integer list index with a colon‘:’ separator. One special index uses an asterisk ‘*’ as an index for all other array indices – the defaultfor an array index.

var Char[5] vowels to { 4:’u’, 0:’a’, 3:’o’, 2:’i’, 1:’e’ };var Real[2] consts to { 0:3.14579, 1:2.7152 };var Integer[3] ints to { *:0, 1:1 };

Example of Creating an Array with Explicit Integer Index

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

Initialization with a Non-List

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

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

Initialization with Default Constructor

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

var String[*] strings;Strings as String[10](“”); //create 10 empty strings

var Int[2] binary;binary as Int[2](0); //create 2 integers initial value 0

Example of Creating an Array Initialization by Constructor

Page 68: The Mynx Book October 2007

8/14/2019 The Mynx Book October 2007

http://slidepdf.com/reader/full/the-mynx-book-october-2007 68/222

 Mynx Programming Language

- 68 -

var String[10] strings to default; //10 strings to defaultvar String[*,*] stringy to default; //compiler error!

//no array bounds specifiedvar Int[3,3,3] ints to default; //3x3x3 array of Int to default

Example of Creating an Array using a Default Constructor

Initialization with Null

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

var String[*] name to null; //initialization null reference

name as String[2](“”); //create 2 empty stringsPoint[*] points; //1-dimensional, uncreated, uninitialized

points as Point[2](0,0); //constructor, all objectsvar points to Point[2]; //compiler error! cast expressionpoints as Point[2](0,0); //initial list of constructorspoints as Point[2]; //create array default constructor

Example of Null in the Declaration of an Array

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

var String[*] name to null;name as String[2];name[0] is “hello”;name[1] is “world”;

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

var Real[*] consts to null;consts[0] is 3.14579;consts[1] is 2.7152;

Example of Declaring an Array but Creation and Initialization Later

Page 69: The Mynx Book October 2007

8/14/2019 The Mynx Book October 2007

http://slidepdf.com/reader/full/the-mynx-book-october-2007 69/222

 Mynx Programming Language

- 69 -

var Int[2] ints to { 0, 1 }; //create new array of 2 ints, implicit indexvar Int[10] ints to { *:0 }; //create new array of 10 ints, initial 0var Char[5] ch to default; //create new array of 5 char with default

Example of Declaring an Array and then Creating a New Array

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

Utilizing an Array 

 An array is a homogeneous finite collection of instance objects as elements, all of the same type orclass. However, an array itself is an instance of an object, so using an array involves two forms of use:

1. Using an Array Element - access a specific instance element of the array.

2. Using an Array Object - access and use the entire array as an object.

Using an Element of an Array 

 An array can be used as the whole, or as one of its elements or parts. Using an element of an array involves accessing the element of the array with an index into the element.

var Int[4] ints to { *:1 }; //new 1-dimensional array of Int 1var Int[0] intx to (0);var Int x, y to (0); //new int variables initially 0

x = ints[0]; //x.set(ints[0]); x == 1

y is ints[1]; //y == ints[1]; y == 1

y++; //both y, Int[1] incremented y==2, ints[1] == 2x--; //x decremented x == 0

int[3] = x + y; //Int[3] = 0 + 2 == 2y = ints[0]++; //y = 1++ == 2x = ints[1] * ints[2]; //1 * 1 == 1int[3]++; //2++ == 3

ints = intx; //assign array to array, valid for same rank=1

Example of Using an Element of an Array

Page 70: The Mynx Book October 2007

8/14/2019 The Mynx Book October 2007

http://slidepdf.com/reader/full/the-mynx-book-october-2007 70/222

 Mynx Programming Language

- 70 -

 Array as an Object

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

var Int[4] ints to { *:1 }; //new 1-dimensional array of Int 1Int x,y to null;

x = ints.rank; //get array rank == 1y = ints.size; //get array size == 1 * 10;

ints as Int[2]; //create new array using default

ints.destruct; //destroy the array instance

if(ints == null) //check for nullityints as Int[3];

elseints.destruct;ints as Int[3];

end if;

Example of Using an Array as an Object

 Array as a Parameter

 An array can be passed as an object to a method that only needs to know the type and rank of thearray object.

public constant transpose(var Int[*,*] int) is

for(x is 0 to int.dim(0) )for(y is 0 to int.dim(1) )

int[x,y] = int[y,x];end for(1);

end for(0);

end transpose;

Example of Passing an Array as a Parameter

var Int[10,10] array2D to { *:0 };this.myMethod(array2D);

Example of Using the Array an the Existing Method

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

Page 71: The Mynx Book October 2007

8/14/2019 The Mynx Book October 2007

http://slidepdf.com/reader/full/the-mynx-book-october-2007 71/222

 Mynx Programming Language

- 71 -

//main method is passed 1-dimension array length unknown method main(String[*] args) is

//put each array element to console or IOfor(Ord index is 0 to args.size)

IO.putln(args[index]);end for;

end main;

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

Page 72: The Mynx Book October 2007

8/14/2019 The Mynx Book October 2007

http://slidepdf.com/reader/full/the-mynx-book-october-2007 72/222

 Mynx Programming Language

- 72 -

 Traps

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

Kinds of Traps

 There are two primary kinds of traps or exceptions in Mynx:

1. Checked - force the calling method to handle any traps.2. Unchecked - do not require calling method to handle traps.

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

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

 Trap Declaration

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

public openFile(in String name) has FileNotFoundTrap,ReadOnlyTrap ispublic Int divide(in Int divisor) has ZeroDivideTrap is

Example of Declaration of Traps in a Method

 Trap Invocation

 A trap is caused or raised with a flag statement. A flag statement begins with the keyword flag,followed by the identifier name of the trap, and any information for the constructor. The flag statement creates the trap object with any parameters such as message, or error number, and themethod is exited. The point of execution in the statements returns to the caller method, and anencompassing try statement. The class for the trap is declared and defined separately, then includedin the class or program.

Page 73: The Mynx Book October 2007

8/14/2019 The Mynx Book October 2007

http://slidepdf.com/reader/full/the-mynx-book-october-2007 73/222

 Mynx Programming Language

- 73 -

if(divisor == 0)flag ZeroDivideTrap;

flag InvalidInput(“Enter a character”);

Example of Flag Statements

 Trap Handling 

 A trap is handled with a try statement. A try statement consists of the try clause which begins withthe keyword try, any statements which can flag traps, and then a series of when clause to handleparticular 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. invokemethods on the instance to get trap information, etc.).

 Trap Propagation

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

tryx.doSomething

 when(Trap)flag OtherTrap(“some information”);

end try;

Example of Propagating a Trap

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

Page 74: The Mynx Book October 2007

8/14/2019 The Mynx Book October 2007

http://slidepdf.com/reader/full/the-mynx-book-october-2007 74/222

 Mynx Programming Language

- 74 -

Page 75: The Mynx Book October 2007

8/14/2019 The Mynx Book October 2007

http://slidepdf.com/reader/full/the-mynx-book-october-2007 75/222

 Mynx Programming Language

- 75 -

Units

Page 76: The Mynx Book October 2007

8/14/2019 The Mynx Book October 2007

http://slidepdf.com/reader/full/the-mynx-book-october-2007 76/222

Page 77: The Mynx Book October 2007

8/14/2019 The Mynx Book October 2007

http://slidepdf.com/reader/full/the-mynx-book-october-2007 77/222

 Mynx Programming Language

- 77 -

Primary Elements – Program and Class

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

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

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

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

Program

 A program is a basic element of an application, and is block structured, with a header and footersurrounding 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 actsas the main method of the program. The program name will always precede the name of the mainmethod in the program header.

program  helloWorld as sayIt isprogram  computeFactorial as factorial isprogram  example as main is

Example of Program Header

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

program  hello_world isprogram  gcd isprogram  ticTacToe is

Example of Bodyless Program Header

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

Page 78: The Mynx Book October 2007

8/14/2019 The Mynx Book October 2007

http://slidepdf.com/reader/full/the-mynx-book-october-2007 78/222

 Mynx Programming Language

- 78 -

Class

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

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

class doIt isclass Void as null isclass subClass as parent isabstract class AClass isdefault class example asvirtual class VMyClass as Void, VObject, VCompare isclass intStack as Void has genericStack to Int is

Example of Class Header

Kinds of Classes

 The class, as a basic unit for a library emphasizes use and re-use. There are two ways to utilize a classin Mynx:

1. Inherit or sub-class a class to re-use code in a class.2. Instance a class or instantiate as an object to use code.

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

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

 The seven kinds of classes are:

1. abstract - an incomplete class; declare and/or define methods.2. constant - a completely finally complete class3. default - the regular instance class4. generic - an incomplete class, generalized in type

5. singular - a class which is completely final and static6. static - a class that has no instances7. virtual - a class that declares method and overloads but not define methods.

Page 79: The Mynx Book October 2007

8/14/2019 The Mynx Book October 2007

http://slidepdf.com/reader/full/the-mynx-book-october-2007 79/222

 Mynx Programming Language

- 79 -

 The three basic categories for the kinds of classes are:

1. default - the implicit, regular default class2. restricted - restricted or limits on class use3. partial - a partially defined but incomplete class

Class Kind Inheritable Instance Inherit From Category  Abstract Required No abstract or virtual PartialConstant Never Yes All RestrictedDefault Yes Yes All DefaultGeneric Only generic No only generic Partial

Singular Never No All RestrictedStatic Only static No All Restricted

Virtual Required No only virtual Partial

Table of Mynx Class Kinds, Inheritance, Instance, Category

 Abstract

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

Constant

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

Default

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

Generic

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

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

Page 80: The Mynx Book October 2007

8/14/2019 The Mynx Book October 2007

http://slidepdf.com/reader/full/the-mynx-book-october-2007 80/222

 Mynx Programming Language

- 80 -

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 issomewhat like a program in that it never can be used to instance or inherit from as a parent class.

Static

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

 Virtual

 The virtual class is useful to specify methods, and to tag another class for functionality. A virtualclass 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 possibleinstance of a class, but cannot use any methods, as Void defines no methods.

Page 81: The Mynx Book October 2007

8/14/2019 The Mynx Book October 2007

http://slidepdf.com/reader/full/the-mynx-book-october-2007 81/222

 Mynx Programming Language

- 81 -

Class Design Rationale

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

Class Kind Derivation Existence Method Specified Bound Type

Abstract Yes – must None Incomplete Yes

Constant No Instance Complete Yes

Default Yes – can Instance Complete Yes

Generic Yes – can None Complete No

Singular No Static Complete Yes

Static Yes Static Complete Yes

Virtual Yes – must None Incomplete Yes

Table Summary of Criterion for Mynx Classes

Both abstract and virtual classes are incomplete in having undefined methods a method is declaredbut not defined. Both classes require the derivation of a sub-class to create a complete class. A

generic class is a special kind of incomplete class; it is fully declared and defined except in terms of the class type--hence the a generic class is a parameterized type. A generic class needs instantiationor binding to a type.

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

 A static and singular class is a complete class in both declaring and defining methods, and bound toa type. Both classes are not instances and exist without a constructor or destructor. The distinction isthat a singular class cannot derive a sub-class via inheritance, but a static class can derive a static sub-

class. For the seven kinds of classes, there are essentially four distinct criterion used to uniquely classify each class. The four criteria for class classification are:

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

Page 82: The Mynx Book October 2007

8/14/2019 The Mynx Book October 2007

http://slidepdf.com/reader/full/the-mynx-book-october-2007 82/222

 Mynx Programming Language

- 82 -

Inheritance and Class Types

Inheritance is used to create a new class, and to re-use existing Mynx source code in the form of pre-existing classes. There are four types of inheritance, each with restrictions and requirements for use.

 All classes must inherit a super class when defined. A program however, is not a class nor does it use

a super class, so it never inherits a super class.

 Types of Inheritance

 The four types of inheritance in Mynx are:

1. Null2. Single3. Multiple Virtual4. 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 isgiven in the virtual class declaration the class inherits null or nothing.

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

//define the class

end class;

Example of Null Inheritance

virtual class Void is //implicitly inherits null or nothing 

//define the class

end class;

Example of Implicit Null Inheritance

  The class Void explicitly inherits null or nothing, but implicitly inherits null. A virtual class can

declare but not define a class, to be used as a specification for implemented functionality in aconcrete 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 virtualclass, it would declare the super class as null.

Page 83: The Mynx Book October 2007

8/14/2019 The Mynx Book October 2007

http://slidepdf.com/reader/full/the-mynx-book-october-2007 83/222

 Mynx Programming Language

- 83 -

For a concrete class implementing multiple virtual classes which inherit null, then there is no overlapin 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, asonly one declared method is implemented in the concrete class.

Single

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

 with mynx.core.*;

default class myClass as baseObject is

//...class body...

end class;

Example of Single Inheritance

Diagram of Single Inheritance

Page 84: The Mynx Book October 2007

8/14/2019 The Mynx Book October 2007

http://slidepdf.com/reader/full/the-mynx-book-october-2007 84/222

Page 85: The Mynx Book October 2007

8/14/2019 The Mynx Book October 2007

http://slidepdf.com/reader/full/the-mynx-book-october-2007 85/222

 Mynx Programming Language

- 85 -

Diagram of UML Class Diagram of Multiple Virtual Inheritance

Multiple Disjoint

Multiple disjoint inheritance is multiple inheritance, but is restricted to abstract classes which declareand 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 definefunctionality, but no constructor to avoid super-class reference ambiguity. A primary reason for anabstract 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 theconstraints of both. If an inherited abstract method is abstract or undefined, then the sub-class mustimplement the declared but not define the method. Multiple disjoint inheritance can be used withsingle inheritance, the caveat being that the super class is likewise disjoint from the multiply inherited abstract classes.

Page 86: The Mynx Book October 2007

8/14/2019 The Mynx Book October 2007

http://slidepdf.com/reader/full/the-mynx-book-october-2007 86/222

 Mynx Programming Language

- 86 -

class SubClassXY as ABaseClassX, ABaseClassY, VirtualRootClass is

!! comparison abstract class methods are disjointfrom persistence class !!

//...class definition...

end class;

Example of Multiple Disjoint Inheritance

Diagram of UML Class Diagram of Multiple Disjoint Inheritance

Page 87: The Mynx Book October 2007

8/14/2019 The Mynx Book October 2007

http://slidepdf.com/reader/full/the-mynx-book-october-2007 87/222

 Mynx Programming Language

- 87 -

Classes and Inheritance

 There are three categories of classes in Mynx:

1. Partial - a partially defined class

2. Default - a normal, default class3. Restricted - restricted class in inheritance or instantiation

 The partial classes are the abstract, generic, and virtual. Partial refers to an incomplete or partial classdefinition. The partial classes can only inherit other partial classes, or become sub-classed (inheritedby a default class) to a non-partial class. The kinds of classes the partial classes can inherit for eachclass kind are:

1. abstracted - abstract, virtual class inheritance2. generic - generic inheritance3. virtual - virtual inheritance

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

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

1. constant - no class inheritance2. singular - no class inheritance3. static - static class inheritance

Inheritance of Attributes and Methods

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

1. attributes2. methods3. operator overloads

 Attributes

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

Page 88: The Mynx Book October 2007

8/14/2019 The Mynx Book October 2007

http://slidepdf.com/reader/full/the-mynx-book-october-2007 88/222

 Mynx Programming Language

- 88 -

class parentAttribute as null is

private construct is null;

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

end class;

class childAttribute as parentAttribute is

private construct is null;

!! semantic error! Attribute shadows super`field !!public Int field to 1;

end class;

Example of Shadowing a Class Attribute in Inheritance

Methods

Methods are inherited by a class, and super class methods, if not constant, can be either overriddenor overloaded. If a super class has an abstract or virtual method, the sub class must implement themethod 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 ininheritance 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 methodtype to override an existing method.

Inheritance of Methods

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

Method Overriding 

Method overriding re-defines a method in a sub class in terms specific for that sub class. A methodoverrides a super class method if it has the same method signature. A method can override a superclass method even if the return type of the method is different from the return type of the parentmethod. 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 

Page 89: The Mynx Book October 2007

8/14/2019 The Mynx Book October 2007

http://slidepdf.com/reader/full/the-mynx-book-october-2007 89/222

 Mynx Programming Language

- 89 -

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

Rules for Method Overriding 

 There are six rules for overriding a method:

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

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

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

4. An overridden method with a self type for the method type must use the class name asthe 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, butinvariant.

class Parent as null is

private construct is null;

public doSomething(in Int i) isif(i == 0)

i = 1 ;else

i++;end if;

end doSomething;

end class;

class Child as Parent is

private construct is null;

!! override method from parent !!public void doSomething(in Int i) is

i++;

end doSomething;

end class;

Example of Method Overriding with Inheritance

Page 90: The Mynx Book October 2007

8/14/2019 The Mynx Book October 2007

http://slidepdf.com/reader/full/the-mynx-book-october-2007 90/222

 Mynx Programming Language

- 90 -

Covariant Method Overriding 

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

 The four rules for covariant method return type override are:

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

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

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

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

Page 91: The Mynx Book October 2007

8/14/2019 The Mynx Book October 2007

http://slidepdf.com/reader/full/the-mynx-book-october-2007 91/222

 Mynx Programming Language

- 91 -

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

public covariant VObject doIt is implied;

public void doProcedure is

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

public Object doObject is implied;

end class;

default class Child as Parent is //define and override methods//in the sub-class of Parent

public baseObject doIt is //covariant override of doIt//baseObject sub-class VObject

//...method body //but not covariant for sub-classend doIt;

public Real doProcedure is //compiler error! Try to overridereturn null; //void in super class return type

end doProcedure; //or class procedural method

public void doObject is //compiler error! Try to overridenull; //void in sub class return type or

end doObject; //class procedural method

end class;

Example of Covariant Method Override with Implied Method

virtual class VCopy is

virtual covariant VObject copy; //covariant method definition//for copy deep-copy method

end class;

class doCopy as VCopy, VObject is

public construct is to null;

public doCopy is //doCopy covariant override//...method body //of virtual method; doCopy

end doCopy; //is sub-class VObject, thus//return of doCopy override

end class; //super-class type of VObject

Example of Covariant Method Override with Virtual Class

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

Page 92: The Mynx Book October 2007

8/14/2019 The Mynx Book October 2007

http://slidepdf.com/reader/full/the-mynx-book-october-2007 92/222

Page 93: The Mynx Book October 2007

8/14/2019 The Mynx Book October 2007

http://slidepdf.com/reader/full/the-mynx-book-october-2007 93/222

 Mynx Programming Language

- 93 -

Operator Overloading 

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

class Ord64 ispublic Ord64 add(in Ord64 op) is

//define addition for Ord64end add;

overload constant + as add;

end class;

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

public Ord32 add(in Ord32 op) is//define addition for Ord32

end add;//re-declare overload from super-class

overload constant in Ord64 is + as add;

end class;

program  addExample is

let Ord64 i64 to 0;let Ord32 i32 to 37;

i64 = i64 + i32;

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

//implicit upcast explicitly:

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

end program ;

Example of Operator Overloading within the Class and Sub-Class

Class Reference Prefixes

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

1. super - parent or super class reference2. this - instance or current class reference3. self - static elements of the current class

Page 94: The Mynx Book October 2007

8/14/2019 The Mynx Book October 2007

http://slidepdf.com/reader/full/the-mynx-book-october-2007 94/222

 Mynx Programming Language

- 94 -

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 anattribute. Hence access of class elements is with a “dottic” operator.

Table of Class Element Access Operators

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

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

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

Example of Accessing Attribute over Method

Super Class Prefix

 The super reference prefix refers to the super class or parent class to access an attribute or method. The methods and attributes of a parent are available in a derived class using the super prefix. Thesuper 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 superclass is implicit with no ambiguity about which method is referenced through the super prefix. Thesuper reference prefix can be used within a method, or method equivalent.

  Access Class Element Operator Name Operator  Attribute Call Tic `

Method Invoke Dot .

Page 95: The Mynx Book October 2007

8/14/2019 The Mynx Book October 2007

http://slidepdf.com/reader/full/the-mynx-book-october-2007 95/222

 Mynx Programming Language

- 95 -

class Parent as null is

private construct is null;

public doSomething(in Int i) is

if(i == 0)i = 1 ;else

i++;end if;

end doSomething;

end class;

Example of Super Class Parent Definition

class Child as Parent is

private construct is null;

!! override method from parent as same method !!public void doSomething(in Int i) is

super.doSomething(i);end doSomething;

!! overload method from parent using parent method !!public void doSomething(in Char c) is

super.doSomething(c.valueOf);end doSomething;

end class;

Example of Super Class Reference with Inheritance

 This Class Prefix

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

Page 96: The Mynx Book October 2007

8/14/2019 The Mynx Book October 2007

http://slidepdf.com/reader/full/the-mynx-book-october-2007 96/222

 Mynx Programming Language

- 96 -

class Parent as null is

private construct is null; //no constructor

private Int zero to 0;

public default theMethod(in Int i) is//define the method ...

end theMethod;

!! overload the method within the class !!public void theMethod(in Bit b) is

this.theMethod(b + this`zero);end theMethod;

end class;

Example of Class with This Reference Prefix

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

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

class X is

public construct is to null;

public X get isreturn this;

end get;

end class;

Example of Class with This Reference as Variable

Page 97: The Mynx Book October 2007

8/14/2019 The Mynx Book October 2007

http://slidepdf.com/reader/full/the-mynx-book-october-2007 97/222

Page 98: The Mynx Book October 2007

8/14/2019 The Mynx Book October 2007

http://slidepdf.com/reader/full/the-mynx-book-october-2007 98/222

 Mynx Programming Language

- 98 -

Generics

 A generic class is type parameterized, or in more simply, the specific type of the generic class isabstract. A generic class is a complete class like a default class, except that the specific type isdeclared but not defined -- it is generic. In order to use a generic class, the class must be bound to a

type or instantiated. A typeful class is a non-generic class that has a specific type, which would be ageneric class that is bound to a type.

 The two primary reasons for a generic class are:

1. Reuse by instantiation to different class types.2. Avoid repeated type casts by using a concrete type.

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

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

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

Elements of a Generic Class

 A generic class is a complete class, and so supports the four major elements of a class-- attributes,methods, operator overloads, and a default method. A generic class method includes constructors

and a destructor. The type of methods and attributes can be both generic and typeful or non-generic.

Generic Attributes

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

class GStack as null is

private Ordinal count to 0; //typeful attributeprivate generic[*] data to null;//generic attribute

end class;

Example of Generic Class Attributes

Page 99: The Mynx Book October 2007

8/14/2019 The Mynx Book October 2007

http://slidepdf.com/reader/full/the-mynx-book-october-2007 99/222

 Mynx Programming Language

- 99 -

Generic Methods

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

generic class GVar as null is

private generic value to null;

public construct(in generic val) isthis`value is val;

end construct;

public constant generic get isreturn this`value;

end get;

public constant void set(in generic val) isthis`value is val;

end set;

end class;

Example of Generic Class Methods

Operator Overloads in Generic Class

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

generic class GVar as null is

private generic value to null;

public construct(in generic val) isthis`value is val;

end construct;

public constant generic get isreturn this`value;

end get;

public constant void set(in generic val) isthis`value is val;

end set;

overload constant = as set;

end class;

Example Operator Overload in a Generic Class

Page 100: The Mynx Book October 2007

8/14/2019 The Mynx Book October 2007

http://slidepdf.com/reader/full/the-mynx-book-october-2007 100/222

 Mynx Programming Language

- 100 -

Default Method in Generic Class

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

generic class GVar as null is

private generic value to null;

public construct(in generic val) isthis`value is val;

end construct;

public constant generic get isreturn this`value;

end get;

public constant void set(in generic val) isthis`value is val;

end set;

overload constant = as set;public default is to get;

end class;

Example of a Default Method in a Generic Class

Inheritance with Generic Classes

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

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

Page 101: The Mynx Book October 2007

8/14/2019 The Mynx Book October 2007

http://slidepdf.com/reader/full/the-mynx-book-october-2007 101/222

 Mynx Programming Language

- 101 -

Inheriting a Generic Class

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

generic class GVarPut as GVar is

public constant generic put(in generic data) issuper.set(data);return super.get;

end get;

end class;

Example of a Generic Class Inheritance of a Generic Class

Inheriting Non-Generic Classes

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

1. abstract - using disjoint multiple inheritance2. virtual - using multiple inheritance

Both abstract and virtual classes can be inter-mixed with inheritance in a generic class. A genericclass, like a default class, can inherit one or many abstract classes. However, with inherited multipleabstract classes must be of disjoint multiple inheritance. A generic class, like with an abstract class,can inherit multiple virtual classes. However, a generic class must implement all methods of the

 virtual class, which are non-generic.

Page 102: The Mynx Book October 2007

8/14/2019 The Mynx Book October 2007

http://slidepdf.com/reader/full/the-mynx-book-october-2007 102/222

 Mynx Programming Language

- 102 -

Inheriting an Abstract Class

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

abstract class AEmpty is

public abstract Ordinal size;

public Bool isEmpty isreturn this.size == 0;

end isEmpty;

end class;

abstract class AFull is

public abstract Ordinal count;

public Bool isFull is

return this.count != 0;end isEmpty;

end class;

generic class GVarSize as AEmpty, AFull is

private Ordinal size to 0;

public Ordinal size isreturn this`size;

end size;

public Ordinal count is to size;

end class;

Example of Generic Class Inheriting Multiple Disjoint Abstract Classes

Page 103: The Mynx Book October 2007

8/14/2019 The Mynx Book October 2007

http://slidepdf.com/reader/full/the-mynx-book-october-2007 103/222

 Mynx Programming Language

- 103 -

Inheriting a Virtual Class

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

virtual class VEmpty is

public Bool isEmpty;public Ordinal size;

end class;

virtual class VFull is

public Bool isFull;public Ordinal size;

end class;

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

private Ordinal size to 0;

public Ordinal size isreturn this`size;

end size;

public Ordinal count is to size;

end class;

Example of a Generic Class Inheriting Multiple Virtual Classes

Page 104: The Mynx Book October 2007

8/14/2019 The Mynx Book October 2007

http://slidepdf.com/reader/full/the-mynx-book-october-2007 104/222

 Mynx Programming Language

- 104 -

Instantiation of a Generic Class

In order to use a generic class, the class must be instantiated, or bound to a specific class type. Theinstantiation 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 aclass 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 beused like any other default class in Mynx.

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

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

Local Instantiation

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

 Attribute level instantiation creates a class that is defined within the class where it is instantiated.

default class myLocalVariable is

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

public construct is to null;

end class;

Example of Local Instantiation of a Generic Class to Type String

Page 105: The Mynx Book October 2007

8/14/2019 The Mynx Book October 2007

http://slidepdf.com/reader/full/the-mynx-book-october-2007 105/222

 Mynx Programming Language

- 105 -

Global Instantiation

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

instantiation syntax from becoming mangled.

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

class StringVar has GVar to String is

public void setEmptyString isthis.set(“ “);

end setEmptyString;

end class;

Example of Global Instantiation of a Generic Class to Type String

Page 106: The Mynx Book October 2007

8/14/2019 The Mynx Book October 2007

http://slidepdf.com/reader/full/the-mynx-book-october-2007 106/222

 Mynx Programming Language

- 106 -

Instance of a Generic Class

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

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

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

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

1. attribute of the class2. parameter of a class method3. variable of a class method

Page 107: The Mynx Book October 2007

8/14/2019 The Mynx Book October 2007

http://slidepdf.com/reader/full/the-mynx-book-october-2007 107/222

 Mynx Programming Language

- 107 -

class StringVar has GVar to String is

public void setEmptyString isthis.set(“ “);

end setEmptyString;

end class;

class useGenericClasses is

//create local, use constructor in declarationpublic GVar to String lstrVar to “local”;

//create global, use constructor elsewherepublic StringVar gStrVar to null;

public construct is to null;

gStrVar as StringVar(“global”);

end construct;

public void doSomething(in StringVar sv) isvar StringVar strvar to null;

strvar = sv;if(sv == this`gStrVar)

this`lStrVar is sv;end if;

end doSomething;

end class;

Example of Local and Global Instantiation Instances within a Class

Page 108: The Mynx Book October 2007

8/14/2019 The Mynx Book October 2007

http://slidepdf.com/reader/full/the-mynx-book-october-2007 108/222

 Mynx Programming Language

- 108 -

Page 109: The Mynx Book October 2007

8/14/2019 The Mynx Book October 2007

http://slidepdf.com/reader/full/the-mynx-book-october-2007 109/222

 Mynx Programming Language

- 109 -

Elements

Page 110: The Mynx Book October 2007

8/14/2019 The Mynx Book October 2007

http://slidepdf.com/reader/full/the-mynx-book-october-2007 110/222

 Mynx Programming Language

- 110 -

Page 111: The Mynx Book October 2007

8/14/2019 The Mynx Book October 2007

http://slidepdf.com/reader/full/the-mynx-book-october-2007 111/222

 Mynx Programming Language

- 111 -

Minor Elements

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

1. Attributes - an element of data or information2. Methods - a basic element of functionality 

 Attributes

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

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

 Attribute Mode

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

1. default - attribute is persisted beyond the instance2. volatile - attribute is not persisted beyond instance

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

 Attribute Kind  The attribute kind is the qualification placed upon the attribute for use in an instance in thedeclaration.

 The kind of attribute determines if it is an instance or class attribute, and if it is a constant or not.

  Attribute Kind Constant Staticconstant Yes Nosingular Yes Yes

static No Yesvariable No No

Table of Attribute Kinds

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

Page 112: The Mynx Book October 2007

8/14/2019 The Mynx Book October 2007

http://slidepdf.com/reader/full/the-mynx-book-october-2007 112/222

 Mynx Programming Language

- 112 -

 Attribute Type

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

 Attribute Name

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

Initial Value

 All attributes initialized explicitly, either by equivalence with a value, or through parameters to theinstance. 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, staticattributes, and static methods. The keyword null can be used as an initial value, indicating the objectinstance reference refers to nothing in the initial value. Initial values can not be initialized with non-static attributes, as the order of attribute initialization is not specified nor guaranteed by Mynx.

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

Example of Initial Values in Attributes

 Attribute Scope

 Attribute scope is used to control visibility of attributes to methods within the class or program. Attributes can optionally be scoped by hiding the attribute from methods, or exposing an attributeto methods. Attributes are checked for visibility by a method if accessed, and a method that can notaccess an attribute will generate an error. Attribute scope is internal to a class or program, soinapplicable 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 thatare exclusive or hidden use the keyword out. Then it is followed by the keyword for, and themethod list.

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

Page 113: The Mynx Book October 2007

8/14/2019 The Mynx Book October 2007

http://slidepdf.com/reader/full/the-mynx-book-october-2007 113/222

 Mynx Programming Language

- 113 -

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

in for all – inclusive for all methodsout for null – exclusive for no methods

Table of Implicit Scope Attributes

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

Program Attributes

Program attributes are declared with the keyword let prefixing or beginning the declaration. The restof 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 formodification within the program, or constant for a final program attribute. Similar to a class

attribute, program attributes must be initialized to a starting value.

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

let variable Ordinal i to (0);let variable Int x, y, z to (3);

Example of Program Attributes

Class Attributes

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

1. public - fully accessible2. protect - accessible only in a sub-class by inheritance, or within class3. private - not accessible ever, except within the class

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

public Int size to 0 in for all;public Int count to -1 in for getCount;

Example of Class Attributes

Page 114: The Mynx Book October 2007

8/14/2019 The Mynx Book October 2007

http://slidepdf.com/reader/full/the-mynx-book-october-2007 114/222

 Mynx Programming Language

- 114 -

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

Methods

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

1. Method header or the method signature2. Method body which defines functionality 3. Method footer that forms a method block 

Program Methods

  A program method is preceded by the keyword method, with the rest of the method header

declaration following, and ends with the is keyword. A method declares a return type, which is aclass 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 oroverridden, 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 aprocedure. If a method does not explicitly state a return type, an implicit void (the method as aprocedure) is used as the return type. Note that the return type void is nothing, but the return typeof Void is the root virtual parent class Void. Both are entirely different entities.

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

Example of Program Method Return Types

Class Methods

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

public implicitVoidMethod is – implicit void return typepublic void doSomething is – explicit void return typeprivate Void doIt is – method return of Void virtual classprotect method(VCompare comp) is – invalid method name, keyword

Example of Class Method Return Types

Page 115: The Mynx Book October 2007

8/14/2019 The Mynx Book October 2007

http://slidepdf.com/reader/full/the-mynx-book-october-2007 115/222

 Mynx Programming Language

- 115 -

Parameter List

  After the method name, the parameters to the method are specified, the name and parameter listform 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 differentreturn types...). Unlike other programming languages, a method with no parameters does not use apair of “dead parenthesis” or dead parens “()” trailing after the method name.

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

Method Parameter Modes

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

1. in - parameter passed into method2. out - parameter passed out of a method3. var - parameter passed both in and out of a method or variant4. series- parameter passed in with variable number of parameters

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

1. Nullity - Object reference can be initially null.2. Mutable - Object reference can change within a method.3. Number - Count of references per parameter (one or many).

ParameterMode

InitiallyNull?

ReferenceImmutable?

Number ofReferences

In No Yes 1Out Yes No 1Var No No 1

Series No Yes N

Table of Method Parameter Modes Table

In Parameter Mode

 An in parameter can not be null, and the object reference is constant or immutable, so can not bechanged. 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 constantto the method. An in parameter does not pass information back from the method.

Page 116: The Mynx Book October 2007

8/14/2019 The Mynx Book October 2007

http://slidepdf.com/reader/full/the-mynx-book-october-2007 116/222

 Mynx Programming Language

- 116 -

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

var Int temp to null;

temp = first;

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

end swap;

Example of Class Method using In Parameter Mode

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

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

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

Example of Using the Defined Method with In Parameter

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

Out Parameter Mode

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

and passed back. An out parameter is used to return information from a method.

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

var Int temp to null;

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

end swap;

Example of Defining a Method with Out Parameter

Page 117: The Mynx Book October 2007

8/14/2019 The Mynx Book October 2007

http://slidepdf.com/reader/full/the-mynx-book-october-2007 117/222

Page 118: The Mynx Book October 2007

8/14/2019 The Mynx Book October 2007

http://slidepdf.com/reader/full/the-mynx-book-october-2007 118/222

 Mynx Programming Language

- 118 -

Series Parameter Mode

 A series parameter is like an in parameter, but takes multiple parameters, and within the method is a1-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 nullis constant.

 There are three rules for using a series parameter:

1. Only one series parameter in a method header.2. With mixed parameters, the series parameter is last.3. A method header with a series parameter cannot be ambiguous with other overloaded

methods of the same name.

public Int addIntegers(series Int[] ints) is

//...end addIntegers;

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

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

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

Example of Defining a Method and Using with Series Parameter

Page 119: The Mynx Book October 2007

8/14/2019 The Mynx Book October 2007

http://slidepdf.com/reader/full/the-mynx-book-october-2007 119/222

Page 120: The Mynx Book October 2007

8/14/2019 The Mynx Book October 2007

http://slidepdf.com/reader/full/the-mynx-book-october-2007 120/222

Page 121: The Mynx Book October 2007

8/14/2019 The Mynx Book October 2007

http://slidepdf.com/reader/full/the-mynx-book-october-2007 121/222

 Mynx Programming Language

- 121 -

Class Methods

  A class method is similar conceptually to a program method, but a class method has differentfeatures 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 implicituse. These special methods are:

1. constructor - create or make a new class instance method2. destructor - destroy or cleanup an existing class instance3. default - default method of an instance called when none specified

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

 A class method is declared first with a keyword indicating access; Mynx does not have any implicitaccess (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 keywordmethod as in a program.

Method Mode

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

1. abstract - undefined in abstract class, must be defined in sub-class2. constant - method can not be overridden in inherited class

3. default - regular method for an instance object4. singular - method is constant, and static5. static - method is a class method, not an instance6. virtual - undefined method in virtual class, must implement in non-virtual sub-class

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

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

 A class method can have two types of synchronization:

1. asynchronous - not thread safe; single-threaded method2. synchronous - thread safe method; multi-threaded method

Page 122: The Mynx Book October 2007

8/14/2019 The Mynx Book October 2007

http://slidepdf.com/reader/full/the-mynx-book-october-2007 122/222

 Mynx Programming Language

- 122 -

 The asynchronous mode is the default synchronization mode used, and is explicitly declared with theasync keyword. The synchronous mode is declared explicitly with the sync keyword before a classmethod header. A synchronous class method for multi-threaded, thread safe methods creates anoverhead for invoking and using a class method. A synchronous method creates a lock on a method,ensuring that a method used has only one thread executing the method at a time.

Method Return Type

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

 The method return type is not part of the method signature.

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

Example of Declaring a Method Return Type

Method Headers

 A class method header is a composite of information about the class method. A class method mustspecify the elements:

1. visibility - the external access level of the class method2. mode - the kind of a class method3. type - the return type of a class method (implicit void)4. synchronized - the class method is thread safe (implicit non-thread safe)

5. name - the name of the class method6. parameters - any parameters in and out of the class method7. traps - any possible traps the class method flags8. scope - the internal access of a class method (implicit scope is visible for all)

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

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

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

Example of Declaring a Class Method Header

Page 123: The Mynx Book October 2007

8/14/2019 The Mynx Book October 2007

http://slidepdf.com/reader/full/the-mynx-book-october-2007 123/222

Page 124: The Mynx Book October 2007

8/14/2019 The Mynx Book October 2007

http://slidepdf.com/reader/full/the-mynx-book-october-2007 124/222

 Mynx Programming Language

- 124 -

Overriding a Static Method

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

Kind of Method OverrideStatic Yes, can optionally override

Singular No, can never override

Table for Overriding a Static Method

  A static method can optionally be overridden, but the override is invariant. Overriding a staticmethod 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 andis always invariant.

default class BubbleSort as null is //implement VSort

public construct is to null;

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

//...implementation of bubble sort

end sort;

end class;

default class QuickSort as null is //implement VSort

public construct is to null;

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

//...implementation if quick sort

end sort;

end class;

Example of Overriding a Static Method in Multiple Classes

Page 125: The Mynx Book October 2007

8/14/2019 The Mynx Book October 2007

http://slidepdf.com/reader/full/the-mynx-book-october-2007 125/222

 Mynx Programming Language

- 125 -

  A refinement of the QuickSort class and the method sort by checking if it is sorted in theQuickerSort class.

 The class QuickerSort and method sort then is:

constant class QuickerSort as QuickSort is

public construct is to null;

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

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

end if;

end sort;

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

end isSorted;

end class;

Example of QuickerSort Method

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

program  sortdemo is

//invoke static methodrankObject robj as randomRankObject.get;

//for each sort must call class by name, no instancesQuickSort.sort(robj);QuickerSort.sort(robj); //already sorted, so will return

BubbleSort.sort(robj); //bubble sort best on already sorted

end program;

Example of Using the Sort Methods

Page 126: The Mynx Book October 2007

8/14/2019 The Mynx Book October 2007

http://slidepdf.com/reader/full/the-mynx-book-october-2007 126/222

Page 127: The Mynx Book October 2007

8/14/2019 The Mynx Book October 2007

http://slidepdf.com/reader/full/the-mynx-book-october-2007 127/222

Page 128: The Mynx Book October 2007

8/14/2019 The Mynx Book October 2007

http://slidepdf.com/reader/full/the-mynx-book-october-2007 128/222

 Mynx Programming Language

- 128 -

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

 with mynx.core.Int;

if(x < MAXIMUM)//do something

end if;

Example of Implicit Static Method Inclusion

 The class must have an absolute namespace to explicitly include the Int class, and allow for implicitstatic 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 multipleclasses that are absolute in namespace, then the class name would have to be explicit in the methodreference.

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

Reference to External Static Method

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

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

than full prefix reference.

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

end if;

Example of Static Method Inclusion for Reference

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

Rewritten with the static class name reference prefix:

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

end if;

Example of Explicit Static Inclusion

Page 129: The Mynx Book October 2007

8/14/2019 The Mynx Book October 2007

http://slidepdf.com/reader/full/the-mynx-book-october-2007 129/222

 Mynx Programming Language

- 129 -

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

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

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

end if;

Example of Explicit Static Inclusion by Class Attribute

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

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

Example of Static Method Inclusion

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

var Int x to null;var Real r to 2.7714;

x = Math.Abs(r);

Example of Explicit Static Method Inclusion

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

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

Page 130: The Mynx Book October 2007

8/14/2019 The Mynx Book October 2007

http://slidepdf.com/reader/full/the-mynx-book-october-2007 130/222

 Mynx Programming Language

- 130 -

Method Equivalents: Low Fat Methods

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

Method equivalents are useful for:

1. default parameters to a method (overload a method)2. alias a method with a different name without rewriting it3. include super class methods explicitly in a class4. define constructor and destructor as regular class methods5. override a super class method with a different local method

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

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

class methodEquiv is

public construct is to null;public desturct is to null;

end class;

Example of Defining Method Equivalents

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

class methodEquiv is

public construct isnull;

end construct;

public destruct isnull;

end destruct;

end class;

Example of Full Method Definition

Page 131: The Mynx Book October 2007

8/14/2019 The Mynx Book October 2007

http://slidepdf.com/reader/full/the-mynx-book-october-2007 131/222

 Mynx Programming Language

- 131 -

Default Parameters by Method Equivalents

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

 Java).

public Int addition(in Int addend, in Int augend) is//method body

end addition;

Example of Method Definition

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

Using an equivalent method to do so:

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

Example of Method Equivalents for Default Parameters

Fully declared and defined with a wrapper method would be:

public Int addition(in Int augend) is

this.addition(this,augend);

end addition;

Example of Full Method Definition

Export Instance Method

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

protect singular void myClassMethod is// method bodyend myClassMethod;

public void myMethod is to myClassMethod;

Example of Method Equivalent Definition with Static Method

Page 132: The Mynx Book October 2007

8/14/2019 The Mynx Book October 2007

http://slidepdf.com/reader/full/the-mynx-book-october-2007 132/222

 Mynx Programming Language

- 132 -

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

Renaming All Class Methods of a Name

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

public writeln is to putln;

Example of Method Equivalent to Rename All Class Methods

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

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

public writeln is //no argument methodthis.putln;

end writeln;

public writeln(in String str) is //String argument methodthis.putln(str);

end writeln;

public writeln(in Char chr) is //Character argument methodthis.putln(chr);

end writeln;

public writeln(in Bool bool) is //Bool argument methodthis.putln(bool);

end writeln;

public writeln(in Ordinal uint) is //Ordinal argument methodthis.putln(uint);

end writeln;

public writeln(in Int int) is //SignedInt parameter methodthis.putln(int);

end writeln;

Example of Equivalent Method Redefinition

Page 133: The Mynx Book October 2007

8/14/2019 The Mynx Book October 2007

http://slidepdf.com/reader/full/the-mynx-book-october-2007 133/222

 Mynx Programming Language

- 133 -

Construction, Destruction, and Default Method of a Class

 There are three special methods of a class, two are to create and destroy instances or objects of aclass. The methods are a constructor, destructor, which are a special kind of method in a class. Thethird method is the default implicit method of the class. All special methods are not directly 

accessible or explicitly invoked, but are indirectly called through usage of a class.

Special Method Number RestrictionsConstructor At least 1 Not for static, singular, or partial classesDestructor Optionally 1 Not for singular, static, or partial classesDefault Optionally 1 Not for static or singular classes

Table Synopsis Special Class Methods

Constructor

 A constructor is used implicitly to create a new class instance, or an object. A non-partial and non-

static class must have at least one constructor defined, and there is no automatically created or apredefined, given constructor (like in Java and C++, although a compiler could generate one but thisis 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 orsingular class (as a static class will never create any instances.) An abstract class can optionally definea constructor, a constant or default class must define at least one constructor. Since a program is nota class, it never has any kind of a constructor.

Constructors are never inherited from the parent classes. A constructor can be overloaded ondifferent 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 keywordconstructor is used instead. Similar to methods, a constructor can be public, private, or protectedaccess. A constructor can have parameters or arguments exactly like a method, or no parameters inthe constructor header. The constructor is defined internally like a method, using statements toinitialize the class instance. The constructor uses a footer like a method with the constructorkeyword instead of the method name. A constructor, like a method, can be overloaded withdifferent parameter signatures for each constructor. The general form of constructor definition is:

 ACCESS construct PARAMETERS is

//code to initialize class

end construct;

Example of Constructor Syntax

Page 134: The Mynx Book October 2007

8/14/2019 The Mynx Book October 2007

http://slidepdf.com/reader/full/the-mynx-book-october-2007 134/222

 Mynx Programming Language

- 134 -

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

public construct is

null;

end construct;

Example of Default Constructor

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

public construct(in Int i) is

this`int = i;

end construct;

Example of Non-Default Constructor

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

1. A set of default parameters to existing constructor or method2. A reference to a super-class constructor or methods.

class childClass as parentClass is

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

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

public construct(Int I, Int j) is//define constructor

end construct;

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

end class;

Example of Constructor Definition with Method Equivalent

Page 135: The Mynx Book October 2007

8/14/2019 The Mynx Book October 2007

http://slidepdf.com/reader/full/the-mynx-book-october-2007 135/222

 Mynx Programming Language

- 135 -

class 2DPoint as Void is

private default variable Int i to null;private default variable Int j to null;

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

public construct(in Int x, in Int y) isthis` i = x ;this` j = y ;

end construct;

public constant x is //access x-coordinate as methodreturn this`x;

end x;

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

return this`y;

end y;

end class;

Example of Defining Multiple Constructors in a Class

Constructor Invocation

 A constructor is invoked indirectly, either through:

1. Create expression as part of an expression statement.2. As part of the declaration of a variable or constant.

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

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

Example of Constructor Declaration

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

Example of Invoking a Constructor

Page 136: The Mynx Book October 2007

8/14/2019 The Mynx Book October 2007

http://slidepdf.com/reader/full/the-mynx-book-october-2007 136/222

 Mynx Programming Language

- 136 -

 There are two special cases of invoking a constructor:

1. Invoking a default constructor.2. Invoking a non-default constructor.

Invoking the default constructor is difficult as it is a call to a constructor without any parameters. Inorder 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 defaultconstructor is invoked without the class having one, then it will generate a compiler error.

var Int x to default; //invoke default Int constructorvar String str to default; //invoke default String constructorvar Point p to default; //invoke default constructor

x as Int; //invoke default Int constructorstr as String; //invoke default String constructorb as Point; //invoke default Point constructor

Example of Invoking Default Constructor

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

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

x as null; or x is null;

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

Example of Not Invoking Default Constructor

In the creation expression involving null, the as creation operator is equivalent to the is assignmentoperator, but only in the case of null. Using the 2DPoint class in a program:

program  2PointProgram  is

var 2DPoint defaultPoint to null;var 2DPoint aPoint to (100,100);

var 2DPoint thePoint to default;

defaultPoint as default; //use default constructor

end program ;

Example of Using Constructors of a Class

Page 137: The Mynx Book October 2007

8/14/2019 The Mynx Book October 2007

http://slidepdf.com/reader/full/the-mynx-book-october-2007 137/222

 Mynx Programming Language

- 137 -

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 adestructor 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 adestructor. Similar to a constructor, a destructor returns no value, so has no method type. There isno 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 aprivate destructor never can invoke the destructor implicitly. The general form of a destructor is:

public destruct is

//cleanup class before terminating

end destructor;

Example of Syntax for a Destructor

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

public destructor is to this.cleanup;public destructor is to this.exitClass;

Example of Destructor Definition with Method Equivalent

Destructor Invocation

 A class destructor is never explicitly invoked directly; it is invoked when the class is taken out of service by the underlying runtime (at this writing July 2004, the .NET or JVM platforms) when

garbage-collected.

 A better class design approach is to use a method to deactivate and take an instance out of service(in this case, the super-class VObject method nullify) and then by method equivalent to define thedestructor in terms of that method. Then the instance can be deactivated explicitly by the user, orimplicitly by the runtime platform using the same functionality.

Page 138: The Mynx Book October 2007

8/14/2019 The Mynx Book October 2007

http://slidepdf.com/reader/full/the-mynx-book-october-2007 138/222

 Mynx Programming Language

- 138 -

default class fileProcessor as Void, VObject is

private File procFile to null;

public construct(in String filename) is

this`procFile as` File(filename);

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

end if;

end construct;

public void nullify isthis`procFile.close; //always close filethis`procFile.nullify; //nullify file instance

end nullify;

public destruct is to nullify;

end class;

Example of Destructor Invocation

Like a constructor, only an abstract, constant, or default class can define a destructor. There is noguarantee 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 calledupon garbage collection, or upon the end of the application, which ever occurs first, with noassurance of when the destructor is called.

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

Page 139: The Mynx Book October 2007

8/14/2019 The Mynx Book October 2007

http://slidepdf.com/reader/full/the-mynx-book-october-2007 139/222

 Mynx Programming Language

- 139 -

Default Class Method

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

a default method as there is never an instance of a static class.

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

Default Method Declaration

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

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

Example of Declaring a Default Method

 A class can only define one default method, and a default method is not inherited from a parentclass (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) andstatic class (static, singular) classes never define a default method (as instances can not be created...),so hence only a class with constructors (a class that can create an instance) can have a default

method.

Default Method Invocation

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

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

sum = zeroInt; //implicitly call get method

Example of Using an Default Method

Page 140: The Mynx Book October 2007

8/14/2019 The Mynx Book October 2007

http://slidepdf.com/reader/full/the-mynx-book-october-2007 140/222

 Mynx Programming Language

- 140 -

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

sum = zeroInt;sum.set(zeroInt);

Example of Operator Overload to Method Invocation

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

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

Example of Default Method

 The default method of a class depends upon the functionality and use of a class. A default methodcan also be called with parameters, depending on the class.

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

Example of Default Method for Output Stream 

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

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

Example of Explicit Method for Output Stream 

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

Incomplete Methods

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

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

Page 141: The Mynx Book October 2007

8/14/2019 The Mynx Book October 2007

http://slidepdf.com/reader/full/the-mynx-book-october-2007 141/222

 Mynx Programming Language

- 141 -

abstract class ATrove as Void is

public abstract VObject get;public abstract void set(in VObject);

end class;

Example of Declaring an Incomplete Method

Page 142: The Mynx Book October 2007

8/14/2019 The Mynx Book October 2007

http://slidepdf.com/reader/full/the-mynx-book-october-2007 142/222

 Mynx Programming Language

- 142 -

Implied Methods

 A class can have a method which is implied, a method which is declared with a method header, butis 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 orabstract method declares a method but a sub-class must define it in Mynx.

Rules for Implied Methods

 An implied method is a method that is declared but not defined in the Mynx programming language. There are four rules for using implied methods in a class:

1. Only default methods of an instance can be implied, non-attributes or overloads.2. An implied method cannot flag any traps.3. An implied method can have any class access.

4. An implied method can be synchronized or asynchronous.

Declaration

 The syntax for an implied class method is similar to a normal class method header, except that afterthe is keyword follows the implied keyword without the method body definition using statements.In effect the method is implied, after the method header is declared.

public void myImpliedMethod(in Real r) is implied;public Bool executeCommand(in String s) is implied;public String getSystemAttribute(in String attr) is implied;public Ordinal getSystemTime is implied;

public sync void myImplied is implied;public async Int computeDelay is implied;

Examples of Implied Method Declaration

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

Page 143: The Mynx Book October 2007

8/14/2019 The Mynx Book October 2007

http://slidepdf.com/reader/full/the-mynx-book-october-2007 143/222

 Mynx Programming Language

- 143 -

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 aninterface. The interface is then implemented as a final class with the implied methods defined in theunderlying implementation programming language (Java or C#).

 module example.impliedMethod;

class X as Void is

public void execute(in String s) is implied;public Int doSomething(in Real r) is implied;

end class;

Example of an Implied Method Implementation

 The Mynx class with the implied method execute will cause the generation of an interface and animplementing class around the implied methods within the same namespace. The implied methodinterface and class use a “mangled” name, with a trailing underscore after the Mynx class name toavoid conflict with any Mynx class names. The interface is prefixed with _impliedI for impliedinterface, and the implementing class is prefixed with _implied before the Mynx class name.

 The implementing class then uses the implied class implementation as a class delegate, and uses aprivate 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, butthe interface ensures the implied methods are implemented, and by instantiation only those methodsare accessible in the implementing programming language. A final class provides the implementationof the interface, separating the interface to the implied method functionality from theimplementation.

 The generated Java interface for the implied method:

package example.impliedMethod;

interface _impliedIX //implied interface{

public void execute(final mynx.core.String s);public mynx.core.Int doSomething(final mynx.core.Real r);

}

Example of Java Interface for Implied Method

Page 144: The Mynx Book October 2007

8/14/2019 The Mynx Book October 2007

http://slidepdf.com/reader/full/the-mynx-book-october-2007 144/222

 Mynx Programming Language

- 144 -

 The generated Java class for the implied method:

package example.impliedMethod;

final class _impliedX implements _impliedIX //implied implementation{

public _impliedX(){} //null constructor

public final void execute(final mynx.core.String s){

//implement implied method}

public final mynx.core.Int doSomething(final mynx.core.Real r){

return null; //implement implied method}

}

Example of Java Class for Implied Method

 The implementation code generated in Java for the corresponding Mynx class:

package example.impliedMethod;

class X implements Void{

//implied methods delegateprivate final _impliedIX _implied = new  _impliedX();

public void execute(final mynx.core.String s){

this._implied.execute(s); //invoke implemented code

}

public mynx.core.Int doSomething(final mynx.core.Real r){

return this._implied.doSomething(r);}

}

Example of Java code for Mynx Class

  The interface and class are both compiled with minimum functionality implemented. Both arecompiled into Java byte code or .NET intermediate language, and all are bundled in a Java JAR 

archive or .NET assembly.

Page 145: The Mynx Book October 2007

8/14/2019 The Mynx Book October 2007

http://slidepdf.com/reader/full/the-mynx-book-october-2007 145/222

 Mynx Programming Language

- 145 -

Implied Method Diagram

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

Diagram of Implied Method

Page 146: The Mynx Book October 2007

8/14/2019 The Mynx Book October 2007

http://slidepdf.com/reader/full/the-mynx-book-october-2007 146/222

 Mynx Programming Language

- 146 -

Obviate Methods

 A visible, callable method can be obviate or removed from a Mynx class. The obviated method is“masked” out or “hidden” from any further derived class, and invoking an obviated method in aclass 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 methodsinherited 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 cannever be obviated. Class methods that are invisible from the outside of the class are already hiddenor masked out from use. Obviating a class method from the interface that is already invisible isredundant. Any method that is callable is explicitly callable; hence implicitly called methods such asconstructor, destructor, and default method cannot be obviated. Implicitly called methods areinvoked automatically in use, so obviating them can cause unexpected side effects within the class.

Rules for Obviating a Class MethodHow the method is defined, an implied method, declared, or method equivalent does not matter toobviate it. The method mode is superfluous; a constant or singular method is hidden from use, notoverridden or overloaded when obviated. A single method or multiple methods of the same namecan be obviated from a class.

 The rules for obviating a class method are:

1. A class method must be visible, protected or public access.2. An obviate method cannot be re-declared or defined in the class.3. A class cannot be abstract or virtual; the methods of the class must be defined.

4. A class method must be explicitly called, hence cannot be a constructor, destructor, ordefault method.

5. A class method cannot be overloaded with an operator.

Single Method by Signature

 A single method can be specified as the method to obviate from a class. The syntax to obviate aspecific single method is by the method name and its signature.

 method openFile(String) as void; method reset(String filename) as void; //error! Only parameter type

 method getSystemTime as void; //valid, no parameter method method convertToBase(Ordinal, Ordinal) as void; method getArgs(String[]) as void; //valid, array for method signature

Example of Method Obviation Declaration

Page 147: The Mynx Book October 2007

8/14/2019 The Mynx Book October 2007

http://slidepdf.com/reader/full/the-mynx-book-october-2007 147/222

 Mynx Programming Language

- 147 -

 The method signature is used to identify which method is obviated from the class. The methodsignature is the same unique information used to identify overloaded methods by the same name. Amethod signature consists of the method name, and the parameters to that specific method. Themethod access level, mode, return type, scope, or flagged traps are not part of the method signature.

Multiple Methods by Method NameObviating a single method can be tedious for a class with many overloaded methods by a commonmethod name, and not the method signature.

 method getln as all void; method write as all void; method putln(Int) as all void; //error! No method signature allowed method substr as all void; method callTo(Char c) as all void; //error! Parameter type, variable

Example of Obviate Method Declaration for Multiple Methods

 The method name is used, similar to method equivalents to obviate all methods in the class by thatname. Because all the methods are obviated, a specific method signature is superfluous andunnecessary. The important difference from obviating a single method is using a keyword all with amethod signature to indicate all methods for that name are obviated.

Inheritance with a Single Obviate Method

 The class Cat contains the public method wagtail, which as on operation on a cat object, wags thetail of the cat, and takes no parameters, and returns nothing when called.

class Cat as null is

//...remaining class methods, constructor

public void wagtail is//…wagtail method body

end wagtail;

end class;

Example of Class Declaring a Method

But, when another class manxCat subclasses or derives a new class from Cat, the method is nolonger valid in the subclass. The method is simply an obsolete method in the class interface.

Page 148: The Mynx Book October 2007

8/14/2019 The Mynx Book October 2007

http://slidepdf.com/reader/full/the-mynx-book-october-2007 148/222

 Mynx Programming Language

- 148 -

class manxCat as Cat is

//...remaining class methods, constructor

 method wagtail as void; //manx cat does not have a tail!

public void myManxCatMethod is

super.wagTail; //method obviated, but available within the//super-class to be invoked from the sub-class

end myManxCatMethod;

end class;

Example of Declaring an Obviate Method for Single Method

 The original method wagtail in the super class Cat is now invalid (since a Manx cat does not have atail…) obsolete or, hence in the sub-class manxCat must be made obviate. Obviating a method does

not “undefined” the method, but removes it from the class interface

  The method myManxCatMethod invokes the method wagtail in the super-class, and is a validmethod call or invocation. The method wagtail is removed from the manxCat and all further sub-class interfaces, but the method still exists in the super-class. Again, obviating a method does not“undefine” the method, but removes it from the class interface.

If a derived class from manxCat, such as a curlyManxCat that has a method wiggleEars, the method wagTail is completely absent or void from the super class.

class curlyManxCat as manxCat is

//...remaining class methods, constructorpublic void wiggleEars is

super.wagTail; //compiler error! Method does not exist!end wiggleEars;

end class;

Example Declaring an Obviate Method for Non-Existent Method

Page 149: The Mynx Book October 2007

8/14/2019 The Mynx Book October 2007

http://slidepdf.com/reader/full/the-mynx-book-october-2007 149/222

 Mynx Programming Language

- 149 -

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

Diagram of an Obviate Class

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

Page 150: The Mynx Book October 2007

8/14/2019 The Mynx Book October 2007

http://slidepdf.com/reader/full/the-mynx-book-october-2007 150/222

 Mynx Programming Language

- 150 -

Inheritance with Multiple Obviate Methods

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

class ConsoleInput as Void is

public void readln(Int) is implied;public void readln(Char) is implied;public void readln(String) is implied;public void readln(Ordinal) is implied;

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

end class;

Example of Multiple Methods in a Class

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

class getConsoleInput as ConsoleInput is

 method readln as all void;

end class;

Example of Declaring Multiple Method Obviation

 The class getConsoleInput sub-classes ConsoleInput, but also obviates all methods by the name

readln. All methods by the name readln are obviated, not just a specific method by the methodsignature. The methods are still visible, just can never be invoked from that class. The only methodthat can be invoked in the getConsoleInput class is the method getln. The method getln is a methodequivalent for all the readln methods, and not obviated.

program  useConsole is

var String input to default;

var consoleInput ci to default;var getConsoleInput gi to default;

ci.readln(input); //read a string

ci.getln(input); //read a string getln is readln

gi.readln(input); //error! Invocation of obviate method in classgi.getln(input); //ok, invokes non-obviate method of the class

end program ;

Example of Method Obviation

Page 151: The Mynx Book October 2007

8/14/2019 The Mynx Book October 2007

http://slidepdf.com/reader/full/the-mynx-book-october-2007 151/222

 Mynx Programming Language

- 151 -

Using a Class with an Obviate Method

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

program  wagTheCat is

var Cat theCat to default;var manxCat myManx to default;

theCat.wagTail; //valid method to invoke  myManx.myManxMethod; //call method which calls wagTail

  myManx.wagTail; //compiler error! method wagTail//not a member of the class interface

end program ;

Example Invoking a Class Method with Obviate Method

 The method myManxMethod internally invokes the super-class method wagtail, but explicitly calling the method that is obviated will generate a compile-time error.

 When a method is obviated, it cannot be re-defined in the class that it is obviate. Removing a classfrom the interface removes it from the complete or total class interface, not just the public orprotect externally accessible methods.

class manxCat as Cat is

//...remaining class methods, constructor

 method wagtail as void; //manx cat does not have a tail!

private wagtail is //compile error:null; //can not re-define obviated method

end wagtail;

end class;

Example of Invalid Redefinition of an Obviate Method

  The obviate method wagtail cannot be re-defined within the class, even as an internal privatemethod.

Once a method is obviated in a class, it cannot be invoked explicitly on an instance, or internally  with a sub-class.

Page 152: The Mynx Book October 2007

8/14/2019 The Mynx Book October 2007

http://slidepdf.com/reader/full/the-mynx-book-october-2007 152/222

 Mynx Programming Language

- 152 -

constant class myManxCat as manxCat is

//...remaining class methods, constructorpublic void wagtail is to super.wagtail; //compile error:

//method not found!

end class;

Example of Invoking an Obviate Method Implicitly

 The method wagtail is not in the interface of the class manxCat, so cannot be defined by calling themethod implicitly as a method equivalent. The manxCat class could call the method obviated withinit implicitly because the method wagtail is in the super-class Cat method interface of the class.

No Side Effects for Never Obviating a Method

Often in programming languages, there is a strong interdependence among the features of the

programming language. However in Mynx, with method obviation, non-use does not have any sideeffects with other features in the language.

Reason to Obviate a Method

Obviating a method is necessary when in sub-classing from a parent class; a method or methodsfrom the parent class no longer are relevant in the sub-class. Specialization of a class throughinheritance can lead to classes that the functionality interface of the parent classes is no longerrelevant to the class.

 Another reason to obviate a method from a class is when the method is deprecated, or disused from

the class. Instead of a compiler warning about using a deprecated method, the method can beremoved by obviating it from the methods available through a class.

Page 153: The Mynx Book October 2007

8/14/2019 The Mynx Book October 2007

http://slidepdf.com/reader/full/the-mynx-book-october-2007 153/222

Page 154: The Mynx Book October 2007

8/14/2019 The Mynx Book October 2007

http://slidepdf.com/reader/full/the-mynx-book-october-2007 154/222

 Mynx Programming Language

- 154 -

 Assignment

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

Operator Description Overloadis reference assignment Noas creation assignment No= overloaded assignment Yes

:= cast assignment Yes+= addition assignment No-= subtraction assignment No*= multiplication assignment No/= division assignment No%= modulus assignment No&= bitwise-and assignment No|= bitwise-inclusive-or assignment No^= bitwise-exclusive-or assignment No

>>= bitwise shift-right assignment No<<= bitwise shift-left assignment No

Table of Assignment Operators

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

Reference Assignment Operator is

  The reference assignment operator is, assigns the reference of an object to another object, and

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

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

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

Example of Reference Assignment Operator

Page 155: The Mynx Book October 2007

8/14/2019 The Mynx Book October 2007

http://slidepdf.com/reader/full/the-mynx-book-october-2007 155/222

 Mynx Programming Language

- 155 -

Creation Operator as

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

var Int x to null;var Int y to null;

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

Example of Creation Operator

Regular Assignment Operator =

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

var Int x to 3;var Int y;

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

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

Example of Regular Assignment Operator

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

//not regular assignment in declaration with initial valuevar Int x to (3); //constructor invocationvar Int y to null;

Example of Declaration with Initial Value

Page 156: The Mynx Book October 2007

8/14/2019 The Mynx Book October 2007

http://slidepdf.com/reader/full/the-mynx-book-october-2007 156/222

 Mynx Programming Language

- 156 -

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 classtype, along with a regular assignment operator, using the class assignment (which can be

overloaded).

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

y : = x ;

y = x to Real; //same as

//using the Int overload for =y.set(x to Real);

Example of Cast Assignment Operator

Dual Assignment Operation Operators

 The dual assignment operation operators are a joining of operation with assignment. Theseoperators are not directly overloaded with a method. However, the dual assignment operator istranslated into separate assignment = and the operation or operator . The general assignmentoperation expression of:

IDENTIFIER = EXPRESSION

 This expression is translated into the more verbose equivalent of:

IDENTIFIER = IDENTIFIER EXPRESSION

Essentially the identifier and the operator precede the remaining expression, which is then assignedto 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 areoverloaded.

Page 157: The Mynx Book October 2007

8/14/2019 The Mynx Book October 2007

http://slidepdf.com/reader/full/the-mynx-book-october-2007 157/222

 Mynx Programming Language

- 157 -

 Addition-Assignment Operator +=

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

overloads.

var Int x to 3;x+=7;

//similarlyx = x + 7;

//overloaded + for intx = x.add(7);

//overloaded = for setx.set( x.add(7) );

Example of Addition Assignment Operator

Subtraction-Assignment Operator -=

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

var Real r to 3.14;

r -= 1.0;

//similarlyr = r - 1 . 0 ;

//overloaded - for realr = r.sub(1.0);

//overloaded = for setx.set( x.sub(1.0) );

Example of Subtraction Assignment Operator

Page 158: The Mynx Book October 2007

8/14/2019 The Mynx Book October 2007

http://slidepdf.com/reader/full/the-mynx-book-october-2007 158/222

 Mynx Programming Language

- 158 -

Multiplication-Assignment Operator *=

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

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

var Real m  to 1.11;  m *= 2.0; //m = 2.22

//similarly  m = m * 2 . 0

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

//overloaded = for setx.set( x.mul(2.0) );

Example of Multiplication Assignment Operator

Division-Assignment Operator /=

 The division-assignment operator /= combines the possibly overloaded division operator / with theassignment operator = in a single operator. The division-assignment operator, because of the dualoperation, cannot be overloaded directly, but indirectly through division and assignment overloads.

var Int i to 4;

i / = 2 ; / / i = 2

//similarlyi = i / 2;

//overloadedi = i.div(2);

//overloaded = for setx.set( x.div(2) );

Example of Division Assignment Operator

Page 159: The Mynx Book October 2007

8/14/2019 The Mynx Book October 2007

http://slidepdf.com/reader/full/the-mynx-book-october-2007 159/222

 Mynx Programming Language

- 159 -

Modulus-Assignment Operator %=

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

overloads.

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

//similarlyj = j % 2;

//overloadedj = j.mod(2);

//overloaded = for setx.set( x.mod(2) );

Example of Modulus Assignment Operator

Bitwise-And Assignment Operator &=

 The bitwise and assignment operator &= combines the possibly overloaded bitwise and operator & with the assignment operator = in a single operator.

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

var Int x to 0XFFFF;x &= 0XFF01; //x = 0XFF01

//similarlyx = x & 0XFF01;

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

//overloaded = for setx.set( x.bitAND(0XFF01) );

Example of Bitwise And Assignment Operator

Page 160: The Mynx Book October 2007

8/14/2019 The Mynx Book October 2007

http://slidepdf.com/reader/full/the-mynx-book-october-2007 160/222

 Mynx Programming Language

- 160 -

Bitwise Inclusive-Or Assignment Operator |=

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

through bitwise inclusive or and assignment overloads.

var Int x to 0XFFFF;x |= 0XFF01; //x = 0XFFFF

//similarlyx = x | 0XFF01;

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

//overloaded = for setx.set( x.bitIOR(0XFF01) );

Example of Bitwise Inclusive Or Assignment Operator

Bitwise Exclusive-Or Assignment Operator ^=

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

var Int x to 0XFFFF;

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

//similarlyx = x ^ 0XFF01;

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

//overloaded = for setx.set( x.bitXOR(0XFF01) );

Example of Bitwise Exclusive Or Assignment Operator

Page 161: The Mynx Book October 2007

8/14/2019 The Mynx Book October 2007

http://slidepdf.com/reader/full/the-mynx-book-october-2007 161/222

 Mynx Programming Language

- 161 -

Bitwise Shift-Right Assignment Operator >>=

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

through bitwise shift-right and assignment overloads.

var Int x to 0XFFFF;x >>= 0X0001; //x = 0X7FFF

x = x >> 0X0001; //similarly

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

//overloaded = for setx.set( x.shiftRight(0X001) );

Example of Bitwise Shift Right Assignment Operator

Bitwise-Shift-Left Assignment Operator <<=

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

var Int x to 0XFFFF;x <<= 0X0001; //x = 0X1FFFE

//similarlyx = x << 0X0001;

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

//overloaded = for setx.set( x.shiftLeft(0X001) );

Example of Bitwise Shift Left Assignment Operator

Page 162: The Mynx Book October 2007

8/14/2019 The Mynx Book October 2007

http://slidepdf.com/reader/full/the-mynx-book-october-2007 162/222

 Mynx Programming Language

- 162 -

Cast Conversion

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

Cast Operator to

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

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

data to Int //cast to Int class type

obj to VObject //cast to VObject class type

Example of Cast Operator

var Int i to 123;var VObject v to null;

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

Example of Using a Cast Operator

Page 163: The Mynx Book October 2007

8/14/2019 The Mynx Book October 2007

http://slidepdf.com/reader/full/the-mynx-book-october-2007 163/222

 Mynx Programming Language

- 163 -

Casting Class and Type

In the Mynx programming language, type and class are synonymous. A class is cast or converted toanother class or type using a type cast—the to operator. Mynx uses references for all objectinstances, and a reference is an identifier or literal—but it has type or the class. Mynx is a strongly 

typed programming language, so the universal rule is that for each reference the type must be thesame or type compatible with another reference. A type cast is valid for a reference of rank zero, ascalar or the element of an array.

 There are two kinds of type casts:

1. Upward – A cast to the super-class of a class.2. Downward – A cast to the base or sub-class for a class.

Casting Type Rules

 The three rules for Mynx type casting that are:

1. Cast to immediate (directly derived) super-class type (not further up the hierarchy) and notto null.

2. Cast type to convert to other class type is explicit, not implicit or automatic.3. Cast to own type or super-type, but not to sub-class class types.

Cast Type Span

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

Cast Type Intent

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

Cast Type Limit

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

Page 164: The Mynx Book October 2007

8/14/2019 The Mynx Book October 2007

http://slidepdf.com/reader/full/the-mynx-book-october-2007 164/222

 Mynx Programming Language

- 164 -

Casting Conversion Examples

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

class superClass as null ispublic construct is null;

end class;

class baseClass as superClass ispublic construct is

super.superClass;end construct;

end class;

class subClass as baseClass ispublic construct is

super.baseClass;end construct;

end class;

Example Definition of Cast Class Types

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

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

var baseClass cls to default;

//error-type intent incompatible - need explicit type castsup is cls;

//valid type-compatible to super (super-class)sup is cls to superClass;

//valid type-compatible to base (sub-class)cls is sup to baseClass;

//valid type-compatiblecls is bas;

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

sup is sub to superClass;

//error-type limit, superClass not originally subClasssub is sup to subClass;

Example Using Type Cast of Class Types

Page 165: The Mynx Book October 2007

8/14/2019 The Mynx Book October 2007

http://slidepdf.com/reader/full/the-mynx-book-october-2007 165/222

 Mynx Programming Language

- 165 -

Logical Bitwise

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

Table of Logical Bitwise Operators

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

classes.

Logical Not Operator !

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

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

if(! logical) //logical = ! True = Falsex++;else

x--;end if;

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

if(logical.not) //logical = ! True = Falsex++;

elsex--;

end if;

Example of Logical Not Operator

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

Page 166: The Mynx Book October 2007

8/14/2019 The Mynx Book October 2007

http://slidepdf.com/reader/full/the-mynx-book-october-2007 166/222

 Mynx Programming Language

- 166 -

Logical Bitwise And Operator &

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

if( x > 0 & y < 0 )doSomething;

end if;

Example of Logical And Operator

var Int y to 0XFFFF;var Int x to 0XFFFF;

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

//overloadedx = x.bitAND(y);

Example of Logical Bitwise And Operator

Logical And Operator &&

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

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

end if;

Example of Logical And Operator

Page 167: The Mynx Book October 2007

8/14/2019 The Mynx Book October 2007

http://slidepdf.com/reader/full/the-mynx-book-october-2007 167/222

 Mynx Programming Language

- 167 -

Logical Bitwise Inclusive Or Operator |

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

if( x > 0 | y < 0 )doSomething;

end if;

Example of Logical Or Operator

var Int y to 0XFFFF;var Int x to 0XFFFF;

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

//overloadedx = x.bitOR(y);

Example of Logical Bitwise Or Operator

Logical Inclusive Or Operator ||

 The logical inclusive or operator || takes a Boolean value of true or false, and returns the logicalinclusive 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 || isoverloadable, and is overloaded in the Mynx core classes.

if( x > 0 || y < 0 )doSomething;

end if;

Example of Logical Inclusive Or Operator

Page 168: The Mynx Book October 2007

8/14/2019 The Mynx Book October 2007

http://slidepdf.com/reader/full/the-mynx-book-october-2007 168/222

 Mynx Programming Language

- 168 -

Bitwise Complement Operator ~

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

let Int b to 0X0000FFFF;b = ~b; //b = 0XFFFF0000

let Int b to 0XFFFF0000;b = ~b; //b = 0X0000FFFF;

Example of Bitwise Complement Operator

Bitwise Shift Left Operator <<

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

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

Example of Bitwise Shift Left Operator

Bitwise Shift Right Operator >>

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

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

Example of Bitwise Shift Right Operator

Logical Exclusive Or Operator ^

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

if( x > 0 ^ y < 0 )doSomething;

end if;

Example of Logical Exclusive Or Operator

Page 169: The Mynx Book October 2007

8/14/2019 The Mynx Book October 2007

http://slidepdf.com/reader/full/the-mynx-book-october-2007 169/222

 Mynx Programming Language

- 169 -

Relational

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

Operator Description== relational equality!= relational inequalityin relational instance of< relational lesser than> relational greater than

>= relational greater-equal<= relational lesser-equal

Table of Relational Operators

 There are 7 relational operators; all but the in instance of relational operator can be overloaded. The

relational operators are overloaded in the Mynx core classes. The two parent objects in the Mynxclass 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 operatorsand 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 isused to determine if two objects are equal. The equality operator returns a Bool logical value of Trueor False. The equality operator requires two objects be of the same type class, otherwise the equality is a indeterminate comparison.

var Int x,y to 3;

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

end if;

//overloadedif(x.isEqual(y))

x.doSomething(y);end if;

Example of Equality Operator

Page 170: The Mynx Book October 2007

8/14/2019 The Mynx Book October 2007

http://slidepdf.com/reader/full/the-mynx-book-october-2007 170/222

 Mynx Programming Language

- 170 -

Inequality Operator !=

 The inequality operator != is overloaded with the method isUnequal in the Mynx class VObject, andis 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 Boollogical value of True or False, and requires both objects being compared for inequality be the sametype class.

var Int i,j to 3;

if(i != j)return i;

elsereturn j;

end if;

//overloadedif(i.isUnequal(j))

return i;else

return j;end if;

Example of Inequality Operator

Page 171: The Mynx Book October 2007

8/14/2019 The Mynx Book October 2007

http://slidepdf.com/reader/full/the-mynx-book-october-2007 171/222

 Mynx Programming Language

- 171 -

Instance Type Of Operator in

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

 virtual class Void. Unlike the other logical operators, the in operator is not overloadable.

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

end if;

Example of In instance-of Class Operator

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

different type of object references cannot reference the same object.

var String x to “hello”;var String y to null;

y is x; //equate y with x

if(x in y)doSomething;

end if;

Example of in Instance Operator

Lesser Than Operator <

 The relational lesser than operator < is used in comparison, and for two objects of the same typethat are unequal. The definition of a lesser-than ordering is an ordering feature of the class whichdefines it. The core Mynx types such as String, Char, Int, Real, Float, Ordinal, Byte, UnsignedBytehave the relational lesser than operator and the ordering defined already.

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

if(j < k)handleInt(k);

elsehandleInt(j);

end if;

Example of Less Than Operator

Page 172: The Mynx Book October 2007

8/14/2019 The Mynx Book October 2007

http://slidepdf.com/reader/full/the-mynx-book-october-2007 172/222

 Mynx Programming Language

- 172 -

Greater Than Operator >

 The relational greater than operator > is used in comparison, and for two objects of the same typethat are unequal. The definition of greater-than ordering is an ordering feature of the class thatdefines it. The core Mynx types such as String, Char, Int, Real, Float, Ordinal, Byte, UnsignedByte

have the relational greater than operator and the ordering defined already.

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

if(k > j)handleInt(k);

elsehandleInt(j);

end if;

Example of Greater Than Operator

Greater Equal Operator >=

 The relational greater than equal operator >= is a logical inclusive or of the equality and greater thanrelation 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 Mynxtypes such as String, Char, Int, Real, Float, Ordinal, Byte, UnsignedByte have the relational greaterequal operator and the ordering defined already. For some classes the greater equal operator simply uses each of the base operators of equality and greater than to define greater equal.

var Char c to ‘ ’;//space charactervar Char d to 32; //space character with ASCII value

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

end while;

Example of Greater Than Equal Operator

Page 173: The Mynx Book October 2007

8/14/2019 The Mynx Book October 2007

http://slidepdf.com/reader/full/the-mynx-book-october-2007 173/222

 Mynx Programming Language

- 173 -

Lesser Equal Operator <=

 The relational lesser than equal operator <= is a logical inclusive or of the equality and lesser thanrelation operator.

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

Page 174: The Mynx Book October 2007

8/14/2019 The Mynx Book October 2007

http://slidepdf.com/reader/full/the-mynx-book-october-2007 174/222

 Mynx Programming Language

- 174 -

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.

Table of Stream Operators

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

Insertion Operator <<<

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

var IOStream IO to default;

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

Example of Insertion Stream Operator

Extraction Operator >>>

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

overloadable.

var IOStream IO to default;

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

Example of Extraction Stream Operator

 with mynx.core.IOStream;

var IOStream IO to default;

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

Example of Overloaded Stream Operators

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

Page 175: The Mynx Book October 2007

8/14/2019 The Mynx Book October 2007

http://slidepdf.com/reader/full/the-mynx-book-october-2007 175/222

 Mynx Programming Language

- 175 -

Mathematic

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

Operator Description+ Addition- Subtraction/ Division% Modulo or Remainder* Multiplication

** Exponentiation or Power of++ Integral Increment-- Integral Decrement

Table of Mathematic Operators

 All 8 mathematical operators can be overloaded, and are overloaded for the core or foundation

Mynx classes. If an operator results in an integral or real value that exceeds the size for a numerictype, it will flag an overflow or underflow trap.

 Addition Operator +

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

var Int x,y to 1;

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

Example of Addition Operator

Subtraction Operator -

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

var Int i,j to 1;

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

Example of Subtraction Operator

Page 176: The Mynx Book October 2007

8/14/2019 The Mynx Book October 2007

http://slidepdf.com/reader/full/the-mynx-book-october-2007 176/222

 Mynx Programming Language

- 176 -

Division Operator /

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

var Int p,q to 1;IO.putln(p/q);IO.putln(p.div(q));

Example of Division Operator

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

Modulus Operator %

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

var Int p,q to 1;IO.putln(p % q);IO.putln(p.mod(q));

Example of Modulus Operator

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

var Int p,q to 1;

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

Example of Multiplication Operator

Page 177: The Mynx Book October 2007

8/14/2019 The Mynx Book October 2007

http://slidepdf.com/reader/full/the-mynx-book-october-2007 177/222

 Mynx Programming Language

- 177 -

Exponentiation Operator **

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

var Int i to 10;

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

Example of Exponentiation Operator

Increment Operator ++

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

var Int i to 0;i++;

//similarlyi.inc;

Example of Post-Increment Operator

Decrement Operator --

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

var Int i to 0;i--;

//similarlyi.dec;

Example of Post-Decrement Operator

Page 178: The Mynx Book October 2007

8/14/2019 The Mynx Book October 2007

http://slidepdf.com/reader/full/the-mynx-book-october-2007 178/222

 Mynx Programming Language

- 178 -

 Access

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

Operator Description. method access` attribute access

[] array access

Table of Access Operators

 The access operators allow for accessing information of instances, through methods (messaging inobject-oriented parlance), attributes, and through arrays (which are multiple attributes bound to aninstance). 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 methodinvocation simply uses the method name.

this.myMethod(3); //explicit instance method invocationsuper.aMethod; //explicit super class method invocationx.doSomething //explicit instance variable invocationcallAMethod; //implicit method invocation

Example of Method Access or Invocation

Page 179: The Mynx Book October 2007

8/14/2019 The Mynx Book October 2007

http://slidepdf.com/reader/full/the-mynx-book-october-2007 179/222

 Mynx Programming Language

- 179 -

 Attribute Access `

 Attribute access gets the attribute reference from an instance variable, or instance class, or the superclass. The tic ‘`’ separates the instance name from the attribute reference. Because of the differentaccess 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 samename and type as the attribute. If not implicitly disambiguated, then an explicit tic must be used todistinguish the attribute access.

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

this`MAXIMUMsuper`varex`value_ getItx_ 

Example of Attribute Access

 Array Access [ ]

 An attribute is one instance of data with a variable name. Multiple instances of attributes can becreated 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 commato separate each index for each dimension. The index does not have to be a literal integer value, itcan be an expression, variable, or method call. As an attribute, the array has to be accessed using explicit tic ‘`’ with an instance reference with a name, or implicitly with only the attribute name.

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

Example of Array Access

Page 180: The Mynx Book October 2007

8/14/2019 The Mynx Book October 2007

http://slidepdf.com/reader/full/the-mynx-book-october-2007 180/222

 Mynx Programming Language

- 180 -

Operator Precedence

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

Level Operator Category Description0 . ̀ [] Access Invoke and Access1 ++ -- Mathematic Increment, Decrement1 ~ Logical Bitwise1 ! Logical Logical Not1 := Assignment Cast Assignment2 ** * / % Mathematic Multipy, Divide, Remainder3 + - Mathematic Addition, Subtraction4 << >> Bitwise Shift5 < <= > >= Relational5 in Relational Relational Instance6 == != Relational Equality and Inequality

7 & Logical Bitwise And8 ^ Bitwise Exclusive Or9 | Bitwise Inclusion Or

10 && Logical And11 || Logical Or12 = is as Assignment or

Creation12 <<< >>> Stream  12 += -= *= /= %=

&= |= ^= <<= >>=  Assignment Operation Dual Assignment Operators

Table of Operator Precedence

Page 181: The Mynx Book October 2007

8/14/2019 The Mynx Book October 2007

http://slidepdf.com/reader/full/the-mynx-book-october-2007 181/222

 Mynx Programming Language

- 181 -

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 permitscleaner expressions with shorter notation for classes. Only a certain set of operators are possible to

overload, and in some classes, some operators are restricted from further overload.

Operator Overload Declaration

 An operator overload is declared like a method or attribute, except without any scope or access. Anoverload 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 animplicit default overload. The operator is then specified, followed by the keyword as, with themethod identifier.

Kinds of Overloads

 There are two types of operator overloads:

1. default - operator can be overloaded in a sub-class2. constant - operator cannot be overloaded again

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

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

Page 182: The Mynx Book October 2007

8/14/2019 The Mynx Book October 2007

http://slidepdf.com/reader/full/the-mynx-book-october-2007 182/222

 Mynx Programming Language

- 182 -

Rules for Operator Overloading 

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

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

Page 183: The Mynx Book October 2007

8/14/2019 The Mynx Book October 2007

http://slidepdf.com/reader/full/the-mynx-book-october-2007 183/222

 Mynx Programming Language

- 183 -

class String as VObject, Void is

public String concat(in String str) is//define the method

end concat;

overload constant + as concat;

end class;

class subString as String, Void is

public String concat(in String str) is//define the method

end concat;

//reference and re-use constant overload in super-classoverload constant in String is + as concat;

end class;

Example of Operator Overloading with Constant Overload

class Integer as VObject, Void, VNumber is

overload default + as add;overload default * as mul;

end class;

class subInteger as VObject, Void, VNumber is

//re-overload operator with new method

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

end class;

Example of Operator Overload with Default

Page 184: The Mynx Book October 2007

8/14/2019 The Mynx Book October 2007

http://slidepdf.com/reader/full/the-mynx-book-october-2007 184/222

 Mynx Programming Language

- 184 -

class Group as Void is

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

end class;

class subGroup2 as Group is

//re-overload operator with new method as constantoverload constant + as transitive;

//reference overloaded operator in parentoverload constant in Group is * as commutative;

overload default - as relative;

end class;

Example of Operator Overload from Default to Constant

Page 185: The Mynx Book October 2007

8/14/2019 The Mynx Book October 2007

http://slidepdf.com/reader/full/the-mynx-book-october-2007 185/222

 Mynx Programming Language

- 185 -

 Table of Operators

Op Level Type Name Overload Category

! 1 Prefix Logical Not Yes Logical Bitwise!= 6 Infix Inequality Yes Relational

% 2 Infix Modulus Yes Mathematical%= 12 Infix Modulus Assignment No Assignment&& 10 Infix Logical And Yes Logical Bitwise& 7 Infix Bitwise Logical And Yes Logical Bitwise

&= 12 Infix Bitwise And Assignment No Assignment* 2 Infix Multiply Yes Mathematical

** 2 Infix Exponentiation Yes Mathematical*= 12 Infix Multiply Assignment No Assignment+ 3 Infix Addition Yes Mathematical

++ 1 Postfix Increment Yes Mathematical+= 12 Infix Addition Assignment No Assignment- 3 Infix Subtract Yes Mathematical

-- 1 Postfix Decrement Yes Mathematical

-= 12 Infix Subtract Assignment No Assignment. 0 Infix Method Access No Access/ 2 Infix Division Yes Mathematical

/= 12 Infix Division Assignment No Assignment:= 1 Infix Cast Assignment Yes Assignment< 5 Infix Less Than Yes Relational

<< 4 Infix Shift Left Yes Logical Bitwise<<< 12 Infix Insertion Yes Stream  <<= 12 Infix Shift Left Assignment No Assignment<= 5 Infix Less Than Equal Yes Relational= 12 Infix Assignment Yes Assignment

== 6 Infix Equality Yes Relational> 5 Infix Greater Than Yes Relational

>= 5 Infix Greater Than Equal Yes Relational>> 4 Infix Shift Right Yes Bitwise Logical

>>= 12 Infix Shift Right Assignment No Assignment>>> 12 Infix Extraction Yes Stream  [] 0 Infix Array Access No Access^ 8 Infix Bitwise Inclusive Or Yes Bitwise Logical

^= 12 Infix Bitwise Exclusive Or Assign No Assignment` 0 Infix Attribute Access No Access

in 5 Infix Instance Of No Relationalis 12 Infix Reference Assignment No Assignmentas 12 Infix Instance Creation No Assignment| 9 Infix Bitwise Inclusive Or Yes Logical Bitwise

|= 12 Infix Bitwise Inclusive Or Assign No Assignment

|| 11 Infix Logical Or Yes Logical Bitwise~ 1 Prefix Complement Yes Logical Bitwise

Table of Operators, Precedence, and Overloaded

Page 186: The Mynx Book October 2007

8/14/2019 The Mynx Book October 2007

http://slidepdf.com/reader/full/the-mynx-book-october-2007 186/222

 Mynx Programming Language

- 186 -

Standard Method Names for Overloads

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

Table of Standard Operator Overloads by Method Name

Operator Operator Name Standard Method Overload= Assignment set, setIs

:= Cast Assign setAs! Logical Not not& Bitwise And bitAnd andis

&& Logical And and| Bitwise Inclusive Or bitOr oris

|| Logical Or or~ Bitwise Not bitNot

<< Bitwise Shift Left bitShl>> Bitwise Shift Right bitShr^ Bitwise Exclusive Or bitXor< Relational Lesser Than isLT> Relational Greater Than isGT

== Relational Equality isEqual isEQ!= Relational Inequality isUnequal isNE>= Relational Greater Equal isGE<= Relational Lesser Equal isLE

<<< Stream Insertion put>>> Stream Extraction get

% Math Modulus mod* Math Multiply mul

** Math Power Of pow+ Math Addition add

++ Math Increment inc-- Math Decrement dec

- Math Subtraction sub/ Math Division div

Page 187: The Mynx Book October 2007

8/14/2019 The Mynx Book October 2007

http://slidepdf.com/reader/full/the-mynx-book-october-2007 187/222

 Mynx Programming Language

- 187 -

Implicit Hierarchy of Operators

 The operators in Mynx that are overloaded have an implicit hierarchy. The operator overloads canchange, but the implicit hierarchy cannot change. The implicit hierarchy of overloaded operators istranslated by Mynx into the equivalent method calls for the methods that are overloaded. In the

process of translation, the operator hierarchy is preserved.

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

Diagram of Hierarchy of Operators for Expression

Page 188: The Mynx Book October 2007

8/14/2019 The Mynx Book October 2007

http://slidepdf.com/reader/full/the-mynx-book-october-2007 188/222

 Mynx Programming Language

- 188 -

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

Diagram of Hierarchy of Operators with Methods for Expression

Page 189: The Mynx Book October 2007

8/14/2019 The Mynx Book October 2007

http://slidepdf.com/reader/full/the-mynx-book-october-2007 189/222

 Mynx Programming Language

- 189 -

 Appendices

Page 190: The Mynx Book October 2007

8/14/2019 The Mynx Book October 2007

http://slidepdf.com/reader/full/the-mynx-book-october-2007 190/222

 Mynx Programming Language

- 190 -

Page 191: The Mynx Book October 2007

8/14/2019 The Mynx Book October 2007

http://slidepdf.com/reader/full/the-mynx-book-october-2007 191/222

 Mynx Programming Language

- 191 -

 Appendix - Mynx Grammar

Header Syntax

START := HEADER (CLASSES | PROGRAM)HEADER := [MODULE](WITH)

*

MODULE := module ( default | NAME ) ‘;’WITH := with NAME [‘.’ ‘*’] ‘;’

Class Syntax

CLASSES := CLASS (CLASS)*

CLASS := [CLASS_MODE] class ID [as (IDLIST | null  )][has ID to ID] is (CLASS_BODY)*

end class ‘;’CLASS_MODE := abstract  | constant  | default  | generic  | singular  | static  | virtual CLASS_BODY := CLASS_METHOD | CLASS_ATTRIBUTE | CLASS_OVERLOAD | CLASS_OBVIATE

| CONSTRUCT | DESTRUCT | DEFAULT

Class Methods

CLASS_METHOD := METHOD_HEADER [is (METHOD_EQUIV| implied  | METHOD_BODY) ] ‘;’

METHOD_EQUIV := to (null  | METHOD_EQUAL)METHOD_HEADER := ACCESS [SYNC][METHOD_MODE][METHOD_TYPE] ID [ ARGS][TRAPS][SCOPE]SYNC := async  | sync METHOD_MODE := abstract  | constant  | covariant  | default  | singular  | static  | virtual METHOD_TYPE := (ID | generic ) [DIMLIST] | void TRAPS := has IDLIST  ARGS := ‘(‘[FIXED_ARGS (‘,’ FIXED_ARGS)

*] [‘,’ VARY_ARGS] ‘)’

FIXED_ARGS := [in | out  | var ] (ID | generic  | self ) [DIM_LIST] IDVARY_ARGS := series (ID | generic  | self  ) DIM_LIST ID  ACCESS :=public  | protect | privateMETHOD_EQUAL := ( [METHOD_PREFIX] | this ) ID [ ARGLIST]SCOPE := (in | out ) for (all  | null | IDLIST)METHOD_BODY := STATEMENTS end  IDMETHOD_PREFIX := (super  | this | self  | ID ) ‘.’CONSTRUCT := ACCESS construct  [ ARGS][SCOPE] is [METHOD_EQUIV | CONSTRUCT_BODY] ‘;’

CONSTRUCT_BODY := STATEMENTS end construct DESTRUCT := ACCESS destruct is [METHOD_EQUIV | DESTRUCT_BODY] ‘;’DESTRUCT_BODY := STATEMENTS end destruct DEFAULT := ACCESS default is to ( ID | null ) ‘;’

Class Attribute

CLASS_ATTRIBUTE := ACCESS [ ATTRIBUTE_MODE][ ATTRIBUTE_KIND] ATTRIBUTE to INIT [SCOPE] ‘;’  ATTRIBUTE_MODE :=default  | volatile  ATTRIBUTE_KIND :=constant  | singular | static  | variable  ATTRIBUTE :=(generic  | ID) [to ID] [DIMLIST] IDLIST

Class Overload

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

Class Method Obviate

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

*

PARAM := ID [PARAMDIM]

PARAMDIM := ‘[‘ [STARLIST] ‘]’

Page 192: The Mynx Book October 2007

8/14/2019 The Mynx Book October 2007

http://slidepdf.com/reader/full/the-mynx-book-october-2007 192/222

 Mynx Programming Language

- 192 -

Program

PROGRAM := program ID [as ID] is (STATEMENTS|PROGRAM_BODY) end program ‘;’ PROGRAM_BODY := (PROGRAM_ATTRIBUTE | PROGRAM_METHOD)

+

PROGRAM_KIND := constant  | variablePROGRAM_ATTRIBUTE := let  [PROGRAM_KIND] DECLARE [SCOPE] ‘;’ PROGRAM_METHOD := method  [LIMITED_MODE][LIMITED_TYPE] ID [ ARGS][TRAPS][SCOPE] is

STATEMENTS end  ID ‘;’LIMITED_MODE := default | static 

LIMITED_TYPE := ID [DIMLIST] | void 

Statements

STATEMENTS := STATEMENT ‘;’ (STATEMENT ‘;’)*

STATEMENT := ASSERT_STATEMENT | CASE_STATEMENT | EXPRESSION_STATEMENT| EXIT_STATEMENT | FLAG_STATEMENT | FOR_STATEMENT| IF_STATEMENT | LOOP_STATEMENT | MUTEX_STATEMENT| NEXT_STATEMENT | NULL_STATEMENT | REPEAT_STATEMENT| RETURN_STATEMENT| TRY_STATEMENT | UNTIL_STATEMENT| WHILE_STATEMENT

  ASSERT_STATEMENT :=assert  ‘(‘ EXPR ‘)’ [as STRINGLIT]CASE_ STATEMENT := case ‘(‘ EXPR ‘)’ CASE_BODY {CASE_BODY} [ else STATEMENTS] end caseCASE_BODY := as EXPRLIST is STATEMENTSEXIT_STATEMENT := exit  [ (for  | loop | repeat  |until | while) [NESTING] ] [ if  ‘(‘ EXPR ‘)’ ]FLAG_ STATEMENT := flag  ID [ARGLIST]FOR_STATEMENT := for  ‘(‘ (FOR_INT | FOR_EACH) ‘)’ STATEMENTS end for [NESTING]FORINT := [ID] ID is EXPR to EXPRFOREACH := ID ID in EXPRIF_STATEMENT := if  ‘(‘ EXPR ‘)’ STATEMENTS {IF_BODY}

*[else STATEMENTS] end if 

IF_BODY := elif ‘(‘ EXPR ‘)’ STATEMENTSLOOP_STATEMENT := loop STATEMENTS end loop [NESTING]MUTEX_STATEMENT := mutex  ‘(‘ EXPR ‘)’ STATEMENTS end mutex NEXT_STATEMENT := next  [ (for  | loop | repeat  |until | while) [NESTING] ] [if  ‘(‘ EXPR ‘)’ ]NULL_STATEMENT := null REPEAT_STATEMENT := repeat  STATEMENTS ( until | while ) [NESTING] ‘(‘ EXPR ’)’

RETURN_STATEMENT := return [‘(‘ EXPR ‘)’]TRY_STATEMENT := try STATEMENTS (TRY_WHEN) (TRY_WHEN)

*TRY_LAST end try 

TRY_WHEN := when ‘(‘ ID [ID] ‘)’ STATEMENTSTRY_LAST := [else STATEMENTS][do STATEMENTS]UNTIL_STATEMENT := until ‘(‘ EXPR ’)’ STATEMENTS end until [NESTING]WHILE_STATEMENT := while ‘(‘ EXPR ’)’ STATEMENTS end while [NESTING]NESTING := ‘(‘ DECIMALINT ‘)’

Page 193: The Mynx Book October 2007

8/14/2019 The Mynx Book October 2007

http://slidepdf.com/reader/full/the-mynx-book-october-2007 193/222

 Mynx Programming Language

- 193 -

Expression Statements

EXPRESSIONSTATEMENT := ASSIGN | var  DECLAREDECLARE := ID [DIMLIST] IDLIST [to INIT]IDLIST := ID ( ‘,’ ID )

*

INIT := default | null | INITLIST | [‘(‘] EXPRLIST [‘)’]INITLIST := ‘{‘ EXPRLIST | INDEXLIST ‘}’

INDEXITEM := STARLIST | (INT_LITERAL ‘,’ INT_LITERAL )*

INDEXLIST := INDEXITEM ‘:’ EXPR (‘ ,’ INDEXITEM ‘ :’ EXPR)*

  ASSIGN := POSTFIX[ ASSIGNOP EXPR | STREAMOP EXPR (STREAMOP EXPR)*

]EXPR := LOGEXPR ( ‘||’ LOGEXPR )

*

LOGEXPR := INCEXPR ( ‘&&’ INCEXPR )*

INCEXPR := XOREXPR ( ‘|’ XOREXPR )*

XOREXPR := ANDEXPR ( ‘^’ ANDEXPR )*

  ANDEXPR := EQUEXPR( ‘&’ EQUEXPR )*

EQUEXPR := RELEXPR ( ( ‘==’|’!=’|in) RELEXPR )*

RELEXPR := SHIFTEXPR ( (‘<’|’>’|’<=’|’>=’) SHIFTEXPR )*

SHIFTEXPR := ADDEXPR ( (‘<<’|’>>’) ADDEXPR )*

  ADDEXPR := MULEXPR( (‘+’|’-‘) MULEXPR )*

MULEXPR := CASTEXPR ( (‘*’|’%’|’/’|’**’) CASTEXPR )*

CASTEXPR := [‘!’|‘~’ |’+’|’-‘] POSTFIX [to NAME]POSTFIX := PRIMARY [ ARGLIST | ARRAYCALL]

( ATTRIBUTECALL [ ARRAYCALL] | METHODCALL)* [‘++’|’—-‘]  ARRAYCALL := ‘[‘ EXPRLIST ‘]’  ATTRIBUTECALL := ‘`’ ID

METHODCALL := ‘.’ ID [ ARGLIST]  ARGLIST := ‘(‘ EXPRLIST ‘)’DIMLIST := ‘[‘ [STARLIST|EXPRLIST] ‘]’STARLIST := ‘*’ (‘,’ ‘*’)

*

EXPRLIST := EXPR (‘,’ EXPR)*

NAME := ID (‘.’ ID)*

PRIMARY := ID | this | self  | super | null | LITERAL | ‘(‘ EXPR ‘)’

Lexical Elements

LITERAL := DECIMALINT | HEXINT | REALLIT | CHARLIT | STRINGLIT | INT

LITERAL_LiST := LITERAL (‘,’ LITERAL)*

DECIMALINT := DIGIT (DIGIT)*

INT := DECIMALINTHEXINT := ‘0X’ HEXDIGIT (HEXDIGIT)

*

DIGIT := ‘0’ | ‘1’ | ‘2’ | ‘3’ | ‘4’ | ‘5’ | ‘6’ | ‘7’ | ‘8’ | ‘9’LETTERCHAR := ‘a’ | ‘b’ | ‘c’ | ‘d’ | ‘e’ | ‘f’| ‘g’| ‘h’ | ‘i’ | ‘j’ | ‘k’| ‘l’ | ‘m’| ‘n’ | ‘o’ | ‘p’ | ‘q’ | ‘r’| ‘s’| ‘t’ | ‘u’ | ‘v’ | ‘w’| ‘x’ |‘y’|‘z’

| ‘A’ | ‘B’| ‘C’| ‘D’| ‘E’| ‘F’ | ‘G’ | ‘H’ | ‘I’| ‘J’| ‘K’| ‘L’ | ‘M’ | ‘N’ | ‘O’ | ‘P’| ‘Q’| ‘R’ | ‘S’ | ‘T’ | ‘U’| ‘V’| ‘W’|‘X’| ‘Y’ | ‘Z’

HEXDIGIT := DIGIT | ‘A’ | ‘B’ | ‘C’ | ‘D’ | ‘E’ | ‘F’CHARLIT := ‘‘ ’ UN ICODECHAR ( UNICODECHAR )

*‘‘’| ESCAPECHAR

| ‘‘’ ‘\u’ HEXDIGIT HEXDIGIT HEXDIGIT HEXDIGIT ‘‘’

ESCAPECHAR := ‘\n’ | ‘\r’ | ‘\t’ | ‘\b’ | ‘\f’ | ‘\\’ | ‘\”’ | ‘\’’STRINGLIT := ‘“’ UNICODECHAR (UNICODECHAR)

*‘“’

METASTRING := ‘#’ IDUNICODECHAR := 000016 … FFFF16

REALLIT := [(‘+’|’-‘)]( DIGIT (DIGIT)*

‘.’ (DIGIT)*

| ‘.’ DIGIT (DIGIT)*

[‘E’(‘+’|’-‘) DECIMALINT ][‘F’]ID := LETTERCHAR (UNICODECHAR | DIGIT | ‘_’ | LETTERCHAR)

*

  ASSIGNOP := ‘=’| as | is | ‘:=’|‘+=’|‘-=’|‘*=’|‘/=’|‘%=’|‘&=’|‘|=’|‘^=’|‘>>=’|‘<<=’LOGICALBITOP := ‘!’ | ‘&’ | ‘&&’ | ‘|’ | ‘||’ | ‘~’ | ‘<<’ | ‘>>’ | ‘^’RELATIONALOP := ‘<’ | ‘>’ | ‘==’ | ‘!=’ | ‘>=’ | ‘<=’ | inSTREAMOP := ‘<<<’ | ‘>>>’MATHOP := ‘%’ | ‘*’ | ‘**’ | ‘+’ | ‘++’ | ‘-‘ | ‘—‘ | ‘/’OP := ASSIGNOP | LOGICALBITOP | RELATIONALOP | STREAMOP | MATHOP

Page 194: The Mynx Book October 2007

8/14/2019 The Mynx Book October 2007

http://slidepdf.com/reader/full/the-mynx-book-october-2007 194/222

 Mynx Programming Language

- 194 -

Comments

COMMENT := ‘//’ (UNICODECHAR)*

(‘\n’ | ‘\r’ | ‘\n’ ‘\r’) | ‘!!’ (UNICODECHAR)*

‘!!’

Page 195: The Mynx Book October 2007

8/14/2019 The Mynx Book October 2007

http://slidepdf.com/reader/full/the-mynx-book-october-2007 195/222

 Mynx Programming Language

- 195 -

 Appendix - Mynx File Types and Tools

 There are six major Mynx file types used by different Mynx tools. Each Mynx tool uses the name of the file extension. Instead of appending a character ‘c’ at the end of the compiler name, like mynxc,the compiler is the same as the file extension mynx.

Table of Mynx File Types and Tools

Mynx

 A Mynx file type has the .mynx file extension, and mynx is the compiler tool name. A single Mynxclass or program has the same name as the file. So a program with the name helloWorld would be ina helloWorld.mynx file. Multiple private classes can be included with a public class.

Myxm

 A file with multiple Mynx classes all public is a .myxm file extension. MYXM is an anagram forMYnX Multiple classes file type. The tool myxm separates and into individual Mynx class files, and

compiles the multiple Mynx classes.

Moxi

 A Moxi or Mynx Object XML I nterface file is the XML interface for a Mynx class, used by thecompiler 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-classbrowser, showing a class in a module namespace, the methods, attributes, obviates, and overloads.

Myna

 A myna or Mynx Archive is a ZIP-compatible archive file format. The Mynx tool allows adding, viewing, extracting, and deleting files from the archive file. A myna file can be processed by otherZIP-compatible programs.

Tool Name/File Extension File Type  mynx source code file, one public class, with

one or more private classes,or one program 

  myxm MYnX Multiple source code file,  multiple public classes

  moxi Mynx Object Xml Interface class file  myna MYNx Archive file in ZIP format  minx Mynx Intermediate XML code file  myxd MYnx Xml Documentation generator

Page 196: The Mynx Book October 2007

8/14/2019 The Mynx Book October 2007

http://slidepdf.com/reader/full/the-mynx-book-october-2007 196/222

 Mynx Programming Language

- 196 -

Minx

  A .minx file type is the end result of compiling Mynx into an intermediate platform-independentrepresentation in XML. Hence MINX is the acronym (and similar pronunciation as Mynx theprogramming 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 istransformed into HTML to place of Mynx code on the Internet.

Myxd

 The myxd file type and tool is for the MYnx XML Documentation generator, which processes aMynx or Myxm source file and generates a myxd documentation file. The myxd tool allows thedocumentation to be browsed and searched interactively.

Page 197: The Mynx Book October 2007

8/14/2019 The Mynx Book October 2007

http://slidepdf.com/reader/full/the-mynx-book-october-2007 197/222

 Mynx Programming Language

- 197 -

 Appendix – GNU Free Documentation License

GNU Free Documentation License Version 1.2, November 2002

Copyright (C) 2000, 2001, 2002 Free Software Foundation, Inc.51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA

Everyone is permitted to copy and distribute verbatim copiesof this license document, but changing it is not allowed.

0. PREAMBLE

 The purpose of this License is to make a manual, textbook, or other functional and useful document"free" in the sense of freedom: to assure everyone the effective freedom to copy and redistribute it,

  with or without modifying it, either commercially or noncommercially. Secondarily, this Licensepreserves for the author and publisher a way to get credit for their work, while not being consideredresponsible for modifications made by others.

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

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

1. APPLICABILITY AND DEFINITIONS

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

 A "Modified Version" of the Document means any work containing the Document or a portion of 

it, either copied verbatim, or with modifications and/or translated into another language.

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

Page 198: The Mynx Book October 2007

8/14/2019 The Mynx Book October 2007

http://slidepdf.com/reader/full/the-mynx-book-october-2007 198/222

 Mynx Programming Language

- 198 -

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

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

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

  A "Transparent" copy of the Document means a machine-readable copy, represented in a format  whose specification is available to the general public, that is suitable for revising the documentstraightforwardly with generic text editors or (for images composed of pixels) generic paintprograms or (for drawings) some widely available drawing editor, and that is suitable for input to

text formatters or for automatic translation to a variety of formats suitable for input to textformatters. A copy made in an otherwise Transparent file format whose markup, or absence of markup, has been arranged to thwart or discourage subsequent modification by readers is not

 Transparent. An image format is not Transparent if used for any substantial amount of text. A copy that is not "Transparent" is called "Opaque".

Examples of suitable formats for Transparent copies include plain ASCII without markup, Texinfoinput format, LaTeX input format, SGML or XML using a publicly available DTD, and standard-conforming simple HTML, PostScript or PDF designed for human modification. Examples of transparent image formats include PNG, XCF and JPG. Opaque formats include proprietary formats that can be read and edited only by proprietary word processors, SGML or XML for which

the DTD and/or processing tools are not generally available, and the machine-generated HTML,PostScript or PDF produced by some word processors for output purposes only.

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

 A section "Entitled XYZ" means a named subunit of the Document whose title either is precisely XYZ or contains XYZ in parentheses following text that translates XYZ in another language. (HereXYZ stands for a specific section name mentioned below, such as "Acknowledgements",

"Dedications", "Endorsements", or "History".) To "Preserve the Title" of such a section when youmodify the Document means that it remains a section "Entitled XYZ" according to this definition.

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

Page 199: The Mynx Book October 2007

8/14/2019 The Mynx Book October 2007

http://slidepdf.com/reader/full/the-mynx-book-october-2007 199/222

 Mynx Programming Language

- 199 -

2. VERBATIM COPYING

  You may copy and distribute the Document in any medium, either commercially ornoncommercially, provided that this License, the copyright notices, and the license notice saying thisLicense applies to the Document are reproduced in all copies, and that you add no other conditions

 whatsoever to those of this License. You may not use technical measures to obstruct or control thereading or further copying of the copies you make or distribute. However, you may acceptcompensation in exchange for copies. If you distribute a large enough number of copies you mustalso follow the conditions in section 3.

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

3. COPYING IN QUANTITY 

If you publish printed copies (or copies in media that commonly have printed covers) of theDocument, numbering more than 100, and the Document's license notice requires Cover Texts, you

must enclose the copies in covers that carry, clearly and legibly, all these Cover Texts: Front-Cover Texts on the front cover, and Back-Cover Texts on the back cover. Both covers must also clearly and legibly identify you as the publisher of these copies. The front cover must present the full title

 with all words of the title equally prominent and visible. You may add other material on the coversin addition.

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

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

If you publish or distribute Opaque copies of the Document numbering more than 100, you musteither include a machine-readable Transparent copy along with each Opaque copy, or state in or

 with each Opaque copy a computer-network location from which the general network-using publichas access to download using public-standard network protocols a complete Transparent copy of the Document, free of added material. If you use the latter option, you must take reasonably prudentsteps, when you begin distribution of Opaque copies in quantity, to ensure that this Transparentcopy will remain thus accessible at the stated location until at least one year after the last time youdistribute an Opaque copy (directly or through your agents or retailers) of that edition to the public.

It is requested, but not required, that you contact the authors of the Document well before

redistributing any large number of copies, to give them a chance to provide you with an updated version of the Document.

4. MODIFICATIONS

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

Page 200: The Mynx Book October 2007

8/14/2019 The Mynx Book October 2007

http://slidepdf.com/reader/full/the-mynx-book-october-2007 200/222

 Mynx Programming Language

- 200 -

the Modified Version to whoever possesses a copy of it. In addition, you must do these things inthe Modified Version:

 A. Use in the Title Page (and on the covers, if any) a title distinct from that of the Document,and from those of previous versions (which should, if there were any, be listed in the History section of the Document). You may use the same title as a previous version if the originalpublisher of that version gives permission.

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

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

D. Preserve all the copyright notices of the Document.

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

notices.

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

 Addendum below.

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

H. Include an unaltered copy of this License.

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

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

permission.

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

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

Page 201: The Mynx Book October 2007

8/14/2019 The Mynx Book October 2007

http://slidepdf.com/reader/full/the-mynx-book-october-2007 201/222

 Mynx Programming Language

- 201 -

M. Delete any section Entitled "Endorsements". Such a section may not be included in theModified Version.

N. Do not retitle any existing section to be Entitled "Endorsements" or to conflict in title withany Invariant Section.

O. Preserve any Warranty Disclaimers.

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

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

 You may add a passage of up to five words as a Front-Cover Text, and a passage of up to 25 words

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

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

5. COMBINING DOCUMENTS

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

 Warranty Disclaimers.

  The combined work need only contain one copy of this License, and multiple identical InvariantSections may be replaced with a single copy. If there are multiple Invariant Sections with the samename but different contents, make the title of each such section unique by adding at the end of it, inparentheses, the name of the original author or publisher of that section if known, or else a unique

number. Make the same adjustment to the section titles in the list of Invariant Sections in the licensenotice of the combined work.

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

Page 202: The Mynx Book October 2007

8/14/2019 The Mynx Book October 2007

http://slidepdf.com/reader/full/the-mynx-book-october-2007 202/222

 Mynx Programming Language

- 202 -

6. COLLECTIONS OF DOCUMENTS

  You may make a collection consisting of the Document and other documents released under thisLicense, and replace the individual copies of this License in the various documents with a singlecopy that is included in the collection, provided that you follow the rules of this License for

 verbatim copying of each of the documents in all other respects.

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

7. AGGREGATION WITH INDEPENDENT WORKS

 A compilation of the Document or its derivatives with other separate and independent documentsor works, in or on a volume of a storage or distribution medium, is called an "aggregate" if the

copyright resulting from the compilation is not used to limit the legal rights of the compilation'susers beyond what the individual works permit. When the Document is included in an aggregate,this License does not apply to the other works in the aggregate which are not themselves derivative

 works of the Document.

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

 whole aggregate.

8. TRANSLATION

  Translation is considered a kind of modification, so you may distribute translations of theDocument under the terms of section 4. Replacing Invariant Sections with translations requiresspecial permission from their copyright holders, but you may include translations of some or allInvariant Sections in addition to the original versions of these Invariant Sections. You may include atranslation of this License, and all the license notices in the Document, and any Warranty Disclaimers, provided that you also include the original English version of this License and theoriginal versions of those notices and disclaimers. In case of a disagreement between the translationand the original version of this License or a notice or disclaimer, the original version will prevail.

If a section in the Document is Entitled "Acknowledgements", "Dedications", or "History", therequirement (section 4) to Preserve its Title (section 1) will typically require changing the actual title.

9. TERMINATION

 You may not copy, modify, sublicense, or distribute the Document except as expressly provided forunder this License. Any other attempt to copy, modify, sublicense or distribute the Document is

  void, and will automatically terminate your rights under this License. However, parties who have

Page 203: The Mynx Book October 2007

8/14/2019 The Mynx Book October 2007

http://slidepdf.com/reader/full/the-mynx-book-october-2007 203/222

 Mynx Programming Language

- 203 -

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

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

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

Page 204: The Mynx Book October 2007

8/14/2019 The Mynx Book October 2007

http://slidepdf.com/reader/full/the-mynx-book-october-2007 204/222

 Mynx Programming Language

- 204 -

Page 205: The Mynx Book October 2007

8/14/2019 The Mynx Book October 2007

http://slidepdf.com/reader/full/the-mynx-book-october-2007 205/222

Page 206: The Mynx Book October 2007

8/14/2019 The Mynx Book October 2007

http://slidepdf.com/reader/full/the-mynx-book-october-2007 206/222

 Mynx Programming Language

- 206 -

Page 207: The Mynx Book October 2007

8/14/2019 The Mynx Book October 2007

http://slidepdf.com/reader/full/the-mynx-book-october-2007 207/222

 Mynx Programming Language

- 207 -

References

Hoare, C. A. R. (1973). Hints on Programming Language Design, StanfordUniversity, Computer Science Department, TR CS-73-403.Hoare, C. A. R. (1981). The Emperor's Old Clothes. Communications of ACM,

24(2), pp. 75-83.

Hoare, C. A. R. (1974). Monitors: An Operating System Structuring Concept.Communications of ACM, 17(10), pp. 549-557.

 Wirth, Niklaus. (1974). On the Design of Programming Languages. IFIP Congress,pp. 386-393.

  Wirth, Niklaus (1977). What Can We Do about the Unnecessary Diversity of Notation for Syntactic Definitions? Communications of ACM, 20(11), pp. 822-823.

Page 208: The Mynx Book October 2007

8/14/2019 The Mynx Book October 2007

http://slidepdf.com/reader/full/the-mynx-book-october-2007 208/222

 Mynx Programming Language

- 208 -

Page 209: The Mynx Book October 2007

8/14/2019 The Mynx Book October 2007

http://slidepdf.com/reader/full/the-mynx-book-october-2007 209/222

 Mynx Programming Language

- 209 -

Credits

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

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

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

Page 210: The Mynx Book October 2007

8/14/2019 The Mynx Book October 2007

http://slidepdf.com/reader/full/the-mynx-book-october-2007 210/222

 Mynx Programming Language

- 210 -

Page 211: The Mynx Book October 2007

8/14/2019 The Mynx Book October 2007

http://slidepdf.com/reader/full/the-mynx-book-october-2007 211/222

 Mynx Programming Language

- 211 -

Indices

Page 212: The Mynx Book October 2007

8/14/2019 The Mynx Book October 2007

http://slidepdf.com/reader/full/the-mynx-book-october-2007 212/222

 Mynx Programming Language

- 212 -

Page 213: The Mynx Book October 2007

8/14/2019 The Mynx Book October 2007

http://slidepdf.com/reader/full/the-mynx-book-october-2007 213/222

 Mynx Programming Language

- 213 -

Index of Diagrams

DIAGRAM OF SINGLE INHERITANCE ............................................................................................................83DIAGRAM OF UML CLASS DIAGRAM OF MULTIPLE V IRTUAL INHERITANCE ........................................85DIAGRAM OF UML CLASS DIAGRAM OF MULTIPLE DISJOINT INHERITANCE .......................................86

DIAGRAM OF IMPLIED METHOD .................................................................................................................145DIAGRAM OF AN OBVIATE CLASS ...............................................................................................................149DIAGRAM OF HIERARCHY OF OPERATORS FOR EXPRESSION.................................................................187DIAGRAM OF HIERARCHY OF OPERATORS WITH METHODS FOR EXPRESSION ...................................188

Page 214: The Mynx Book October 2007

8/14/2019 The Mynx Book October 2007

http://slidepdf.com/reader/full/the-mynx-book-october-2007 214/222

 Mynx Programming Language

- 214 -

Page 215: The Mynx Book October 2007

8/14/2019 The Mynx Book October 2007

http://slidepdf.com/reader/full/the-mynx-book-october-2007 215/222

 Mynx Programming Language

- 215 -

Index of Examples

EXAMPLE OF IDENTIFIERS .............................................................................................................................27EXAMPLE OF UNICODE LITERALS.................................................................................................................28EXAMPLE OF S YMBOL LITERALS....................................................................................................................28

EXAMPLE OF NUMERIC LITERALS .................................................................................................................29EXAMPLE OF USING META S TRINGS .............................................................................................................31EXAMPLE OF M YNX SINGLE-LINE COMMENTS ..........................................................................................32EXAMPLE OF V  ARIABLE DECLARATION EXPRESSION ...............................................................................38EXAMPLE OF POSTFIX EXPRESSION..............................................................................................................39EXAMPLE OF ASSIGN EXPRESSION ...............................................................................................................39EXAMPLE OF CREATION EXPRESSION ..........................................................................................................40EXAMPLE OF INPUT-OUTPUT EXPRESSION .................................................................................................40EXAMPLE OF A TTRIBUTE ACCESS SUB-EXPRESSION..................................................................................40EXAMPLE OF METHOD ACCESS SUB-EXPRESSION .....................................................................................41EXAMPLE OF METHOD ACCESS BY DEFAULT SUB-EXPRESSION ..............................................................41EXAMPLE OF ARRAY ACCESS SUB-EXPRESSION..........................................................................................41EXAMPLE OF MULTIPLE ACCESS EXPRESSION S TATEMENT .....................................................................41EXAMPLE OF NULL S TATEMENT ...................................................................................................................42EXAMPLE OF ASSERT S TATEMENTS ..............................................................................................................42EXAMPLE OF FLAG S TATEMENT....................................................................................................................43EXAMPLE OF TRY S TATEMENT ......................................................................................................................43EXAMPLE OF TRY S TATEMENT WITH ELSE CLAUSE ...................................................................................43EXAMPLE OF INVALID TRY S TATEMENT WITH FLOW OF CONTROL USING R ETURN............................44EXAMPLE OF INVALID TRY S TATEMENT WITH FLOW OF CONTROL USING NEXT ................................44EXAMPLE OF EXIT S TATEMENT ....................................................................................................................45EXAMPLE OF EXIT S TATEMENT ....................................................................................................................45EXAMPLE OF NEXT S TATEMENT ...................................................................................................................46

EXAMPLE OF PREFIX IF S TATEMENT ............................................................................................................46EXAMPLE OF R ETURN S TATEMENT ..............................................................................................................47EXAMPLE OF FOR S TATEMENT OVER FIXED R  ANGE.................................................................................48EXAMPLE OF FOR S TATEMENT OVER R  ANGE .............................................................................................48EXAMPLE OF FOR S TATEMENT OVER AN ARRAY ........................................................................................49EXAMPLE OF A FOR S TATEMENT WITH AN EXPLICIT INTEGRAL T YPE...................................................49EXAMPLE OF A FOR S TATEMENT WITH AN EXPLICIT INTEGRAL T YPE...................................................49EXAMPLE OF LOOP S TATEMENT ...................................................................................................................50EXAMPLE OF LOOP S TATEMENT WITH PREFIX IF S TATEMENT ................................................................50EXAMPLE OF LOOP S TATEMENT WITH EXIT IN C ASE S TATEMENT .........................................................50EXAMPLE OF UNTIL S TATEMENT ..................................................................................................................51

EXAMPLE OF W HILE S TATEMENT .................................................................................................................51EXAMPLE OF R EPEAT S TATEMENT WITH W HILE CONDITION .................................................................52EXAMPLE OF R EPEAT S TATEMENT WITH UNTIL CONDITION ..................................................................52EXAMPLE OF R EPEAT S TATEMENT WITH PREFIX -IF AND NESTING........................................................53EXAMPLE OF C ASE S TATEMENT ....................................................................................................................54EXAMPLE OF DELIMITED LIST OF V  ALUES WITH A C ASE S TATEMENT ...................................................54EXAMPLE OF C ASE S TATEMENT WITH S TRING LITERAL ...........................................................................55EXAMPLE OF EQUIVALENT IF S TATEMENTS ...............................................................................................55

Page 216: The Mynx Book October 2007

8/14/2019 The Mynx Book October 2007

http://slidepdf.com/reader/full/the-mynx-book-october-2007 216/222

Page 217: The Mynx Book October 2007

8/14/2019 The Mynx Book October 2007

http://slidepdf.com/reader/full/the-mynx-book-october-2007 217/222

 Mynx Programming Language

- 217 -

EXAMPLE OF COVARIANT METHOD O VERRIDE WITH IMPLIED METHOD .............................................91EXAMPLE OF COVARIANT METHOD O VERRIDE WITH V IRTUAL CLASS ..................................................91EXAMPLE OF O VERLOADING WITHIN THE CLASS AND SUB-CLASS .........................................................92EXAMPLE OF OPERATOR O VERLOADING WITHIN THE CLASS AND SUB-CLASS ....................................93EXAMPLE OF ACCESSING A TTRIBUTE OVER METHOD ..............................................................................94EXAMPLE OF SUPER CLASS P ARENT DEFINITION ......................................................................................95EXAMPLE OF SUPER CLASS R EFERENCE WITH INHERITANCE ..................................................................95EXAMPLE OF CLASS WITH THIS R EFERENCE PREFIX .................................................................................96EXAMPLE OF CLASS WITH THIS R EFERENCE AS V  ARIABLE .......................................................................96EXAMPLE OF CLASS WITH INCREMENT METHOD USING SELF PREFIX ...................................................97EXAMPLE OF GENERIC CLASS A TTRIBUTES.................................................................................................98EXAMPLE OF GENERIC CLASS METHODS ....................................................................................................99EXAMPLE OPERATOR O VERLOAD IN A GENERIC CLASS...........................................................................99EXAMPLE OF A DEFAULT METHOD IN A GENERIC CLASS ......................................................................100EXAMPLE OF A GENERIC CLASS INHERITANCE OF A GENERIC CLASS..................................................101EXAMPLE OF GENERIC CLASS INHERITING MULTIPLE DISJOINT ABSTRACT CLASSES.......................102EXAMPLE OF A GENERIC CLASS INHERITING MULTIPLE V IRTUAL CLASSES .......................................103

EXAMPLE OF LOCAL INSTANTIATION OF A GENERIC CLASS TO T YPE S TRING ...................................104EXAMPLE OF GLOBAL INSTANTIATION OF A GENERIC CLASS TO T YPE S TRING ................................105EXAMPLE OF LOCAL AND GLOBAL INSTANTIATION INSTANCES WITHIN A CLASS .............................107EXAMPLE OF INITIAL V  ALUES IN A TTRIBUTES .........................................................................................112EXAMPLE OF PROGRAM A TTRIBUTES .........................................................................................................113EXAMPLE OF CLASS A TTRIBUTES ................................................................................................................113EXAMPLE OF PROGRAM METHOD R ETURN T YPES ..................................................................................114EXAMPLE OF CLASS METHOD R ETURN T YPES..........................................................................................114EXAMPLE OF CLASS METHOD USING IN P ARAMETER MODE .................................................................116EXAMPLE OF USING THE DEFINED METHOD WITH IN P ARAMETER ....................................................116EXAMPLE OF DEFINING A METHOD WITH OUT P ARAMETER ................................................................116

EXAMPLE OF USING THE DEFINED METHOD WITH OUT P ARAMETER ................................................117EXAMPLE OF DEFINING A METHOD WITH V  AR P ARAMETER .................................................................117EXAMPLE OF USING THE DEFINED METHOD WITH V  AR P ARAMETER .................................................117EXAMPLE OF DEFINING A METHOD AND USING WITH SERIES P ARAMETER .......................................118EXAMPLE OF USING A METHOD WITH SERIES P ARAMETER INCORRECTLY .........................................119EXAMPLE OF DECLARING TRAPS IN A METHOD ......................................................................................120EXAMPLE OF DECLARING METHOD SCOPE ..............................................................................................120EXAMPLE OF DECLARING PROGRAM METHOD HEADERS......................................................................120EXAMPLE OF DECLARING A METHOD R ETURN T YPE .............................................................................122EXAMPLE OF DECLARING A CLASS METHOD HEADER ...........................................................................122EXAMPLE OF AN UNDEFINED CLASS METHOD HEADER ........................................................................123

EXAMPLE OF O VERRIDING A S TATIC METHOD IN MULTIPLE CLASSES ................................................124EXAMPLE OF QUICKER SORT METHOD ......................................................................................................125EXAMPLE OF USING THE SORT METHODS ................................................................................................125EXAMPLE OF ACCESSING S TATIC METHODS AND A TTRIBUTES IN A PROGRAM ..................................127EXAMPLE EXPLICIT S TATIC METHOD INCLUSION ...................................................................................127EXAMPLE OF IMPLICIT S TATIC METHOD INCLUSION...............................................................................128EXAMPLE OF S TATIC METHOD INCLUSION FOR R EFERENCE.................................................................128EXAMPLE OF EXPLICIT S TATIC INCLUSION ...............................................................................................128EXAMPLE OF EXPLICIT S TATIC INCLUSION BY CLASS A TTRIBUTE.........................................................129

Page 218: The Mynx Book October 2007

8/14/2019 The Mynx Book October 2007

http://slidepdf.com/reader/full/the-mynx-book-october-2007 218/222

 Mynx Programming Language

- 218 -

EXAMPLE OF S TATIC METHOD INCLUSION ...............................................................................................129EXAMPLE OF EXPLICIT S TATIC METHOD INCLUSION..............................................................................129EXAMPLE OF DEFINING METHOD EQUIVALENTS ...................................................................................130EXAMPLE OF FULL METHOD DEFINITION ................................................................................................130EXAMPLE OF METHOD DEFINITION ..........................................................................................................131EXAMPLE OF METHOD EQUIVALENTS FOR DEFAULT P ARAMETERS ....................................................131EXAMPLE OF FULL METHOD DEFINITION ................................................................................................131EXAMPLE OF METHOD EQUIVALENT DEFINITION WITH S TATIC METHOD ........................................131EXAMPLE OF METHOD EQUIVALENT TO R ENAME ALL CLASS METHODS ...........................................132EXAMPLE OF EQUIVALENT METHOD R EDEFINITION .............................................................................132EXAMPLE OF CONSTRUCTOR S YNTAX ........................................................................................................133EXAMPLE OF DEFAULT CONSTRUCTOR .....................................................................................................134EXAMPLE OF NON-DEFAULT CONSTRUCTOR ...........................................................................................134EXAMPLE OF CONSTRUCTOR DEFINITION WITH METHOD EQUIVALENT............................................134EXAMPLE OF DEFINING MULTIPLE CONSTRUCTORS IN A CLASS ...........................................................135EXAMPLE OF CONSTRUCTOR DECLARATION ............................................................................................135EXAMPLE OF INVOKING A CONSTRUCTOR ................................................................................................135

EXAMPLE OF INVOKING DEFAULT CONSTRUCTOR .................................................................................136EXAMPLE OF NOT INVOKING DEFAULT CONSTRUCTOR ........................................................................136EXAMPLE OF USING CONSTRUCTORS OF A CLASS ....................................................................................136EXAMPLE OF S YNTAX FOR A DESTRUCTOR ...............................................................................................137EXAMPLE OF DESTRUCTOR DEFINITION WITH METHOD EQUIVALENT ..............................................137EXAMPLE OF DESTRUCTOR INVOCATION..................................................................................................138EXAMPLE OF DECLARING A DEFAULT METHOD .....................................................................................139EXAMPLE OF USING AN DEFAULT METHOD.............................................................................................139EXAMPLE OF OPERATOR O VERLOAD TO METHOD INVOCATION .........................................................140EXAMPLE OF DEFAULT METHOD ...............................................................................................................140EXAMPLE OF DEFAULT METHOD FOR OUTPUT S TREAM ........................................................................140

EXAMPLE OF EXPLICIT METHOD FOR OUTPUT S TREAM.........................................................................140EXAMPLE OF DECLARING AN INCOMPLETE METHOD ............................................................................141EXAMPLES OF IMPLIED METHOD DECLARATION ....................................................................................142EXAMPLE OF AN IMPLIED METHOD IMPLEMENTATION..........................................................................143EXAMPLE OF J AVA INTERFACE FOR IMPLIED METHOD ..........................................................................143EXAMPLE OF J AVA CLASS FOR IMPLIED METHOD ....................................................................................144EXAMPLE OF J AVA CODE FOR M YNX CLASS ..............................................................................................144EXAMPLE OF METHOD OBVIATION DECLARATION ................................................................................146EXAMPLE OF OBVIATE METHOD DECLARATION FOR MULTIPLE METHODS ......................................147EXAMPLE OF CLASS DECLARING A METHOD............................................................................................147EXAMPLE OF DECLARING AN OBVIATE METHOD FOR SINGLE METHOD ...........................................148

EXAMPLE DECLARING AN OBVIATE METHOD FOR NON-EXISTENT METHOD ..................................148EXAMPLE OF MULTIPLE METHODS IN A CLASS ........................................................................................150EXAMPLE OF DECLARING MULTIPLE METHOD OBVIATION..................................................................150EXAMPLE OF METHOD OBVIATION............................................................................................................150EXAMPLE INVOKING A CLASS METHOD WITH OBVIATE METHOD.......................................................151EXAMPLE OF INVALID R EDEFINITION OF AN OBVIATE METHOD ........................................................151EXAMPLE OF INVOKING AN OBVIATE METHOD IMPLICITLY .................................................................152EXAMPLE OF R EFERENCE ASSIGNMENT OPERATOR ...............................................................................154EXAMPLE OF CREATION OPERATOR ..........................................................................................................155

Page 219: The Mynx Book October 2007

8/14/2019 The Mynx Book October 2007

http://slidepdf.com/reader/full/the-mynx-book-october-2007 219/222

 Mynx Programming Language

- 219 -

EXAMPLE OF R EGULAR ASSIGNMENT OPERATOR ...................................................................................155EXAMPLE OF DECLARATION WITH INITIAL V  ALUE .................................................................................155EXAMPLE OF C AST ASSIGNMENT OPERATOR ...........................................................................................156EXAMPLE OF ADDITION ASSIGNMENT OPERATOR ..................................................................................157EXAMPLE OF SUBTRACTION ASSIGNMENT OPERATOR  ...........................................................................157EXAMPLE OF MULTIPLICATION ASSIGNMENT OPERATOR ......................................................................158EXAMPLE OF DIVISION ASSIGNMENT OPERATOR ....................................................................................158EXAMPLE OF MODULUS ASSIGNMENT OPERATOR ..................................................................................159EXAMPLE OF BITWISE AND ASSIGNMENT OPERATOR ............................................................................159EXAMPLE OF BITWISE INCLUSIVE OR ASSIGNMENT OPERATOR ...........................................................160EXAMPLE OF BITWISE EXCLUSIVE OR ASSIGNMENT OPERATOR ..........................................................160EXAMPLE OF BITWISE SHIFT R IGHT ASSIGNMENT OPERATOR ..............................................................161EXAMPLE OF BITWISE SHIFT LEFT ASSIGNMENT OPERATOR .................................................................161EXAMPLE OF C AST OPERATOR ....................................................................................................................162EXAMPLE OF USING A C AST OPERATOR ....................................................................................................162EXAMPLE DEFINITION OF C AST CLASS T YPES..........................................................................................164EXAMPLE USING T YPE C AST OF CLASS T YPES ..........................................................................................164

EXAMPLE OF LOGICAL NOT OPERATOR ....................................................................................................165EXAMPLE OF LOGICAL AND OPERATOR ....................................................................................................166EXAMPLE OF LOGICAL BITWISE AND OPERATOR ....................................................................................166EXAMPLE OF LOGICAL AND OPERATOR ....................................................................................................166EXAMPLE OF LOGICAL OR OPERATOR ......................................................................................................167EXAMPLE OF LOGICAL BITWISE OR OPERATOR .......................................................................................167EXAMPLE OF LOGICAL INCLUSIVE OR OPERATOR ..................................................................................167EXAMPLE OF BITWISE COMPLEMENT OPERATOR ....................................................................................168EXAMPLE OF BITWISE SHIFT LEFT OPERATOR .........................................................................................168EXAMPLE OF BITWISE SHIFT R IGHT OPERATOR ......................................................................................168EXAMPLE OF LOGICAL EXCLUSIVE OR OPERATOR .................................................................................168

EXAMPLE OF EQUALITY OPERATOR ...........................................................................................................169EXAMPLE OF INEQUALITY OPERATOR .......................................................................................................170EXAMPLE OF IN INSTANCE-OF CLASS OPERATOR ....................................................................................171EXAMPLE OF IN INSTANCE OPERATOR ......................................................................................................171EXAMPLE OF LESS THAN OPERATOR .........................................................................................................171EXAMPLE OF GREATER THAN OPERATOR ................................................................................................172EXAMPLE OF GREATER THAN EQUAL OPERATOR ...................................................................................172EXAMPLE OF INSERTION S TREAM OPERATOR ..........................................................................................174EXAMPLE OF EXTRACTION S TREAM OPERATOR ......................................................................................174EXAMPLE OF O VERLOADED S TREAM OPERATORS ..................................................................................174EXAMPLE OF ADDITION OPERATOR ..........................................................................................................175

EXAMPLE OF SUBTRACTION OPERATOR ....................................................................................................175EXAMPLE OF DIVISION OPERATOR ............................................................................................................176EXAMPLE OF MODULUS OPERATOR ...........................................................................................................176EXAMPLE OF MULTIPLICATION OPERATOR ..............................................................................................176EXAMPLE OF EXPONENTIATION OPERATOR ............................................................................................177EXAMPLE OF POST-INCREMENT OPERATOR .............................................................................................177EXAMPLE OF POST-DECREMENT OPERATOR  ...........................................................................................177EXAMPLE OF METHOD ACCESS OR INVOCATION.....................................................................................178EXAMPLE OF A TTRIBUTE ACCESS ...............................................................................................................179

Page 220: The Mynx Book October 2007

8/14/2019 The Mynx Book October 2007

http://slidepdf.com/reader/full/the-mynx-book-october-2007 220/222

 Mynx Programming Language

- 220 -

EXAMPLE OF ARRAY ACCESS .......................................................................................................................179EXAMPLE OF OPERATOR O VERLOADING WITH CONSTANT O VERLOAD .............................................183EXAMPLE OF OPERATOR O VERLOAD WITH DEFAULT ............................................................................183EXAMPLE OF OPERATOR O VERLOAD FROM DEFAULT TO CONSTANT .................................................184

Page 221: The Mynx Book October 2007

8/14/2019 The Mynx Book October 2007

http://slidepdf.com/reader/full/the-mynx-book-october-2007 221/222

 Mynx Programming Language

- 221 -

Index of Tables

 T ABLE OF M YNX K EYWORDS ........................................................................................................................27 T ABLE OF ESCAPED CHARACTERS.................................................................................................................28 T ABLE OF S TANDARD META S TRINGS IN M YNX .........................................................................................30

 T ABLE OF OUTPUT WITH USING A META S TRING .......................................................................................31 T ABLE OF M YNX MULTIPLE LINE COMMENTS ...........................................................................................32 T ABLE OF PRE- AND POST- CONDITIONAL S TATEMENTS AND BOUNDS ...............................................53 T ABLE OF M YNX N AMESPACES .....................................................................................................................62 T ABLE OF M YNX CLASS K INDS, INHERITANCE, INSTANCE, C ATEGORY ................................................79 T ABLE SUMMARY OF CRITERION FOR M YNX CLASSES...............................................................................81 T ABLE OF CLASS ELEMENT ACCESS OPERATORS .......................................................................................94 T ABLE OF A TTRIBUTE K INDS ......................................................................................................................111 T ABLE OF IMPLICIT SCOPE A TTRIBUTES ....................................................................................................113 T ABLE OF METHOD P ARAMETER MODES T ABLE .....................................................................................115 T ABLE FOR O VERRIDING A S TATIC METHOD ...........................................................................................124 T ABLE OF S TATIC METHOD PREFIXES .......................................................................................................126 T ABLE S YNOPSIS SPECIAL CLASS METHODS ..............................................................................................133 T ABLE OF ASSIGNMENT OPERATORS .........................................................................................................154 T ABLE OF LOGICAL BITWISE OPERATORS .................................................................................................165 T ABLE OF R ELATIONAL OPERATORS..........................................................................................................169 T ABLE OF S TREAM OPERATORS...................................................................................................................174 T ABLE OF M ATHEMATIC OPERATORS ........................................................................................................175 T ABLE OF ACCESS OPERATORS....................................................................................................................178 T ABLE OF OPERATOR PRECEDENCE ..........................................................................................................180 T ABLE OF OPERATORS, PRECEDENCE, AND O VERLOADED...................................................................185 T ABLE OF S TANDARD OPERATOR O VERLOADS BY METHOD N AME ....................................................186 T ABLE OF M YNX FILE T YPES AND TOOLS .................................................................................................195

Page 222: The Mynx Book October 2007

8/14/2019 The Mynx Book October 2007

http://slidepdf.com/reader/full/the-mynx-book-october-2007 222/222

 Mynx Programming Language