This is a read-only snapshot of the ComputerCraft forums, taken in April 2020.
wiggle1000's profile picture

[BETA] WBASIC - a BASIC interpreter for CC

Started by wiggle1000, 02 January 2015 - 04:25 PM
wiggle1000 #1
Posted 02 January 2015 - 05:25 PM
WBASIC

A BASIC interpreter for ComputerCraft.



(PLEASE DO NOT PM ME OR COMMENT ABOUT NOT LIKING BASIC!)

Hello fellow Computers and Crafters! Today I bring you the really really early version of WBASIC!



WHAT IS WBASIC?


WBASIC is a programming language inspired by BASIC.


WHERE CAN I GET IT?


you can find it on pastebin by typing "pastebin get tW4vDUAF WB" on any computer.


WELL HOW DO I USE IT?


YOU RUN A PROGRAM BY SAVING CODE IN A FILE, STARTING WBASIC,

AND TYPING IN THAT FILE'S NAME!




SIMPLE DOCUMENTATION:

Spoiler

PRINT: prints text and goes to next line

WRITE: prints text without new line

GOTO: jumps to a line

SLEEP: delays in tenths of seconds

SET: sets variable in arg 1 to value in arg 2

GOIF: if arg1 is equal to arg2 then goto arg3

READ: reads a string and stores it in arg1

READNUM: same as READ but gets a number

SETCURSOR: sets cursor pos to arg1, arg2

FGC and BGC: set text and back color to color

specefied in string arg1.

GETKEY: waits until keypress or for arg1 sec.s

stores key or string "nil" in var "ret1"

ADD, SUB, MUL, POW, and DIV: perform basic

math operations on arg1 and arg2,

returning result to var "ret1"


REDSTONE:


REDSTONE "R":

reads signal on side of first argument and stores to "ret1"


REDSTONE "S":

sets side (first arg) to output a redstone signal with the

intensity found in the second argument.



MODEM:


MODEM "S":

SEND MODE(EG. MODEM "S","MESSAGE","KEY")

OR MODEM "S","message",[number channel]

OR JUST MODEM "S","MESSAGE" TO BROADCAST!


MODEM "R":

RECEIVE MODE

WAITS FOR REDNET MESSAGE TO COME IN TO MODEM AND THEN

SETS VARIABLES "ret1" and "ret2" to the sender ID and the message, respectively

MODEM "O":

OPENS MODEM ON SIDE OF FIRST ARG( EG. "MODEM "O" "top" )

MODEM "C":

SAME AS MODEM "O" BUT CLOSES MODEM


DATA TYPES:

"STRING" <–string

{VAR} <–variable recall statement (value of variable called var)

1337 <–number(NO DECIMALS OR NEGATIVES YET!

IF NEEDED PLEASE USE A MATH FUNCTION!)




Thanks to squiddev for showing me how to make a spoiler XD
Edited on 16 February 2015 - 12:59 PM
SquidDev #2
Posted 02 January 2015 - 06:03 PM
Looks cool. Other languages in ComputerCraft are always awesome. BASIC is an odd choice though:
Dijkstra said:
It is practically impossible to teach good programming to students that have had a prior exposure to BASIC: as potential programmers they are mentally mutilated beyond hope of regeneration.
From here

If you could get it converting to lua bytecode like JVML-JIT that would be even cooler.

Just a couple of things though:
  • Your variables are local, but functions should be too.
  • Your strToCol function can be replaced with colors or colours or colors.black. This tries to look up the colour in the colors table, then colours table then just returns black if neither exists.

SIMPLE DOCUMENTATION:
(IF YOU KNOW HOW TO MAKE A SPOILER, PLEASE TELL ME!)

[spoiler][/spoiler]
wiggle1000 #3
Posted 03 January 2015 - 07:48 AM
@SquidDev

Thanks for checking this out!

I agree BASIC has some pretty goofy syntax, but I definately dont think it mutilates peoples brains! I mean…look at me: first language i learned was BASIC, now i know BASIC, Lua, and C# (as well as a few misc. languages noone cares about! :3)

also: I wasn't aware you could use the color api as a table…although i shouldve known considering thats how peripherals and all the other APIs work!

Thanks for a really constructive and helpful comment, SquidDev!
Edited on 03 January 2015 - 06:48 AM