Skip to content
This repository was archived by the owner on Apr 25, 2023. It is now read-only.

Commit c661311

Browse files
authored
Merge pull request #4 from I-Language-Development/dev
Update from Dev
2 parents 2c2c396 + 0057bd4 commit c661311

File tree

6 files changed

+186
-7
lines changed

6 files changed

+186
-7
lines changed

Main/lexer.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
Final,
3838
)
3939

40+
import Main._types
4041

4142
#############
4243
# CONSTANTS #
@@ -268,7 +269,7 @@ def gettoken(string: str, line: int, column: int) -> LexerToken | None:
268269

269270
index += 1
270271

271-
return [str(token) for token in self.tokens if token is not None]
272+
return [str(token) for token in self.tokens if token is not None] # TODO (ElBe): Change it back
272273

273274

274275
if __name__ == "__main__":

Modules/Math.ilang

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,17 +35,26 @@ import _core
3535
// CONSTANTS //
3636
///////////////
3737

38-
const float Pi = 3.141592653589793238462643383279502884197
39-
const float E = 2.718281828459045235360287471352662497757
40-
const float Infinite = _core.Math.Infinite
38+
const float pi = 3.141592653589793238462643383279502884197
39+
const float e = 2.718281828459045235360287471352662497757
40+
const float infinite = _core.Math.Infinite
4141

4242

4343
///////////
4444
// ROUND //
4545
///////////
4646

47+
/*
48+
* Returns the rounded version of the number.
49+
*
50+
* @params
51+
* number (float): Number to round.
52+
*
53+
* @return
54+
* int: Rounded number.
55+
*/
4756
int round(float number) {
48-
return _core.Math.round(number)
57+
return _core.Math._round(number)
4958
}
5059

5160
// Todo (ElBe): Add floor and ceil

Modules/Random.ilang

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,16 @@ import _core
3535
// RANDOM INTEGER //
3636
////////////////////
3737

38+
/*
39+
* Returns a randomly generated number.
40+
*
41+
* @params
42+
* minimum (int): Lowest possible value for the number generation.
43+
* maximum (int): Highest possible value for the number generation.
44+
*
45+
* @return
46+
* int: Randomly generated number.
47+
*/
3848
int randint(int minimum, int maximum) {
3949

4050
return _core.Random.randint(minimum, maximum)
@@ -50,10 +60,10 @@ int randint(int minimum, int maximum) {
5060
*
5161
* @params
5262
* iterable (list): List to return a random choice from.
53-
* choices (list): Choices to return form the iterable. If choices is bigger than the iterable, the remaining values will be skipped.
63+
* choices (list): Number of choices to return form the iterable. If choices is bigger than the iterable, the remaining values will be skipped.
5464
*
5565
* @return
56-
* Any: Chosen object(s) from the iterable.
66+
* Any: Random value(s) from the iterable.
5767
*/
5868
function choices(list iterable, int choices = 1) {
5969
return _core.Random.choices(iterable, choices)

Modules/_core/Math.py

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
"""
2+
I Language Math module.
3+
Version: 0.1.0
4+
5+
Copyright (c) 2023-present ElBe Development.
6+
7+
Permission is hereby granted, free of charge, to any person obtaining a
8+
copy of this software and associated documentation files (the 'Software'),
9+
to deal in the Software without restriction, including without limitation
10+
the rights to use, copy, modify, merge, publish, distribute, sublicense,
11+
and/or sell copies of the Software, and to permit persons to whom the
12+
Software is furnished to do so, subject to the following conditions:
13+
14+
The above copyright notice and this permission notice shall be included in
15+
all copies or substantial portions of the Software.
16+
17+
THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS
18+
OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
22+
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
23+
DEALINGS IN THE SOFTWARE.
24+
"""
25+
26+
###########
27+
# IMPORTS #
28+
###########
29+
30+
import math
31+
from typing import (
32+
Final,
33+
)
34+
35+
36+
#############
37+
# CONSTANTS #
38+
#############
39+
40+
Infinite: Final[float] = float("inf")
41+
42+
43+
#########
44+
# ROUND #
45+
#########
46+
47+
def _round(number: float) -> int:
48+
"""Rounds a number.
49+
50+
:param number: Number to round.
51+
:return: Rounded number.
52+
"""
53+
54+
return round(number)

Modules/_core/Random.py

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
"""
2+
I Language Random module.
3+
Version: 0.1.0
4+
5+
Copyright (c) 2023-present ElBe Development.
6+
7+
Permission is hereby granted, free of charge, to any person obtaining a
8+
copy of this software and associated documentation files (the 'Software'),
9+
to deal in the Software without restriction, including without limitation
10+
the rights to use, copy, modify, merge, publish, distribute, sublicense,
11+
and/or sell copies of the Software, and to permit persons to whom the
12+
Software is furnished to do so, subject to the following conditions:
13+
14+
The above copyright notice and this permission notice shall be included in
15+
all copies or substantial portions of the Software.
16+
17+
THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS
18+
OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
22+
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
23+
DEALINGS IN THE SOFTWARE.
24+
"""
25+
26+
###########
27+
# IMPORTS #
28+
###########
29+
30+
import random
31+
from typing import (
32+
Any,
33+
List,
34+
)
35+
36+
37+
###########
38+
# RANDINT #
39+
###########
40+
41+
def randint(minimum: int, maximum: int) -> int:
42+
"""Generates a random number.
43+
44+
:param minimum: Lowest possible value.
45+
:param maximum: Highest possible value.
46+
:return: Random number between minimum and maximum.
47+
"""
48+
49+
return random.randint(minimum, maximum)
50+
51+
52+
###########
53+
# CHOICES #
54+
###########
55+
56+
def choices(iterable: List, choices: int = 1) -> Any:
57+
"""Returns a random value from a given list.
58+
59+
:param iterable: List to return a random value from.
60+
:param choices: Number of choices to return form the iterable. If choices is bigger than the iterable, the remaining
61+
values will be skipped.
62+
:return: Random value(s) from iterable.
63+
"""
64+
65+
if choices == 1:
66+
return random.choice(iterable)
67+
else:
68+
return random.choices(iterable)
69+
70+
###########
71+
# SHUFFLE #
72+
###########

Modules/_core/__init__.py

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
"""
2+
I Language core.
3+
Version: 0.1.0
4+
5+
Copyright (c) 2023-present ElBe Development.
6+
7+
Permission is hereby granted, free of charge, to any person obtaining a
8+
copy of this software and associated documentation files (the 'Software'),
9+
to deal in the Software without restriction, including without limitation
10+
the rights to use, copy, modify, merge, publish, distribute, sublicense,
11+
and/or sell copies of the Software, and to permit persons to whom the
12+
Software is furnished to do so, subject to the following conditions:
13+
14+
The above copyright notice and this permission notice shall be included in
15+
all copies or substantial portions of the Software.
16+
17+
THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS
18+
OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
22+
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
23+
DEALINGS IN THE SOFTWARE.
24+
"""
25+
26+
###########
27+
# IMPORTS #
28+
###########
29+
30+
from Modules._core import (
31+
Math,
32+
Random,
33+
)

0 commit comments

Comments
 (0)