forked from jwillia3/BASIC
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathREADME
executable file
·95 lines (80 loc) · 2.67 KB
/
README
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
BASIC INTERPRETER
JERRY WILLIAMS JR
STATEMENTS:
# COMMENT ...
> EXPR
DIM VAR(LENGTH)
LOCAL [VAR [, VAR ...]]
SUB NAME [PARAM [, PARAM ...]] ... END SUB
NAME [ARG [, ARG ...]]
RETURN [EXPRESSION]
IF CONDITION ... [ELSE IF CONDITION ...] [ELSE ...] END IF
IF CONDITION THEN STATEMENT
WHILE CONDITION ... END WHILE
FOR VAR=INIT TO FINAL ... END FOR
FORMAT STRING [, EXPRESSION ...]
RESUME
BREAK
BYE
* "%" IN "FORMAT" PRINTS THE NEXT ARGUMENT AS AN INTEGER
* "SUB" MAY NOT BE NESTED
* "LOCAL" MAY ONLY BE USED IN A SUBROUTINE
EXPRESSIONS:
NUMBER, "", NAME, NAME(INDEX), NAME(ARG,...), UBOUND(VAR), (EXPRESSION)
[EXPRESSION {*|/|\}] EXPRESSION
[EXPRESSION {+|-}] EXPRESSION
[EXPRESSION {=|<|>|<>|<=|=>}] EXPRESSION
[EXPRESSION {AND|OR}] EXPRESSION
* BOOLEAN VALUES ARE -1 FOR TRUE AND 0 FOR FALSE
* "AND" AND "OR" ARE NOT SHORT-CIRCUITING
* OPERATORS ARE LEFT-ASSOCIATIVE
* STRINGS SHOULD ONLY BE USED FOR "FORMAT"
GENERAL NOTES:
* VARIABLES ARE CASE-INSENSITIVE
* ARRAY INDEXES START FROM 1
IMPLEMENTATION
* ALL BLOCK STRUCTURES LEAVE THEIR KEYWORD AT THE TOP
OF THE C-STACK TO BE CHECKED AGAINST "END"
* "TEMP" KEEPS TRACK OF HOW MANY CELLS ARE ON THE
RUN-TIME STACK. "RETURN" DROPS THESE BEFORE
EXITING THE FUNCTION.
* "LOCAL" CANNOT CHANGE THE MODE OF A VARIABLE; A
VARIABLE MUST BE NORMAL, AN ARRAY, OR SUBROUTINE
IN ALL CONTEXTS.
* "INITBASIC" IS NOT MEANT TO RESET THE INTERPRETER
COMPILING AND INTERPRETING:
IF GIVEN A FILE, WE BEGIN IN COMPILED MODE
IF NO FILE IS GIVEN, WE BEGIN IN INTERPRETED MODE
"CPC" IS THE "PC" OF THE NEXT INSTRUCTION TO COMPILE
"IPC" IS THE BEGINNING OF TEMPORARY INTERPRETED CODE
"OPC" IS THE PC TO RETURN TO AFTER INTERPRETED CODE IS RUN
A STATMENT IS COMPILED IN EITHER MODE
AFTER A STATEMENT IS COMPILED, IT IS RUN IN I-MODE BY:
SETTING "PC" TO "IPC"
EMITTING A "STOP_"
RUNNING THE DRIVER
RESTORING THE "PC" AND "CPC"
COMPLEX STATEMENTS LIKE IF SET ENTER COMPILED MODE
* "OPC" IS NULL IF "BREAK" IS RUN FROM COMPILED CODE
* "RESUME" WITH A VALUE FOR EXPRESSIONS NOT STATEMENTS
SUBROUTINES:
C-STACK: {JMP}
STACK: {LINK,SAVED...}
SUBROUTINE DESCRIPTOR:
TOTAL LOCALS
PARAM COUNT
INDEXES OF PARAMS
VALUE OF A SUBROUTINE IS IT'S PC
CALL TAKES VARIABLE INDEX
* NO DISTINCTION BETWEEN FUNCTIONS AND SUBROUTINES
* LOCALS MAY ONLY BE USED INSIDE OF A SUBROUTINE
* TRYING TO USE THEM OUTSIDE WILL NOT REPORT AN ERROR
WHILE: C-STACK: {TEST-FALSE-BRANCH, TOP}
FOR:
C-STACK: {TEST-FALSE-BRANCH, I, TOP}
STACK: {HI}
* "FOR_" AND "NEXT_" INSTRUCTIONS DROP THE HI VALUE
FROM THE STACK ON FAILURE AND INCREMENT
DIMENSIONS:
THE VALUE OF A DIM IS A POINTER
THE LENGTH OF THE DIM IS STORED IN THE FIRST CELL