Jump to content
  • Advertisement
Sign in to follow this  
Shrinker

ideas for language constructs in a c-style language

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

If you intended to correct an error in the post then please contact us.

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 this post


Link to post
Share on other sites
Advertisement
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 this post


Link to post
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).

Nah, they already work well.

Quote:
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.

Nono, not missing out any of that fun :P

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!