mirror of
https://github.com/vishapoberon/oberonbyexample.git
synced 2026-04-05 21:02:25 +00:00
intro to PROCEDUREs, functions and var-parameters
This commit is contained in:
parent
290ea11c03
commit
f483b3630f
6 changed files with 83 additions and 0 deletions
10
procedures/function-procedure/Makefile
Normal file
10
procedures/function-procedure/Makefile
Normal file
|
|
@ -0,0 +1,10 @@
|
||||||
|
VOC = /opt/voc/bin/voc
|
||||||
|
|
||||||
|
all:
|
||||||
|
$(VOC) -m Square.Mod
|
||||||
|
|
||||||
|
clean:
|
||||||
|
rm *.c
|
||||||
|
rm *.h
|
||||||
|
rm *.o
|
||||||
|
rm *.sym
|
||||||
17
procedures/function-procedure/Square.Mod
Normal file
17
procedures/function-procedure/Square.Mod
Normal file
|
|
@ -0,0 +1,17 @@
|
||||||
|
MODULE square;
|
||||||
|
|
||||||
|
|
||||||
|
IMPORT Out;
|
||||||
|
|
||||||
|
VAR s : INTEGER;
|
||||||
|
|
||||||
|
PROCEDURE squared(x : INTEGER): INTEGER;
|
||||||
|
BEGIN
|
||||||
|
RETURN x * x
|
||||||
|
END squared;
|
||||||
|
|
||||||
|
BEGIN
|
||||||
|
s := squared(7);
|
||||||
|
Out.Int(s, 0); Out.Ln;
|
||||||
|
Out.Int(squared(8), 0); Out.Ln;
|
||||||
|
END square.
|
||||||
10
procedures/procedure/Makefile
Normal file
10
procedures/procedure/Makefile
Normal file
|
|
@ -0,0 +1,10 @@
|
||||||
|
VOC = /opt/voc/bin/voc
|
||||||
|
|
||||||
|
all:
|
||||||
|
$(VOC) -m Procedure.Mod
|
||||||
|
|
||||||
|
clean:
|
||||||
|
rm *.c
|
||||||
|
rm *.h
|
||||||
|
rm *.o
|
||||||
|
rm *.sym
|
||||||
14
procedures/procedure/Procedure.Mod
Normal file
14
procedures/procedure/Procedure.Mod
Normal file
|
|
@ -0,0 +1,14 @@
|
||||||
|
MODULE proc;
|
||||||
|
|
||||||
|
|
||||||
|
IMPORT Out;
|
||||||
|
|
||||||
|
PROCEDURE printSum(a, b : INTEGER);
|
||||||
|
BEGIN
|
||||||
|
Out.Int(a + b, 0); Out.Ln
|
||||||
|
END printSum;
|
||||||
|
|
||||||
|
|
||||||
|
BEGIN
|
||||||
|
printSum(6, 9)
|
||||||
|
END proc.
|
||||||
10
procedures/var-parameter/Makefile
Normal file
10
procedures/var-parameter/Makefile
Normal file
|
|
@ -0,0 +1,10 @@
|
||||||
|
VOC = /opt/voc/bin/voc
|
||||||
|
|
||||||
|
all:
|
||||||
|
$(VOC) -m VarParam.Mod
|
||||||
|
|
||||||
|
clean:
|
||||||
|
rm *.c
|
||||||
|
rm *.h
|
||||||
|
rm *.o
|
||||||
|
rm *.sym
|
||||||
22
procedures/var-parameter/VarParam.Mod
Normal file
22
procedures/var-parameter/VarParam.Mod
Normal file
|
|
@ -0,0 +1,22 @@
|
||||||
|
MODULE varparam;
|
||||||
|
|
||||||
|
IMPORT Out;
|
||||||
|
|
||||||
|
VAR
|
||||||
|
a, b : INTEGER;
|
||||||
|
|
||||||
|
PROCEDURE swapVals(VAR x, y : INTEGER);
|
||||||
|
VAR tmp : INTEGER;
|
||||||
|
BEGIN
|
||||||
|
tmp := x; x := y; y := tmp;
|
||||||
|
END swapVals;
|
||||||
|
|
||||||
|
|
||||||
|
BEGIN
|
||||||
|
a := 6; b := 9;
|
||||||
|
Out.String("initial "); Out.Ln;
|
||||||
|
Out.String("a : "); Out.Int(a, 0); Out.String("; b : "); Out.Int(b, 0); Out.Ln;
|
||||||
|
swapVals(a, b);
|
||||||
|
Out.String("after swap"); Out.Ln;
|
||||||
|
Out.String("a : "); Out.Int(a, 0); Out.String("; b : "); Out.Int(b, 0); Out.Ln;
|
||||||
|
END varparam.
|
||||||
Loading…
Add table
Add a link
Reference in a new issue