myfunction.pr 7.04 KB
Newer Older
1
/* CIF PROCESS (197, 146), (150, 75) */
2
PROCESS myfunction;
Maxime Perrotin's avatar
Maxime Perrotin committed
3
    /* CIF TEXT (0, 133), (282, 216) */
4
5
6
7
8
9
    dcl str MyOctStr := 'abc';
dcl variable_str String := 'Hello!';

dcl seqof  MySeqOf := {hello, world};

dcl seqint seqInt := {1};
Maxime Perrotin's avatar
Maxime Perrotin committed
10
11
dcl seqbool seqBool := { true, false};
dcl seqbool2 seqBool2 := { true, false};
Maxime Perrotin's avatar
Maxime Perrotin committed
12
13
14
15

dcl iseq IntSeq := {0,1,2,3};
dcl fixedseq FixedIntSeq := {0,1,2,3,4};
dcl n t_UInt8;
16
17
18
    /* CIF ENDTEXT */
    /* CIF TEXT (7, 43), (334, 41) */
    -- Test substrings in various contexts and operators
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
    /* CIF ENDTEXT */
    /* CIF PROCEDURE (1416, 490), (91, 35) */
    PROCEDURE factorial;
        /* CIF TEXT (29, 42), (215, 53) */
        fpar in N MyInteger, 
          in/out result MyInteger;
        /* CIF ENDTEXT */
        /* CIF START (298, 33), (70, 35) */
        START;
            /* CIF TASK (284, 83), (97, 35) */
            TASK result := 1;
            /* CIF TASK (223, 133), (220, 53) */
            TASK for x in range(1, n+1):
    result := (result * x) mod 255
endfor;
            /* CIF RETURN (315, 201), (35, 35) */
            RETURN ;
    ENDPROCEDURE;
Maxime Perrotin's avatar
Maxime Perrotin committed
37
    /* CIF START (353, 217), (65, 37) */
38
    START;
39
        /* CIF TASK (320, 269), (131, 35) */
Maxime Perrotin's avatar
Maxime Perrotin committed
40
41
42
43
44
45
46
47
48
49
50
        TASK n := iseq(0,2)(0);
        /* CIF PROCEDURECALL (335, 319), (100, 35) */
        CALL writeln(n)
        /* CIF COMMENT (455, 319), (77, 35) */
        COMMENT 'print 0';
        /* CIF TASK (306, 369), (158, 40) */
        TASK iseq := iseq(0,3)(0,2);
        /* CIF TASK (316, 424), (138, 56) */
        TASK for x in iseq:
   call writeln(x);
endfor
51
        /* CIF COMMENT (489, 416), (81, 72) */
Maxime Perrotin's avatar
Maxime Perrotin committed
52
53
54
55
56
57
58
59
60
61
        COMMENT 'print
0
1
2';
        /* CIF TASK (289, 495), (192, 35) */
        TASK n := length(fixedseq(0,1));
        /* CIF PROCEDURECALL (335, 545), (100, 35) */
        CALL writeln(n)
        /* CIF COMMENT (455, 545), (83, 35) */
        COMMENT 'print 2';
62
        /* CIF TASK (310, 595), (151, 35) */
63
        TASK seqof := seqof(0,1)
64
        /* CIF COMMENT (482, 595), (209, 35) */
65
        COMMENT 'equivalent to seqof := seqof';
66
67
        /* CIF TASK (303, 645), (165, 35) */
        TASK n := iseq(0,2)(0,1)(0);
68
        /* CIF TASK (315, 695), (141, 35) */
69
70
        TASK n := iseq(100- 1);
        /* CIF DECISION (324, 745), (123, 50) */
71
        DECISION hello in seqof
72
        /* CIF COMMENT (468, 744), (179, 53) */
73
74
        COMMENT 'Check IN operator with
enumerated type';
75
                /* CIF ANSWER (242, 815), (70, 33) */
76
                (true):
77
                    /* CIF PROCEDURECALL (188, 863), (177, 35) */
78
                    CALL writeln(hello in seqof)
79
                    /* CIF COMMENT (386, 863), (114, 35) */
80
                    COMMENT 'print "TRUE"';
81
                /* CIF ANSWER (505, 815), (70, 33) */
82
83
                (false):
        ENDDECISION;
84
        /* CIF DECISION (308, 913), (155, 50) */
85
        DECISION hello in seqof(0,0)
86
        /* CIF COMMENT (475, 910), (236, 56) */
87
88
89
        COMMENT 'Check IN operator with
list substring - first element only
should go to branch TRUE';
90
                /* CIF ANSWER (228, 983), (66, 33) */
91
                (true):
92
                    /* CIF PROCEDURECALL (160, 1031), (201, 35) */
93
                    CALL writeln(hello in seqof(0,1))
94
                    /* CIF COMMENT (396, 1031), (114, 35) */
95
                    COMMENT 'print "TRUE"';
96
                /* CIF ANSWER (518, 983), (70, 33) */
97
98
                (false):
        ENDDECISION;
99
        /* CIF PROCEDURECALL (290, 1081), (191, 35) */
100
        CALL writeln(variable_str(0,4))
101
        /* CIF COMMENT (496, 1081), (113, 35) */
102
        COMMENT 'print "Hello"';
103
        /* CIF TASK (297, 1131), (176, 56) */
104
105
106
        TASK for x in seqof:
    call writeln(num(x));
endfor
107
        /* CIF COMMENT (498, 1131), (96, 56) */
108
109
110
        COMMENT 'print:
12
13';
111
        /* CIF TASK (295, 1202), (180, 56) */
112
113
114
        TASK for x in seqof(0,1):
    call writeln(-num(x));
endfor
115
        /* CIF COMMENT (503, 1202), (96, 56) */
116
117
118
        COMMENT 'print:
-12
-13';
119
        /* CIF PROCEDURECALL (295, 1273), (180, 35) */
120
        CALL writeln(length(seqof))
121
        /* CIF COMMENT (506, 1273), (77, 35) */
122
        COMMENT 'print 2';
123
        /* CIF PROCEDURECALL (281, 1323), (209, 35) */
124
        CALL writeln(length(seqof(0,1)))
125
        /* CIF COMMENT (515, 1323), (77, 35) */
126
        COMMENT 'print 2';
127
        /* CIF LABEL (304, 1373), (162, 35) */
128
        variable_length_seq:
129
        /* CIF TASK (314, 1423), (142, 56) */
130
131
132
        TASK for x in seqint:
    call writeln(x);
endfor
133
        /* CIF COMMENT (488, 1425), (96, 53) */
134
135
        COMMENT 'print:
1';
136
        /* CIF TASK (309, 1494), (152, 56) */
137
138
139
        TASK for x in seqint(0,0):
    call writeln(x);
endfor
140
        /* CIF COMMENT (478, 1496), (96, 53) */
141
142
        COMMENT 'print:
1';
143
        /* CIF DECISION (324, 1565), (123, 50) */
144
        DECISION 1 in seqint
145
        /* CIF COMMENT (455, 1564), (179, 53) */
146
147
        COMMENT 'Check IN operator with
variable-length seqOf';
148
                /* CIF ANSWER (215, 1635), (66, 33) */
149
                (true):
150
                    /* CIF PROCEDURECALL (159, 1683), (177, 35) */
151
                    CALL writeln(1 in seqint)
152
                    /* CIF COMMENT (369, 1683), (114, 35) */
153
                    COMMENT 'print "TRUE"';
154
                /* CIF ANSWER (492, 1635), (70, 24) */
155
156
                (false):
        ENDDECISION;
157
        /* CIF DECISION (321, 1733), (128, 50) */
158
        DECISION 1 in seqint(0,0)
159
        /* CIF COMMENT (460, 1732), (179, 53) */
160
161
        COMMENT 'Check IN operator with
variable-length seqOf';
162
                /* CIF ANSWER (236, 1803), (70, 24) */
163
                (true):
164
                    /* CIF PROCEDURECALL (180, 1842), (182, 35) */
165
                    CALL writeln(1 in seqint(0,0))
166
                    /* CIF COMMENT (384, 1842), (114, 35) */
167
                    COMMENT 'print "TRUE"';
168
                /* CIF ANSWER (508, 1803), (70, 24) */
169
170
                (false):
        ENDDECISION;
171
        /* CIF PROCEDURECALL (295, 1892), (180, 35) */
172
        CALL writeln(length(seqint))
173
        /* CIF COMMENT (499, 1892), (77, 35) */
174
        COMMENT 'print 1';
175
        /* CIF PROCEDURECALL (279, 1942), (212, 35) */
176
        CALL writeln(length(seqint(0,0)))
177
        /* CIF COMMENT (514, 1942), (77, 35) */
178
        COMMENT 'print 1';
179
        /* CIF TASK (304, 1992), (163, 35) */
180
        TASK seqint := seqint // {2};
181
        /* CIF TASK (290, 2042), (190, 35) */
182
        TASK seqint := seqint(0,0) // {5};
183
        /* CIF TASK (314, 2092), (142, 56) */
184
185
186
        TASK for x in seqint:
    call writeln(x);
endfor
187
        /* CIF COMMENT (499, 2092), (96, 56) */
188
189
190
        COMMENT 'print:
1
5';
191
        /* CIF TASK (269, 2163), (233, 35) */
Maxime Perrotin's avatar
Maxime Perrotin committed
192
        TASK seqbool := seqbool and seqbool
193
        /* CIF COMMENT (525, 2163), (194, 35) */
Maxime Perrotin's avatar
Maxime Perrotin committed
194
        COMMENT 'should not raise any error';
195
        /* CIF TASK (256, 2213), (259, 38) */
Maxime Perrotin's avatar
Maxime Perrotin committed
196
        TASK 'seqbool2 := seqbool2 and seqbool2'
197
        /* CIF COMMENT (530, 2215), (216, 35) */
Maxime Perrotin's avatar
Maxime Perrotin committed
198
        COMMENT 'Variable-length -> raise error';
199
        /* CIF NEXTSTATE (339, 2266), (68, 33) */
200
        NEXTSTATE Wait;
Maxime Perrotin's avatar
Maxime Perrotin committed
201
    /* CIF STATE (839, 313), (70, 35) */
202
203
204
    STATE wait;
    ENDSTATE;
ENDPROCESS myfunction;