blob: b3491daea024645e58d62cd7e24f9d41c047914a (
plain) (
blame)
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
|
/* A tiny BASIC interpreter */
/*
Thank the Internet for providing me with this program.
Please report any bugs/security holes to: katchup@adnab.fr.nf
*/
#ifndef DEF_BASIC_H
#define DEF_BASIC_H
// Token types
#define DELIMITER 1
#define VARIABLE 2
#define NUMBER 3
#define COMMAND 4
#define STRING 5
#define QUOTE 6
// Keywords
#define EOL 98 // Special characters
#define FINISHED 99
#define IF 1 // Control structures
#define THEN 2
#define FOR 3
#define NEXT 4
#define TO 5
#define GOTO 6
#define GOSUB 7
#define RETURN 8
#define END 9
#define EXEC 10
#define LOAD 11
#define RUN 12
#define LIST 13
#define PRINT 20 // Built-in commands
#define INPUT 21
#define RND 50 // Built-in functions
// Buffer size definitions
#define TOK_LEN 80
#define LAB_LEN 10 // Control structures
#define NUM_LAB 100
#define FOR_NEST 25
#define SUB_NEST 25
// Lexer
extern char *program; // Data for program
extern char *prog_ip; // Program instructino pointer
extern char token[TOK_LEN];
extern int token_type, tok;
int get_token();
void putback();
void find_eol();
char *load_file(char *fname);
// Data structures
int* find_var(char *s); // returns a pointer to the variable
// Program structure
void init();
extern char *interp_name; /* given by command line argument 0 */
void load_program(char *); // load and scan labels
void insert_line(char *l, int n); // add line to program
int start(char *entry); // start execution at given point
void serror(int);
// BASIC commands
void exec_print(), input();
void assignment();
void get_exp(int*);
#endif
|