-
Notifications
You must be signed in to change notification settings - Fork 1
Syntax
YJLO Script has similar syntax as JavaScript or Swift with support for higher order functional programming and object-oriented programming.
Semicolon separator at the end of each statement is optional (since ver 0.3.0).
YJLO Script supports both line comments //
and block comments /* ... */
, likes other C-like languages.
YJLO Script is a case-sensitive language. Identifiers start with a letter and may contain letters, digits, and underscores.
The following examples are all valid identifiers:
a
count
sum2
Hello_World
isValid
Declare a variable with an initial value:
var myVar = "Hello"
To declare a variable with a specified initial value, you can use the short variable declaration operator :=
.
myVar := "Hello"
All variable's default value is null
if the initial value is not given.
Declare multiple variables in one line:
var a = 0, b = "abc", c
/*
EQUIVALENT TO:
a := 0
b := "abc"
c := null
*/
Assigning one value to multiple variables is allowed.
var a, b, c
a = b = c = 4
However, assigning one value to multiple variables in var
statement is not allowed.
var a = b = 4 // ERROR
Instead, use :=
to declare multiple variables and initialize them with the same value.
a := b := 4
print(a, b) // OUTPUT 4 4
Unlike JavaScript (ES5 and older versions), YJLO Script is block-scoped. Every pair of braces {}
defines a new scope. Local variables declared in a scope are visible to its own scope as well as all sub-scopes, but invisible to its parent-scopes.
a := 1
func bar(){
a := 2
b := 3
print( a ) // output 2
if (true) {
print( b ) // output 3
c := 4
print( c ) // output 4
}
print( c ) // Error: Cannot find variable: c
}
bar()
print( a ) // output 1
print( b ) // Error: Cannot find variable: b
Introduction
Langauge Guide
Libraries
- Utility
- ListUtil
- StringUtil
- Math
- Data Structure
- LinkedList
- Stack
- Heap
- HeapList
- HashMap
- HashSet
- Others
- UnitTest
- Tokenizer
Dev Reference
- Syntax Sugar