-
Notifications
You must be signed in to change notification settings - Fork 0
/
tinybasic.c
1125 lines (958 loc) · 22.1 KB
/
tinybasic.c
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
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/* A tiny BASIC interpreter */
#include <string.h>
#include <stdio.h>
#include <setjmp.h>
#include <math.h>
#include <ctype.h>
#include <stdlib.h>
#define NUM_LAB 100
#define LAB_LEN 10
#define LOOP_NEST 25
#define SUB_NEST 25
#define PROG_SIZE 1024*1024
#define DELIMITER 1
#define VARIABLE 2
#define NUMBER 3
#define COMMAND 4
#define STRING 5
#define QUOTE 6
#define NEXT 1
#define IF 2
#define ENDIF 3
#define FOR 4
#define TO 5
#define ELSE 6
#define WHILE 7
#define WEND 8
#define BREAK 9
#define CONTINUE 10
#define PRINT 11
#define GOTO 12
#define GOSUB 13
#define RETURN 14
#define INPUT 15
#define END 16
#define EOL 17
#define FINISHED 18
char *prog; /* holds expression to be analyzed */
jmp_buf e_buf; /* hold environment for longjmp() */
int variables[26]= { /* 26 user variables, A-Z */
0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0
};
struct commands { /* keyword lookup table */
char command[20];
char tok;
} table[] = { /* Commands must be entered lowercase */
"next", NEXT, /* in this table. */
"if", IF,
"endif", ENDIF,
"for", FOR,
"to", TO,
"else", ELSE,
"while", WHILE,
"wend", WEND,
"break", BREAK,
"continue", CONTINUE,
"print", PRINT,
"goto", GOTO,
"gosub", GOSUB,
"return", RETURN,
"input", INPUT,
"end", END,
"", END /* mark end of table */
};
char token[80];
char token_type, tok;
struct label {
char *p; /* points to place to go in source file*/
int name;
} label_table[NUM_LAB];
struct loop_stack {
int var; /* counter variable */
int target; /* target value */
char *beginLoc; /* top of loop */
char *endLoc;
char *breakLoc;
} lstack[LOOP_NEST]; /* stack for FOR/NEXT loop */
char *gstack[SUB_NEST]; /* stack for gosub */
int ltos; /* index to top of FOR stack */
int gtos; /* index to top of GOSUB stack */
/**************************************/
/************* utility ****************/
/**************************************/
/* Load a program. */
int load_program(char *p, char *fname)
{
FILE *fp;
int i=0;
int notInQuote = 1;
if(!(fp=fopen(fname, "rb"))) return 0;
i = 0;
do {
*p = getc(fp);
if (*p == '"')
notInQuote = 1 - notInQuote;
if (notInQuote)
*p = tolower(*p);
++p;
++i;
} while(!feof(fp) && i<PROG_SIZE);
*(p-2) = '\0'; /* null terminate the program */
fclose(fp);
return 1;
}
/* display an error message */
void serror(int error)
{
static char *e[]= {
"syntax error",
"unbalanced parentheses",
"no expression present",
"equals sign expected",
"not a variable",
"Label table full",
"duplicate label",
"undefined label",
"improper loop nest",
"TO expected",
"too many nested FOR loops",
"NEXT without FOR",
"too many nested GOSUBs",
"RETURN without GOSUB"
};
printf("%s\n", e[error]);
longjmp(e_buf, 1); /* return to save point */
}
/***********************************/
/************** lexer **************/
/***********************************/
static char *lastTokPos;
int iswhite(char c)
{
return ((c == ' ' || c == '\t') ? 1 : 0) ;
}
/* Return true if c is a delimiter. */
int isdelim(char c)
{
return ((strchr(" ;,+-<>/*%^=()", c) || c==9 || c=='\n' || c==0) ? 1 : 0) ;
}
/* Look up a a token's internal representation in the
token table.
*/
int look_up(char *s)
{
int i;
/* see if token is in table */
for(i=0; *table[i].command; ++i)
if(!strcmp(table[i].command, s))
return table[i].tok;
return 0; /* unknown command */
}
/* Get a token. */
int get_token()
{
char *temp;
token_type=0; tok=0;
temp=token;
lastTokPos = prog; /* to capture FINISHED token */
if(*prog == '\0') { /* end of file */
*token=0;
tok = FINISHED;
return(token_type=DELIMITER);
}
while(iswhite(*prog)) ++prog; /* skip over white space */
lastTokPos = prog ; /* more aggressive position */
if(*prog == '\n') { /* newline */
++prog;
tok = EOL; *token='\n';
token[1]=0;
return (token_type = DELIMITER);
}
if(strchr("+-*^/%=;(),><", *prog)){ /* delimiter */
*temp++ = *prog++;
*temp=0;
return (token_type=DELIMITER);
}
if(*prog == '"') { /* quoted string */
++prog;
while((*prog != '"') && (*prog != '\n'))
*temp++ = *prog++;
if(*prog=='\n')
serror(1);
++prog;
*temp=0;
return(token_type=QUOTE);
}
if(isdigit(*prog)) { /* number */
while(isdigit(*prog))
*temp++ = *prog++;
*temp = '\0';
return(token_type = NUMBER);
}
if(islower(*prog)) { /* var or command */
while(!isdelim(*prog))
*temp++ = *prog++;
token_type=STRING;
}
*temp = '\0';
/* see if a string is a command or a variable */
if(token_type==STRING) {
tok = look_up(token); /* convert to internal rep */
if(!tok)
token_type = VARIABLE;
else
token_type = COMMAND; /* is a command */
}
return token_type;
}
/* Return a token to input stream. */
void putback()
{
prog = lastTokPos;
}
/* Find the start of the next line. */
void find_eol()
{
while(*prog != '\n' && *prog!='\0')
++prog;
if(*prog)
++prog;
}
/*****************************************/
/************ label management ***********/
/*****************************************/
/* Initialize the array that holds the labels.
By convention, a null label name indicates that
array position is unused.
*/
void label_init()
{
int t;
for(t=0; t<NUM_LAB; ++t) label_table[t].name=0;
}
/* Return index of next free position in label array.
A -1 is returned if the array is full.
A -2 is returned when duplicate label is found.
*/
int get_next_label(int name)
{
int t;
for(t=0;t<NUM_LAB;++t) {
if(label_table[t].name==0)
return t;
if(label_table[t].name == name)
return -2; /* dup */
}
return -1;
}
/* Find location of given label. A null is returned if
label is not found; otherwise a pointer to the position
of the label is returned.
*/
char *find_label(int name)
{
int t;
for(t=0; t<NUM_LAB; ++t)
if(label_table[t].name == name)
return label_table[t].p;
return 0; /* error condition */
}
/* Find all labels. */
void scan_labels()
{
int addr;
char *temp;
label_init(); /* zero all labels */
temp = prog; /* save pointer to top of program */
/* a label is an integer at the beginning of the line */
do {
get_token();
if(token_type==NUMBER) {
int name = atoi(token) ;
addr = ((name == 0) ? -2 : get_next_label(name));
if(addr < 0) {
(addr==-1) ? serror(5) : serror(6);
}
label_table[addr].name = name;
label_table[addr].p = prog; /* current point in program */
}
/* if not on a blank line, find next line */
if(tok!=EOL)
find_eol();
} while(tok!=FINISHED);
prog = temp; /* restore to original */
}
/***************************************************/
/**************** Expression parser ****************/
/***************************************************/
/* Find value of number or variable. */
void primitive(int *result)
{
switch(token_type) {
case VARIABLE:
*result = variables[*token-'a'];
get_token();
return;
case NUMBER:
*result = atoi(token);
get_token();
return;
default:
serror(0);
}
}
void level2(int *result) ;
/* Process parenthesized expression. */
void level6(int *result)
{
if(*token == '(') {
get_token();
level2(result);
if(*token != ')')
serror(1);
get_token();
}
else
primitive(result);
}
/* Reverse the sign. */
void unary(char o, int *r)
{
if(o == '-')
*r = -(*r);
}
/* Is a unary + or -. */
void level5(int *result)
{
char op = 0;
if(*token=='+' || *token=='-') {
op = *token;
get_token();
}
level6(result);
if(op)
unary(op, result);
}
/* Perform the specified arithmetic. */
void arith(char o, int *r, int *h)
{
int t, ex;
switch(o) {
case '-':
*r = *r-*h;
break;
case '+':
*r = *r+*h;
break;
case '*':
*r = *r * *h;
break;
case '/':
*r = (*r)/(*h);
break;
case '%':
t = (*r)/(*h);
*r = *r-(t*(*h));
break;
case '^':
ex = *r;
if(*h==0) {
*r = 1;
break;
}
for(t=*h-1; t>0; --t) *r = (*r) * ex;
break;
}
}
/* Process integer exponent. */
void level4(int *result)
{
int hold;
level5(result);
if(*token== '^') {
get_token();
level4(&hold);
arith('^', result, &hold);
}
}
/* Multiply or divide two factors. */
void level3(int *result)
{
char op;
int hold;
level4(result);
while((op = *token) == '*' || op == '/' || op == '%') {
get_token();
level4(&hold);
arith(op, result, &hold);
}
}
/* Add or subtract two terms. */
void level2(int *result)
{
char op;
int hold;
level3(result);
while((op = *token) == '+' || op == '-') {
get_token();
level3(&hold);
arith(op, result, &hold);
}
}
/* Entry point into parser. */
void get_exp(int *result)
{
get_token();
if(!*token) {
serror(2);
return;
}
level2(result);
putback(); /* return last token read to input stream */
}
/* Assign a variable a value. */
void assignment()
{
int var, value;
/* token contains variable name */
var = *token-'a';
/* get the equals sign */
get_token();
if(*token != '=') {
serror(3);
}
/* get the value to assign to var */
get_exp(&value);
/* assign the value */
variables[var] = value;
}
/****************************************/
/********* statement parsers ************/
/****************************************/
void exit_block(const char *msg, int beginTok, int endTok, int endTok2)
{
int blockScope = 1 ;
while (blockScope > 0) {
if (tok == endTok) {
if (--blockScope == 0) {
break ;
}
}
else if (tok == beginTok) {
++blockScope ;
}
else if (tok == FINISHED) {
printf("%s not properly terminated ", msg) ;
serror(0) ;
}
else if (tok == endTok2 && blockScope == 1)
break;
do get_token();
while (token_type != COMMAND);
}
/* scanner 'token' now points at endTok, and prog points after endTok */
}
/************* print **********/
/* Execute a simple version of the BASIC PRINT statement */
void print()
{
int answer;
int len=0, spaces;
char last_delim;
do {
get_token(); /* get next list item */
if(tok==EOL || tok==FINISHED) break;
if(token_type==QUOTE) { /* is string */
printf(token);
len += strlen(token);
get_token();
}
else { /* is expression */
putback();
get_exp(&answer);
get_token();
len += printf("%d", answer);
}
last_delim = *token;
if(*token==';') {
/* compute number of spaces to move to next tab */
spaces = 8 - (len % 8);
len += spaces; /* add in the tabbing position */
while(spaces) {
printf(" ");
spaces--;
}
}
else if(*token==',') /* do nothing */;
else if(tok!=EOL && tok!=FINISHED) serror(0);
} while (*token==';' || *token==',');
if(tok==EOL || tok==FINISHED) {
if(last_delim != ';' && last_delim!=',') printf("\n");
}
else serror(0); /* error is not , or ; */
}
/************* goto **********/
/* Execute a computed GOTO statement. */
void exec_goto()
{
char *loc;
int value;
get_exp(&value);
loc = find_label(value);
if(loc == 0)
serror(7); /* label not defined */
else prog=loc; /* start program running at that loc */
}
/************* if **********/
void statement();
/* Execute an IF statement. */
void exec_if()
{
int x , y, cond;
char op;
get_exp(&x); /* get left expression */
get_token(); /* get the operator */
if(!strchr("=<>", *token)) {
serror(0); /* not a legal operator */
return;
}
op=*token;
get_exp(&y); /* get right expression */
/* determine the outcome */
cond = 0;
switch(op) {
case '<':
if(x<y) cond=1;
break;
case '>':
if(x>y) cond=1;
break;
case '=':
if(x==y) cond=1;
break;
}
if (cond) {
while (tok != ELSE && tok != ENDIF && tok != FINISHED)
statement();
if (tok == ELSE)
exit_block("If statement", IF, ENDIF, -1) ;
else if (tok == FINISHED) {
printf("if-statement has no else or endif ") ;
serror(0) ;
}
}
else { /* (!cond): throw away until ENDIF */
exit_block("If statement", IF, ENDIF, ELSE) ;
if (tok == ELSE) {
while (tok != ENDIF && tok != FINISHED)
statement();
if (tok == FINISHED) {
printf("if-statement has no else or endif ") ;
serror(0) ;
}
}
}
}
/*********** loop stack ************/
/* Push function for the FOR/WHILE stack. */
void lpush(struct loop_stack i)
{
if(++ltos>=LOOP_NEST)
serror(10);
lstack[ltos]=i;
}
struct loop_stack lpop()
{
if(ltos < 0)
serror(11);
return(lstack[ltos--]);
}
/*********** for statement ************/
/* Execute a FOR loop. */
void exec_for()
{
struct loop_stack i;
int value;
get_token(); /* read the control variable */
if(!islower(*token)) {
serror(4);
return;
}
i.var=*token-'a'; /* save its index */
get_token(); /* read the equals sign */
if(*token != '=') {
serror(3);
return;
}
get_exp(&value); /* get initial value */
variables[i.var]=value;
get_token();
if(tok!=TO) serror(9); /* read and discard the TO */
get_exp(&i.target); /* get target value */
/* if loop can execute at least once, push info on stack */
if(value <= i.target) {
i.beginLoc = prog;
i.endLoc = 0;
i.breakLoc = 0;
lpush(i);
}
else { /* otherwise, skip loop code altogether */
exit_block("For statement", FOR, NEXT, -1);
#ifdef LOOPELSE
/* check for for-else here, and execute */
get_token() ;
if (tok != ELSE) {
putback() ;
}
#endif
}
}
/************ next statement **************/
void next()
{
struct loop_stack *ii = &lstack[ltos];
if (ltos == -1 || ii->var == 0xff) {
serror(8) ;
}
if (ii->endLoc == 0) { /* allow for fast break-stmt */
ii->endLoc = prog ; /* point to statement after for-else construct */
#ifdef LOOPELSE
get_token() ;
if (tok == ELSE) {
exit_block("If statement", IF, ENDIF, -1) ;
}
else {
putback() ;
ii->endLoc = prog ; /* keep breakLoc and endLoc consistent */
}
#endif
ii->breakLoc = prog ; /* point to statement after for-else construct */
}
++variables[ii->var]; /* increment control variable */
if(variables[ii->var] <= ii->target) {
prog = ii->beginLoc; /* loop */
}
else {
lpop() ;
#ifdef LOOPELSE
/* check for for-else here, and execute if available */
get_token() ;
if (tok != ELSE) {
putback() ;
}
#endif
}
}
/************ break statement **************/
void exec_break()
{
if (lstack[ltos].breakLoc) {
prog = lstack[ltos].breakLoc ; /* points past loop-else construct */
}
else {
const char *msg;
int bTok, eTok;
if (lstack[ltos].var == 0xff) { /* while statement */
msg = "While statement" ;
bTok = WHILE ;
eTok = WEND ;
}
else { /* for statement */
msg = "For statement" ;
bTok = FOR ;
eTok = NEXT ;
}
exit_block(msg, bTok, eTok, -1) ;
#ifdef LOOPELSE
/* check for for-else here, and skip it due to break-statement exit */
get_token() ;
if (tok != ELSE) {
putback() ;
}
else {
exit_block("For-else block", IF, ENDIF, -1) ;
}
#endif
}
lpop() ;
}
/************ continue statement **************/
void exec_continue()
{
struct loop_stack *ii = &lstack[ltos] ;
if (ii->var == 0xff) { /* while statement */
prog = ii->beginLoc ;
}
else { /* for statement */
++variables[ii->var]; /* increment control variable */
if(variables[ii->var] <= ii->target) {
prog = ii->beginLoc; /* loop */
}
else {
if (ii->endLoc) {
prog = ii->endLoc ;
}
else {
exit_block("For statement", FOR, NEXT, -1); /* find next-stmt location */
}
#ifdef LOOPELSE
if (ii->endLoc != ii->breakLoc) { /* An else clause exists */
/* Should/can endLoc point past the else? */
get_token() ; /* skip past else keyword */
}
#endif
lpop() ; /* Now, we need to throw away the for loop context */
}
}
}
/************* while **********/
/* Execute an IF statement. */
void exec_while()
{
struct loop_stack i ;
int pushWhile = 0 ;
int x , y;
int cond;
char op;
if (ltos != -1) {
if (lstack[ltos].beginLoc == lastTokPos) {
/* This while statement is on TOS and active! Keep going! */
}
else {
/* Do not allow direct While-stmt recursion. */
/* Alternating between while and next statements, */
/* or nesting more than one unique while statements is allowed */
/* See if this while has been registered */
/* at a different nest level. */
for (int jj=ltos ; jj >= 0; --jj) {
if (lstack[jj].var != 0xff) { /* no danger of direct recursion */
break ;
}
if (lstack[jj].beginLoc == lastTokPos) {
printf("while statement cannot be directly recursive ") ;
serror(3);
}
}
/* First encounter. Create new while-statement nest */
pushWhile = 1 ;
}
}
else {
pushWhile = 1 ;
}
if (pushWhile) {
i.beginLoc = lastTokPos ;
i.endLoc = 0 ;
i.breakLoc = 0 ;
i.var = 0xff ; /* hack a nonsense var to indicate while-stmt */
}
get_exp(&x); /* get left expression */
get_token(); /* get the operator */
if(!strchr("=<>", *token)) {
serror(0); /* not a legal operator */
return;
}
op=*token;
get_exp(&y); /* get right expression */
/* determine the outcome */
cond = 0;
switch(op) {
case '<':
if(x<y) cond=1;
break;
case '>':
if(x>y) cond=1;
break;
case '=':
if(x==y) cond=1;
break;
}
if(!cond) { /* is false so chew everything through wend */
if (pushWhile == 0) { /* This while is on the stack top */
if (lstack[ltos].endLoc) { /* go to the else */
prog = lstack[ltos].endLoc ;
}
else {
exit_block("While loop", WHILE, WEND, -1) ;
}
#ifdef LOOPELSE
if (lstack[ltos].endLoc != lstack[ltos].breakLoc) { /* else exists */
get_token() ; /* skip else keyword */
}
#endif
lpop();
}
else {
exit_block("While loop", WHILE, WEND, -1) ;
#ifdef LOOPELSE
get_token() ;
if (tok != ELSE) {
putback() ;
}
#endif
}
}
else if (pushWhile) {
lpush(i) ;
}
}
/************* wend **********/
void wend()
{
struct loop_stack *ii = &lstack[ltos] ;
if (ltos == -1 || ii->var != 0xff) { /* check for while stmt */
printf("wend found outside of while statement nest ") ;
serror(3) ;
}
if (ii->endLoc == 0) { /* allow for fast break-stmt */
ii->endLoc = prog ; /* point to statement after for-else construct */
#ifdef LOOPELSE
get_token() ;
if (tok == ELSE) {
exit_block("If statement", IF, ENDIF, -1) ;
}
else {
putback() ;
ii->endLoc = prog ; /* keep breakLoc and endLoc consistent */
}
#endif
ii->breakLoc = prog ; /* point to statement after for-else construct */
}
prog = ii->beginLoc ;
}
/********* input statement *************/
/* Execute a simple form of the BASIC INPUT command */
void input()
{
char var;
int i;
get_token(); /* see if prompt string is present */
if(token_type==QUOTE) {
printf(token); /* if so, print it and check for comma */
get_token();
if(*token!=',') serror(1);
get_token();
}
else
printf("? "); /* otherwise, prompt with / */
var = *token-'a'; /* get the input var */
scanf("%d", &i); /* read input */
variables[var] = i; /* store it */
}
/********* gosub statement ************/
/* GOSUB stack push function. */
void gpush(char *s)
{
if(++gtos == SUB_NEST) {
serror(12);