home *** CD-ROM | disk | FTP | other *** search
Text File | 1986-03-19 | 2.9 KB | 149 lines | [TEXT/ttxt] |
- \ Assembler ReeseWarner 3/85
- \ 03/06/86 GDC fixed MOVEM
- \ 03/07/86 GDC fixed displacement
-
- \ KEY for TOKENTYPES
-
- \ 1 - number
- \ 2 - word
- \ 3 - special
- \ 4 - EOL
-
- 0 -> dlevel
-
- 3 4 2darray next.state
- 3 4 2darray action
-
- scon specials ",.\#/=]["
-
- 0 value pos \ position on line
- 0 value tiblen \ length of line
-
- 0 value linect
-
- 0 value storedToken
-
- 0 value charCount \ char in definition
-
- String token
-
- 5 x-array actions
-
- \ all action handlers for the action table
- ( char -- tokentype T or F )
- : act0
- +: token 1 ++> pos
- FALSE
- ;
- 'c act0 0 to: actions
-
- : act1
- drop
- 1 TRUE
- ;
- 'c act1 1 to: actions
-
- : act2
- +: token
- 1 ++> pos
- 3 TRUE
- ;
- 'c act2 2 to: actions
-
- : act3
- drop
- 2 TRUE
- ;
- 'c act3 3 to: actions
-
- : act4
- drop
- 1 ++> pos
- FALSE
- ;
- 'c act4 4 to: actions
-
- \ is char in the specials?
- : isSpec { char secchar \ bool slen saddr -- bool }
- false -> bool
- specials -> slen -> saddr
- slen 0
- DO
- saddr i + c@ char =
- IF
- true -> bool leave
- THEN
- LOOP
- char ascii - = secchar ascii D = secchar ascii A = \ for MOVEM
- secchar ascii d = secchar ascii a =
- or or or and
- IF
- true -> bool
- THEN
- bool
- ;
-
- \ determine character class
- : charClass { char secchar -- class }
- char secchar isSpec
- IF
- 2 \ special char
- ELSE
- char
- CASE
- $ 41 $ 5A RANGEOF 0 ENDOF \ A to Z
- $ 61 $ 7A RANGEOF 0 ENDOF \ a to z
- $ 30 $ 39 RANGEOF 1 ENDOF \ 0 to 9
- $ 24 OF 1 ENDOF \ $
- $ 0 $ 20 RANGEOF 3 ENDOF \ control char
- 0 swap
- ENDCASE
- char $ 2D = secchar $ 28 <> and IF drop 1 THEN
- THEN
- ;
-
- : getLine { \ #chars -- }
- \ 13 word
- msg" getLine called"
- query: topfile abort" Premature end of file"
- bytesread: [ last: loadFile ] val" #chars read=" -> #chars
- #chars ++> charCount
- 0 -> pos #chars -> tiblen
- 1 ++> linect
- ;
-
- \ NextToken puts the token into string Token and returns one of the following
- \ four token types:
- \ number, word, special, end-of-line
- : nextToken { \ curState nextChar secchar actNum theClass -- tokentype }
- 0 -> curState
- clear: token
- storedToken 0=
- IF
- BEGIN
- pos tiblen =
- IF
- getLine
- curState 0=
- IF
- eol TRUE
- ELSE
- eol -> storedToken
- curState TRUE
- THEN
- ELSE
- tib pos + dup c@ -> nextChar \ get next char
- 1+ c@ -> secchar
- nextChar secchar charClass -> theClass
- curState theClass at: action -> actNum
- curState theClass at: next.state -> curState
- nextChar actNum exec: actions
- THEN
- UNTIL
- ELSE
- storedToken
- 0 -> storedToken
- THEN
- uc: token 2drop
- ;
-