File: comment.tst

package info (click to toggle)
scilab 5.2.2-9
  • links: PTS, VCS
  • area: main
  • in suites: squeeze
  • size: 334,832 kB
  • ctags: 52,586
  • sloc: xml: 526,945; ansic: 223,590; fortran: 163,080; java: 56,934; cpp: 33,840; tcl: 27,936; sh: 20,397; makefile: 9,908; ml: 9,451; perl: 1,323; cs: 614; lisp: 30
file content (409 lines) | stat: -rw-r--r-- 7,799 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
// =============================================================================
// Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
// Copyright (C) ????-2008 - INRIA
//
//  This file is distributed under the same license as the Scilab package.
// =============================================================================

//for version after 3.0 the comments are no more handled by a preprocessor, 
//but by the parser itself

a=1//test
if a<>1 then pause,end
a=2;//test
if a<>2 then pause,end
a=1..//test
2
if a<>12 then pause,end
a='1//test';
if a<>'1/'+'/test' then pause,end
a=33;//'sqdf'qsdf'
if a<>33 then pause,end

//in matrix concatenation

a=[//test
1 //test1
2 //test2
];//endtest
if or(a<>[1;2])  then pause,end
a=[//test
];
if a<>[]  then pause,end
a=[//test
//test1
//test2
];
if a<>[]  then pause,end

//in multi-line control instruction

if %t //test
  a=3; //test1
else //test2 end
  a=4//test3 end
end//endtest
if a<>3 then pause,end

if %f //test
 a=3; //test1
else //test2 end
 a=4//test3 end
end//endtest
if a<>4 then pause,end

a=0;
for k=1:10 //loop begin
  if a> 10 then //
    break // go out the loop
  else //111111
    a=a-1; //sdfdfd
  end //xxxxx
  a=a+k; //hhhhh
end //loop end
if a<>15 then pause,end

for i=1
  a=1;
end //


a=0;k=0
while %t //loop begin
  k=k+1; //ttttt
  if a> 10 then //
    break // go out the loop
  else //111111
    a=a-1; //sdfdfd
  end //xxxxx
  a=a+k; //hhhhh
end //loop end
if a<>15 then pause,end

c=1;
select c //test
case 1 then//test then
  a=8; //test8
case 2 then //test end
  a=-1 //test minus 1
else //else
  a=0  //test zeor
end //end
if a<>8 then pause,end

c=2;
select c //test
case 1 then//test then
  a=8; //test8
case 2 then //test end
  a=-1 //test minus 1
else //else
  a=0  //test zeor
end //end
if a<>-1 then pause,end

// In execstr
execstr('a=1//test')
if a<>1 then pause,end
execstr('a=2;//test')
if a<>2 then pause,end
execstr('a=''1//test'';')
if a<>'1/'+'/test' then pause,end
execstr('a=33;//''sqdf''qsdf''')
if a<>33 then pause,end

// In execstr with matrix concatenation

t=['a=[//test'
   '1 //test1'
   '2 //test2'
   '];//endtest'];
execstr(t)
if or(a<>[1;2])  then pause,end
t=['a=[//test'
   '];'];
execstr(t)

if a<>[]  then pause,end
t=['a=[//test'
   '//test1'
   '//test2'
   '];'];
execstr(t)

if a<>[]  then pause,end

// In execstr with control instructions

t=['if %t //test'
   '  a=3; //test1'
   'else //test2 end'
   '  a=4//test3 end'
   'end//endtest'];execstr(t)
if a<>3 then pause,end

t=['if %f //test'
' a=3; //test1'
'else //test2 end'
' a=4//test3 end'
'end//endtest'];execstr(t)
if a<>4 then pause,end

// in deff (without compilation)
funcprot(0)
deff('a=foo','a=1//test','n');a=foo();
if a<>1 then pause,end
deff('a=foo','a=''1//test'';','n');a=foo();
if a<>'1/'+'/test' then pause,end
deff('a=foo','a=33;//''sqdf''qsdf''','n');a=foo();
if a<>33 then pause,end

t=['if %t //test'
   '  a=3; //test1'
   'else //test2 end'
   '  a=4//test3 end'
   'end//endtest'];deff('a=foo',t,'n');a=foo();
if a<>3 then pause,end

// in deff (with compilation)
deff('a=foo','a=1//test');a=foo();
if a<>1 then pause,end
deff('a=foo','a=''1//test'';');a=foo();
if a<>'1/'+'/test' then pause,end
deff('a=foo','a=33;//''sqdf''qsdf''');a=foo();
if a<>33 then pause,end

t=['if %t //test'
   '  a=3; //test1'
   'else //test2 end'
   '  a=4//test3 end'
   'end//endtest'];deff('a=foo',t);a=foo();
if a<>3 then pause,end

// in function
function a=foo
  a=1//test
endfunction
a=foo();
if a<>1 then pause,end

function a=foo(..
	       )
  a=1//test
endfunction
a=foo();
if a<>1 then pause,end

function a=foo// CALLING SYNTAX
  a=1//test
endfunction
a=foo();
if a<>1 then pause,end

function a=foo// CALLING SYNTAX
  a=0;k=0
  while %t //loop begin
    k=k+1; //ttttt
    if a> 10 then //
      break // go out the loop
    else //111111
      a=a-1; //sdfdfd
    end //xxxxx
    a=a+k; //hhhhh
  end //loop end
endfunction
a=foo();
if a<>15 then pause,end


function a=foo
  a=0;k=0;//initialization
  function a=fii  //internal function
    while %t //loop begin
      k=k+1; //ttttt
      if a> 10 then //
	break // go out the loop
      else //111111
	a=a-1; //sdfdfd
      end //xxxxx
      a=a+k; //hhhhh
    end //loop end
  endfunction
  a=fii()
  //SDSDFD
endfunction
a=foo();
if a<>15 then pause,end

warning('off');
//with  getf
t=['function a=foo'
  'a=0;k=0;//initialization'
  '  while %t //loop begin'
  '    k=k+1; //ttttt'
  '    if a> 10 then //'
  '	break // go out the loop'
  '    else //111111'
  '	a=a-1; //sdfdfd'
  '    end //xxxxx'
  '    a=a+k; //hhhhh'
  '  end //loop end'
  'endfunction'];

mputl(t,TMPDIR+'/foo.sci');
getf(TMPDIR+'/foo.sci','n')
a=foo();
if a<>15 then pause,end
getf(TMPDIR+'/foo.sci')
a=foo();
if a<>15 then pause,end

t=['//sdffgfgfgggg'
   '//sdsdsddfgfgfghgfhjhui'
   'function a=foo//uuuuuuu'
   'a=0;k=0;//initialization'
   '  while %t //loop begin'
   '    k=k+1; //ttttt'
   '    if a> 10 then //'
   '	break // go out the loop'
   '    else //111111'
   '	a=a-1; //sdfdfd'
   '    end //xxxxx'
   '    a=a+k; //hhhhh'
   '  end //loop end'
   'endfunction'];

mputl(t,TMPDIR+'/foo.sci');
getf(TMPDIR+'/foo.sci','n')
a=foo();
if a<>15 then pause,end
getf(TMPDIR+'/foo.sci')
a=foo();
if a<>15 then pause,end
warning('on');

//with macr2lst

//first define an utilitary function
function [C,L,lc]=getcomments(lst,lc)
 C=[],L=[];
 if argn(2)<2 then lc=0,end
  for l=lst
    if type(l)==15 then
      [CC,LL,lc]=getcomments(l,lc)
      C=[C;CC]
      L=[L;LL]
    elseif l==[] then
    elseif l(1)=='31' then
      C=[C;l(2)]
      L=[L;lc]
    elseif l(1)=='15' then
      lc=lc+1
    end
  end
endfunction
function [C,L,lc]=getcommentsintree(T,lc)
 C=[],L=[];
 if argn(2)<2 then lc=0,end
  for k=1:size(T)
    l=T(k)
    if  l(1)(1)=='ifthenelse' then
      [CC,LL,lc]=getcommentsintree(l.then,lc)
      C=[C;CC]
      L=[L;LL]
      [CC,LL,lc]=getcommentsintree(l.elseifs,lc)
      C=[C;CC]
      L=[L;LL]
      [CC,LL,lc]=getcommentsintree(l.else,lc)
      C=[C;CC]
      L=[L;LL]
    elseif  l(1)(1)=='while' then
      [CC,LL,lc]=getcommentsintree(l.statements,lc)
      C=[C;CC]
      L=[L;LL]
    elseif l(1)(1)=='comment' then
      C=[C;l.text]
      L=[L;lc]
    elseif l(1)=='EOL' then
      lc=lc+1
    end
  end
endfunction
  
function a=foo
  a=0;k=0;//initialization
  while %t //loop begin
    k=k+1; //ttt tt
    if a> 10 then //
      break // go out the loop
    else //111 111
      a=a-1; //sdf dfd
    end //x xxxx
    a=a+k; //hhhh h
  end //loop end
endfunction

[C,L]=getcomments(macr2lst(foo));
Cref=["initialization";
"loop begin";
"ttt tt";
"";
" go out the loop";
"111 111";
"sdf dfd";
"x xxxx";
"hhhh h";
"loop end"];
if or(C<>Cref) then pause,end
if or(L<>(1:10)') then pause,end

//with macr2tree

function a=foo
  a=0;k=0;//initialization
  while %t
    k=k+1; //ttttt ttttt
    if a> 10 then //f f
      break // go out the loop
    else //111 111
      a=a-1; //sdf dfd
    end //xx xxx
    a=a+k; //hhh hh
  end //loop end
endfunction
T=macr2tree(foo);
[C,L]=getcommentsintree(T.statements)
Cref=["initialization";
      "ttttt ttttt";
      "f f";
      " go out the loop";
      "111 111";
      "sdf dfd";
      "xx xxx";
      "hhh hh";
      "loop end"];
Lref=[1 3:10]';
if or(C<>Cref) then pause,end
if or(L<>Lref) then pause,end


function a=foo
  a=0;k=0;//initialization
  while %t //loop begin
    k=k+1; //ttttt tttt 
    if a> 10 then //ff
      break // go out the loop
    else //111111
      a=a-1; //sdfdfd
    end //xxxxx
    a=a+k; //hhhhh
  end //loop end
endfunction

//T=macr2tree(foo);  bug a cause du commentaire //loop begin


deff('[y]=u(t)','if t==0 then y=0;else y=1,end') //step qsdqsqsd
function y=foo(a),y=a,endfunction//test qsdqsd
foo(2)  //zeros=0
foo("f//");