User:Maxdamantus/lang

Description
This is just a page I'm using to dump my ideas for this language I'm designing + making. It has some ideas and example syntax. If you're actually reading this, and see something that doesn't really make sense, uhh.. Put it under the "Comments" subheading. I'll try fixing it, or explaining why it does work.

Comments
Use the talk/discussion page to discuss stuff about the language or suggest things.. Find stuff that makes no sense!

About
This is a conceptual language. It has no name yet, if you think of one, just put it in the comments. It has functions, each function being a single expression (so therefore one parse tree for each function (internally)). Because of this, it has no expression separators (ie, semicolons in C, JS, etc). It will have most operators that are in C however, plus some more (eg, a loop operator, since you usually can't do that without recursion, using single expressions).

Semicolon supplicant
The comma operator will probably be the most used operator in my language. As ifs/loops will be implemented as expressions, it can be used to separate them (but making a new bigger expression)

if/else supplicant
As mentioned earlier, most C operators will be implemented. Unlike C, there will be no values with incomplete types, so anything can be used as a statement. A common if emulation in C is the && operator. This could be useful for a bunch of ifs, but what about else? This could be one way of implementing if/else.. But pretty nasty. How about using the ternary operator instead? Alright. In my opinion, it's neater than the && method. But what about else if? In this example, I'll make some use of the comma operator, described earlier. So comparing to C, you could say the equivalent of if(expr)( is (expr)?{, while }else{ will be ):(, so therefore, }else if{ will become ):(expr)?( (Note that the brackets are not needed, unless you want to use something with lower precedence than the ternary operator (like the comma operator) - operators will have the same precedence as in C)

Functions
I want to make function syntaxes fairly simple, they will be implemented using {}.. {a + b} will be a function that returns a + b (from the scope that it was defined it - more to come about scoping etc) So a function will pretty much hold an expression, except the function has the scope from which it was defined in. I don't want to have to do really tricky escaping techniques to get out of statements in my language, so there will be a return operator (higher precedence than ternary operator, perhaps $ or % character) which will instantly return the value (it takes one right operand). Therefore, the following functions will have the same uses. And this one lets you jump out of an if-like statement So the second will never be evaluated. Because of what's under the objects heading, functions will probably be "objects" as far as the language its self is concerned.

Variables
Variables are referenced (before parse time) with names. The naming rules are like that of C/JS, ie /^[a-zA-Z_][a-zA-Z0-9_]*$/ Variables must be declared before they can be used (more on that next), and the scope works the same way as in JavaScript.

Declarations
This language will be loosely typed.. That meaning variables aren't assigned a type, and can hold whatever (there'll also be a function similar to JS's typeof (so it's a function rather than a language construct) in the standard library, which will determine a value's type). Variable declarations appear (optionally) preceding the function's opening curly brace. The declarations are comma-separated, and a group of declarations is surrounded by <>. There may be more than one group, for code organisation purposes. Dynamic scoping will be used, so a variable can exist with the same name as one on the higher scope, and these will not interfere with each other. There are also possible sigils on the variables as they're declared, which will define an initial value for the variable (otherwise it starts off as undefined (more on that later)). The sigils are: Note that the sigils only exist during the declaration. <@a> will declare a variable called "a" (which will contain the first argument passed to the function, assuming there was no declaration before). Here's an example.

Objects
Objects are actually associated arrays, but since functions have values, they can be stored in objects too (obj.method(param)). Initialisation of objects is between two square brackets, where there is no expression to the right (operand is not an expression). Only scalar values (numbers, strings) are allowed to be used for dereferencing objects, a[42] will be different to a["42"] (unlike PHP). Okay, the next bit is a bit crazy, because of its conceptual ideas. The a[b] syntax of arrays is expanded to use only function calls, meaning "dynamic objects" can be implemented using some functions - don't need an extension that provides the interface for this provided by extensions.. Crazy, eh? Okay, here's an example on actually making a dynamic object, which outputs sets/gets applied to the variables, but stores them in another, usual object, rather than actually changing the values used. Cool, eh? Bummer.. What about iterating?

More to dump from memory
More work on functions.. Variable declarions.. Loops..