diff --git a/README.md b/README.md index abf6337..f68a2cc 100644 --- a/README.md +++ b/README.md @@ -20,6 +20,15 @@ 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 ``` @@ -29,10 +38,10 @@ struct MyStruct { field3: SomeOtherStruct } -my_struct: MyStruct = MyStruct{ +my_struct: MyStruct = MyStruct.{ field1=1, field2="Hello, World!", - field3=SomeOtherStruct{...} // whatever SomeOtherStruct takes + field3=SomeOtherStruct.{...} // whatever SomeOtherStruct takes }; my_struct.field1 = 2; @@ -55,12 +64,12 @@ enum Weekday { day: Weekday = Weekday.Tuesday; match day in { - case Monday do { ... } - case Tuesday do { ... } - case Wednesday do { ... } - case Thursday do { ... } - case Friday do { ... } - case _ do { ... } // default + case Monday { ... } // handle Monday + case Tuesday { ... } // handle Tuesday + case Wednesday { ... } // and so on... + case Thursday { ... } + case Friday { ... } + case _ { ... } // default } ``` or @@ -73,8 +82,8 @@ enum IntResult { result: IntResult = IntResult.Ok(5); match result in { - case Ok(num) do { ... } // num is defined in this scope - case Err(err) do { ... } // similarly err is defined in this scope + 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. @@ -98,10 +107,28 @@ 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 diff --git a/examples/numbers.ppp b/examples/numbers.ppp new file mode 100644 index 0000000..3527ba5 --- /dev/null +++ b/examples/numbers.ppp @@ -0,0 +1,5 @@ +numbers: int[] = [:int, 0, 1, 2, 3, 4, 5]; + +numbers = [:int, 2*x for x in numbers]; + +for number in numbers print(int_to_str(number)+"\n"); \ No newline at end of file diff --git a/examples/person.ppp b/examples/person.ppp new file mode 100644 index 0000000..e546835 --- /dev/null +++ b/examples/person.ppp @@ -0,0 +1,11 @@ +struct Person { + age: int, + name: str +} + +my_person: Person = Person.{ + age=50, + name="Hello, World" +}; + +print(int_to_str(my_person.age)+" "+my_person.name+"\n"); \ No newline at end of file diff --git a/examples/weekday.ppp b/examples/weekday.ppp new file mode 100644 index 0000000..04a5870 --- /dev/null +++ b/examples/weekday.ppp @@ -0,0 +1,21 @@ +enum Weekday { + Monday, + Tuesday, + Wednesday, + Thursday, + Friday, + Saturday, + Sunday +} + +day: Weekday = Weekday.Monday; + +match day { + case Monday print("It's Monday!\n"); + case Tuesday print("It's Tuesday!\n"); + case Wednesday print("It's Wednesday!\n"); + case Thursday print("It's Thursday!\n"); + case Friday print("It's Friday!\n"); + case Saturday print("It's Saturday!\n"); + case Sunday print("It's Sunday!\n"); +} \ No newline at end of file