├── LICENSE.GPL2 ├── LICENSE.GPL3 ├── README.md ├── The_Programming_Language_Oberon+.adoc └── The_Programming_Language_Oberon+.html /LICENSE.GPL2: -------------------------------------------------------------------------------- 1 | GNU GENERAL PUBLIC LICENSE 2 | Version 2, June 1991 3 | 4 | Copyright (C) 1989, 1991 Free Software Foundation, Inc. 5 | 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 6 | Everyone is permitted to copy and distribute verbatim copies 7 | of this license document, but changing it is not allowed. 8 | 9 | Preamble 10 | 11 | The licenses for most software are designed to take away your 12 | freedom to share and change it. By contrast, the GNU General Public 13 | License is intended to guarantee your freedom to share and change free 14 | software--to make sure the software is free for all its users. This 15 | General Public License applies to most of the Free Software 16 | Foundation's software and to any other program whose authors commit to 17 | using it. (Some other Free Software Foundation software is covered by 18 | the GNU Library General Public License instead.) You can apply it to 19 | your programs, too. 20 | 21 | When we speak of free software, we are referring to freedom, not 22 | price. Our General Public Licenses are designed to make sure that you 23 | have the freedom to distribute copies of free software (and charge for 24 | this service if you wish), that you receive source code or can get it 25 | if you want it, that you can change the software or use pieces of it 26 | in new free programs; and that you know you can do these things. 27 | 28 | To protect your rights, we need to make restrictions that forbid 29 | anyone to deny you these rights or to ask you to surrender the rights. 30 | These restrictions translate to certain responsibilities for you if you 31 | distribute copies of the software, or if you modify it. 32 | 33 | For example, if you distribute copies of such a program, whether 34 | gratis or for a fee, you must give the recipients all the rights that 35 | you have. You must make sure that they, too, receive or can get the 36 | source code. And you must show them these terms so they know their 37 | rights. 38 | 39 | We protect your rights with two steps: (1) copyright the software, and 40 | (2) offer you this license which gives you legal permission to copy, 41 | distribute and/or modify the software. 42 | 43 | Also, for each author's protection and ours, we want to make certain 44 | that everyone understands that there is no warranty for this free 45 | software. If the software is modified by someone else and passed on, we 46 | want its recipients to know that what they have is not the original, so 47 | that any problems introduced by others will not reflect on the original 48 | authors' reputations. 49 | 50 | Finally, any free program is threatened constantly by software 51 | patents. We wish to avoid the danger that redistributors of a free 52 | program will individually obtain patent licenses, in effect making the 53 | program proprietary. To prevent this, we have made it clear that any 54 | patent must be licensed for everyone's free use or not licensed at all. 55 | 56 | The precise terms and conditions for copying, distribution and 57 | modification follow. 58 | 59 | GNU GENERAL PUBLIC LICENSE 60 | TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION 61 | 62 | 0. This License applies to any program or other work which contains 63 | a notice placed by the copyright holder saying it may be distributed 64 | under the terms of this General Public License. The "Program", below, 65 | refers to any such program or work, and a "work based on the Program" 66 | means either the Program or any derivative work under copyright law: 67 | that is to say, a work containing the Program or a portion of it, 68 | either verbatim or with modifications and/or translated into another 69 | language. (Hereinafter, translation is included without limitation in 70 | the term "modification".) Each licensee is addressed as "you". 71 | 72 | Activities other than copying, distribution and modification are not 73 | covered by this License; they are outside its scope. The act of 74 | running the Program is not restricted, and the output from the Program 75 | is covered only if its contents constitute a work based on the 76 | Program (independent of having been made by running the Program). 77 | Whether that is true depends on what the Program does. 78 | 79 | 1. You may copy and distribute verbatim copies of the Program's 80 | source code as you receive it, in any medium, provided that you 81 | conspicuously and appropriately publish on each copy an appropriate 82 | copyright notice and disclaimer of warranty; keep intact all the 83 | notices that refer to this License and to the absence of any warranty; 84 | and give any other recipients of the Program a copy of this License 85 | along with the Program. 86 | 87 | You may charge a fee for the physical act of transferring a copy, and 88 | you may at your option offer warranty protection in exchange for a fee. 89 | 90 | 2. You may modify your copy or copies of the Program or any portion 91 | of it, thus forming a work based on the Program, and copy and 92 | distribute such modifications or work under the terms of Section 1 93 | above, provided that you also meet all of these conditions: 94 | 95 | a) You must cause the modified files to carry prominent notices 96 | stating that you changed the files and the date of any change. 97 | 98 | b) You must cause any work that you distribute or publish, that in 99 | whole or in part contains or is derived from the Program or any 100 | part thereof, to be licensed as a whole at no charge to all third 101 | parties under the terms of this License. 102 | 103 | c) If the modified program normally reads commands interactively 104 | when run, you must cause it, when started running for such 105 | interactive use in the most ordinary way, to print or display an 106 | announcement including an appropriate copyright notice and a 107 | notice that there is no warranty (or else, saying that you provide 108 | a warranty) and that users may redistribute the program under 109 | these conditions, and telling the user how to view a copy of this 110 | License. (Exception: if the Program itself is interactive but 111 | does not normally print such an announcement, your work based on 112 | the Program is not required to print an announcement.) 113 | 114 | These requirements apply to the modified work as a whole. If 115 | identifiable sections of that work are not derived from the Program, 116 | and can be reasonably considered independent and separate works in 117 | themselves, then this License, and its terms, do not apply to those 118 | sections when you distribute them as separate works. But when you 119 | distribute the same sections as part of a whole which is a work based 120 | on the Program, the distribution of the whole must be on the terms of 121 | this License, whose permissions for other licensees extend to the 122 | entire whole, and thus to each and every part regardless of who wrote it. 123 | 124 | Thus, it is not the intent of this section to claim rights or contest 125 | your rights to work written entirely by you; rather, the intent is to 126 | exercise the right to control the distribution of derivative or 127 | collective works based on the Program. 128 | 129 | In addition, mere aggregation of another work not based on the Program 130 | with the Program (or with a work based on the Program) on a volume of 131 | a storage or distribution medium does not bring the other work under 132 | the scope of this License. 133 | 134 | 3. You may copy and distribute the Program (or a work based on it, 135 | under Section 2) in object code or executable form under the terms of 136 | Sections 1 and 2 above provided that you also do one of the following: 137 | 138 | a) Accompany it with the complete corresponding machine-readable 139 | source code, which must be distributed under the terms of Sections 140 | 1 and 2 above on a medium customarily used for software interchange; or, 141 | 142 | b) Accompany it with a written offer, valid for at least three 143 | years, to give any third party, for a charge no more than your 144 | cost of physically performing source distribution, a complete 145 | machine-readable copy of the corresponding source code, to be 146 | distributed under the terms of Sections 1 and 2 above on a medium 147 | customarily used for software interchange; or, 148 | 149 | c) Accompany it with the information you received as to the offer 150 | to distribute corresponding source code. (This alternative is 151 | allowed only for noncommercial distribution and only if you 152 | received the program in object code or executable form with such 153 | an offer, in accord with Subsection b above.) 154 | 155 | The source code for a work means the preferred form of the work for 156 | making modifications to it. For an executable work, complete source 157 | code means all the source code for all modules it contains, plus any 158 | associated interface definition files, plus the scripts used to 159 | control compilation and installation of the executable. However, as a 160 | special exception, the source code distributed need not include 161 | anything that is normally distributed (in either source or binary 162 | form) with the major components (compiler, kernel, and so on) of the 163 | operating system on which the executable runs, unless that component 164 | itself accompanies the executable. 165 | 166 | If distribution of executable or object code is made by offering 167 | access to copy from a designated place, then offering equivalent 168 | access to copy the source code from the same place counts as 169 | distribution of the source code, even though third parties are not 170 | compelled to copy the source along with the object code. 171 | 172 | 4. You may not copy, modify, sublicense, or distribute the Program 173 | except as expressly provided under this License. Any attempt 174 | otherwise to copy, modify, sublicense or distribute the Program is 175 | void, and will automatically terminate your rights under this License. 176 | However, parties who have received copies, or rights, from you under 177 | this License will not have their licenses terminated so long as such 178 | parties remain in full compliance. 179 | 180 | 5. You are not required to accept this License, since you have not 181 | signed it. However, nothing else grants you permission to modify or 182 | distribute the Program or its derivative works. These actions are 183 | prohibited by law if you do not accept this License. Therefore, by 184 | modifying or distributing the Program (or any work based on the 185 | Program), you indicate your acceptance of this License to do so, and 186 | all its terms and conditions for copying, distributing or modifying 187 | the Program or works based on it. 188 | 189 | 6. Each time you redistribute the Program (or any work based on the 190 | Program), the recipient automatically receives a license from the 191 | original licensor to copy, distribute or modify the Program subject to 192 | these terms and conditions. You may not impose any further 193 | restrictions on the recipients' exercise of the rights granted herein. 194 | You are not responsible for enforcing compliance by third parties to 195 | this License. 196 | 197 | 7. If, as a consequence of a court judgment or allegation of patent 198 | infringement or for any other reason (not limited to patent issues), 199 | conditions are imposed on you (whether by court order, agreement or 200 | otherwise) that contradict the conditions of this License, they do not 201 | excuse you from the conditions of this License. If you cannot 202 | distribute so as to satisfy simultaneously your obligations under this 203 | License and any other pertinent obligations, then as a consequence you 204 | may not distribute the Program at all. For example, if a patent 205 | license would not permit royalty-free redistribution of the Program by 206 | all those who receive copies directly or indirectly through you, then 207 | the only way you could satisfy both it and this License would be to 208 | refrain entirely from distribution of the Program. 209 | 210 | If any portion of this section is held invalid or unenforceable under 211 | any particular circumstance, the balance of the section is intended to 212 | apply and the section as a whole is intended to apply in other 213 | circumstances. 214 | 215 | It is not the purpose of this section to induce you to infringe any 216 | patents or other property right claims or to contest validity of any 217 | such claims; this section has the sole purpose of protecting the 218 | integrity of the free software distribution system, which is 219 | implemented by public license practices. Many people have made 220 | generous contributions to the wide range of software distributed 221 | through that system in reliance on consistent application of that 222 | system; it is up to the author/donor to decide if he or she is willing 223 | to distribute software through any other system and a licensee cannot 224 | impose that choice. 225 | 226 | This section is intended to make thoroughly clear what is believed to 227 | be a consequence of the rest of this License. 228 | 229 | 8. If the distribution and/or use of the Program is restricted in 230 | certain countries either by patents or by copyrighted interfaces, the 231 | original copyright holder who places the Program under this License 232 | may add an explicit geographical distribution limitation excluding 233 | those countries, so that distribution is permitted only in or among 234 | countries not thus excluded. In such case, this License incorporates 235 | the limitation as if written in the body of this License. 236 | 237 | 9. The Free Software Foundation may publish revised and/or new versions 238 | of the General Public License from time to time. Such new versions will 239 | be similar in spirit to the present version, but may differ in detail to 240 | address new problems or concerns. 241 | 242 | Each version is given a distinguishing version number. If the Program 243 | specifies a version number of this License which applies to it and "any 244 | later version", you have the option of following the terms and conditions 245 | either of that version or of any later version published by the Free 246 | Software Foundation. If the Program does not specify a version number of 247 | this License, you may choose any version ever published by the Free Software 248 | Foundation. 249 | 250 | 10. If you wish to incorporate parts of the Program into other free 251 | programs whose distribution conditions are different, write to the author 252 | to ask for permission. For software which is copyrighted by the Free 253 | Software Foundation, write to the Free Software Foundation; we sometimes 254 | make exceptions for this. Our decision will be guided by the two goals 255 | of preserving the free status of all derivatives of our free software and 256 | of promoting the sharing and reuse of software generally. 257 | 258 | NO WARRANTY 259 | 260 | 11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY 261 | FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN 262 | OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES 263 | PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED 264 | OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 265 | MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS 266 | TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE 267 | PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, 268 | REPAIR OR CORRECTION. 269 | 270 | 12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING 271 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR 272 | REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, 273 | INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING 274 | OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED 275 | TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY 276 | YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER 277 | PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE 278 | POSSIBILITY OF SUCH DAMAGES. 279 | 280 | END OF TERMS AND CONDITIONS 281 | 282 | How to Apply These Terms to Your New Programs 283 | 284 | If you develop a new program, and you want it to be of the greatest 285 | possible use to the public, the best way to achieve this is to make it 286 | free software which everyone can redistribute and change under these terms. 287 | 288 | To do so, attach the following notices to the program. It is safest 289 | to attach them to the start of each source file to most effectively 290 | convey the exclusion of warranty; and each file should have at least 291 | the "copyright" line and a pointer to where the full notice is found. 292 | 293 | 294 | Copyright (C) 295 | 296 | This program is free software; you can redistribute it and/or modify 297 | it under the terms of the GNU General Public License as published by 298 | the Free Software Foundation; either version 2 of the License, or 299 | (at your option) any later version. 300 | 301 | This program is distributed in the hope that it will be useful, 302 | but WITHOUT ANY WARRANTY; without even the implied warranty of 303 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 304 | GNU General Public License for more details. 305 | 306 | You should have received a copy of the GNU General Public License 307 | along with this program; if not, write to the Free Software 308 | Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 309 | 310 | 311 | Also add information on how to contact you by electronic and paper mail. 312 | 313 | If the program is interactive, make it output a short notice like this 314 | when it starts in an interactive mode: 315 | 316 | Gnomovision version 69, Copyright (C) year name of author 317 | Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'. 318 | This is free software, and you are welcome to redistribute it 319 | under certain conditions; type `show c' for details. 320 | 321 | The hypothetical commands `show w' and `show c' should show the appropriate 322 | parts of the General Public License. Of course, the commands you use may 323 | be called something other than `show w' and `show c'; they could even be 324 | mouse-clicks or menu items--whatever suits your program. 325 | 326 | You should also get your employer (if you work as a programmer) or your 327 | school, if any, to sign a "copyright disclaimer" for the program, if 328 | necessary. Here is a sample; alter the names: 329 | 330 | Yoyodyne, Inc., hereby disclaims all copyright interest in the program 331 | `Gnomovision' (which makes passes at compilers) written by James Hacker. 332 | 333 | , 1 April 1989 334 | Ty Coon, President of Vice 335 | 336 | This General Public License does not permit incorporating your program into 337 | proprietary programs. If your program is a subroutine library, you may 338 | consider it more useful to permit linking proprietary applications with the 339 | library. If this is what you want to do, use the GNU Library General 340 | Public License instead of this License. 341 | 342 | 343 | -------------------------------------------------------------------------------- /LICENSE.GPL3: -------------------------------------------------------------------------------- 1 | GNU GENERAL PUBLIC LICENSE 2 | Version 3, 29 June 2007 3 | 4 | Copyright (C) 2007 Free Software Foundation, Inc. 5 | Everyone is permitted to copy and distribute verbatim copies 6 | of this license document, but changing it is not allowed. 7 | 8 | Preamble 9 | 10 | The GNU General Public License is a free, copyleft license for 11 | software and other kinds of works. 12 | 13 | The licenses for most software and other practical works are designed 14 | to take away your freedom to share and change the works. By contrast, 15 | the GNU General Public License is intended to guarantee your freedom to 16 | share and change all versions of a program--to make sure it remains free 17 | software for all its users. We, the Free Software Foundation, use the 18 | GNU General Public License for most of our software; it applies also to 19 | any other work released this way by its authors. You can apply it to 20 | your programs, too. 21 | 22 | When we speak of free software, we are referring to freedom, not 23 | price. Our General Public Licenses are designed to make sure that you 24 | have the freedom to distribute copies of free software (and charge for 25 | them if you wish), that you receive source code or can get it if you 26 | want it, that you can change the software or use pieces of it in new 27 | free programs, and that you know you can do these things. 28 | 29 | To protect your rights, we need to prevent others from denying you 30 | these rights or asking you to surrender the rights. Therefore, you have 31 | certain responsibilities if you distribute copies of the software, or if 32 | you modify it: responsibilities to respect the freedom of others. 33 | 34 | For example, if you distribute copies of such a program, whether 35 | gratis or for a fee, you must pass on to the recipients the same 36 | freedoms that you received. You must make sure that they, too, receive 37 | or can get the source code. And you must show them these terms so they 38 | know their rights. 39 | 40 | Developers that use the GNU GPL protect your rights with two steps: 41 | (1) assert copyright on the software, and (2) offer you this License 42 | giving you legal permission to copy, distribute and/or modify it. 43 | 44 | For the developers' and authors' protection, the GPL clearly explains 45 | that there is no warranty for this free software. For both users' and 46 | authors' sake, the GPL requires that modified versions be marked as 47 | changed, so that their problems will not be attributed erroneously to 48 | authors of previous versions. 49 | 50 | Some devices are designed to deny users access to install or run 51 | modified versions of the software inside them, although the manufacturer 52 | can do so. This is fundamentally incompatible with the aim of 53 | protecting users' freedom to change the software. The systematic 54 | pattern of such abuse occurs in the area of products for individuals to 55 | use, which is precisely where it is most unacceptable. Therefore, we 56 | have designed this version of the GPL to prohibit the practice for those 57 | products. If such problems arise substantially in other domains, we 58 | stand ready to extend this provision to those domains in future versions 59 | of the GPL, as needed to protect the freedom of users. 60 | 61 | Finally, every program is threatened constantly by software patents. 62 | States should not allow patents to restrict development and use of 63 | software on general-purpose computers, but in those that do, we wish to 64 | avoid the special danger that patents applied to a free program could 65 | make it effectively proprietary. To prevent this, the GPL assures that 66 | patents cannot be used to render the program non-free. 67 | 68 | The precise terms and conditions for copying, distribution and 69 | modification follow. 70 | 71 | TERMS AND CONDITIONS 72 | 73 | 0. Definitions. 74 | 75 | "This License" refers to version 3 of the GNU General Public License. 76 | 77 | "Copyright" also means copyright-like laws that apply to other kinds of 78 | works, such as semiconductor masks. 79 | 80 | "The Program" refers to any copyrightable work licensed under this 81 | License. Each licensee is addressed as "you". "Licensees" and 82 | "recipients" may be individuals or organizations. 83 | 84 | To "modify" a work means to copy from or adapt all or part of the work 85 | in a fashion requiring copyright permission, other than the making of an 86 | exact copy. The resulting work is called a "modified version" of the 87 | earlier work or a work "based on" the earlier work. 88 | 89 | A "covered work" means either the unmodified Program or a work based 90 | on the Program. 91 | 92 | To "propagate" a work means to do anything with it that, without 93 | permission, would make you directly or secondarily liable for 94 | infringement under applicable copyright law, except executing it on a 95 | computer or modifying a private copy. Propagation includes copying, 96 | distribution (with or without modification), making available to the 97 | public, and in some countries other activities as well. 98 | 99 | To "convey" a work means any kind of propagation that enables other 100 | parties to make or receive copies. Mere interaction with a user through 101 | a computer network, with no transfer of a copy, is not conveying. 102 | 103 | An interactive user interface displays "Appropriate Legal Notices" 104 | to the extent that it includes a convenient and prominently visible 105 | feature that (1) displays an appropriate copyright notice, and (2) 106 | tells the user that there is no warranty for the work (except to the 107 | extent that warranties are provided), that licensees may convey the 108 | work under this License, and how to view a copy of this License. If 109 | the interface presents a list of user commands or options, such as a 110 | menu, a prominent item in the list meets this criterion. 111 | 112 | 1. Source Code. 113 | 114 | The "source code" for a work means the preferred form of the work 115 | for making modifications to it. "Object code" means any non-source 116 | form of a work. 117 | 118 | A "Standard Interface" means an interface that either is an official 119 | standard defined by a recognized standards body, or, in the case of 120 | interfaces specified for a particular programming language, one that 121 | is widely used among developers working in that language. 122 | 123 | The "System Libraries" of an executable work include anything, other 124 | than the work as a whole, that (a) is included in the normal form of 125 | packaging a Major Component, but which is not part of that Major 126 | Component, and (b) serves only to enable use of the work with that 127 | Major Component, or to implement a Standard Interface for which an 128 | implementation is available to the public in source code form. A 129 | "Major Component", in this context, means a major essential component 130 | (kernel, window system, and so on) of the specific operating system 131 | (if any) on which the executable work runs, or a compiler used to 132 | produce the work, or an object code interpreter used to run it. 133 | 134 | The "Corresponding Source" for a work in object code form means all 135 | the source code needed to generate, install, and (for an executable 136 | work) run the object code and to modify the work, including scripts to 137 | control those activities. However, it does not include the work's 138 | System Libraries, or general-purpose tools or generally available free 139 | programs which are used unmodified in performing those activities but 140 | which are not part of the work. For example, Corresponding Source 141 | includes interface definition files associated with source files for 142 | the work, and the source code for shared libraries and dynamically 143 | linked subprograms that the work is specifically designed to require, 144 | such as by intimate data communication or control flow between those 145 | subprograms and other parts of the work. 146 | 147 | The Corresponding Source need not include anything that users 148 | can regenerate automatically from other parts of the Corresponding 149 | Source. 150 | 151 | The Corresponding Source for a work in source code form is that 152 | same work. 153 | 154 | 2. Basic Permissions. 155 | 156 | All rights granted under this License are granted for the term of 157 | copyright on the Program, and are irrevocable provided the stated 158 | conditions are met. This License explicitly affirms your unlimited 159 | permission to run the unmodified Program. The output from running a 160 | covered work is covered by this License only if the output, given its 161 | content, constitutes a covered work. This License acknowledges your 162 | rights of fair use or other equivalent, as provided by copyright law. 163 | 164 | You may make, run and propagate covered works that you do not 165 | convey, without conditions so long as your license otherwise remains 166 | in force. You may convey covered works to others for the sole purpose 167 | of having them make modifications exclusively for you, or provide you 168 | with facilities for running those works, provided that you comply with 169 | the terms of this License in conveying all material for which you do 170 | not control copyright. Those thus making or running the covered works 171 | for you must do so exclusively on your behalf, under your direction 172 | and control, on terms that prohibit them from making any copies of 173 | your copyrighted material outside their relationship with you. 174 | 175 | Conveying under any other circumstances is permitted solely under 176 | the conditions stated below. Sublicensing is not allowed; section 10 177 | makes it unnecessary. 178 | 179 | 3. Protecting Users' Legal Rights From Anti-Circumvention Law. 180 | 181 | No covered work shall be deemed part of an effective technological 182 | measure under any applicable law fulfilling obligations under article 183 | 11 of the WIPO copyright treaty adopted on 20 December 1996, or 184 | similar laws prohibiting or restricting circumvention of such 185 | measures. 186 | 187 | When you convey a covered work, you waive any legal power to forbid 188 | circumvention of technological measures to the extent such circumvention 189 | is effected by exercising rights under this License with respect to 190 | the covered work, and you disclaim any intention to limit operation or 191 | modification of the work as a means of enforcing, against the work's 192 | users, your or third parties' legal rights to forbid circumvention of 193 | technological measures. 194 | 195 | 4. Conveying Verbatim Copies. 196 | 197 | You may convey verbatim copies of the Program's source code as you 198 | receive it, in any medium, provided that you conspicuously and 199 | appropriately publish on each copy an appropriate copyright notice; 200 | keep intact all notices stating that this License and any 201 | non-permissive terms added in accord with section 7 apply to the code; 202 | keep intact all notices of the absence of any warranty; and give all 203 | recipients a copy of this License along with the Program. 204 | 205 | You may charge any price or no price for each copy that you convey, 206 | and you may offer support or warranty protection for a fee. 207 | 208 | 5. Conveying Modified Source Versions. 209 | 210 | You may convey a work based on the Program, or the modifications to 211 | produce it from the Program, in the form of source code under the 212 | terms of section 4, provided that you also meet all of these conditions: 213 | 214 | a) The work must carry prominent notices stating that you modified 215 | it, and giving a relevant date. 216 | 217 | b) The work must carry prominent notices stating that it is 218 | released under this License and any conditions added under section 219 | 7. This requirement modifies the requirement in section 4 to 220 | "keep intact all notices". 221 | 222 | c) You must license the entire work, as a whole, under this 223 | License to anyone who comes into possession of a copy. This 224 | License will therefore apply, along with any applicable section 7 225 | additional terms, to the whole of the work, and all its parts, 226 | regardless of how they are packaged. This License gives no 227 | permission to license the work in any other way, but it does not 228 | invalidate such permission if you have separately received it. 229 | 230 | d) If the work has interactive user interfaces, each must display 231 | Appropriate Legal Notices; however, if the Program has interactive 232 | interfaces that do not display Appropriate Legal Notices, your 233 | work need not make them do so. 234 | 235 | A compilation of a covered work with other separate and independent 236 | works, which are not by their nature extensions of the covered work, 237 | and which are not combined with it such as to form a larger program, 238 | in or on a volume of a storage or distribution medium, is called an 239 | "aggregate" if the compilation and its resulting copyright are not 240 | used to limit the access or legal rights of the compilation's users 241 | beyond what the individual works permit. Inclusion of a covered work 242 | in an aggregate does not cause this License to apply to the other 243 | parts of the aggregate. 244 | 245 | 6. Conveying Non-Source Forms. 246 | 247 | You may convey a covered work in object code form under the terms 248 | of sections 4 and 5, provided that you also convey the 249 | machine-readable Corresponding Source under the terms of this License, 250 | in one of these ways: 251 | 252 | a) Convey the object code in, or embodied in, a physical product 253 | (including a physical distribution medium), accompanied by the 254 | Corresponding Source fixed on a durable physical medium 255 | customarily used for software interchange. 256 | 257 | b) Convey the object code in, or embodied in, a physical product 258 | (including a physical distribution medium), accompanied by a 259 | written offer, valid for at least three years and valid for as 260 | long as you offer spare parts or customer support for that product 261 | model, to give anyone who possesses the object code either (1) a 262 | copy of the Corresponding Source for all the software in the 263 | product that is covered by this License, on a durable physical 264 | medium customarily used for software interchange, for a price no 265 | more than your reasonable cost of physically performing this 266 | conveying of source, or (2) access to copy the 267 | Corresponding Source from a network server at no charge. 268 | 269 | c) Convey individual copies of the object code with a copy of the 270 | written offer to provide the Corresponding Source. This 271 | alternative is allowed only occasionally and noncommercially, and 272 | only if you received the object code with such an offer, in accord 273 | with subsection 6b. 274 | 275 | d) Convey the object code by offering access from a designated 276 | place (gratis or for a charge), and offer equivalent access to the 277 | Corresponding Source in the same way through the same place at no 278 | further charge. You need not require recipients to copy the 279 | Corresponding Source along with the object code. If the place to 280 | copy the object code is a network server, the Corresponding Source 281 | may be on a different server (operated by you or a third party) 282 | that supports equivalent copying facilities, provided you maintain 283 | clear directions next to the object code saying where to find the 284 | Corresponding Source. Regardless of what server hosts the 285 | Corresponding Source, you remain obligated to ensure that it is 286 | available for as long as needed to satisfy these requirements. 287 | 288 | e) Convey the object code using peer-to-peer transmission, provided 289 | you inform other peers where the object code and Corresponding 290 | Source of the work are being offered to the general public at no 291 | charge under subsection 6d. 292 | 293 | A separable portion of the object code, whose source code is excluded 294 | from the Corresponding Source as a System Library, need not be 295 | included in conveying the object code work. 296 | 297 | A "User Product" is either (1) a "consumer product", which means any 298 | tangible personal property which is normally used for personal, family, 299 | or household purposes, or (2) anything designed or sold for incorporation 300 | into a dwelling. In determining whether a product is a consumer product, 301 | doubtful cases shall be resolved in favor of coverage. For a particular 302 | product received by a particular user, "normally used" refers to a 303 | typical or common use of that class of product, regardless of the status 304 | of the particular user or of the way in which the particular user 305 | actually uses, or expects or is expected to use, the product. A product 306 | is a consumer product regardless of whether the product has substantial 307 | commercial, industrial or non-consumer uses, unless such uses represent 308 | the only significant mode of use of the product. 309 | 310 | "Installation Information" for a User Product means any methods, 311 | procedures, authorization keys, or other information required to install 312 | and execute modified versions of a covered work in that User Product from 313 | a modified version of its Corresponding Source. The information must 314 | suffice to ensure that the continued functioning of the modified object 315 | code is in no case prevented or interfered with solely because 316 | modification has been made. 317 | 318 | If you convey an object code work under this section in, or with, or 319 | specifically for use in, a User Product, and the conveying occurs as 320 | part of a transaction in which the right of possession and use of the 321 | User Product is transferred to the recipient in perpetuity or for a 322 | fixed term (regardless of how the transaction is characterized), the 323 | Corresponding Source conveyed under this section must be accompanied 324 | by the Installation Information. But this requirement does not apply 325 | if neither you nor any third party retains the ability to install 326 | modified object code on the User Product (for example, the work has 327 | been installed in ROM). 328 | 329 | The requirement to provide Installation Information does not include a 330 | requirement to continue to provide support service, warranty, or updates 331 | for a work that has been modified or installed by the recipient, or for 332 | the User Product in which it has been modified or installed. Access to a 333 | network may be denied when the modification itself materially and 334 | adversely affects the operation of the network or violates the rules and 335 | protocols for communication across the network. 336 | 337 | Corresponding Source conveyed, and Installation Information provided, 338 | in accord with this section must be in a format that is publicly 339 | documented (and with an implementation available to the public in 340 | source code form), and must require no special password or key for 341 | unpacking, reading or copying. 342 | 343 | 7. Additional Terms. 344 | 345 | "Additional permissions" are terms that supplement the terms of this 346 | License by making exceptions from one or more of its conditions. 347 | Additional permissions that are applicable to the entire Program shall 348 | be treated as though they were included in this License, to the extent 349 | that they are valid under applicable law. If additional permissions 350 | apply only to part of the Program, that part may be used separately 351 | under those permissions, but the entire Program remains governed by 352 | this License without regard to the additional permissions. 353 | 354 | When you convey a copy of a covered work, you may at your option 355 | remove any additional permissions from that copy, or from any part of 356 | it. (Additional permissions may be written to require their own 357 | removal in certain cases when you modify the work.) You may place 358 | additional permissions on material, added by you to a covered work, 359 | for which you have or can give appropriate copyright permission. 360 | 361 | Notwithstanding any other provision of this License, for material you 362 | add to a covered work, you may (if authorized by the copyright holders of 363 | that material) supplement the terms of this License with terms: 364 | 365 | a) Disclaiming warranty or limiting liability differently from the 366 | terms of sections 15 and 16 of this License; or 367 | 368 | b) Requiring preservation of specified reasonable legal notices or 369 | author attributions in that material or in the Appropriate Legal 370 | Notices displayed by works containing it; or 371 | 372 | c) Prohibiting misrepresentation of the origin of that material, or 373 | requiring that modified versions of such material be marked in 374 | reasonable ways as different from the original version; or 375 | 376 | d) Limiting the use for publicity purposes of names of licensors or 377 | authors of the material; or 378 | 379 | e) Declining to grant rights under trademark law for use of some 380 | trade names, trademarks, or service marks; or 381 | 382 | f) Requiring indemnification of licensors and authors of that 383 | material by anyone who conveys the material (or modified versions of 384 | it) with contractual assumptions of liability to the recipient, for 385 | any liability that these contractual assumptions directly impose on 386 | those licensors and authors. 387 | 388 | All other non-permissive additional terms are considered "further 389 | restrictions" within the meaning of section 10. If the Program as you 390 | received it, or any part of it, contains a notice stating that it is 391 | governed by this License along with a term that is a further 392 | restriction, you may remove that term. If a license document contains 393 | a further restriction but permits relicensing or conveying under this 394 | License, you may add to a covered work material governed by the terms 395 | of that license document, provided that the further restriction does 396 | not survive such relicensing or conveying. 397 | 398 | If you add terms to a covered work in accord with this section, you 399 | must place, in the relevant source files, a statement of the 400 | additional terms that apply to those files, or a notice indicating 401 | where to find the applicable terms. 402 | 403 | Additional terms, permissive or non-permissive, may be stated in the 404 | form of a separately written license, or stated as exceptions; 405 | the above requirements apply either way. 406 | 407 | 8. Termination. 408 | 409 | You may not propagate or modify a covered work except as expressly 410 | provided under this License. Any attempt otherwise to propagate or 411 | modify it is void, and will automatically terminate your rights under 412 | this License (including any patent licenses granted under the third 413 | paragraph of section 11). 414 | 415 | However, if you cease all violation of this License, then your 416 | license from a particular copyright holder is reinstated (a) 417 | provisionally, unless and until the copyright holder explicitly and 418 | finally terminates your license, and (b) permanently, if the copyright 419 | holder fails to notify you of the violation by some reasonable means 420 | prior to 60 days after the cessation. 421 | 422 | Moreover, your license from a particular copyright holder is 423 | reinstated permanently if the copyright holder notifies you of the 424 | violation by some reasonable means, this is the first time you have 425 | received notice of violation of this License (for any work) from that 426 | copyright holder, and you cure the violation prior to 30 days after 427 | your receipt of the notice. 428 | 429 | Termination of your rights under this section does not terminate the 430 | licenses of parties who have received copies or rights from you under 431 | this License. If your rights have been terminated and not permanently 432 | reinstated, you do not qualify to receive new licenses for the same 433 | material under section 10. 434 | 435 | 9. Acceptance Not Required for Having Copies. 436 | 437 | You are not required to accept this License in order to receive or 438 | run a copy of the Program. Ancillary propagation of a covered work 439 | occurring solely as a consequence of using peer-to-peer transmission 440 | to receive a copy likewise does not require acceptance. However, 441 | nothing other than this License grants you permission to propagate or 442 | modify any covered work. These actions infringe copyright if you do 443 | not accept this License. Therefore, by modifying or propagating a 444 | covered work, you indicate your acceptance of this License to do so. 445 | 446 | 10. Automatic Licensing of Downstream Recipients. 447 | 448 | Each time you convey a covered work, the recipient automatically 449 | receives a license from the original licensors, to run, modify and 450 | propagate that work, subject to this License. You are not responsible 451 | for enforcing compliance by third parties with this License. 452 | 453 | An "entity transaction" is a transaction transferring control of an 454 | organization, or substantially all assets of one, or subdividing an 455 | organization, or merging organizations. If propagation of a covered 456 | work results from an entity transaction, each party to that 457 | transaction who receives a copy of the work also receives whatever 458 | licenses to the work the party's predecessor in interest had or could 459 | give under the previous paragraph, plus a right to possession of the 460 | Corresponding Source of the work from the predecessor in interest, if 461 | the predecessor has it or can get it with reasonable efforts. 462 | 463 | You may not impose any further restrictions on the exercise of the 464 | rights granted or affirmed under this License. For example, you may 465 | not impose a license fee, royalty, or other charge for exercise of 466 | rights granted under this License, and you may not initiate litigation 467 | (including a cross-claim or counterclaim in a lawsuit) alleging that 468 | any patent claim is infringed by making, using, selling, offering for 469 | sale, or importing the Program or any portion of it. 470 | 471 | 11. Patents. 472 | 473 | A "contributor" is a copyright holder who authorizes use under this 474 | License of the Program or a work on which the Program is based. The 475 | work thus licensed is called the contributor's "contributor version". 476 | 477 | A contributor's "essential patent claims" are all patent claims 478 | owned or controlled by the contributor, whether already acquired or 479 | hereafter acquired, that would be infringed by some manner, permitted 480 | by this License, of making, using, or selling its contributor version, 481 | but do not include claims that would be infringed only as a 482 | consequence of further modification of the contributor version. For 483 | purposes of this definition, "control" includes the right to grant 484 | patent sublicenses in a manner consistent with the requirements of 485 | this License. 486 | 487 | Each contributor grants you a non-exclusive, worldwide, royalty-free 488 | patent license under the contributor's essential patent claims, to 489 | make, use, sell, offer for sale, import and otherwise run, modify and 490 | propagate the contents of its contributor version. 491 | 492 | In the following three paragraphs, a "patent license" is any express 493 | agreement or commitment, however denominated, not to enforce a patent 494 | (such as an express permission to practice a patent or covenant not to 495 | sue for patent infringement). To "grant" such a patent license to a 496 | party means to make such an agreement or commitment not to enforce a 497 | patent against the party. 498 | 499 | If you convey a covered work, knowingly relying on a patent license, 500 | and the Corresponding Source of the work is not available for anyone 501 | to copy, free of charge and under the terms of this License, through a 502 | publicly available network server or other readily accessible means, 503 | then you must either (1) cause the Corresponding Source to be so 504 | available, or (2) arrange to deprive yourself of the benefit of the 505 | patent license for this particular work, or (3) arrange, in a manner 506 | consistent with the requirements of this License, to extend the patent 507 | license to downstream recipients. "Knowingly relying" means you have 508 | actual knowledge that, but for the patent license, your conveying the 509 | covered work in a country, or your recipient's use of the covered work 510 | in a country, would infringe one or more identifiable patents in that 511 | country that you have reason to believe are valid. 512 | 513 | If, pursuant to or in connection with a single transaction or 514 | arrangement, you convey, or propagate by procuring conveyance of, a 515 | covered work, and grant a patent license to some of the parties 516 | receiving the covered work authorizing them to use, propagate, modify 517 | or convey a specific copy of the covered work, then the patent license 518 | you grant is automatically extended to all recipients of the covered 519 | work and works based on it. 520 | 521 | A patent license is "discriminatory" if it does not include within 522 | the scope of its coverage, prohibits the exercise of, or is 523 | conditioned on the non-exercise of one or more of the rights that are 524 | specifically granted under this License. You may not convey a covered 525 | work if you are a party to an arrangement with a third party that is 526 | in the business of distributing software, under which you make payment 527 | to the third party based on the extent of your activity of conveying 528 | the work, and under which the third party grants, to any of the 529 | parties who would receive the covered work from you, a discriminatory 530 | patent license (a) in connection with copies of the covered work 531 | conveyed by you (or copies made from those copies), or (b) primarily 532 | for and in connection with specific products or compilations that 533 | contain the covered work, unless you entered into that arrangement, 534 | or that patent license was granted, prior to 28 March 2007. 535 | 536 | Nothing in this License shall be construed as excluding or limiting 537 | any implied license or other defenses to infringement that may 538 | otherwise be available to you under applicable patent law. 539 | 540 | 12. No Surrender of Others' Freedom. 541 | 542 | If conditions are imposed on you (whether by court order, agreement or 543 | otherwise) that contradict the conditions of this License, they do not 544 | excuse you from the conditions of this License. If you cannot convey a 545 | covered work so as to satisfy simultaneously your obligations under this 546 | License and any other pertinent obligations, then as a consequence you may 547 | not convey it at all. For example, if you agree to terms that obligate you 548 | to collect a royalty for further conveying from those to whom you convey 549 | the Program, the only way you could satisfy both those terms and this 550 | License would be to refrain entirely from conveying the Program. 551 | 552 | 13. Use with the GNU Affero General Public License. 553 | 554 | Notwithstanding any other provision of this License, you have 555 | permission to link or combine any covered work with a work licensed 556 | under version 3 of the GNU Affero General Public License into a single 557 | combined work, and to convey the resulting work. The terms of this 558 | License will continue to apply to the part which is the covered work, 559 | but the special requirements of the GNU Affero General Public License, 560 | section 13, concerning interaction through a network will apply to the 561 | combination as such. 562 | 563 | 14. Revised Versions of this License. 564 | 565 | The Free Software Foundation may publish revised and/or new versions of 566 | the GNU General Public License from time to time. Such new versions will 567 | be similar in spirit to the present version, but may differ in detail to 568 | address new problems or concerns. 569 | 570 | Each version is given a distinguishing version number. If the 571 | Program specifies that a certain numbered version of the GNU General 572 | Public License "or any later version" applies to it, you have the 573 | option of following the terms and conditions either of that numbered 574 | version or of any later version published by the Free Software 575 | Foundation. If the Program does not specify a version number of the 576 | GNU General Public License, you may choose any version ever published 577 | by the Free Software Foundation. 578 | 579 | If the Program specifies that a proxy can decide which future 580 | versions of the GNU General Public License can be used, that proxy's 581 | public statement of acceptance of a version permanently authorizes you 582 | to choose that version for the Program. 583 | 584 | Later license versions may give you additional or different 585 | permissions. However, no additional obligations are imposed on any 586 | author or copyright holder as a result of your choosing to follow a 587 | later version. 588 | 589 | 15. Disclaimer of Warranty. 590 | 591 | THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY 592 | APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT 593 | HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY 594 | OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, 595 | THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 596 | PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM 597 | IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF 598 | ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 599 | 600 | 16. Limitation of Liability. 601 | 602 | IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING 603 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS 604 | THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY 605 | GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE 606 | USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF 607 | DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD 608 | PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), 609 | EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF 610 | SUCH DAMAGES. 611 | 612 | 17. Interpretation of Sections 15 and 16. 613 | 614 | If the disclaimer of warranty and limitation of liability provided 615 | above cannot be given local legal effect according to their terms, 616 | reviewing courts shall apply local law that most closely approximates 617 | an absolute waiver of all civil liability in connection with the 618 | Program, unless a warranty or assumption of liability accompanies a 619 | copy of the Program in return for a fee. 620 | 621 | END OF TERMS AND CONDITIONS 622 | 623 | How to Apply These Terms to Your New Programs 624 | 625 | If you develop a new program, and you want it to be of the greatest 626 | possible use to the public, the best way to achieve this is to make it 627 | free software which everyone can redistribute and change under these terms. 628 | 629 | To do so, attach the following notices to the program. It is safest 630 | to attach them to the start of each source file to most effectively 631 | state the exclusion of warranty; and each file should have at least 632 | the "copyright" line and a pointer to where the full notice is found. 633 | 634 | 635 | Copyright (C) 636 | 637 | This program is free software: you can redistribute it and/or modify 638 | it under the terms of the GNU General Public License as published by 639 | the Free Software Foundation, either version 3 of the License, or 640 | (at your option) any later version. 641 | 642 | This program is distributed in the hope that it will be useful, 643 | but WITHOUT ANY WARRANTY; without even the implied warranty of 644 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 645 | GNU General Public License for more details. 646 | 647 | You should have received a copy of the GNU General Public License 648 | along with this program. If not, see . 649 | 650 | Also add information on how to contact you by electronic and paper mail. 651 | 652 | If the program does terminal interaction, make it output a short 653 | notice like this when it starts in an interactive mode: 654 | 655 | Copyright (C) 656 | This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'. 657 | This is free software, and you are welcome to redistribute it 658 | under certain conditions; type `show c' for details. 659 | 660 | The hypothetical commands `show w' and `show c' should show the appropriate 661 | parts of the General Public License. Of course, your program's commands 662 | might be different; for a GUI interface, you would use an "about box". 663 | 664 | You should also get your employer (if you work as a programmer) or school, 665 | if any, to sign a "copyright disclaimer" for the program, if necessary. 666 | For more information on this, and how to apply and follow the GNU GPL, see 667 | . 668 | 669 | The GNU General Public License does not permit incorporating your program 670 | into proprietary programs. If your program is a subroutine library, you 671 | may consider it more useful to permit linking proprietary applications with 672 | the library. If this is what you want to do, use the GNU Lesser General 673 | Public License instead of this License. But first, please read 674 | . 675 | 676 | 677 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | This is the specification of the Oberon+ programming language 2 | written in AsciiDoc format. 3 | The HTML version is rendered using https://asciidoclive.com. 4 | 5 | For the compiler and the IDE see https://github.com/rochus-keller/Oberon. 6 | -------------------------------------------------------------------------------- /The_Programming_Language_Oberon+.adoc: -------------------------------------------------------------------------------- 1 | // This file may be used under the terms of the GNU General Public 2 | // License (GPL) versions 2.0 or 3.0 as published by the Free Software 3 | // Foundation, see http://www.gnu.org/copyleft/gpl.html for more information 4 | 5 | // missing in AsciiDoc: 6 | // - clear concept how to add line breaks to tables without physically breaking lines in the adoc source 7 | // - table in labeled list item 8 | // - referencable title id independent of text 9 | // - reference format as title number instead of name, or both combined 10 | 11 | = The Programming Language Oberon+ 12 | :author: Rochus Keller 13 | :email: me@rochus-keller.ch 14 | :revdate: 2023-09-29 15 | :revremark: work in progress 16 | :doctype: article 17 | :listing-caption: Listing 18 | :sectnums: 19 | :toc: left 20 | 21 | [dedication] 22 | Based on work by Niklaus Wirth and Hanspeter Mössenböck (<>, <>). 23 | 24 | == Introduction 25 | Oberon+ (i.e. _Oberon with extensions_, abbreviated *OBX*, pronounced _obex_) is a general-purpose, procedural and object-oriented programming language in the tradition of Oberon-07 <> and Oberon-2 <>. 26 | 27 | The most important features of Oberon+ are block structure, modularity, separate compilation, static typing with strong type checking, generic programming footnote:[generic modules, inspired by <>], garbage collection, and type extension with type-bound procedures. 28 | 29 | A major design goal of Oberon in 1987 was to make the language as simple as possible <>. Oberon+ follows the same goal, but taking into account the current state of the art. Backwards compatibility remains ensured: each valid Oberon-2 or Oberon-07 program is also a valid Oberon+ program. 30 | 31 | The language allows several simplifications compared to previous Oberon versions: reserved words can be written in lower case, all semicolons are optional, and for some reserved words there are shorter variants; a declaration sequence can contain more than one CONST, TYPE and VAR section in arbitrary order, interleaved with procedures. 32 | 33 | Furthermore, enumeration types (known as _scalar types_ in Pascal <>), type-bound procedure types, explicit bit operations and exception handling have been added to the language. IN can be used instead of VAR for constant variable parameters. The length of array type local variable can be specified at runtime (VLA). The foreign function interface (FFI) is a regular feature of the language. 34 | 35 | This report is not intended as a programmer's tutorial. It is intentionally kept concise. Its function is to serve as a reference for programmers, implementors, and tutorial writers. What remains unsaid is mostly left so intentionally, either because it can be derived from stated rules of the language, or because it would require to commit the definition when a general commitment appears as unwise. 36 | 37 | .Oberon+ example featuring syntactic simplifications and type parameters 38 | [[obx-generics-example]] 39 | [source,oberon] 40 | ---- 41 | module Lists(T) 42 | type 43 | List* = ^record 44 | value* : T 45 | next* : List 46 | end 47 | 48 | proc (l : List) Add* (v : T) 49 | begin 50 | new( l.next ) 51 | l.next.value := v 52 | end Add 53 | 54 | proc (l : List) Print*() 55 | begin 56 | println(l.value) 57 | end Print 58 | end Lists 59 | 60 | module ListTest 61 | import 62 | L := Lists(integer) 63 | var 64 | l : L.List 65 | begin 66 | new(l) 67 | l.value := 123 68 | l.Add(456) 69 | l.Print() 70 | l.next.Print() 71 | end ListTest 72 | ---- 73 | 74 | See <> for more examples. 75 | 76 | == Syntax 77 | An extended Backus-Naur Formalism (EBNF) is used to describe the syntax of Oberon+: 78 | 79 | - Alternatives are separated by *|*. 80 | - Brackets *[* and *]* denote optionality of the enclosed expression. 81 | - Braces *{* and *}* denote its repetition (possibly 0 times). 82 | - Syntactic entities (non-terminal symbols) are denoted by English words expressing their intuitive meaning. 83 | - Symbols of the language vocabulary (terminal symbols) are denoted by strings enclosed in quotation marks or by words in capital letters. 84 | 85 | == Vocabulary and Representation 86 | Oberon+ source code is a string of characters encoded using the UTF-8 variable-width encoding as defined in ISO/IEC 10646. 87 | Identifiers, numbers, operators, and delimiters are represented using the ASCII character set; strings and comments can be either represented in the ASCII, Latin-1 (as defined in ISO/IEC 8859-1) or the Unicode Basic Multilingual Plane (BMP, plane 0, as defined in ISO/IEC 10646) character set. 88 | 89 | The following lexical rules apply: blanks and line breaks must not occur within symbols (except in comments, and blanks in strings); they are ignored unless they are essential to separate two consecutive symbols. Capital and lower-case letters are considered as distinct. 90 | 91 | === Identifiers 92 | Identifiers are sequences of letters, digits and underscore. The first character must be a letter or an underscore. 93 | 94 | .Syntax: 95 | .... 96 | ident = ( letter | '_' ) { letter | digit | '_' } 97 | letter = 'A' ... 'Z' | 'a' ... 'z' 98 | digit = '0' ... '9' 99 | .... 100 | 101 | .Examples: 102 | .... 103 | x 104 | Scan 105 | Oberon_2 106 | _y 107 | firstLetter 108 | .... 109 | 110 | === Numbers 111 | Number literals are (unsigned) integer or real constants. The type of an integer literal is the minimal type to which the constant value belongs (see <>). If the literal is specified with the suffix `H` (or `h`), the representation is hexadecimal otherwise the representation is decimal. If a decimal or hexadecimal literal is specified with the suffix `I` (or `i`), then the type is `INT32`. If a decimal or hexadecimal constant is specified with the suffix `L` (or `l`), then the type is `INT64`. 112 | 113 | A real number always contains a decimal point and at least one digit before the point. Optionally it may also contain a decimal scale factor. The letter `E`, `D` or `S` (or `e`, `d` or `s`) means _times ten to the power of_. A real number is of type `LONGREAL`, if it has a scale factor containing the letter `D`, or of type `REAL`, if it has a scale factor containing the letter `S`. If the scale factor contains the letter `E` the type is `LONGREAL` if the mantissa or exponent are too large to be represented by `REAL`. 114 | 115 | .Syntax: 116 | .... 117 | number = integer | real 118 | integer = ( digit {digit} | digit {hexDigit} ('H' | 'h') ) ['L' | 'l' | 'I' | 'i'] 119 | real = digit {digit} '.' {digit} [Exponent] 120 | Exponent = ('E' | 'e' | 'D' | 'd' | 'S' | 's') ['+' | '-'] digit {digit} 121 | hexDigit = digit | 'A' ... 'F' | 'a' ... 'f' 122 | digit = '0' ... '9' 123 | .... 124 | 125 | .Examples: 126 | .... 127 | 1234 128 | 0dh 0DH 129 | 12.3 130 | 4.567e8 4.567E8 131 | 0.57712566d-6 0.57712566D-6 132 | .... 133 | 134 | === Characters 135 | Character constants are denoted by the ordinal number of the character in hexadecimal notation followed by the letter `X` (or `x`). 136 | 137 | .Syntax: 138 | .... 139 | character = digit {hexDigit} ('X' | 'x') 140 | .... 141 | 142 | A character is either encoded as a 8-bit code value using the ISO/IEC 8859-1 Latin-1 encoding scheme or a 16-bit code value using the Unicode BMP scheme. 143 | 144 | === Strings 145 | Strings are sequences of printable characters enclosed in single (') or double (") quote marks. The opening quote must be the same as the closing quote and must not occur within the string. A string must not extend over the end of a line. The number of characters in a string is called its length. A string of length 1 can be used wherever a character constant is allowed and vice versa. 146 | 147 | .Syntax: 148 | .... 149 | string = ''' {character} ''' | '"' {character} '"' 150 | .... 151 | 152 | .Examples: 153 | .... 154 | 'Oberon' 155 | "Don't worry!" 156 | 'x' 157 | .... 158 | 159 | ==== Hex Strings 160 | Hex strings are sequences of bytes encoded in hexadecimal format and enclosed in dollar signs. The number of hex digits in the string must be even, two hex digits per byte. The number of bytes in a hex string is called its length. Line breaks and other white space between the dollar signs is ignored. 161 | 162 | .Syntax: 163 | .... 164 | hexstring = '$' {hexDigit} '$' 165 | .... 166 | 167 | .Examples: 168 | .... 169 | const arrow = $0F0F 0060 0070 0038 001C 000E 0007 8003 170 | C101 E300 7700 3F00 1F00 3F00 7F00 FF00$ 171 | .... 172 | 173 | [NOTE] 174 | Hex strings are not specified in <> but are used by the Project Oberon implementation, e.g. in Display.Mod. Hex strings are useful to represent all kinds of binary resources such as images and icons in the source code. 175 | 176 | === Operators and Delimiters 177 | Operators and delimiters are the special characters, or character pairs listed below. 178 | [cols="1,1,1,1,1,1"] 179 | |=== 180 | |- 181 | |, 182 | |; 183 | |: 184 | |:= 185 | |. 186 | |.. 187 | |( 188 | |) 189 | |[ 190 | |] 191 | |{ 192 | |} 193 | |* 194 | |/ 195 | |# 196 | |^ 197 | |+ 198 | |\<= 199 | |= 200 | |>= 201 | |\| 202 | |~ 203 | | 204 | | 205 | |=== 206 | 207 | 208 | === Reserved Words 209 | The reserved words consist of either all capital or all lower case letters and cannot be used as identifiers. All words listed below are reserved (only capital letter versions shown). 210 | [cols="1,1,1,1,1"] 211 | |=== 212 | |ARRAY 213 | |BEGIN 214 | |BY 215 | |CASE 216 | |CONST 217 | |DEFINITION 218 | |DIV 219 | |DO 220 | |ELSE 221 | |ELSIF 222 | |END 223 | |EXIT 224 | |FALSE 225 | |FOR 226 | |IF 227 | |IMPORT 228 | |IN 229 | |IS 230 | |LOOP 231 | |MOD 232 | |MODULE 233 | |NIL 234 | |OF 235 | |OR 236 | |POINTER 237 | |PROC 238 | |PROCEDURE 239 | |RECORD 240 | |REPEAT 241 | |RETURN 242 | |THEN 243 | |TO 244 | |TRUE 245 | |TYPE 246 | |UNTIL 247 | |VAR 248 | |WHILE 249 | |WITH 250 | | 251 | | 252 | |=== 253 | 254 | [NOTE] 255 | WITH, LOOP and EXIT are Oberon-2 reserved words not present in Oberon-07. In contrast TRUE and FALSE are Oberon-07 and Oberon+ reserved words but just predeclared identifiers in Oberon-2. DEFINITION and PROC are Oberon+ reserved words not present in previous Oberon versions. All lower-case versions are only reserved words in Oberon+. The compiler is supposed to offer a dedicated Oberon-2 and Oberon-07 compatibility mode to support legacy code with reserved word collisions. 256 | 257 | === Comments 258 | Comments are arbitrary character sequences opened by the bracket `(\*` and closed by `*)`. Comments may be nested. They do not affect the meaning of a program. Oberon+ also supports line comments; text starting with `//` up to a line break is considered a comment. 259 | 260 | == Declarations and scope rules 261 | Every identifier occurring in a program must be introduced by a declaration, unless it is a predeclared identifier. Declarations also specify certain permanent properties of an object, such as whether it is a constant, a type, a variable, or a procedure. The identifier is then used to refer to the associated object. 262 | 263 | The scope of an object x is the whole block (module, procedure, or record) to which the declaration belongs and hence to which the object is local. It excludes the scopes of equally named objects which are declared in nested blocks. The scope rules are: 264 | 265 | 1. No identifier may denote more than one object within a given scope (i.e. no identifier may be declared twice in a block); 266 | 2. An object may only be referenced within its scope; 267 | 3. The order of declaration is not significant; 268 | 4. Identifiers denoting record fields (see <>) or type-bound procedures (see <>) are valid in record designators only. 269 | 270 | An identifier declared in a module block may be followed by an export mark (`*` or `-`) in its declaration to indicate that it is exported. An identifier `x` exported by a module `M` may be used in other modules, if they import `M` (see <>). The identifier is then denoted as `M.x` in these modules and is called a qualified identifier. Identifiers marked with `-` in their declaration are read-only in importing modules. 271 | 272 | .Syntax: 273 | .... 274 | qualident = [ident '.'] ident 275 | identdef = ident ['*' | '-'] 276 | .... 277 | 278 | [NOTE] 279 | Oberon-07 only knows the `*` export mark; all module variables are exported read-only and exported record fields are writable. Oberon+ and Oberon-2 permit finer writability control of exported variables and fields. 280 | 281 | The following identifiers are predeclared; their meaning is defined in the indicated sections; either all capital or all lower case identifiers are supported (only capital versions shown). 282 | [cols="1,1,1,1"] 283 | |=== 284 | |ABS 285 | |ANYREC 286 | |ASH 287 | |ASR 288 | |ASSERT 289 | |BITAND 290 | |BITNOT 291 | |BITOR 292 | |BITS 293 | |BITSHL 294 | |BITSHR 295 | |BITXOR 296 | |BOOLEAN 297 | |BYTE 298 | |BYTES 299 | |CAST 300 | |CAP 301 | |CHAR 302 | |CHR 303 | |COPY 304 | |DEC 305 | |DEFAULT 306 | |ENTIER 307 | |EXCL 308 | |FLOOR 309 | |FLT 310 | |HALT 311 | |INC 312 | |INCL 313 | |INT8 314 | |INT16 315 | |INT32 316 | |INT64 317 | |INTEGER 318 | |LEN 319 | |LONG 320 | |LONGINT 321 | |LONGREAL 322 | |LSL 323 | |MAX 324 | |MIN 325 | |NEW 326 | |NUMBER 327 | |ODD 328 | |ORD 329 | |PACK 330 | |PCALL 331 | |RAISE 332 | |REAL 333 | |ROR 334 | |SET 335 | |SHORT 336 | |SHORTINT 337 | |SIZE 338 | |UNPK 339 | |WCHR 340 | | 341 | | 342 | | 343 | |=== 344 | 345 | [NOTE] 346 | BYTE, ASR, FLOOR, ROR, LSL, FLT, PACK and UNPK are predeclared identifiers in Oberon-07 and Oberon+, but not in Oberon-2. All lower-case versions are only predeclared in Oberon+. 347 | 348 | == Constant declarations 349 | A constant declaration associates an identifier with a constant value. 350 | 351 | .Syntax: 352 | .... 353 | ConstDeclaration = identdef '=' ConstExpression 354 | ConstExpression = expression 355 | .... 356 | 357 | A constant expression is an expression that can be evaluated by a mere textual scan without actually executing the program. Its operands are constants (see <>) or predeclared functions (see <>) that can be evaluated at compile time. Examples of constant declarations are: 358 | 359 | .Examples: 360 | .... 361 | N = 100 362 | limit = 2*N - 1 363 | fullSet = {min(set) .. max(set)} 364 | .... 365 | 366 | [NOTE] 367 | For compile time calculations of values the same rules as for runtime calculation apply. The ConstExpression of ConstDeclaration behaves as if each use of the constant identifier was replaced by the ConstExpression. An expression like `MAX(INTEGER)+1` thus causes an overflow of the INTEGER range. To avoid this either `LONG(MAX(INTEGER))+1` or `MAX(INTEGER)+1L` has to be used. 368 | 369 | == Type declarations 370 | A data type determines the set of values which variables of that type may assume, and the operators that are applicable. A type declaration associates an identifier with a type. In the case of structured types (arrays and records) it also defines the structure of variables of this type. A structured type cannot contain itself. 371 | 372 | .Syntax: 373 | .... 374 | TypeDeclaration = identdef '=' type 375 | type = NamedType | ArrayType | RecordType 376 | | PointerType | ProcedureType | enumeration 377 | NamedType = qualident 378 | .... 379 | 380 | .Examples: 381 | .... 382 | Table = array N of real 383 | Tree = pointer to Node 384 | Node = record 385 | key: integer 386 | left, right: Tree 387 | end 388 | CenterTree = pointer to CenterNode 389 | CenterNode = record (Node) 390 | width: integer 391 | subnode: Tree 392 | end 393 | Function = procedure(x: integer): integer 394 | .... 395 | 396 | === Basic types 397 | The basic types are denoted by predeclared identifiers. The associated operators are defined in <> and the predeclared function procedures in <>. Either all capital or all lower case identifiers are supported (only capital versions shown). There are fixed and variable size basic types. For the fixed size basic types the byte widths and ranges are explicitly specified herein. The variable size basic types are just alternative names for the fixed size integer types. 398 | 399 | The values of the given fixed size basic types are the following: 400 | 401 | [cols="2,1,5"] 402 | |==================================================== 403 | | BOOLEAN | 1 byte | the truth values true and false 404 | | BYTE | 1 byte | the integers between 0 and 255 405 | | CHAR | 1 byte | the characters of the Latin-1 set (0x .. 0ffx) 406 | | INT8 | 1 byte | the integers between -128 and 127 407 | | INT16 | 2 byte | the integers between -32'768 and 32'767 408 | | INT32 | 4 byte | the integers between -2'147'483'648 and 2'147'483'647 409 | | INT64 | 8 byte | the integers between -9'223'372'036'854'775'808 and 9'223'372'036'854'775'807 410 | | REAL | 32 bit | an IEEE 754 floating point number 411 | | LONGREAL | 64 bit | an IEEE 754 floating point number 412 | | SET | 4 byte | the sets of integers between 0 and MAX(SET) 413 | | WCHAR | 2 byte | the characters of the Unicode BMP set (0x .. 0d7ffx, 0f900x .. 0ffffx) 414 | |==================================================== 415 | 416 | The values of the given variable size basic types are the following: 417 | 418 | [cols="2,5"] 419 | |==================================================== 420 | | SHORTINT | the integers between MIN(SHORTINT) and MAX(SHORTINT) 421 | | INTEGER | the integers between MIN(INTEGER) and MAX(INTEGER) 422 | | LONGINT | the integers between MIN(LONGINT) and MAX(LONGINT) 423 | |==================================================== 424 | 425 | Types INT64, INT32, INT16, INT8, LONGINT, INTEGER, SHORTINT and BYTE are integer types, types REAL and LONGREAL are floating point types, and together they are called numeric types. The larger type includes (the values of) the smaller type according to the following relations: 426 | 427 | [[type-inclusion-relations]] 428 | .... 429 | INT64 >= INT32 >= INT16 >= INT8 430 | INT16 >= BYTE 431 | LONGREAL >= REAL 432 | REAL >= INT16 433 | LONGREAL >= INT32 434 | WCHAR >= CHAR 435 | LONGINT >= INTEGER >= SHORTINT 436 | .... 437 | 438 | [NOTE] 439 | Because of the limited bit precision of the LONGREAL mantissa (which is 52 bits in IEEE 754 double precision representation), a LONGREAL does not fully include INT64. Similarly REAL does not include the full range of INT32. To convert a INT64 to a LONGREAL or an INT32 to a REAL the FLT() built-in function should be used to . 440 | 441 | A compiler may support other type inclusion relations in addition to the ones specified herein, but shall at least issue a warning if in a given operation information could be lost. A compiler shall at least support the Oberon 90 and Oberon-2 type inclusion relations in this way. 442 | 443 | A compiler may map the variable size integer names to any of the fixed size integers as long as the inclusion relations are obeyed. By default a correspondence of LONGINT with INT64, INTEGER with INT32 and SHORTINT with INT16 is assumed. 444 | 445 | [NOTE] 446 | Oberon 90 and Oberon-2 specify the following type inclusion relations assuming that LONGINT maps to INT32, INTEGER to INT16 and SHORTINT to INT8: LONGREAL >= REAL >= LONGINT >= INTEGER >= SHORTINT. 447 | 448 | === Array types 449 | An array is a structure consisting of a number of elements which are all of the same type, called the element type. The number of elements of an array is called its length. The length is a positive integer. The elements of the array are designated by indices, which are integers between 0 and the length minus 1. Zero array length are supported in declarations, but accessing such arrays halts the program. 450 | 451 | .Syntax: 452 | .... 453 | ArrayType = ARRAY [ LengthList ] OF type 454 | | '[' [ LengthList ] ']' type 455 | LengthList = length {',' length} | VAR varlength {',' varlength} 456 | length = ConstExpression 457 | varlength = expression 458 | .... 459 | 460 | A type of the form 461 | 462 | .... 463 | array L0, L1, ..., Ln of T 464 | .... 465 | 466 | is an abbreviation for 467 | 468 | .... 469 | array L0 of array L1 of ... array Ln of T 470 | .... 471 | 472 | Arrays declared without length are called _open arrays_. They are restricted to pointer base types (see <>), element types of open array types, and formal parameter types (see <>). 473 | 474 | .Examples: 475 | .... 476 | array 10, N of integer 477 | array of char 478 | [N][M] T 479 | .... 480 | 481 | Local variables of array type can have variable lengths calculated at runtime; in this case the LengthList is prefixed with the VAR reserved word; the expression cannot reference other local variables of the same scope. 482 | 483 | [NOTE] 484 | In contrast to array pointers allocated with new(), variable length arrays (VLA) can be allocated on the stack instead of the heap (depending on the compiler and supported options), which makes them attractive to low-resource embedded applications where dynamic memory allocation is not feasible. It is also interesting to note that already the length/range of ALGOL 60 arrays was defined using an ordinary arithmetic expression and thus could be calculated at runtime; even ALGOL W had this feature, but unfortunately it was removed in Pascal, and even Oberon-07 still uses a const expression for array lengths evaluated at compile time. 485 | 486 | Array lengths at least up to MAX(INT32) shall be supported by a compiler, for both constant and variable lengths. 487 | 488 | === Record types 489 | A record type is a structure consisting of a fixed number of elements, called fields, with possibly different types. The record type declaration specifies the name and type of each field. The scope of the field identifiers extends from the point of their declaration to the end of the record type, but they are also visible within designators referring to elements of record variables (see <>). If a record type is exported, field identifiers that are to be visible outside the declaring module must be marked. They are called public fields; unmarked elements are called private fields. 490 | 491 | .Syntax: 492 | .... 493 | RecordType = RECORD ['(' BaseType ')'] 494 | FieldList { [';'] FieldList} END 495 | BaseType = NamedType 496 | FieldList = [ IdentList ':' type ] 497 | IdentList = identdef { [','] identdef } 498 | .... 499 | 500 | Record types are extensible, i.e. a record type can be declared as an extension of another record type. In the example 501 | 502 | .... 503 | T0 = record x: integer end 504 | T1 = record (T0) y: real end 505 | .... 506 | 507 | T1 is a (direct) _extension_ of T0 and T0 is the (direct) base type of T1 (see <>). An extended type T1 consists of the fields of its base type and of the fields which are declared in T1. Fields declared in the extended record shadow equally named fields declared in a base type. 508 | 509 | // TODO shall we really support this: 510 | // A pointer field of the base record can be re-declared in the extended record with a pointer type which is an extension of the corresponding base record field type footnote:[this corresponds to the implementation of the Blackbox framework 1.7, see https://blackboxframework.org <>]. 511 | 512 | Alternatively, a pointer to record type can be used as the BaseType; in this case the record base type of the pointer is used as the base type of the declared record. 513 | 514 | Each record is implicitly an extension of the predeclared record type ANYREC. ANYREC does not contain any fields and can only be used in pointer and variable parameter declarations. 515 | 516 | .Examples: 517 | .... 518 | record 519 | day, month, year: integer 520 | end 521 | 522 | record 523 | name, firstname: array 32 of char 524 | age: integer 525 | salary: real 526 | end 527 | .... 528 | 529 | === Pointer types 530 | Variables of a pointer type P assume as values pointers to variables of some type T. T is called the pointer base type of P and must be a record or array type. Pointer types adopt the _extension_ relation of their pointer base types: if a type T1 is an extension of T, and P1 is of type `POINTER TO T1`, then P1 is also an extension of P (see <>). 531 | 532 | .Syntax: 533 | .... 534 | PointerType = ( POINTER TO | '^' ) type 535 | .... 536 | 537 | If p is a variable of type `P = POINTER TO T`, a call of the predeclared procedure `NEW(p)` (see <>) allocates a variable of type T in free storage. If T is a record type or an array type with fixed length, the allocation has to be done with `NEW(p)`; if T is an n-dimensional open array type the allocation has to be done with `NEW(p, e~0~, ..., e~n-1~)` where T is allocated with lengths given by the expressions e~0~, ..., e~n-1~. In either case a pointer to the allocated variable is assigned to `p`. `p` is of type P. The referenced variable `p^` is of type T. Any pointer variable may assume the value NIL, which points to no variable at all. All pointer fields or elements of a newly allocated record or array are set to NIL. 538 | 539 | [NOTE] 540 | Oberon doesn't support taking the address (i.e. making a pointer) of a variable, parameter or record field. If you need a pointer the record or array has to be allocated using NEW(). 541 | 542 | === Procedure types 543 | Variables of a procedure type T have a procedure (or NIL) as value. If a procedure P is assigned to a variable of type T, the formal parameter lists and result types (see <>) of P and T must _match_ (see <>). A procedure P assigned to a variable or a formal parameter must not be a predeclared, nor a type-bound procedure, nor may it access local variables or parameters declared in outer (type-bound) procedures or call procedure which access local variables or parameters declared in outer (type-bound) procedures. 544 | 545 | [NOTE] 546 | Oberon 90, 2 and 07 don't support assignment of procedures local to another procedure to a procedure type variable. Oberon+ doesn't make this restriction, as long as the local procedure (or one of its nested procedures) isn't nested and doesn't depend on local variables or parameters declared in its enclosing procedure. 547 | 548 | .Syntax: 549 | .... 550 | ProcedureType = PROCEDURE [FormalParameters] 551 | .... 552 | 553 | === Enumeration types 554 | An enumeration is a list of identifiers that denote the values which constitute a data type. 555 | These identifiers are used as constants in the program. They, and no other values, belong to 556 | this type. The values are ordered. and the ordering relation is defined by their sequence in 557 | the enumeration. The ordinal number of the first value is O. 558 | 559 | .Syntax: 560 | .... 561 | enumeration = '(' ident { [','] ident } ')' 562 | .... 563 | 564 | .Examples: 565 | .... 566 | (red, green, blue) 567 | (club, diamond, heart, spade) 568 | (Monday, Tuesday, Wednesday, Thursday, Friday, Saturday, Sunday) 569 | .... 570 | 571 | The ordinal number of an enumeration identifier can be obtained using the `ORD` predeclared function procedure, or by just assigning/passing to an integer type variable or parameter. `CAST` is the reverse operation. `MIN` returns the first and `MAX` the last ident of the enumeration. `INC` returns the next and `DEC` the previous ident. If T is an enumeration type then `INC(MAX(T))` and `DEC(MIN(T))` are undefined and terminate the program. 572 | 573 | 574 | == Variable declarations 575 | Variable declarations introduce variables by defining an identifier and a data type for them. 576 | 577 | .Syntax: 578 | .... 579 | VariableDeclaration = IdentList ":" type 580 | .... 581 | 582 | Record and pointer variables have both a static type (the type with which they are declared - simply called their type) and a dynamic type (the type of their value at run time). For pointers and variable parameters of record type the dynamic type may be an extension of their static type. The static type determines which fields of a record are accessible. The dynamic type is used to call type-bound procedures (see <>). 583 | 584 | .Examples: 585 | .... 586 | i, j, k: integer 587 | x, y: real 588 | p, q: bool 589 | s: set 590 | F: Function 591 | a: array 100 of real 592 | w: array 16 of record 593 | name: arra 32 of char 594 | count: integer 595 | end 596 | t, c: Tree 597 | .... 598 | 599 | == Expressions 600 | Expressions are constructs denoting rules of computation whereby constants and current values of variables are combined to compute other values by the application of operators and function procedures. Expressions consist of operands and operators. Parentheses may be used to express specific associations of operators and operands. 601 | 602 | === Operands 603 | With the exception of set constructors and literal constants (numbers, character constants, or strings), operands are denoted by designators. A designator consists of an identifier referring to a constant, variable, or procedure. This identifier may possibly be qualified by a module identifier (see <> and <>) and may be followed by selectors if the designated object is an element of a structure. 604 | 605 | .Syntax: 606 | .... 607 | designator = qualident {selector} 608 | selector = '.' ident | '[' ExpList ']' | '^' | '(' qualident ')' 609 | ExpList = expression {',' expression} 610 | .... 611 | 612 | If `a` designates an array, then `a[e]` denotes that element of `a` whose index is the current value of the expression `e`. The type of `e` must be an _integer type_. A designator of the form `a[e~0~, e~1~, ..., e~n~]` is an abbreviation for `a[e~0~][e~1~]...[e~n~]`. 613 | 614 | If `r` designates a record, then `r.f` denotes the field `f` of `r` or the procedure `f` bound to the dynamic type of `r` (see <>). If `p` designates a pointer, `p^` denotes the variable which is referenced by `p`. The designators `p^.f` and `p^[e]` may be abbreviated as `p.f` and `p[e]`, i.e. record and array selectors imply dereferencing. 615 | 616 | Dereferencing is also implied if a pointer is assigned to a variable of a record or array type, if a pointer is used as actual parameter for a formal parameter of a record or array type, or if a pointer is used as argument of the standard procedure LEN footnote:[adopted from <>]. 617 | 618 | If `a` or `r` are read-only, then also `a[e]` and `r.f` are read-only. 619 | 620 | A type guard `v(T)` asserts that the dynamic type of `v` is T (or an extension of T), i.e. program execution is aborted, if the dynamic type of `v` is not T (or an extension of T). Within the designator, `v` is then regarded as having the static type T. The guard is applicable, if 621 | 622 | . `v` is a variable parameter of record type or `v` is a pointer to record type, and if 623 | . T is an extension of the static type of `v`. 624 | 625 | If the designated object is a constant or a variable, then the designator refers to its current value. If it is a procedure, the designator refers to that procedure unless it is followed by a (possibly empty) parameter list in which case it implies an activation of that procedure and stands for the value resulting from its execution. The actual parameters must correspond to the formal parameters as in proper procedure calls (see <>). 626 | 627 | .Examples: 628 | .... 629 | i // integer 630 | a[i] // real 631 | w[3].name[i] // char 632 | t.left.right // Tree 633 | t(CenterTree).subnode // Tree 634 | .... 635 | 636 | === Operators 637 | Four classes of operators with different precedences (binding strengths) are syntactically distinguished in expressions. The operator `~` has the highest precedence, followed by multiplication operators, addition operators, and relations. Operators of the same precedence associate from left to right. For example, `x-y-z` stands for `(x-y)-z`. 638 | 639 | .Syntax: 640 | .... 641 | expression = SimpleExpression [ relation SimpleExpression ] 642 | relation = '=' | '#' | '<' | '<=' | '>' | '>=' | IN | IS 643 | SimpleExpression = ['+' | '-'] term { AddOperator term } 644 | AddOperator = '+' | '-' | OR 645 | term = factor {MulOperator factor} 646 | MulOperator = '*' | '/' | DIV | MOD | '&' 647 | literal = number | string | hexstring | hexchar 648 | | NIL | TRUE | FALSE | set 649 | factor = literal | designator [ActualParameters] 650 | | '(' expression ')' | '~' factor 651 | ActualParameters = '(' [ ExpList ] ')' 652 | set = '{' [ element {',' element} ] '}' 653 | element = expression ['..' expression] 654 | .... 655 | 656 | ==== Logical operators 657 | 658 | [cols="1,2,1,2"] 659 | |=== 660 | | OR | logical disjunction | `p or q` | _if p then TRUE, else q_ 661 | | & | logical conjunction | `p & q` | _if p then q, else FALSE_ 662 | | ~ | negation | `~p` | _not p_ 663 | |=== 664 | 665 | These operators apply to BOOLEAN operands and yield a BOOLEAN result. 666 | 667 | ==== Arithmetic operators 668 | 669 | [width=50%,cols="1,3"] 670 | |=== 671 | | + | sum 672 | | - | difference 673 | | * | product 674 | | / | real quotient 675 | | DIV | integer quotient 676 | | MOD | modulus 677 | |=== 678 | 679 | The operators `+`, `-`, `*`, and `/` apply to operands of numeric types. The type of the result is the type of that operand which includes the type of the other operand, except for division (`/`), where the result is the smallest real type which includes both operand types. When used as monadic operators, `-` denotes sign inversion and `+` denotes the identity operation. The operators `DIV` and `MOD` apply to integer operands only. They are related by the following formulas defined for any `x` and positive divisors `y`: 680 | 681 | .... 682 | x = (x DIV y) * y + (x MOD y) 683 | 0 <= (x MOD y) < y 684 | .... 685 | 686 | .Examples: 687 | .... 688 | x y x DIV y x MOD y 689 | 5 3 1 2 690 | -5 3 -2 1 691 | .... 692 | 693 | [NOTE] 694 | Oberon+ doesn't require overflow checks. If the representation of the result of an arithmetic operation would require a wider integer type than provided by the type of the expression, the behaviour is undefined; e.g. `MAX(INTEGER)+1` causes an overflow, i.e. the result could be MIN(INTEGER) or anything else (even a termination of the program). 695 | 696 | ==== Set Operators 697 | 698 | [width=70%,cols="1,3"] 699 | |====================================== 700 | | + | union 701 | | - | difference (x - y = x * (-y)) 702 | | * | intersection 703 | | / | symmetric set difference (x / y = (x-y) + (y-x)) 704 | |====================================== 705 | 706 | 707 | Set operators apply to operands of type SET and yield a result of type SET. The monadic minus sign denotes the complement of `x`, i.e. `-x` denotes the set of integers between 0 and `MAX(SET)` which are not elements of `x`. Set operators are not associative (`(a+b)-c # a+(b-c)`). 708 | 709 | A set constructor defines the value of a set by listing its elements between curly brackets. The elements must be integers in the range `0..MAX(SET)`. A range `a..b` denotes all integers in the interval [a, b]. 710 | 711 | ==== Relations 712 | 713 | [width=50%,cols="1,3"] 714 | |====================================== 715 | | = | equal 716 | | # | unequal 717 | | < | less 718 | | \<= | less or equal 719 | | > | greater 720 | | >= | greater or equal 721 | | IN | set membership 722 | | IS | type test 723 | |====================================== 724 | 725 | Relations yield a BOOLEAN result. The relations `=`, `\#`, `<`, `\<=`, `>`, and `>=` apply to the numeric types, as well as enumerations, CHAR, strings, and CHAR arrays containing `0x` as a terminator. The relations `=` and `#` also apply to BOOLEAN and SET, as well as to pointer and procedure types (including the value NIL). `x IN s` stands for _x is an element of s_. `x` must be of an integer type, and `s` of type SET. `v IS T` stands for _the dynamic type of `v` is T (or an extension of T )_ and is called a type test. It is applicable if 726 | 727 | . `v` is a variable parameter of record type, or `v` is a pointer to record variable (which can be NIL), and if 728 | . T is an _extension_ of the static type of `v` (see <>). 729 | 730 | .Examples: 731 | .... 732 | 1991 // integer 733 | i div 3 // integer 734 | ~p or q // boolean 735 | (i+j) * (i-j) // integer 736 | s - {8, 9, 13} // set 737 | i + x // real 738 | a[i+j] * a[i-j] // real 739 | (0<=i) & (i<100) // boolean 740 | t.key = 0 // boolean 741 | k in {i..j-1} // boolean 742 | w[i].name <= "John" // boolean 743 | t is CenterTree // boolean 744 | .... 745 | 746 | ==== String operators 747 | 748 | [width=50%,cols="1,3"] 749 | |====================================== 750 | | + | concatenation 751 | |====================================== 752 | 753 | The concatenation operator applies to operands of string types (literals as well as char or wchar arrays). The resulting string consists of the characters of the first operand followed by the characters of the second operand. If a char string (literal or char array) is concatenated with a wchar string (literal or wchar array) the result is a wchar string. 754 | 755 | ==== Function Call 756 | A function call is a factor in an expression. In contrast to <> in a function call the actual parameter list is mandatory. Each expression in the actual parameters list (if any) is used to initialize a corresponding formal parameter. The number of expressions in the actual parameter list must correspond the number of formal parameters. See also <>. 757 | 758 | .Syntax: 759 | .... 760 | FunctionCall = designator ActualParameters 761 | ActualParameters = '(' [ ExpList ] ')' 762 | .... 763 | 764 | == Statements 765 | Statements denote actions. There are elementary and structured statements. Elementary statements are not composed of any parts that are themselves statements. They are the assignment, the procedure call, the return, and the `exit` statement. Structured statements are composed of parts that are themselves statements. They are used to express sequencing and conditional, selective, and repetitive execution. 766 | 767 | .Syntax: 768 | .... 769 | statement = [ assignment | ProcedureCall | IfStatement 770 | | CaseStatement | WithStatement | LoopStatement 771 | | ExitStatement | ReturnStatement 772 | | RepeatStatement | ForStatement ] 773 | .... 774 | 775 | === Statement sequences 776 | Statement sequences denote the sequence of actions specified by the component statements which are optionally separated by semicolons. 777 | 778 | .Syntax: 779 | .... 780 | StatementSequence = statement { [";"] statement} 781 | .... 782 | 783 | === Assignments 784 | Assignments replace the current value of a variable by a new value specified by an expression. The expression must be _assignment compatible_ with the variable (see <>). The assignment operator is written as `:=` and pronounced as _becomes_. 785 | 786 | .Syntax: 787 | .... 788 | assignment = designator ':=' expression 789 | .... 790 | 791 | If an expression `e` of type T~e~ is assigned to a variable `v` of type T~v~, the following happens: 792 | 793 | . if T~v~ and T~e~ are record types, only those fields of T~e~ are assigned which also belong to T~v~ (projection); the dynamic type of `v` must be the same as the static type of `v` and is not changed by the assignment; 794 | . if T~v~ and T~e~ are pointer types, the dynamic type of `v` becomes the dynamic type of `e`; 795 | . if T~v~ is `ARRAY n OF CHAR` and `e` is a string of length m < n, `v[i]` becomes e~i~ for i = 0..m-1 and `v[m]` becomes 0X; 796 | . if T~v~ and T~e~ are open or non-open CHAR arrays, `v[i]` becomes `e[i]` for i = 0..STRLEN(e); if LEN(v) \<= STRLEN(e) or `e` is not terminated by 0X the program halts; 797 | . if T~v~ is an open CHAR array and `e` is a string `v[i]` becomes `e[i]` for i = 0..LEN(e)-1 and `v[LEN(e)]` becomes 0X; if LEN(v) \<= LEN(e) the program halts; 798 | 799 | 800 | .Examples: 801 | .... 802 | i := 0 803 | p := i = j 804 | x := i + 1 805 | k := log2(i+j) 806 | F := log2 807 | s := {2, 3, 5, 7, 11, 13} 808 | a[i] := (x+y) * (x-y) 809 | t.key := i 810 | w[i+1].name := "John" 811 | t := c 812 | .... 813 | 814 | === Procedure calls 815 | A procedure call activates a procedure. It may contain a list of actual parameters which replace the corresponding formal parameter list defined in the procedure declaration (see <>). The correspondence is established by the positions of the parameters in the actual and formal parameter lists. There are three kinds of parameters: _variable_ (VAR), IN and _value_ parameters. 816 | 817 | If a formal parameter is a VAR or IN parameter, the corresponding actual parameter must be a designator denoting a variable. If it denotes an element of a structured variable, the component selectors are evaluated when the formal/actual parameter substitution takes place, i.e. before the execution of the procedure. If a formal parameter is a value parameter, the corresponding actual parameter must be an expression. This expression is evaluated before the procedure activation, and the resulting value is assigned to the formal parameter (see also <>). 818 | 819 | .Syntax: 820 | .... 821 | ProcedureCall = designator [ ActualParameters ] 822 | .... 823 | 824 | .Examples: 825 | .... 826 | WriteInt(i*2+1) 827 | inc(w[k].count) 828 | t.Insert("John") 829 | .... 830 | 831 | === If statements 832 | If statements specify the conditional execution of guarded statement sequences. The boolean expression preceding a statement sequence is called its guard. The guards are evaluated in sequence of occurrence, until one evaluates to TRUE, whereafter its associated statement sequence is executed. If no guard is satisfied, the statement sequence following the symbol ELSE is executed, if there is one. 833 | 834 | .Syntax: 835 | .... 836 | IfStatement = IF expression THEN StatementSequence 837 | {ElsifStatement} [ElseStatement] END 838 | ElsifStatement = ELSIF expression THEN StatementSequence 839 | ElseStatement = ELSE StatementSequence 840 | .... 841 | 842 | .Example: 843 | .... 844 | if (ch >= "A") & (ch <= "Z") then ReadIdentifier 845 | elsif (ch >= "0") & (ch <= "9") then ReadNumber 846 | elsif (ch = "'") OR (ch = '"') then ReadString 847 | else SpecialCharacter 848 | end 849 | .... 850 | 851 | === Case statements 852 | Case statements specify the selection and execution of a statement sequence according to the value of an expression. First the case expression is evaluated, then that statement sequence is executed whose case label list contains the obtained value. The case expression must either be of an integer type that includes the types of all case labels, or an enumeration type with all case labels being valid members of this type, or both the case expression and the case labels must be of type CHAR. Case labels are constants, and no value must occur more than once. If the value of the expression does not occur as a label of any case, the statement sequence following the symbol ELSE is selected, if there is one, otherwise the program is aborted. 853 | 854 | The type T of the case expression (case variable) may also be a variable parameter of record type or a pointer to record variable. Then each case consists of exactly one case label which must be an _extension_ of T (see <>), and in the statements S~i~ labelled by T~i~, the case variable is considered as of type T~i~. If the case variable is of POINTER type, then one case label can also be NIL. The evaluation order corresponds to the case label order; the first statement sequence is executed whose case label meets the condition. 855 | 856 | .Syntax: 857 | .... 858 | CaseStatement = CASE expression OF ['|'] Case { '|' Case } 859 | [ ELSE StatementSequence ] END 860 | Case = [ CaseLabelList ':' StatementSequence ] 861 | CaseLabelList = LabelRange { ',' LabelRange } 862 | LabelRange = label [ '..' label ] 863 | label = ConstExpression 864 | .... 865 | 866 | .Examples: 867 | .... 868 | case ch of 869 | "A" .. "Z": ReadIdentifier 870 | | "0" .. "9": ReadNumber 871 | | "'", '"': ReadString 872 | else SpecialCharacter 873 | end 874 | 875 | type R = record a: integer end 876 | R0 = record (R) b: integer end 877 | R1 = record (R) b: real end 878 | R2 = record (R) b: set end 879 | P = ^R 880 | P0 = ^R0 881 | P1 = ^R1 882 | P2 = ^R2 883 | var p: P 884 | case p of 885 | | P0: p.b := 10 886 | | P1: p.b := 2.5 887 | | P2: p.b := {0, 2} 888 | | NIL: p.b := {} 889 | end 890 | .... 891 | 892 | === While statements 893 | While statements specify the repeated execution of a statement sequence while the Boolean expression (its guard) yields TRUE. The guard is checked before every execution of the statement sequence. 894 | The ELSIF part is integrated in the loop; as long as any of the Boolean expressions (either the WHILE or ELSIF guard) yields TRUE, the corresponding statement sequence is executed; repetition only terminates, when all guards are FALSE. 895 | 896 | .Syntax: 897 | .... 898 | WhileStatement = WHILE expression DO StatementSequence 899 | {ELSIF expression DO StatementSequence} END 900 | .... 901 | 902 | .Examples: 903 | .... 904 | while i > 0 do i := i div 2; k := k + 1 end 905 | 906 | while (t # nil) & (t.key # i) do t := t.left end 907 | 908 | // Euclidean algorithm to compute the greatest common divisor of m and n: 909 | while m > n do 910 | m := m – n 911 | elsif n > m do 912 | n := n – m 913 | end 914 | // is equivalent to: 915 | loop 916 | if m > 0 then 917 | m := m – n 918 | elsif n > m then 919 | n := n – m 920 | else 921 | exit 922 | end 923 | end 924 | .... 925 | 926 | [NOTE] 927 | The ELSIF part was added to Oberon-07. It is noteably Dijkstra’s form of the WHILE loop. Contrary to intuition, the ELSIF part is not executed only if the first check of the WHILE guard evaluates to FALSE; instead, both parts are checked and executed until both guards evaluate to FALSE. 928 | 929 | === Repeat statements 930 | A repeat statement specifies the repeated execution of a statement sequence until a condition specified by a Boolean expression is satisfied. The statement sequence is executed at least once. 931 | 932 | .Syntax: 933 | .... 934 | RepeatStatement = REPEAT StatementSequence UNTIL expression 935 | .... 936 | 937 | === For statements 938 | A for statement specifies the repeated execution of a statement sequence while a progression of values is assigned to a control variable of the for statement. Control variables can be of integer or enumeration types. An explicit BY expression is only supported for integer control variables. 939 | 940 | .Syntax: 941 | .... 942 | ForStatement = FOR ident ':=' expression TO expression 943 | [BY ConstExpression] 944 | DO StatementSequence END 945 | .... 946 | 947 | The statement 948 | 949 | .... 950 | for v := first to last by step do statements end 951 | .... 952 | 953 | is equivalent to 954 | 955 | .... 956 | temp := last; v := first 957 | if step > 0 then 958 | while v <= temp do statements; INC(v,step) end 959 | else 960 | while v >= temp do statements; DEC(v,-step) end 961 | end 962 | .... 963 | 964 | temp has the same type as `v`. For integer control variables, step must be a nonzero constant expression; if step is not specified, it is assumed to be 1. For enumeration control variables, there is no explicit step, but the INC or DEC version of the while loop is used depending on ORD(first) <= ORD(last). 965 | 966 | .Examples: 967 | .... 968 | for i := 0 to 79 do k := k + a[i] end 969 | for i := 79 to 1 by -1 do a[i] := a[i-1] end 970 | .... 971 | 972 | === Loop statements 973 | A loop statement specifies the repeated execution of a statement sequence. It is terminated upon execution of an exit statement within that sequence (see <>). 974 | 975 | .Syntax: 976 | .... 977 | LoopStatement = LOOP StatementSequence END 978 | ExitStatement = EXIT 979 | .... 980 | 981 | .Example: 982 | .... 983 | loop 984 | ReadInt(i) 985 | if i < 0 then exit end 986 | WriteInt(i) 987 | end 988 | .... 989 | 990 | Loop statements are useful to express repetitions with several exit points or cases where the exit condition is in the middle of the repeated statement sequence. 991 | 992 | === Return and exit statements 993 | A return statement indicates the termination of a procedure. It is denoted by the symbol RETURN, followed by an expression if the procedure is a function procedure. The type of the expression must be assignment compatible (see <>) with the result type specified in the procedure heading (see <>). 994 | 995 | .Syntax: 996 | .... 997 | ReturnStatement = RETURN [ expression ] 998 | ExitStatement = EXIT 999 | .... 1000 | 1001 | Function procedures require the presence of a return statement indicating the result value. In proper procedures, a return statement is implied by the end of the procedure body. Any explicit return statement therefore appears as an additional (probably exceptional) termination point. 1002 | 1003 | [NOTE] 1004 | The optional expression causes an LL(k) ambiguity which can be resolved in that the parser expects a return expression if the procedure has a return type and vice versa. 1005 | 1006 | An exit statement is denoted by the symbol EXIT. It specifies termination of the enclosing loop statement and continuation with the statement following that loop statement. Exit statements are contextually, although not syntactically associated with the loop statement which contains them. 1007 | 1008 | === With statements 1009 | With statements execute a statement sequence depending on the result of a type test and apply a type guard to every occurrence of the tested variable within this statement sequence. 1010 | 1011 | .Syntax: 1012 | .... 1013 | WithStatement = WITH ['|'] Guard DO StatementSequence 1014 | { '|' Guard DO StatementSequence} 1015 | [ ELSE StatementSequence ] END 1016 | Guard = qualident ':' qualident 1017 | .... 1018 | 1019 | If `v` is a variable parameter of record type or a pointer to record variable, and if it is of a static type T0, the statement 1020 | 1021 | .... 1022 | with v: T1 do S1 | v: T2 do S2 else S3 end 1023 | .... 1024 | 1025 | has the following meaning: if the dynamic type of `v` is T1, then the statement sequence S1 is executed where `v` is regarded as if it had the static type T1; else if the dynamic type of `v` is T2, then S2 is executed where `v` is regarded as if it had the static type T2; else S3 is executed. T1 and T2 must be _extensions_ of T0 (see <>). If no type test is satisfied and if an else clause is missing the program is aborted. 1026 | 1027 | .Example: 1028 | .... 1029 | with t: CenterTree do i := t.width; c := t.subnode end 1030 | .... 1031 | === Exception handling 1032 | 1033 | Exception handling in Oberon+ is implemented using the predeclared procedures PCALL and RAISE (see <>), without any special syntax. There are no predefined exceptions. 1034 | 1035 | An exception is a record allocated with NEW(). The pointer to this record is passed as an actual argument to RAISE. If the pointer is nil the program execution aborts. RAISE may be called without an argument in which case the compiler provides an allocated record the exact type of which is not relevant. RAISE never returns, but control is transferred from the place where RAISE is called to the nearest dynamically-enclosing call of PCALL. When calling RAISE without a dynamically-enclosing call of PCALL the program execution is aborted. 1036 | 1037 | PCALL executes a protected call of the procedure or procedure type P. P is passed as the second argument to PCALL. P cannot have a return type. P can be a type-bound procedure type. P can be a nested procedure, even if it accesses local variables or parameters of an outer procedure. If P has formal parameters the corresponding actual parameters are passed to PCALL immediately after P. The actual parameters must be _parameter compatible_ with the formal parameters of P (see <>). The first parameter R of PCALL is a POINTER TO ANYREC; if RAISE(E) is called in the course of P, then R is set to E; otherwise R is set to NIL. The state of VAR parameters of P or local variables or parameters of an outer procedure accessed by P is non-deterministic in case RAISE is called in the course of P. 1038 | 1039 | 1040 | .Example: 1041 | ---- 1042 | module ExceptionExample 1043 | type Exception = record end 1044 | proc Print(in str: array of char) 1045 | var e: pointer to Exception 1046 | begin 1047 | println(str) 1048 | new(e) 1049 | raise(e) 1050 | println("this is not printed") 1051 | end Print 1052 | var res: pointer to anyrec 1053 | begin 1054 | pcall(res, Print, "Hello World") 1055 | case res of 1056 | | Exception: println("got Exception") 1057 | | anyrec: println("got anyrec") 1058 | | nil: println("no exception") 1059 | else 1060 | println("unknown exception") 1061 | // could call raise(res) here to propagate the exception 1062 | end 1063 | end ExceptionExample 1064 | ---- 1065 | 1066 | 1067 | == Procedure declarations 1068 | A procedure declaration consists of a procedure heading and a procedure body. The heading specifies the procedure identifier and the formal parameters (see <>). For type-bound procedures it also specifies the receiver parameter. The body contains declarations and statements. The procedure identifier must be repeated at the end of the procedure declaration unless it has no body. 1069 | 1070 | There are two kinds of procedures: proper procedures and function procedures. The latter are activated by a function designator as a constituent of an expression and yield a result that is an operand of the expression. Proper procedures are activated by a procedure call. A procedure is a function procedure if its formal parameters specify a result type. Each control path of a function procedure must return a value. 1071 | 1072 | All constants, variables, types, and procedures declared within a procedure body are local to the procedure. Since procedures may be declared as local objects too, procedure declarations may be nested. The call of a procedure within its declaration implies recursive activation. 1073 | 1074 | Objects declared in the environment of the procedure are also visible in those parts of the procedure in which they are not concealed by a locally declared object with the same name. The type of a parameter or local variable declared in an outer procedure and accessed from a nested procedure cannot be a CSTRUCT, CUNION, CARRAY or CPOINTER (see <>). 1075 | 1076 | [NOTE] 1077 | Procedures can be nested, and inner procedures have access to the parameters or local variables of outer procedures ("non-local access"). This feature was already supported in ALGOL 60 and adopted by Wirth in Pascal; it is also supported by original Oberon and Oberon-2, but no longer by Oberon-07. Previous versions of Oberon+ followed Oberon-07 and didn't support this feature, mostly because the "classic" implementation by "static links" doesn't fit CIL/ECMA-335 or C99 backends; this version of Oberon+ supports an implementation based on hidden var parameters, which is feasible with the mentioned backends. 1078 | 1079 | A procedure body may have no statements in which case the ident after the END reserved word can also be left out; in a function procedure with no statements a return statement with a default value is assumed. 1080 | 1081 | .Syntax: 1082 | .... 1083 | ProcedureDeclaration = ProcedureHeading [';'] 1084 | ProcedureBody END [ ident ] 1085 | ProcedureHeading = ( PROCEDURE | PROC ) 1086 | [Receiver] identdef [ FormalParameters ] 1087 | ProcedureBody = DeclarationSequence 1088 | [ BEGIN StatementSequence 1089 | | ReturnStatement [';'] ] 1090 | Receiver = '(' [VAR] ident ':' ident ')' 1091 | DeclarationSequence = { CONST { ConstDeclaration [';'] } 1092 | | TYPE { TypeDeclaration [';'] } 1093 | | VAR { VariableDeclaration [';'] } 1094 | | ProcedureDeclaration [';'] } 1095 | .... 1096 | 1097 | If a procedure declaration specifies a receiver parameter, the procedure is considered to be bound to a type (see <>). 1098 | 1099 | 1100 | === Formal parameters 1101 | Formal parameters are identifiers declared in the formal parameter list of a procedure. They correspond to actual parameters specified in the procedure call. The correspondence between formal and actual parameters is established when the procedure is called. There are three kinds of parameters, value, variable (VAR) and IN parameters, indicated in the formal parameter list by the absence or presence of the reserved words VAR and IN. 1102 | 1103 | Value parameters are local variables to which the value of the corresponding actual parameter is assigned as an initial value. VAR parameters correspond to actual parameters that are variables, and they stand for these variables. 1104 | 1105 | IN parameters are like VAR parameters, but they are read-only in the procedure body. If an IN parameters is of ARRAY or RECORD type, then also the elements or fields are transitively read-only in the procedure body. 1106 | 1107 | [NOTE] 1108 | IN parameters of pointer type are supported, but the dereferenced ARRAY or RECORD is not read-only in the procedure body. IN parameters of pointer type are mostly relevant for generic modules (see <>). 1109 | 1110 | The scope of a formal parameter extends from its declaration to the end of the procedure block in which it is declared. A function procedure without parameters must have an empty parameter list. It must be called by a function designator whose actual parameter list is empty too. The result type of a procedure cannot be an open array. 1111 | 1112 | [NOTE] 1113 | In contrast to previous Oberon versions the return type of a procedure may also be a record or array type, and it is possible to ignore the return value of a function procedure call. 1114 | 1115 | .Syntax: 1116 | .... 1117 | FormalParameters = '(' [ FPSection { [';'] FPSection } ] ')' 1118 | [ ':' ReturnType ] 1119 | ReturnType = type 1120 | FPSection = [ VAR | IN ] ident { [','] ident } 1121 | ':' FormalType 1122 | FormalType = type 1123 | .... 1124 | 1125 | Let T~f~ be the type of a formal parameter `f` and T~a~ the type of the corresponding actual parameter `a`. If T~f~ is an open array, then T~a~ must be _array compatible_ to `f`; the lengths of `f` are taken from `a`. Otherwise T~a~ must be _parameter compatible_ to `f` (see <>). 1126 | 1127 | [NOTE] 1128 | Also value parameters can have an open array type, but for efficiency reasons (to avoid unneccessary copying) open arrays should be VAR or IN parameters. 1129 | 1130 | .Examples: 1131 | .... 1132 | proc ReadInt(var x: integer) 1133 | var i: integer; ch: char 1134 | begin i := 0; Read(ch) 1135 | while ("0" <= ch) & (ch <= "9") do 1136 | i := 10*i + (ord(ch)-ord("0")); Read(ch) 1137 | end 1138 | x := i 1139 | end ReadInt 1140 | 1141 | proc WriteInt(x: integer) // 0 <= x <100000 1142 | var i: integer; buf: [5]integer 1143 | begin i := 0 1144 | repeat buf[i] := x mod 10; x := x div 10; inc(i) until x = 0 1145 | repeat dec(i); Write(chr(buf[i] + ord("0"))) until i = 0 1146 | end WriteInt 1147 | 1148 | proc WriteString(s: []char) 1149 | var i: integer 1150 | begin i := 0 1151 | while (i < len(s)) & (s[i] # 0x) do Write(s[i]); inc(i) end 1152 | end WriteString 1153 | 1154 | proc log2(x: integer): integer 1155 | var y: integer // assume x>0 1156 | begin 1157 | y := 0; while x > 1 do x := x div 2; inc(y) end 1158 | return y 1159 | end log2 1160 | .... 1161 | 1162 | === Type-bound procedures 1163 | Procedures may be associated with a record type declared in the same scope. The procedures are said to be bound to the record type. The binding is expressed by the type of the receiver in the heading of a procedure declaration. The receiver may be either a variable (VAR or IN) parameter of record type T or a value parameter of type POINTER TO T (where T is a record type). The procedure is bound to the type T and is considered local to it. 1164 | 1165 | .Syntax: 1166 | .... 1167 | ProcedureHeading = ( PROCEDURE | PROC ) 1168 | [Receiver] identdef [ FormalParameters ] 1169 | Receiver = '(' [VAR|IN] ident ':' ident ')' 1170 | .... 1171 | 1172 | If a procedure P is bound to a type T0, it is implicitly also bound to any type T1 which is an extension of T0. However, a procedure P' (with the same name as P) may be explicitly bound to T1 in which case it overrides the binding of P. P' is considered a redefinition of P for T1. The formal parameters of P and P' must _match_ (see <>). If P and T1 are exported (see <>), P' must be exported too. 1173 | 1174 | [NOTE] 1175 | The name of a type-bound procedure must be unique within the type to which it is bound, not within the scope in which it is declared. 1176 | 1177 | // TODO: shall we really support Covariance? 1178 | //The formal parameter lists of P and P' must _match_ (see <>). Also the result types must _match_, or if P and P' both have pointer result types, then the result type of P' must be an _extension_ of the result type of P footnote:[this is called _covariance_, adopted with modifications from <>]. 1179 | 1180 | If `v` is a designator and `P` is a type-bound procedure, then `v.P` denotes that procedure `P` which is bound to the dynamic type of `v`. Note, that this may be a different procedure than the one bound to the static type of `v`. `v` is passed to `P`'s receiver according to the parameter passing rules specified in Chapter <>. 1181 | 1182 | If `r` is the receiver parameter of P declared with type T, `r.P^` denotes the (redefined, sometimes calles _super_) procedure P bound to a base type of T. 1183 | 1184 | .Examples: 1185 | .... 1186 | proc (t: Tree) Insert (node: Tree) 1187 | var p, father: Tree 1188 | begin p := t 1189 | repeat father := p 1190 | if node.key = p.key then return end 1191 | if node.key < p.key then 1192 | p := p.left 1193 | else 1194 | p := p.right 1195 | end 1196 | until p = nil 1197 | if node.key < father.key then 1198 | father.left := node 1199 | else 1200 | father.right := node 1201 | end 1202 | node.left := nil; node.right := nil 1203 | end Insert 1204 | 1205 | proc (t: CenterTree) Insert (node: Tree) // redefinition 1206 | begin 1207 | WriteInt(node(CenterTree).width) 1208 | t.Insert^(node) // calls the Insert procedure bound to Tree 1209 | end Insert 1210 | .... 1211 | 1212 | Type-bound procedure declarations may be nested and have access to constants, types and procedures declared in the environment of the type-bound procedure (unless concealed by a local declaration), but they don’t have access to the parameters or local variables of outer procedures. 1213 | 1214 | [NOTE] 1215 | A type-bound procedure can still include nested procedures which have access to its parameters and local variables. 1216 | 1217 | 1218 | === Type-bound procedure types 1219 | Variables of a type-bound procedure type T have a type-bound procedure or NIL as value. To assign a type-bound procedure P to a variable of a type-bound procedure type T, the right side of the assignment must be a designator of the form `v^.P` or `v.P`, where `v` is a pointer to record and `P` is a procedure bound to this record. Note, that the dynamic type of `v` determines which procedure is assigned; this may be a different procedure than the one bound to the static type of `v`. The formal parameter lists and result types (see <>) of P and T must _match_ (see <>). The same rules apply when passing a type-bound procedure to a formal argument of a type-bound procedure type. 1220 | 1221 | .Syntax: 1222 | .... 1223 | ProcedureType = PROCEDURE '(' ( POINTER | '^' ) ')' [FormalParameters] 1224 | .... 1225 | 1226 | 1227 | === Predeclared procedures 1228 | The following table lists the predeclared procedures. Some are generic procedures, i.e. they apply to several types of operands. `v` stands for a variable, `x` and `n` for expressions, and T for a type. 1229 | 1230 | ==== Predeclared function procedures 1231 | 1232 | [%header,cols="1,2,2,3"] 1233 | |=== 1234 | |Name |Argument type |Result type |Function 1235 | |ABS(x) |numeric type |type of x |absolute value 1236 | |CAP(x) |CHAR |CHAR |corresponding capital letter (only for the ASCII subset of the CHAR type) 1237 | |BITAND(x,y) |x, y: INT32 or INT64|INT32 or INT64|bitwise AND; result is INT64 if x or y is INT64, else INT32 1238 | |BITASR(x,n) |x: INT32 or INT64, n: INT32|INT32 or INT64|arithmetic shift right by n bits, where n >= 0 and n < SIZE(x)*8; result is INT64 if x is INT64, else INT32 1239 | |BITNOT(x) |x: INT32 or INT64|INT32 or INT64|bitwise NOT; result is INT64 if x or y is INT64, else INT32 1240 | |BITOR(x,y) |x, y: INT32 or INT64|INT32 or INT64|bitwise OR; result is INT64 if x or y is INT64, else INT32 1241 | |BITS(x) |x: INT32 |SET |set corresponding to the integer; the first element corresponds to the least significant digit of the integer and the last element to the most significant digit. 1242 | |BITSHL(x,n) |x: INT32 or INT64, n: INT32|INT32 or INT64|logical shift left by n bits, where n >= 0 and n < SIZE(x)*8; result is INT64 if x is INT64, else INT32 1243 | |BITSHR(x,n) |x: INT32 or INT64, n: INT32|INT32 or INT64|logical shift right by n bits, where n >= 0 and n < SIZE(x)*8; result is INT64 if x is INT64, else INT32 1244 | |BITXOR(x,y) |x, y: INT32 or INT64|INT32 or INT64|bitwise XOR; result is INT64 if x or y is INT64, else INT32 1245 | |CAST(T,x) |T:enumeration type x:ordinal number|enumeration type|the enum item with the ordinal number x; halt if no match 1246 | | |T,x: integer type |T |convert integer types, accept possible loss of information 1247 | | |T, x: cpointer to cstruct or void|T |unsafe cast of a C pointer (see <>) 1248 | | |T: integer type, x: cpointer to void|T |convert C pointer to integer (see <>) 1249 | | |T: cpointer to void, x: integer type|T |reinterpret integer x as a C pointer (see <>) 1250 | |CHR(x) |integer type |CHAR |Latin-1 character with ordinal number x 1251 | |DEFAULT(T) |T = basic type |T |zero for numeric and character types, false for boolean, empty set 1252 | | |T = enumeration type |T |same as MIN(T) 1253 | | |T = pointer/proc type|T |nil 1254 | | |T = record/array type|T |all fields/elements set to their DEFAULT type 1255 | |FLOOR(x) |x: REAL or LONGREAL |INT32 or INT64|largest integer not greater than x; result is INT64 if x is LONGREAL, else INT32 1256 | |FLT(x) |x: INT32 or INT64|REAL or LONGREAL|Convert integer to real type; result is LONGREAL if x was INT64, else REAL, accepting potential loss of information 1257 | |LDCMD(m,c) |m,c: string |PROCEDURE |dynamically loads the command procedure with name c from the Oberon+ module with name m; returns NIL if not successful 1258 | |LDMOD(n) |n: string |BOOLEAN |dynamically loads the Oberon+ module with the given name n; returns TRUE if successful 1259 | |LEN(v, n) |v: array n: INT32 |INT32 |length of v in dimension n (first dimension = 0) 1260 | |LEN(v) |v: array |INT32 |equivalent to LEN(v, 0) 1261 | | |v: string |INT32 |length of string (including the terminating 0X) 1262 | |LONG(x) |x: INT8 or BYTE |INT16 |identity 1263 | | |x: INT16 |INT32 | 1264 | | |x: INT32 |INT64 | 1265 | | |x: REAL |LONGREAL | 1266 | | |x: CHAR |WCHAR |projection 1267 | |MAX(T) |T = basic type |T |maximum value of type T 1268 | | |T = SET |INT32 |maximum element of a set 1269 | | |T = enumeration type |T |last element of the enumeration 1270 | |MAX(x,y) |x,y: numeric type |numeric type |greater of x and y, returns smallest numeric type including both arguments 1271 | | |x,y: character type |character type |greater of x and y, returns smallest character type including both arguments 1272 | |MIN(T) |T = basic type |T |minimum value of type T 1273 | | |T = SET |INT32 |0 1274 | | |T = enumeration type |T |first element of the enumeration 1275 | |MIN(x,y) |x,y: numeric type |numeric type |smaller of x and y, returns smallest numeric type including both arguments 1276 | | |x,y: character type |character type |smaller of x and y, returns smallest character type including both arguments 1277 | |ODD(x) |integer type |BOOLEAN |x MOD 2 = 1 1278 | |ORD(x) |x: CHAR or WCHAR |BYTE or SHORT |ordinal number of x 1279 | | |x: enumeration type |INT32 |ordinal number of the given identifier 1280 | | |x: BOOLEAN |BYTE |TRUE = 1, FALSE = 0 1281 | | |x: set type |INT32 |number representing the set; the first element corresponds to the least significant digit of the number and the last element to the most significant digit. 1282 | |SHORT(x) |x: INT64 |INT32 |identity 1283 | | |x: INT32 |INT16 |identity 1284 | | |x: INT16 |INT8 |identity 1285 | | |x: LONGREAL |REAL |identity (truncation possible) 1286 | | |x: WCHAR |CHAR |projection (0x if there is no projection) 1287 | |SIZE(T) |any type |INT32 |number of bytes required by T 1288 | |STRLEN(s) |s: array of char or wchar|INT32 |dynamic length of the string up to and not including the terminating 0X 1289 | | |s: string literal | | 1290 | |WCHR(x) |integer type |WCHAR |Unicode BMP character with ordinal number x 1291 | |=== 1292 | 1293 | ==== Deprecated predeclared functions for backward compatibility 1294 | 1295 | [%header,cols="1,2,2,3"] 1296 | |=== 1297 | |Name |Argument type |Result type |Function 1298 | |ASH(x, n) |x: INT32 or INT64, n: INT32|INT32 or INT64|Same as LSL(x,n) for positive n, same as ASR(x,-n) for negative n 1299 | |ASR(x, n) |x: INT32 or INT64, n: INT32|INT32 or INT64|signed shift right, x DIV 2^n_MOD_w^, with w bitwidth of x; result is INT64 if x is INT64, else INT32 1300 | |ENTIER(x) |real type |INT64 |largest integer not greater than x 1301 | |LSL(x,n) |x: INT32 or INT64, n: INT32|INT32 or INT64|logical shift left, x * 2^n_MOD_w^, with w bitwidth of x; result is INT64 if x is INT64, else INT32 1302 | |ROR(x, n) |x, n: INT32 |INT32 |x rotated right by n bits (where the fading right bits re-appear at the left side) 1303 | |=== 1304 | 1305 | 1306 | [NOTE] 1307 | The functions ENTIER(x) or FLOOR(x) round down to the largest integer not greater than x. The functions are identical, but the former is defined in Oberon-2 and the latter in Oberon-07. 1308 | 1309 | .Exampes: 1310 | .... 1311 | FLOOR(1.5) = 1; FLOOR(-1.5) = -2 1312 | .... 1313 | 1314 | [NOTE] 1315 | The Oberon and Oberon-2 built-in function ASH was replaced by ASR and LSL in Oberon-07; note that ASR(x,-n) gives not the same result as LSL(x,n) for a given n. LSL(x,n) with positive n is identical to BITSHL(x,n), and ASR(x,n) with positive n is identical to BITASR(x,n). 1316 | 1317 | 1318 | 1319 | ==== Predeclared proper procedures 1320 | 1321 | [%header,cols="1,2,3"] 1322 | |=== 1323 | |Name |Argument types |Function 1324 | |ASSERT(x) |x: Boolean expression |terminate program execution if not x 1325 | |ASSERT(x, n) |x: Boolean expression |terminate program execution if not x 1326 | | |n: integer constant | 1327 | |BYTES(a,n) |a: ARRAY OF BYTE/CHAR; n: numeric or set type |stores the raw memory of n in a; if the length of a is smaller than the number of bytes required to represent n, the program halts 1328 | |DEC(v) |integer type |v := v - 1 1329 | | |enumeration type |previous ident in enumeration 1330 | |DEC(v, n) |v, n: integer type |v := v - n 1331 | |EXCL(v, x) |v: SET; x: integer type |v := v - {x} 1332 | |HALT(n) |integer constant |terminate program execution 1333 | |INC(v) |integer type |v := v + 1 1334 | | |enumeration type |next ident in enumeration 1335 | |INC(v, n) |v, n: integer type |v := v + n 1336 | |INCL(v, x) |v: SET; x: integer type |v := v + {x} 1337 | |NEW(v) |pointer to record or |allocate v^ 1338 | | |fixed array | 1339 | |NEW(v,x~0~,...,x~n~) |v: pointer to open array |allocate v^ with lengths 1340 | | |x~i~: integer type |x~0~..x~n~ 1341 | |NUMBER(n,a) |n: numeric or set type; a: ARRAY OF BYTE/CHAR |interprets the bytes in a as number of the numeric type of n and assigns it to n; if the length of a is smaller than the number of bytes required to represent n, the program halts 1342 | |PCALL(e,p,a~0~,...,a~n~)|VAR e: pointer to anyrec; p: proper procedure type; a~i~: actual parameters |call procedure type p with arguments a~0~...a~n~ corresponding to the parameter list of p; e becomes nil in normal case and gets the pointer passed to RAISE() otherwise 1343 | |RAISE(e) |e: pointer to anyrec |terminates the last protected function called and returns e as the exception value; RAISE() never returns 1344 | |=== 1345 | 1346 | In `ASSERT(x, n)` and `HALT(n)`, the interpretation of `n` is left to the underlying system implementation. 1347 | 1348 | The predeclared procedure NEW is used to allocate data blocks in free memory. There is, however, no way to explicitly dispose an allocated block. Rather, the Oberon+ runtime uses a garbage collector to find the blocks that are not used any more and to make them available for allocation again. A block is in use as long as it can be reached from a global pointer variable via a pointer chain. Cutting this chain (e.g., setting a pointer to NIL) makes the block collectable. 1349 | 1350 | [NOTE] 1351 | The procedures BYTES(a,n) and NUMBER(n,a) are a replacement of the VAR ARRAY OF BYTES trick supported by many Oberon implementations, where any numeric type or array of numeric types can be used as actual parameter. 1352 | 1353 | ==== Deprecated predeclared proper procedures for backward compatibility 1354 | 1355 | [%header,cols="1,2,3"] 1356 | |=== 1357 | |Name |Argument types |Function 1358 | |COPY(x, v) |x: CHAR array, string |v := x 1359 | | |v: CHAR array | 1360 | |PACK(x, n) |VAR x:REAL; n:INT32 |pack x and n into x 1361 | |UNPK(x, n) |VAR x:REAL; VAR n:INT32 |unpack x into x and n 1362 | |=== 1363 | 1364 | The parameter `n` of PACK represents the exponent of `x`. `PACK(x, y)` is equivalent to `x := x * 2^y^`. 1365 | UNPK is the reverse operation. The resulting `x` is normalized, such that 1.0 \<= x < 2.0. 1366 | 1367 | COPY allows the assignment of a string or a CHAR array containing a terminating 0X to another CHAR array. If necessary, the assigned value is truncated to the target length minus one. The target will always contain 0X as a terminator. 1368 | 1369 | 1370 | == Modules 1371 | A module is a collection of declarations of constants, types, variables, and procedures, together with a sequence of statements for the purpose of assigning initial values to the variables. A module constitutes a text that is compilable as a unit (compilation unit). 1372 | 1373 | .Syntax: 1374 | .... 1375 | module = MODULE ident [ MetaParams ] [';'] 1376 | { ImportList | DeclarationSequence } 1377 | [ BEGIN StatementSequence ] END ident ['.'] 1378 | ImportList = IMPORT import { [','] import } [';'] 1379 | import = [ ident ':=' ] ImportPath ident [ MetaActuals ] 1380 | ImportPath = { ident '.' } 1381 | .... 1382 | 1383 | The import list specifies the names of the imported modules. If a module A is imported by a module M and A exports an identifier `x`, then `x` is referred to as `A.x` within M. 1384 | 1385 | If A is imported as `B := A`, the object `x` must be referenced as `B.x`. This allows short alias names in qualified identifiers. 1386 | 1387 | In Oberon+ the import can refer to a module by means of a module name optionally prefixed with an import path. There is no requirement that the import path actually exists in the file system, or that the source files corresponding to an import path are in the same file system directory. It is up to the compiler how source files are mapped to import paths. An imported module with no import path is first looked up in the import path of the importing module. 1388 | 1389 | A module must not import itself. 1390 | 1391 | Identifiers that are to be exported (i.e. that are to be visible in client modules) must be marked by an export mark in their declaration (see Chapter <>). 1392 | 1393 | 1394 | The statement sequence following the symbol BEGIN is executed when the module is loaded, which is done after the imported modules have been loaded. It follows that cyclic import of modules is illegal. 1395 | 1396 | .Example with original Oberon-2 syntax 1397 | [[oberon-2-example]] 1398 | [source,oberon] 1399 | ---- 1400 | MODULE Lists; 1401 | IMPORT Out; 1402 | TYPE 1403 | List* = POINTER TO ListNode; 1404 | ListNode = RECORD 1405 | value : INTEGER; 1406 | next : List; 1407 | END; 1408 | 1409 | PROCEDURE (l : List) Add* (v : INTEGER); 1410 | BEGIN 1411 | IF l = NIL THEN 1412 | NEW(l); (* create record instance *) 1413 | l.value := v 1414 | ELSE 1415 | l.next.Add(v) 1416 | END 1417 | END Add; 1418 | 1419 | PROCEDURE (t: List) Write*; 1420 | BEGIN 1421 | Out.Int(t.value,8); Out.Ln; 1422 | IF t.next # NIL THEN t.next.Write END; 1423 | END Write; 1424 | END Lists. 1425 | ---- 1426 | 1427 | .<> with syntactic simplifications 1428 | [source,oberon] 1429 | ---- 1430 | module Lists2 1431 | import Out 1432 | type 1433 | List* = ^record 1434 | value : integer 1435 | next : List 1436 | end 1437 | 1438 | proc (l : List) Add* (v : integer) 1439 | begin 1440 | if l = nil then 1441 | new(l) // create record instance 1442 | l.value := v 1443 | else 1444 | l.next.Add(v) 1445 | end 1446 | end Add 1447 | 1448 | proc (t: List) Write* 1449 | begin 1450 | Out.Int(t.value,8); Out.Ln 1451 | if t.next # nil then t.next.Write end 1452 | end Write 1453 | end Lists2 1454 | ---- 1455 | 1456 | === Generics 1457 | Oberon+ supports generic programming. Modules can be made generic by adding formal meta parameters. Meta parameters represent types or constants; the latter include procedures. Meta parameters default to types, but can be explicitly prefixed with the TYPE reserved word; the CONST prefix designates a constant meta parameter. A meta parameter can be constrained with a named type, in which case the actual meta parameter must correspond to this type; the correspondence is established when the generic module is instantiated; the type of the actual meta parameter must be assignment compatible with the constraint type (see <>). 1458 | 1459 | Generic modules can be instantiated with different sets of meta actuals which enables the design of reusable algorithms and data structures. The instantiation of a generic module occurs when importing it. A generic module can be instantiated more than once in the same module with different actual meta parameters. See also <>. 1460 | 1461 | .Syntax: 1462 | .... 1463 | MetaParams = '(' MetaSection { [';'] MetaSection } ')' 1464 | MetaSection = [ TYPE | CONST ] ident { [','] ident } [ ':' TypeConstraint ] 1465 | TypeConstraint = NamedType 1466 | MetaActuals = '(' ConstExpression { [','] ConstExpression } ')' 1467 | module = MODULE ident [ MetaParams ] [';'] { ImportList | DeclarationSequence } 1468 | [ BEGIN StatementSequence ] END ident ['.'] 1469 | ImportList = IMPORT import { [','] import } [';'] 1470 | import = [ ident ':=' ] ImportPath ident [ MetaActuals ] 1471 | .... 1472 | 1473 | 1474 | Meta parameters can be used within the generic module like normal types or constants. If no type constraint is present, the types and constants can be used wherever no information about the actual type is required; otherwise the type constraint determines the permitted operations. The rules for _same types_ and _equal types_ apply analogously to meta parameters, and subsequently also the corresponding assignment, parameter and array compatibility rules. 1475 | 1476 | [NOTE] 1477 | It follows that a type meta parameter can only be the base type of a record or a pointer if a record or pointer to record type constraint is present(because in absence of the type constraint we don't know before instantiation whether the type parameter represents e.g. a record or not); but it is e.g. possible to use a record declared in the same or another generic module as a base type. 1478 | 1479 | See also <>. 1480 | 1481 | === Definitions 1482 | A DEFINITION is a special kind of MODULE which only includes public declarations. The export mark `*` is redundant, but `-` can be used to mark read-only exports (see <>). 1483 | 1484 | Definitions can be used when the implementation of a module is not available or done in another programming language than Oberon+. 1485 | 1486 | .Syntax: 1487 | .... 1488 | definition = DEFINITION ident [';'] [ ImportList ] DeclarationSequence2 END ident ['.'] 1489 | DeclarationSequence2 = { CONST { ConstDeclaration [';'] } 1490 | | TYPE { TypeDeclaration [';'] } 1491 | | VAR { VariableDeclaration [';'] } 1492 | | ProcedureHeading [';'] } 1493 | .... 1494 | 1495 | 1496 | == Foreign Function Interface 1497 | 1498 | Oberon+ includes the possibility to call functions from and exchange data with external C shared libraries. To avoid confusion with existing POINTER, ARRAY and RECORD types, Oberon+ includes special C compatible types. 1499 | 1500 | [NOTE] 1501 | Oberon+ has no SYSTEM module. Use the foreign function interface instead and the predeclared BITop() function procedures to convert basic types to byte arrays and vice versa. 1502 | 1503 | === External Library Modules 1504 | 1505 | An external library module is a DEFINITION module with an attribute list, and with a few more differences to normal DEFINITIONs, which will be discussed in the following. 1506 | 1507 | .Syntax 1508 | .... 1509 | definition = DEFINITION ident attributeList [';'] [ ImportList ] DeclarationSequence3 END ident ['.'] 1510 | attributeList = '[' [ attribute { ',' attribute } ] ']' 1511 | attribute = ident { ConstExpression } 1512 | DeclarationSequence3 = 1513 | { CONST { ConstDeclaration [';'] } 1514 | | TYPE { TypeDeclaration [';'] } 1515 | | ProcedureHeading [ attributeList ] [';'] } 1516 | .... 1517 | 1518 | An external library module can only import other external library modules, but not ordinary or definition modules. Module variables are not supported. 1519 | 1520 | The following attributes are defined on module level: 1521 | 1522 | [%header,cols="1,1,3"] 1523 | |=== 1524 | |Name |Type, Value |Description 1525 | |extern |string, 'C' |optional; as soon as an attribute list is present (even an empty one), extern 'C' is assumed 1526 | |dll |string |mandatory; the name of the library; on Windows ".dll" is appended; on Linux "lib" is prepended and ".so" is appended 1527 | |prefix |string |optional; the name under which a procedure is known in the external library corresponds to the procedure name combined with the prefix 1528 | |=== 1529 | 1530 | === C Types 1531 | 1532 | In an external library module only C types and named types pointing to C types can be declared. A C type is either a CSTRUCT, CUNION, CARRAY, CPOINTER, procedure type or basic type. Structured C types are not subject to garbage collection and cannot be instantiated with NEW. 1533 | 1534 | .Syntax: 1535 | .... 1536 | C_Type = ( CSTRUCT | CUNION ) FieldList { [';'] FieldList} END 1537 | | ( CPOINTER TO | '*' ) ( C_Type | VOID ) 1538 | | CARRAY [ length ] OF C_Type 1539 | | ( PROCEDURE | PROC ) [FormalParameters] 1540 | | BasicType 1541 | .... 1542 | 1543 | A CARRAY is a one-dimensional array of C_Types. A CARRAY declared without length is an open array. An open CARRAY can only be used as a CPOINTER base type. LEN(v) is undefined if v is an open CARRAY. An open CARRAY cannot be on the left or right side of an assignment unless the element type is CHAR or WCHAR. 1544 | 1545 | A CPOINTER can point to CSTRUCT, CUNION, CARRAY or VOID. 1546 | 1547 | CSTRUCT and CUNION are the Oberon+ representation of C struct and C union. Field types are restricted to C_Types. 1548 | 1549 | The basic types correspond to the ones defined in <>. BOOLEAN and BYTE map to uint8_t, CHAR to the C char type, INT16 to int16_t, WCHAR to uint16_t, INT32 to int32_t, INT64 to int64_t, REAL to float, LONGREAL to double, and SET to uint32_t. 1550 | 1551 | The formal parameter types of a procedure type compatible with an external library module can only be of C_Type. VAR and IN are not supported in external library modules, and CARRAY cannot be passed by value. 1552 | 1553 | [NOTE] 1554 | Instead of writing `cpointer to T` one can simply write `\*T`; `cpointer to carray of T` can be abbreviated by `*[]T`. In C an out parameter is usually implemented by a pointer; when the value to be put out is itself a pointer, the parameter is a pointer to pointer; Oberon+ doesn't support pointer to pointer, but the same effect can be achieved by a pointer to an array of length one of the pointer type, e.g. `\*[1]*T`, or just an open array `*[]*T` for simplicity; but of course one can also write `cpointer to carray of cpointer to T`, or equivalently `CPOINTER TO CARRAY OF CPOINTER TO T`. 1555 | 1556 | [NOTE] 1557 | In Oberon+ POINTER, RECORD and ARRAY are considered safe, whereas CPOINTER, CSTRUCT, CUNION and CARRAY are considered unsafe; of course, it must always be assessed on a case-by-case basis whether a specific application of C_Types is safe or unsafe. 1558 | 1559 | === Type interoperability 1560 | 1561 | ARRAY and RECORD types cannot be used in external library modules, but it is perfectly legal to use C_Types as formal parameter, or local or module variable types in regular Oberon+ modules. CPOINTER (but not structured C_Types) can be used as field or element type in RECORD or ARRAY. Structured C_Types (in contrast to CPOINTER to structured C_Types) cannot be used as formal VAR or IN parameters. 1562 | 1563 | POINTER and CPOINTER are disjoint in what they can point to and it is not possible to assign from a POINTER to a CPOINTER or vice versa. 1564 | 1565 | A CARRAY and an ARRAY are only assignment compatible if both element types are either CHAR or WCHAR. A CARRAY cannot be passed to a parameter of ARRAY type. 1566 | 1567 | === External procedures 1568 | 1569 | The formal parameter types of an external procedure can only be of C_Type. VAR and IN are not supported, and CARRAY cannot be passed by value. 1570 | 1571 | The following attributes can be applied to each procedure: 1572 | 1573 | [%header,cols="1,1,3"] 1574 | |=== 1575 | |Name |Type, Value |Description 1576 | |dll |string |optional; override of the module wide library name for the given procedure 1577 | |prefix |string |optional; override of the module wide prefix for the given procedure 1578 | |alias |string |optional; the name by which the given procedure is known in the external library 1579 | |varargs |- |optional; if present the given procedure accepts optional arguments (in addition to the ones specified); same as the `...` parameter in C 1580 | |=== 1581 | 1582 | === Implicit address-of operation 1583 | 1584 | Oberon+ implicitly takes the address of a CSTRUCT, CUNION or CARRAY 1585 | 1586 | - when passing an actual value of this type to a formal parameter of CPOINTER type, 1587 | - and when assigning a value of this type to a variable of CPOINTER type; 1588 | 1589 | in both cases the CPOINTER base type must be _assignment compatible_ with the actual or assigned value type (see <>); as an extension to this rule, each structured C_Type is compatible with a CPOINTER TO VOID. 1590 | 1591 | Oberon+ supports passing an actual parameter of ARRAY type or a string literal to a formal parameter of CPOINTER TO CARRAY type of a procedure in an external library module, if the CARRAY and ARRAY element types are _assignment compatible_; as an extension to this rule, an ARRAY of an unstructured type (including CPOINTER), a string literal or an INT32 (and its included types) is compatible with a CPOINTER TO VOID. The compiler or runtime system in use is free to either create a CARRAY copy of the ARRAY or string literal, or to directly pass the memory address for efficiency reasons; in the latter case the compiler or runtime system assure that the memory address remains valid during the call. 1592 | 1593 | [NOTE] 1594 | Remember that taking the address of a variable is a potentially unsafe operation because the memory location the address points to could become invalid. 1595 | 1596 | == Source code directives 1597 | Source code directives are used to set configuration variables in the source text and to select specific pieces of the source text to be compiled (conditional compilation). Oberon+ uses the syntax recommended in <>. 1598 | 1599 | === Configuration Variables 1600 | 1601 | Configuration variables can be set or unset in the source code using the following syntax: 1602 | 1603 | .Syntax: 1604 | .... 1605 | directive = '<*' ident ( '+' | '-' ) '*>' 1606 | .... 1607 | 1608 | Each variable is named by an ident which follows the syntax specified in <>. Variable names have compilation unit scope which is separate from all other scopes of the program. Configuration variable directives can be placed anywhere in the source code. The directive only affects the present compilation unit, starting from its position in the source code. 1609 | 1610 | .Example: 1611 | .... 1612 | <* WIN32+ *> 1613 | <* WIN64- *> 1614 | .... 1615 | 1616 | [NOTE] 1617 | Usually the compiler provides the possibility to set configuration variables, e.g. via command line interface. 1618 | 1619 | === Conditional compilation 1620 | 1621 | Conditional compilation directives can be placed anywhere in the source code. The following syntax applies: 1622 | 1623 | .Syntax: 1624 | .... 1625 | directive = '<*' [ scIf | scElsif | scElse | scEnd ] '*>' 1626 | scIf = IF scExpr THEN 1627 | scElsif = ELSIF condition THEN 1628 | scElse = ELSE 1629 | scEnd = END 1630 | condition = scTerm { OR scTerm } 1631 | scTerm = scFactor {'&' scFactor} 1632 | scFactor = ident | '(' condition ')' | '~' scFactor 1633 | .... 1634 | 1635 | An ELSIF or ELSE directive must be preceded by an IF or another ELSIF directive. Each IF directive must be ended by an END directive. The directives form sections of the source code. Only the section the condition of which is TRUE (or the section framed by ELSE and END directive otherwise) is visible to the compiler. Conditions are boolean expressions. Ident refers to a configuration variable. When a configuration variable is not explicitly set it is assumed to be FALSE. Each section can contain nested conditional compilation directives. 1636 | 1637 | .Example: 1638 | .... 1639 | <* if A then *> 1640 | println("A") 1641 | <* elsif B & ~C then *> 1642 | println("B & ~C") 1643 | <* else *> 1644 | println("D") 1645 | <* end *> 1646 | .... 1647 | 1648 | [appendix] 1649 | == Definition of terms 1650 | 1651 | Integer types:: 1652 | BYTE, INT8, INT16, INT32, INT64, SHORTINT, INTEGER, LONGINT 1653 | 1654 | Real types:: 1655 | REAL, LONGREAL 1656 | 1657 | Numeric types:: 1658 | integer types, real types 1659 | 1660 | Same types:: 1661 | Two variables a and b with types T~a~ and T~b~ are of the same type if 1662 | 1663 | 1. T~a~ and T~b~ are both denoted by the same type identifier, or 1664 | 2. T~a~ is declared to equal T~b~ in a type declaration of the form T~a~ = T~b~, or 1665 | 3. a and b appear in the same identifier list in a variable, record field, or formal parameter declaration and are not open arrays. 1666 | 1667 | Equal types:: 1668 | Two types T~a~ and T~b~ are equal if 1669 | 1670 | 1. T~a~ and T~b~ are the _same type_, or 1671 | 2. T~a~ and T~b~ are open array types with _equal element types_, or 1672 | 3. T~a~ and T~b~ are procedure types whose formal parameters _match_, or 1673 | 4. T~a~ and T~b~ are pointer types with _equal_ base types. 1674 | 1675 | Type inclusion:: 1676 | Numeric types include (the values of) smaller numeric types. WCHAR includes the values of CHAR. See <> for more information. 1677 | 1678 | Type extension (record):: 1679 | Given a type declaration T~b~ = RECORD(T~a~)...END, T~b~ is a direct extension of T~a~, and T~a~ is a direct base type of T~b~. A type T~b~ is an extension of a type T~a~ (T~a~ is a base type of T~b~) if 1680 | 1681 | 1. T~a~ and T~b~ are the _same types_, or 1682 | 2. T~b~ is a direct extension of T~a~. 1683 | 3. T~a~ is of type ANYREC. 1684 | 1685 | Type extension (pointer):: 1686 | If P~a~ = POINTER TO T~a~ and P~b~ = POINTER TO T~b~ , P~b~ is an extension of P~a~ (P~a~ is a base type of P~b~) if T~b~ is an extension of T~a~. 1687 | 1688 | [NOTE] 1689 | The extension relation is between record types or between pointer to record types; there is no extension relation between a pointer to record and a record type or between a record and a pointer to record type. 1690 | 1691 | Assignment compatible:: 1692 | An expression e of type T~e~ is assignment compatible with a variable v of type T~v~ if one of the following conditions hold: 1693 | 1694 | . T~e~ and T~v~ are the _same type_; 1695 | . T~e~ and T~v~ are numeric or character types and T~v~ _includes_ T~e~ footnote:[character types include strings with length 1]; 1696 | . T~v~ is a SET type and T~e~ is of INT32 or smaller type; 1697 | . T~v~ is a BYTE type and T~e~ is a Latin-1 character type; 1698 | . T~v~ is an integer type and T~e~ is a enumeration type; 1699 | . T~e~ and T~v~ are record types and T~e~ is a _type extension_ of T~v~ and the dynamic type of v is T~v~; 1700 | . T~e~ and T~v~ are pointer types and T~e~ is a _type extension_ of T~v~ or the pointers have _equal_ base types; 1701 | . T~v~ is a pointer or a procedure type and `e` is NIL; 1702 | . T~e~ is an open array and T~v~ is an array of _equal_ base type; 1703 | . T~v~ is an array of WCHAR, T~e~ is a Unicode BMP or Latin-1 string or character array, and STRLEN(e) < LEN(v); 1704 | . T~v~ is an array of CHAR, T~e~ is a Latin-1 string or character array, and STRLEN(e) < LEN(v); 1705 | . T~v~ is a procedure type and `e` is the name of a procedure whose formal parameters _match_ those of T~v~. 1706 | 1707 | 1708 | Parameter compatible:: 1709 | An actual parameter `a` of type T~a~ is parameter compatible with a formal parameter `f` of type T~f~ if 1710 | 1711 | 1. T~f~ and T~a~ are _equal_ types, or 1712 | 2. `f` is a value parameter and T~a~ is _assignment compatible_ with T~f~, or 1713 | 3. `f` is an IN or VAR parameter T~a~ must be the _same type_ as T~f~, or T~f~ must be a record type and T~a~ an _extension_ of T~f~. 1714 | 1715 | Array compatible:: 1716 | An actual parameter `a` of type T~a~ is array compatible with a formal parameter `f` of type T~f~ if 1717 | 1718 | 1. T~f~ and T~a~ are the _equal type_, or 1719 | 2. T~f~ is an open array, T~a~ is any array, and their element types are _array compatible_, or 1720 | 3. T~f~ is an open array of CHAR and T~a~ is a Latin-1 string, or 1721 | 4. T~f~ is an open array of WCHAR and T~a~ is a Unicode BMP or Latin-1 string, or 1722 | 5. T~f~ is an open array of BYTE and T~a~ is a byte string. 1723 | 1724 | Expression compatible:: 1725 | For a given operator, the types of its operands are expression compatible if they conform to the following table (which shows also the result type of the expression). CHAR and WCHAR arrays that are to be compared must contain 0X as a terminator. Type T1 must be an extension of type T0: 1726 | 1727 | [%header,cols="1,2,2,3"] 1728 | |=== 1729 | |operator |first operand |second operand |result type 1730 | |+ - * |numeric |numeric |smallest numeric type including both operands 1731 | |/ |numeric |numeric |smallest real type type including both operands 1732 | |+ - * / |SET |SET |SET 1733 | |DIV MOD |integer |integer |smallest integer type type including both operands 1734 | |OR & ~ |BOOLEAN |BOOLEAN |BOOLEAN 1735 | |= # < |numeric |numeric |BOOLEAN 1736 | |\<= > >= |CHAR |CHAR |BOOLEAN 1737 | | |CHAR array, string |CHAR array, string |BOOLEAN 1738 | |= # |BOOLEAN |BOOLEAN |BOOLEAN 1739 | | |SET |SET |BOOLEAN 1740 | | |NIL, pointer type T0 or T1 |NIL, pointer type T0 or T1 |BOOLEAN 1741 | | |procedure type T, NIL |procedure type T, NIL |BOOLEAN 1742 | |IN |integer |SET |BOOLEAN 1743 | |IS |type T0 |type T1 |BOOLEAN 1744 | |=== 1745 | 1746 | Matching formal parameter lists:: 1747 | Two formal parameter lists match if 1748 | 1749 | . they have the same number of parameters, and 1750 | . parameters at corresponding positions have _equal types_, and 1751 | . parameters at corresponding positions are both either value, VAR or IN parameters. 1752 | 1753 | Matching result types:: 1754 | The result types of two procedures match if they are either the _same type_ or none. 1755 | 1756 | [appendix] 1757 | == Syntax of Oberon+ 1758 | 1759 | .... 1760 | Oberon = module | definition 1761 | qualident = [ ident '.' ] ident 1762 | identdef = ident [ '*' | '-' ] 1763 | ConstDeclaration = identdef '=' ConstExpression 1764 | ConstExpression = expression 1765 | TypeDeclaration = identdef '=' type 1766 | type = NamedType | enumeration 1767 | | ArrayType | RecordType | PointerType | ProcedureType 1768 | NamedType = qualident 1769 | MetaParams = '(' MetaSection { [';'] MetaSection } ')' 1770 | MetaSection = [ TYPE | CONST ] ident { [','] ident } [ ':' NamedType ] 1771 | MetaActuals = '(' ConstExpression { [','] ConstExpression } ')' 1772 | enumeration = '(' ident { [','] ident } ')' 1773 | ArrayType = ARRAY [ LengthList ] OF type 1774 | | '[' [ LengthList ] ']' type 1775 | LengthList = length {',' length} | VAR varlength {',' varlength} 1776 | length = ConstExpression 1777 | varlength = expression 1778 | RecordType = RECORD ['(' BaseType ')'] [FieldListSequence] END 1779 | BaseType = NamedType 1780 | FieldListSequence = FieldList [ ';' ] { FieldList [ ';' ] } 1781 | FieldList = IdentList ':' type 1782 | IdentList = identdef { [','] identdef} 1783 | PointerType = ( POINTER TO | '^' ) type 1784 | ProcedureType = ( PROCEDURE | PROC ) ['(' ( POINTER | '^' ) ')'] [FormalParameters] 1785 | VariableDeclaration = IdentList ':' type 1786 | designator = qualident {selector} 1787 | selector = '.' ident | '[' ExpList ']' | '^' | '(' qualident ')' 1788 | ExpList = expression {',' expression} 1789 | expression = SimpleExpression [ relation SimpleExpression ] 1790 | relation = '=' | '#' | '<' | '<=' | '>' | '>=' | IN | IS 1791 | SimpleExpression = ['+' | '-'] term { AddOperator term } 1792 | AddOperator = '+' | '-' | OR 1793 | term = factor {MulOperator factor} 1794 | MulOperator = '*' | '/' | DIV | MOD | '&' 1795 | literal = number | string | hexstring | hexchar | NIL 1796 | | TRUE | FALSE | set 1797 | factor = literal 1798 | | designator [ActualParameters] 1799 | | '(' expression ')' | '~' factor 1800 | set = '{' [ element {',' element} ] '}' 1801 | element = expression ['..' expression] 1802 | ActualParameters = '(' [ExpList] ')' 1803 | statement = [ assignment | ProcedureCall 1804 | | IfStatement | CaseStatement 1805 | | WithStatement | LoopStatement 1806 | | ExitStatement | ReturnStatement 1807 | | WhileStatement | RepeatStatement | ForStatement ] 1808 | assignment = designator ':=' expression 1809 | ProcedureCall = designator [ActualParameters] 1810 | StatementSequence = statement { [";"] statement} 1811 | IfStatement = IF expression THEN StatementSequence 1812 | {ElsifStatement} [ElseStatement] END 1813 | ElsifStatement = ELSIF expression THEN StatementSequence 1814 | ElseStatement = ELSE StatementSequence 1815 | CaseStatement = CASE expression OF ['|'] Case { '|' Case } 1816 | [ ELSE StatementSequence ] END 1817 | Case = [ CaseLabelList ':' StatementSequence ] 1818 | CaseLabelList = LabelRange { ',' LabelRange } 1819 | LabelRange = label [ '..' label ] 1820 | label = ConstExpression 1821 | WhileStatement = WHILE expression DO StatementSequence 1822 | {ElsifStatement2} END 1823 | ElsifStatement2 = ELSIF expression DO StatementSequence 1824 | RepeatStatement = REPEAT StatementSequence UNTIL expression 1825 | ForStatement = FOR ident ':=' expression TO expression 1826 | [ BY ConstExpression ] DO StatementSequence END 1827 | WithStatement = WITH ['|'] Guard DO StatementSequence 1828 | { '|' Guard DO StatementSequence} 1829 | [ ELSE StatementSequence ] END 1830 | Guard = qualident ':' qualident 1831 | LoopStatement = LOOP StatementSequence END 1832 | ExitStatement = EXIT 1833 | ProcedureDeclaration = ProcedureHeading [ ';' ] 1834 | ProcedureBody END ident 1835 | ProcedureHeading = ( PROCEDURE | PROC ) [Receiver] 1836 | identdef [ FormalParameters ] 1837 | Receiver = '(' [VAR|IN] ident ':' ident ')' 1838 | ProcedureBody = DeclarationSequence 1839 | [ BEGIN StatementSequence 1840 | | ReturnStatement [ ';' ] ] 1841 | DeclarationSequence = 1842 | { CONST { ConstDeclaration [';'] } 1843 | | TYPE { TypeDeclaration [';'] } 1844 | | VAR { VariableDeclaration [';'] } 1845 | | ProcedureDeclaration [';'] } 1846 | ReturnStatement = RETURN [ expression ] 1847 | FormalParameters = '(' [ FPSection { [';'] FPSection } ] ')' 1848 | [ ':' ReturnType ] 1849 | ReturnType = type 1850 | FPSection = [ VAR | IN ] ident { [','] ident } ':' FormalType 1851 | FormalType = type 1852 | module = MODULE ident [ MetaParams ] [';'] { ImportList | DeclarationSequence } 1853 | [ BEGIN StatementSequence ] END ident ['.'] 1854 | ImportList = IMPORT import { [','] import } [';'] 1855 | import = [ ident ':=' ] ImportPath ident [ MetaActuals ] 1856 | ImportPath = { ident '.' } 1857 | definition = DEFINITION ident [';'] [ ImportList ] 1858 | DeclarationSequence2 END ident ['.'] 1859 | DeclarationSequence2 = 1860 | { CONST { ConstDeclaration [';'] } 1861 | | TYPE { TypeDeclaration [';'] } 1862 | | VAR { VariableDeclaration [';'] } 1863 | | ProcedureHeading [';'] } 1864 | .... 1865 | 1866 | [NOTE] 1867 | The <> and <> syntax is not included here. 1868 | 1869 | [appendix] 1870 | == More Code Examples 1871 | 1872 | .Procedural programming 1873 | [source,oberon] 1874 | ---- 1875 | module Fibonacci 1876 | proc calc*(n : integer): integer 1877 | var a, b: integer // comma is optional 1878 | begin 1879 | if n > 1 then 1880 | a := calc(n - 1) 1881 | b := calc(n - 2) 1882 | return a + b 1883 | elsif n = 0 then 1884 | return 0 1885 | else 1886 | return 1 1887 | end 1888 | end calc 1889 | var res: integer 1890 | begin 1891 | res := calc(21) 1892 | assert(res = 10946) 1893 | end Fibonacci 1894 | ---- 1895 | 1896 | .Generic programming 1897 | [source,oberon] 1898 | ---- 1899 | module Collections(T) 1900 | type Deque* = pointer to record 1901 | data: pointer to array of T 1902 | size: integer end 1903 | proc createDeque*(): Deque 1904 | const initial_len = 50 1905 | var this: Deque // this is initialized to nil 1906 | begin 1907 | new(this); new(this.data,initial_len) 1908 | // semicolon is optional 1909 | return this 1910 | // this and data will be garbage collected 1911 | end createDeque 1912 | 1913 | proc (this: Deque) append*(in element: T) 1914 | begin 1915 | if this.size = len(this.data) then assert(false) end 1916 | this.data[this.size] := element inc(this.size) 1917 | end append 1918 | 1919 | type Iterator* = record end 1920 | proc (var this: Iterator) apply*(in element: T) end 1921 | 1922 | proc (this: Deque) forEach*(var iter: Iterator) 1923 | var i: integer 1924 | begin 1925 | for i := 0 to this.size-1 do 1926 | iter.apply(this.data[i]) 1927 | end 1928 | end forEach 1929 | end Collections 1930 | ---- 1931 | 1932 | .Object-oriented programming 1933 | [source,oberon] 1934 | ---- 1935 | module Drawing 1936 | import F := Fibonacci 1937 | C := Collections(Figure) 1938 | 1939 | type Figure* = pointer to record 1940 | position: record 1941 | x,y: integer end end 1942 | proc (this: Figure) draw*() end 1943 | 1944 | type 1945 | Circle* = pointer to record (Figure) 1946 | diameter: integer end 1947 | Square* = pointer to record (Figure) 1948 | width: integer end 1949 | proc (this: Circle) draw*() end 1950 | proc (this: Square) draw*() end 1951 | 1952 | var figures: C.Deque 1953 | circle: Circle 1954 | square: Square 1955 | 1956 | proc drawAll() 1957 | type I = record(C.Iterator) count: integer end 1958 | proc (var this: I) apply( in figure: Figure ) 1959 | begin 1960 | figure.draw(); inc(this.count) 1961 | end apply 1962 | var i: I // count is initialized to zero 1963 | begin 1964 | figures.forEach(i) 1965 | assert(i.count = 2) 1966 | end drawAll 1967 | begin 1968 | figures := C.createDeque() 1969 | new(circle) 1970 | circle.position.x := F.calc(3) 1971 | circle.position.y := F.calc(4) 1972 | circle.diameter := 3 1973 | figures.append(circle) 1974 | new(square) 1975 | square.position.x := F.calc(5) 1976 | square.position.y := F.calc(6) 1977 | square.width := 4 1978 | figures.append(square) 1979 | drawAll() 1980 | end Drawing 1981 | ---- 1982 | 1983 | .Unicode support 1984 | [source,oberon] 1985 | ---- 1986 | module Unicode 1987 | var 1988 | str: array 32 of char 1989 | ustr: array 32 of wchar 1990 | begin 1991 | str := "Isto é português" 1992 | ustr := "美丽的世界,你好!" + " " + str 1993 | println(ustr) 1994 | // prints "美丽的世界,你好! Isto é português" 1995 | end Unicode 1996 | ---- 1997 | 1998 | 1999 | 2000 | [appendix] 2001 | // [bibliography] 2002 | == References 2003 | - [[[Ada83]]] ISO 8652:1987 Programming languages — Ada. International Organization for Standardization. 2004 | - [[[Mo91]]] Mössenböck, H.; Wirth, N. (1991). The Programming Language Oberon-2. Structured Programming, 12(4):179-195, 1991. http://www.ssw.uni-linz.ac.at/Research/Papers/Oberon2.pdf (accessed 2020-11-16). 2005 | - [[[Oak95]]] Kirk, B. et al. (1995). The Oakwood Guidelines for Oberon-2 Compiler Developers. Revision 1A. https://web.archive.org/web/20171226172235/https://www.math.bas.bg/bantchev/place/oberon/oakwood-guidelines.pdf (accessed 2022-04-26). 2006 | - [[[Om01]]] Oberon microsystems, Inc. (2001). Component Pascal Language Report. https://web.archive.org/web/20191021025943/http://www.oberon.ch/pdf/CP-Lang.pdf (accessed 2021-01-21). 2007 | - [[[Wi16]]] Wirth, N. (2016). The Programming Language Oberon. https://people.inf.ethz.ch/wirth/Oberon/Oberon07.Report.pdf (accessed 2020-11-16). 2008 | - [[[Wi73]]] Wirth, N. (1973). The Programming Language Pascal (Revised Report). ETH Report. https://doi.org/10.3929/ethz-a-000814158 (accessed 2020-11-16). 2009 | - [[[Wi87]]] Wirth, N. (1987). From Modula to Oberon and the programming language Oberon. ETH Report. https://doi.org/10.3929/ethz-a-005363226 (accessed 2020-11-16). 2010 | 2011 | 2012 | TODO: 2013 | - array literals, e.g. [ 1, 2, 3 ] or [ [1,2], [3,4], [5,6] ] 2014 | or like ISO Modula like Array1dType{ 1,2,3 } or Array2dType{ {1,2}, {3,4}, {5,6} } 2015 | which would also support record literals 2016 | - allow to register a type-bound procedure as a finalzier for a pointer to record 2017 | - literals and procedure refs as generic arguments, e.g. like ISO Modula 2018 | - combine generic modules with source code directives so that the directive can check the type of a type param; add built-in compile time functions to check for non anyrec descendant types (isinteger, isnumber, isreal, isboolean) 2019 | - means to avoid record assignment 2020 | - underscores or ' in number literals 2021 | - embedded type declaration, e.g. cast(type cpointer to void, x) 2022 | --------------------------------------------------------------------------------