-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhbas.c
More file actions
executable file
·51 lines (44 loc) · 853 Bytes
/
hbas.c
File metadata and controls
executable file
·51 lines (44 loc) · 853 Bytes
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
#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>
#include <string.h>
#include "util.h"
#include "hbasic.h"
#include "tokenizer.h"
char error[256];
void intro() {
puts("HBASIC v0.1\n");
}
void readline(char *line) {
int pos = 0;
while (TRUE) {
char c = getchar();
if (c == '\n' || c == '\r') {
break;
}
line[pos++] = c;
}
line[pos] = '\0';
}
void mainLoop() {
char line[256];
struct Token token;
token.value = malloc(256);
while (TRUE) {
putchar('>');
readline(line);
strupper(rtrimwhitespace(ltrimwhitespace(line)));
tokenize(line);
nextToken(&token);
if (token.type == TYPE_QUIT) {
break;
} else {
printf("token: type=%d, value=%s\n", token.type, token.value);
}
}
free(token.value);
}
int main(int argc, char *argv[]) {
intro();
mainLoop();
}