Archived

This topic is now archived and is closed to further replies.

TetsuoAkira22

Writing your own "language"

Recommended Posts

TetsuoAkira22    122
Lately, I''ve been coming up with some good ideas for AI - and one of those, requires me writing my own language... But I do not know a THING about file input/output and creating your own language (I.E.: an if statement in C++ is "if (statement)" - In my language, I''d like it to be "if statement" - notice, no ()''s). Basically - I need to learn how to import files, and search for certain keywords, do certain things once they are found, etc. - then do exactly what it says to do what it says. I.E. Lets say I have a test.ta2 file, that contains the following. --- IF user SAYS "hello" { SAY "Hello!" } --- I would need to read this file, and change "IF user SAYS "hello"" into "shello = "hello" If (shello == true) { printf("Hello!"); }" or something similiar. Can anyone help me in either fields? A tutorial, example, or anything of the like would be very useful. ----- Also: What about file encryption, reading encrypted files, etc.. (Like .pak files) - and reading certain folder groups (I.E. - all words the AI learns, go into a folder named "Words" - then from that they go into seperate folders "Verb", "adj", "noun", etc.) - from an encrypted file/ or just folder groups period.

Share this post


Link to post
Share on other sites
EL    122
You''re covering a lot of ground here, so I''ll give some keywords to use in Google (I can''t explain everything). What you''re trying to do is build an interpreter, to build an interpreter you''ll need a parser - think of it as transforming the input file with keywords etc. to entities you can handle and translate (like IF statement -> if(statement)).

I doubt you''ll have radically new ideas about AI, so why not try to some simple Prolog first. Then look into grammars (for building your language) and maybe, just maybe, then you will be ready to do what you''re planning here.

ps: a tutorial on reading or writing a file in C++ should be easy to find.

Share this post


Link to post
Share on other sites
civguy    308
Why do you need your own language? There are some good scripting languages out there, such as Python.

It would allow you to write code like this:

if user.says(''hello''):
print ''Hello!''

Share this post


Link to post
Share on other sites
TetsuoAkira22    122
quote:
Original post by EL
You''re covering a lot of ground here, so I''ll give some keywords to use in Google (I can''t explain everything). What you''re trying to do is build an interpreter , to build an interpreter you''ll need a parser - think of it as transforming the input file with keywords etc. to entities you can handle and translate (like IF statement -> if(statement)).

I doubt you''ll have radically new ideas about AI, so why not try to some simple Prolog first. Then look into grammars (for building your language) and maybe, just maybe, then you will be ready to do what you''re planning here.

ps: a tutorial on reading or writing a file in C++ should be easy to find.


interpreter! Thats the word! I wrote a small one in BASIC 8-9 years ago... I just forgot what the technical name was.

Thanks - and about the file input/output - cplusplus.com, about''s tutorial, cprogramming.com, and msdn don''t really cover reading only certain parts of the file (I''ve asked a few friends, and they gave me the keywords to search up on msdn because "Its hard to explain" - but they don''t exist in the msdn database)

Share this post


Link to post
Share on other sites
TetsuoAkira22    122
quote:
Original post by civguy
Why do you need your own language? There are some good scripting languages out there, such as Python.

It would allow you to write code like this:

if user.says(''hello''):
print ''Hello!''




I was thinking about using a pre-existing one - but I like a challenge, and I think it''d be fun to make my own... Plus I like having flexiblitiy - and writing a language how -=I=- want it.

Share this post


Link to post
Share on other sites
EL    122
quote:
Original post by TetsuoAkira22
quote:
Original post by EL
You''re covering a lot of ground here, so I''ll give some keywords to use in Google (I can''t explain everything). What you''re trying to do is build an interpreter , to build an interpreter you''ll need a parser - think of it as transforming the input file with keywords etc. to entities you can handle and translate (like IF statement -> if(statement)).

I doubt you''ll have radically new ideas about AI, so why not try to some simple Prolog first. Then look into grammars (for building your language) and maybe, just maybe, then you will be ready to do what you''re planning here.

ps: a tutorial on reading or writing a file in C++ should be easy to find.


interpreter! Thats the word! I wrote a small one in BASIC 8-9 years ago... I just forgot what the technical name was.

Thanks - and about the file input/output - cplusplus.com, about''s tutorial, cprogramming.com, and msdn don''t really cover reading only certain parts of the file (I''ve asked a few friends, and they gave me the keywords to search up on msdn because "Its hard to explain" - but they don''t exist in the msdn database)


What do you mean by reading only certain parts of a file? You can read a file and skip the sections you don''t need, e.g. if you have a keyword DONOT_BOTHER_START and you find this while reading the input, you keep skipping until you find DONOT_BOTHER_END. Or am I missing something here?

Share this post


Link to post
Share on other sites
TetsuoAkira22    122
quote:
Original post by EL
quote:
Original post by TetsuoAkira22
quote:
Original post by EL
You''re covering a lot of ground here, so I''ll give some keywords to use in Google (I can''t explain everything). What you''re trying to do is build an interpreter , to build an interpreter you''ll need a parser - think of it as transforming the input file with keywords etc. to entities you can handle and translate (like IF statement -> if(statement)).

I doubt you''ll have radically new ideas about AI, so why not try to some simple Prolog first. Then look into grammars (for building your language) and maybe, just maybe, then you will be ready to do what you''re planning here.

ps: a tutorial on reading or writing a file in C++ should be easy to find.


interpreter! Thats the word! I wrote a small one in BASIC 8-9 years ago... I just forgot what the technical name was.

Thanks - and about the file input/output - cplusplus.com, about''s tutorial, cprogramming.com, and msdn don''t really cover reading only certain parts of the file (I''ve asked a few friends, and they gave me the keywords to search up on msdn because "Its hard to explain" - but they don''t exist in the msdn database)


What do you mean by reading only certain parts of a file? You can read a file and skip the sections you don''t need, e.g. if you have a keyword DONOT_BOTHER_START and you find this while reading the input, you keep skipping until you find DONOT_BOTHER_END. Or am I missing something here?


Oh sorry, I''m also writing a config file reader - should of mentioned that...

My config file will (eventually) look like this

---
[Config]
Database=DB1
Name=Tetsuo
---
etc.

Share this post


Link to post
Share on other sites
EL    122
So? You''ll still have to read everything, don''t you? Or else you''re just putting redundant data in there. Any part of the file you don''t want to read shouldn''t be in that file in the first place.

Share this post


Link to post
Share on other sites
Guest Anonymous Poster   
Guest Anonymous Poster
quote:
Original post by TetsuoAkira22
I was thinking about using a pre-existing one - but I like a challenge, and I think it''d be fun to make my own... Plus I like having flexiblitiy - and writing a language how -=I=- want it.
If you''re interested in learning how a programming language is built up, you really should do some reading before trying to implement anything. It''s not a beginner''s thing to start with.

It''s a difficult task to write a good compiler/interpreter for an existing well-specified language. Now you''re talking about designing your own language.

I don''t mean to insult you, but if you seriously think you''ll make a better or more flexible language than any existing one, RE-THINK!!! At least, you should make sure you''re a good programmer before starting writing your own language. As already suggested, Python is probably what you should learn.

Share this post


Link to post
Share on other sites
RapidStunna    122
Stop putting him down. Creating a language isn''t as bad as you all say. Sure, he''s probobly not going to make a language better than C++, but there''s still a good chance he''ll end up with a simple scripting language. Oh well...to the poster: just do some reading on scripting languages and you''ll find most of what you need to know.

---
Brent Gunning | My Site

Share this post


Link to post
Share on other sites
If your''re really interested in writing your own scripting langauge, then check out the Peroxide Website. A note of warning though, making your own compiler/interpreter etc. takes a lot of time and effort, my own took me about 4 months to get it up to something decent. You might also be interested in looking at the Unreal scripting language reference here.

HTH

Share this post


Link to post
Share on other sites
RenderTarget    398
I must respectfully disagree (without having read Game Scripting Mastery yet):

http://www.amazon.com/exec/obidos/ASIN/0201100886/qid=1060294374/sr=2-1/ref=sr_2_1/103-2220606-3565416

I love this book.

I like pie.

Share this post


Link to post
Share on other sites