Skip to content
This repository has been archived by the owner on Dec 11, 2022. It is now read-only.

Commit

Permalink
Merge pull request #83 from SK1Y101/develop
Browse files Browse the repository at this point in the history
v0.7.0
  • Loading branch information
mergify[bot] authored Mar 27, 2021
2 parents 204f43e + adaa304 commit 7f6a724
Show file tree
Hide file tree
Showing 33 changed files with 781 additions and 137 deletions.
17 changes: 17 additions & 0 deletions ExampleCode/Assignment/Augmented_Assignment.skiy
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
///this should allow more complex assignment
things like ++a instead of a = a+1///

//post- and pre- fixed '++'
var a = 0

print(++a) //increment before returning value, should show 1

print(a++) //increment after returning value, should show 1

print(a) //2

print(--a) //decrement before returning value, should show 1

print(a--) //decrement after returning value, should show 1

print(a) //0
9 changes: 7 additions & 2 deletions ExampleCode/ControlFlow/ForTest.skiy
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
//test different for loop examples
//1) no conditional or incremental for x, (incremental is implicit):

for var x:
print(x)

//0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 20, ...


//2) only conditional (incremental is implicit):
for var x when x < 10:
Expand All @@ -17,7 +22,7 @@ for var x when x < 10 do x = x+2:

//4) only incremental

//for var x do x = x+2:
// print(x)
for var x do x = x+2:
print(x)

//0, 2, 4, 6, 8, 10, 12, 14, 16, 18, 20, ...
31 changes: 31 additions & 0 deletions ExampleCode/ControlFlow/Interuptions.skiy
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
///interuptions can be excellent points of control flow,
in Skiylia, we have both break and continue///

//keep looping until a condition, then stop
var x = 1
while true:
print(x++)
if x > 20:
break

//2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20

//don't compute the rest of the loop, unless a condition
for var n = 1 when n < 20 do n = n + 2:
if mod(n, 3):
print(n, "divisible by 3")
continue
print(n)

///
1
3 divisible by 3
5
7
9 divisible by 3
11
13
15 divisible by 3
17
19
///
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ parameters > Identifier ( "," Identifier )*

vardeclaration > ("var" Idenitifer ( "=" expression )? ) "\n"+ <=explicit requires "var"

statement > exprstmt | forstmt | ifstmt | returnstmt | whilestmt | block
statement > exprstmt | forstmt | ifstmt | interuptstmt | returnstmt | whilestmt | block

block > {Indent level increases} declaration {End token}+ {token with lower indentation}

Expand All @@ -50,11 +50,15 @@ forstmt > "for" (vardeclaration | exprstmt) (("when" | "where") expres

ifstmt > "if" expression {Block token} statement ("else" statement)?

interuptstmt > "break" | "continue"

returnstmt > "return" expression?

whilestmt > "while" expression {Block token} statement

expression > assignment
expression > condition

conditional > assignment ( ( ( "?" expression ":" ) | "?:" | "??" ) conditional )?

assignment > (call ".")? Identifier "=" assignment | logicalOr

Expand All @@ -65,10 +69,10 @@ logicalXor > logicalAnd ( ( "^" | "xor" ) logicalAnd )*

logicalAnd > equality ( ( ( "&" | "and" ) ) equality )*

equality > comparison ( ( "!=" | "==" ) comparison )*
equality > comparison ( ( "!=" | "==" | "!==" | "===" | "!~~" | "~~~" ) comparison )*

//Then comparisons
comparison > term ( ( ">" | "<" ) term )*
comparison > term ( ( ">" | ">=" | "<" | "<=" ) term )*

//Then terms
term > factor ( ( "-" | "+" ) factor )*
Expand All @@ -77,7 +81,9 @@ term > factor ( ( "-" | "+" ) factor )*
factor > unary ( ( "*" | "/" ) unary )*

//then unaries
unary > ( "!" | "-" ) unary | call
unary > ( "!" | "-" )* unary | ( ( "++" | "--" ) call )? | postfix

postfix > call ( "--" | "++" )?

//And finally call has the lowest precedence (and is computed first)
call > literal ( "(" arguments? ")" | "." Identifier)*
Expand Down
183 changes: 183 additions & 0 deletions ExampleCode/Grammar/FullGrammar.skiy
Original file line number Diff line number Diff line change
@@ -0,0 +1,183 @@
//An example of the absolute minimum required for a Skiylia pre-release

//reserved words:
true, false, null, var, and, or, xor, if, else, elif, while, for, do, Where, When, def, class, super, self, {primitives}

//required symbols:
'(', ')', ':', ',', '.', '-', '+', '*', '/', '>', '<', '=', '!', '?', '"', '&', '|',

//GRAMMAR IDEAS BELOW
//single line comments

///this is a multi-line comment.
it must be completed with another set of three slashes///

//Bool
true
false

//numbers
123 //int
12.4 //float
0 //zero evaluates as false, all others as true

//strings
"56" //string, not int
"hi there" //strings
"" //empty, evaluates as false, all else true

//miscellaneous
null //None-type
//null can be implicitly converted to zero if required

//Expressions
a + b //addition
a - b //subtraction
a * b //multiplication
a ** b //exponentiation
a / c //division

--a //prefix negation
++a //prefix addition
a-- //postfix negation
a++ //postfix addition

//Comparisons and equalities
a < b //less than
a <= b //less than or equal to
a > b //greater than
a >= b //greater than or equal to
a == b //equal to
a === b //strictly equal to (same type, as well as same value) <- "3.0" == 3 gives true, "3.0" === 3 gives false, as "3.0" is a string
a ~~~ b //Fuzzily equal to (same type, don't care about value) <- "3.0" == 3 gives false, "3.0" === 3 gives false, none of them have the same type
a != b //not equal to
a !== b //not strictly equal to
a !~~ b //not fuzzily equal to

//Logical operators
-a //negates the value of a -6 -> 6, "-6" causes an error (at the present)
!a //not a
a & b //a and b
a | b //a or b
a ^ b //a xor b
a and b //a and b
a or b //a or b
a xor b //a xor b
a ? b : c //if a then b else c <-ternary operator
a ?: b //if a is true, then a, else b <-elvis operator, equivalent to a ? a : b, but does not evaluate 'a' twice
a ?? b //if a null, then b, else a <-null coalescence operator, equivalent to a!=null ? a : b, but does not evaluate 'a' twice

//Variables and assignment
var a //initialise as 0
a = 5 //reassign a as 5. a must already exist

//control flow
//if statements
if (condition):
action-if-True
action-if-true
elif (condition): //not always required
action-if-True
action-if-true
else: //not always required
action otherwise

ie:
if a > 5:
print("a was greater than 5")
else:
print("a was not greater than 5")

//while loop
while condition: //require any variables to be defined prior to
action-while-True
action-while-True

ie:
a=100
while true:
print(a--)
if a < 10:
break

//for loop
for (increment variable) ("where" | "when") (condition) "do" (increment operation):
action-during-loop

ie:
for x (Where | When) x<=10:
print(x)
//the loop increments by one implicitly

for x (Where | When) x<10 do x=x+2
print(x)
//explicitly defining the increment operation

for x in 10:
print(x)
//implicitly define '(Where | When) x<10' as 'in 10' <-- NOT SURE IF I WANT TO KEEP THIS BEHAVIOUR

for x do x=x+2:
print(x)
//basically a while loop with a defined increment and implicitly declared variable

//functions
def thisFunc(a, b, c=""):
return a+b

thisFunc(1, 2)

//use def to declare, can have any number of required arguments, can assign default arguments to them too
//implicitly return null, unless a "return" block is provided

a = thisFunc
a(1, 2)
//gives same result, as function declaration counts as a varibale (first class function declaration)

//Classes
class Parent:
init():
print("I am a parent")

class Child(Parent):
def init()
print("I am a child")

class Child2(Parent):
init():
print("I am a child who executes my Parents' functions too")
super.init()

a = Child()
a.trial = 4
print(a.trial) //4

//declared with class, inherited by placing parent in brackets. methods can be implicitly declared without "def" if desired.
//super accesses parent methods,
//self accesses own methods and variables
//can implictly store variables and functions using (class).(method/function)

def trial(a, b):
print(a + b)

class Test:
init():
trial(5, 2) //outputs 7, as it searches for global functions first //fails is class does not have method, shows warning that global does not exist either
self.trial(5, 2) //3, as this forces looking for own method. //fails if class does not have method
trial(a, b):
print(a - b)

//Standard library
print(thing-to-print) //shows display to screen, can be any data-type or variable
str(a) / string(a) //explicitly converts a to a string
int(a) / integer(a) //explicitly converts a to an integer
float(a) //explicitly converts a to a float

//primitives (Functions from the base language, rather than ones I wrote myself)
clock //returns the current utc time
abs(a) //return the absolute value of a
ceil(a) //returns a, rounded up
floor(a) //returns a, rounded down
pow(a, b) //returns a raised to the power b
mod(a, b) //returns a modulo b
round(a, b) //returns a, rounded to 'b' decimal places
20 changes: 20 additions & 0 deletions ExampleCode/Logicals/Conditionals.skiy
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
//Test the ternary operator
print(true ? 1 : 2) //1
print(false ? 1 : 2) //2
print(0 ? 1 : 2) //2 <- '0' evaluates as false
print("ternary" ? 1 : 2) //1 <- everything except '0' and "" evaluates as true
print(null ? 1 : 2) //2 <- 'null' evaluates as false

//elvis operator
print(true ?: 2) //true
print(false ?: 2) //2
print(0 ?: 2) //2 <- '0' evaluates as false
print("ternary" ?: 2) //"ternary" <- everything except '0' and "" evaluates as true
print(null ?: 2) //2 <- 'null' evaluates as false

//null-coalescence operator
print(true ?? 2) //true
print(false ?? 2) //false
print(0 ?? 2) //0
print("ternary" ?? 2) //"ternary"
print(null ?? 2) //2 <- 'null' is the only 'null'
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ print(false == false) //true

print(true == 1) //true
print(false == 0) //true
print(true == "true") //false
print(false == "false") //false
print(false == "") //false
print(true == "true") //true
print(false == "false") //false <- nonempty strings evaluate as true
print(false == "") //true <- empty strings evaluate as false

print(true != true) //false
print(true != false) //true
Expand All @@ -17,6 +17,6 @@ print(false != false) //false

print(true != 1) //false
print(false != 0) //false
print(true != "true") //true
print(true != "true") //false <- nonempty strings evaluate as true
print(false != "false") //true
print(false != "") //true
print(false != "") //false <- empty strings evaluate as false
Loading

0 comments on commit 7f6a724

Please sign in to comment.