Επόμενο Προηγούμενο Περιεχόμενα
Θα κατασκευάσουμε ένα απλό πρόγραμμα για να δούμε την
δομή του αναλυτικά. Ο κώδικας που θα δούμε περιέχει
αριθμούς γραμμής που στην πραγματικότητα δεν
χρειαζόμαστε. Μπήκαν απλά για να μπορεί να γίνει
κατανοητή η εξήγηση των ενοτήτων.
1. '
2. ' ####################
3. ' ##### PROLOG #####
4. ' ####################
5. '
6. PROGRAM "multiply" ' 1-8 char program/file name without .x or any .extent
7. VERSION "1.0000" ' version number - increment before saving altered program
8. '
9. ' You can stop the PDE from inserting the following PROLOG comment lines
10.' by removing them from the prolog.xxx file in your \xb\xxx directory.
11.'
12.' Programs contain: 1: PROLOG - no executable code - see below
13.' 2: Entry function - start execution at 1st declared func
14.' * = optional 3: Other functions - everything else - all other functions
15.'
16.' The PROLOG contains (in this order):
17.' * 1. Program name statement PROGRAM "progname"
18.' * 2. Version number statement VERSION "0.0000"
19.' * 3. Import library statements IMPORT "libName"
20.' * 4. Composite type definitions TYPE <typename> ... END TYPE
21.' 5. Internal function declarations DECLARE/INTERNAL FUNCTION Func (args)
22.' * 6. External function declarations EXTERNAL FUNCTION FuncName (args)
23.' * 7. Shared constant definitions $$ConstantName = literal or constant
24.' * 8. Shared variable declarations SHARED variable
25.'
26.' ****** Comment libraries in/out as needed *****
27.'
28.' IMPORT "xma" ' Math library : SIN/ASIN/SINH/ASINH/LOG/EXP/SQRT...
29.' IMPORT "xcm" ' Complex library : complex number library (trig, etc)
30. IMPORT "xst" ' Standard library : required by most programs
31.' IMPORT "xgr" ' GraphicsDesigner : required by GuiDesigner programs
32.' IMPORT "xui" ' GuiDesigner : required by GuiDesigner programs
33.'
34.
35.DECLARE FUNCTION Entry ()
36.DECLARE FUNCTION multiply (numa%,numb%)
37.'
38.'
39.' ######################
40.' ##### Entry () #####
41.' ######################
42.'
43.' Programs contain:
44.' 1. A PROLOG with type/function/constant declarations.
45.' 2. This Entry() function where execution begins.
46.' 3. Zero or more additional functions.
47.'
48.FUNCTION Entry ()
49. STATIC prompt$,inpu$
50. STATIC numa%, numb%,numc%
51. inpu$=INLINE$("Enter a number 1..100 ")
52. numa%=SSHORT(inpu$)
53. inpu$=INLINE$("Enter a number 1..100 ")
54. numb%=SSHORT(inpu$)
55. numc%=multiply(numa%,numb%)
56. PRINT numc%
57.
58.END FUNCTION
59.'
60.'
61.' #########################
62.' ##### multiply () #####
63.' #########################
64.'
65.FUNCTION multiply (numa%,numb%)
66.STATIC p1%
67.
68.p1%=numa%*numb%
69.
70.END FUNCTION p1%
71.END PROGRAM
Επόμενο Προηγούμενο Περιεχόμενα