Jump to content


Writing a custom language?


36 replies to this topic

#1 cypher543

    Member

  • Members
  • PipPip
  • 74 posts

Posted 04 August 2006 - 01:50 PM

I like game development. Really, I do. But I find sitting in front of a computer and programming in C/C++ all day very boring. So, here's what I would like to do...

I would like to write my own compiler using C that would allow me to write games using a custom BASIC-like language. Of course, it wouldn't be exactly like BASIC. It would include classes, inline assembly, etc. This same approach was taken by Naughty Dog for their Jak and Daxter series of games. They created a custom LISP variant called GOAL (Game Oriented Assembly Lisp).

I know that I would need to do what I originally said I didn't want to do (sitting in front of a computer all day and programming in C/C++), but I'm willing to do that if it means I can use a powerful BASIC variant to program my games.

So, what exactly should I start with? Should I use Bison to parse the language? Does anyone know of a good compiler design tutorial? Is this even a good idea? :P

#2 eddie

    Senior Member

  • Members
  • PipPipPipPip
  • 751 posts

Posted 04 August 2006 - 02:13 PM

Personally, I wouldn't do it.

You'll spend more time debugging your compiler than you will be making games, in my opinion.

If you were to do it, I'd take a look at something like ANTLR, bison/flex for the parsing. Perhaps Boost::Spirit, but I'd probably favour the earlier two.

#3 cypher543

    Member

  • Members
  • PipPip
  • 74 posts

Posted 04 August 2006 - 02:17 PM

Quote

You'll spend more time debugging your compiler than you will be making games, in my opinion.
You're right. But, this new language would be available for everyone to use. So my relentless debugging would help a lot of newbies who want to get into game development (yes... alright... I'm talking about myself here) :P

#4 eddie

    Senior Member

  • Members
  • PipPipPipPip
  • 751 posts

Posted 04 August 2006 - 02:23 PM

Community projects are great, and if you're truly dedicated to writing this language, then perhaps it has a chance. Just keep in mind that the freely-available-software world doesn't need another project that's just going to get orphaned.

That said, have you looked at any of the other 'starter' programming languages targetted at game programming?

BlitzBasic? DarkBasic? PyGame?

If not, I highly suggest you do and see if any of those fill your needs. If they don't, and you decide to go ahead with your own language, I suggest filling a niche that they don't, otherwise you might find it harder to get a community together when you'll be competing against these larger, established "easy-to-program" languages.

Disclaimer: I've never used any of those, but we do get a lot of posts from people who do, who are mostly newbies.

#5 cypher543

    Member

  • Members
  • PipPip
  • 74 posts

Posted 04 August 2006 - 02:35 PM

I've never tried BlitzBasic, but I do have some comments on DarkBasic and PyGame:

For me, DarkBASIC seems limiting. I don't know why, but when I open up that ugly IDE, I just get the feeling that I'm in a box. With my language, I want it to be simple enough for a newbie, but powerful enough for the average programmer who's had a few years of experience.

PyGame is nice, but Python is not my ideal language for writing games. I don't like that just anyone can edit the source. Sure, it might be ok for some games that I just let people do what they want with, but Python isn't for commercial games. I could use py2exe, but the programs it puts out are for Windows only and tend to be very large.

My main design hurdle right now is the decision on usability. Should the language be designed for games alone? Or should I include other functions/libraries that make it suitable for everyday application development? To me, designing it for game programming only would be slightly easier. But allowing general application development would make it available to a wider range of programmers.

What does everyone think?

#6 Nodlehs

    Valued Member

  • Members
  • PipPipPip
  • 152 posts

Posted 04 August 2006 - 03:41 PM

I think it is a colossal waste of time, and here are my reasons why.

1. Have you written a compiler before?
2. Have you designed a language before?
3. If you want to program games, why waste at the minimum a year of your time, not programming games?
4. The more powerfull you make the language, without 'limiting' it as you say, you induce complexity, which in turns, makes it harder to use, which in turn, doesn't make it newbie friendly.
5. What is so boring about C/C++ that would make your language such a joy to use?

I could go on, but I think I nailed a few key points there. I don't want to be a downer on your idea, but it just seems far fetched, and not really worth your time.

#7 Kenneth Gorking

    Senior Member

  • Members
  • PipPipPipPip
  • 939 posts

Posted 04 August 2006 - 07:03 PM

Nodlehs said:

I think it is a colossal waste of time, and here are my reasons why.

1. Have you written a compiler before?
2. Have you designed a language before?
3. If you want to program games, why waste at the minimum a year of your time, not programming games?
4. The more powerfull you make the language, without 'limiting' it as you say, you induce complexity, which in turns, makes it harder to use, which in turn, doesn't make it newbie friendly.
5. What is so boring about C/C++ that would make your language such a joy to use?

I could go on, but I think I nailed a few key points there. I don't want to be a downer on your idea, but it just seems far fetched, and not really worth your time.

Under no circumstances do I think it's a collosal waste of time! Writing a compiler and virtual machine was the most fun coding I have ever done, and I encourache everybody to at least try it out! Especially in these times where every new game seems to have some form of scripting...

In response to 1 and 2: Peroxide script tutorials is where I learned the trade. The language is not the most complex, but it does work, and the framework is easy to expand. His 'hello world' example looks like this:
// A 'hack' to print a string from script.. send it via a 'setint' on the player as the name..

void printLog(string msg)

{

	setint(TYPE_PLY, msg, 2, 0);

}


program helloWorld trigger_on_init

{

	printLog("Hello world from PxdScript!");

}

and my expanded test script-code looks like this (built on his framework):

//

// The base class of all actors that can be controlled by players or AI,

// and collide with the world.

//

class Character expands Actor

{

	// The character mesh (property means its a c++ variable, but can be changed by the scripts)

	property Mesh mesh;


	// The linked list of items being carried

	Inventory inventory;


	// The weapon currently in use

	Weapon currentWeapon;


	// TODO: Add functions for moving the character

	// TODO: Add events for other characters entering/leaving view

	// TODO: Add events for when sounds are heard


	// Spawned event. Called by the engine when this character is created.

	event Spawned

	{

		SetMesh("models/characters/test2.mesh");

	}


	// Touch event. Called by the engine when this actor touches another actor (overridden from class Actor)

	event Touch(Actor other)

	{

		//super.Touch(other);

		if(class(other) == class<Inventory>)

			OnPickup( (Inventory)other );

	}


	// Play animation on current mesh (interface means it's an internal c++ function, callable from scripts)

	interface bool PlayAnimation(string filename);


	// Attach/detach an actor to a bone in the mesh

	interface bool AttachToBone(Actor attachment, string boneName);

	interface bool DetachFromBone(Actor attachment);


	// This is called when a character collides with an inventory item

	void OnPickup(Inventory item)

	{

		// TODO: Should have some rules for this...

		// if(CanPickup(item))

		{

			Log("Picked up " + item.GetName());

			AddToInventory(item);

		}

	}


	// Adds a new item to the inventory

	void AddToInventory(Inventory item)

	{

		if(inventory == none)

			inventory = item;

		else

			inventory.Add(item);

	}


	// Switch to the next weapon

	bool SwitchToNextWeapon()

	{

		Weapon newWeapon;


		// If the character already has a weapon, use it as the base

		if(currentWeapon != none)

		{

			newWeapon = currentWeapon.Find( class<Weapon> );

			if(newWeapon != none)

			{

				currentWeapon = newWeapon;

				return true;

			}

		}


		// Use inventory as base

		newWeapon = inventory.Find( class<Weapon> );

		if(newWeapon == none)

			return false;


		currentWeapon = newWeapon;

		return true;

	}



	// Remove an inventory item from the list.

	// Returns false if the item was not found.

	bool RemoveFromInventory(Inventory inv)

	{

		if(inventory == none)

			return false;


		if(inventory == inv)

		{

			inventory = inventory.next;

			return true;

		}

		else

		{

			if(inventory.next != none)

			{

				for(Inventory i = inventory; i != none; i = i.next)

				{

					if(i.next == inv)

					{

						i.next = i.next.next;

						return true;

					}

				}

			}


			return false;

		}

	}

}


This took about two moths to do, and that was while building the engine on the side.

I do not agree that making a language too powerful will make it complex, on the contrary. Making a powerful script language is all about removing the low-level stuff from the user, and make simpler high-level interfaces that they can use instead. A good example of this is UnrealScript's networking architecture, where instead of having to write code for transferring data to and from the server, they simply mark what is to be sent, and what conditions have to be met for the transfer to occur. The compiler code to do this doesn't even have to complex, just flag class-members as stated in the scripts, and have the runtime send it.

I too would also like to now what is so boring about C++? I use it all the time, and I love it!
"Stupid bug! You go squish now!!" - Homer Simpson

#8 cypher543

    Member

  • Members
  • PipPip
  • 74 posts

Posted 04 August 2006 - 07:09 PM

[1] No, but I have to start somewhere. >_>
[2] No, but again, I have to start somewhere
[3] Because, as I said, I don't like to write games in C. I like to write other stuff in C, just not games.
[4] Well, I'm not going to make it completely easy. That would just be another BASIC clone. I think Classes, trash collection, inline assembly, etc would be a good addition to the traditional BASIC language. But, newbies wouldn't have to use those features if they didn't want to. By "limiting", I was speaking in terms of the feature set.
[5] When I'm writing a game, I like to think from the design side. C/C++ is just not the language for me when I try to make a game. If I had something simple, yet powerful, I'm sure making games would be a lot easier for me.

About my time... honestly, I have a ton of it. I've been thinking for the last 3 days about something I should work on. A compiler finally popped into my head and I decided to give it a try. Besides, who says you have to use it? Or anyone else? I'm really making it for my benefit because I think it would help me in the long run. If other people like it and want to use it, more power to them. When you say it's a waste of time, you're speaking from your point of view. But, here's the thing... you're not making the compiler. I am. So, it's really up to me whether it's a waste of time or not.

#9 eddie

    Senior Member

  • Members
  • PipPipPipPip
  • 751 posts

Posted 04 August 2006 - 07:13 PM

Half of the things I end up coding turn into wastes of time. That said, they're wicked learning experiences.

I wrote my own compiler tools for some work-related language stuff, and it was a *pain*. That said, it was super interesting, and it helped me understand why gcc/cl do the things they do, and it was very rewarding.

I won't rain on your parade, but just know that it *can* be very difficult. I do wish you luck however.

#10 SamuraiCrow

    Senior Member

  • Members
  • PipPipPipPip
  • 459 posts

Posted 04 August 2006 - 07:15 PM

You could join an existing open-source Basic compiler project like Mattathias Basic which is a freeware sequel to Amos Basic on the old Amiga computers and an open-source counterpart to DarkBasic. We are aiming to make it cross-platform compliant so that it will still generate code for the next generation PowerPC-based Amigas as well as for PC. If you're interested you might like to join the mailing list and read up on the progress first.

If you're looking for something closed-source that will only work on Linux, Mac, and PC, you're better off looking into buying BlitzMax instead. It's object-oriented like Mattathias but broke the backward-compatability mold with their Amiga version to better support the PC.

#11 jkleinecke

    New Member

  • Members
  • PipPip
  • 27 posts

Posted 04 August 2006 - 08:50 PM

A custom language doesn't have to take a ton of time. I used Flex++ and Bison++ to generate my own compiler, and with no previous compiler building experience I have my own language in less than 3 months time.

#12 Nodlehs

    Valued Member

  • Members
  • PipPipPip
  • 152 posts

Posted 04 August 2006 - 09:12 PM

cypher543 said:

[3] Because, as I said, I don't like to write games in C. I like to write other stuff in C, just not games.

Fair enough, you don't like that tool for that job.

cypher543 said:

[4] Well, I'm not going to make it completely easy. That would just be another BASIC clone. I think Classes, trash collection, inline assembly, etc would be a good addition to the traditional BASIC language. But, newbies wouldn't have to use those features if they didn't want to. By "limiting", I was speaking in terms of the feature set.

Agreed, beginner developers would not need to use the more advanced features. But to create anything really deep, you would need to use those features. You can make it easier to interface with low level operations, agreed. I just don't see why you don't create a C++ class to do that for you, instead of an entirely new language. But, as you said, you don't like using C to program games in.

cypher543 said:

[5] When I'm writing a game, I like to think from the design side. C/C++ is just not the language for me when I try to make a game. If I had something simple, yet powerful, I'm sure making games would be a lot easier for me.

From what you are saying, it sounds as if you are an experienced programmer, expecially if you are willing to takle creating a new language(with the feature set you have described). So, why are you finding it so difficult programming in C/C++ for games? What makes a game so much harder than other apps you have written? The design side should be very code non specific. You should never even talk about what language you are going to use in your game design. The eventual implementation of your design will have tons to do with C++, not the creating of the design itself.

cypher543 said:

About my time... honestly, I have a ton of it. I've been thinking for the last 3 days about something I should work on. A compiler finally popped into my head and I decided to give it a try. Besides, who says you have to use it? Or anyone else? I'm really making it for my benefit because I think it would help me in the long run. If other people like it and want to use it, more power to them. When you say it's a waste of time, you're speaking from your point of view. But, here's the thing... you're not making the compiler. I am. So, it's really up to me whether it's a waste of time or not.

Agreed, it is your time, you can do with it as you please. But you also asked on a forum what people though of your idea, your time. Don't ask if you don't want answers. I don't think I was being rude in saying I thought it was a waste of time given your target goals, which is game programming, not tools programming(from the information you provided). If you indeed do feel that you are more interested in programming a language than go for it, it sounds like a great challange, and a blast. But if your goal is to program games? Then no, this is not worth your time.

Kenneth Gorking said:

I do not agree that making a language too powerful will make it complex, on the contrary. Making a powerful script language is all about removing the low-level stuff from the user, and make simpler high-level interfaces that they can use instead.

From what I gathered he wasn't talking about a simple scripting language, he was talking a fully featured programming language, his feature set seemed to indicate that as well. As I said above yea, you can reduce the complexity by making higher level interfaces to low level stuff, but in the end, your going to need to do more than basic read and writes, especially when it comes to games programming. Like inline assembly, he wants that, how is that easier in his proposed language than in C++?

Cypher, in the end, it comes down to, do you want to program games right now, or later? If you want to program games right now, then this is a waste of your time, as you won't be programming games for quite a while(going under the assumption this is a fully featured language, not just a limited feature set scripting language). If you can wait, and you really like the idea of your proposed language, then go for it, it sounds like it would be a good time.

#13 monjardin

    Senior Member

  • Members
  • PipPipPipPip
  • 1033 posts

Posted 05 August 2006 - 01:17 AM

cypher543 said:

They created a custom LISP variant called GOAL (Game Oriented Assembly Lisp).

I'd just like to add that creating a variant of Lisp is a whole different ball-game than creating a completely different language compiler. Search around for LISP and "Domain Specific Languages". Lisp programmers tend to morph the language to suite there needs, rather than create a whole new language.

I'm not trying to dissuade you, but I don't think the Jak and Daxter's guys went the the trouble of a lexer and parser. They probably used the Lisp compiler and directly editited the code tree with macros.
monjardin's JwN Meter (1,2,3,4,5,6):
|----|----|----|----|----|----|----|----|----|----|
*

#14 cypher543

    Member

  • Members
  • PipPip
  • 74 posts

Posted 05 August 2006 - 02:36 AM

Thanks for your opinions, guys!

Quote

I don't think I was being rude in saying I thought it was a waste of time given your target goals, which is game programming, not tools programming(from the information you provided).
I'm sorry if I sounded annoyed. I didn't think you were being rude, at all. My target goal isn't really game programming, it's making game programming easier for myself and for people like me who tend to not get the whole process.

Anyway, I think what I'm going to do is just write the basic compiler, then expand it with an OpenGL library. That way, people can write their own engines for it. Maybe I'll work on my own, that way newbies have something to work with. I know this is going to take awhile, but I'm so completely bored right now, and I need some exciting to do. :P

#15 Nodlehs

    Valued Member

  • Members
  • PipPipPip
  • 152 posts

Posted 05 August 2006 - 05:05 AM

I would say it would be well worth your time then, since you seem to want to focus more on a game language, rather than game development itself.

Before you begin, it would be good to check out what some of the other game programming scripting languages do, and check on their forums to see what people do/don't like. That would give you a good idea of possibly where to start when implementing a feature set.

#16 snk_kid

    New Member

  • Members
  • PipPip
  • 16 posts

Posted 05 August 2006 - 08:05 AM

If you want to start some where you should buy a thew good books on the subject, there is no substitute for this as online resources are generally sparse and/or poor. Tutorials are not enough, you need to understand theory aswell, i suggest starting here.

Lastly do yourself a favour and use a more appropriate programming language for this such as SML, O'Caml, or haskell.

#17 Alex

    Valued Member

  • Members
  • PipPipPip
  • 152 posts

Posted 05 August 2006 - 10:02 AM

snk_kid: you keep amazing me with good links about language ponderings..I had almost given up on finding those..there really isn't much good stuff(or it's hard to find) dealing with "new" languages..
thx

#18 cypher543

    Member

  • Members
  • PipPip
  • 74 posts

Posted 05 August 2006 - 02:22 PM

Quote

Lastly do yourself a favour and use a more appropriate programming language for this such as SML, O'Caml, or haskell.
I would... if I knew them. It's taken me a very long time to get used to C. Besides, I think Flex/Bison look very cool, and I doubt they generate lexers and grammar for SML, O'Caml, or haskell.

#19 snk_kid

    New Member

  • Members
  • PipPip
  • 16 posts

Posted 05 August 2006 - 03:36 PM

cypher543 said:

I would... if I knew them. It's taken me a very long time to get used to C.

These languages are more declarative which is one of the points so they shouldn't take any where near as long as C/C++ besides SML & O'Caml allow you to mix imperative code with functional.

The only thing which may have a slight learning curve (which depends on yourself) is learning functional concepts/practices (i don't mean procedural, not the samething) such as

  • functions are values too (there first-class entities)
  • higher-order functions (functions which take or return functions because "functions are values too")
  • lamdba functions/expression (anonymous/unnamed functions)
  • The recursive operators (patterns of recursion and higher-order functions) such as folds, unfolds, iterate, map, zip, etc, etc.
  • Currying and/or partial application (not paritial evalution), function composition.

Once you've got your head wrapped around these concepts the rest will just be learning syntax which is 1 a day job.

cypher543 said:

Besides, I think Flex/Bison look very cool, and I doubt they generate lexers and grammar for SML, O'Caml, or haskell.

Each of those language have there own versions of lex & yacc (which is what flex & bison desecend from). C is just awful for compiler development even when you have tools to help out. Don't let the fact that GCC is written in C make you think otherwise because it really is a bad idea and it doesn't mean you can't write a GCC front-end in any language because you can so it's all mute.

Don't use the wrong tool for the job.

#20 SigKILL

    Valued Member

  • Members
  • PipPipPip
  • 200 posts

Posted 05 August 2006 - 04:26 PM

The first place to start when creating a custom language (IMO) is the dragon book (it's proper name is "Compilers: Principles, Techniques and Tools"). It is the classical reference, and doesn't cover new or really advanced stuff. You might want to look at "Advanced Compiler Design and Implementation" by Muchnick, "Engineering a Compiler" by Cooper and "Programming Language Pragmatics" by Scott, but I don't know these books. Then there is alot of stuff on the .net.





1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users