Go to file
2024-11-21 10:33:34 +11:00
compile-expr Add compile-expr/ 2024-10-01 23:48:00 +10:00
examples Update README.md and more examples 2024-11-21 10:10:36 +11:00
plans Fix up do-while.md 2024-08-11 13:07:05 +10:00
ppp Move .ppp files into ppp/ directory 2024-08-11 11:35:49 +10:00
.gitignore Initial commit 2024-08-08 21:54:03 +10:00
dump_tokens.py Add dump_tokens.py 2024-10-01 19:02:20 +10:00
ppp_ast.py Make array literals explicitly state the element type 2024-10-01 14:30:05 +10:00
ppp_interpreter.py Change syntax for tuple indexing 2024-11-21 10:33:34 +11:00
ppp_lexer.py Add dump_tokens.py 2024-10-01 19:02:20 +10:00
ppp_object.py Clean up ppp_stdlib.py 2024-10-01 14:37:23 +10:00
ppp_parser.py Change syntax for tuple indexing 2024-11-21 10:33:34 +11:00
ppp_stdlib.py Clean up ppp_stdlib.py 2024-10-01 14:37:23 +10:00
ppp_tokens.py Add dump_tokens.py 2024-10-01 19:02:20 +10:00
ppp_types.py Make return a regular statement instead of an expression 2024-10-01 14:29:41 +10:00
ppp.py Initial commit 2024-08-08 21:54:03 +10:00
README.md Change syntax for tuple indexing 2024-11-21 10:33:34 +11:00
TODO.md Change syntax for tuple indexing 2024-11-21 10:33:34 +11:00

Python++

I created this language as a result of my frustrations with Python.

Currently my language is significantly worse than Python, and needs a lot of work before it can be considered functional.

Hello World

print("Hello, World!\n");

The following is a non-comprehensive list of stuff that currently works.

Assignment & Declaration

a: str = "Hello, World!\n";
b: int = 0;
c: str; // declared, but not yet assigned

Expressions

a: int = 34;
b: int = 35;
c: int = 1;
d: int = a + b * c; // with correct operator precedence

Structs

struct MyStruct {
	field1: int,
	field2: str,
	field3: SomeOtherStruct
}

my_struct: MyStruct = MyStruct.{
	field1=1,
	field2="Hello, World!",
	field3=SomeOtherStruct.{...} // whatever SomeOtherStruct takes
};

my_struct.field1 = 2;
plus5: int = my_struct.field1 + 5;

Enums

enum Weekday {
	Monday,
	Tuesday,
	Wednesday,
	Thursday,
	Friday,
	Saturday,
	Sunday
}

day: Weekday = Weekday.Tuesday;

match day in {
	case Monday    { ... } // handle Monday
	case Tuesday   { ... } // handle Tuesday
	case Wednesday { ... } // and so on...
	case Thursday  { ... }
	case Friday    { ... }
	case _         { ... } // default
}

or

enum IntResult {
	Ok(int),
	Err(Error)
}

result: IntResult = IntResult.Ok(5);

match result in {
	case Ok(num) { ... } // num is defined in this scope
	case Err(err) { ... } // similarly err is defined in this scope
}

Currently, polymorphic structs/enums are not supported, however I plan to eventually do so.

Functions

func random_number(seed: int) -> int {
	return 42;
}

my_random_number: int = random_number(69);

func min(a: int, b: int) -> int {
	if a < b return a;
	return b;
}

the_min: int = min(5, 10);

Arrays

numbers: int[] = [:int, 0, 1, 2, 3, 4]; // array literal must state element type (for now)
numbers = [:int, 2*x for x in numbers]; // list comprehension must also (for now)

For loops

// prints numbers 0-9
for i in range(0, 10) {
	print(int_to_str(i)+"\n");
}

While loops

a: int = 0;
while a < 10 {
	print(int_to_str(a)+"\n");
	a = a + 1;
}

Reading files

Importing

Assertions

Tuples

a: (int, str) = (0, "hello");
print(int_to_str(a.0)+" "+a.1+"\n");