|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| ||||||||||||||||||||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
I started reading "The Programming Language Wiki" and i read First Steps and it says you need to have a game programming language and game engine.
I want to know how to make my own game engine and my own game programming language, but if someone gives my any help of making my own programming language or game engine, i can proceed on reading! What program could make my own program language, like C++ or vb but i want to make my own! Please, i need help! ![]() |
|
#2
|
||||
|
||||
|
Since you insist on trying this I'll give you small overview... I'm a little rusty on the subject so maybe someone else can add corrections/additions to what I'm saying...
First you need to define your language syntax. This means you define operators for addition, subtraction etc, specify how you write and call methods, how loops and if's look or how you work with variables. You decide if you operators have different priority (* before +) or not (you have to group operations with parentheses). Are there classes and interfaces? How is inheritance defined? What types are there? Strong-typed like C or loosely typed like PHP? Do you need to declare variables in order to use them (C) or can you create them adhoc (PHP)? How do comments look? How do you create and destroy objects? How do you reference and call external libraries? And so on... Then you need to bring that into a structured form from which you can start producing a parser. The EBNF is commonly used for that. Code:
An example for some simple computations could look like:
Expr = Mult , { ( "+" | "-" ), Mult }
Mult = Num , { ( "*" | "/" ), Num }
Num = ("(" , Expr, ")" ) | ( DigitNZ , {Digit} )
Digit = DigitNZ | "0"
DigitNZ = "1" | "2" | "3" | "4" | "5" | "6" | "7" | "8" | "9"
When you have that you need to write a scanner/tokenizer that takes a source code and converts a the stream of characters into a stream of syntax objects: KEYWORD_IF, IDENTIFIER('strlen'), OPERATOR('('), LITERAL_STRING('foo'), OPERATOR(')'), OPERATOR('>'), LITERAL_INT('0'), KEYWORD_THEN, KEYWORD_ENDIF Then you can use your scanner/tokenizer to feed a parser that in a first version just checks if your program is syntactically correct. In a second version you'll have to improve the parser to build a syntax tree. Code:
Using the above EBNF the expression "(0 - 12) * 5 + 1" would result in the following tree: Expr ? + ? +-Mult ? * ? | +- Num ( ? ) | | +- Expr ? - ? | | +- "0" | | +- "12" | +- "5" +- "1" Then as a last step you need to write either a compiler or an interpreter. An interpreter takes your syntax tree and executes it step by step. This is probably the simpler option but will not perform as well as a compiled program. The other option would be to write a compiler that takes the syntax tree and converts that into a windows executable. ------------------------------------------------------------- If you really want to try this i strongly suggest you first try to implement the simple computation example of mine to get a glimpse of what's ahead of you. If you manage to do that you can start to expand your language with additional operators then variables, flow control statements etc...
__________________
- Hugh of Borg The first thing young borg are taught: Keep away from Microsoft software! Last edited by Hugh of Borg : May 18th, 2009 at 09:48 AM. |
|
#3
|
|||
|
|||
|
OK, what program could you use to make your own operators such as:
Quote:
and so on and convert it into your script.. ..and for the compilier, do I need to design a compiler using vb2008? If so, i need help on making a compilier... Can someone please tell me any program that could make your operators work for your own game programming language, AND Help for vb on making my own compilier, please?? ![]() |
|
#4
|
||||
|
||||
|
Quote:
And you said, how can I create a word that means "house". It's like you think that the languages are all about the vocabulary. It's true that you are going to have vocabulary as part of the language, but what's really interesting is the grammar. Do you remember concepts like nouns, adjectives, and verbs? The English language has certain grammar rules. It is defined by the grammar, and the vocabulary you use falls into some aspect of that grammar. So when you talk about implementing operators in a programming language, what you really need to be thinking is the grammatical equivalent of an operator. What is the grammar of your language? How do operators fall into play? It's not necessarily as simple as hardcoding it, by the way. Quote:
__________________
When you ask a question, be prepared to tell us: what have you tried? If you think you don't need to try anything, we will never be interested in helping you. If you agree with the link, and you refuse to answer that question, you are being a hypocrite. Need help with broken code? Your question should be like a good bug report: (1) It has the smallest number of steps to reproduce the problem you see (2) It tells us precisely what you expected to see and (3) It tells us what you saw and how it differed from what you expected. We need all three to help you. Want better answers? Tell us what you Googled for and what steps you took to answer your own question. |
|
#5
|
|||
|
|||
|
About creating your language and making up a new identifier like "House" or another identifier replacing other ones. How can you do that, do you just use vb6C++ or do i need some sort of code to input into notepad??
|
|
#6
|
|||
|
|||
|
Quote:
|
|
#7
|
||||
|
||||
|
Quote:
Your question tells me that you didn't quite understand what Oler1s tried to say. To make a computer understand a language it has to follow very clear and specific rules. Humans are pretty good at interpreting sentences even broken very it much is if. Computers require any sentence to follow some clear pattern - the syntax. While in English you can say "What is the time?" or "What time is it?" or "Yo man! *points to wrist*" to inquire about the time a computer is less flexible. That's the heart of a language - natural or programming language. You first need to decide on the pattern that form a sentence. When you've done that you already have a programming language. But it's still empty. Before you can write any kind of literature (programs) with it you need a vocabulary (an API). You need to create words (classes, interfaces, enumerations, etc) before you can write a novel. In time others might start to use your language and find that it lacks some words so they create them (write additional classes). So first you need to create the syntax like i told you in my first post here. Only after you completed the compiler you can start building the API (the vocabulary) by creating standard classes to work with. |
|
#8
|
|||
|
|||
|
If I am going to make my programming language, what code things am I suppose to write in my text editor like special identifiers or do I just write:
Code:
" ' ? + - Hello "" And any other identifiers i need in code. Also about the compilier, if I make it my self to make it compile the text above, well what scripting stuff do you need to make a compilier for visual studio 2008 (visual basic). Need tips for DRAGON BOOK)): please help! ![]() |
|
#9
|
||||||
|
||||||
|
Quote:
Is there any vb2008 tutorials here? Quote:
Can someone list me all variables and identifiers to convert to my own identifier? Also do i need to write it like this: Quote:
But if i write it like this: Quote:
What code are you suppose to input into my text editor if i make up a code? please ![]() |
|
#10
|
|||
|
|||
|
About the
Quote:
|
|
#11
|
||||
|
||||
|
Quote:
This was just a highly simplified illustration on what a tokenizer does... There's a lot more to it in practice. But alright. I'm gonna dig up my old CS stuff when I get home and provide you with a small challenge. If you manage to do that we'll see how to proceed from there. As a first thing I'd like you to the following things:
|
|
#12
|
|||||
|
|||||
|
Quote:
So I could use my own programming language to create my Game Engine and then I could make my 2d and 3d games. Quote:
Other languages like vbC++ or python ok but I decide to make my own programming language so I could understand it easier for my scripting. Quote:
Ok, I'll show you the codes: Code:
Comments look like:
//
Example:
\\This is an example code of a comment.
Math signs look like:
+, -, \ (divide), *(multiply), ~ (Round-up answer)
They will appear blue text
Example:
5 + 4 \ 3
On the code the answer will be 3.
IF you round your answer:
5.4 +4.91 ~ (1)
Your answer will be 10.31 but the rounding to 1 decimal will make it 10.3.
~ = round-up
(1) = round decimals
If you wanted to define text:
Integer as [test_text]
then you can input without errors:
test_text =
Adding a word like "Interger" and the string [Your_string] will define your word.
Showing message boxes:
ShowMsgbox("Your text here", ButtonsOKCancel, Exclamation, "Msgbox test" -noclosebutton)
Parameters (special):
The - define the parameter such as for msgboxes:
-noclosebutton
-opaquebox #
-showhelpbutton
-addbutton, "Testtext", [TEST01]
TEST01 = Code
Starting a code:
Start {
Ending a code:
End }
If's, thens, ends, else
If <ADDTEXT> Then
<ADDTEXT>
Else
<ADDTEXT>
End If
the <ADDTEXT> areas are where you add your txt.
If you want a word to be nothing you just input:
Void
The use of OR:
<ADDTEXT> or <ADDTEXT>
Running applications, including files:
Run "\MYAPP.exe" or Run "$GAMEDIR\MyApp.exe"
Include Test.bzc
The BZC files are the script file extension.
You can also include files in the same folder as the code:
Include Test01.bzc
Or
Include Folder01\Test02.bzc
The "print" function:
Print "123"
Color function:
ColorRed, ColorBlue or
Color0, 0, 0, 0 (ColorRed, Green, Blue, Alpha)
Loops:
Loops=repeats
Example:
ShowMsgbox("Test") Loop [U]
U = If file("Test.txt") *exists
(don't know much about loops)
Files existing
If "Text1.txt" exists Then
<ADDTEXT>
Else
ShowMsgbox("Test")
End If
Eliminating/Adding objects:
Eliminate object.test
Add object.test at position(X,Y,Z)
Object properties:
Example: pressbutton
Pressbutton01.Text ("Pressbutton")
Output a file:
outputfile > ("\$APPDIR\", "Test", *.txt)
Output folder, name and extension. Many more codes.
In game code: Code:
Showing a message when picked up item (medikit)
Item.medikit.pickup {
Print("You picked up a medikit")
AddPlayerHealth "25"
PickupSound("\Sounds\Items\MediPickup25.wav")
That is just an simple medi-kit pickup.
}
Some Variables:
AddPlayerHealth #
AddPlayerArmor #
AddPlayerAmmo #
# = Enter a value
Thats all. --These codes might change... ![]() |
|
#13
|
|||
|
|||
|
And for arrays, loops, and many others i need to learn a bit more about them before i can convert them into code!
![]() |
|
#14
|
|||
|
|||
|
ok. All i just need is a list of all the keywords that you input into a text editor and a compilier.
Please, i need all of the keywords like: Code:
Expr = Mult , { ( "+" | "-" ), Mult }
Mult = Num , { ( "*" | "/" ), Num }
Num = ("(" , Expr, ")" ) | ( DigitNZ , {Digit} )
Digit = DigitNZ | "0"
DigitNZ = "1" | "2" | "3" | "4" | "5" | "6" | "7" | "8" | "9"
I just wand all of the keywords, please? Also: Code:
When you have that you need to write a scanner/tokenizer that takes a source code and converts a the stream of characters into a stream of syntax objects: Where are you suppose to find a scanner/tokenizer or do i just make it my self with some help. |
|
#15
|
|||
|
|||
|
Quote:
Ok, I did that. What do I need to do now? |
![]() |
| Viewing: Dev Shed Forums > Programming Languages > Game Development > Create my own programming language |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|
|