├── .gitattributes ├── .gitignore ├── LICENSE ├── README.md ├── _config.yml ├── examples ├── arguments │ └── unixstyle_oberon_traditional │ │ ├── makefile │ │ ├── partest.Mod │ │ └── readme.md ├── arrays │ ├── Arrays.Mod │ └── Makefile ├── case │ ├── Case.Mod │ └── Makefile ├── constants │ ├── Constants.Mod │ └── Makefile ├── enums_example │ ├── 0 │ │ ├── Days.Mod │ │ ├── readme.md │ │ └── test.Mod │ └── 1 │ │ ├── Days.Mod │ │ ├── readme.md │ │ └── test.Mod ├── for │ ├── For.Mod │ └── Makefile ├── hello-world │ ├── Console │ │ ├── Hello.Mod │ │ └── Makefile │ └── Out │ │ ├── Hello.Mod │ │ └── Makefile ├── ifelse │ ├── IfElse.Mod │ └── Makefile ├── procedures │ ├── function-procedure │ │ ├── Makefile │ │ └── Square.Mod │ ├── procedure │ │ ├── Makefile │ │ └── Procedure.Mod │ └── var-parameter │ │ ├── Makefile │ │ └── VarParam.Mod ├── records │ └── Records.Mod ├── recursion │ ├── Fib.Mod │ └── Gcd.Mod ├── value-types │ ├── Makefile │ └── Values.Mod ├── variables │ ├── Makefile │ └── Variables.Mod └── while │ ├── Makefile │ └── While.Mod └── src └── obe.Mod /.gitattributes: -------------------------------------------------------------------------------- 1 | *.Mod linguist-language=Oberon 2 | 3 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | build/* 2 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | This is free and unencumbered software released into the public domain. 2 | 3 | Anyone is free to copy, modify, publish, use, compile, sell, or 4 | distribute this software, either in source code form or as a compiled 5 | binary, for any purpose, commercial or non-commercial, and by any 6 | means. 7 | 8 | In jurisdictions that recognize copyright laws, the author or authors 9 | of this software dedicate any and all copyright interest in the 10 | software to the public domain. We make this dedication for the benefit 11 | of the public at large and to the detriment of our heirs and 12 | successors. We intend this dedication to be an overt act of 13 | relinquishment in perpetuity of all present and future rights to this 14 | software under copyright law. 15 | 16 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 17 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 18 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 19 | IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR 20 | OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, 21 | ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 22 | OTHER DEALINGS IN THE SOFTWARE. 23 | 24 | For more information, please refer to 25 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | ## Oberon by Examples 2 | 3 | [Oberon](https://en.wikipedia.org/wiki/Oberon_(programming_language)) is a general-purpose programming language created in 1986 by Niklaus Wirth and the latest member of the Wirthian family of ALGOL-like languages. 4 | 5 | [Oberon-2](https://en.wikipedia.org/wiki/Oberon-2) is an extension of the original Oberon programming language developed in 1991 at ETH Zurich by Niklaus Wirth and Hanspeter Mössenböck that adds limited reflection and object-oriented programming facilities, open arrays as pointer base types, read-only field export. 6 | 7 | Oberon By Example is a hands-on introduction to Oberon-2 using examples. 8 | 9 | This repository is under heavy modification to make it better for beginners. 10 | 11 | To start, make sure you have [Vishap Oberon Compiler](https://github.com/vishapoberon/voc) 12 | 13 | Check out the [hello-world](https://github.com/vishapoberon/oberonbyexample/tree/master/examples/hello-world) example or browse the full list below. 14 | 15 | - [Hello World](https://github.com/vishapoberon/oberonbyexample/tree/master/examples/hello-world) 16 | - [Types](https://github.com/vishapoberon/oberonbyexample/tree/master/examples/value-types) 17 | - [Variables](https://github.com/vishapoberon/oberonbyexample/tree/master/examples/variables) 18 | - [Constants](https://github.com/vishapoberon/oberonbyexample/tree/master/examples/constants) 19 | - [For](https://github.com/vishapoberon/oberonbyexample/tree/master/examples/for) 20 | - [While](https://github.com/vishapoberon/oberonbyexample/tree/master/examples/while) 21 | - [If/Else](https://github.com/vishapoberon/oberonbyexample/tree/master/examples/ifelse) 22 | - [Case](https://github.com/vishapoberon/oberonbyexample/tree/master/examples/case) 23 | - [Arrays](https://github.com/vishapoberon/oberonbyexample/tree/master/examples/arrays) 24 | - [Procedures](https://github.com/vishapoberon/oberonbyexample/tree/master/examples/procedures) 25 | - [Procedure](https://github.com/vishapoberon/oberonbyexample/tree/master/examples/procedures/procedure) 26 | - [Functions](https://github.com/vishapoberon/oberonbyexample/tree/master/examples/procedures/function-procedure) 27 | - [VAR-Parameters](https://github.com/vishapoberon/oberonbyexample/tree/master/examples/procedures/var-parameter) 28 | - TODO 29 | -------------------------------------------------------------------------------- /_config.yml: -------------------------------------------------------------------------------- 1 | theme: jekyll-theme-minimal -------------------------------------------------------------------------------- /examples/arguments/unixstyle_oberon_traditional/makefile: -------------------------------------------------------------------------------- 1 | 2 | VOC = /opt/voc/bin/voc 3 | 4 | 5 | all: 6 | $(VOC) -m partest.Mod 7 | 8 | 9 | test: 10 | ./partest -str aaa -int 111 11 | ./partest -str 1 -int 111 12 | -------------------------------------------------------------------------------- /examples/arguments/unixstyle_oberon_traditional/partest.Mod: -------------------------------------------------------------------------------- 1 | MODULE partest; 2 | 3 | IMPORT Oberon, Texts; 4 | 5 | CONST 6 | argStr0 = "str"; (* we only have two types of args, one string and one int *) 7 | argInt0 = "int"; (* i. e. -str somestring -int somenumber *) 8 | 9 | VAR 10 | W: Texts.Writer; (* for console output *) 11 | S: Texts.Scanner; T: Texts.Text; 12 | BEGIN 13 | Texts.OpenWriter(W); 14 | Texts.WriteString(W, "hello, world, let's see which arguments do we get"); Texts.WriteLn(W); 15 | 16 | (* open arguments scanner *) 17 | Texts.OpenScanner(S, Oberon.Par.text, Oberon.Par.pos); 18 | 19 | WHILE ~S.eot DO 20 | Texts.Scan(S); 21 | 22 | IF S.class = Texts.Char THEN (* do we get '-' sign ? *) 23 | IF S.c = "-" THEN 24 | Texts.Scan(S); 25 | IF S.class = Texts.Name THEN (* we got the key *) 26 | Texts.WriteString(W, "key: "); Texts.WriteString(W, S.s); Texts.WriteLn(W); 27 | (* now get the value *) 28 | IF S.s = argStr0 THEN 29 | Texts.Scan(S); 30 | IF S.class = Texts.Name THEN 31 | Texts.WriteString(W, "value: "); Texts.WriteString (W, S.s); Texts.WriteLn(W); Texts.Append(Oberon.Log, W.buf); 32 | ELSE 33 | Texts.WriteString(W, "string expected"); Texts.WriteLn(W); 34 | Texts.Append(Oberon.Log, W.buf); 35 | HALT(1); 36 | END; 37 | ELSIF S.s = argInt0 THEN 38 | Texts.Scan(S); 39 | IF S.class = Texts.Int THEN 40 | Texts.WriteString(W, "value: "); Texts.WriteInt (W, S.i, 0); Texts.WriteLn(W); Texts.Append(Oberon.Log, W.buf); 41 | ELSE 42 | Texts.WriteString(W, "integer expected"); Texts.WriteLn(W); 43 | Texts.Append(Oberon.Log, W.buf); 44 | HALT(1); 45 | END; 46 | END; 47 | ELSE 48 | (* we were expecting characters after the '-' sign *) 49 | Texts.WriteString(W, "key name expected"); Texts. WriteLn(W); 50 | Texts.Append(Oberon.Log, W.buf); 51 | HALT(1); 52 | END; 53 | END 54 | ELSE 55 | Texts.WriteString(W, "key option must start with '-' sign "); Texts.WriteLn(W); 56 | HALT(1); 57 | END; (* if got '-' *) 58 | Oberon.Par.pos := Texts.Pos(S); 59 | Texts.Append(Oberon.Log, W.buf) 60 | END; (* while *) 61 | 62 | 63 | END partest. 64 | -------------------------------------------------------------------------------- /examples/arguments/unixstyle_oberon_traditional/readme.md: -------------------------------------------------------------------------------- 1 | 2 | example shows how to implement unix style arguments parsing by using traditional oberon functions from modules Texts and Oberon. 3 | 4 | compile 5 | ======= 6 | 7 | ``` 8 | make 9 | ``` 10 | 11 | run 12 | === 13 | 14 | ``` 15 | make test 16 | ``` 17 | 18 | or type 19 | 20 | ``` 21 | ./partest -str aaa -int 111 22 | ``` 23 | 24 | that should produce the following output 25 | 26 | ``` 27 | hello, world, let's see which arguments do we get 28 | key: str 29 | value: aaa 30 | key: int 31 | value: 111 32 | ``` 33 | 34 | ``` 35 | ./partest -str 000 -int 111 36 | ``` 37 | 38 | the output will be 39 | 40 | ``` 41 | hello, world, let's see which arguments do we get 42 | key: str 43 | string expected 44 | Terminated by Halt(1). 45 | ``` 46 | 47 | that's all folks. 48 | -------------------------------------------------------------------------------- /examples/arrays/Arrays.Mod: -------------------------------------------------------------------------------- 1 | MODULE arrays; 2 | 3 | IMPORT Out; 4 | 5 | VAR 6 | tmp : INTEGER; 7 | matrix : ARRAY 3 OF ARRAY 3 OF INTEGER; 8 | i, v, k : INTEGER; 9 | 10 | BEGIN 11 | v := 1; 12 | FOR i := 0 TO LEN(matrix) - 1 DO 13 | FOR k := 0 TO LEN(matrix[i]) - 1 DO 14 | matrix[i][k] := v; 15 | INC(v); 16 | END; 17 | END; 18 | 19 | FOR i := 0 TO LEN(matrix) - 1 DO 20 | FOR k := 0 TO LEN(matrix[i]) - 1 DO 21 | Out.Int(matrix[i][k], 0); Out.String(" "); 22 | END; 23 | Out.Ln; 24 | END; 25 | 26 | FOR i := 0 TO LEN(matrix) - 1 DO 27 | FOR k := i + 1 TO LEN(matrix[i]) - 1 DO 28 | tmp := matrix[i][k]; 29 | matrix[i][k] := matrix[k][i]; 30 | matrix[k][i] := tmp; 31 | END; 32 | END; 33 | 34 | Out.Ln; Out.Ln; 35 | 36 | FOR i := 0 TO LEN(matrix) - 1 DO 37 | FOR k := 0 TO LEN(matrix[i]) - 1 DO 38 | Out.Int(matrix[i][k], 0); Out.String(" "); 39 | END; 40 | Out.Ln; 41 | END; 42 | END arrays. 43 | -------------------------------------------------------------------------------- /examples/arrays/Makefile: -------------------------------------------------------------------------------- 1 | VOC = /opt/voc/bin/voc 2 | 3 | all: 4 | $(VOC) -m Arrays.Mod 5 | 6 | clean: 7 | rm *.c 8 | rm *.h 9 | rm *.o 10 | rm *.sym 11 | -------------------------------------------------------------------------------- /examples/case/Case.Mod: -------------------------------------------------------------------------------- 1 | MODULE case; 2 | 3 | 4 | IMPORT Out, Modules; 5 | 6 | 7 | BEGIN 8 | CASE Modules.ArgCount - 1 OF 9 | 0 : Out.String("There are no arguments"); 10 | | 1 : Out.String("There is one argument"); 11 | | 2 : Out.String("There are two arguments"); 12 | ELSE Out.String("There are more than two arguments") END; 13 | Out.Ln; 14 | END case. 15 | -------------------------------------------------------------------------------- /examples/case/Makefile: -------------------------------------------------------------------------------- 1 | VOC = /opt/voc/bin/voc 2 | 3 | all: 4 | $(VOC) -m Case.Mod 5 | 6 | clean: 7 | rm *.c 8 | rm *.h 9 | rm *.o 10 | rm *.sym 11 | -------------------------------------------------------------------------------- /examples/constants/Constants.Mod: -------------------------------------------------------------------------------- 1 | MODULE constants; 2 | 3 | IMPORT Out; 4 | 5 | CONST 6 | s = "if it moves, compile it!"; 7 | n = 42; 8 | m = n * 2; 9 | 10 | BEGIN 11 | Out.String(s); Out.Ln; 12 | Out.Int(n, 0); Out.Ln; 13 | Out.Int(m, 0); Out.Ln; 14 | END constants. 15 | -------------------------------------------------------------------------------- /examples/constants/Makefile: -------------------------------------------------------------------------------- 1 | VOC = /opt/voc/bin/voc 2 | 3 | all: 4 | $(VOC) -m Constants.Mod 5 | 6 | clean: 7 | rm *.c 8 | rm *.h 9 | rm *.o 10 | rm *.sym 11 | -------------------------------------------------------------------------------- /examples/enums_example/0/Days.Mod: -------------------------------------------------------------------------------- 1 | MODULE Days; 2 | 3 | TYPE 4 | Day* = POINTER TO DayDesc; 5 | DayDesc = RECORD 6 | next, prev : Day 7 | END; 8 | Week = ARRAY 7 OF Day; 9 | 10 | VAR 11 | sun*, mon*, tue*, wed*, thu*, fri*, sat* : Day; 12 | week: Week; 13 | 14 | PROCEDURE Next*(d : Day): Day; 15 | BEGIN 16 | RETURN d.next 17 | END Next; 18 | 19 | PROCEDURE Prev*(d: Day): Day; 20 | BEGIN 21 | RETURN d.prev; 22 | END Prev; 23 | 24 | PROCEDURE inc(VAR j: SHORTINT); 25 | BEGIN 26 | IF j = 6 THEN 27 | j := 0 28 | ELSE 29 | INC(j) 30 | END 31 | END inc; 32 | 33 | PROCEDURE dec(VAR j: SHORTINT); 34 | BEGIN 35 | IF j = 0 THEN 36 | j := 6 37 | ELSE 38 | DEC(j) 39 | END 40 | END dec; 41 | 42 | PROCEDURE init(VAR w : Week); 43 | VAR 44 | i,j : SHORTINT; 45 | BEGIN 46 | i := 0; 47 | REPEAT 48 | j := i; inc(j); 49 | w[i].next := w[j]; 50 | j := i; dec(j); 51 | w[i].prev := w[j]; 52 | INC(i) 53 | UNTIL i > 6; 54 | END init; 55 | 56 | BEGIN 57 | NEW(sun); NEW(mon); NEW(tue); NEW(wed); NEW(thu); NEW(fri); NEW(sat); 58 | week[0] := sun; 59 | week[1] := mon; 60 | week[2] := tue; 61 | week[3] := wed; 62 | week[4] := thu; 63 | week[5] := fri; 64 | week[6] := sat; 65 | 66 | init(week); 67 | 68 | END Days. 69 | -------------------------------------------------------------------------------- /examples/enums_example/0/readme.md: -------------------------------------------------------------------------------- 1 | 2 | 3 | Example aimed to show how to survive without enumerations in Oberon. 4 | 5 | This way is even cooler than enumerations. (: 6 | 7 | -------------------------------------------------------------------------------- /examples/enums_example/0/test.Mod: -------------------------------------------------------------------------------- 1 | MODULE test; 2 | 3 | IMPORT Days, Out; 4 | 5 | VAR today, yesterday, tomorrow: Days.Day; 6 | 7 | BEGIN 8 | today := Days.mon; (*init*) 9 | 10 | yesterday := Days.Prev(today); 11 | IF yesterday = Days.sun 12 | THEN 13 | Out.String("it works!"); Out.Ln 14 | END; 15 | tomorrow := Days.Next(today); 16 | 17 | IF tomorrow = Days.tue 18 | THEN 19 | Out.String("it works!"); Out.Ln 20 | END; 21 | 22 | END test. 23 | -------------------------------------------------------------------------------- /examples/enums_example/1/Days.Mod: -------------------------------------------------------------------------------- 1 | MODULE Days; 2 | 3 | TYPE 4 | Day* = POINTER TO DayDesc; 5 | DayDesc = RECORD 6 | num: INTEGER 7 | END; 8 | Week* = ARRAY 7 OF Day; 9 | VAR 10 | sun*, mon*, tue*, wed*, thu*, fri*, sat* : Day; 11 | week: Week; 12 | 13 | PROCEDURE Next*(d : Day): Day; 14 | BEGIN RETURN week[(d.num + 1) MOD 7]; 15 | END Next; 16 | 17 | PROCEDURE Prev*(d: Day): Day; 18 | BEGIN RETURN week[(d.num - 1) MOD 7]; 19 | END Prev; 20 | 21 | PROCEDURE day(VAR d: Day; num: INTEGER); 22 | BEGIN NEW(d); d.num := num; week[num] := d; 23 | END day; 24 | 25 | BEGIN 26 | day(sun, 0); 27 | day(mon, 1); 28 | day(tue, 2); 29 | day(wed, 3); 30 | day(thu, 4); 31 | day(fri, 5); 32 | day(sat, 6); 33 | END Days. 34 | -------------------------------------------------------------------------------- /examples/enums_example/1/readme.md: -------------------------------------------------------------------------------- 1 | 2 | 3 | Example aimed to show how to survive without enumerations in Oberon. 4 | 5 | This example is contributed by @pdewacht. 6 | -------------------------------------------------------------------------------- /examples/enums_example/1/test.Mod: -------------------------------------------------------------------------------- 1 | MODULE test; 2 | 3 | IMPORT Days, Out; 4 | 5 | VAR today, yesterday, tomorrow: Days.Day; 6 | 7 | BEGIN 8 | today := Days.mon; (*init*) 9 | 10 | yesterday := Days.Prev(today); 11 | IF yesterday = Days.sun 12 | THEN 13 | Out.String("it works!"); Out.Ln 14 | END; 15 | tomorrow := Days.Next(today); 16 | 17 | IF tomorrow = Days.tue 18 | THEN 19 | Out.String("it works!"); Out.Ln 20 | END; 21 | 22 | END test. 23 | -------------------------------------------------------------------------------- /examples/for/For.Mod: -------------------------------------------------------------------------------- 1 | MODULE for; 2 | 3 | IMPORT Out; 4 | 5 | VAR 6 | i : INTEGER; 7 | 8 | 9 | BEGIN 10 | Out.String("i is "); Out.Int(i, 0); Out.Ln; 11 | Out.String("For loop started"); Out.Ln; 12 | FOR i := 0 TO 10 DO 13 | Out.String("i : "); Out.Int(i, 0); Out.Ln; 14 | END; 15 | Out.String("For-By loop started"); Out.Ln; 16 | FOR i := 0 TO 10 BY 2 DO 17 | Out.String("i : "); Out.Int(i, 0); Out.Ln; 18 | END; 19 | END for. 20 | -------------------------------------------------------------------------------- /examples/for/Makefile: -------------------------------------------------------------------------------- 1 | VOC = /opt/voc/bin/voc 2 | 3 | all: 4 | $(VOC) -m For.Mod 5 | 6 | clean: 7 | rm *.c 8 | rm *.h 9 | rm *.o 10 | rm *.sym 11 | -------------------------------------------------------------------------------- /examples/hello-world/Console/Hello.Mod: -------------------------------------------------------------------------------- 1 | MODULE hello; 2 | 3 | 4 | IMPORT Console; 5 | 6 | 7 | BEGIN 8 | Console.String("Hello World!"); 9 | Console.Ln 10 | END hello. 11 | -------------------------------------------------------------------------------- /examples/hello-world/Console/Makefile: -------------------------------------------------------------------------------- 1 | VOC = /opt/voc/bin/voc 2 | 3 | all: 4 | $(VOC) -m Hello.Mod 5 | 6 | clean: 7 | rm *.c 8 | rm *.h 9 | rm *.o 10 | rm *.sym 11 | -------------------------------------------------------------------------------- /examples/hello-world/Out/Hello.Mod: -------------------------------------------------------------------------------- 1 | MODULE hello; 2 | 3 | 4 | IMPORT Out; 5 | 6 | 7 | BEGIN 8 | Out.String("Hello, World"); Out.Ln 9 | END hello. 10 | -------------------------------------------------------------------------------- /examples/hello-world/Out/Makefile: -------------------------------------------------------------------------------- 1 | VOC = /opt/voc/bin/voc 2 | 3 | all: 4 | $(VOC) -m Hello.Mod 5 | 6 | clean: 7 | rm *.c 8 | rm *.h 9 | rm *.o 10 | rm *.sym 11 | -------------------------------------------------------------------------------- /examples/ifelse/IfElse.Mod: -------------------------------------------------------------------------------- 1 | MODULE ifelse; 2 | 3 | 4 | IMPORT Out; 5 | 6 | VAR n, m : INTEGER; 7 | 8 | 9 | BEGIN 10 | n := 8; m := 4; 11 | 12 | IF n MOD m = 0 THEN 13 | Out.Int(n,0); Out.String(" is divisible by "); Out.Int(m,0); Out.Ln; 14 | END; 15 | 16 | n := 7; m := 6; 17 | 18 | IF n * m = 42 THEN 19 | Out.Int(n,0); Out.String(" times "); Out.Int(m,0); Out.String(" equals 42"); Out.Ln; 20 | END; 21 | 22 | IF n # m THEN Out.Int(n,0); Out.String(" does not equal "); Out.Int(m,0); Out.Ln; END; 23 | 24 | IF ODD(n) 25 | THEN 26 | Out.Int(n,0); Out.String(" is odd"); Out.Ln; 27 | ELSE 28 | Out.Int(n,0); Out.String(" is even"); Out.Ln; 29 | END; 30 | 31 | IF ~ODD(m) 32 | THEN 33 | Out.Int(m,0); Out.String(" is even"); Out.Ln; 34 | ELSE 35 | Out.Int(m,0); Out.String(" is odd"); Out.Ln; 36 | END; 37 | 38 | n := 9; 39 | 40 | IF n < 0 41 | THEN 42 | Out.Int(n, 0); Out.String(" is negative"); Out.Ln; 43 | ELSIF n < 10 44 | THEN 45 | Out.Int(n, 0); Out.String(" has 1 digit"); Out.Ln; 46 | ELSE 47 | Out.Int(n, 0); Out.String(" has multiple digits"); Out.Ln; 48 | END; 49 | END ifelse. 50 | -------------------------------------------------------------------------------- /examples/ifelse/Makefile: -------------------------------------------------------------------------------- 1 | VOC = /opt/voc/bin/voc 2 | 3 | all: 4 | $(VOC) -m IfElse.Mod 5 | 6 | clean: 7 | rm *.c 8 | rm *.h 9 | rm *.o 10 | rm *.sym 11 | -------------------------------------------------------------------------------- /examples/procedures/function-procedure/Makefile: -------------------------------------------------------------------------------- 1 | VOC = /opt/voc/bin/voc 2 | 3 | all: 4 | $(VOC) -m Square.Mod 5 | 6 | clean: 7 | rm *.c 8 | rm *.h 9 | rm *.o 10 | rm *.sym 11 | -------------------------------------------------------------------------------- /examples/procedures/function-procedure/Square.Mod: -------------------------------------------------------------------------------- 1 | MODULE square; 2 | 3 | 4 | IMPORT Out; 5 | 6 | 7 | VAR s : INTEGER; 8 | 9 | 10 | PROCEDURE squared(x : INTEGER): INTEGER; 11 | BEGIN 12 | RETURN x * x 13 | END squared; 14 | 15 | 16 | BEGIN 17 | s := squared(7); 18 | Out.Int(s, 0); Out.Ln; 19 | Out.Int(squared(8), 0); Out.Ln; 20 | END square. 21 | -------------------------------------------------------------------------------- /examples/procedures/procedure/Makefile: -------------------------------------------------------------------------------- 1 | VOC = /opt/voc/bin/voc 2 | 3 | all: 4 | $(VOC) -m Procedure.Mod 5 | 6 | clean: 7 | rm *.c 8 | rm *.h 9 | rm *.o 10 | rm *.sym 11 | -------------------------------------------------------------------------------- /examples/procedures/procedure/Procedure.Mod: -------------------------------------------------------------------------------- 1 | MODULE proc; 2 | 3 | 4 | IMPORT Out; 5 | 6 | 7 | PROCEDURE printSum(a, b : INTEGER); 8 | BEGIN 9 | Out.Int(a + b, 0); Out.Ln 10 | END printSum; 11 | 12 | 13 | BEGIN 14 | printSum(6, 9) 15 | END proc. 16 | -------------------------------------------------------------------------------- /examples/procedures/var-parameter/Makefile: -------------------------------------------------------------------------------- 1 | VOC = /opt/voc/bin/voc 2 | 3 | all: 4 | $(VOC) -m VarParam.Mod 5 | 6 | clean: 7 | rm *.c 8 | rm *.h 9 | rm *.o 10 | rm *.sym 11 | -------------------------------------------------------------------------------- /examples/procedures/var-parameter/VarParam.Mod: -------------------------------------------------------------------------------- 1 | MODULE varparam; 2 | 3 | 4 | IMPORT Out; 5 | 6 | 7 | VAR a, b : INTEGER; 8 | 9 | 10 | PROCEDURE swapVals(VAR x, y : INTEGER); 11 | VAR tmp : INTEGER; 12 | BEGIN 13 | tmp := x; x := y; y := tmp; 14 | END swapVals; 15 | 16 | 17 | BEGIN 18 | a := 6; b := 9; 19 | Out.String("initial "); Out.Ln; 20 | Out.String("a : "); Out.Int(a, 0); Out.String("; b : "); Out.Int(b, 0); Out.Ln; 21 | swapVals(a, b); 22 | Out.String("after swap"); Out.Ln; 23 | Out.String("a : "); Out.Int(a, 0); Out.String("; b : "); Out.Int(b, 0); Out.Ln; 24 | END varparam. 25 | -------------------------------------------------------------------------------- /examples/records/Records.Mod: -------------------------------------------------------------------------------- 1 | MODULE record; 2 | 3 | 4 | IMPORT Out; 5 | 6 | 7 | CONST 8 | Male = 1; 9 | Female = 2; 10 | 11 | 12 | TYPE 13 | SexDesc = INTEGER; 14 | Person = RECORD 15 | Name : ARRAY 32 OF CHAR; 16 | Age : INTEGER; 17 | Title : ARRAY 64 OF CHAR; 18 | Sex : SexDesc; 19 | END; 20 | 21 | 22 | VAR 23 | i : INTEGER; 24 | employer : Person; 25 | employee : ARRAY 2 OF Person; 26 | 27 | 28 | PROCEDURE dumpPerson ( p : Person ); 29 | BEGIN 30 | Out.String("Meet "); Out.String(p.Name); 31 | IF p.Sex = Male THEN Out.String(". He is ") END; 32 | IF p.Sex = Female THEN Out.String(". She is ") END; 33 | Out.Int(p.Age, 0); Out.String(" years old and a "); Out.String(p.Title); Out.Ln; 34 | END dumpPerson; 35 | 36 | 37 | 38 | BEGIN 39 | (* define people *) 40 | employer.Name := "Bing"; employer.Age := 42; employer.Title := "CEO"; employer.Sex := Male; 41 | 42 | employee[0].Name := "Bob"; employee[0].Age := 26; 43 | employee[0].Title := "SysAdmin"; employee[0].Sex := Male; 44 | 45 | employee[1].Name := "Alice" ; employee[1].Age := 22; 46 | employee[1].Title := "Programmer"; employee[1].Sex := Female; 47 | 48 | (* print people *) 49 | dumpPerson(employer); 50 | FOR i := 0 TO LEN(employee) - 1 DO 51 | dumpPerson(employee[i]); 52 | END; 53 | END record. 54 | -------------------------------------------------------------------------------- /examples/recursion/Fib.Mod: -------------------------------------------------------------------------------- 1 | MODULE fibonacci; 2 | 3 | 4 | IMPORT Out, Modules; 5 | 6 | 7 | VAR 8 | n : LONGINT; 9 | Arg0 : LONGINT; 10 | 11 | 12 | PROCEDURE getFib (n : LONGINT) : LONGINT; 13 | VAR result : LONGINT; 14 | BEGIN 15 | IF n = 0 THEN 16 | result := 0 17 | ELSIF n = 1 THEN 18 | result:= 1 19 | ELSE 20 | result := getFib(n-1) + getFib(n-2) 21 | END; 22 | RETURN result 23 | END getFib; 24 | 25 | 26 | BEGIN 27 | IF Modules.ArgCount # 2 THEN 28 | Out.String("one argument needed"); Out.Ln; 29 | HALT(1); 30 | END; 31 | Modules.GetIntArg(1, Arg0); 32 | Out.Int(getFib(Arg0), 0); Out.Ln; 33 | END fibonacci. 34 | -------------------------------------------------------------------------------- /examples/recursion/Gcd.Mod: -------------------------------------------------------------------------------- 1 | MODULE gcd; 2 | 3 | 4 | IMPORT Out, Modules; 5 | 6 | 7 | VAR 8 | gcd : INTEGER; 9 | arg0, arg1 : LONGINT; 10 | 11 | 12 | PROCEDURE getGCD(a, b : INTEGER): INTEGER; 13 | VAR ret : INTEGER; 14 | BEGIN 15 | IF a = 0 THEN ret := b; 16 | ELSIF b = 0 THEN ret := a; 17 | ELSIF b > a THEN ret := getGCD(b, a); 18 | ELSE ret := getGCD(b, a MOD b) END; 19 | RETURN ret; 20 | END getGCD; 21 | 22 | 23 | BEGIN 24 | IF Modules.ArgCount # 3 THEN 25 | Out.String("enter two integers to get GCD"); Out.Ln; 26 | HALT(1) 27 | END; 28 | Modules.GetIntArg(1, arg0); Modules.GetIntArg(2, arg1); 29 | gcd := getGCD(SHORT(arg0), SHORT(arg1)); 30 | Out.Int(gcd, 0); Out.Ln; 31 | END gcd. 32 | -------------------------------------------------------------------------------- /examples/value-types/Makefile: -------------------------------------------------------------------------------- 1 | VOC = /opt/voc/bin/voc 2 | 3 | all: 4 | $(VOC) -m Values.Mod 5 | 6 | clean: 7 | rm *.c 8 | rm *.h 9 | rm *.o 10 | rm *.sym 11 | -------------------------------------------------------------------------------- /examples/value-types/Values.Mod: -------------------------------------------------------------------------------- 1 | MODULE values; 2 | 3 | 4 | IMPORT Out; 5 | 6 | 7 | BEGIN 8 | Out.String("Oberon has types, for example, I am a string type (ARRAY OF CHAR);"); Out.Ln; 9 | Out.String("There are also other types, e.g. INTEGERs and BOOLEANs"); Out.Ln; 10 | Out.Int(42, 0); 11 | Out.Ln 12 | END values. 13 | -------------------------------------------------------------------------------- /examples/variables/Makefile: -------------------------------------------------------------------------------- 1 | VOC = /opt/voc/bin/voc 2 | 3 | all: 4 | $(VOC) -m Variables.Mod 5 | 6 | clean: 7 | rm *.c 8 | rm *.h 9 | rm *.o 10 | rm *.sym 11 | -------------------------------------------------------------------------------- /examples/variables/Variables.Mod: -------------------------------------------------------------------------------- 1 | MODULE variables; 2 | 3 | IMPORT Out; 4 | 5 | 6 | VAR 7 | s : ARRAY 32 OF CHAR; 8 | i : REAL; 9 | n, m : INTEGER; 10 | 11 | 12 | BEGIN 13 | s := "Initial"; 14 | Out.String(s); Out.Ln; 15 | i := 3.14; 16 | n := 64; 17 | m := 42; 18 | Out.Int(m, 0); Out.Ln; 19 | Out.Int(n, 0); Out.Ln; 20 | Out.Real(i, 0); Out.Ln; 21 | 22 | s := "assigning new values"; 23 | Out.String(s); Out.Ln; 24 | i := 2.71; 25 | n := 128; 26 | m := 84; 27 | Out.Int(m, 0); Out.Ln; 28 | Out.Int(n, 0); Out.Ln; 29 | Out.Real(i, 0); 30 | Out.Ln 31 | END variables. 32 | -------------------------------------------------------------------------------- /examples/while/Makefile: -------------------------------------------------------------------------------- 1 | VOC = /opt/voc/bin/voc 2 | 3 | all: 4 | $(VOC) -m While.Mod 5 | 6 | clean: 7 | rm *.c 8 | rm *.h 9 | rm *.o 10 | rm *.sym 11 | -------------------------------------------------------------------------------- /examples/while/While.Mod: -------------------------------------------------------------------------------- 1 | MODULE while; 2 | 3 | IMPORT Out; 4 | 5 | 6 | VAR 7 | i : INTEGER; 8 | 9 | 10 | BEGIN 11 | i := 0; 12 | Out.String("WHILE loop started"); Out.Ln; 13 | WHILE i < 10 DO 14 | i := i + 1; 15 | Out.Int(i, 0); Out.Ln; 16 | END; 17 | END while. 18 | -------------------------------------------------------------------------------- /src/obe.Mod: -------------------------------------------------------------------------------- 1 | MODULE obe; 2 | 3 | IMPORT 4 | Files, 5 | Platform, 6 | Out; 7 | 8 | PROCEDURE CheckDirectories; 9 | BEGIN 10 | END CheckDirectories; 11 | 12 | PROCEDURE GenIndex; 13 | CONST 14 | templpath = "../templates/index.html"; 15 | outputpath = "../public/index.html"; 16 | examplespath = "../examples.txt"; 17 | VAR 18 | outputfd, templfd, examplesfd: Files.File; 19 | outputrd, templrd, examplesrd: Files.Rider; 20 | BEGIN 21 | END GenIndex; 22 | 23 | BEGIN 24 | CheckDirectories; 25 | GenIndex; 26 | END obe. 27 | --------------------------------------------------------------------------------