University of Calgary

tiny basic exercises

Tiny Basic Interpreter

Exercises
created by: Katrin Becker, 1999
adapted from: ACM programming contest problem set

CONTENTS of THIS PAGE...
Example 1:
Example 2:
Example 3:
Example 4:
Example 5:
Example 6:
Example 7:
Example 8:
Example 9:
Example 10:
Empty form for results from Scanner

 

Stand-Alone Form (different Page)


Exercise 1:
Reduce the following Tiny Basic program to its set of tokens and interpret it. Print out the results as the Interpreter would.
1 LET A=10
2 LET I=0
3 LET X=I+I
4 LET T=1
5 LET X=X+T
6 PRINT X
7 LET T=1
8 LET I=I+T
9 IF A>I
10 GOTO 3
11 STOP

Exercise 2:
Reduce the following Tiny Basic program to its set of tokens and interpret it. Print out the results as the Interpreter would.
1 LET X=-12
2 LET R=4
3 GOTO 14
4 PRINT V
5 LET X=3
6 LET R=8
7 GOTO 14
8 PRINT V
9 LET X=0
10 LET R=12
11 GOTO 14
12 PRINT V
13 STOP
14 IF Z>X
15 GOTO 23
16 LET V=1
17 LET T=-1
18 LET V=V+T
19 LET T=V+X
20 IF T>Z
21 GOTO 17
22 GOTO R+Z
23 LET V=-1
24 LET T=1
25 LET V=V+T
26 LET T=V+X
27 IF Z>T
28 GOTO 24
29 GOTO R+Z

Exercise 3:
Reduce the following Tiny Basic program to its set of tokens and interpret it. Print out the results as the Interpreter would.
1 LET F=5
2 LET I=10
3 LET N=100
4 LET R=0
5 IF R>N
6    STOP
7 PRINT R
8 LET R=R+F
9 GOTO 5

Exercise 4:
Reduce the following Tiny Basic program to its set of tokens and interpret it. Print out the results as the Interpreter would.
1 LET A=5
2 LET B=10
3 LET C=15
4 IF A>B
5    LET R=A
6 IF B>A
7    LET R=B
8 IF C>R
9    R=C
10 PRINT R
11 STOP

Exercise 5:
 

Exercise 6:

Exercise 7:
 

Exercise 8:
 

Exercise 9: 

Exercise 10:
 

Form:
 Line #
Statement Token 2 Token 3 Token 4 Token 5 Token 6
   
 Type
Value
 Type
Value
 Type
Value
 Type
Value
 Type
Value
 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                      


Updated: August 5, 2005 07:04 PM