/
demo.FPL
392 lines (318 loc) · 9.66 KB
/
demo.FPL
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
/***************************************************************************
** $Filename: demo.FPL $
** $Release: 13.2 $
** $Date: 95/07/23 $
**
** (C) Copyright 1992 - 1995 by FrexxWare
** All Rights Reserved
****************************************************************************
>>>>>> Frexx Programming Language (FPL) demonstration program <<<<<<
Author: Daniel Stenberg.
****************************************************************************
FPL is an interpreting, library based programming language designed to be
flexible and easy to insert in any software that needs some kind of
batch/macro control.
FPL is a complete programming language very similar to C. (Just look at
this program example!)
FPL.library lets the software programmer define functions that FPL should
accept. The library will call a function in the software whenever any of
these functions are discovered.
In this example, the printf() function is a such function. To be able to
run this example you must use the "src/SFPL" program. (Look at the code in
caller.c and see how simple it is to implement.) This example is working with
FPL version 9+.
FPL is freely distributable for non-commercial purposes only, including
extensive documentation and source code.
***************************************************************************
*
* Prototype all function we'll use:
*/
#pragma cache /* pragma using little example! */
void strings();
void integers();
void mix_them();
void arrays();
int expressions();
void conditions();
void loops();
void constants();
void locals();
void recursive();
void functions();
export void arg_functions(); /* make this global system-wide */
typedef long LONG; /* good old Commodore habit! */
LONG label(int);
LONG test(int);
LONG setvar(int *);
LONG printint(int);
LONG double2(int a) /* declare before use instead of prototype! */
{
return a*2; // with or without parentheses!
}
int ninja=1;
export int ninjax=0;
auto loop;
/***************************************************************************
*
* Main program part coming up:
*/
do {
strings(); // How to use strings.
integers(); // How to use integers.
mix_them(); // How to mix strings and integers.
arrays(); // How to use arrays.
//expressions();// How to write expressions.
conditions(); // How to check conditions.
loops(); // How to loop.
constants(); // How to write constants.
locals(); // How to use local variables.
recursive(); // How to recurse.
functions(); // How to use the functions.
arg_functions(); // How to send parameters to your own functions.
} while(loop++<10);
exit;
/***************************************************************************
*
* Here follows a subroutine featuring some of the string expression
* facilities that FPL includes:
*/
void strings()
{
string a; /* declaration of a string */
string b="Written "; /* declaration and assign */
string c[2]; /* string array declaration */
string d="\x65\157"; /* hexadecimal + octal ASCII */
a="bb"; /* string variable assign */
a[1]='y'; /* single character access! */
b+=a; /* string appending */
c[0]={"Daniel",
"Stenberg"}; /* array assigning */
printf("%s %s %s ", b, c[0], c[1]); /* display result */
}
/***************************************************************************
*
* Here follows a subroutine featuring some of the integer handlings that
* can be done:
*/
void integers()
{
int a; /* integer declaration */
int b=200; /* declaration assign */
int c[2]={-25, 1234}; /* array declaration and assign */
a=10; /* integer variable assign */
c[0]+={2019, 758}; /* compound array assign */
printf("%d - %d!\n", c[1], c[0]); /* display the contents of c[0-1] */
}
/***************************************************************************
*
* Numerical expressions can be converted to strings by using ltostr() or
* itoa().
*/
void mix_them()
{
string a="Copyright ", c; /* two string variables */
int b; /* one integer variable */
b=a[0]; /* get ASCII code of column 2 */
printf("%s%s by ", a, ltostr(b*97+30+022, 16)); /* display result */
}
/***************************************************************************
*
* FPL supports multi dimensional arrays (max 40 dimensions though):
*/
void arrays()
{
int c[5][2]={
{2, 0},
{3, 1}
};
int a[25]={0, 1, 2, 3, 4, 5, 6}; /* declaration assign */
string b[4];
a[12]^={3, 2, 1, 0}; /* array compound assign */
resize a[10]; /* array resizing */
output(b[0]={"FPL", "is", "Copyright by", "FrexxWare!"});
output("\n");
}
/***************************************************************************
*
* Expressions are very extensible in FPL. It features all ANSI C operators
* and has 100% operator precedence compatibility:
*/
int expressions()
{
int a=128, b=3, c, d;
string out;
c=~(a>>b)+2*b-a++/50 & (d=a*2-1); /* complex formula */
c^= (2^3&3+a)%c; /* compound assign */
output(d = c---a-b*10); /* output integer! */
output("% "); /* output string! */
return d;
}
/***************************************************************************
*
* Conditions are used just as i C.
*/
void conditions()
{
int a=11;
switch( expressions() ) {
case 99:
output("Turbo pascal");
break;
case 100:
output("ANSI C");
default:
output(" operator ");
}
if(a==11)
output("compliance!\n");
else
output("failure!\n");
}
/***************************************************************************
*
* Loops are used just as in C. (While has been improved with else support
* and break with a level option!):
*/
void loops()
{
int a, b;
for(a=0; a<10; a++) {
int Bninja;
output("-");
b=a;
while(b<5)
b++;
else {
output("Very " /* Strings in */
"easy" /* several parts */
" implemented, "); /* just as in C! */
/* This upper thing is a 5.3+ feature! */
break; /* break out of loop! */
}
}
do {
if(++b<10)
continue;
break;
} while(a);
while(1)
while(1)
while(1)
while(1)
while(1) {
output("very similar to C.\n");
break 5;/* break out of multiple loops! */
}
}
/***************************************************************************
*
* Constants can be written in several different ways in FPL:
*/
void constants()
{
int a= 010 + /* octal number */
0b100 + /* binary number */
0xdead - /* hexadecimal number */
211 + /* common decimal number */
'A'+ /* ASCII code */
'\t'; /* ASCII code of control char */
}
/***************************************************************************
*
* Variables always exist in their declared level and in the following ones
* execpt when new variables are declared there with the same name:
*/
void locals()
{
int a=2, b=11; /* declare a and b here */
{
int a=3; /* declare a here */
{
int a=4; /* declare a here */
{
int a=5; /* declare a here */
test(b); /* jump to test and come back */
} /* this removes one a variable */
} /* this removes another a variable */
} /* this removes yet another a variable */
printf("%d kinds of comments, ", a); /* this is the original variable */
}
int test(int b)
{
printf("FPL features %d internal functions\n", b);
}
/***************************************************************************
*
* FPL is fully recursive:
*/
void recursive()/* This example shows the recursiveness by using a lot of */
/* unnecessary braces and from within the innermost brace */
/* level call itself. */
{
int b;
label(0);
}
int label(int b)
{
int a;
if(++b<5) {
while(1) {
{
{
{
{
{
label(b);
break;
}
}
}
}
}
}
} else
printf("Finally we reached this point when b equals %d.\n", 2<<b);
}
/***************************************************************************
*
* FPL supplies several internal functions:
*/
void functions()
{
int a, b=2, c;
string str1="hello", str2="world", str3="l", num="12";
a=strcmp(str1, str2); /* compare two strings */
a=strncmp(str1, str2, b); /* compare two strings a certain length */
a=strstr(str2, str3); /* search for substring within a big string */
str3=substr(str1, 0, 3); /* get substring */
a=atoi(num); /* decimal string to numerical */
a=strtol(num, 16); /* any-base string to numerical */
str3=ltostr(a, 14); /* integer to string, base 14 */
num+="-19"; /* append to string */
c=eval(num); /* calculate a string!!! */
a=strlen(str2); /* length of a string */
/* absolute value of integer: */
printf("abs(%s) equals %d.\n", num, abs(c));
}
void arg_functions()
{
long a; // supports `long', which is the same as `int'
for(a=0; a<5; a++)
printint(double2(a)); // `inside' functions used as any other function!
setvar(&a); // assign variable a!
printint(a); // to prove it really changed!
printint((++ninjax, ninja++)); /* Using comma separator in functions that
only wants one parameter! */
output("\n");
}
int setvar(int *variable) // integer variable as argument
{
*variable=100; // assigns the received variable!
}
int printint(int x) // integer as argument
{
printf("|%d|", x); // output the numer received!
}
/***************************************************************************
>Copyright (C) 1992 - 1994 by FrexxWare<
****************************************************************************/