I've never owned an Apple or coded 6502 assembly, so this is just a crazy obsession to figure out a puzzle. Out of pure curiosity, I found myself trying to understand how Woz implemented syntax rules in his integer basic. Here is the disassembled source I'm using.
http://www.easy68k.com/paulrsm/6502/INTLST.TXT
Would a kindly soul be willing to explain how the syntax rules in the syntax table are represented?
For what it's worth -- I've come to this approximate understanding of the structure of the parser/interpreter.
The parser uses a set of syntax diagrams to convert each line into a set of tokens/operators. The interpreter then executes the tokens using a pair of stacks and a precedence-operator style sequence of operations.
There is a subroutine for each operator that the interpreter uses. The addresses are available in VERBADRL (line 19960) and VERBADRH (line 20300) in the source above. The addresses are indexed by their token value -- so token $00 is the BEGIN_LINE operator, and so on.
The 2 precedence weights for each operator are also available from $e980 (line 19760 in the source above) as an interleaved pair of 4-bit values -- 1 byte per operator, and indexed by the operator's token value. So far so good.
The syntax rules should be present in SYNTABL and SYNTABL2. I can even roughly understand how the keywords are organized -- they are backwards, have $20 subtracted from them, and end either if the value exceeds $bf, or is less than $80.
Here's where i'm stuck -- I don't understand how the syntax rules are represented. I'll pick an example statement like
HLINE x1,x2 at y
The corresponding portion of the syntax table that seems most promising looks like this.
Code:
22500 DB $67,"T"-32,"A"-32 ;AT
22510 DB $07,","-32 ;
22520 DB $07,"N"-32,"I"-32,"L"-32,"H"-32 ;HLIN
I'll reverse this so it's easier to see the underlying values that are puzzling me.
Code:
"HLIN" $07 "," $07 "AT" $67
So the $07 and $67 clearly denote elements of the intermediate parse diagram, but I don't understand what these numbers map to. $07 for instance, can't map to token $07 (the RUN n operator) shouldn't it map to an expression?
Any guidance would be much appreciated!
-kb