Based off of Jonathan Blow's ideas about a new programming language for games (check them out on yt if you haven't, he has some really good ideas), I decided out of personal interest to try to write a compiler for a new language myself. What I have so far is working parser and AST-creation, but I need some input on a few things.
The syntax for variable declaration and assignment is
1 2 3
|
a : Int;
b : Int = 3;
c := 3; //type inference
| |
I like this syntax, but when trying to apply it to function declaration (since I want functions to be declared the same way as variables) I'm having some trouble getting the syntax down. What I have so far is
|
func := (a : Int) -> Int { ... }
| |
where "func" is a function that takes an argument 'a' of type Int, and returns an Int. This way, because function definitions are basically expressions, I can easily treat lambdas etc:
|
passFuncToFunc((x : Int) -> Int { ... } );
| |
But this changes the syntax from the usual variable declaration (what should be between ':' and '='?). So I thought I might change it to
|
func : (a : Int) -> Int = { ... }
| |
But now function definitions are no longer expressions. What could be a good way to acommodate both of these demands? I.e. that function defs are expressions, but that I can still define their types as a mapping from arguments to output.