You are on page 1of 216
Mynx Programming Language July 2007
Mynx Programming Language
Mynx
Programming
Language
July 2007
July 2007

Mynx Programming Language

Mynx Programming Language -2-

-2-

Mynx Programming Language

Mynx Programming Language Copyright July 2007 William F. Gilreath http://www.williamgilreath.com/mynx

Mynx Programming Language

Mynx Programming Language Copyright July 2007 William F. Gilreath http://www.williamgilreath.com/mynx
Mynx Programming Language Copyright July 2007 William F. Gilreath http://www.williamgilreath.com/mynx

Copyright July 2007

William F. Gilreath

http://www.williamgilreath.com/mynx

Mynx Programming Language Copyright July 2007 William F. Gilreath http://www.williamgilreath.com/mynx

-3-

Mynx Programming Language

This book Documentation License. is licensed under the terms of the GNU Free Permission is

This book

Documentation License.

is

licensed under

the

terms

of

the

GNU Free

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

no Back- Cover Texts. A copy of the license is included in the section entitled "GNU

-4-

Mynx Programming Language

Table of Contents

PROLOG

13

PRELUDE

15

NAME AND PROJECT

15

PHILOSOPHICAL STATEMENT

16

TARGET PLATFORMS

16

MANIFESTO

17

LANGUAGE PRINCIPLES

20

DESIGN RATIONALE

21

Syntax

21

Statements

21

Units

22

GOALS

23

LICENSE

24

License Objectives

24

Documentation

24

Software

24

LEXICON

25

IDENTIFIERS

27

KEYWORDS

27

LITERALS

27

SYMBOLS

28

NUMBERS

28

META STRINGS

29

OPERATORS

30

ENCODING

31

COMMENTS

31

Single Comments

31

Multiple Comments

31

ENUMERATED TYPES

32

STATEMENTS

33

COMPUTATION

36

Expression Statement

36

Declaration

36

Expression

36

Postfix

37

Assignment

37

Assign

37

Create

37

Input-Output

38

Access

38

Attribute

38

-5-

Mynx Programming Language

Method

39

Array

39

Multiple

39

Null Statement

40

ERROR

40

Assert Statement

40

Flag Statement

41

Try Statement

41

FLOW OF CONTROL

42

Exit Statement

43

Next Statement

44

Prefix If Statement

44

Return Statement

45

REPETITION

46

For Statement

46

For Statement over a Range

46

For Statement over an Array

47

For Statement over Other Integral Type

47

Until Statement

49

While Statement

49

Repeat Statement

50

Pre-conditional and Post-conditional Loops

51

Case Statement

52

If Statement

53

MUTEX STATEMENT

55

Mutex Statement Syntax

55

Mutex Expression

55

NAMESPACES

57

Declaration

57

Default Namespace

57

Classes and Programs within a Namespace

58

Inclusion of Classes from a Namespace

58

Nested Namespace Inclusion

59

Declaration Order for Namespace Inclusion

60

Mynx Namespace

60

Nonexistent Namespace Inclusion

60

Static Inclusion from Default Namespace

61

ARRAYS

62

Array Attributes

62

Array Declaration

63

Array Creation

64

Initialization with a List

64

Initialization with an Implicit Indexed List

64

Initialization with an Explicit Indexed List

65

Initialization with a Non-List

65

Initialization with Default Constructor

65

Initialization with Null

66

Using an Element of an Array

67

-6-

Mynx Programming Language

Array as an Object

68

Array as a Parameter

68

TRAPS

70

Kinds of Traps

70

Trap Declaration

70

Trap Invocation

70

Trap Handling

71

Trap Propagation

71

UNITS

73

PRIMARY ELEMENTS – PROGRAM AND CLASS

75

Program

75

Class

76

KINDS OF CLASSES

76

Abstract

77

Constant

77

Default

77

Generic

77

Singular

78

Static

78

Virtual

78

INHERITANCE AND CLASS TYPES

79

TYPES OF INHERITANCE

79

Null

79

Single

80

Multiple Virtual

81

Multiple Disjoint

82

CLASSES AND INHERITANCE

84

INHERITANCE OF ATTRIBUTES AND METHODS

84

Attributes

84

Methods

85

INHERITANCE OF METHODS

85

METHOD OVERRIDING

85

Rules for Method Overriding

OPERATOR OVERLOADING

86

Covariant Method Overriding

87

Method Overloading

89

90

CLASS REFERENCE PREFIXES

90

Dottic Access Prefix

91

Super Class Prefix

91

This Class Prefix

92

Self Class Prefix

94

GENERICS

95

Elements of a Generic Class

95

Generic Attributes

95

Generic Methods

96

Operator Overloads in Generic Class

96

Default Method in Generic Class

97

-7-

Mynx Programming Language

Inheritance with Generic Classes

97

Inheriting a Generic Class

98

Inheriting Non-Generic Classes

98

Inheriting an Abstract Class

99

Inheriting a Virtual Class

100

Instantiation of a Generic Class

101

Kinds of Instantiation

101

Local Instantiation

101

Global Instantiation

102

Instance of a Generic Class

103

ELEMENTS

105

MINOR ELEMENTS

107

ATTRIBUTES

107

Attribute Mode

107

Attribute Kind

107

Attribute Type

108

Attribute Name

108

Initial Value

108

Attribute Scope

108

PROGRAM ATTRIBUTES

109

CLASS ATTRIBUTES

109

METHODS

110

Program Methods

110

Class Methods

110

Parameter List

111

Method Parameter Modes

111

In Parameter Mode

111

Out Parameter Mode

112

Var Parameter Mode

113

Series Parameter Mode

114

Method Traps

115

Method Scope

116

CLASS METHODS

117

Method Mode

117

Method Synchronization

117

Method Return Type

118

Method Headers

118

Undefined Method Header

119

ADVANCED METHOD DEFINITION AND USE

119

STATIC METHODS

119

Kinds of Static Methods

119

Overriding a Static Method

120

Prefix for Static Method

122

Program Methods as Default Static

123

Implicit Static Method Inclusion

123

Reference to External Static Method

124

METHOD EQUIVALENTS: LOW FAT METHODS

126

-8-

Mynx Programming Language

Default Parameters by Method Equivalents

CONSTRUCTION, DESTRUCTION, AND DEFAULT METHOD OF A CLASS

127

Export Instance Method

127

Renaming All Class Methods of a Name

128

129

CONSTRUCTOR

129

Constructor Definition

129

Constructor Invocation

131

DESTRUCTOR

133

Destructor Definition

133

Destructor Invocation

133

DEFAULT CLASS METHOD

135

Default Method Declaration

135

Default Method Invocation

135

INCOMPLETE METHODS

136

IMPLIED METHODS

138

Rules for Implied Methods

138

Declaration

138

Implementation

139

Implied Method Diagram

141

OBVIATE METHODS

142

Rules for Obviating a Class Method

142

Single Method by Signature

142

Multiple Methods by Method Name

143

Inheritance with a Single Obviate Method

143

Using a Class with an Obviate Method

147

No Side Effects for Never Obviating a Method

148

Reason to Obviate a Method

148

OPERATORS AND OPERATOR OVERLOADING

149

Operators

149

Assignment

150

Reference Assignment Operator is

150

Creation Operator as

151

Regular Assignment Operator =

151

Cast Operator to

152

Cast Assignment Operator :=

153

Dual Assignment Operation Operators

153

Subtraction-Assignment Operator -=

154

Multiplication-Assignment Operator *=

155

Division-Assignment Operator /=

155

Modulus-Assignment Operator %=

156

Bitwise-And Assignment Operator &=

156

Bitwise Inclusive-Or Assignment Operator |=

157

Bitwise Exclusive-Or Assignment Operator ^=

157

Bitwise Shift-Right Assignment Operator >>=

158

Bitwise-Shift-Left Assignment Operator <<=

158

Logical Bitwise

159

Logical Not Operator !

159

Logical Bitwise And Operator &

160

-9-

Mynx Programming Language

Logical And Operator &&

160

Logical Bitwise Inclusive Or Operator |

161

Logical Inclusive Or Operator ||

161

Bitwise Complement Operator ~

162

Bitwise Shift Left Operator <<

162

Bitwise Shift Right Operator >>

162

Logical Exclusive Or Operator ^

162

Relational

163

Equality Operator ==

163

Inequality Operator !=

164

Instance Type Of Operator in

165

Lesser Than Operator <

165

Greater Than Operator >

166

Greater Equal Operator >=

166

Lesser Equal Operator <=

167

Stream

168

Insertion Operator <<<

168

Extraction Operator >>>

168

Mathematic

169

Addition Operator +

169

Subtraction Operator -

169

Division Operator /

170

Modulus Operator %

170

Multiplication Operator *

170

Exponentiation Operator **

171

Increment Operator ++

171

Decrement Operator --

171

Access

172

Method Invocation

172

Attribute Access `

173

Array Access [ ]

173

Operator Precedence

174

OPERATOR OVERLOADING

175

Operator Overload Declaration

175

Kinds of Overloads

175

Rules for Operator Overloading

176

Table of Operators

179

Standard Method Names for Overloads

180

Implicit Hierarchy of Operators

181

APPENDICES

183

APPENDIX - MYNX GRAMMAR

185

Header Syntax

185

Class Syntax

185

Class Methods

185

Class Attribute

185

Class Overload

185

Class Method Obviate

185

- 10 -

Mynx Programming Language

Program

186

Statements

186

Expression Statements

187

Lexical Elements

187

Comments

188

APPENDIX - MYNX FILE TYPES AND TOOLS

189

Mynx

189

Myxm

189

Moxi

189

Myna

189

Minx

190

Myxd

190

APPENDIX – GNU FREE DOCUMENTATION LICENSE

191

EPILOG

199

REFERENCES

201

CREDITS

203

INDICES

205

INDEX OF DIAGRAMS

207

INDEX OF EXAMPLES

209

INDEX OF TABLES

215

- 11 -

Mynx Programming Language

Mynx Programming Language - 12 -

- 12 -

Mynx Programming Language

Prolog

- 13 -

Mynx Programming Language

Mynx Programming Language - 14 -

- 14 -

Mynx Programming Language

Prelude

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

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

Name and Project

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

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

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

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

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

MYNX = Manx + lYnx + NX

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

- 15 -

Mynx Programming Language

Philosophical Statement

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

Target Platforms

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

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

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

C# is used for the .NET platform and is similar enough but not identical to Java to allow mirroring

similar code generation. (Although in theory J# could be used for both

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

Depending on the

).

- 16 -

Mynx Programming Language

Manifesto

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

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

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

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

end.

Use explicit block

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

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

Integer x = new Integer(7);

Int x to 7;

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

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

Java:

int x = 0;

switch(x)

{

case 0:

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

Mynx:

Int x to 0;

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

- 17 -

Mynx Programming Language

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

8. No nesting of classes or methods.

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

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

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

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

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

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

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

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

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

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

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

- 18 -

Mynx Programming Language

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

class example is

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

//C++ public myMethod(int x, int y=0) is

//Java public myMethod(int x) {

this.myMethod(x,0);

}

//Proxima method equivalent public myMethod(int x) is to this.myMethod(x,0);

end class;

- 19 -

Mynx Programming Language

Language Principles

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

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

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

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

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

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

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

- 20 -

Mynx Programming Language

Design Rationale

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

1. Syntax

2. Statement

3. Units

Syntax

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

Other syntax forms of object-oriented programming languages include:

1. Smalltalk - convoluted syntax style, lacks expressivity.

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

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

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

Inventing a new syntax might be more expressive and efficient, but too far different. A level of familiarity in syntax is needed to explore and use a new programming language.

Statements

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

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

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

- 21 -

Mynx Programming Language

rather than either make the choice for them by design or for easier compiler construction.

Units

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

1. program - unit of application

2. class

- unit of library or reuse

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

- 22 -

Mynx Programming Language

Goals

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

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

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

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

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

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

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

- 23 -

Mynx Programming Language

License

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

License Objectives

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

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

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

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

Documentation

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

Software

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

1. example software and code in the book

2. implemented compiler and language tools

3. libraries that are part of the core package

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

- 24 -

Mynx Programming Language

Lexicon

- 25 -

Mynx Programming Language

Mynx Programming Language - 26 -

- 26 -

Mynx Programming Language

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

Identifiers

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

X

– legal, at least one letter character

_1x

– illegal, begins with underscore

helloWorld

– legal

123myVar

– illegal, begins with digit

_variable

– illegal, begins with underscore

myVeryLongVariableName

– legal

Example of Identifiers

Keywords

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

abstract access

all

as

assert

async

case

class

constant construct covariant default

destruct do

elif

else

end

enum

exit

flag

for

generic

goto

has

if

implied

in

is

let

loop

method

module

mutex

new

next

null

out

overload own

private

program

protect

public

reader

repeat return

self

series

singular static

super

sync

this

to

try

type

until

var

variable

virtual

void

volatile when

while

with

writer

Table of Mynx Keywords

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

Literals

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

- 27 -

Mynx Programming Language

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

in Mynx possibly as meta-code for classes.

Symbols

A literal character is enclosed in single quotes, a string with double quotes. A literal character uses a

single symbol; a string is a sequence of multiple symbols. There are nine special “escaped” character literals that are delimited with the ‘\’ escape character.

Character

Description

\b

Backspace

\f

Form Feed

\n

Newline

\r

Carriage Return

\t

Tabulation

\u

Unicode Prefix

\\

Slash (Escape Character)

\”

Double Quote or Parenthesis

\’

Single Quote or Apostrophe

Table of Escaped Characters

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

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

\uFF3E

– legal – legal – illegal, all hexadecimal digits uppercase

\u2323

\uffff

\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 – legal string

“123”

“c”

– legal 1-character string

Example of Symbol Literals

Numbers

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

- 28 -

Mynx Programming Language

A numeric real literal (which is the default for non-integer number literals) is 64-bit, a float is 32-bit,

and is indicated with a trailing capital ‘F’ to indicate a float numeric literal. Both a numeric real and

float must begin with a digit.

123

– legal integer

-123

– legal integer – legal integer – illegal hexadecimal integer without prefix 0X – legal real – illegal hexadecimal prefix 0X is invalid – legal hexadecimal integer – legal float

+73

FFE3

3.145

0xFF

0XFF

2.713F

.333337 – illegal real, must begin with a digit

OxCAFE

– illegal hexadecimal integer needs ‘0X’ prefix

0.5

- legal real

Example of Numeric Literals

Meta Strings

A

meta string is the Mynx partial replacement for the macro system of C/C++. It does not attempt

to

replace or define macros for conditional code inclusion, or textual substitutions. Meta strings are

equivalent to the the

FILE

and

LINE

macros.

A meta-string is a string identifier in uppercase, beginning with the hash or pound sign #. A meta

string is substituted with the information it represents. A meta-string allows for information about the source code, but without the manual effort to represent it, or the overhead of changing it when

the source code is revised. There are 19-standard meta strings in Mynx.

Meta String

Description

Example

#AUTHOR

Author of the source

“Jon Q. Doe”

#BUILD

Build version for file

“Build 1.1”

#CLASS

Name of the class

“myClass”

#COMPILER

Compiler information

“Mynx Compiler 2.033”

#DATE

Date of the Build

“03/04/2004”

#DAY

Day of Month as Integer 1…31

“17”

#FILE

File Name

“myClass.mynx”

#LINE

Line Number

“237”

#METHOD

Name of the Method

“myData”

#MODULE

Name of the Module

“mynx.core”

#MONTH

Month of the Year as Text

“August”

#ORG

Organization Name (Company, University, etc.)

“University Old York”

#PLATFORM

Name of the Platform (Machine/Operating System)

“AMD64X86:Linux”

#PROGRAM

Name of the Program

“myProgram”

#SYSTEM

Name of the System (Internet or Network Name)

“cupcake.oldyork.edu”

#TIME

Time of Build

“2:31 P.M”

#VENDOR

Vendor of the compiler

“MynxSoft LLC”

#VERSION

Compiler Version

“version 1.0.1”

#YEAR

Year of Build as an Integer

“2003”

#WEEKDAY

Day of the Week of Build as Text

“Friday”

Table of Standard Meta Strings in Mynx

- 29 -

Mynx Programming Language

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

class metaStrExample as null is

public

construct

is

to

null;

public

singular

void

aMethod is

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

 

public

destruct

is

to

null;

end

class;

Example of using Meta Strings

The output for calling aMethod with the class metaStrExample is:

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

Table of Output with using a Meta String

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

Operators

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

1. Assignment

2. Logical and Bitwise

3. Relational

4. Stream

5. Mathematic

- 30 -

Mynx Programming Language

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

Encoding

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

Comments

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

Single Comments

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

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

///another single line comment /* old C-style comment */ //* another C-style comment */ / wrong comment

– legal, with triple slash – illegal, no double slash – legal, with C-style comment – illegal, only single slash

Example of Mynx Single-Line Comments

Multiple Comments

Multiple-line comments are comments which span multiple lines, beginning with a double exclamation mark (bang-bang) prefix !! and ending with a similar trailing suffix. The double

exclamation mark is used for opening and closing symmetry, and the comment style allows C-style

and Java-style multiple comments included /*

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

*/ to be used with existing documentation tools.

!! this is multiple-line !!

– legal, even on one line

!!

!!

!!

!! //a comment !! ! this is a comment ! !! /** C-style

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

Table of Mynx Multiple Line Comments

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

- 31 -

Mynx Programming Language

Enumerated Types

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

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

- 32 -

Mynx Programming Language

Statements

- 33 -

Mynx Programming Language

Mynx Programming Language - 34 -

- 34 -

Mynx Programming Language

Concept of Statements

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

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

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

1. flow of control or jump

2. repetition or iteration

3. selection or decision

4. error computation

5. mutual exclusion

Statement

Category

Type

Assert

Error

Singular

Case

Selection

Multiple

Exit

Flow of Control

Singular

Expression

Computation

Singular

Flag

Error

Singular

For

Repetition

Multiple

If

Selection

Multiple

Loop

Repetition

Multiple

Mutex

Mutual Exclusion

Multiple

Next

Flow of Control

Singular

Null

Computation

Singular

Prefix if

Flow of Control

Singular

Repeat

Flow of Control

Multiple

Return

Flow of Control

Singular

Try

Error

Multiple

Until

Repetition

Multiple

While

Repetition

Multiple

Table of Statement Category and Types

- 35 -

Mynx Programming Language

Computation

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

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

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

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

Declaration

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

var Int x to 0; var Char c,d;

var Point p

to

var Real r

to

//no initial value, just a declaration to null; null; default;

var String[*] tables to { “0”,“1”,“2”,“3” };

Example of Variable Declaration Expression

Expression

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

1. postfix

2. assignment

3. creation

4. input-output

5. access

- 36 -

Mynx Programming Language

Postfix

A postfix expression involves a variable, method call, or an instance object, and the method which

the postfix operator (++ or --) which is overloaded. For the integral numeric types the increment operator ++ overloads the increment method, and the decrement operator –- overloads the

decrement method.

var Int x to 0;

var Int y

to

null;

x++;

y=(this.getValue)--;

Example of Postfix Expression

Assignment

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

1. Assign

2. Create

3. Input-output

– associate an object value to an object instance by the identifier

– create a new class instance as an object, and assign it to an identifier

– 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 =

y += x+7 / 2;

z = this.computeValue(x,y);

data[3] =

3;

17;

x`y

:= i+j*3;

total

=

x**y + 1;

q

is y;

this`y

=

0;

self`ct

=

super.getCount;

Example of Assign Expression

Create

A create or creation statement is an assignment expression that creates a new instance of a class and

assigns it to an object reference or variable. The keyword as follows the object reference variable

and the class name with any constructor parameters.

- 37 -

Mynx Programming Language

var Int x to null; //declare an initial values to null

y var String z

var

Int

to

null;

to

null;

x

as Int;

//default construct

y

as Int(-1234);

//create -1234 Int

z

as String(“hello world!!!”);//create String

x

as Byte;

//create sub-type of parent type instance

x

as

null;

//compiler error! Null is not valid class to create

y

as

default;//compiler

error! Default constructor by class name

z

as Int; //compiler error! Incompatible class type Int to String

Example of Creation Expression

Input-Output

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

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

Example of Input-Output Expression

Access

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

1. attribute

2. method

3. array

4. multiple

– access the attribute of a class

– access the method of a class

– access the element of an array

– 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

y = super`rawData;

=

0;

//write access of class attribute

//read access of class attribute

Example of Attribute Access Sub-Expression

- 38 -

Mynx Programming Language

Method

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

this.callMethod(0,”hello”);

super.invokeMethod(‘a’);

x.doIt;

Example of Method Access Sub-Expression

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

this.x;

//default invocation

super.y;

//default invocation

data;

//default invocation

Example of Method Access by Default Sub-Expression

Array

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

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

Example of Array Access Sub-Expression

Multiple

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

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

super.doIt[x]`data;

Example of Multiple Access Expression Statement

- 39 -

Mynx Programming Language

Null Statement

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

public doNothing is null; end doNothing;

Example of Null Statement

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

Error

The error statements include explicit error assertion checking with an assert statement, and error flagging with a trap, and handling a flagged trap with a try statement.

Error statements are for debugging software and to manage software errors as they occur in software. Methods can require that a trap error must be handled with a try statement. The method then must flag the trap when it occurs, and a caller of the method must handle the error with a try statement or propagate it by declaring it as a flagged trap of the method.

One form of error statement, the assert statement is for debugging software under development, and the other kinds of error flagging and handling are for handling software errors.

Assert Statement

The assert statement is used to debug software. The assert statement is compiled during a debug build by the compiler, but during a release or final build becomes a null statement and is excluded from the compiled source.

As the assert statement is for debugging purposes, it is a very simple statement. An expression is asserted, and if it is not true, then the assert statement causes execution of software to stop, along with reporting an error message, and an optional literal string message. Assert statements are not intended for sophisticated error handling or logic, only to assist in debugging source code.

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

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

assert

x !=

null

Example of Assert Statements

- 40 -

Mynx Programming Language

Flag Statement

The flag statement is used to raise, or flag an exception or trap. The flag statement takes a class that

is the trap to be flagged. Essentially the flag statement creates a new instance of the trap class, and

then returns from the method to the caller.

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

Example of Flag Statement

Try Statement

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

the try statement tries to handle the trap.

A try statement encloses statements within a try-clause, and then has a series of when-clauses for the

traps it handles, and then has an else-clause optionally, and an optional do-clause.

A try statement restricts placing a flow of control statement (exit, next, return) in the do-clause of a

try statement. This is to avoid flow of control ambiguity in a try statement.

A when-clause has the trap class, and an optional identifier to associate with the instance.

try

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

do

file.close;

end

try;

Example of Try Statement

try

file = File(“test.data”);

when(FileNotFoundTrap

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

fnf)

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

do

file.close;

end

try;

Example of Try Statement with Else Clause

- 41 -

Mynx Programming Language

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

try

 

return

0;

do

 

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

end

try;

//from try do-clause

Example of Invalid Try Statement with Flow of Control using Return

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

loop

 

try

 

next

loop(0);

 

do

 

next

loop(0);

//compiler

error: invalid flow of control

 

end

try;

//from try do-clause

end

loop(0);

 

Example of Invalid Try Statement with Flow of Control using Next

Flow of Control

Nesting and need for non-sequential exit and next stepping through the iteration statements. Not valid for try, if, or case. Statements, in particular the repetition category of statements, are nested often. There are times when a non-sequential skip or continuation from a nested loop block is efficient. An exit statement exits or skips out from a nested block of repetition statements, a next statement continues to the next cycle of a loop cycle.

The repetition statement blocks can be nested, and with each nesting have a nesting level in the

form of a parenthesized integer following the end clause before the semicolon. The nesting level

starts at zero and progressively counts upward by an increment of one, so the range is 0

nested repetition statements. An exit or next can specify the level to which an exit or next is reached, the default being the current repetition statement only.

for n

n-1

- 42 -

Mynx Programming Language

Exit Statement

The exit statement is used within an iteration statement, such as a loop, while, or for, or statement. The exit statement causes an immediate exiting of the iterative structure, a jump to the end clause of the iteration block statement.

for(Int x is 0 to 100) for(Int y is 0 to 200) if(x == 100
for(Int
x
is
0
to
100)
for(Int
y
is
0
to
200)
if(x
==
100
&&
x
==
y)
exit
for(0);
end
if;
end
for(1);
end
for(0);

Example of Exit Statement

var InputFile file to (“input.data”); var Bool status to (Bool.False); file.open; while(! file.endOfFile) //read
var InputFile file to (“input.data”);
var Bool status to (Bool.False);
file.open;
while(!
file.endOfFile)
//read 100 records
for(Int
i
is 0 to 100)
this.processRecord(file,i,status);
if(!status)
exit
while(0);
end
if;
end
for(1);
end
while(0);
file.close;

Example of Exit Statement

- 43 -

Mynx Programming Language

Next Statement

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

public void findInMatrix(in Matrix matrix) is var Int col to matrix.getCol; var Int row to
public void findInMatrix(in Matrix matrix) is
var Int col to matrix.getCol;
var Int row to matrix.getRow;
var Int val to –1;
for(Int
x
is
0 to row)
for(Int
y
is
0 to col)
val = matrix.get(x,y);
if(val
== 0)
next
for(1);//skip
to
next y
end
if;
end
for(1);
end
for(0);
end findInMatrix;

Example of Next Statement

Prefix If Statement

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

exit(0) if ( i >= j ); next(2) if ( foundFlag ); public Ordinal findFirst(in
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

- 44 -

Mynx Programming Language

Return Statement

A return statement returns or exits a class or program method, and can return a value. The value returned from a method must correspond with the method type or return nothing if the method is a void type return or procedure. The type null is a valid return type for all return values except void, indicating a null or non-initialized object reference return. A return statement is like a non-sequential exit that can return a value from a method.

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

for(Int

x

is 0 to list.length) ==

value)

if(list[x]

 

return

value;

end

if;

end

for;

return

null;

end find;

public Ordinal factorial(in Unsigned uint) is

if(uint

== 0)

1;

return

else

end

return (uint * factorial(uint-1)); 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

- 45 -

Mynx Programming Language

Repetition

The repetition statements repeat or iterate over a block of statements. A for statement iterates over a fixed range or count of elements. A loop statement is a infinite loop, no specific explicit conditions exist to terminate the loop. The until-loop and while-loop have explicit conditions to exit a loop, which are logically the inverse of each other.

For Statement

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

for loop statements:

1. Iterate over a fixed integer range from lower to upper bound.

2. Iterate over an array of fixed dimensions and length.

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

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

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

For Statement over a Range

A fixed for statement over an integral range counts up or down from an initial value up to an upper

limit. The lower bound and upper bound are an actual for loop variables; the for-loop variable will equal the boundary values.

//x implicitly Ordinal, count from 0 to 20

for(x

is

0 to 20)

end

IO.putln(x);

for;

Example of For Statement over Fixed Range

//x implicitly Ordinal, count from 100 to 0

for(y

is 100

to

0)

end

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

for;

Example of For Statement over Range

- 46 -

Mynx Programming Language

For Statement over an Array

The for-statement over an array iterates over the range of a 1-dimensional array, returning the element of an array at an index instead of the value in the range.

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

for(String

x

in dataTable)

end

IO <<< x <<< eoln;

for(0);

Example of For Statement over an Array

For Statement over Other Integral Type

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

Implementing a for statement with a non-implicit integral type is:

//Byte is signed from -128 to +127

for(Byte

b

is -128 to +127)

end

IO <<< b << eoln;

for;

Example of a For Statement with an Explicit Integral Type

//2^16-1 is upper limit

for(UnsignedShort

ush

is 0 to 65535)

end

sum += sum + ush; //compute sum from 0 to 65536

for;

Example of a For Statement with an Explicit Integral Type

For a non-implicit integral variable in a for loop, the type must be explicitly declared and the ranges for the variable must be valid for the integral range.

- 47 -

Mynx Programming Language

Loop Statement

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

//infinite loop without explicit end loop

end

null;

loop;

Example of Loop Statement

var Bool statusFlag to False;

loop

 

doFileOperation(statusFlag);

exit

if(statusFlag);

//prefix-if explicit exit

end

loop;

Example of Loop Statement with Prefix If Statement

var Char c to

null;

loop

 

IO.read(c); case(c) as ‘x’,’X’,’e’,’E’ is exit loop; //exit on character x or e

 

as ‘n’,’N’

is

next

loop;

//exit on character n

else

next;

//implicitly next

loop

 

end

case;

end

loop;

 

Example of Loop Statement with Exit in Case Statement

- 48 -

Mynx Programming Language

Until Statement

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

var Int x to 3;

until(x

== 0)

end

x--;

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

- 49 -

Mynx Programming Language

Repeat Statement

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

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

2. repeat-until

- repeat loop with an until logical condition for continuation.

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

var File dataFile to “myfile.dat”;

dataFile.open;

repeat

dataFile.readRecord;

while(!dataFile.endOfFile

);

Example of Repeat Statement with While Condition

var File dataFile to “myfile.dat”;

dataFile.open;

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

Example of Repeat Statement with Until Condition

Each of the repeat loop statements is logically equivalent. Depending upon the logical expression, a repeat-while and repeat-until can be used. A loop statement is equivalent to a repeat statement, only with the logic to terminate of the loop part of the body of statements. A repeat statement avoids the mixing of logic and statements in a cleaner repetition statement.

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

- 50 -

Mynx Programming Language

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

repeat

rec = dataFile.readRecord; ==

exit

if(rec

null)

repeat(0);

while(!dataFile.endOfFile

)(0);

dataFile.close

Example of Repeat Statement with Prefix-If and Nesting

Pre-conditional and Post-conditional Loops

A repeat statement is similar to a loop statement in that both will execute the body of statements at least once. A while and until statement can optionally never execute the body of statements, and the for statement (again depending on the logic of the expression) can possibly never execute the body statements.

Repetition Statement

Kind of Loop

Lower Bound

Upper Bound

For

Pre-conditional

0

c

<

Loop

Post-conditional

1

n

Repeat

Post-conditional

1

n

Until

Pre-conditional

0

n

While

Pre-conditional

0

n

Table of Pre- and Post- Conditional Statements and Bounds

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

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

- 51 -

Mynx Programming Language

Selection

Selection statements select a block of statements to execute based upon a value or condition. A case statement uses a discrete value to select a statement block to execute, the if statement uses a logical Boolean condition or set of Boolean conditionals to select a block to execute.

Case Statement

A case statement is a multi-way selection statement that uses a discrete value to select the choice of decision. A case statement can be more efficient than a ladder of nested if-elif-else statements. A case statement uses a discrete type such as integer, Boolean, character, or strings.

The case of the variable heads a case statement, then with each valid case values as a comma- delimited list between the keywords as and is. The last part of a case statement is the optional else- clause that begins with the keyword else, which is the catchall if no specific case is selected. A case statement ends with the case footer, which follows the syntactic form of an if statement with an end keyword with a case keyword with the terminating semicolon.

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

case(x)

end

as

0

is

 

doSomething0;

as

1

is

 

doSomething1;

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

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.

- 52 -

Mynx Programming Language

A case statement can case on a String literal:

var String cmd to null;

loop

 

cmd = in.readLine; case(cmd)

 

as

as

“exit”, “quit” is exit;

“version” is reportVersion;

 

end

else execute(cmd); case;

end

loop;

Example of Case Statement with String Literal

If Statement

An if statement is a logical condition selection statement; based upon the condition in the if-clause, either the then-block is evaluated, or the else-block. An else-block for an if-statement is an optional part, the equivalent if-statement with an else-block has a null statement.

if(x

< y)

end

= y; //then-block if;

x

if(x

< y)

end

x = y;//then-block else null; //else-block if;

Example of Equivalent If Statements

- 53 -

Mynx Programming Language

if(x < y) this.computeValue(x,y); elif(x > y) this.computeValue(y,x); else //x == y this.computeValue(x,x);
if(x
< y)
this.computeValue(x,y);
elif(x
> y)
this.computeValue(y,x);
else //x == y
this.computeValue(x,x);
end
if;
if(x
< y)
x += y;
else //x >= y
if(x
>
y)
y
-= x;
else //x == y
x is
y;
end
if;
end
if;

Example of Equivalent If Statement with Else-If Elif Block

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

if(x

> y)

//no else required

x.computeWith(y);

elif(x

< y)

end

y.computeWith(x);

if;

Example of If Statement without Else Block

public default Int factorial(in Int ival) in for factorial is if(ival < 0) flag IntegerValueTrap;
public default Int factorial(in Int ival) in for factorial is
if(ival
< 0)
flag IntegerValueTrap;
elif(ival
==
0)
return
1;
else
return(
ival
*
this.factorial(ival-1)
);
end
if;
end factorial;

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

- 54 -

Mynx Programming Language

Mutex Statement

A mutex (mutual exclusion) statement is used to create a block of mutual exclusive statements (a

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

A mutex statement consists of a mutex header, the block of statements forming a critical section,

and the mutex footer. The mutex header begins with the keyword mutex, and the mutex variable or expression in parenthesis. The mutex footer is simply the keyword end followed by mutex and a

semicolon.

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

end

STATEMENTS

mutex

;

Example of Mutex Statement Syntax

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

Mutex Expression

The mutex expression is an expression for an object lock, or a monitor for the object. A monitor is a fundamental mutual exclusion concept, but for each object there is one lock. Hence a synchronized method uses the instance object lock implicitly; but for a block of statements in a mutex statement requires an explicit lock – in the form of a mutex expression.

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

mutex(this)

 

null;

end

mutex;

Example Mutex Expression with This Class Reference

- 55 -

Mynx Programming Language

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

Object myMutex to default;

mutex(myMutex)

 

null;

end

mutex;

Example of Mutex Expression using Local Variable

- 56 -

Mynx Programming Language

Namespaces

The namespace concept is organizing classes and programs into a hierarchy based upon a module name to give unique names to a class or program. A namespace helps to modularize classes and programs so that a more descriptive full namespace name can be given, rather than a simple name to

an individual class or program. Mynx requires an explicit namespace, or else a default namespace is implicitly given (unless of course the default namespace is explicitly used