• 15
• 15
• 11
• 9
• 10

# ideas for language constructs in a c-style language

This topic is 3068 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

I like function pointers and also prefer a tuple syntax over the boring old struct syntax, so this is part of my language:
void test1(int x)
{
}

(function<void(int)> func, int context) test2(int context)
return (test1<int>, context);

(function<void(int)> func, int context) test3()
return test2(5);

void main()
test3().func(test3().context);

test1 is called with x = 5. As I just got that working properly, I just wanted to share :P Yes, {} can be omitted at function level if there is only one statement.

##### Share on other sites
the problem is you need the keywords (like 'if') to give your compiler/interpretor a clue as to what the statement is doing (unless you ALWAYS have a test clause followed by a list of action clauses (or a bracketed set). Simple nesting repeating the same limitation ( how do you handle/delineate an optional 'else' ????)

Of course that messes up other statement types (loops with pre and post tests).

That could be OK if your use only requires the simpler control constructs but now its hardly c-like.

If you are lucky enough that thats all you need it will save you from the fun of the jump addressing mechanisms needed for else clauses and gotos (still very usesful despite instructors bemoaning their existance). Function definition with ghah!! parameters and call stacks add more fun.

If you go far enough reinventing the wheel you can also consider using an imbedded C like TinyC ( http://bellard.org/tcc/ ) which might save you alot of work (though you would be back using 'if' keywords again).

##### Share on other sites
Quote:
 the problem is you need the keywords (like 'if') to give your compiler/interpretor a clue as to what the statement is doing (unless you ALWAYS have a test clause followed by a list of action clauses (or a bracketed set). Simple nesting repeating the same limitation ( how do you handle/delineate an optional 'else' ????)

Hey, it's either a single statement OR a block of statements in curly braces as the function body, it works well. I already got the common control structures and loops covered too. Associating an optional else with the right if is already done before, in the parser.

I had to live with one limitation to my syntax though: Having at least two elements in a tuple type or expression was necessary because I just couldn't get it done clean otherwise.

Quote:
 Of course that messes up other statement types (loops with pre and post tests).