Jump to content




Nextbasic


  • You cannot reply to this topic
6 replies to this topic

#1 immibis

    Lua God

  • Members
  • 1,033 posts
  • LocationWellington, New Zealand

Posted 11 September 2013 - 05:49 AM

(correct capitalization is NextBASIC. Forum is stupid)

Pastebin code: XechUbLP

This is a simple BASIC dialect written in Lua for CC.
There are no loops or functions, only single-line IF and GOTO. This is intentional to keep the number of language features down. Arrays are a future possibility.

Commands do not have to be in uppercase. Variable names are case insensitive (XYZ and xyz are the same variable)
String variables have names ending in $, number variables do not.

Supported commands:
LET variable = value - sets a variable.
PRINT something - prints text or numbers. See the example program for examples of the various ways you can use PRINT.
INPUT variable - gets input from the user. Works for both number and string variables.
IF condition THEN command - runs command if condition is true. See example program for examples of how to use this.
[label] - a label that GOTO can go to.
GOTO [label] - jumps to a label.
CLS - clears the screen
REM anything - does nothing (this is a comment)
WAIT value SECONDS - waits a certain amount of time

SET REDSTONE SIGNAL side ON/OFF - sets a redstone signal output
SET REDSTONE SIGNAL side colour ON/OFF - sets a bundled redstone signal output
WAIT FOR REDSTONE SIGNAL side ON/OFF - waits for a redstone signal to be on or off
WAIT FOR REDSTONE SIGNAL side colour ON/OFF - waits for a bundled redstone signal to be on or off
WAIT FOR REDSTONE SIGNAL CHANGE - waits for any redstone input to change

INT(number) - equivalent to math.floor in Lua, rounds a number down to the nearest integer.
RND() - random number between 0 and 1
VAL(string) - converts a string to a number
STR$(number) - converts a number to a string
LEN(number) - the length of a string
LEFT$(string, number) - a certain number of characters from the start of a string
RIGHT$(string, number) - a certain number of characters from the end of a string
MID$(string, start, length) - a certain number of characters from the middle of a string. start is the position of the first character to get.
LOWER$(string) - converts a string to lowercase
UPPER$(string) - converts a string to uppercase
TRIM$(string) - removes spaces from the start and end of a string
INSTR(string to look in, string to look for, start position) - the position where one string occurs in another, or -1 if not found. Example: INSTR("hello world", "lo", 1) is 4. Always starts looking at start position.

< > <> <= >= = - comparison operators (respectively: greater than, less than, not equal, less than or equal, greater than or equal, equal)
X AND Y - true if X and Y are true
X OR Y - true if X or Y or both are true
NOT X - true if X is not true
REDSTONE SIGNAL side - true if there is a redstone signal input on side
REDSTONE SIGNAL side colour - true if there is a bundled signal input on side, wire colour colour

Example program (number guessing game):
LET NumberOfGames = 0
LET NGuesses = 0

PRINT "What's your name? ";
INPUT name$
PRINT "Hi ";NAME$;"!"
IF INSTR(UPPER$(NAME$), "A", 1) <> -1 THEN PRINT "I see your name has an A in it."
PRINT

[difficulty]
PRINT "Select difficulty level - enter EASY, HARD or INSANE: ";
INPUT SEL$
LET SEL$ = UPPER$(SEL$)
IF SEL$ = "EASY" THEN LET MAX = 10:GOTO [startgame]
IF SEL$ = "HARD" THEN LET MAX = 100:GOTO [startgame]
IF SEL$ = "INSANE" THEN LET MAX = 10000:GOTO [startgame]
CLS
PRINT "That's not a valid answer, silly ";name$;"!"
GOTO [difficulty]

[startgame]
LET G = INT(RND() * MAX + 1)

PRINT
PRINT "=== GAME IS STARTING ==="

[enternumber]
PRINT "Enter a number between 1 and ";MAX;": ";
INPUT A
LET NGuesses = nguesses + 1
IF A < G THEN PRINT "Too low!"
IF A > G THEN PRINT "Too high!"
IF A <> G THEN GOTO [enternumber]

LET NumberOfGames = NumberOfGames + 1
PRINT "That's right!"
PRINT "You have won: ";NumberOfGames;" games in ";nguesses;" guesses, ";name$
GOTO [startgame]


#2 Zudo

  • Members
  • 800 posts
  • LocationUK

Posted 11 September 2013 - 11:28 AM

Nice :)

#3 ElvishJerricco

  • Members
  • 803 posts

Posted 11 September 2013 - 05:14 PM

I hope new languages becomes a popular thing in CC. Making or modifying a language is great fun!

#4 Mitchfizz05

  • Members
  • 125 posts
  • LocationAdelaide, Australia

Posted 11 September 2013 - 05:35 PM

Good job! It looks a bit like batch.
Actually: how about FileIO functions?

#5 immibis

    Lua God

  • Members
  • 1,033 posts
  • LocationWellington, New Zealand

Posted 12 September 2013 - 04:07 AM

Updated - added AND, OR, NOT, WAIT x SECONDS and redstone signal commands: WAIT FOR REDSTONE SIGNAL side, WAIT FOR REDSTONE SIGNAL side colour, SET REDSTONE SIGNAL side ON/OFF, SET REDSTONE SIGNAL side colour ON/OFF, IF REDSTONE SIGNAL side, IF REDSTONE SIGNAL side colour, and WAIT FOR REDSTONE SIGNAL CHANGE

Also renamed to NextBASIC because next is an actual word.

Trivia: You can use variable names that are the same as commands.
INPUT IF
IF IF = 5 THEN PRINT "You typed 5!"
More trivia: NextBASIC usually doesn't care about spaces.
PRINT"Enter two numbers"
INPUTIF
INPUTTHEN
IFTHEN=IF THENPRINT"They're the same!"


#6 kreezxil

  • Members
  • 128 posts
  • LocationBowie, TX

Posted 12 September 2013 - 04:17 AM

You Sir are a MAD MAN and I commend thee! Hear hear!!

I give you 5 :D :D :D :D :D for both advancing CC in lua to create this and setting the modern programmer back 30 years!

I might actually write something in this dialect now that you've gone and made it. Ironically I was thinking about making something like this a week ago, but alas implementation is not in the scope of a professional procrastinator.

#7 Yevano

  • Members
  • 376 posts
  • LocationUSA

Posted 12 September 2013 - 08:57 PM

Could be nice to have an interfacing feature between this and Lua. For example, "LCALL lua_func args" to call a Lua function. This way you don't have to make a command for each and every CC library function.





2 user(s) are reading this topic

0 members, 2 guests, 0 anonymous users