CWarp2
Jump to navigation
Jump to search
CWarp2 is an upgraded version of CWarp made by User:WoodyFan3412 that has better syntax
Syntax
Commands in CWarp2 are separated by spaces, you can use quotation marks to group multiple words into 1
print "Hello World!" print "The quick" "brown fox" test "Example 1" "Example 2" "Example 3" apple banana pear
You can also use the semicolon ; for comments
; hello ; this is a comment ; write that down
The "#define" keyword can be used to define a constant variable
#define APPLE "Hello, World!" #define TEST "This is a Test!" print APPLE print TEST ; output: ; Hello, World! ; This is a Test
An example on how variables work
; set the "apple" variable to 15 var apple = 15 ; you can assign variables that already exist var apple = 10 ; you can do math operations on variables var apple + 5 var apple * 3 var apple / 2 var apple % 5 ; Strings can be combined together using the .. operator (similar to Lua) var text = "Hello " var text .. " world!" var text .. " my favourite number is " var text .. apple var text .. "!"
Example on how IF statements are used
@main var num = 45 if num > 10 option1 if num < 10 option2 halt @option1 print "number is greater than 10!" return @option2 print "number is less than 10." return
Example on how the "wait" command works
wait 3 seconds wait 1000 milliseconds wait 30 frames wait 5 minutes
Command List
A list of all commands that are available in CWarp2
Command Name | Description |
---|---|
print <text> | Prints the first argument to the console. |
assert <value> | If this value is 0, then throw an error. |
wait | Wait an amount of time, example: 'wait 3 seconds' 'wait 1000 milliseconds' 'wait 30 frames' |
var | assign a variable, if you do 'var test = 5' test will be set to 5, you can also do math operations, 'var test + 15' will add 15 to test. |
goto <func> | jump to a certain label, labels are defined with the @ symbol |
halt | stop the program from running |
if <value1> <compare> <value2> <func> | IF statement, used for comparing numbers, if this condition is met it will jump to the function, example: 'if test > 10 otherFunc' |
call <func> | jump to a certain label, also sets the 'return address' so it can be returned to later |
return | jumps to the return address that was set by "call" |
input | prompts the user for input and then stores it in the variable |
Example Programs
Any CWarp2 program should have a label called "main", similar to C.
This program prints Hello World to the console.
@main print "Hello, World!" halt
Print the infamous "99 bottles of beer" song
@main ; set the bottles to 99 var bottles = 99 ; start the loop call loop halt @loop var str = bottles var str .. " bottles of beer on the wall." print str var str = bottles var str .. " bottles of beer!" print str print "take one down, pass it around," var bottles - 1 if bottles == 0 "ending" var str = bottles var str .. " bottles of beer on the wall!" print str goto loop @ending print "no more bottles of beer on the wall!" halt
A random number generator.
@random var rand + 5298.1939 var rand * 1.923 var rand / 1.215 var rand mod 255 return @main var rand = 0 func loop halt @loop func random print rand goto loop
Computational class
Turing complete assuming variables are unbounded. See counter machines.