basic Basic is a one pass basic Basic compiler for a basic dialect of Basic.
It supports the following commands:
command | syntax | description |
LET | cnum LET v e | Assigns variable v to the value of expression e |
GOTO | cnum GOTO ‘cnum | Goes to the command numbered ‘cnum |
IF | cnum IF p THEN t ELSE e | if p is not 0 execute command t else execute command e |
PLOT | cnum PLOT x y color | Fills the pixel at x,y with the given color |
FOR | cnum FOR i init TO end …new lines containing commands… cnum NEXT i | Repeats the commands between the FOR and the NEXT while end >= i. i is incremented once in every iteration |
look at pirate-ship.bas for an example. It will produce the following image
LET red 13583410
LET lightRed 16541523
LET blue 7574225
LET white 16777215
LET brown 7355966
LET lightBrown 9393750
LET grey 10921638
LET lightGrey 12105912
LET height 800
LET width 800
LET seaLevel (height/4)*3
FOR x 0 TO width-1
FOR y 0 TO height-1
IF y > seaLevel THEN LET color blue ELSE LET color white
PLOT x y color
NEXT y
NEXT x
LET startAt width/20
LET diagonalLen width/6
LET sink 25
LET borderWidth 4
FOR c 0 TO diagonalLen
LET y (seaLevel + c) - diagonalLen + sink
FOR f startAt + c TO width - (startAt + c)
PLOT f y brown
NEXT f
LET x startAt + c
FOR depth 0 TO borderWidth
LET ywithDepth y + depth
PLOT x ywithDepth lightBrown
PLOT width - x ywithDepth lightBrown
NEXT depth
NEXT c
LET lowestX (startAt + diagonalLen)
LET y seaLevel + sink
FOR x lowestX TO (width - lowestX)
FOR depth 0 TO borderWidth
PLOT x y + depth lightBrown
NEXT depth
NEXT x
LET boatTop seaLevel - diagonalLen + sink
FOR x startAt TO (width - startAt)
FOR depth 0 TO borderWidth
PLOT x boatTop-depth lightBrown
NEXT depth
NEXT x
LET poleXStart startAt*4+10
LET poleWidth 5
FOR y height/3-50 TO boatTop-borderWidth-1
FOR depth 0 TO 3
PLOT poleXStart-depth y lightGrey
PLOT poleXStart-depth y lightGrey
NEXT depth
FOR depth 0 TO poleWidth
PLOT poleXStart+depth y grey
NEXT depth
NEXT y
LET flagEnd width/2 + poleXStart
FOR y height/3-50 TO boatTop-80
FOR x poleXStart + poleWidth + 1 TO flagEnd
PLOT x y red
NEXT x
NEXT y
FOR depth 0 TO 2
FOR x poleXStart + poleWidth + 1 TO flagEnd
PLOT x y+depth lightRed
NEXT x
NEXT depth
LET red 16711680
LET blue 255
LET width 800
LET halfWidth width/2
FOR c 0 TO width-1
IF halfWidth > c THEN LET color red ELSE LET color blue
PLOT (width-c) (width-c) color
PLOT c (width-c) color
PLOT halfWidth c color
PLOT halfWidth+1 c color
PLOT c halfWidth color
PLOT c halfWidth+1 color
NEXT c
The following command will compile example.bas to UVM assembly.
clj -M basic.clj example.bas
You will need to download UVM and use it to run the generated assembly.
- UVM (https://github.com/maximecb/uvm)
- clojure