Upload
william-gilreath
View
225
Download
0
Embed Size (px)
Citation preview
8/14/2019 The Mynx Programming Language July 2007
1/216
Mynx
Programming
Language
July 2007
8/14/2019 The Mynx Programming Language July 2007
2/216
Mynx Programming Language
- 2 -
8/14/2019 The Mynx Programming Language July 2007
3/216
Mynx Programming Language
- 3 -
Mynx Programming Language
Copyright July 2007
William F. Gilreath
http://www.williamgilreath.com/mynx
8/14/2019 The Mynx Programming Language July 2007
4/216
Mynx Programming Language
- 4 -
This book is licensed under the terms of the GNU FreeDocumentation License.
Permission is granted to copy, distribute and/or modifythis document under the terms of the GNU Free DocumentationLicense, Version 1.2 or any later version published by theFree 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 thesection entitled "GNU Free Documentation License".
8/14/2019 The Mynx Programming Language July 2007
5/216
Mynx Programming Language
- 5 -
Table of ContentsPROLOG......................................................................................................................................................... 13
PRELUDE ...................................................................................................................................................... 15NAME AND PROJECT .................................................................................................................................. 15PHILOSOPHICAL STATEMENT.................................................................................................................... 16
TARGET PLATFORMS .................................................................................................................................. 16MANIFESTO.................................................................................................................................................. 17LANGUAGE PRINCIPLES............................................................................................................................. 20DESIGN RATIONALE .................................................................................................................................. 21
Syntax....................................................................................................................................................... 21Statements ............................................................................................................................................... 21Units......................................................................................................................................................... 22
GOALS .......................................................................................................................................................... 23
LICENSE........................................................................................................................................................ 24License Objectives ................................................................................................................................. 24Documentation....................................................................................................................................... 24Software................................................................................................................................................... 24
LEXICON ....................................................................................................................................................... 25
IDENTIFIERS ................................................................................................................................................ 27KEYWORDS .................................................................................................................................................. 27LITERALS ...................................................................................................................................................... 27SYMBOLS....................................................................................................................................................... 28NUMBERS ..................................................................................................................................................... 28
META STRINGS ............................................................................................................................................ 29OPERATORS ................................................................................................................................................. 30ENCODING................................................................................................................................................... 31COMMENTS .................................................................................................................................................. 31
Single Comments ................................................................................................................................... 31Multiple Comments ............................................................................................................................... 31
ENUMERATED TYPES ................................................................................................................................. 32
STATEMENTS .............................................................................................................................................. 33
COMPUTATION ............................................................................................................................................ 36Expression Statement............................................................................................................................ 36
Declaration ......................................................................................................................................... 36
Expression.......................................................................................................................................... 36Postfix............................................................................................................................................. 37
Assignment..................................................................................................................................... 37 Assign......................................................................................................................................... 37Create ......................................................................................................................................... 37Input-Output............................................................................................................................. 38
Access ............................................................................................................................................. 38 Attribute..................................................................................................................................... 38
8/14/2019 The Mynx Programming Language July 2007
6/216
Mynx Programming Language
- 6 -
Method....................................................................................................................................... 39 Array........................................................................................................................................... 39Multiple ...................................................................................................................................... 39
Null Statement........................................................................................................................................ 40ERROR.......................................................................................................................................................... 40
Assert Statement..................................................................................................................................... 40Flag Statement ........................................................................................................................................ 41 Try Statement.......................................................................................................................................... 41
FLOW OF CONTROL .................................................................................................................................... 42Exit Statement ........................................................................................................................................ 43Next Statement....................................................................................................................................... 44Prefix If Statement................................................................................................................................. 44Return Statement.................................................................................................................................... 45
REPETITION ................................................................................................................................................. 46For Statement ......................................................................................................................................... 46
For Statement over a Range............................................................................................................. 46For Statement over an Array ........................................................................................................... 47
For Statement over Other Integral Type ....................................................................................... 47Until Statement....................................................................................................................................... 49
While Statement ..................................................................................................................................... 49Repeat Statement.................................................................................................................................... 50Pre-conditional and Post-conditional Loops ..................................................................................... 51Case Statement ....................................................................................................................................... 52If Statement............................................................................................................................................. 53
MUTEXSTATEMENT ................................................................................................................................... 55Mutex Statement Syntax........................................................................................................................ 55Mutex Expression .................................................................................................................................. 55
NAMESPACES ............................................................................................................................................... 57
Declaration.............................................................................................................................................. 57Default Namespace................................................................................................................................ 57Classes and Programs within a Namespace ....................................................................................... 58Inclusion of Classes from a Namespace............................................................................................. 58Nested Namespace Inclusion............................................................................................................... 59Declaration Order for Namespace Inclusion..................................................................................... 60Mynx Namespace................................................................................................................................... 60Nonexistent Namespace Inclusion...................................................................................................... 60Static Inclusion from Default Namespace ......................................................................................... 61
ARRAYS ......................................................................................................................................................... 62 Array Attributes...................................................................................................................................... 62
Array Declaration................................................................................................................................... 63Array Creation ........................................................................................................................................ 64Initialization with a List .................................................................................................................... 64
Initialization with an Implicit Indexed List............................................................................... 64Initialization with an Explicit Indexed List............................................................................... 65
Initialization with a Non-List........................................................................................................... 65Initialization with Default Constructor...................................................................................... 65Initialization with Null.................................................................................................................. 66
Using an Element of an Array......................................................................................................... 67
8/14/2019 The Mynx Programming Language July 2007
7/216
Mynx Programming Language
- 7 -
Array as an Object............................................................................................................................. 68Array as a Parameter ......................................................................................................................... 68
TRAPS............................................................................................................................................................ 70Kinds of Traps........................................................................................................................................ 70
Trap Declaration .................................................................................................................................... 70
Trap Invocation...................................................................................................................................... 70 Trap Handling......................................................................................................................................... 71Trap Propagation ................................................................................................................................... 71
UNITS .............................................................................................................................................................. 73
PRIMARYELEMENTS PROGRAM AND CLASS........................................................................................ 75Program................................................................................................................................................... 75Class ......................................................................................................................................................... 76
KINDS OF CLASSES...................................................................................................................................... 76Abstract ................................................................................................................................................... 77Constant .................................................................................................................................................. 77Default ..................................................................................................................................................... 77
Generic .................................................................................................................................................... 77Singular .................................................................................................................................................... 78Static......................................................................................................................................................... 78
Virtual ...................................................................................................................................................... 78INHERITANCE AND CLASS TYPES ............................................................................................................. 79
TYPES OF INHERITANCE ............................................................................................................................ 79Null........................................................................................................................................................... 79Single........................................................................................................................................................ 80Multiple Virtual....................................................................................................................................... 81Multiple Disjoint .................................................................................................................................... 82
CLASSES AND INHERITANCE ..................................................................................................................... 84
INHERITANCE OF ATTRIBUTES AND METHODS ..................................................................................... 84 Attributes................................................................................................................................................. 84Methods................................................................................................................................................... 85
INHERITANCE OF METHODS ..................................................................................................................... 85METHOD OVERRIDING.............................................................................................................................. 85
Rules for Method Overriding............................................................................................................... 86Covariant Method Overriding.............................................................................................................. 87Method Overloading ............................................................................................................................. 89
OPERATOROVERLOADING....................................................................................................................... 90CLASS REFERENCE PREFIXES.................................................................................................................... 90
Dottic Access Prefix.............................................................................................................................. 91Super Class Prefix.............................................................................................................................. 91
This Class Prefix................................................................................................................................ 92Self Class Prefix ................................................................................................................................. 94
GENERICS .................................................................................................................................................... 95Elements of a Generic Class................................................................................................................. 95
Generic Attributes............................................................................................................................. 95Generic Methods ............................................................................................................................... 96
Operator Overloads in Generic Class................................................................................................. 96Default Method in Generic Class........................................................................................................ 97
8/14/2019 The Mynx Programming Language July 2007
8/216
Mynx Programming Language
- 8 -
Inheritance with Generic Classes......................................................................................................... 97Inheriting a Generic Class................................................................................................................ 98Inheriting Non-Generic Classes...................................................................................................... 98
Inheriting an Abstract Class ........................................................................................................ 99Inheriting a Virtual Class............................................................................................................ 100
Instantiation of a Generic Class......................................................................................................... 101Kinds of Instantiation..................................................................................................................... 101Local Instantiation...................................................................................................................... 101Global Instantiation.................................................................................................................... 102
Instance of a Generic Class ................................................................................................................ 103
ELEMENTS.................................................................................................................................................. 105
MINORELEMENTS.................................................................................................................................... 107ATTRIBUTES ............................................................................................................................................... 107
Attribute Mode..................................................................................................................................... 107Attribute Kind ...................................................................................................................................... 107Attribute Type ...................................................................................................................................... 108
Attribute Name..................................................................................................................................... 108Initial Value ........................................................................................................................................... 108
Attribute Scope..................................................................................................................................... 108PROGRAM ATTRIBUTES ............................................................................................................................ 109CLASS ATTRIBUTES ................................................................................................................................... 109METHODS................................................................................................................................................... 110
Program Methods ................................................................................................................................ 110Class Methods....................................................................................................................................... 110Parameter List....................................................................................................................................... 111Method Parameter Modes .................................................................................................................. 111
In Parameter Mode.......................................................................................................................... 111
Out Parameter Mode ...................................................................................................................... 112Var Parameter Mode....................................................................................................................... 113Series Parameter Mode ................................................................................................................... 114
Method Traps ....................................................................................................................................... 115Method Scope....................................................................................................................................... 116
CLASS METHODS ....................................................................................................................................... 117Method Mode....................................................................................................................................... 117Method Synchronization..................................................................................................................... 117Method Return Type ........................................................................................................................... 118Method Headers................................................................................................................................... 118Undefined Method Header................................................................................................................. 119
ADVANCED METHOD DEFINITION AND USE ...................................................................................... 119STATIC METHODS ..................................................................................................................................... 119
Kinds of Static Methods ..................................................................................................................... 119Overriding a Static Method ................................................................................................................ 120Prefix for Static Method...................................................................................................................... 122Program Methods as Default Static................................................................................................... 123Implicit Static Method Inclusion ....................................................................................................... 123Reference to External Static Method................................................................................................ 124
METHOD EQUIVALENTS: LOWFAT METHODS.................................................................................... 126
8/14/2019 The Mynx Programming Language July 2007
9/216
Mynx Programming Language
- 9 -
Default Parameters by Method Equivalents .................................................................................... 127Export Instance Method..................................................................................................................... 127Renaming All Class Methods of a Name.......................................................................................... 128
CONSTRUCTION, DESTRUCTION, AND DEFAULT METHOD OF A CLASS .......................................... 129CONSTRUCTOR.......................................................................................................................................... 129
Constructor Definition........................................................................................................................ 129Constructor Invocation....................................................................................................................... 131DESTRUCTOR............................................................................................................................................. 133
Destructor Definition.......................................................................................................................... 133Destructor Invocation......................................................................................................................... 133
DEFAULT CLASS METHOD....................................................................................................................... 135Default Method Declaration .............................................................................................................. 135Default Method Invocation................................................................................................................ 135
INCOMPLETE METHODS .......................................................................................................................... 136IMPLIED METHODS................................................................................................................................... 138
Rules for Implied Methods................................................................................................................. 138Declaration............................................................................................................................................ 138
Implementation.................................................................................................................................... 139Implied Method Diagram ................................................................................................................... 141
OBVIATE METHODS ................................................................................................................................. 142Rules for Obviating a Class Method ................................................................................................. 142Single Method by Signature................................................................................................................ 142Multiple Methods by Method Name................................................................................................. 143Inheritance with a Single Obviate Method....................................................................................... 143Using a Class with an Obviate Method............................................................................................. 147No Side Effects for Never Obviating a Method............................................................................. 148Reason to Obviate a Method.............................................................................................................. 148
OPERATORS AND OPERATOROVERLOADING ..................................................................................... 149
Operators............................................................................................................................................... 149Assignment............................................................................................................................................ 150
Reference Assignment Operator is ............................................................................................... 150Creation Operator as....................................................................................................................... 151Regular Assignment Operator =................................................................................................... 151Cast Operator to.............................................................................................................................. 152Cast Assignment Operator :=........................................................................................................ 153Dual Assignment Operation Operators....................................................................................... 153Subtraction-Assignment Operator -= .......................................................................................... 154Multiplication-Assignment Operator *=...................................................................................... 155Division-Assignment Operator /=............................................................................................... 155
Modulus-Assignment Operator %=............................................................................................. 156Bitwise-And Assignment Operator &= ....................................................................................... 156Bitwise Inclusive-Or Assignment Operator |=.......................................................................... 157Bitwise Exclusive-Or Assignment Operator ^=......................................................................... 157Bitwise Shift-Right Assignment Operator >>=......................................................................... 158Bitwise-Shift-Left Assignment Operator
8/14/2019 The Mynx Programming Language July 2007
10/216
Mynx Programming Language
- 10 -
Logical And Operator &&............................................................................................................. 160Logical Bitwise Inclusive Or Operator | ..................................................................................... 161Logical Inclusive Or Operator ||................................................................................................. 161Bitwise Complement Operator ~ ................................................................................................. 162Bitwise Shift Left Operator .................................................................................................. 162Logical Exclusive Or Operator ^.................................................................................................. 162Relational............................................................................................................................................... 163
Equality Operator ==..................................................................................................................... 163Inequality Operator !=.................................................................................................................... 164Instance Type Of Operator in....................................................................................................... 165Lesser Than Operator .............................................................................................................. 166Greater Equal Operator >= .......................................................................................................... 166Lesser Equal Operator .............................................................................................................. 168Mathematic............................................................................................................................................ 169
Addition Operator +....................................................................................................................... 169Subtraction Operator -.................................................................................................................... 169Division Operator /........................................................................................................................ 170Modulus Operator %...................................................................................................................... 170Multiplication Operator *............................................................................................................... 170Exponentiation Operator **.......................................................................................................... 171Increment Operator ++................................................................................................................. 171Decrement Operator --................................................................................................................... 171
Access .................................................................................................................................................... 172
Method Invocation ......................................................................................................................... 172Attribute Access ` ............................................................................................................................ 173Array Access [ ] ................................................................................................................................ 173
Operator Precedence........................................................................................................................... 174OPERATOROVERLOADING..................................................................................................................... 175
Operator Overload Declaration......................................................................................................... 175Kinds of Overloads.............................................................................................................................. 175Rules for Operator Overloading........................................................................................................ 176
Table of Operators............................................................................................................................... 179Standard Method Names for Overloads .......................................................................................... 180Implicit Hierarchy of Operators ........................................................................................................ 181
APPENDICES.............................................................................................................................................. 183
APPENDIX- MYNXGRAMMAR................................................................................................................ 185Header Syntax....................................................................................................................................... 185Class Syntax........................................................................................................................................... 185Class Methods....................................................................................................................................... 185Class Attribute...................................................................................................................................... 185Class Overload...................................................................................................................................... 185Class Method Obviate ......................................................................................................................... 185
8/14/2019 The Mynx Programming Language July 2007
11/216
Mynx Programming Language
- 11 -
Program................................................................................................................................................. 186Statements ............................................................................................................................................. 186Expression Statements ........................................................................................................................ 187Lexical Elements .................................................................................................................................. 187Comments ............................................................................................................................................. 188
APPENDIX
- MYNX
FILE
TYPES AND
TOOLS
........................................................................................ 189Mynx ...................................................................................................................................................... 189Myxm ..................................................................................................................................................... 189Moxi ....................................................................................................................................................... 189Myna....................................................................................................................................................... 189Minx ....................................................................................................................................................... 190Myxd ...................................................................................................................................................... 190
APPENDIX GNU FREE DOCUMENTATION LICENSE ....................................................................... 191
EPILOG......................................................................................................................................................... 199
REFERENCES.............................................................................................................................................. 201CREDITS...................................................................................................................................................... 203
INDICES ....................................................................................................................................................... 205
INDEX OF DIAGRAMS ............................................................................................................................... 207INDEX OF EXAMPLES ............................................................................................................................... 209INDEX OF TABLES..................................................................................................................................... 215
8/14/2019 The Mynx Programming Language July 2007
12/216
Mynx Programming Language
- 12 -
8/14/2019 The Mynx Programming Language July 2007
13/216
Mynx Programming Language
- 13 -
Prolog
8/14/2019 The Mynx Programming Language July 2007
14/216
Mynx Programming Language
- 14 -
8/14/2019 The Mynx Programming Language July 2007
15/216
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 dont 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 onlyone 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 programminglanguage can serve as a way to understand the programming language itself within the creatorscontext. The what of a feature in a programming language can be less important than the whyfor 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 Horizonand 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 programminglanguage 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 wildcatMynx is meant to reflect qualities ofboth names, unusual like the Manx, but still having some of aggressive properties of the Lynx.
8/14/2019 The Mynx Programming Language July 2007
16/216
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 toclone 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 ofnative 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(GUIs), and other modules.
C# is used for the .NET platform and is similar enough but not identical to Java to allow mirroringsimilar 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).
8/14/2019 The Mynx Programming Language July 2007
17/216
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 blockstructuring 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 forcingcode 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;
8/14/2019 The Mynx Programming Language July 2007
18/216
Mynx Programming Language
- 18 -
7. All things are objects, no primitive types that are not objects as in Java, no boxingand 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 ofreference 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 ofmethods 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.
8/14/2019 The Mynx Programming Language July 2007
19/216
8/14/2019 The Mynx Programming Language July 2007
20/216
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 ofexpression, 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.
8/14/2019 The Mynx Programming Language July 2007
21/216
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 scriptinglanguage.
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 and efficient, but too far different. A level offamiliarity 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 ofcolors used to paint a canvas.
Different programming languages have different degrees of statements. Mynx provides seventeenstatements, 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,
8/14/2019 The Mynx Programming Language July 2007
22/216
Mynx Programming Language
- 22 -
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 application2. 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.
8/14/2019 The Mynx Programming Language July 2007
23/216
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 abstractlyreason 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.
8/14/2019 The Mynx Programming Language July 2007
24/216
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 allowothers 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 book2. 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.
8/14/2019 The Mynx Programming Language July 2007
25/216
Mynx Programming Language
- 25 -
Lexicon
8/14/2019 The Mynx Programming Language July 2007
26/216
Mynx Programming Language
- 26 -
8/14/2019 The Mynx Programming Language July 2007
27/216
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 underscoremyVeryLongVariableName 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 ofthe keywords goto and new as the name of a variable, constant, class, or program can be confusingand 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.
Literals
Literals are actual data for characters, strings, integers, and real numbers. A literal can be thought ofas 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.
8/14/2019 The Mynx Programming Language July 2007
28/216
Mynx Programming Language
- 28 -
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 givenencoding scheme (such as UTF-8, US-ASCII, or Unicode.)
The Unicode escape character indicates a following Unicode character literal, using four uppercasehexadecimal 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 stringhello world!!! legal stringhello illegal literal, character is only one symbol123 legal stringc legal 1-character string
Example of Symbol Literals
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.
8/14/2019 The Mynx Programming Language July 2007
29/216
Mynx Programming Language
- 29 -
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
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 #. A metastring is substituted with the information it represents. A meta-string allows for information aboutthe source code, but without the manual effort to represent it, or the overhead of changing it whenthe 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 131 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
8/14/2019 The Mynx Programming Language July 2007
30/216
Mynx Programming Language
- 30 -
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.
class metaStrExample as null is
public construct is to null;
public singular void aMethod isIO.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 aMethodClass 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 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 five categories:
1. Assignment2. Logical and Bitwise3. Relational4. Stream5. Mathematic
8/14/2019 The Mynx Programming Language July 2007
31/216
Mynx Programming Language
- 31 -
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
The Mynx compiler ignores comments, but for documentation, the comments are processed withthe specific documentation with XML markup tags.
8/14/2019 The Mynx Programming Language July 2007
32/216
Mynx Programming Language
- 32 -
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 programminglanguage 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 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 creatingclasses, attributes, constants, variables, or methods with those names and cause confusion.
8/14/2019 The Mynx Programming Language July 2007
33/216
Mynx Programming Language
- 33 -
Statements
8/14/2019 The Mynx Programming Language July 2007
34/216
Mynx Programming Language
- 34 -
8/14/2019 The Mynx Programming Language July 2007
35/216
Mynx Programming Language
- 35 -
Concept of Statements
Mynx statements are the basic means for expressing functionality of methods, and the data ofattributes. 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 ofend along with the keyword, and a last semicolon. There are eight single-line and nine multiple-linestatements.
The 17-statements are organized into 5-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 Multiple
Next Flow of Control SingularNull Computation Singular
Prefix if Flow of Control SingularRepeat Flow of Control MultipleReturn Flow of Control SingularTry Error MultipleUntil Repetition MultipleWhile Repetition Multiple
Table of Statement Category and Types
8/14/2019 The Mynx Programming Language July 2007
36/216
Mynx Programming Language
- 36 -
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 representinga 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 ofnull. 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
8/14/2019 The Mynx Programming Language July 2007
37/216
Mynx Programming Language
- 37 -
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.
8/14/2019 The Mynx Programming Language July 2007
38/216
Mynx Programming Language
- 38 -
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 ofassigning 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 >> 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 array4. 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 orvariable.
this`total = 0; //write access of class attributey = super`rawData; //read access of class attribute
Example of Attribute Access Sub-Expression
8/14/2019 The Mynx Programming Language July 2007
39/216
Mynx Programming Language
- 39 -
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 arrayaccess 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
8/14/2019 The Mynx Programming Language July 2007
40/216
8/14/2019 The Mynx Programming Language July 2007
41/216
Mynx Programming Language
- 41 -
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
8/14/2019 The Mynx Programming Language July 2007
42/216
8/14/2019 The Mynx Programming Language July 2007
43/216
Mynx Programming Language
- 43 -
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 ofthe 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
8/14/2019 The Mynx Programming Language July 2007
44/216
Mynx Programming Language
- 44 -
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
8/14/2019 The Mynx Programming Language July 2007
45/216
Mynx Programming Language
- 45 -
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
8/14/2019 The Mynx Programming Language July 2007
46/216
Mynx Programming Language
- 46 -
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 offor 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 va