## death

first of all, i wannee say that im new to this forum :D
i have a great idea for a language, so i was wondering how can i make an actual programming language??

## Chainsaw 12

You mean, like how do you write a compiler?

Well, there are many good books and such on the topic; Google can be very helpful there. But generally the hardest part is to define the language in a rigourous way.

If you can write a BNF for your language, you can then translate the BNF into code and *presto* you have a start on a compiler.

## Chainsaw 12

So you searched and found Backus Naur Form. And maybe you saw some examples like (this is from Oberon):

number = integer | real.
integer = digit {digit} | digit {hexDigit} "H" .
real = digit {digit} "." {digit} [ScaleFactor].
ScaleFactor = ("E" | "D") ["+" | "-"] digit {digit}.
hexDigit = digit | "A" | "B" | "C" | "D" | "E" | "F".
digit = "0" | "1" | "2" | "3" | "4" | "5" | "6" | "7" | "8" | "9".

So now you can define your language!

Then you can parse it following these rules.

## onauc

So you searched and found Backus Naur Form. And maybe you saw some examples like (this is from Oberon):

number = integer | real.
integer = digit {digit} | digit {hexDigit} "H" .
real = digit {digit} "." {digit} [ScaleFactor].
ScaleFactor = ("E" | "D") ["+" | "-"] digit {digit}.
hexDigit = digit | "A" | "B" | "C" | "D" | "E" | "F".
digit = "0" | "1" | "2" | "3" | "4" | "5" | "6" | "7" | "8" | "9".

So now you can define your language!

Then you can parse it following these rules.

Hi,

Care to explain what all that was about ?
Frankly, I am interested to write my own C like compiler too.

Example, in C, you use PRINTF to spit an input on the screen but my language's command would be simply PRINT.
So, how can I teach this to the C compiler so if anyone now types in a source code PRINT it actually means PRINTF ?
I mean, underneath since C is programmed to understand the PRINTF only then I must teach it to understand the PRINT command too.
SO, how do I do it ?
What's the first thing I do ?
I will not only change 1 (PRINTF to PRINT) only but I will change others too.
For example PRINT in my language is CHAP so if anyone writes in the source-code CHAP then my compiler must do the same function as PRINTF.
Understand ?
Frankly, I really do not want to write a whole compiler but teach the C compiler to understand other words (PRINT, CHAP) too.
Get it ?
This way, people of my country who do not know english can learn the C in our own language.
So, to do all this, which part of the C compiler's source codes should I change/update ?
Or alternatively, shall I give you my function words (PRINT, CHAP, etc.) and you can change/add them on the C compiler ?
Afterwards, I can check the source code to see which parts you have updated. This way, I can learn which parts need updating should I wish to create another version of C in another language this time such as Arabic and then Hindi and then Urdu etc.

Cheers.

## death

hmm... seems good, ill start on the weekend! :D, but i still have to think of a good name :P

## Chainsaw 12

There are various tools that can turn a BNF description of your language into state tables or code; you might check out YACC, but there are others (see Google). Another approach is to build your own parser; that generally gives you more control over error messages and the like. Plus, its a bunch of fun to see your parser come to life!

"Recursive Descent" parsers are easy to build and match the BNF pretty well. Here's a funky and simplified example, based on the first line of that bnf (number = integer | real):

``````// Lets say we have a class called 'AParser' that contains all the methods to parse
// your BNF.  The end result of parsing is one or more errors, OR a 'parse tree', which
// is the internal representation of the language in tree form.  So, the parser's
// job is to build the tree and detect errors.
// Each production from the BNF can be represented as a single method.
// The result of that method is an error or a node filled in for the caller to
// do whatever it needs to (generally adding it to HER node and passing that
// up the call chain too).
bool AParser::Number( AParseTreeNode& node )
{
// The result of this routine will be to fill in 'node' or
// give an error.  For working, we need to pass another
// node to routines we call....
AParseTreeNode childNode;

// Set up the passed-in node with info about who I am for later reference
// and/or error messages:
node.SetType( kNumber );

// And you may want to know later what source line and col this node came
// from (for debugging output, say, or setting breakpoints, or whatnot)
SetLineNumberInfoIntoNode( node );

// Now, from the BNF, we know that a number is either an int or a real:
if (Integer( childNode ) || Real( childNode ))
{
// Here we glue the child node onto our node, or maybe sometimes you might
// morph the child node INTO our node, or whatever, depending on your needs.
node.AddChild( childNode ); // makes a copy of childNode
}
else
{
// This might display the source line and column, too
Error("Expected a NUMBER here.");
return false;
}
return true;
}``````

So that gives you something to start with. Each BNF line roughly cooresponds to a parser method, and if you can, phrase the parser method in the same manner as the BNF so it is easy to read and verify that you are doing the right thing.

Then you can see that you need some helper routines to manage the source text, especially tracking what row and column you are on for error reporting and debugging.

Once you have a parse tree, you know that your code is syntactically correct. Then you need to resolve named references (variables), maybe do optimizations, and generate code or pseudocode or just exececute (depending on if this is a compiler, interpreter, or something in-between).

## Chainsaw 12

For Onauc:

There are a few different ways to simply change the language of the keywords. One method is to take a running C compiler and tinker with the parser; where the bnf says 'WHILE' you could change that to something else.

Things like 'printf' are library routines, so you can add your own library routines instead of the standard ones, without changing the C compiler at all. In fact, if you just want to RENAME the standard routines to, say, German, you could do something like this:

#define DerPrinten printf

(I don't know German, of course, but 'DerPrinten' sounds fun)

Then in your source code you could include this definition from a file you've written and wherever someone coded DerPrinten the compiler would change that to 'printf'.

Another, totally different approach, would be to write a PRE-compiler that just looked for things like 'DerPrinten' and changed them to printf, and then the output of this pre-compiler would be fed to a standard C compiler.

Just some ideas!

## onauc

For Onauc:

There are a few different ways to simply change the language of the keywords. One method is to take a running C compiler and tinker with the parser; where the bnf says 'WHILE' you could change that to something else.

Things like 'printf' are library routines, so you can add your own library routines instead of the standard ones, without changing the C compiler at all. In fact, if you just want to RENAME the standard routines to, say, German, you could do something like this:

#define DerPrinten printf

(I don't know German, of course, but 'DerPrinten' sounds fun)

Then in your source code you could include this definition from a file you've written and wherever someone coded DerPrinten the compiler would change that to 'printf'.

Another, totally different approach, would be to write a PRE-compiler that just looked for things like 'DerPrinten' and changed them to printf, and then the output of this pre-compiler would be fed to a standard C compiler.

Just some ideas!

Thanx.
I was aware of the pre-compiler technique but the pre-compiler technique does not sound too professional, tasty or satisfying so it is better to change the english C functions to another language and create a vew version of C.

## TitusRevised

Does anyone know how to make your own web scripting language such as PHP or whatnot. Or maybe your own database language like MySQL?

## freesoft_2000 9

Hi everyone,

Maybe your own database language like MySQL?

Actually i only just finished a project that does that. I basically used Java. I can't post the code here as its a code that now belongs to my company but i can tell you how to go about doing it.

Do like what the people do at sun you basically need to create Api's that require this database to get up and running. In my case i had to create close to 78,000 apis(40,000 for internal usage and 38,000 for external usage) - i know its hard to believe but it took us about 2 years simply to get the main data engine running

Now people can load your classes fom either Java or C/C++. What you are asking can't be created in a day or week but years so if get around to doing this keep us posted.

Richard West

## rakoon13

Hi everyone,

Actually i only just finished a project that does that. I basically used Java. I can't post the code here as its a code that now belongs to my company but i can tell you how to go about doing it.

Do like what the people do at sun you basically need to create Api's that require this database to get up and running. In my case i had to create close to 78,000 apis(40,000 for internal usage and 38,000 for external usage) - i know its hard to believe but it took us about 2 years simply to get the main data engine running

Now people can load your classes fom either Java or C/C++. What you are asking can't be created in a day or week but years so if get around to doing this keep us posted.

Richard West

2 years as a team or 2 years with work done only by you ?

Thanks,
Steven Dale

## jwenting 1,649

Libraries have been written full of books about designing and implementing programming languages.
I'd not even seriously think about it unless I had a very high level theoretical software engineering education (Master of Science level) and years of experience in the field.
Dabbling in the fringes is of course fine but don't think you're going to write the next killer language on a friday afternoon in between lunch and dinner :)

As to databases, pretty similar though it's easier to get results with a partial implementation with limited functionality.
In fact I'm doint that right now for my Sun Certified Developer for the Java 2 Platform exam part of which is the implementation of a small limited functionality database server and client.
With professional experience and/or a good education that's actually doable.
And I might even take it further in the future and create a more full featured DBMS as a hobby.

## rakoon13

first of all, i wannee say that im new to this forum
i have a great idea for a language, so i was wondering how can i make an actual programming language??

Let me know more... maybe we can partner up.

dr. Steven Dale
Oncolgist
www.cellforum.net

## jwenting 1,649

2 years as a team or 2 years with work done only by you ?

Thanks,
Steven Dale

Such projects are never the work of a single person.
80.000 public methods (which I think he means) likely hints to about 10.000 classes.
That's rougly a million lines of code if not more. Half a million lines of code a year produced means 1.5 million lines of code written in a year.
I'd say 3 people at least, probably 5 or more depending on the company culture (i.e. how much of their time they actually spend coding and how much is wasted on "progress meetings", design reviews, etc. etc).

## C.G.P. -15

Here a simple breakdown in comparison to all the rhetoric post's above.

BASIC - One of the first languages. In a similar stance to SGML. Many of the languages we see to date are by products made up as an enhancement to SGML and BASIC (I may be off a little from the exact truth).

Are you extremely interested in your own developeing you own language? Or, are you more or less interested in helping enhance another language..

Here is an example, that I was actually around to help make - using BASIC to make the Time() Tag that you see in many Code-Based Languages today.

Although I can't remember exactly the correct string of integres.

its' like

time() = sec(.01 + .01)
when sex() - 1
count = (1 + sex()) time() = 1+1
display 1 + (time())

and so forth, technically a series of strings counting integers with a variable and display

when this is this, display this, when this gets to that display that, when it get's to this point, do this, once this string is finished = call it time(), or date(), or sec(), or whatever..

That's BASICally how they came up with Q-Basic/QuickBasic which is also extremely similar to PHP which is a LINUx Internet-Based Language also know as PIMP HOE PARTY CODE j/k.. Pre/Post Hypertext Pre-Post-Preprocessor..

Still interested - I gotta remember what the exact name of the language was that that time() integer string is called;

I'm looking at the same idea to help build a few things.. Do me a favor before you respond to this, especially if you understand what I'm saying and your interested in the possibility of maybe working with me, and maybe putting together a "Classroom Group" we can teach each other, others, while helping out.. IDK

look up information on a program called Libero, it is known for translating PHP into a software routined package of sorts.. I need someone to help me with it.

commented: What are you on ? Some hybrid magic mushroom dipped in LSD ? eh ? -2
commented: this is trash -2

## MosaicFuneral 812

This post is a million years old, C.G.P. No one cares, anymore; nor do I know what you're even talking about - stoned?

A real language would simply take something like:

``````imbedded function quit()
{ asm("MOV AX, 4Ch\n",
"INT 21h"); }
main()
{
quit();
}``````

Into, roughly: `B8014CCD21`

## C.G.P. -15

then again daniweb seems like an utterly facist place to ask or say anything, unless it's disregarding on a i didn't say anything basis.

What's A884073ARE you referring too.

## Rashakil Fol 978

then again daniweb seems like an utterly facist place to ask or say anything,

No it isn't, except towards people who write like sperging imbeciles, making statements not grounded in reality.

## C.G.P. -15

No it isn't, except towards people who write like sperging imbeciles, making statements not grounded in reality.

Truthfully. It's a great statement, especially for the posters I've come across. "Is being a degenerate rude punk, the comraderie of choice on DaniWEB??" Or, is everyone just an amatuer porn star that doesn't know anyone beside their cousin.

commented: [insult goes here] -3