Skip to content

jpaffrath/jask

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Version Badge License Badge Java Badge

jask

jask is a highly readable interpreter language in early development. The jask interpreter is fully written in Java. It is just a hobby project for fun and learning. Contributions are always welcome!

Seeing jask for the first time? Try the Getting started guide! For further information, please visit the jask Wiki.

Use

To use the interactive mode, invoke jask:

java -jar jask.jar

jask can interpret files:

jask file.jask arg1 arg2 ...

The arguments are stored in a global list variable called _ENV. To test your freshly compiled jask-version, just run the test.jask file.

Examples

Creating new variables

Jask can store three types of primitive data: numbers, strings and boolean values. To mark a variable as empty, you can use the value NULL.

store 100 in z
store 5.2 in d

store "Hello World!" in str

store TRUE in bool

store NULL in foo

There are two abstract data types, lists and dictionaries, which will be covered later.

Assigning values

In order to assign values to variables, they need to be stored first.

assign 1 plus 2 to z
assign d minus 3 to z
assign 3 times 2 to z
assign 10 divide 2 to z
assign 8 mod 3 to z

assign "A string" to str
assign "Hello " plus "World!" to str
assign "Repeating string" times 10 to str

assign FALSE to bool

You can increment and decrement numbers very quickly:

increment myNum ; same as assign myNum plus 1 to myNum
decrement myNum ; same as assign myNum minus 1 to myNum

Control flow

if-else conditions:

if z equals d
  printLine("z equals d")
else
  printLine("z and d are different")
endif

run and while loops:

run i from 0 to 10 with i plus 1
    print("i is ":i)
endrun

store TRUE in val

while val equals TRUE
    print("val is TRUE!")
endrun

for element in list(1:2:3)
  printLine(element)
endrun

Want more examples? Visit Control flow wiki!

Creating functions

Functions in jask can return nothing, any type of variables or data, calculations or other function calls.

function myFunction(param1:param2)
  printLine("Function call with parameters":param1:param2)
end

function divide(num1:num2)
  return num1 divide num2
end

Want more examples? Visit Functions Wiki!

Work with list variables

A list in jask can store strings, numbers, boolean values, other lists and dictionaries. In addition, a list can store different types at the same time.

store list(1:2:3) in numbers
print(numbers)

store listGet(numbers:0) in item1

; add value 4
assign listAdd(numbers:4) to numbers

; remove value at index 2
assign listRemove(numbers:2) to numbers

store list(1:"String":TRUE:list():dictionary("key":"value")) in myList

Want more examples? Visit List variables Wiki!

Work with dictionary variables

A dictionary in jask stores values with associated keys.

store dictionary("myKey":"myValue") in dict
print(dict)

store dictionaryGet(dict:"myKey") in myValue

Want more examples? Visit Dictionary variables Wiki!

Structs in jask

You can store several variables together in a c-like struct:

struct myStruct
    store "Text" in str
    store 100 in num
endstruct

printLine(myStruct->str)

store myStruct in anotherStruct ;creates a copy of your struct
printLine(myStruct->num)

Want more examples? Visit Structs in jask

Honorable mentions

jask has some very interesting features! Visit the jask Wiki to find out more!

Callbacks

You can use callbacks in jask. Callback wiki

Modules

Other jask files can be used as modules. Learn how to do it in the Modules wiki!

Internal Modules

jask provides some internal modules for you to use. Learn more in the Internal Modules wiki!

Converting variables

Learn how to convert variables into different types in the Convert Variables Wiki

Access Operator

You want to know how to access variables inside a function which are defined outside? Visit Access operator wiki!

Functions inside functions

You can define functions inside functions! Learn how to do it in the Functions inside functions Wiki

Modules inside functions

In a function you can import modules. Visit Modules inside functions Wiki to learn more.