Jump to content
  • Advertisement
Sign in to follow this  
Tocs1001

Creating a Scripting Language with YACC?

This topic is 4437 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

Well My "MMORPG" could use a decent scripting language to easily add some content and give some of my not so computer savy friends a chance to help out =). The scripting language will be able to Give specail features to NPC's allowing some out of the rote standard NPC conversation/kill the NPC I could script special pathes and Specail Attacks. As well as script things like Traps and Special Items that arnt like potions or food or a weapon. Its not to create the game but to embelish it and add some specail features that would normally take some editing of the games source code. but to the question... I was working on the logic involved when writing a script parser, but my dad told me about a thing called YACC (Yet Another Compiler Compiler) and how I could create through a special programming language to create a set of "rules" or "Grammer" for a language and it would create a c++ file to parse it. He didnt have much time to explain it and he hasnt used it but he remembers it from a book he read with it. Question is.. Is this what i want? I've been looking at some YACC tutorials it doesnt really seem to be it Could anyone give some pointers about it and if I'm drifting the wrong way. I finished how i'm going to parse the script if YACC doesnt work out.

Share this post


Link to post
Share on other sites
Advertisement
I could also suggest, in the same vein, Bison (and flex for lexing). Of course, you might be able to go for something much simpler if your language has certain properties (assembler: you don't need more parsing than ifstream provides, XML: use an XML parser, Python: use boost, Lua: use the default parser etc)

Share this post


Link to post
Share on other sites
Consider using an existing scripting language, such as Lua. Whether you write your own language or not, you'll still spend a good chunk of time integrating that language in a usefull fashion with your game. By using an existing language, you remove a lot of extra work, and you get something that is probably far more stable and useful than what you'd create yourself as a first attempt.

Also, in addition to Lex/Yacc and the various ports thereof, you may want to take a look at ANTLR, which tends to generate code that is much more maintainable (in my opinion).

Share this post


Link to post
Share on other sites
Well I dont know much about scripting so its a humble beginning if i use an existing scripting language how do i create my own functions to be used in the scripts if their already made? (the most experience with scripting i have is Second Life lol)

I have a list of functions that scripts should be able to use like GiveExp (int Ammount, int SkillID) is one I want to be able to call that in my script if i use a premade scripting language can i do that? I'm aiming for a C like simplified language that is read "compiled" when the script gets triggered. I wrote out a flow chart of how to write the parser for my script.

Basically it will look kinda like this

Func Main
{
GiveItem (ITEM_ID_SWORD,1);
SpawnNPC (MONSTER_ID_GOBLIN, <0,0,0>);
SayDialog ("Use the sword to kill the Goblin");
}

and loops would just be

Loop (3)
{

}
would loop 3 times.

I am using XML to give definitions for Weapon Stats, Potion Effects, Zone Details like where things are, and other things that fit within the norm of a RPG things that dont need some special scripting. But to create various things like A Portal which a demon comes out Causing some damage as he comes through or even coding special AI for a boss would be done through the script

The problem is I'm scratching my head with all the YACC tutorials, i wish i could use it but I dont quite understand it. Most of them address YACC working with something called Lex and its very confusing.

I guess to say should i learn to use the YACC or similar thing or should i just write my own OO parser with just straight c++ to get it done...

PS ANTLR it seems to have a better base of documentation, its intro didnt leave me scratching my head =P

[Edited by - Tocs1001 on July 21, 2006 1:05:48 PM]

Share this post


Link to post
Share on other sites
Quote:
Original post by jpetrie
Consider using an existing scripting language, such as Lua. Whether you write your own language or not, you'll still spend a good chunk of time integrating that language in a usefull fashion with your game. By using an existing language, you remove a lot of extra work, and you get something that is probably far more stable and useful than what you'd create yourself as a first attempt.

Also, in addition to Lex/Yacc and the various ports thereof, you may want to take a look at ANTLR, which tends to generate code that is much more maintainable (in my opinion).



I can only second this post,

sadly that none of my favorite scripting languages workes on my current installation Suse10.0 x86_64
squirrel with sqplus creates a segfault and angelcode seems to be pretty unportable to 64 bit platforms, it doesn t work either, I simply can t bind a function and all function calls always return false :(

The only option is to write my own scripting language now. With bytecode of course, this allows the construction of a language independently from the script processor the Virtual Machine

Share this post


Link to post
Share on other sites
Quote:
Original post by Basiror
*snip* this allows the construction of a language independently from the script processor the Virtual Machine


well, theoretically, yes. Unless you plan on creating a front end/back end combination, with an intermediate representation of your code, then this isn't really feasible. You'll need to know the opcodes and operands of the vm's byte-code language, which will be closely tied with how the Virtual Machine works.

Share this post


Link to post
Share on other sites
Quote:
Original post by daerid
Quote:
Original post by Basiror
*snip* this allows the construction of a language independently from the script processor the Virtual Machine


well, theoretically, yes. Unless you plan on creating a front end/back end combination, with an intermediate representation of your code, then this isn't really feasible. You'll need to know the opcodes and operands of the vm's byte-code language, which will be closely tied with how the Virtual Machine works.


a wa? You lost me, I'm just gonna write a parser in c++, it will be good learning as well... Although the Flipcode tut on Script Languages gave me more understanding of Lex and YACC

Share this post


Link to post
Share on other sites
Tocs1001: The big advantage is bytecode is you can compile your script and release them without releasing the actual source code to anyone.
Bytecode can look like this
32 bit per line
#########
addintref
address1-
address2-
addintval
----50050
----12334

... You should at least know assembler to do this efficiently

Writing an interpreter will probably work in most cases, we did this in our first semester at university, it was really fun :)


(yes I know thats a huge wast of memory, but it helps speeding up the VM on 32 bit systems)
Whats the block size of 64 bit systems? Also 32 bit? You can plug in the same memory)

[Edited by - Basiror on July 22, 2006 3:53:59 AM]

Share this post


Link to post
Share on other sites
Quote:
Original post by Basiror
Tocs1001: The big advantage is bytecode is you can compiler your script and release them without releasing the actual source code to anyone.


Compilering scripts sounds great! I want to learn how to compiler scripts! Sorry I couldn't help it [grin]

Share this post


Link to post
Share on other sites
Quote:
Original post by deathkrush
Quote:
Original post by Basiror
Tocs1001: The big advantage is bytecode is you can compiler your script and release them without releasing the actual source code to anyone.


Compilering scripts sounds great! I want to learn how to compiler scripts! Sorry I couldn't help it [grin]


Some people just can t contribute in a constructive manner.

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!