making another "simple language" using C++

This is a discussion on making another "simple language" using C++ within the C++ Programming forums, part of the General Programming Boards category; Let's say that i wanted to create a simple web programming language using C++, that has the extension of *.web
...

"C makes it easy to shoot yourself in the foot; C++ makes it harder, but when you do, it blows away your whole leg."-Bjarne Stroustrup
Nearing the end of finishing my 2D card game! I have to work on its 'manifesto' though <_<

if all you want is a few simple commands e.g.
text(somestring)
add(number1, number2)

that's relatively easy to do with simple text parsing. if you want to get more complicated, you want something more flexible.

a couple of options are (ranging from easy and fast but rigid to more complex, slower but more flexible)
simple string parsing (i.e. if (cmd == "text") std::cout << arg; )boost.spirit - allows you to define a language grammar within your c++ code
embed an interpretted language like python or lua

if you give some more detail as to what you'd like to achieve, I could probably point you in a more specific direction

As a programming exercise, you can probably do this, and you can keep it as simple as you want.

does it have to be pure C++ ??

No. Typically, you would write an interpreter. You can write that in "pure C++", or with whatever additional libraries you want to use. Then, you would compile that into an EXE (or other executable file).

When someone writes (and runs) a program in your special-language, they don't care what language you used to write the interpreter. They just need to run your interpreter-program before they run their application-program.

If you wanted to create a compiled language, you could do that with C++ too. (As you probably know, a compiler creates a stand-alone executable. The end-user wouldn't need your program to run the EXE file.) But to do it "correctly", you would need to know quite a bit of Assembly language.

is it gonna be pain in the butt ?

Probably. Again, if this is just an exercise you can make it as simple as you want. Is this going to be a browser plug-in? If so, it's going to take quite a bit of study if you don't know how to make plug-in (I don't).

---------------------------
If this is going to be a real-world program (as opposed to an exercise), I see some problems. You would need users to download and run your interpreter/plug-in. Most of us are paranoid about that kind of thing, and we don't like "clogging-up" our computer with extra junk.

And in order for it to be useful, it can't be too simple. In that case, it's probably not a one-man project.

----------------------------
There are some applications where a simple scripting language is useful. Let's say you make a microprocessor-controlled temperature chamber...

You might want to give the user a way to program it without using Assembly, C/C++, or whatever you used to make the thing work. And, you might not want the user hacking-into your firmware, etc.

You might want to create a few programming commands to give the user a way to program temperature changes, run temperature cycling loops, maybe include some "if-statements" in case something unexpected happens, etc.

A simple language like that can be learned in a day or so by a technically competent person who is not a programmer.

However, your part wouldn't be quite that simple.... The idea is to make things simple for the programmer, not to make things simple for the language-creator compiler/interpreter-writer. You would need to know C/C++ and/or Assembly. You would have to understand the nitty-gritty details of how the temperature-controller hardware & firmware work together. You would have to make sure your interpreter handles syntax errors by the end user, and maybe put-in some other error protection to keep the user from writing a program that's invalid, "stupid", or maybe even dangerous.

thank all for replies. I asked this because I was planning to make a simple web designing language, like HTML, but at the same time, it offers more functionality than HTML. My design was like this for printing a text or displaying image:

"C makes it easy to shoot yourself in the foot; C++ makes it harder, but when you do, it blows away your whole leg."-Bjarne Stroustrup
Nearing the end of finishing my 2D card game! I have to work on its 'manifesto' though <_<

To be honest I think this design offers much less functionality, and nobody will want to use it.
For example, with HTML you can see the order in which things will appear, while reading the code. With this, you cannot.
>>and i also planned to provide the user functionality make loops and stuff.
We've got PHP for that. You will have to come up with something really original if you want your brainchild to be preferred over existing technologies.

Like pronecracker said, it would have to be really good to be able to be better than the existing technologies.

HTML is a "mark-up language". It is very useful for what it was designed to do, and is even more powerful when combined with a CSS style sheet to help it out. For everything else, there is a multitude of scripting languages to do the job: JavaScript on the client side, and PHP and Python on the server side.

But let's say we completely ignore all that for now:

If you really want to create your own language, it takes a lot more than knowing how to code a program in C++. Do you know what a grammar is? Do you know anything about context-free grammars or regular grammars? Do you know anything about LL(k) parsing...or more specifically...LL(1) parsing? Do you know what a Finite State Machine is?

If you don't know those topics, I suggest reading up and studying them, because they are pretty important for defining a language. You define a language completely separate of coding any C++. You define a language on paper. Then you code a parser and a lexical analyzer in C++. After a parser is written, you can worry about doing an interpreter.

Some other good topics to read up on that might help you out, although they are not 100% vital: regular and context-free languages and turing machines, and graph theory