|
108 | 108 | <li><!-- 13.2 --><a href="#Exceptions"><b>Exceptions</b></a></li> |
109 | 109 | <li><!-- 13.3 --><a href="#Handlers"><b>Handlers</b></a></li> |
110 | 110 | <li><!-- 13.4 --><a href="#Other_errors_and_warnings"><b>Other errors and warnings</b></a></li></ol> |
111 | | -</ol></p> |
| 111 | +</ol></p><hr> |
112 | 112 |
|
113 | | -<hr><p></p> |
| 113 | +<p></p> |
114 | 114 | <a name="INTRODUCTION"><big><b>1. INTRODUCTION</b></big></a> |
115 | 115 | <!-- =============== --> |
116 | 116 | <p></p> |
|
184 | 184 | <p> |
185 | 185 | Seed7 has the following features |
186 | 186 | </p><ul> |
187 | | - <li><!-- - -->It is object oriented</li> |
| 187 | + <li><!-- - -->User defined statements and operators.</li> |
188 | 188 |
|
189 | | - <li><!-- - -->User defined statements and operators</li> |
| 189 | + <li><!-- - -->Types are first class objects and therefore templates and |
| 190 | + generics can be defined easily without special syntax.</li> |
190 | 191 |
|
191 | | - <li><!-- - -->exception handling</li> |
| 192 | + <li><!-- - -->Predefined constructs like arrays or for-loops are |
| 193 | + declared in the language itself.</li> |
192 | 194 |
|
193 | | - <li><!-- - -->overloading of procedures/functions/operators/statements</li> |
| 195 | + <li><!-- - -->Object orientation is used where it brings advantages and |
| 196 | + not in places where other solutions are more obvious.</li> |
194 | 197 |
|
195 | | - <li><!-- - -->templates/generics (in the form of functions with |
196 | | - type results and type parameters)</li> |
| 198 | + <li><!-- - -->Strong typing</li> |
197 | 199 |
|
198 | | - <li><!-- - -->Resizable arrays</li> |
| 200 | + <li><!-- - -->exception handling</li> |
199 | 201 |
|
200 | | - <li><!-- - -->Bitsets</li> |
| 202 | + <li><!-- - -->overloading of procedures/functions/operators/statements</li> |
201 | 203 |
|
202 | | - <li><!-- - -->Strong typing</li> |
| 204 | + <li><!-- - -->Various predefined types like resizable arrays, hashes, |
| 205 | + bitsets, structs, etc.</li> |
203 | 206 | </ul><p> |
204 | | - |
205 | 207 | But a new programming language differs not only from existing |
206 | 208 | ones by new features. The real advantage comes from omitting |
207 | 209 | features which are outdated. |
|
323 | 325 | and chapter 4 contains various examples of syntax and semantic |
324 | 326 | declarations. The primary parts of the syntax are described in |
325 | 327 | the chapters 9 and 10. |
326 | | -</p> |
| 328 | +</p><hr> |
327 | 329 |
|
328 | | -<hr><p></p> |
| 330 | +<p></p> |
329 | 331 | <a name="TUTORIAL"><big><b>2. TUTORIAL</b></big></a> |
330 | 332 | <!-- =========== --> |
331 | 333 | <p> |
|
371 | 373 | <font color=blue>begin</font> |
372 | 374 | writeln(<font color=maroon>"hello world"</font>); |
373 | 375 | <font color=blue>end func</font>; |
374 | | - |
375 | | - $ <font color=blue>system</font> <font color=maroon>"main"</font> is main; |
376 | 376 | </pre><p> |
377 | 377 | The first line includes all definitions of the standard |
378 | 378 | library. In contrast to other standard libraries the seed7_05.s7i |
379 | 379 | library contains not only function declarations but also |
380 | 380 | declarations of statements and operators. |
381 | | -</p><p> |
382 | | - The last line specifies that in this program the object |
383 | | - <tt>'main'</tt> should be executed. |
| 381 | + Additionally the seed7_05.s7i library defines the '<tt>main</tt>' function |
| 382 | + as entry point for a Seed7 program. |
384 | 383 | </p><p> |
385 | 384 | If you write this program in a file called hello.sd7 |
386 | 385 | and execute the command |
|
433 | 432 | fahr := fahr + increment; |
434 | 433 | <font color=blue>end while</font>; |
435 | 434 | <font color=blue>end func</font>; |
436 | | - |
437 | | - $ <font color=blue>system</font> <font color=maroon>"main"</font> <font color=blue>is</font> main; |
438 | 435 | </pre><p> |
439 | 436 | Everything between <font color=green>(* and *)</font> is a comment which is ignored. |
440 | 437 | This program contains local constants and variables of the |
|
487 | 484 | writeln(fahr <font color=blue>lpad</font> 3 <& <font color=maroon>" "</font> <& celsius <font color=blue>digits</font> 2 <font color=blue>lpad</font> 6); |
488 | 485 | <font color=blue>end for</font>; |
489 | 486 | <font color=blue>end func</font>; |
490 | | - |
491 | | - $ <font color=blue>system</font> <font color=maroon>"main"</font> <font color=blue>is</font> main; |
492 | 487 | </pre><p> |
493 | 488 | To use the type <tt>'<font color=red>float</font>'</tt> it is necessary to include |
494 | 489 | <tt><font color=maroon>"float.s7i"</font></tt>. The <tt>'<font color=red>float</font>'</tt> variable <tt>'celsius'</tt> must be |
|
653 | 648 | <font color=blue>end for</font>; |
654 | 649 | writeln; |
655 | 650 | <font color=blue>end func</font>; |
656 | | - |
657 | | - $ <font color=blue>system</font> <font color=maroon>"main"</font> <font color=blue>is</font> main; |
658 | 651 | </pre><p> |
659 | 652 | The <tt>'<font color=blue>for</font>'</tt> statement iterates over <tt>'argv(PROGRAM)'</tt>. |
660 | 653 | The <tt>'argv(PROGRAM)'</tt> function returns an <tt>'<font color=red>array string</font>'</tt> |
|
691 | 684 | <font color=blue>const</font> <font color=red>proc</font>: FOR_DECLS (<font color=blue>in</font> <font color=red>type</font>: aType) <font color=blue>is func</font> |
692 | 685 | <font color=blue>begin</font> |
693 | 686 |
|
694 | | - <font color=blue>const</font> <font color=red>proc</font>: for (<font color=blue>inout</font> <font color=red>aType</font>: variable) range (<font color=blue>in</font> <font color=red>aType</font>: lower_limit) to (<font color=blue>in</font> <font color=red>aType</font>: upper_limit) do |
| 687 | + <font color=blue>const</font> <font color=red>proc</font>: for (<font color=blue>inout</font> <font color=red>aType</font>: variable) range (<font color=blue>in</font> <font color=red>aType</font>: low) to (<font color=blue>in</font> <font color=red>aType</font>: high) do |
695 | 688 | (<font color=blue>in</font> <font color=red>proc</font>: statements) end for <font color=blue>is func</font> |
696 | 689 | <font color=blue>begin</font> |
697 | | - variable := lower_limit; |
698 | | - <font color=blue>if</font> variable <= upper_limit <font color=blue>then</font> |
| 690 | + variable := low; |
| 691 | + <font color=blue>if</font> variable <= high <font color=blue>then</font> |
699 | 692 | statements; |
700 | | - <font color=blue>while</font> variable < upper_limit <font color=blue>do</font> |
| 693 | + <font color=blue>while</font> variable < high <font color=blue>do</font> |
701 | 694 | incr(variable); |
702 | 695 | statements; |
703 | 696 | <font color=blue>end while</font>; |
|
714 | 707 | <font color=red>char</font> and <font color=red>boolean</font> as parameter creates corresponding declarations |
715 | 708 | of <tt>'<font color=blue>for</font>'</tt> statements. The example above is a simplified part of |
716 | 709 | the standard Seed7 library <font color=maroon>"seed7_05.s7i"</font>. |
| 710 | +</p><hr> |
717 | 711 |
|
718 | | -<hr><p></p> |
| 712 | +<p></p> |
719 | 713 | <a name="SYNTAX"><big><b>3. SYNTAX</b></big></a> |
720 | 714 | <!-- ========= --> |
721 | 715 | <p> |
|
922 | 916 | Note that the second line of syntax description is different |
923 | 917 | to the syntax description of the previous example. The 'else' |
924 | 918 | is taken out to form an expression of its own. |
925 | | -</p> |
| 919 | +</p><hr> |
926 | 920 |
|
927 | | -<hr><p></p> |
| 921 | +<p></p> |
928 | 922 | <a name="PREDEFINED_STATEMENTS"><big><b>4. PREDEFINED STATEMENTS</b></big></a> |
929 | 923 | <!-- ======================== --> |
930 | 924 | <p> |
|
1412 | 1406 |
|
1413 | 1407 | CASE_DECLS(<font color=red>integer</font>); |
1414 | 1408 | CASE_DECLS(<font color=red>char</font>); |
1415 | | -</pre><p></p> |
| 1409 | +</pre><p></p><hr> |
1416 | 1410 |
|
1417 | | -<hr><p></p> |
| 1411 | +<p></p> |
1418 | 1412 | <a name="PREDEFINED_TYPES"><big><b>5. PREDEFINED TYPES</b></big></a> |
1419 | 1413 | <!-- =================== --> |
1420 | 1414 | <p> |
|
2674 | 2668 | Functions: |
2675 | 2669 | WRITE_EXPR(A) |
2676 | 2670 | Write expr A to FILE OUT |
2677 | | -</pre><p></p> |
| 2671 | +</pre><p></p><hr> |
2678 | 2672 |
|
2679 | | -<hr><p></p> |
| 2673 | +<p></p> |
2680 | 2674 | <a name="PARAMETERS"><big><b>6. PARAMETERS</b></big></a> |
2681 | 2675 | <!-- ============= --> |
2682 | 2676 | <p> |
|
3000 | 2994 | </p><pre> |
3001 | 2995 | symbol_parameter ::= |
3002 | 2996 | name_identifier | special_identifier . |
3003 | | -</pre><p></p> |
| 2997 | +</pre><p></p><hr> |
3004 | 2998 |
|
3005 | | -<hr><p></p> |
| 2999 | +<p></p> |
3006 | 3000 | <a name="THE_FILE_SYSTEM"><big><b>7. THE FILE SYSTEM</b></big></a> |
3007 | 3001 | <!-- ================== --> |
3008 | 3002 | <p> |
|
3028 | 3022 | </p><pre> |
3029 | 3023 | writeln(<font color=maroon>"result = "</font> <& number <font color=blue>div</font> 5 <& <font color=maroon>" "</font> <& <font color=blue>not</font> error); |
3030 | 3024 | </pre><p> |
3031 | | - The <tt>'<&'</tt> operator requests a <tt>'<font color=blue>string</font>'</tt> as left operand and |
3032 | | - is overloaded for various types as right operand. |
| 3025 | + The <tt>'<&'</tt> operator needs a <tt>'<font color=blue>string</font>'</tt> as left operand and |
| 3026 | + is overloaded for various types as right operand. To allow things like |
| 3027 | +</p><pre> |
| 3028 | + write(next_time <& <font color=maroon>" \r"</font>); |
| 3029 | +</pre><p> |
| 3030 | + the <tt>'<&'</tt> operator is also overloaded for various types as |
| 3031 | + left operand and a <tt>'<font color=blue>string</font>'</tt> as right operand. |
| 3032 | + This allows you to concatenate several objects with <tt>'<&'</tt> when |
| 3033 | + at least the first or the second object is a <tt>'<font color=blue>string</font>'</tt>. |
3033 | 3034 | We can also read data from the keyboard: |
3034 | 3035 | </p><pre> |
3035 | 3036 | write(<font color=maroon>"Amount? "</font>); |
|
3765 | 3766 | <font color=green>(* Statements that do the input *)</font> |
3766 | 3767 | ... |
3767 | 3768 | <font color=blue>end func</font>; |
3768 | | -</pre><p></p> |
| 3769 | +</pre><p></p><hr> |
3769 | 3770 |
|
3770 | | -<hr><p></p> |
| 3771 | +<p></p> |
3771 | 3772 | <a name="DECLARATIONS"><big><b>8. DECLARATIONS</b></big></a> |
3772 | 3773 | <!-- =============== --> |
3773 | 3774 | <p> |
|
3994 | 3995 | is already defined. To allow the declaration of objects of a |
3995 | 3996 | new user defined type the constructor operation for this type |
3996 | 3997 | must be defined. |
3997 | | -</p> |
| 3998 | +</p><hr> |
3998 | 3999 |
|
3999 | | -<hr><p></p> |
| 4000 | +<p></p> |
4000 | 4001 | <a name="TOKENS"><big><b>9. TOKENS</b></big></a> |
4001 | 4002 | <!-- ========= --> |
4002 | 4003 | <p> |
|
4293 | 4294 | '\a' | '\b' | '\e' | '\f' | '\n' | '\r' | '\t' | '\v' | |
4294 | 4295 | '\\' | '\''' | '\"' | '\' upper_case_letter | |
4295 | 4296 | '\' { space } '\' | '\' integer_literal '\' . |
4296 | | -</pre><p></p> |
| 4297 | +</pre><p></p><hr> |
4297 | 4298 |
|
4298 | | -<hr><p></p> |
| 4299 | +<p></p> |
4299 | 4300 | <a name="EXPRESSIONS"><big><b>10. EXPRESSIONS</b></big></a> |
4300 | 4301 | <!-- =============== --> |
4301 | 4302 | <p> |
|
4396 | 4397 | </p><pre> |
4397 | 4398 | dot_expression ::= |
4398 | 4399 | [ '.' ] call_expression { '.' call_expression } . |
4399 | | -</pre><p></p> |
| 4400 | +</pre><p></p><hr> |
4400 | 4401 |
|
4401 | | -<hr><p></p> |
| 4402 | +<p></p> |
4402 | 4403 | <a name="OPERATING_SYSTEM_ACCESS"><big><b>11. OPERATING SYSTEM ACCESS</b></big></a> |
4403 | 4404 | <!-- =========================== --> |
4404 | 4405 | <p> |
|
4481 | 4482 | remove(<font color=maroon>"file"</font>); |
4482 | 4483 | rename(<font color=maroon>"old_name"</font>, <font color=maroon>"new_name"</font>); |
4483 | 4484 | copy(<font color=maroon>"from"</font>, <font color=maroon>"to"</font>); |
4484 | | -</pre><p></p> |
| 4485 | +</pre><p></p><hr> |
4485 | 4486 |
|
4486 | | -<hr><p></p> |
| 4487 | +<p></p> |
4487 | 4488 | <a name="PRIMITIVE_ACTIONS"><big><b>12. PRIMITIVE ACTIONS</b></big></a> |
4488 | 4489 | <!-- ===================== --> |
4489 | 4490 | <p> |
|
4580 | 4581 | </pre><p> |
4581 | 4582 | If you are interested in the primitive actions just look into |
4582 | 4583 | the file seed7_05.s7i . |
4583 | | -</p> |
| 4584 | +</p><hr> |
4584 | 4585 |
|
4585 | | -<hr><p></p> |
| 4586 | +<p></p> |
4586 | 4587 | <a name="ERRORS"><big><b>13. ERRORS</b></big></a> |
4587 | 4588 | <!-- ========== --> |
4588 | 4589 | <p></p> |
|
0 commit comments